Add hot plug event in rte eal interrupt and inplement it in i40e driver.
Subsystems (2)
Re: [PATCH V18 2/4] eal: add device event monitor framework
In reply to Tan, JianfengQuoted 238 lines · Jianfeng
Quoted 138 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 2/4] eal: add device event monitor frameworkThis patch aims to add a general device event monitor framework at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other types of device event monitor, but not in this scope at the stage.
To get started, users firstly call below new added APIs to enable/disable the device event monitor mechanism:
-rte_dev_event_monitor_start
-rte_dev_event_monitor_stopThen users shell register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_event_callback_register -rte_dev_event_callback_unregisterUse hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could benefit further fail-safe or live-migration.
Signed-off-by Jeff Guo <[email protected]>---
v18->v17:
add feature announcement in release document, fix bsp compile issue.--- doc/guides/rel_notes/release_18_05.rst | 9 ++ lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 ++++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 168 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 +++ lib/librte_eal/common/include/rte_dev.h | 94 ++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 22 +++++ lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 8 ++ 11 files changed, 341 insertions(+)create mode 100644
lib/librte_eal/bsdapp/eal/eal_dev.ccreate mode 100644lib/librte_eal/linuxapp/eal/eal_dev.cdoc/guides/rel_notes/release_18_05.rst +0
-0@@ -41,6 +41,15 @@ New Features Also, make sure to start the actual text at the margin.=========================================================
doc/guides/rel_notes/release_18_05.rst +3
-0+* **Added device event monitor framework.** + + Added a general device event monitor framework at EAL, for devicedynamic management.
+ Such as device hotplug awareness and actions adopted accordingly. The list of new APIs:doc/guides/rel_notes/release_18_05.rst +2
-0+ + * ``rte_dev_event_monitor_start`` and ``rte_dev_event_monitor_stop``are for
doc/guides/rel_notes/release_18_05.rst +2
-0+ the event monitor enable and disable. + * ``rte_dev_event_callback_register`` and``rte_dev_event_callback_unregister``
doc/guides/rel_notes/release_18_05.rst +1
-0+ are for the user's callbacks register and unregister. API Changes -----------lib/librte_eal/bsdapp/eal/Makefile +0
-0@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=
eal_lcore.c
SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_timer.cSRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_interrupts.cSRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_alarm.clib/librte_eal/bsdapp/eal/Makefile +1
-0+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.clib/librte_eal/bsdapp/eal/eal_dev.c new file +21
-0@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}lib/librte_eal/bsdapp/eal/meson.build +1
-0@@ -12,4 +12,5 @@ env_sources = files('eal_alarm.c', 'eal_timer.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c' )lib/librte_eal/common/eal_common_dev.c +0
-0lib/librte_eal/common/eal_common_dev.c line 22
Quoted 9 lines
lib/librte_eal/common/eal_common_dev.c +3
-0@@ -14,9 +14,34 @@#include <rte_devargs.h> #include <rte_debug.h> #include <rte_log.h> +#include <rte_spinlock.h> +#include <rte_malloc.h> #include "eal_private.h" +/* spinlock for device callbacks */ It's for protect callback list.
lib/librte_eal/common/eal_common_dev.c line 23
Quoted 1 line
lib/librte_eal/common/eal_common_dev.c +1
-0+static rte_spinlock_t dev_event_lock =RTE_SPINLOCK_INITIALIZER ;Put this spinlock where the list locates.
Quoted 86 lines
lib/librte_eal/common/eal_common_dev.c +12
-0+ +/** +* The device event callback description. +* +* It contains callback address to be registered by user application, +* the pointer to the parameters for callback, and the device name. +*/ +struct dev_event_callback { +TAILQ_ENTRY (dev_event_callback) next;/**< Callbacks list */ +rte_dev_event_cb_fn cb_fn;/**< Callback address */ +void *cb_arg;/**< Callback parameter */ +char *dev_name;/**< Callback device name, NULL is for all device */
lib/librte_eal/common/eal_common_dev.c +28
-0+uint32_t active;/**< Callback is executing */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (dev_event_cb_list, dev_event_callback); + +/* The device event callback list for all registered callbacks. */ +static struct dev_event_cb_list dev_event_cbs; +static int cmp_detached_dev_name (const struct rte_device *dev,const void *_name) {@@ -207,3 +232,146 @@ rte_eal_hotplug_remove(const char *busname, const char *devname)rte_eal_devargs_remove (busname ,devname );return ret; } + +int __rte_experimental +rte_dev_event_callback_register(const char *device_name, + rte_dev_event_cb_fn cb_fn, + void *cb_arg) +{ + struct dev_event_callback *event_cb; + int ret; + + if (!cb_fn) + return -EINVAL; + + rte_spinlock_lock(&dev_event_lock); + + if (TAILQ_EMPTY(&dev_event_cbs)) + TAILQ_INIT(&dev_event_cbs); + + TAILQ_FOREACH(event_cb, &dev_event_cbs, next) { + if (event_cb->cb_fn == cb_fn && event_cb->cb_arg ==
cb_arg) {lib/librte_eal/common/eal_common_dev.c +1
-0+ if (device_name == NULL && event_cb->dev_name== NULL)
lib/librte_eal/common/eal_common_dev.c +2
-0+break ; + if (device_name == NULL || event_cb->dev_name== NULL)
lib/librte_eal/common/eal_common_dev.c +17
-0+continue ; +if (!strcmp (event_cb->dev_name, device_name)) +break ; + } + } + +/* create a new callback. */ +if (event_cb ==NULL ) { + event_cb =malloc (sizeof (struct dev_event_callback )); +if (event_cb !=NULL ) { + event_cb->cb_fn = cb_fn; + event_cb->cb_arg = cb_arg; + event_cb->active =0 ; +if (!device_name) { + event_cb->dev_name =NULL ; + }else { + event_cb->dev_name =
strdup(device_name);lib/librte_eal/common/eal_common_dev.c +6
-0+if (event_cb->dev_name ==NULL ) { + ret = -ENOMEM ; + goto error; + } + } + TAILQ_INSERT_TAIL(&dev_event_cbs, event_cb,next);
lib/librte_eal/common/eal_common_dev.c +6
-0+ }else { +RTE_LOG (ERR ,EAL , +"Failed to allocate memory for device " +"event callback." ); + ret = -ENOMEM ; + goto error;
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 292
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+ } + }else { +RTE_LOG (ERR ,EAL , +"The callback is already exist, no need " +"to register again.\n" ); + ret = -EEXIST ; + goto error;Here is a bug that you will free an existing callback entry.
you are correct.
Quoted 26 lines
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+ } + +rte_spinlock_unlock (&dev_event_lock); +return 0 ; +error:lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 307
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+free (event_cb); +rte_spinlock_unlock (&dev_event_lock); +return ret; +} + +int __rte_experimental +rte_dev_event_callback_unregister (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg) +{Let's clearly define the behavior and return of this API. If I understand it correctly,
If cb_arg != -1, we use (dev_name, cb_fn, cb_arg) as the key to look up the registered API. If cb_arg == -1, we use (cb_fn) as the key to look up the registered API.For return value, we want to return the number of callbacks being removed. It could be:
Quoted 1 line
=0, number of callbacks been removed. (When we encounter an active callback, we shall skip it or just return
-EAGAIN, neither sounds good to me actually)<0, error encountered.
If you agree with above statement, below implementation has lots of issues.
Quoted 14 lines
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 320
Quoted 13 lines
lib/librte_eal/common/eal_common_dev.c +13
-0+int ret =0 ; +struct dev_event_callback *event_cb, *next; + +if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&dev_event_lock); + +/*walk through the callbacks and remove all that match. */ +for (event_cb =TAILQ_FIRST (&dev_event_cbs); event_cb !=NULL ; + event_cb = next) { + + next =TAILQ_NEXT (event_cb, next);First of all, if
cb_fn!=event_cb->cb_fn, we shall continue.
might not, if cb_arg = -1 for all cb, don't need to care if cb_fn equal event_cb->cb_fn or not.
Quoted 4 lines
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +4
-0+ +if (device_name !=NULL && event_cb->dev_name !=NULL ) { +if (!strcmp (event_cb->dev_name, device_name)) { + if (event_cb->cb_fn != cb_fn ||
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 331
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+ (cb_arg != (void *)-1 && + event_cb->cb_arg != cb_arg)) + continue; + } + }else if (device_name !=NULL ) { +continue ; + }What about
device_name== NULL &&event_cb->dev_name!= NULL &&cb_arg== -1?
if device_name == NULL, it mean for all device, just process any cb.
Quoted 2 lines
What about
device_name== NULL &&event_cb->dev_name== NULL &&cb_arg!= -1 &&cb_arg!=event_cb->cb_arg?
if device_name == NULL, don't care about cb_arg, just remove the back.
Quoted 4 lines
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +4
-0+ +/* +* if this callback is not executing right now, +* then remove it.
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 342
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+*/ +if (event_cb->active ==0 ) { +TAILQ_REMOVE (&dev_event_cbs, event_cb, next); +free (event_cb); + ret++; + }else { + ret = -EAGAIN ;If you don't break here, next time you find another satisfied callback, you will ret++ on a (
-EAGAIN) value.
here , i think you are correct. but since return ret value is for number check, so that it would just continue here.
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 301
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+ } + } +rte_spinlock_unlock (&dev_event_lock); +return ret; +}BTW, don't know why DPDK has the tradition of using cb_arg==-1 to stand for multiple callbacks, it's not a good API design to me. Would like as others' opinions, shall we continue this?
i don't have obvious objection for the cb_arg=-1 usage, it might make sense.
Quoted 66 lines
Quoted 16 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+ +void +dev_callback_process(char *device_name, enum rte_dev_event_typeevent)
lib/librte_eal/common/eal_common_dev.c +12
-0+{ +struct dev_event_callback *cb_lst; +int rc; + +if (device_name ==NULL ) +return ; + +rte_spinlock_lock (&dev_event_lock); + + TAILQ_FOREACH(cb_lst, &dev_event_cbs, next) { +if (cb_lst->dev_name) { +if (strcmp (cb_lst->dev_name, device_name))lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 372
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+continue ; + } + cb_lst->active =1 ; +rte_spinlock_unlock (&dev_event_lock); + rc = cb_lst->cb_fn (device_name, event, + cb_lst->cb_arg); +if (rc) { +RTE_LOG (ERR ,EAL , +"Failed to process callback function." ); + }I don't see a reason why we need the return value from callbacks. Probably, define it as void type.
Quoted 27 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+rte_spinlock_lock (&dev_event_lock); + cb_lst->active =0 ; + } +rte_spinlock_unlock (&dev_event_lock); +}lib/librte_eal/common/eal_private.h +5
-0@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). * @@ -205,4 +207,17 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* Internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User lib/librte_eal/common/eal_private.h struct rte_bus · line 223
Quoted 10 lines
lib/librte_eal/common/eal_private.h +10
-0+* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type. +* +*/ +void +dev_callback_process (char *device_name,enum rte_dev_event_type event);Too many
*_processfunctions in this patch. Let's avoid using such ambiguous words.
Quoted 1 line
For example, you can rename this function to
dev_event_callback_invoke().
hold on this define,will consider rename other side.
Quoted 187 lines
Quoted 187 lines
#endif /* _EAL_PRIVATE_H_ */lib/librte_eal/common/include/rte_dev.h +94
-0@@ -24,6 +24,25 @@ extern "C" {#include <rte_compat.h> #include <rte_log.h> +/** +* The device event type. +*/ +enum rte_dev_event_type { +RTE_DEV_EVENT_ADD ,/**< device being added */ +RTE_DEV_EVENT_REMOVE ,/**< device being removed */ +RTE_DEV_EVENT_MAX /**< max value of this enum */ +}; + +struct rte_dev_event { +enum rte_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +}; + +typedef int (*rte_dev_event_cb_fn )(char *device_name, +enum rte_dev_event_type event, +void *cb_arg); + __attribute__((format (printf,2 ,0 )))static inline void rte_pmd_debug_trace (const char *func_name,const char *fmt, ...)@@ -267,4 +286,79 @@ __attribute__((used)) = str }#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It registers the callback for the specific device. +* Multiple callbacks cal be registered at the same time. +* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_callback_register (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It unregisters the callback according to the specified device. +* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback, (void *)-1 means to remove all +* registered which has the same callback address. +* +* @return +* - On success, return the number of callback entities removed. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_callback_unregister (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Start the device event monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_start (void); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Stop the device event monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_stop (void);#endif /* _RTE_DEV_H_ */ lib/librte_eal/linuxapp/eal/Makefile +0
-0@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=
eal_lcore.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_timer.cSRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_interrupts.cSRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_alarm.clib/librte_eal/linuxapp/eal/Makefile +1
-0+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.clib/librte_eal/linuxapp/eal/eal_dev.c new file +22
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}lib/librte_eal/linuxapp/eal/meson.build +1
-0@@ -18,6 +18,7 @@ env_sources = files('eal_alarm.c', 'eal_vfio_mp_sync.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c', ) if has_libnuma == 1lib/librte_eal/rte_eal_version.map +8
-1@@ -256,3 +256,11 @@ EXPERIMENTAL { rte_service_start_with_defaults; } DPDK_18.02; + +EXPERIMENTAL { + global: + + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; + +} DPDK_18.05; --2.7.4
PATCH v18 3/4 eal/linux: uevent parse and process
In reply to Jeff GuoIn order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
---v18->v17:
refine socket configuration.
--- lib/librte_eal/linuxapp/eal/eal_dev.c | 178 +++++++++++++++++++++++++++++++++- 1 file changed, 176 insertions(+), 2 deletions(-)
lib/librte_eal/linuxapp/eal/eal_dev.c +176 -2
@@ -2,21 +2,195 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> + +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which event exposure from */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ; + } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind socket for netlink fd.\n" ); + goto err; + } + +return 0 ; +err: +close (intr_handle.fd); +return ret; +} + +static void +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +} + +static int +dev_uev_receive (int fd,struct rte_dev_event *uevent) +{ +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s.\n" , + errno,strerror (errno)); +return -1 ; + }else if (ret ==0 ) +/* connection closed */ +return -1 ; + +dev_uev_parse (buf, uevent,EAL_UEV_MSG_LEN ); + +return 0 ; +} + +static void +dev_uev_process(__rte_unused void *param) +{ +struct rte_dev_event uevent; + +if (dev_uev_receive (intr_handle.fd, &uevent)) +return ; +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_process,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_process, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; }
Signature · 1 line
2.7.4
Re: [PATCH V18 3/4] eal/linux: uevent parse and process
Hi Jeff,
Looks much better now, but still have some issues to address.
Quoted 43 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 3/4] eal/linux: uevent parse and processIn order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
Signed-off-by Jeff Guo <[email protected]>---
v18->v17:
refine socket configuration.--- lib/librte_eal/linuxapp/eal/eal_dev.c | 178 +++++++++++++++++++++++++++++++++- 1 file changed, 176 insertions(+), 2 deletions(-)lib/librte_eal/linuxapp/eal/eal_dev.c +7
-0@@ -2,21 +2,195 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h>
lib/librte_eal/linuxapp/eal/eal_dev.c line 24
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which event exposure from */
Reword it a little bit:
/* identify the system layer which reports this event */
Quoted 19 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +19
-0+enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ;
lib/librte_eal/linuxapp/eal/eal_dev.c line 53
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind socket for netlink fd.\n" );
Reword it a little bit so that we can understand it's a log related to hotplug:
Failed to bind uevent socket
lib/librte_eal/linuxapp/eal/eal_dev.c line 59
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+ goto err; + } + +return 0 ; +err: +close (intr_handle.fd);
Then: intr_handle.fd = -1?
Quoted 37 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +37
-0+return ret; +} + +static void +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' )
lib/librte_eal/linuxapp/eal/eal_dev.c line 106
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+break ; + buf++; + } + } + +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 ))
How can we indicate it is an event with subsystem that we will not handle?
lib/librte_eal/linuxapp/eal/eal_dev.c line 111
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +5
-0+ event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ;
How can we indicate it is an event with type that we will not handle?
My suggestion is to define a return value for that:
- EVENT_VALID returned for an event that we will handle later.
- EVENT_INVALID returned for any unknown events.
Quoted 22 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +22
-0+} + +static int +dev_uev_receive (int fd,struct rte_dev_event *uevent) +{ +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s.\n" , + errno,strerror (errno)); +return -1 ; + }else if (ret ==0 ) +/* connection closed */ +return -1 ; + +dev_uev_parse (buf, uevent,EAL_UEV_MSG_LEN );
lib/librte_eal/linuxapp/eal/eal_dev.c line 143
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ +return 0 ; +} + +static void +dev_uev_process(__rte_unused void *param) +{ +struct rte_dev_event uevent; + +if (dev_uev_receive (intr_handle.fd, &uevent))
If error happens, we shall start an alarm task to remove the callback of interrupt thread.
lib/librte_eal/linuxapp/eal/eal_dev.c line 144
Quoted 1 line
lib/librte_eal/linuxapp/eal/eal_dev.c +1
-0+return ;
You may want to add a log here for debugging, showing what event comes for which device.
lib/librte_eal/linuxapp/eal/eal_dev.c line 146
Quoted 2 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +1
-0+if (uevent.devname)
You can also filter this kind of events using the way I suggested above.
Quoted 55 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +38
-3+dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_process,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_process, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; } --2.7.4
Re: [PATCH V18 3/4] eal/linux: uevent parse and process
thanks for review.
Quoted 92 lines · Jianfeng
Hi Jeff,
Looks much better now, but still have some issues to address.
Quoted 43 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 3/4] eal/linux: uevent parse and processIn order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
Signed-off-by Jeff Guo <[email protected]>---
v18->v17:
refine socket configuration.--- lib/librte_eal/linuxapp/eal/eal_dev.c | 178 +++++++++++++++++++++++++++++++++- 1 file changed, 176 insertions(+), 2 deletions(-)lib/librte_eal/linuxapp/eal/eal_dev.c +7
-0@@ -2,21 +2,195 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> lib/librte_eal/linuxapp/eal/eal_dev.c line 24
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which event exposure from */ Reword it a little bit:
/* identify the system layer which reports this event */Quoted 19 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +19
-0+enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ;lib/librte_eal/linuxapp/eal/eal_dev.c line 53
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind socket for netlink fd.\n" );Reword it a little bit so that we can understand it's a log related to hotplug:
Failed to bind uevent socket
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 59
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+ goto err; + } + +return 0 ; +err: +close (intr_handle.fd);Then: intr_handle.fd = -1?
sure.
Quoted 56 lines
Quoted 37 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +37
-0+return ret; +} + +static void +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' )lib/librte_eal/linuxapp/eal/eal_dev.c line 106
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+break ; + buf++; + } + } + +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 ))How can we indicate it is an event with subsystem that we will not handle?
lib/librte_eal/linuxapp/eal/eal_dev.c line 111
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +5
-0+ event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ;How can we indicate it is an event with type that we will not handle?
Quoted 3 lines
My suggestion is to define a return value for that:
-EVENT_VALIDreturned for an event that we will handle later.
-EVENT_INVALIDreturned for any unknown events.
make sense ,just need 0 & -1 enough i think.
Quoted 94 lines
Quoted 22 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +22
-0+} + +static int +dev_uev_receive (int fd,struct rte_dev_event *uevent) +{ +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s.\n" , + errno,strerror (errno)); +return -1 ; + }else if (ret ==0 ) +/* connection closed */ +return -1 ; + +dev_uev_parse (buf, uevent,EAL_UEV_MSG_LEN );lib/librte_eal/linuxapp/eal/eal_dev.c line 143
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ +return 0 ; +} + +static void +dev_uev_process(__rte_unused void *param) +{ +struct rte_dev_event uevent; + +if (dev_uev_receive (intr_handle.fd, &uevent))If error happens, we shall start an alarm task to remove the callback of interrupt thread.
lib/librte_eal/linuxapp/eal/eal_dev.c line 144
Quoted 1 line
lib/librte_eal/linuxapp/eal/eal_dev.c +1
-0+return ;You may want to add a log here for debugging, showing what event comes for which device.
lib/librte_eal/linuxapp/eal/eal_dev.c line 146
Quoted 1 line
lib/librte_eal/linuxapp/eal/eal_dev.c +1
-0+if (uevent.devname)You can also filter this kind of events using the way I suggested above.
Quoted 55 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +38
-3+dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_process,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_process, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; } --2.7.4
PATCH v18 4/4 app/testpmd: enable device hotplug monitoring
In reply to Jeff GuoUse testpmd for example, to show how an application use device event APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c 0x3 --n 4 -- -i --hot-plug
then testpmd start the device event monitor by call the new API (rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly.
This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set.
---v18->v17:
remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.
--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 112 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 121 insertions(+), 2 deletions(-)
app/test-pmd/parameters.c +4 -1
@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enable hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE
@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };
@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);
app/test-pmd/testpmd.c +111 -1
167 lines not on this page · raw message
app/test-pmd/testpmd.h +2 -0
@@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
doc/guides/testpmd_app_ug/run_app.rst +4 -0
@@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug.
Signature · 1 line
2.7.4
Re: [PATCH V18 4/4] app/testpmd: enable device hotplug monitoring
Quoted 13 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 4/4] app/testpmd: enable device hotplug monitoring
Quoted 1 line
Use testpmd for example, to show how an application use device event
s/use/uses
Quoted 8 lines
APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c
0x3--n 4 -- -i --hot-plugthen testpmd start the device event monitor by call the new API
s/start/starts
s/call/calling
Quoted 10 lines
(
rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly.This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set.
Signed-off-by Jeff Guo <[email protected]>
Some typos and a trivial suggestion. Feel free to carry my
in the next version.
Quoted 166 lines
---
v18->v17:
remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 112 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 121 insertions(+), 2 deletions(-)app/test-pmd/parameters.c +1
-0@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n"); printf(" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n"); + printf(" --hot-plug: enable hot plug for device.\n"); }#ifdef
RTE_LIBRTE_CMDLINEapp/test-pmd/parameters.c +3
-1@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n"); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :app/test-pmd/parameters.c +0
-0usage (argv[0 ]);app/test-pmd/testpmd.c +9
-0@@ -12,6 +12,7 @@#include <sys/mman.h> #include <sys/types.h> #include <errno.h> +#include <stdbool.h> #include <sys/queue.h> #include <sys/stat.h> @@ -284,6 +285,8 @@ uint8_t lsc_interrupt = 1; /* enabled by default */*/ uint8_t rmv_interrupt =1 ;/* enabled by default */ +uint8_t hot_plug =0 ;/**< hotplug disabled by default. */ +/* * Display or mask ether events * Default to all events except VF_MBOX @@ -391,6 +394,12 @@ static void check_all_ports_link_status(uint32_t port_mask);static int eth_event_callback (portid_t port_id,enum rte_eth_event_type type,void *param,void *ret_param); +static int eth_dev_event_callback (char *device_name, +enum rte_dev_event_type type, +void *param); +static int eth_dev_event_callback_register (void ); +static int eth_dev_event_callback_unregister (void ); +/* * Check if all the ports are started.
app/test-pmd/testpmd.c +52
-0@@ -1853,6 +1862,39 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_dev_event_callback_register (void ) +{ +int diag; + +/* register the device event callback */ + diag =rte_dev_event_callback_register (NULL , + eth_dev_event_callback,NULL ); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +return 0 ; +} + + +static int +eth_dev_event_callback_unregister (void ) +{ +int diag; + +/* unregister the device event callback */ + diag =rte_dev_event_callback_unregister (NULL , + eth_dev_event_callback,NULL ); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {@@ -1916,6 +1958,7 @@ voidpmd_test_exit (void) {portid_t pt_id; +int ret;if (test_done ==0 )stop_packet_forwarding ();@@ -1929,6 +1972,18 @@ pmd_test_exit(void)close_port (pt_id); } } + +if (hot_plug) { + ret =rte_dev_event_monitor_stop (); +if (ret) +RTE_LOG (ERR ,EAL , +"fail to stop device event monitor." ); + + ret =eth_dev_event_callback_unregister (); +if (ret) +RTE_LOG (ERR ,EAL , +"fail to unregister all event callbacks." ); + }printf ("\nBye...\n" ); }@@ -2059,6 +2114,48 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, return 0; } +/* This function is used by the interrupt thread */ +static int +eth_dev_event_callback (char *device_name,enum rte_dev_event_type type, + __rte_unused void *arg) +{ +int ret =0 ;From here
app/test-pmd/testpmd.c +4
-0+static const char *const event_desc[] = { + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + };
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2136
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+ +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + }
to here, these check are not necessary.
Quoted 78 lines
app/test-pmd/testpmd.c +22
-0+ +switch (type) { +case RTE_DEV_EVENT_REMOVE : +RTE_LOG (ERR ,EAL ,"The device: %s has been removed!\n" , + device_name); +/* TODO: After finish failure handle, begin to stop +* packet forward, stop port, close port, detach port. +*/ +break ; +case RTE_DEV_EVENT_ADD : +RTE_LOG (ERR ,EAL ,"The device: %s has been added!\n" , + device_name); +/* TODO: After finish kernel driver binding, +* begin to attach port. +*/ +break ; +default : +break ; + } +return ret; +} +static int set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port*port)
{app/test-pmd/testpmd.c +14
-1@@ -2474,8 +2571,9 @@ signal_handler(int signum)int main (int argc,char ** argv) { -int diag; +int diag;portid_t port_id; +int ret;signal (SIGINT , signal_handler);signal (SIGTERM , signal_handler);@@ -2543,6 +2641,18 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +if (hot_plug) { +/* enable hot plug monitoring */ + ret =rte_dev_event_monitor_start (); +if (ret) { + rte_errno =EINVAL ; +return -1 ; + } +eth_dev_event_callback_register (); + + } +if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );app/test-pmd/testpmd.h +0
-0@@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packetforwarding when set to 1. */
externuint8_tlsc_interrupt; /**< disabled by "--no-lsc-interrupt" parameter
*/
externuint8_trmv_interrupt; /**< disabled by "--no-rmv-interrupt"
parameter */
externuint32_tevent_print_mask;app/test-pmd/testpmd.h +2
-0+extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS doc/guides/testpmd_app_ug/run_app.rst +0
-0
doc/guides/testpmd_app_ug/run_app.rst The commandline options are: · line 485
Quoted 7 lines
doc/guides/testpmd_app_ug/run_app.rst +4
-0@@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug.
s/machenism/mechanism
Quoted 2 lines
--
2.7.4
Re: [PATCH V18 4/4] app/testpmd: enable device hotplug monitoring
Hi all
What do you think about adding the "--hotplug" parameter as a new EAL command line parameter?
From: Tan, Jianfeng, Wednesday, April 4, 2018 6:23 AM
Quoted 311 lines
Quoted 11 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 4/4] app/testpmd: enable device hotplug monitoringQuoted 1 line
Use testpmd for example, to show how an application use device event
s/use/uses
Quoted 8 lines
APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c
0x3--n 4 -- -i --hot-plugthen testpmd start the device event monitor by call the new API
s/start/starts
s/call/callingQuoted 10 lines
(
rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly.This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set.
Signed-off-by Jeff Guo <[email protected]>Some typos and a trivial suggestion. Feel free to carry my
Reviewed-by Jianfeng Tan <[email protected]>in the next version.
Quoted 17 lines
---
v18->v17:
remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 112 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 121 insertions(+), 2 deletions(-)app/test-pmd/parameters.c +0
-0app/test-pmd/parameters.c usage(char* progname) · line 189
Quoted 4 lines
app/test-pmd/parameters.c +0
-0@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n"); printf(" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TXqueue
Quoted 127 lines
app/test-pmd/parameters.c +1
-0offloads\n"); + printf(" --hot-plug: enable hot plug for device.\n" ); }#ifdef
RTE_LIBRTE_CMDLINEapp/test-pmd/parameters.c +3
-1@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n"); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :app/test-pmd/parameters.c +0
-0usage (argv[0 ]);app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0
-04c0e258..2faeb90 100644
app/test-pmd/testpmd.c +3
-0@@ -12,6 +12,7 @@#include <sys/mman.h> #include <sys/types.h> #include <errno.h> +#include <stdbool.h> #include <sys/queue.h> #include <sys/stat.h> @@ -284,6 +285,8 @@ uint8_t lsc_interrupt = 1; /* enabled by default */*/ uint8_t rmv_interrupt =1 ;/* enabled by default */ +uint8_t hot_plug =0 ;/**< hotplug disabled by default. */ +/* * Display or mask ether events * Default to all events except VF_MBOX @@ -391,6 +394,12 @@ static void check_all_ports_link_status(uint32_t
port_mask);
static int eth_event_callback(portid_tport_id,app/test-pmd/testpmd.c +52
-0enum rte_eth_event_type type, void *param, void *ret_param); +static int eth_dev_event_callback (char *device_name, +enum rte_dev_event_type type, +void *param); +static int eth_dev_event_callback_register (void ); +static int eth_dev_event_callback_unregister (void ); +/* * Check if all the ports are started. @@ -1853,6 +1862,39 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_dev_event_callback_register (void ) +{ +int diag; + +/* register the device event callback */ + diag =rte_dev_event_callback_register (NULL , + eth_dev_event_callback,NULL ); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +return 0 ; +} + + +static int +eth_dev_event_callback_unregister (void ) +{ +int diag; + +/* unregister the device event callback */ + diag =rte_dev_event_callback_unregister (NULL , + eth_dev_event_callback,NULL ); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {@@ -1916,6 +1958,7 @@ voidpmd_test_exit (void) {portid_t pt_id; +int ret;if (test_done ==0 )stop_packet_forwarding ();@@ -1929,6 +1972,18 @@ pmd_test_exit(void)close_port (pt_id); } } + +if (hot_plug) { + ret =rte_dev_event_monitor_stop (); +if (ret) +RTE_LOG (ERR ,EAL , +"fail to stop device event monitor." ); + + ret =eth_dev_event_callback_unregister (); +if (ret) +RTE_LOG (ERR ,EAL , +"fail to unregister all event callbacks." ); + }printf ("\nBye...\n" ); }app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum · line 2123
Quoted 10 lines
app/test-pmd/testpmd.c +5
-0@@ -2059,6 +2114,48 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, return 0; } +/* This function is used by the interrupt thread */ static int +eth_dev_event_callback (char *device_name,enum rte_dev_event_type type, + __rte_unused void *arg) +{ +int ret =0 ;From here
Quoted 4 lines
app/test-pmd/testpmd.c +4
-0+static const char *const event_desc[] = { + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + };app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2136
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+ +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + }to here, these check are not necessary.
Quoted 76 lines
app/test-pmd/testpmd.c +22
-0+ +switch (type) { +case RTE_DEV_EVENT_REMOVE : +RTE_LOG (ERR ,EAL ,"The device: %s has been removed!\n" , + device_name); +/* TODO: After finish failure handle, begin to stop +* packet forward, stop port, close port, detach port. +*/ +break ; +case RTE_DEV_EVENT_ADD : +RTE_LOG (ERR ,EAL ,"The device: %s has been added!\n" , + device_name); +/* TODO: After finish kernel driver binding, +* begin to attach port. +*/ +break ; +default : +break ; + } +return ret; +} + static int set_tx_queue_stats_mapping_registers(portid_t port_id, struct
rte_port
*port)
{app/test-pmd/testpmd.c +14
-1@@ -2474,8 +2571,9 @@ signal_handler(int signum) int main(int argc, char** argv) { -int diag; +int diag;portid_t port_id; +int ret;signal (SIGINT , signal_handler);signal (SIGTERM , signal_handler);@@ -2543,6 +2641,18 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +if (hot_plug) { +/* enable hot plug monitoring */ + ret =rte_dev_event_monitor_start (); +if (ret) { + rte_errno =EINVAL ; +return -1 ; + } +eth_dev_event_callback_register (); + + } +if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );app/test-pmd/testpmd.h index renamed from app/test-pmd/testpmd.h +0
-0153abea..8fde68d 100644
app/test-pmd/testpmd.h +0
-0@@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packetforwarding when set to 1. */ extern
uint8_tlsc_interrupt; /**< disabled by "--no-lsc-interrupt" parameter */ externuint8_trmv_interrupt; /**< disabled by "--no-rmv-interrupt" parameter */
externuint32_tevent_print_mask;app/test-pmd/testpmd.h +2
-0+extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS doc/guides/testpmd_app_ug/run_app.rst +0
-0doc/guides/testpmd_app_ug/run_app.rst The commandline options are: · line 485
Quoted 7 lines
doc/guides/testpmd_app_ug/run_app.rst +4
-0@@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug.s/machenism/mechanism
Quoted 2 lines
--
2.7.4
Re: [PATCH V18 4/4] app/testpmd: enable device hotplug monitoring
Quoted 3 lines · Matan Azrad
Hi all
What do you think about adding the "--hotplug" parameter as a new EAL command line parameter?
that just use testpmd for example at this stage, if the total solution is accept for all and got agreement for that i think could let it in EAL command in the coming patch set.. good suggestion, azrad.
Quoted 306 lines
From: Tan, Jianfeng, Wednesday, April 4, 2018 6:23 AM
Quoted 305 lines
Quoted 11 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 4/4] app/testpmd: enable device hotplug monitoringQuoted 1 line
Use testpmd for example, to show how an application use device event
s/use/uses
Quoted 8 lines
APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c
0x3--n 4 -- -i --hot-plugthen testpmd start the device event monitor by call the new API
s/start/starts
s/call/callingQuoted 10 lines
(
rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly.This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set.
Signed-off-by Jeff Guo <[email protected]>Some typos and a trivial suggestion. Feel free to carry my
Reviewed-by Jianfeng Tan <[email protected]>in the next version.
Quoted 17 lines
---
v18->v17:
remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 112 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 121 insertions(+), 2 deletions(-)app/test-pmd/parameters.c +0
-0app/test-pmd/parameters.c usage(char* progname) · line 189
Quoted 4 lines
app/test-pmd/parameters.c +0
-0@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n"); printf(" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TXqueue
Quoted 127 lines
app/test-pmd/parameters.c +1
-0offloads\n"); + printf(" --hot-plug: enable hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINEapp/test-pmd/parameters.c +3
-1@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n"); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage(argv[0]);app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0
-04c0e258..2faeb90 100644
app/test-pmd/testpmd.c +3
-0@@ -12,6 +12,7 @@#include <sys/mman.h> #include <sys/types.h> #include <errno.h> +#include <stdbool.h> #include <sys/queue.h> #include <sys/stat.h> @@ -284,6 +285,8 @@ uint8_t lsc_interrupt = 1; /* enabled by default */*/ uint8_t rmv_interrupt =1 ;/* enabled by default */ +uint8_t hot_plug =0 ;/**< hotplug disabled by default. */ +/* * Display or mask ether events * Default to all events except VF_MBOX @@ -391,6 +394,12 @@ static void
check_all_ports_link_status(uint32_t port_mask);
static int eth_event_callback(portid_tport_id,
enumrte_eth_event_typetype, void *param, void*ret_param);app/test-pmd/testpmd.c +52
-0+static int eth_dev_event_callback (char *device_name, +enum rte_dev_event_type type, +void *param); +static int eth_dev_event_callback_register (void ); +static int eth_dev_event_callback_unregister (void ); +/* * Check if all the ports are started. @@ -1853,6 +1862,39 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_dev_event_callback_register (void ) +{ +int diag; + +/* register the device event callback */ + diag =rte_dev_event_callback_register (NULL , + eth_dev_event_callback,NULL ); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +return 0 ; +} + + +static int +eth_dev_event_callback_unregister (void ) +{ +int diag; + +/* unregister the device event callback */ + diag =rte_dev_event_callback_unregister (NULL , + eth_dev_event_callback,NULL ); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {@@ -1916,6 +1958,7 @@ voidpmd_test_exit (void) {portid_t pt_id; +int ret;if (test_done ==0 )stop_packet_forwarding ();@@ -1929,6 +1972,18 @@ pmd_test_exit(void)close_port (pt_id); } } + +if (hot_plug) { + ret =rte_dev_event_monitor_stop (); +if (ret) +RTE_LOG (ERR ,EAL , +"fail to stop device event monitor." ); + + ret =eth_dev_event_callback_unregister (); +if (ret) +RTE_LOG (ERR ,EAL , +"fail to unregister all event callbacks." ); + }printf ("\nBye...\n" ); }app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum · line 2123
Quoted 10 lines
app/test-pmd/testpmd.c +5
-0@@ -2059,6 +2114,48 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, return 0; } +/* This function is used by the interrupt thread */ static int +eth_dev_event_callback (char *device_name,enum rte_dev_event_type type, + __rte_unused void *arg) +{ +int ret =0 ;From here
Quoted 4 lines
app/test-pmd/testpmd.c +4
-0+static const char *const event_desc[] = { + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + };app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2136
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+ +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + }to here, these check are not necessary.
Quoted 76 lines
app/test-pmd/testpmd.c +22
-0+ +switch (type) { +case RTE_DEV_EVENT_REMOVE : +RTE_LOG (ERR ,EAL ,"The device: %s has been removed!\n" , + device_name); +/* TODO: After finish failure handle, begin to stop +* packet forward, stop port, close port, detach port. +*/ +break ; +case RTE_DEV_EVENT_ADD : +RTE_LOG (ERR ,EAL ,"The device: %s has been added!\n" , + device_name); +/* TODO: After finish kernel driver binding, +* begin to attach port. +*/ +break ; +default : +break ; + } +return ret; +} + static int set_tx_queue_stats_mapping_registers(portid_t port_id, struct
rte_port
*port)
{app/test-pmd/testpmd.c +14
-1@@ -2474,8 +2571,9 @@ signal_handler(int signum) int main(int argc, char** argv) { -int diag; +int diag;portid_t port_id; +int ret;signal (SIGINT , signal_handler);signal (SIGTERM , signal_handler);@@ -2543,6 +2641,18 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +if (hot_plug) { +/* enable hot plug monitoring */ + ret =rte_dev_event_monitor_start (); +if (ret) { + rte_errno =EINVAL ; +return -1 ; + } +eth_dev_event_callback_register (); + + } +if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );app/test-pmd/testpmd.h index renamed from app/test-pmd/testpmd.h +0
-0153abea..8fde68d 100644
app/test-pmd/testpmd.h +0
-0@@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packetforwarding when set to 1. */ extern
uint8_tlsc_interrupt; /**< disabled by "--no-lsc-interrupt" parameter */ externuint8_trmv_interrupt; /**< disabled by "--no-rmv-interrupt" parameter */
externuint32_tevent_print_mask;app/test-pmd/testpmd.h +2
-0+extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS doc/guides/testpmd_app_ug/run_app.rst +0
-0doc/guides/testpmd_app_ug/run_app.rst The commandline options are: · line 485
Quoted 7 lines
doc/guides/testpmd_app_ug/run_app.rst +4
-0@@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug.s/machenism/mechanism
Quoted 2 lines
--
2.7.4
Re: [PATCH V18 4/4] app/testpmd: enable device hotplug monitoring
In reply to Matan AzradQuoted 3 lines · Matan Azrad
Hi all
What do you think about adding the "--hotplug" parameter as a new EAL command line parameter?
+1
Thanks,
Jianfeng
Quoted 307 lines
From: Tan, Jianfeng, Wednesday, April 4, 2018 6:23 AM
Quoted 305 lines
Quoted 11 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 4/4] app/testpmd: enable device hotplug monitoringQuoted 1 line
Use testpmd for example, to show how an application use device event
s/use/uses
Quoted 8 lines
APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c
0x3--n 4 -- -i --hot-plugthen testpmd start the device event monitor by call the new API
s/start/starts
s/call/callingQuoted 10 lines
(
rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly.This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set.
Signed-off-by Jeff Guo <[email protected]>Some typos and a trivial suggestion. Feel free to carry my
Reviewed-by Jianfeng Tan <[email protected]>in the next version.
Quoted 17 lines
---
v18->v17:
remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 112 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 121 insertions(+), 2 deletions(-)app/test-pmd/parameters.c +0
-0app/test-pmd/parameters.c usage(char* progname) · line 189
Quoted 4 lines
app/test-pmd/parameters.c +0
-0@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n"); printf(" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TXqueue
Quoted 127 lines
app/test-pmd/parameters.c +1
-0offloads\n"); + printf(" --hot-plug: enable hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINEapp/test-pmd/parameters.c +3
-1@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n"); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage(argv[0]);app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0
-04c0e258..2faeb90 100644
app/test-pmd/testpmd.c +3
-0@@ -12,6 +12,7 @@#include <sys/mman.h> #include <sys/types.h> #include <errno.h> +#include <stdbool.h> #include <sys/queue.h> #include <sys/stat.h> @@ -284,6 +285,8 @@ uint8_t lsc_interrupt = 1; /* enabled by default */*/ uint8_t rmv_interrupt =1 ;/* enabled by default */ +uint8_t hot_plug =0 ;/**< hotplug disabled by default. */ +/* * Display or mask ether events * Default to all events except VF_MBOX @@ -391,6 +394,12 @@ static void
check_all_ports_link_status(uint32_t port_mask);
static int eth_event_callback(portid_tport_id,
enumrte_eth_event_typetype, void *param, void*ret_param);app/test-pmd/testpmd.c +52
-0+static int eth_dev_event_callback (char *device_name, +enum rte_dev_event_type type, +void *param); +static int eth_dev_event_callback_register (void ); +static int eth_dev_event_callback_unregister (void ); +/* * Check if all the ports are started. @@ -1853,6 +1862,39 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_dev_event_callback_register (void ) +{ +int diag; + +/* register the device event callback */ + diag =rte_dev_event_callback_register (NULL , + eth_dev_event_callback,NULL ); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +return 0 ; +} + + +static int +eth_dev_event_callback_unregister (void ) +{ +int diag; + +/* unregister the device event callback */ + diag =rte_dev_event_callback_unregister (NULL , + eth_dev_event_callback,NULL ); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {@@ -1916,6 +1958,7 @@ voidpmd_test_exit (void) {portid_t pt_id; +int ret;if (test_done ==0 )stop_packet_forwarding ();@@ -1929,6 +1972,18 @@ pmd_test_exit(void)close_port (pt_id); } } + +if (hot_plug) { + ret =rte_dev_event_monitor_stop (); +if (ret) +RTE_LOG (ERR ,EAL , +"fail to stop device event monitor." ); + + ret =eth_dev_event_callback_unregister (); +if (ret) +RTE_LOG (ERR ,EAL , +"fail to unregister all event callbacks." ); + }printf ("\nBye...\n" ); }app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum · line 2123
Quoted 10 lines
app/test-pmd/testpmd.c +5
-0@@ -2059,6 +2114,48 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, return 0; } +/* This function is used by the interrupt thread */ static int +eth_dev_event_callback (char *device_name,enum rte_dev_event_type type, + __rte_unused void *arg) +{ +int ret =0 ;From here
Quoted 4 lines
app/test-pmd/testpmd.c +4
-0+static const char *const event_desc[] = { + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + };app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2136
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+ +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + }to here, these check are not necessary.
Quoted 76 lines
app/test-pmd/testpmd.c +22
-0+ +switch (type) { +case RTE_DEV_EVENT_REMOVE : +RTE_LOG (ERR ,EAL ,"The device: %s has been removed!\n" , + device_name); +/* TODO: After finish failure handle, begin to stop +* packet forward, stop port, close port, detach port. +*/ +break ; +case RTE_DEV_EVENT_ADD : +RTE_LOG (ERR ,EAL ,"The device: %s has been added!\n" , + device_name); +/* TODO: After finish kernel driver binding, +* begin to attach port. +*/ +break ; +default : +break ; + } +return ret; +} + static int set_tx_queue_stats_mapping_registers(portid_t port_id, struct
rte_port
*port)
{app/test-pmd/testpmd.c +14
-1@@ -2474,8 +2571,9 @@ signal_handler(int signum) int main(int argc, char** argv) { -int diag; +int diag;portid_t port_id; +int ret;signal (SIGINT , signal_handler);signal (SIGTERM , signal_handler);@@ -2543,6 +2641,18 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +if (hot_plug) { +/* enable hot plug monitoring */ + ret =rte_dev_event_monitor_start (); +if (ret) { + rte_errno =EINVAL ; +return -1 ; + } +eth_dev_event_callback_register (); + + } +if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );app/test-pmd/testpmd.h index renamed from app/test-pmd/testpmd.h +0
-0153abea..8fde68d 100644
app/test-pmd/testpmd.h +0
-0@@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packetforwarding when set to 1. */ extern
uint8_tlsc_interrupt; /**< disabled by "--no-lsc-interrupt" parameter */ externuint8_trmv_interrupt; /**< disabled by "--no-rmv-interrupt" parameter */
externuint32_tevent_print_mask;app/test-pmd/testpmd.h +2
-0+extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS doc/guides/testpmd_app_ug/run_app.rst +0
-0doc/guides/testpmd_app_ug/run_app.rst The commandline options are: · line 485
Quoted 7 lines
doc/guides/testpmd_app_ug/run_app.rst +4
-0@@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug.s/machenism/mechanism
Quoted 2 lines
--
2.7.4
v19 cover add device event monitor framework
In reply to Jeff GuoAbout hot plug in dpdk, We already have proactive way to add/remove devices through APIs (rte_eal_hotplug_add/remove), and also have fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general mechanism to monitor hotplug event for all driver, now the hotplug interrupt event is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring like below. remove@/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 ACTION=remove DEVPATH=/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 SUBSYSTEM=uio
MAJOR=243
MINOR=2
DEVNAME=uio2
SEQNUM=11366
b.add device event monitor framework:
add several general api to enable uevent monitoring.
c.show example how to use uevent monitor
enable uevent monitoring in testpmd to show device event monitor machenism usage.
TODO: failure handler mechanism for hot plug and driver auto bind for hot insertion. that would let the next hot plug patch set to cover.
patchset history:v19->v18:
fix some typo and misunderstanding part
v18->v17:
1.add feature announcement in release document, fix bsp compile issue. 2.refine socket configuration.
3.remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.
v17->v16:
1.add related part of the interrupt handle type adding.
2.add new API into map, fix typo issue, add (void*)-1 value for unregister all callback 3.add new file into meson.build, modify coding sytle and add print info, delete unused part. 4.unregister all user's callback when stop event monitor
v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
v15->v14:
1.use exist eal interrupt epoll to replace of rte service usage for monitor thread, 2.add new device event handle type in eal interrupt.
3.remove the uevent type check and any policy from eal,
let it check and management in user's callback.
4.add "--hot-plug" configure parameter in testpmd to switch the hotplug feature.
v14->v13:
1.add __rte_experimental on function defind and fix bsd build issue
v13->v12:
1.fix some logic issue and null check issue
2.fix monitor stop func issue
v12->v11:
1.identify null param in callback for monitor all devices uevent
v11->v10:
1:modify some typo and add experimental tag in new file. 2:modify callback register calling.
v10->v9:
1.fix prefix issue.
2.use a common callback lists for all device and all type to replace add callback parameter into device struct.
3.delete some unuse part.
v9->v8:
split the patch set into small and explicit patch
v8->v7:
1.use rte_service to replace pthread management.
2.fix defind issue and copyright issue
3.fix some lock issue
v7->v6:
1.modify vdev part according to the vdev rework 2.re-define and split the func into common and bus specific code 3.fix some incorrect issue.
4.fix the system hung after send packcet issue.
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug.
2.modify to manage event callback in each device.
3.fix some system hung issue when igb_uioome typo error.release. 4.modify the pci part to the bus-pci base on the bus rework. 5.add hot plug policy in app, show example to use hotplug list to manage to deside which device need to hot plug.
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer.
2.Redefine the eal device API for common, and distinguish between linux and bsd
3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device. 5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue
7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables of hotplug_fd, add uevent_fd in rte_intr_handle to let each pci device self maintain it fd, to fix dual device fd issue.
2.refine some typo error.
Jeff Guo (4):
eal: add device event handle in interrupt thread
eal: add device event monitor framework eal/linux: uevent parse and process app/testpmd: enable device hotplug monitoring
app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 101 +++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/rel_notes/release_18_05.rst | 9 + doc/guides/testpmd_app_ug/run_app.rst | 4 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 ++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 161 ++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 ++ lib/librte_eal/common/include/rte_dev.h | 94 +++++++++ lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 214 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +- lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 10 + test/test/test_interrupts.c | 39 +++- 18 files changed, 686 insertions(+), 5 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
Signature · 1 line
2.7.4
PATCH v19 1/4 eal: add device event handle in interrupt thread
Add new interrupt handle type of RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.
---v19->v18:
fix some typo
--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++- test/test/test_interrupts.c | 39 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_eal_interrupts.h +1 -0
@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10 -1
@@ -559,6 +559,9 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -606,6 +609,9 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -674,7 +680,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
test/test/test_interrupts.c +37 -2
@@ -20,6 +20,7 @@ enum test_interrupt_handle_type {TEST_INTERRUPT_HANDLE_VALID ,TEST_INTERRUPT_HANDLE_VALID_UIO ,TEST_INTERRUPT_HANDLE_VALID_ALARM , +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ,TEST_INTERRUPT_HANDLE_CASE1 , TEST_INTERRUPT_HANDLE_MAX };
@@ -80,6 +81,10 @@ test_interrupt_init(void) intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM ].type =RTE_INTR_HANDLE_ALARM ; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].fd = pfds.readfd; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].type = +RTE_INTR_HANDLE_DEV_EVENT ; + intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].fd = pfds.writefd; intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].type =RTE_INTR_HANDLE_UIO ;
@@ -250,6 +255,14 @@ test_interrupt_enable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_enable (&test_intr_handle) ==0 ) { +printf ("unexpectedly enable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_enable (&test_intr_handle) <0 ) {
@@ -306,6 +319,14 @@ test_interrupt_disable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_disable (&test_intr_handle) ==0 ) { +printf ("unexpectedly disable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_disable (&test_intr_handle) <0 ) {
@@ -393,9 +414,17 @@ test_interrupt(void) goto out; } +printf ("Check valid device event interrupt full path\n" ); +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) { +printf ("failure occurred during checking valid device event " +"interrupt full path\n" ); + goto out; + } +printf ("Check valid alarm interrupt full path\n" ); -if (test_interrupt_full_path_check (TEST_INTERRUPT_HANDLE_VALID_ALARM ) - <0 ) { +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) {printf ("failure occurred during checking valid alarm " "interrupt full path\n" ); goto out;
@@ -513,6 +542,12 @@ test_interrupt(void)rte_intr_callback_unregister (&test_intr_handle, test_interrupt_callback_1, (void *)-1 ); + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback, (void *)-1 ); +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback_1, (void *)-1 ); +rte_delay_ms (2 *TEST_INTERRUPT_CHECK_INTERVAL );/* deinit */ test_interrupt_deinit ();
Signature · 1 line
2.7.4
PATCH v19 2/4 eal: add device event monitor framework
In reply to Jeff GuoThis patch aims to add a general device event monitor framework at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other types of device event monitor, but not in this scope at the stage.
To get started, users firstly call below new added APIs to enable/disable the device event monitor mechanism:
- rte_dev_event_monitor_start
- rte_dev_event_monitor_stop
Then users shell register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_event_callback_register -rte_dev_event_callback_unregister
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could benefit further fail-safe or live-migration.
---v19->v18:
clear the coding style and fix typo
--- doc/guides/rel_notes/release_18_05.rst | 9 ++ lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 +++++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 161 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 +++ lib/librte_eal/common/include/rte_dev.h | 94 +++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 22 +++++ lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 10 ++ 11 files changed, 336 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
doc/guides/rel_notes/release_18_05.rst +9 -0
@@ -58,6 +58,15 @@ New Features * Added support for NVGRE, VXLAN and GENEVE filters in flow API. * Added support for DROP action in flow API. +* **Added device event monitor framework.** + + Added a general device event monitor framework at EAL, for device dynamic management. + Such as device hotplug awareness and actions adopted accordingly. The list of new APIs: + + * ``rte_dev_event_monitor_start`` and ``rte_dev_event_monitor_stop`` are for + the event monitor enable and disable. + * ``rte_dev_event_callback_register`` and ``rte_dev_event_callback_unregister`` + are for the user's callbacks register and unregister. API Changes -----------
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/bsdapp/eal/meson.build +1 -0
@@ -12,4 +12,5 @@ env_sources = files('eal_alarm.c', 'eal_timer.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c' )
lib/librte_eal/common/eal_common_dev.c +161 -0
173 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +15 -0
@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). *
@@ -205,4 +207,17 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* Internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type. +* +*/ +void +dev_callback_process (char *device_name,enum rte_dev_event_type event);#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +94 -0
104 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}
lib/librte_eal/linuxapp/eal/meson.build +1 -0
@@ -18,6 +18,7 @@ env_sources = files('eal_alarm.c', 'eal_vfio_mp_sync.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c', ) if has_libnuma == 1
lib/librte_eal/rte_eal_version.map +10 -0
@@ -260,3 +260,13 @@ EXPERIMENTAL { rte_socket_id_by_idx; } DPDK_18.02; + +EXPERIMENTAL { + global: + + rte_dev_event_monitor_start; + rte_dev_event_monitor_stop; + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; + +} DPDK_18.05;
Signature · 1 line
2.7.4
Re: [PATCH V19 2/4] eal: add device event monitor framework
Quoted 15 lines · Jeff Guo
This patch aims to add a general device event monitor framework at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other types of device event monitor, but not in this scope at the stage.
To get started, users firstly call below new added APIs to enable/disable the device event monitor mechanism:
-rte_dev_event_monitor_start
-rte_dev_event_monitor_stopThen users shell register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_event_callback_register -rte_dev_event_callback_unregister
Quoted 6 lines
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could benefit further fail-safe or live-migration.
Signed-off-by Jeff Guo <[email protected]>
Except some trivial things, I'm ok with this patch, so
Quoted 107 lines
---
v19->v18:
clear the coding style and fix typo--- doc/guides/rel_notes/release_18_05.rst | 9 ++ lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 +++++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 161 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 +++ lib/librte_eal/common/include/rte_dev.h | 94 +++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 22 +++++ lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 10 ++ 11 files changed, 336 insertions(+)create mode 100644
lib/librte_eal/bsdapp/eal/eal_dev.ccreate mode 100644lib/librte_eal/linuxapp/eal/eal_dev.cdoc/guides/rel_notes/release_18_05.rst +9
-0@@ -58,6 +58,15 @@ New Features * Added support for NVGRE, VXLAN and GENEVE filters in flow API. * Added support for DROP action in flow API. +* **Added device event monitor framework.** + + Added a general device event monitor framework at EAL, for device dynamic management. + Such as device hotplug awareness and actions adopted accordingly. The list of new APIs: + + * ``rte_dev_event_monitor_start`` and ``rte_dev_event_monitor_stop`` are for + the event monitor enable and disable. + * ``rte_dev_event_callback_register`` and ``rte_dev_event_callback_unregister`` + are for the user's callbacks register and unregister. API Changes -----------lib/librte_eal/bsdapp/eal/Makefile +1
-0@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.clib/librte_eal/bsdapp/eal/eal_dev.c new file +21
-0@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}lib/librte_eal/bsdapp/eal/meson.build +1
-0@@ -12,4 +12,5 @@ env_sources = files('eal_alarm.c', 'eal_timer.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c' )lib/librte_eal/common/eal_common_dev.c +8
-0@@ -14,9 +14,34 @@#include <rte_devargs.h> #include <rte_debug.h> #include <rte_log.h> +#include <rte_spinlock.h> +#include <rte_malloc.h> #include "eal_private.h" +/** +* The device event callback description. +* +* It contains callback address to be registered by user application, +* the pointer to the parameters for callback, and the device name. +*/
lib/librte_eal/common/eal_common_dev.c line 37
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+struct dev_event_callback { +TAILQ_ENTRY (dev_event_callback) next;/**< Callbacks list */ +rte_dev_event_cb_fn cb_fn;/**< Callback address */ +void *cb_arg;/**< Callback parameter */ +char *dev_name;/**< Callback device name, NULL is for all device */ +uint32_t active;/**< Callback is executing */ +}; + +/* spinlock for device callbacks */ +static rte_spinlock_t dev_event_lock =RTE_SPINLOCK_INITIALIZER ;
It's still not in the right position; it shall be put after dev_event_callback list.
Quoted 238 lines
lib/librte_eal/common/eal_common_dev.c +143
-0+ +/* The device event callback list for all registered callbacks. */ +static struct dev_event_cb_list dev_event_cbs; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (dev_event_cb_list, dev_event_callback); +static int cmp_detached_dev_name (const struct rte_device *dev,const void *_name) {@@ -207,3 +232,139 @@ rte_eal_hotplug_remove(const char *busname, const char *devname)rte_eal_devargs_remove (busname, devname);return ret; } + +int __rte_experimental +rte_dev_event_callback_register (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg) +{ +struct dev_event_callback *event_cb; +int ret; + +if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&dev_event_lock); + +if (TAILQ_EMPTY (&dev_event_cbs)) +TAILQ_INIT (&dev_event_cbs); + + TAILQ_FOREACH(event_cb, &dev_event_cbs, next) { +if (event_cb->cb_fn == cb_fn && event_cb->cb_arg == cb_arg) { +if (device_name ==NULL && event_cb->dev_name ==NULL ) +break ; +if (device_name ==NULL || event_cb->dev_name ==NULL ) +continue ; +if (!strcmp (event_cb->dev_name, device_name)) +break ; + } + } + +/* create a new callback. */ +if (event_cb ==NULL ) { + event_cb =malloc (sizeof (struct dev_event_callback )); +if (event_cb !=NULL ) { + event_cb->cb_fn = cb_fn; + event_cb->cb_arg = cb_arg; + event_cb->active =0 ; +if (!device_name) { + event_cb->dev_name =NULL ; + }else { + event_cb->dev_name =strdup (device_name); +if (event_cb->dev_name ==NULL ) { + ret = -ENOMEM ; + goto error; + } + } +TAILQ_INSERT_TAIL (&dev_event_cbs, event_cb, next); + }else { +RTE_LOG (ERR ,EAL , +"Failed to allocate memory for device " +"event callback." ); + ret = -ENOMEM ; + goto error; + } + }else { +RTE_LOG (ERR ,EAL , +"The callback is already exist, no need " +"to register again.\n" ); + ret = -EEXIST ; + } + +rte_spinlock_unlock (&dev_event_lock); +return 0 ; +error: +free (event_cb); +rte_spinlock_unlock (&dev_event_lock); +return ret; +} + +int __rte_experimental +rte_dev_event_callback_unregister (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg) +{ +int ret =0 ; +struct dev_event_callback *event_cb, *next; + +if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&dev_event_lock); +/*walk through the callbacks and remove all that match. */ +for (event_cb =TAILQ_FIRST (&dev_event_cbs); event_cb !=NULL ; + event_cb = next) { + + next =TAILQ_NEXT (event_cb, next); + +if (device_name !=NULL && event_cb->dev_name !=NULL ) { +if (!strcmp (event_cb->dev_name, device_name)) { +if (event_cb->cb_fn != cb_fn || + (cb_arg != (void *)-1 && + event_cb->cb_arg != cb_arg)) +continue ; + } + }else if (device_name !=NULL ) { +continue ; + } + +/* +* if this callback is not executing right now, +* then remove it. +*/ +if (event_cb->active ==0 ) { +TAILQ_REMOVE (&dev_event_cbs, event_cb, next); +free (event_cb); + ret++; + }else { +continue ; + } + } +rte_spinlock_unlock (&dev_event_lock); +return ret; +} + +void +dev_callback_process (char *device_name,enum rte_dev_event_type event) +{ +struct dev_event_callback *cb_lst; + +if (device_name ==NULL ) +return ; + +rte_spinlock_lock (&dev_event_lock); + + TAILQ_FOREACH(cb_lst, &dev_event_cbs, next) { +if (cb_lst->dev_name) { +if (strcmp (cb_lst->dev_name, device_name)) +continue ; + } + cb_lst->active =1 ; +rte_spinlock_unlock (&dev_event_lock); + cb_lst->cb_fn (device_name, event, + cb_lst->cb_arg); +rte_spinlock_lock (&dev_event_lock); + cb_lst->active =0 ; + } +rte_spinlock_unlock (&dev_event_lock); +}lib/librte_eal/common/eal_private.h +15
-0@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). * @@ -205,4 +207,17 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* Internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type. +* +*/ +void +dev_callback_process (char *device_name,enum rte_dev_event_type event);#endif /* _EAL_PRIVATE_H_ */ lib/librte_eal/common/include/rte_dev.h +42
-0@@ -24,6 +24,25 @@ extern "C" {#include <rte_compat.h> #include <rte_log.h> +/** +* The device event type. +*/ +enum rte_dev_event_type { +RTE_DEV_EVENT_ADD ,/**< device being added */ +RTE_DEV_EVENT_REMOVE ,/**< device being removed */ +RTE_DEV_EVENT_MAX /**< max value of this enum */ +}; + +struct rte_dev_event { +enum rte_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +}; + +typedef void (*rte_dev_event_cb_fn )(char *device_name, +enum rte_dev_event_type event, +void *cb_arg); + __attribute__((format (printf,2 ,0 )))static inline void rte_pmd_debug_trace (const char *func_name,const char *fmt, ...)@@ -267,4 +286,79 @@ __attribute__((used)) = str }#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It registers the callback for the specific device. +* Multiple callbacks cal be registered at the same time. +* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_callback_register (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg);
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 321
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h +10
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It unregisters the callback according to the specified device. +* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices.
Do you mean all callbacks?
Quoted 101 lines
lib/librte_eal/common/include/rte_dev.h +42
-0+* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback, (void *)-1 means to remove all +* registered which has the same callback address. +* +* @return +* - On success, return the number of callback entities removed. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_callback_unregister (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Start the device event monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_start (void); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Stop the device event monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_stop (void);#endif /* _RTE_DEV_H_ */ lib/librte_eal/linuxapp/eal/Makefile +1
-0@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.clib/librte_eal/linuxapp/eal/eal_dev.c new file +22
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}lib/librte_eal/linuxapp/eal/meson.build +1
-0@@ -18,6 +18,7 @@ env_sources = files('eal_alarm.c', 'eal_vfio_mp_sync.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c', ) if has_libnuma == 1lib/librte_eal/rte_eal_version.map +0
-0@@ -260,3 +260,13 @@ EXPERIMENTAL { rte_socket_id_by_idx;
lib/librte_eal/rte_eal_version.map EXPERIMENTAL { · line 270
Quoted 10 lines
lib/librte_eal/rte_eal_version.map +8
-0} DPDK_18.02; + +EXPERIMENTAL { + global: + + rte_dev_event_monitor_start; + rte_dev_event_monitor_stop; + rte_dev_event_callback_register; + rte_dev_event_callback_unregister;
Use tab instead of spaces.
Quoted 2 lines
lib/librte_eal/rte_eal_version.map +2
-0+ +} DPDK_18.05;
PATCH v19 3/4 eal/linux: uevent parse and process
In reply to Jeff GuoIn order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
---
v19->18:
fix some misunderstanding part
--- lib/librte_eal/linuxapp/eal/eal_dev.c | 196 +++++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 2 deletions(-)
lib/librte_eal/linuxapp/eal/eal_dev.c +194 -2
@@ -2,21 +2,213 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> + +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which reports this event. */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ; + } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind uevent socket.\n" ); + goto err; + } + +return 0 ; +err: +close (intr_handle.fd); + intr_handle.fd =-1 ; +return ret; +} + +static int +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 , ret =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +/** +* check device uevent from kernel side, no need to check +* uevent from udev. +*/ +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; +return -1 ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +/* parse the subsystem layer */ +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +else + ret =-1 ; +/* parse the action type */ +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +else if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +else + ret =-1 ; +return ret; +} + +static void +dev_uev_handler(__rte_unused void *param) +{ +struct rte_dev_event uevent; +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (&uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (intr_handle.fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret ==0 || (ret <0 && errno !=EAGAIN )) { +/* connection is closed or broken, can not up again. */ +RTE_LOG (ERR ,EAL ,"uevent socket connection is broken.\n" ); +return ; + }else if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"uevent socket read error(%d): %s.\n" , + errno,strerror (errno)); +return ; + } + + ret =dev_uev_parse (buf, &uevent,EAL_UEV_MSG_LEN ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"It is not an valid event " +"that need to be handle.\n" ); +return ; + } + +RTE_LOG (DEBUG ,EAL ,"receive uevent(name:%s, type:%d, subsystem:%d)\n" , + uevent.devname, uevent.type, uevent.subsystem); + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_handler,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_handler, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; }
Signature · 1 line
2.7.4
PATCH v19 4/4 app/testpmd: enable device hotplug monitoring
In reply to Jeff GuoUse testpmd for example, to show how an application uses device event APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c 0x3 --n 4 -- -i --hot-plug
then testpmd starts the device event monitor by calling the new API (rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly.
This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set.
---v19->v18:
fix some typo
--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 101 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 110 insertions(+), 2 deletions(-)
app/test-pmd/parameters.c +4 -1
@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enable hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE
@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };
@@ -1101,7 +1103,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);
app/test-pmd/testpmd.c +100 -1
156 lines not on this page · raw message
app/test-pmd/testpmd.h +2 -0
@@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
doc/guides/testpmd_app_ug/run_app.rst +4 -0
@@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug.
Signature · 1 line
2.7.4
v19 cover add device event monitor framework
In reply to Jeff GuoAbout hot plug in dpdk, We already have proactive way to add/remove devices through APIs (rte_eal_hotplug_add/remove), and also have fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general mechanism to monitor hotplug event for all driver, now the hotplug interrupt event is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring like below. remove@/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 ACTION=remove DEVPATH=/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 SUBSYSTEM=uio
MAJOR=243
MINOR=2
DEVNAME=uio2
SEQNUM=11366
b.add device event monitor framework:
add several general api to enable uevent monitoring.
c.show example how to use uevent monitor
enable uevent monitoring in testpmd to show device event monitor machenism usage.
TODO: failure handler mechanism for hot plug and driver auto bind for hot insertion. that would let the next hot plug patch set to cover.
patchset history:v19->v18:
fix some typo and misunderstanding part
v18->v17:
1.add feature announcement in release document, fix bsp compile issue. 2.refine socket configuration.
3.remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.
v17->v16:
1.add related part of the interrupt handle type adding.
2.add new API into map, fix typo issue, add (void*)-1 value for unregister all callback 3.add new file into meson.build, modify coding sytle and add print info, delete unused part. 4.unregister all user's callback when stop event monitor
v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
v15->v14:
1.use exist eal interrupt epoll to replace of rte service usage for monitor thread, 2.add new device event handle type in eal interrupt.
3.remove the uevent type check and any policy from eal,
let it check and management in user's callback.
4.add "--hot-plug" configure parameter in testpmd to switch the hotplug feature.
v14->v13:
1.add __rte_experimental on function defind and fix bsd build issue
v13->v12:
1.fix some logic issue and null check issue
2.fix monitor stop func issue
v12->v11:
1.identify null param in callback for monitor all devices uevent
v11->v10:
1:modify some typo and add experimental tag in new file. 2:modify callback register calling.
v10->v9:
1.fix prefix issue.
2.use a common callback lists for all device and all type to replace add callback parameter into device struct.
3.delete some unuse part.
v9->v8:
split the patch set into small and explicit patch
v8->v7:
1.use rte_service to replace pthread management.
2.fix defind issue and copyright issue
3.fix some lock issue
v7->v6:
1.modify vdev part according to the vdev rework 2.re-define and split the func into common and bus specific code 3.fix some incorrect issue.
4.fix the system hung after send packcet issue.
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug.
2.modify to manage event callback in each device.
3.fix some system hung issue when igb_uioome typo error.release. 4.modify the pci part to the bus-pci base on the bus rework. 5.add hot plug policy in app, show example to use hotplug list to manage to deside which device need to hot plug.
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer.
2.Redefine the eal device API for common, and distinguish between linux and bsd
3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device. 5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue
7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables of hotplug_fd, add uevent_fd in rte_intr_handle to let each pci device self maintain it fd, to fix dual device fd issue.
2.refine some typo error.
Jeff Guo (4):
eal: add device event handle in interrupt thread
eal: add device event monitor framework eal/linux: uevent parse and process app/testpmd: enable device hotplug monitoring
app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 101 +++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/rel_notes/release_18_05.rst | 9 + doc/guides/testpmd_app_ug/run_app.rst | 4 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 ++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 161 ++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 ++ lib/librte_eal/common/include/rte_dev.h | 94 +++++++++ lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 214 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +- lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 10 + test/test/test_interrupts.c | 39 +++- 18 files changed, 686 insertions(+), 5 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
Signature · 1 line
2.7.4
PATCH v19 1/4 eal: add device event handle in interrupt thread
Add new interrupt handle type of RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.
---v19->v18:
fix some typo
--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++- test/test/test_interrupts.c | 39 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_eal_interrupts.h +1 -0
@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10 -1
@@ -559,6 +559,9 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -606,6 +609,9 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -674,7 +680,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
test/test/test_interrupts.c +37 -2
@@ -20,6 +20,7 @@ enum test_interrupt_handle_type {TEST_INTERRUPT_HANDLE_VALID ,TEST_INTERRUPT_HANDLE_VALID_UIO ,TEST_INTERRUPT_HANDLE_VALID_ALARM , +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ,TEST_INTERRUPT_HANDLE_CASE1 , TEST_INTERRUPT_HANDLE_MAX };
@@ -80,6 +81,10 @@ test_interrupt_init(void) intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM ].type =RTE_INTR_HANDLE_ALARM ; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].fd = pfds.readfd; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].type = +RTE_INTR_HANDLE_DEV_EVENT ; + intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].fd = pfds.writefd; intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].type =RTE_INTR_HANDLE_UIO ;
@@ -250,6 +255,14 @@ test_interrupt_enable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_enable (&test_intr_handle) ==0 ) { +printf ("unexpectedly enable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_enable (&test_intr_handle) <0 ) {
@@ -306,6 +319,14 @@ test_interrupt_disable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_disable (&test_intr_handle) ==0 ) { +printf ("unexpectedly disable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_disable (&test_intr_handle) <0 ) {
@@ -393,9 +414,17 @@ test_interrupt(void) goto out; } +printf ("Check valid device event interrupt full path\n" ); +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) { +printf ("failure occurred during checking valid device event " +"interrupt full path\n" ); + goto out; + } +printf ("Check valid alarm interrupt full path\n" ); -if (test_interrupt_full_path_check (TEST_INTERRUPT_HANDLE_VALID_ALARM ) - <0 ) { +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) {printf ("failure occurred during checking valid alarm " "interrupt full path\n" ); goto out;
@@ -513,6 +542,12 @@ test_interrupt(void)rte_intr_callback_unregister (&test_intr_handle, test_interrupt_callback_1, (void *)-1 ); + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback, (void *)-1 ); +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback_1, (void *)-1 ); +rte_delay_ms (2 *TEST_INTERRUPT_CHECK_INTERVAL );/* deinit */ test_interrupt_deinit ();
Signature · 1 line
2.7.4
PATCH v19 2/4 eal: add device event monitor framework
In reply to Jeff GuoThis patch aims to add a general device event monitor framework at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other types of device event monitor, but not in this scope at the stage.
To get started, users firstly call below new added APIs to enable/disable the device event monitor mechanism:
- rte_dev_event_monitor_start
- rte_dev_event_monitor_stop
Then users shell register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_event_callback_register -rte_dev_event_callback_unregister
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could benefit further fail-safe or live-migration.
---v19->v18:
clear the coding style and fix typo
--- doc/guides/rel_notes/release_18_05.rst | 9 ++ lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 +++++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 161 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 +++ lib/librte_eal/common/include/rte_dev.h | 94 +++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 22 +++++ lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 10 ++ 11 files changed, 336 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
doc/guides/rel_notes/release_18_05.rst +9 -0
@@ -58,6 +58,15 @@ New Features * Added support for NVGRE, VXLAN and GENEVE filters in flow API. * Added support for DROP action in flow API. +* **Added device event monitor framework.** + + Added a general device event monitor framework at EAL, for device dynamic management. + Such as device hotplug awareness and actions adopted accordingly. The list of new APIs: + + * ``rte_dev_event_monitor_start`` and ``rte_dev_event_monitor_stop`` are for + the event monitor enable and disable. + * ``rte_dev_event_callback_register`` and ``rte_dev_event_callback_unregister`` + are for the user's callbacks register and unregister. API Changes -----------
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/bsdapp/eal/meson.build +1 -0
@@ -12,4 +12,5 @@ env_sources = files('eal_alarm.c', 'eal_timer.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c' )
lib/librte_eal/common/eal_common_dev.c +161 -0
173 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +15 -0
@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). *
@@ -205,4 +207,17 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* Internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type. +* +*/ +void +dev_callback_process (char *device_name,enum rte_dev_event_type event);#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +94 -0
104 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}
lib/librte_eal/linuxapp/eal/meson.build +1 -0
@@ -18,6 +18,7 @@ env_sources = files('eal_alarm.c', 'eal_vfio_mp_sync.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c', ) if has_libnuma == 1
lib/librte_eal/rte_eal_version.map +10 -0
@@ -260,3 +260,13 @@ EXPERIMENTAL { rte_socket_id_by_idx; } DPDK_18.02; + +EXPERIMENTAL { + global: + + rte_dev_event_monitor_start; + rte_dev_event_monitor_stop; + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; + +} DPDK_18.05;
Signature · 1 line
2.7.4
PATCH v19 3/4 eal/linux: uevent parse and process
In reply to Jeff GuoIn order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
---
v19->18:
fix some misunderstanding part
--- lib/librte_eal/linuxapp/eal/eal_dev.c | 196 +++++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 2 deletions(-)
lib/librte_eal/linuxapp/eal/eal_dev.c +194 -2
@@ -2,21 +2,213 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> + +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which reports this event. */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ; + } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind uevent socket.\n" ); + goto err; + } + +return 0 ; +err: +close (intr_handle.fd); + intr_handle.fd =-1 ; +return ret; +} + +static int +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 , ret =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +/** +* check device uevent from kernel side, no need to check +* uevent from udev. +*/ +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; +return -1 ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +/* parse the subsystem layer */ +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +else + ret =-1 ; +/* parse the action type */ +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +else if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +else + ret =-1 ; +return ret; +} + +static void +dev_uev_handler(__rte_unused void *param) +{ +struct rte_dev_event uevent; +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (&uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (intr_handle.fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret ==0 || (ret <0 && errno !=EAGAIN )) { +/* connection is closed or broken, can not up again. */ +RTE_LOG (ERR ,EAL ,"uevent socket connection is broken.\n" ); +return ; + }else if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"uevent socket read error(%d): %s.\n" , + errno,strerror (errno)); +return ; + } + + ret =dev_uev_parse (buf, &uevent,EAL_UEV_MSG_LEN ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"It is not an valid event " +"that need to be handle.\n" ); +return ; + } + +RTE_LOG (DEBUG ,EAL ,"receive uevent(name:%s, type:%d, subsystem:%d)\n" , + uevent.devname, uevent.type, uevent.subsystem); + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_handler,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_handler, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; }
Signature · 1 line
2.7.4
Re: [PATCH V19 3/4] eal/linux: uevent parse and process
Quoted 126 lines · Jeff Guo
In order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
Signed-off-by Jeff Guo <[email protected]>---
v19->18:
fix some misunderstanding part--- lib/librte_eal/linuxapp/eal/eal_dev.c | 196 +++++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 2 deletions(-)lib/librte_eal/linuxapp/eal/eal_dev.c +103
-0@@ -2,21 +2,213 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> + +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which reports this event. */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ; + } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind uevent socket.\n" ); + goto err; + } + +return 0 ; +err: +close (intr_handle.fd); + intr_handle.fd =-1 ; +return ret; +} + +static int +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 , ret =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +/** +* check device uevent from kernel side, no need to check +* uevent from udev. +*/ +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; +return -1 ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + }
lib/librte_eal/linuxapp/eal/eal_dev.c line 120
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ +/* parse the subsystem layer */ +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +else + ret =-1 ;
We can just return -1 here.
lib/librte_eal/linuxapp/eal/eal_dev.c line 128
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +7
-0+/* parse the action type */ +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +else if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +else + ret =-1 ;
We can just return -1 here.
lib/librte_eal/linuxapp/eal/eal_dev.c line 128
Quoted 1 line
lib/librte_eal/linuxapp/eal/eal_dev.c +1
-0+return ret;
return 0 here.
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+} + +static void +dev_uev_handler(__rte_unused void *param) +{ +struct rte_dev_event uevent;
lib/librte_eal/linuxapp/eal/eal_dev.c line 145
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (&uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (intr_handle.fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret ==0 || (ret <0 && errno !=EAGAIN )) { +/* connection is closed or broken, can not up again. */ +RTE_LOG (ERR ,EAL ,"uevent socket connection is broken.\n" );
Again, we need an alarm to unregister the callback from intr thread.
lib/librte_eal/linuxapp/eal/eal_dev.c line 152
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +7
-0+return ; + }else if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"uevent socket read error(%d): %s.\n" , + errno,strerror (errno)); +return ; + }
I think the above code can be adjusted as:
if (ret == 0 || (ret < 0 && errno == EAGAIN))
return;
else if (ret < 0) {
RTE_LOG(ERR, EAL, "...");
set_alarm_to_unregister();
}lib/librte_eal/linuxapp/eal/eal_dev.c line 156
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +4
-0+ + ret =dev_uev_parse (buf, &uevent,EAL_UEV_MSG_LEN ); +if (ret <0 ) { + RTE_LOG(ERR, EAL, "It is not an valid event "
s/ERR/DEBUG, or there are too many logs.
Quoted 60 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +46
-2+ "that need to be handle.\n"); +return ; + } + +RTE_LOG (DEBUG ,EAL ,"receive uevent(name:%s, type:%d, subsystem:%d)\n" , + uevent.devname, uevent.type, uevent.subsystem); + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_handler,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_handler, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; }
Re: [PATCH V19 3/4] eal/linux: uevent parse and process
Quoted 167 lines · Jianfeng
Quoted 127 lines · Jeff Guo
In order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
Signed-off-by Jeff Guo <[email protected]>---
v19->18:
fix some misunderstanding part--- lib/librte_eal/linuxapp/eal/eal_dev.c | 196 +++++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 2 deletions(-)lib/librte_eal/linuxapp/eal/eal_dev.c +102
-0@@ -2,21 +2,213 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> + +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which reports this event. */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ; + } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind uevent socket.\n" ); + goto err; + } + +return 0 ; +err: +close (intr_handle.fd); + intr_handle.fd =-1 ; +return ret; +} + +static int +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 , ret =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +/** +* check device uevent from kernel side, no need to check +* uevent from udev. +*/ +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; +return -1 ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + }lib/librte_eal/linuxapp/eal/eal_dev.c line 120
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ +/* parse the subsystem layer */ +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +else + ret =-1 ;We can just return -1 here.
lib/librte_eal/linuxapp/eal/eal_dev.c line 128
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+/* parse the action type */ + if (!strncmp(action, "add", 3)) + event->type = RTE_DEV_EVENT_ADD; + else if (!strncmp(action, "remove", 6)) + event->type =RTE_DEV_EVENT_REMOVE ; + else + ret =-1 ;We can just return -1 here.
lib/librte_eal/linuxapp/eal/eal_dev.c line 128
Quoted 1 line
lib/librte_eal/linuxapp/eal/eal_dev.c +1
-0+return ret;return 0 here.
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+} + +static void +dev_uev_handler(__rte_unused void *param) +{ +struct rte_dev_event uevent; +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (&uevent,0 ,sizeof (struct rte_dev_event ));
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 145
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (intr_handle.fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret ==0 || (ret <0 && errno !=EAGAIN )) { +/* connection is closed or broken, can not up again. */ +RTE_LOG (ERR ,EAL ,"uevent socket connection is broken.\n" );Again, we need an alarm to unregister the callback from intr thread.
ok.
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 152
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +7
-0+return ; + }else if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"uevent socket read error(%d): %s.\n" , + errno,strerror (errno)); +return ; + }
Quoted 10 lines
I think the above code can be adjusted as:
if (ret == 0 || (ret < 0 && errno == EAGAIN)) return; else if (ret < 0) { RTE_LOG(ERR, EAL, "..."); set_alarm_to_unregister(); }
will check the best coding style.
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 156
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +4
-0+ + ret =dev_uev_parse (buf, &uevent,EAL_UEV_MSG_LEN ); +if (ret <0 ) { + RTE_LOG(ERR, EAL, "It is not an valid event "s/ERR/DEBUG, or there are too many logs.
make sense.
Quoted 61 lines
Quoted 60 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +46
-2+ "that need to be handle.\n"); +return ; + } + +RTE_LOG (DEBUG ,EAL ,"receive uevent(name:%s, type:%d, subsystem:%d)\n", + uevent.devname, uevent.type, uevent.subsystem); + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_handler,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_handler, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; }
PATCH v19 4/4 app/testpmd: enable device hotplug monitoring
In reply to Jeff GuoUse testpmd for example, to show how an application uses device event APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c 0x3 --n 4 -- -i --hot-plug
then testpmd starts the device event monitor by calling the new API (rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly.
This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set.
---v19->v18:
fix some typo
--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 101 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 110 insertions(+), 2 deletions(-)
app/test-pmd/parameters.c +4 -1
@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enable hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE
@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };
@@ -1101,7 +1103,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);
app/test-pmd/testpmd.c +100 -1
156 lines not on this page · raw message
app/test-pmd/testpmd.h +2 -0
@@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
doc/guides/testpmd_app_ug/run_app.rst +4 -0
@@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug.
Signature · 1 line
2.7.4
v20 cover add device event monitor framework
About hot plug in dpdk, We already have proactive way to add/remove devices through APIs (rte_eal_hotplug_add/remove), and also have fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general mechanism to monitor hotplug event for all driver, now the hotplug interrupt event is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring like below. remove@/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 ACTION=remove DEVPATH=/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 SUBSYSTEM=uio
MAJOR=243
MINOR=2
DEVNAME=uio2
SEQNUM=11366
b.add device event monitor framework:
add several general api to enable uevent monitoring.
c.show example how to use uevent monitor
enable uevent monitoring in testpmd to show device event monitor machenism usage.
TODO: failure handler mechanism for hot plug and driver auto bind for hot insertion. that would let the next hot plug patch set to cover.
patchset history:v20->v19:
add more detail note and socket error handler.
v19->18:
fix some typo and misunderstanding part
v18->v17:
1.add feature announcement in release document, fix bsp compile issue. 2.refine socket configuration.
3.remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.
v17->v16:
1.add related part of the interrupt handle type adding.
2.add new API into map, fix typo issue, add (void*)-1 value for unregister all callback 3.add new file into meson.build, modify coding sytle and add print info, delete unused part. 4.unregister all user's callback when stop event monitor
v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
v15->v14:
1.use exist eal interrupt epoll to replace of rte service usage for monitor thread, 2.add new device event handle type in eal interrupt.
3.remove the uevent type check and any policy from eal,
let it check and management in user's callback.
4.add "--hot-plug" configure parameter in testpmd to switch the hotplug feature.
v14->v13:
1.add __rte_experimental on function defind and fix bsd build issue
v13->v12:
1.fix some logic issue and null check issue
2.fix monitor stop func issue
v12->v11:
1.identify null param in callback for monitor all devices uevent
v11->v10:
1:modify some typo and add experimental tag in new file. 2:modify callback register calling.
v10->v9:
1.fix prefix issue.
2.use a common callback lists for all device and all type to replace add callback parameter into device struct.
3.delete some unuse part.
v9->v8:
split the patch set into small and explicit patch
v8->v7:
1.use rte_service to replace pthread management.
2.fix defind issue and copyright issue
3.fix some lock issue
v7->v6:
1.modify vdev part according to the vdev rework 2.re-define and split the func into common and bus specific code 3.fix some incorrect issue.
4.fix the system hung after send packcet issue.
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug.
2.modify to manage event callback in each device.
3.fix some system hung issue when igb_uioome typo error.release. 4.modify the pci part to the bus-pci base on the bus rework. 5.add hot plug policy in app, show example to use hotplug list to manage to deside which device need to hot plug.
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer.
2.Redefine the eal device API for common, and distinguish between linux and bsd
3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device. 5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue
7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables of hotplug_fd, add uevent_fd in rte_intr_handle to let each pci device self maintain it fd, to fix dual device fd issue.
2.refine some typo error.
Jeff Guo (4):
eal: add device event handle in interrupt thread
eal: add device event monitor framework eal/linux: uevent parse and process app/testpmd: enable device hotplug monitoring
app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 101 +++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/rel_notes/release_18_05.rst | 9 + doc/guides/testpmd_app_ug/run_app.rst | 4 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 ++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 161 +++++++++++++++ lib/librte_eal/common/eal_private.h | 15 ++ lib/librte_eal/common/include/rte_dev.h | 94 +++++++++ lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 224 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +- lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 10 + test/test/test_interrupts.c | 39 +++- 18 files changed, 696 insertions(+), 5 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
Signature · 1 line
2.7.4
PATCH v20 1/4 eal: add device event handle in interrupt thread
Add new interrupt handle type of RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.
---
v20->19:
no change
--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++- test/test/test_interrupts.c | 39 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_eal_interrupts.h +1 -0
@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10 -1
@@ -559,6 +559,9 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -606,6 +609,9 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -674,7 +680,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
test/test/test_interrupts.c +37 -2
@@ -20,6 +20,7 @@ enum test_interrupt_handle_type {TEST_INTERRUPT_HANDLE_VALID ,TEST_INTERRUPT_HANDLE_VALID_UIO ,TEST_INTERRUPT_HANDLE_VALID_ALARM , +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ,TEST_INTERRUPT_HANDLE_CASE1 , TEST_INTERRUPT_HANDLE_MAX };
@@ -80,6 +81,10 @@ test_interrupt_init(void) intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM ].type =RTE_INTR_HANDLE_ALARM ; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].fd = pfds.readfd; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].type = +RTE_INTR_HANDLE_DEV_EVENT ; + intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].fd = pfds.writefd; intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].type =RTE_INTR_HANDLE_UIO ;
@@ -250,6 +255,14 @@ test_interrupt_enable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_enable (&test_intr_handle) ==0 ) { +printf ("unexpectedly enable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_enable (&test_intr_handle) <0 ) {
@@ -306,6 +319,14 @@ test_interrupt_disable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_disable (&test_intr_handle) ==0 ) { +printf ("unexpectedly disable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_disable (&test_intr_handle) <0 ) {
@@ -393,9 +414,17 @@ test_interrupt(void) goto out; } +printf ("Check valid device event interrupt full path\n" ); +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) { +printf ("failure occurred during checking valid device event " +"interrupt full path\n" ); + goto out; + } +printf ("Check valid alarm interrupt full path\n" ); -if (test_interrupt_full_path_check (TEST_INTERRUPT_HANDLE_VALID_ALARM ) - <0 ) { +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) {printf ("failure occurred during checking valid alarm " "interrupt full path\n" ); goto out;
@@ -513,6 +542,12 @@ test_interrupt(void)rte_intr_callback_unregister (&test_intr_handle, test_interrupt_callback_1, (void *)-1 ); + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback, (void *)-1 ); +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback_1, (void *)-1 ); +rte_delay_ms (2 *TEST_INTERRUPT_CHECK_INTERVAL );/* deinit */ test_interrupt_deinit ();
Signature · 1 line
2.7.4
PATCH v20 2/4 eal: add device event monitor framework
In reply to Jeff GuoThis patch aims to add a general device event monitor framework at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other types of device event monitor, but not in this scope at the stage.
To get started, users firstly call below new added APIs to enable/disable the device event monitor mechanism:
- rte_dev_event_monitor_start
- rte_dev_event_monitor_stop
Then users shell register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_event_callback_register -rte_dev_event_callback_unregister
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could benefit further fail-safe or live-migration.
---v20->v19:
add more detail note for callback unregister.
--- doc/guides/rel_notes/release_18_05.rst | 9 ++ lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 +++++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 161 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 +++ lib/librte_eal/common/include/rte_dev.h | 94 +++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 22 +++++ lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 10 ++ 11 files changed, 336 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
doc/guides/rel_notes/release_18_05.rst +9 -0
@@ -58,6 +58,15 @@ New Features * Added support for NVGRE, VXLAN and GENEVE filters in flow API. * Added support for DROP action in flow API. +* **Added device event monitor framework.** + + Added a general device event monitor framework at EAL, for device dynamic management. + Such as device hotplug awareness and actions adopted accordingly. The list of new APIs: + + * ``rte_dev_event_monitor_start`` and ``rte_dev_event_monitor_stop`` are for + the event monitor enable and disable. + * ``rte_dev_event_callback_register`` and ``rte_dev_event_callback_unregister`` + are for the user's callbacks register and unregister. API Changes -----------
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/bsdapp/eal/meson.build +1 -0
@@ -12,4 +12,5 @@ env_sources = files('eal_alarm.c', 'eal_timer.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c' )
lib/librte_eal/common/eal_common_dev.c +161 -0
173 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +15 -0
@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). *
@@ -205,4 +207,17 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* Internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type. +* +*/ +void +dev_callback_process (char *device_name,enum rte_dev_event_type event);#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +94 -0
104 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}
lib/librte_eal/linuxapp/eal/meson.build +1 -0
@@ -18,6 +18,7 @@ env_sources = files('eal_alarm.c', 'eal_vfio_mp_sync.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c', ) if has_libnuma == 1
lib/librte_eal/rte_eal_version.map +10 -0
@@ -260,3 +260,13 @@ EXPERIMENTAL { rte_socket_id_by_idx; } DPDK_18.02; + +EXPERIMENTAL { + global: + + rte_dev_event_monitor_start; + rte_dev_event_monitor_stop; + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; + +} DPDK_18.05;
Signature · 1 line
2.7.4
Re: [PATCH V20 2/4] eal: add device event monitor framework
05/04/2018 18:10, Jeff Guo:
Quoted 6 lines
lib/librte_eal/rte_eal_version.map +0
-0@@ -260,3 +260,13 @@ EXPERIMENTAL { rte_socket_id_by_idx; } DPDK_18.02;
lib/librte_eal/rte_eal_version.map EXPERIMENTAL { · line 272
Quoted 10 lines
lib/librte_eal/rte_eal_version.map +10
-0+ +EXPERIMENTAL { + global: + + rte_dev_event_monitor_start; + rte_dev_event_monitor_stop; + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; + +} DPDK_18.05;
These functions should go in the already existing EXPERIMENTAL block above.
Re: [PATCH V20 2/4] eal: add device event monitor framework
Quoted 6 lines · Thomas Monjalon
05/04/2018 18:10, Jeff Guo:
Quoted 5 lines
lib/librte_eal/rte_eal_version.map +0
-0@@ -260,3 +260,13 @@ EXPERIMENTAL { rte_socket_id_by_idx;
Quoted 13 lines
lib/librte_eal/rte_eal_version.map EXPERIMENTAL { · line 272
Quoted 11 lines
lib/librte_eal/rte_eal_version.map +10
-0} DPDK_18.02; + +EXPERIMENTAL { + global: + + rte_dev_event_monitor_start; + rte_dev_event_monitor_stop; + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; + +} DPDK_18.05;These functions should go in the already existing EXPERIMENTAL block above.
ok.
Quoted 1 line
PATCH v20 3/4 eal/linux: uevent parse and process
In reply to Jeff GuoIn order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
---v20->v19:
add socket error handler
--- lib/librte_eal/linuxapp/eal/eal_dev.c | 206 +++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 2 deletions(-)
lib/librte_eal/linuxapp/eal/eal_dev.c +204 -2
@@ -2,21 +2,223 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> +#include <rte_alarm.h> + +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +static void dev_uev_handler(__rte_unused void *param); + +/* identify the system layer which reports this event. */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ; + } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind uevent socket.\n" ); + goto err; + } +return 0 ; +err: +close (intr_handle.fd); + intr_handle.fd =-1 ; +return ret; +} + +static int +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +/** +* check device uevent from kernel side, no need to check +* uevent from udev. +*/ +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; +return -1 ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +/* parse the subsystem layer */ +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +else +return -1 ; + +/* parse the action type */ +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +else if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +else +return -1 ; +return 0 ; +} + +static void +dev_delayed_unregister (void *param) +{ +rte_intr_callback_unregister (&intr_handle, dev_uev_handler, param); +} + +static void +dev_uev_handler(__rte_unused void *param) +{ +struct rte_dev_event uevent; +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (&uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (intr_handle.fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret ==0 || (ret <0 && errno !=EAGAIN )) { +/* connection is closed or broken, can not up again. */ +RTE_LOG (ERR ,EAL ,"uevent socket connection is broken.\n" ); +rte_eal_alarm_set (1 , dev_delayed_unregister,NULL ); +return ; + }else if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"uevent socket read error(%d): %s.\n" , + errno,strerror (errno)); +return ; + } + + ret =dev_uev_parse (buf, &uevent,EAL_UEV_MSG_LEN ); +if (ret <0 ) { +RTE_LOG (DEBUG ,EAL ,"It is not an valid event " +"that need to be handle.\n" ); +return ; + } + +RTE_LOG (DEBUG ,EAL ,"receive uevent(name:%s, type:%d, subsystem:%d)\n" , + uevent.devname, uevent.type, uevent.subsystem); + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_handler,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_handler, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; }
Signature · 1 line
2.7.4
Re: [PATCH V20 3/4] eal/linux: uevent parse and process
Quoted 5 lines · Jeff Guo
In order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
Signed-off-by Jeff Guo <[email protected]>
Other than two nits below,
Quoted 139 lines
---
v20->v19:
add socket error handler--- lib/librte_eal/linuxapp/eal/eal_dev.c | 206 +++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 2 deletions(-)lib/librte_eal/linuxapp/eal/eal_dev.c +120
-0@@ -2,21 +2,223 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> +#include <rte_alarm.h> + +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +static void dev_uev_handler(__rte_unused void *param); + +/* identify the system layer which reports this event. */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ; + } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind uevent socket.\n" ); + goto err; + } +return 0 ; +err: +close (intr_handle.fd); + intr_handle.fd =-1 ; +return ret; +} + +static int +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +/** +* check device uevent from kernel side, no need to check +* uevent from udev. +*/ +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; +return -1 ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +/* parse the subsystem layer */ +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +else +return -1 ; + +/* parse the action type */ +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +else if (!strncmp (action,"remove" ,6 ))
lib/librte_eal/linuxapp/eal/eal_dev.c line 138
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ event->type =RTE_DEV_EVENT_REMOVE ; + else + return -1; +return 0 ; +} + +static void +dev_delayed_unregister (void *param) +{ +rte_intr_callback_unregister (&intr_handle, dev_uev_handler, param);
You might also want to:
+ close(intr_handle.fd);
+ intr_handle.fd = -1;
Quoted 14 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +14
-0+} + +static void +dev_uev_handler(__rte_unused void *param) +{ +struct rte_dev_event uevent; +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (&uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (intr_handle.fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret ==0 || (ret <0 && errno !=EAGAIN )) {
lib/librte_eal/linuxapp/eal/eal_dev.c line 162
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+/* connection is closed or broken, can not up again. */ +RTE_LOG (ERR ,EAL ,"uevent socket connection is broken.\n" ); +rte_eal_alarm_set (1 , dev_delayed_unregister,NULL ); +return ; + }else if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"uevent socket read error(%d): %s.\n" , + errno,strerror (errno)); +return ; + }
Above error handle can be rewritten a little bit:
+ if (ret < 0 && errno == EAGAIN)
+ return;
+ else if (ret <= 0) {
+ /* connection is closed or broken, can not up again. */
+ RTE_LOG(ERR, EAL, "uevent socket connection is broken.\n");
+ rte_eal_alarm_set(1, dev_delayed_unregister, NULL);
+ return;
+ }
Quoted 64 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +50
-2+ + ret =dev_uev_parse (buf, &uevent,EAL_UEV_MSG_LEN ); +if (ret <0 ) { +RTE_LOG (DEBUG ,EAL ,"It is not an valid event " +"that need to be handle.\n" ); +return ; + } + +RTE_LOG (DEBUG ,EAL ,"receive uevent(name:%s, type:%d, subsystem:%d)\n" , + uevent.devname, uevent.type, uevent.subsystem); + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_handler,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_handler, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; }
Re: [PATCH V20 3/4] eal/linux: uevent parse and process
thanks.
Quoted 270 lines · Jianfeng
Quoted 5 lines · Jeff Guo
In order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
Signed-off-by Jeff Guo <[email protected]>Other than two nits below,
Reviewed-by Jianfeng Tan <[email protected]>Quoted 139 lines
---
v20->v19:
add socket error handler--- lib/librte_eal/linuxapp/eal/eal_dev.c | 206 +++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 2 deletions(-)lib/librte_eal/linuxapp/eal/eal_dev.c +118
-0@@ -2,21 +2,223 @@* Copyright(c) 2018 Intel Corporation */ +#include <string.h> +#include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_log.h> #include <rte_compat.h> #include <rte_dev.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> +#include <rte_alarm.h> + +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +static void dev_uev_handler(__rte_unused void *param); + +/* identify the system layer which reports this event. */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_VFIO ,/* VFIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_socket_fd_create (void ) +{ +struct sockaddr_nl addr; +int ret; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ; + } + +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + ret =bind (intr_handle.fd, (struct sockaddr *) &addr,sizeof (addr)); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"Failed to bind uevent socket.\n" ); + goto err; + } + return 0; +err: +close (intr_handle.fd); + intr_handle.fd =-1 ; +return ret; +} + +static int +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +/** +* check device uevent from kernel side, no need to check +* uevent from udev. +*/ +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; +return -1 ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +/* parse the subsystem layer */ +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +else if (!strncmp (subsystem,"vfio" ,4 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_VFIO ; +else +return -1 ; + +/* parse the action type */ +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +else if (!strncmp (action,"remove" ,6 ))lib/librte_eal/linuxapp/eal/eal_dev.c line 137
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ event->type =RTE_DEV_EVENT_REMOVE ; + else + return -1; +return 0 ; +} + +static void +dev_delayed_unregister (void *param) +{ +rte_intr_callback_unregister (&intr_handle, dev_uev_handler, param);You might also want to:
(quoted diff) +2
-0+ close(intr_handle.fd); + intr_handle.fd = -1;Quoted 16 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +14
-0+} + +static void +dev_uev_handler(__rte_unused void *param) +{ +struct rte_dev_event uevent; +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (&uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (intr_handle.fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret ==0 || (ret <0 && errno !=EAGAIN )) {lib/librte_eal/linuxapp/eal/eal_dev.c line 162
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+/* connection is closed or broken, can not up again. */ +RTE_LOG (ERR ,EAL ,"uevent socket connection is broken.\n" ); +rte_eal_alarm_set (1 , dev_delayed_unregister,NULL ); +return ; + }else if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"uevent socket read error(%d): %s.\n" , + errno,strerror (errno)); +return ; + }Above error handle can be rewritten a little bit:
lib/librte_eal/linuxapp/eal/eal_dev.c +8
-0+if (ret <0 && errno ==EAGAIN ) +return ; +else if (ret <=0 ) { +/* connection is closed or broken, can not up again. */ +RTE_LOG (ERR ,EAL ,"uevent socket connection is broken.\n" ); +rte_eal_alarm_set (1 , dev_delayed_unregister,NULL ); +return ; + }Quoted 66 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +50
-2+ + ret =dev_uev_parse (buf, &uevent,EAL_UEV_MSG_LEN ); +if (ret <0 ) { +RTE_LOG (DEBUG ,EAL ,"It is not an valid event " +"that need to be handle.\n" ); +return ; + } + +RTE_LOG (DEBUG ,EAL ,"receive uevent(name:%s, type:%d, subsystem:%d)\n", + uevent.devname, uevent.type, uevent.subsystem); + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + ret =dev_uev_socket_fd_create (); +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event fd.\n" ); +return -1 ; + } + + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + ret =rte_intr_callback_register (&intr_handle, dev_uev_handler,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_handler, + (void *)-1 ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback.\n" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; }
Re: [PATCH V20 3/4] eal/linux: uevent parse and process
In reply to Jeff Guo05/04/2018 18:10, Jeff Guo:
Quoted 8 lines
In order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
Signed-off-by Jeff Guo <[email protected]>--- lib/librte_eal/linuxapp/eal/eal_dev.c | 206 +++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 2 deletions(-)
Please update the release notes entry, explaining that Linux uevent is supported as backend of the new EAL device event notification framework.
Thanks for the work, I think we are close to the merge.
Re: [PATCH V20 3/4] eal/linux: uevent parse and process
Quoted 5 lines · Thomas Monjalon
05/04/2018 18:10, Jeff Guo:
Quoted 4 lines
In order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Jeff Guo <[email protected]>--- lib/librte_eal/linuxapp/eal/eal_dev.c | 206 +++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 2 deletions(-)Please update the release notes entry, explaining that Linux uevent is supported as backend of the new EAL device event notification framework.
Thanks for the work, I think we are close to the merge.
also thanks for your review and great suggestions.
Quoted 1 line
PATCH v20 4/4 app/testpmd: enable device hotplug monitoring
In reply to Jeff GuoUse testpmd for example, to show how an application uses device event APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c 0x3 --n 4 -- -i --hot-plug
then testpmd starts the device event monitor by calling the new API (rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly.
This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set.
---v20->v19:
no change
--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 101 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 110 insertions(+), 2 deletions(-)
app/test-pmd/parameters.c +4 -1
@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enable hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE
@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };
@@ -1101,7 +1103,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);
app/test-pmd/testpmd.c +100 -1
156 lines not on this page · raw message
app/test-pmd/testpmd.h +2 -0
@@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
doc/guides/testpmd_app_ug/run_app.rst +4 -0
@@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug.
Signature · 1 line
2.7.4
Re: [PATCH V20 4/4] app/testpmd: enable device hotplug monitoring
05/04/2018 18:10, Jeff Guo:
Quoted 7 lines
Use testpmd for example, to show how an application uses device event APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c
0x3--n 4 -- -i --hot-plug
I am not convinced by the testpmd option.
Why not just a CLI command to start monitoring events?
Re: [PATCH V20 4/4] app/testpmd: enable device hotplug monitoring
Quoted 10 lines · Thomas Monjalon
05/04/2018 18:10, Jeff Guo:
Quoted 7 lines
Use testpmd for example, to show how an application uses device event APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c
0x3--n 4 -- -i --hot-plugI am not convinced by the testpmd option.
Why not just a CLI command to start monitoring events?
hot plug is a basic related memory like feature, let the feature go into option like other base option would be make sense i think.
Quoted 1 line
v21 cover add device event monitor framework
In reply to Jeff GuoAbout hot plug in dpdk, We already have proactive way to add/remove devices through APIs (rte_eal_hotplug_add/remove), and also have fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general mechanism to monitor hotplug event for all driver, now the hotplug interrupt event is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring like below. remove@/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 ACTION=remove DEVPATH=/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 SUBSYSTEM=uio
MAJOR=243
MINOR=2
DEVNAME=uio2
SEQNUM=11366
b.add device event monitor framework:
add several general api to enable uevent monitoring.
c.show example how to use uevent monitor
enable uevent monitoring in testpmd to show device event monitor machenism usage.
TODO: failure handler mechanism for hot plug and driver auto bind for hot insertion. that would let the next hot plug patch set to cover.
patchset history:v21->v20:
refine release note and some code cleaning.
v20->v19:
add more detail note and socket error handler.
v19->18:
fix some typo and misunderstanding part
v18->v17:
1.add feature announcement in release document, fix bsp compile issue. 2.refine socket configuration.
3.remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.
v17->v16:
1.add related part of the interrupt handle type adding.
2.add new API into map, fix typo issue, add (void*)-1 value for unregister all callback 3.add new file into meson.build, modify coding sytle and add print info, delete unused part. 4.unregister all user's callback when stop event monitor
v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
v15->v14:
1.use exist eal interrupt epoll to replace of rte service usage for monitor thread, 2.add new device event handle type in eal interrupt.
3.remove the uevent type check and any policy from eal,
let it check and management in user's callback.
4.add "--hot-plug" configure parameter in testpmd to switch the hotplug feature.
v14->v13:
1.add __rte_experimental on function defind and fix bsd build issue
v13->v12:
1.fix some logic issue and null check issue
2.fix monitor stop func issue
v12->v11:
1.identify null param in callback for monitor all devices uevent
v11->v10:
1:modify some typo and add experimental tag in new file. 2:modify callback register calling.
v10->v9:
1.fix prefix issue.
2.use a common callback lists for all device and all type to replace add callback parameter into device struct.
3.delete some unuse part.
v9->v8:
split the patch set into small and explicit patch
v8->v7:
1.use rte_service to replace pthread management.
2.fix defind issue and copyright issue
3.fix some lock issue
v7->v6:
1.modify vdev part according to the vdev rework 2.re-define and split the func into common and bus specific code 3.fix some incorrect issue.
4.fix the system hung after send packcet issue.
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug.
2.modify to manage event callback in each device.
3.fix some system hung issue when igb_uioome typo error.release. 4.modify the pci part to the bus-pci base on the bus rework. 5.add hot plug policy in app, show example to use hotplug list to manage to deside which device need to hot plug.
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer.
2.Redefine the eal device API for common, and distinguish between linux and bsd
3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device. 5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue
7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables of hotplug_fd, add uevent_fd in rte_intr_handle to let each pci device self maintain it fd, to fix dual device fd issue.
2.refine some typo error.
Jeff Guo (4):
eal: add device event handle in interrupt thread
eal: add device event monitor framework eal/linux: uevent parse and process app/testpmd: enable device hotplug monitoring
app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 101 +++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/rel_notes/release_18_05.rst | 11 + doc/guides/testpmd_app_ug/run_app.rst | 4 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 ++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 161 +++++++++++++++ lib/librte_eal/common/eal_private.h | 15 ++ lib/librte_eal/common/include/rte_dev.h | 94 +++++++++ lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 223 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +- lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 4 + test/test/test_interrupts.c | 39 +++- 18 files changed, 691 insertions(+), 5 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
Signature · 1 line
2.7.4
PATCH v21 1/4 eal: add device event handle in interrupt thread
Add new interrupt handle type of RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.
---v21->v20:
no change
--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++- test/test/test_interrupts.c | 39 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_eal_interrupts.h +1 -0
@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10 -1
@@ -559,6 +559,9 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -606,6 +609,9 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -674,7 +680,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
test/test/test_interrupts.c +37 -2
@@ -20,6 +20,7 @@ enum test_interrupt_handle_type {TEST_INTERRUPT_HANDLE_VALID ,TEST_INTERRUPT_HANDLE_VALID_UIO ,TEST_INTERRUPT_HANDLE_VALID_ALARM , +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ,TEST_INTERRUPT_HANDLE_CASE1 , TEST_INTERRUPT_HANDLE_MAX };
@@ -80,6 +81,10 @@ test_interrupt_init(void) intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM ].type =RTE_INTR_HANDLE_ALARM ; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].fd = pfds.readfd; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].type = +RTE_INTR_HANDLE_DEV_EVENT ; + intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].fd = pfds.writefd; intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].type =RTE_INTR_HANDLE_UIO ;
@@ -250,6 +255,14 @@ test_interrupt_enable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_enable (&test_intr_handle) ==0 ) { +printf ("unexpectedly enable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_enable (&test_intr_handle) <0 ) {
@@ -306,6 +319,14 @@ test_interrupt_disable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_disable (&test_intr_handle) ==0 ) { +printf ("unexpectedly disable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_disable (&test_intr_handle) <0 ) {
@@ -393,9 +414,17 @@ test_interrupt(void) goto out; } +printf ("Check valid device event interrupt full path\n" ); +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) { +printf ("failure occurred during checking valid device event " +"interrupt full path\n" ); + goto out; + } +printf ("Check valid alarm interrupt full path\n" ); -if (test_interrupt_full_path_check (TEST_INTERRUPT_HANDLE_VALID_ALARM ) - <0 ) { +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) {printf ("failure occurred during checking valid alarm " "interrupt full path\n" ); goto out;
@@ -513,6 +542,12 @@ test_interrupt(void)rte_intr_callback_unregister (&test_intr_handle, test_interrupt_callback_1, (void *)-1 ); + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback, (void *)-1 ); +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback_1, (void *)-1 ); +rte_delay_ms (2 *TEST_INTERRUPT_CHECK_INTERVAL );/* deinit */ test_interrupt_deinit ();
Signature · 1 line
2.7.4
PATCH v21 2/4 eal: add device event monitor framework
In reply to Jeff GuoThis patch aims to add a general device event monitor framework at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other types of device event monitor, but not in this scope at the stage.
To get started, users firstly call below new added APIs to enable/disable the device event monitor mechanism:
- rte_dev_event_monitor_start
- rte_dev_event_monitor_stop
Then users shell register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_event_callback_register -rte_dev_event_callback_unregister
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could benefit further fail-safe or live-migration.
---v21->v20:
refind map document
--- doc/guides/rel_notes/release_18_05.rst | 9 ++ lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 +++++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 161 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 +++ lib/librte_eal/common/include/rte_dev.h | 94 +++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 22 +++++ lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 4 + 11 files changed, 330 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
doc/guides/rel_notes/release_18_05.rst +9 -0
@@ -58,6 +58,15 @@ New Features * Added support for NVGRE, VXLAN and GENEVE filters in flow API. * Added support for DROP action in flow API. +* **Added device event monitor framework.** + + Added a general device event monitor framework at EAL, for device dynamic management. + Such as device hotplug awareness and actions adopted accordingly. The list of new APIs: + + * ``rte_dev_event_monitor_start`` and ``rte_dev_event_monitor_stop`` are for + the event monitor enable and disable. + * ``rte_dev_event_callback_register`` and ``rte_dev_event_callback_unregister`` + are for the user's callbacks register and unregister. API Changes -----------
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/bsdapp/eal/meson.build +1 -0
@@ -12,4 +12,5 @@ env_sources = files('eal_alarm.c', 'eal_timer.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c' )
lib/librte_eal/common/eal_common_dev.c +161 -0
173 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +15 -0
@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). *
@@ -205,4 +207,17 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* Internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type. +* +*/ +void +dev_callback_process (char *device_name,enum rte_dev_event_type event);#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +94 -0
104 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}
lib/librte_eal/linuxapp/eal/meson.build +1 -0
@@ -18,6 +18,7 @@ env_sources = files('eal_alarm.c', 'eal_vfio_mp_sync.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c', ) if has_libnuma == 1
lib/librte_eal/rte_eal_version.map +4 -0
@@ -258,5 +258,9 @@ EXPERIMENTAL { rte_service_start_with_defaults; rte_socket_count; rte_socket_id_by_idx; + rte_dev_event_monitor_start; + rte_dev_event_monitor_stop; + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; } DPDK_18.02;
Signature · 1 line
2.7.4
Re: [PATCH V21 2/4] eal: add device event monitor framework
06/04/2018 05:55, Jeff Guo:
Quoted 1 line
v21->v20:
This is a very high number of revisions.
I cannot see them in my mail client because they are too much nested and indented in the thread representation.
Tip: when sending a new revision, it is better to thread it with the first revision, so we do not have an infinite nesting.
doc/guides/rel_notes/release_18_05.rst New Features · line 71
Quoted 13 lines
doc/guides/rel_notes/release_18_05.rst +9
-0+* **Added device event monitor framework.** + + Added a general device event monitor framework at EAL, for device dynamic management. + Such as device hotplug awareness and actions adopted accordingly. The list of new APIs: + + * ``rte_dev_event_monitor_start`` and ``rte_dev_event_monitor_stop`` are for + the event monitor enable and disable. + * ``rte_dev_event_callback_register`` and ``rte_dev_event_callback_unregister`` + are for the user's callbacks register and unregister. API Changes
Please keep 2 blank lines before the title.
doc/guides/rel_notes/release_18_05.rst
Quoted 5 lines
doc/guides/rel_notes/release_18_05.rst +5
-0+/* The device event callback list for all registered callbacks. */ +static struct dev_event_cb_list dev_event_cbs; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD(dev_event_cb_list, dev_event_callback);
There is a compilation error with clang:
lib/librte_eal/common/eal_common_dev.c:37:33: fatal error:
tentative definition of variable with internal linkage
has incomplete non-array type
'struct dev_event_cb_list' [-Wtentative-definition-incomplete-type]
static struct dev_event_cb_list dev_event_cbs;
^lib/librte_eal/rte_eal_version.map EXPERIMENTAL { · line 266
Quoted 12 lines
lib/librte_eal/rte_eal_version.map +4
-0@@ -258,5 +258,9 @@ EXPERIMENTAL { rte_service_start_with_defaults; rte_socket_count; rte_socket_id_by_idx; + rte_dev_event_monitor_start; + rte_dev_event_monitor_stop; + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; } DPDK_18.02;
Please keep the alphabetical order.
PATCH v21 3/4 eal/linux: uevent parse and process
In reply to Jeff GuoIn order to handle the uevent which has been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribed to monitor.
---v21->v20:
refine release note and some code cleaning
--- doc/guides/rel_notes/release_18_05.rst | 2 + lib/librte_eal/linuxapp/eal/eal_dev.c | 205 ++++++++++++++++++++++++++++++++- 2 files changed, 205 insertions(+), 2 deletions(-)
doc/guides/rel_notes/release_18_05.rst +2 -0
@@ -68,6 +68,8 @@ New Features * ``rte_dev_event_callback_register`` and ``rte_dev_event_callback_unregister`` are for the user's callbacks register and unregister. + Linux uevent is supported as backend of this device event notification framework. + API Changes -----------
lib/librte_eal/linuxapp/eal/eal_dev.c +203 -2
224 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v21 4/4 app/testpmd: enable device hotplug monitoring
In reply to Jeff GuoUse testpmd for example, to show how an application uses device event APIs to monitor the hotplug events, including both hot removal event and hot insertion event.
The process is that, testpmd first enable hotplug by below commands,
E.g. ./build/app/testpmd -c 0x3 --n 4 -- -i --hot-plug
then testpmd starts the device event monitor by calling the new API (rte_dev_event_monitor_start) and register the user's callback by call the API (rte_dev_event_callback_register), when device being hotplug insertion or hotplug removal, the device event monitor detects the event and call user's callbacks, user could process the event in the callback accordingly.
This patch only shows the event monitoring, device attach/detach would not be involved here, will add from other hotplug patch set.
---v21->v20:
no change.
--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 101 +++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/testpmd_app_ug/run_app.rst | 4 ++ 4 files changed, 110 insertions(+), 2 deletions(-)
app/test-pmd/parameters.c +4 -1
@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enable hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE
@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };
@@ -1101,7 +1103,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);
app/test-pmd/testpmd.c +100 -1
156 lines not on this page · raw message
app/test-pmd/testpmd.h +2 -0
@@ -319,6 +319,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
doc/guides/testpmd_app_ug/run_app.rst +4 -0
@@ -479,3 +479,7 @@ The commandline options are: Set the hexadecimal bitmask of TX queue offloads. The default value is 0. + +* ``--hot-plug`` + + Enable device event monitor machenism for hotplug.
Signature · 1 line
2.7.4
Re: [PATCH V14 1/3] eal: add uevent monitor api and callback func
In reply to Jeff GuoQuoted 18 lines · On Tue, 30 Jan 2018 20:20:58 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c new file +18
-0+memset (&ep_kernel,0 ,sizeof (struct epoll_event )); + ep_kernel.events =EPOLLIN |EPOLLPRI |EPOLLRDHUP |EPOLLHUP ; + ep_kernel.data.fd = netlink_fd; +if (epoll_ctl (fd_ep,EPOLL_CTL_ADD , netlink_fd, + &ep_kernel) <0 ) { +RTE_LOG (ERR ,EAL ,"error addding fd to epoll: %m\n" ); + goto out; + } + +while (!service_exit) { +int fdcount; +struct epoll_event ev[1 ]; + + fdcount =epoll_wait (fd_ep, ev,1 ,-1 ); +if (fdcount <0 ) { +if (errno !=EINTR ) +RTE_LOG (ERR ,EAL ,"error receiving uevent " +"message: %m\n" );
lib/librte_eal/linuxapp/eal/eal_dev.c line 148
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+continue ; + } + +/* epoll_wait has at least one fd ready to read */ +if (dev_uev_process (ev, fdcount) <0 ) { +if (errno !=EINTR ) +RTE_LOG (ERR ,EAL ,"error processing uevent " +"message: %m\n" ); + } + }
What is the point of the extra epoll here? Why not just make netlink_fd blocking and do recv? Rather than having two syscalls per event.
Re: [PATCH V14 1/3] eal: add uevent monitor api and callback func
Quoted 26 lines · Stephen Hemminger
Quoted 23 lines · On Tue, 30 Jan 2018 20:20:58 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c new file +23
-0+memset (&ep_kernel,0 ,sizeof (struct epoll_event )); + ep_kernel.events =EPOLLIN |EPOLLPRI |EPOLLRDHUP |EPOLLHUP ; + ep_kernel.data.fd = netlink_fd; +if (epoll_ctl (fd_ep,EPOLL_CTL_ADD , netlink_fd, + &ep_kernel) <0 ) { +RTE_LOG (ERR ,EAL ,"error addding fd to epoll: %m\n" ); + goto out; + } + +while (!service_exit) { +int fdcount; +struct epoll_event ev[1 ]; + + fdcount =epoll_wait (fd_ep, ev,1 ,-1 ); +if (fdcount <0 ) { +if (errno !=EINTR ) +RTE_LOG (ERR ,EAL ,"error receiving uevent " +"message: %m\n" ); +continue ; + } + +/* epoll_wait has at least one fd ready to read */ +if (dev_uev_process (ev, fdcount) <0 ) {
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 148
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +5
-0+if (errno !=EINTR ) +RTE_LOG (ERR ,EAL ,"error processing uevent " +"message: %m\n" ); + } + }What is the point of the extra epoll here? Why not just make
netlink_fdblocking and do recv? Rather than having two syscalls per event.
if device event monitor only monitor a netlink fd, that might be right not need to add extra epoll, let me think about that if it is need to restore for future advance or just make it simpler. thanks , stephen.
Re: [PATCH V13 1/3] eal: add uevent monitor api and callback func
In reply to Jeff GuoQuoted 18 lines · Jeff Guo
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum ofrte_eal_dev_event_typeand struct ofrte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stop
Quoted 1 line
Signed-off-by Jeff Guo <[email protected]>
Hi Jeff,
Quoted 4 lines
---
v13->v12:
fix some logic issue and null check issue
fix monitor stop func issue and bsp build issue
<snip>
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+int +rte_dev_event_monitor_start (void ) +{ +int ret; +struct rte_service_spec service; +const uint32_t sid =0 ; + +if (!service_no_init) +return 0 ; +
lib/librte_eal/linuxapp/eal/eal_dev.c line 178
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+ slcore =rte_get_next_lcore (/* start core */ -1 , +/* skip master */ 1 , +/* wrap */ 0 ); + + ret =rte_service_lcore_add (slcore); +if (ret) { +RTE_LOG (ERR ,EAL ,"dev event monitor lcore add fail" ); +return ret; + } +
I don't think you should be taking another service core for this purpose without the user asking for it. I also don't think service cores is the right "tool" for monitoring the epoll. Rather than using a non-blocking poll on a service core, I think you should look to reuse the existing infrastructure for handling interrupts in the EAL, which relies on a separate thread blocked on fd's awaiting input.
Quoted 31 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +31
-0+memset (&service,0 ,sizeof (service)); +snprintf (service.name,sizeof (service.name),DEV_EV_MNT_SERVICE_NAME ); + + service.socket_id =rte_socket_id (); + service.callback = dev_uev_monitoring; + service.callback_userdata =NULL ; + service.capabilities =0 ; + ret =rte_service_component_register (&service, &sevice_id); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to register service %s " +"err = %" PRId32, + service.name, ret); +return ret; + } + ret =rte_service_runstate_set (sid,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to set the runstate of " +"the service" ); + goto err_done; + } + ret =rte_service_component_runstate_set (sevice_id,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to set the backend runstate" +" of a component" ); +return ret; + } + ret =rte_service_map_lcore_set (sid, slcore,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to enable lcore 1 on " +"dev event monitor service" ); +return ret;
lib/librte_eal/linuxapp/eal/eal_dev.c line 219
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+ } +rte_service_lcore_start (slcore); + service_no_init = false; +return 0 ; + +err_done: +rte_service_component_unregister (sevice_id); +return ret; +} +
Regards,
/Bruce
Re: [PATCH V13 1/3] eal: add uevent monitor api and callback func
Quoted 47 lines · Bruce Richardson
Quoted 18 lines · Jeff Guo
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum ofrte_eal_dev_event_typeand struct ofrte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stopQuoted 1 line
Signed-off-by Jeff Guo <[email protected]>Hi Jeff,
Quoted 4 lines
---
v13->v12:
fix some logic issue and null check issue
fix monitor stop func issue and bsp build issue<snip>
Quoted 18 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +18
-0+int +rte_dev_event_monitor_start (void ) +{ +int ret; +struct rte_service_spec service; +const uint32_t sid =0 ; + +if (!service_no_init) +return 0 ; + + slcore =rte_get_next_lcore (/* start core */ -1 , +/* skip master */ 1 , +/* wrap */ 0 ); + + ret =rte_service_lcore_add (slcore); +if (ret) { +RTE_LOG (ERR ,EAL ,"dev event monitor lcore add fail" ); +return ret;
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } +I don't think you should be taking another service core for this purpose without the user asking for it. I also don't think service cores is the right "tool" for monitoring the epoll. Rather than using a non-blocking poll on a service core, I think you should look to reuse the existing infrastructure for handling interrupts in the EAL, which relies on a separate thread blocked on fd's awaiting input.
bruce, seems that you might be see the other view of the mountain, so if service cores tools basically be born to need user knowledge and control it, and it is no need to add user to control service tool in the case, i thinks we might not use the existing interrupts infrastructure because it is the device uevent not interrupt as the same functional scope , we could use a separate thread which i have used before in v7 to specialize poll the uevent, please check v7 part to see if it is good.
@tomas, do you agree with that above , or other suggestion, could it be got agreement all or let it improvement later?
Quoted 43 lines
Quoted 31 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +31
-0+memset (&service,0 ,sizeof (service)); +snprintf (service.name,sizeof (service.name),DEV_EV_MNT_SERVICE_NAME ); + + service.socket_id =rte_socket_id (); + service.callback = dev_uev_monitoring; + service.callback_userdata =NULL ; + service.capabilities =0 ; + ret =rte_service_component_register (&service, &sevice_id); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to register service %s " +"err = %" PRId32, + service.name, ret); +return ret; + } + ret =rte_service_runstate_set (sid,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to set the runstate of " +"the service" ); + goto err_done; + } + ret =rte_service_component_runstate_set (sevice_id,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to set the backend runstate" +" of a component" ); +return ret; + } + ret =rte_service_map_lcore_set (sid, slcore,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to enable lcore 1 on " +"dev event monitor service" ); +return ret;lib/librte_eal/linuxapp/eal/eal_dev.c line 219
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+ } +rte_service_lcore_start (slcore); + service_no_init = false; +return 0 ; + +err_done: +rte_service_component_unregister (sevice_id); +return ret; +} +Regards,
/Bruce
Re: [PATCH V13 1/3] eal: add uevent monitor api and callback func
27/01/2018 04:48, Guo, Jia:
Quoted 15 lines · Bruce Richardson
Quoted 5 lines · Jeff Guo
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +4
-0+ ret =rte_service_lcore_add (slcore); +if (ret) { +RTE_LOG (ERR ,EAL ,"dev event monitor lcore add fail" ); +return ret;Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } +I don't think you should be taking another service core for this purpose without the user asking for it. I also don't think service cores is the right "tool" for monitoring the epoll. Rather than using a non-blocking poll on a service core, I think you should look to reuse the existing infrastructure for handling interrupts in the EAL, which relies on a separate thread blocked on fd's awaiting input.
Quoted 7 lines
bruce, seems that you might be see the other view of the mountain, so if service cores tools basically be born to need user knowledge and control it, and it is no need to add user to control service tool in the case, i thinks we might not use the existing interrupts infrastructure because it is the device uevent not interrupt as the same functional scope , we could use a separate thread which i have used before in v7 to specialize poll the uevent, please check v7 part to see if it is good.
The v7 was using pthread_create, so it was not the right solution.
Quoted 2 lines
@tomas, do you agree with that above , or other suggestion, could it be got agreement all or let it improvement later?
I have no issue about using rte_service.
I think the other events processing in EAL could use rte_service. Maybe Harry has a different view?
My main concerns are:
1/ There is not enough review
2/ The callback lookup is using device name from uevent 3/ There is no reference to the rte_device struct
Minor extra requirement: the new __rte_experimental should be used, see http://dpdk.org/commit/77b7b81e32e
Re: [PATCH V13 1/3] eal: add uevent monitor api and callback func
Quoted 30 lines · Thomas Monjalon
27/01/2018 04:48, Guo, Jia:
Quoted 14 lines · Bruce Richardson
Quoted 5 lines · Jeff Guo
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +4
-0+ ret =rte_service_lcore_add (slcore); +if (ret) { +RTE_LOG (ERR ,EAL ,"dev event monitor lcore add fail" ); +return ret;Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } +I don't think you should be taking another service core for this purpose without the user asking for it. I also don't think service cores is the right "tool" for monitoring the epoll. Rather than using a non-blocking poll on a service core, I think you should look to reuse the existing infrastructure for handling interrupts in the EAL, which relies on a separate thread blocked on fd's awaiting input.
Quoted 7 lines
bruce, seems that you might be see the other view of the mountain, so if service cores tools basically be born to need user knowledge and control it, and it is no need to add user to control service tool in the case, i thinks we might not use the existing interrupts infrastructure because it is the device uevent not interrupt as the same functional scope , we could use a separate thread which i have used before in v7 to specialize poll the uevent, please check v7 part to see if it is good.
The v7 was using
pthread_create, so it was not the right solution.Quoted 2 lines
@tomas, do you agree with that above , or other suggestion, could it be got agreement all or let it improvement later?
I have no issue about using
rte_service.
I think the other events processing in EAL could userte_service. Maybe Harry has a different view?
Quoted 7 lines
My main concerns are:
1/ There is not enough review
2/ The callback lookup is using device name from uevent 3/ There is no reference to therte_devicestructMinor extra requirement: the new
__rte_experimentalshould be used, see http://dpdk.org/commit/77b7b81e32e
please review my patch v14 , hope i can fix all your concern, about rte_device struct , i think if there is not better idea to handler the null struct issue, the device name should be use as experimental and i have verify that is ok for use.
Re: [PATCH V12 1/3] eal: add uevent monitor api and callback func
In reply to Jeff Guo18/01/2018 05:12, Jeff Guo:
Quoted 5 lines
+ * It registers the callback for the specific device.
+ * Multiple callbacks cal be registered at the same time.
+ *
+ * @paramdevice_name
+ * The device name, that is the param name of the structrte_device,
Why not using rte_device pointer?
Quoted 1 line
+ * null value means for all devices.
I don't see any management of NULL value.
On the contrary, I see
+ if (device_name == NULL)
+ return -EINVAL;
Quoted 12 lines
+ * @param
cb_fn
+ * callback address.
+ * @paramcb_arg
+ * address of parameter for callback.
+ *
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */lib/librte_eal/common/include/rte_dev.h +3
-0+int rte_dev_callback_register (char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg); +
Re: [PATCH V12 1/3] eal: add uevent monitor api and callback func
Quoted 7 lines · Thomas Monjalon
18/01/2018 05:12, Jeff Guo:
Quoted 5 lines
+ * It registers the callback for the specific device.
+ * Multiple callbacks cal be registered at the same time.
+ *
+ * @paramdevice_name
+ * The device name, that is the param name of the structrte_device,Why not using
rte_devicepointer?
sorry, maybe i have address the reason in other patch mail loop but i will explain again. since if use NULL for all device, a callback could not belong to a NULL rte_device pointer.
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 347
Quoted 5 lines
Quoted 1 line
+ * null value means for all devices.
I don't see any management of NULL value.
On the contrary, I seelib/librte_eal/common/eal_common_dev.c +2
-0+if (device_name ==NULL ) +return -EINVAL ;
the device_name is from the uevent massage, it should not be null for ever. NULL value for all devices is use the params dev_name in the structure of rte_dev_event_callback, and control by below part of code. if dev->name is null, don't care about the whether the device_name have been registered or not. i think that would be fulfill all new device monitor.
TAILQ_FOREACH(cb_lst, &(dev_event_cbs), next) {
if (cb_lst->cb_fn == NULL || (strcmp(cb_lst->dev_name,
device_name) && cb_lst->dev_name))
continue;
dev_cb = *cb_lst;Quoted 14 lines
Quoted 12 lines
+ * @param
cb_fn
+ * callback address.
+ * @paramcb_arg
+ * address of parameter for callback.
+ *
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */lib/librte_eal/common/include/rte_dev.h +3
-0+int rte_dev_callback_register (char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg); +
Re: [PATCH V12 1/3] eal: add uevent monitor api and callback func
In reply to Jeff GuoQuoted 45 lines
-----Original Message-----
From: Guo, Jia
Sent: Thursday, January 18, 2018 12:12 PM
To: [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Cc: Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; Wu, Jingjing <[email protected]>; [email protected]; Guo, Jia <[email protected]>; [email protected]; Zhang, Helin <[email protected]>; [email protected]
Subject: [PATCH V12 1/3] eal: add uevent monitor api and callback funcThis patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum ofrte_eal_dev_event_typeand struct ofrte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stopSigned-off-by Jeff Guo <[email protected]>---
v12->v11:
identify null param in callback for monitor all devices uevent--- lib/librte_eal/bsdapp/eal/eal_dev.c | 38 ++++++ lib/librte_eal/common/eal_common_dev.c | 128 ++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 119 +++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 223 ++++++++++++++++++++++++++++++++ 5 files changed, 509 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
[......]
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+int +rte_dev_callback_register (char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg) +{ +struct rte_dev_event_callback *event_cb =NULL ;
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 275
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+ +rte_spinlock_lock (&rte_dev_event_lock); + +if (TAILQ_EMPTY (&(dev_event_cbs))) +TAILQ_INIT (&(dev_event_cbs)); + + TAILQ_FOREACH(event_cb, &(dev_event_cbs), next) { +if (event_cb->cb_fn == cb_fn && + event_cb->cb_arg == cb_arg && + !strcmp (event_cb->dev_name, device_name))
device_name = NULL means means for all devices, right? Can strcmp accept NULL arguments?
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 287
Quoted 12 lines
lib/librte_eal/common/eal_common_dev.c +12
-0+break ; + } + +/* create a new callback. */ +if (event_cb ==NULL ) { +/* allocate a new user callback entity */ + event_cb =malloc (sizeof (struct rte_dev_event_callback )); +if (event_cb !=NULL ) { + event_cb->cb_fn = cb_fn; + event_cb->cb_arg = cb_arg; + event_cb->dev_name = device_name; + }
Is that OK to call TAILQ_INSERT_TAIL below if event_cb == NULL?
Quoted 20 lines
lib/librte_eal/common/eal_common_dev.c +20
-0+TAILQ_INSERT_TAIL (&(dev_event_cbs), event_cb, next); + } + +rte_spinlock_unlock (&rte_dev_event_lock); +return (event_cb ==NULL ) ?-1 :0 ; +} + +int +rte_dev_callback_unregister (char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg) +{ +int ret; +struct rte_dev_event_callback *event_cb, *next; + +if (!cb_fn || device_name ==NULL ) +return -EINVAL ; + +rte_spinlock_lock (&rte_dev_event_lock); + + ret =0 ;
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 317
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+ +for (event_cb =TAILQ_FIRST (&(dev_event_cbs)); event_cb !=NULL ; + event_cb = next) { + + next =TAILQ_NEXT (event_cb, next); + +if (event_cb->cb_fn != cb_fn || + (event_cb->cb_arg != (void *)-1 && + event_cb->cb_arg != cb_arg) || +strcmp (event_cb->dev_name, device_name))
The same comments as above.
Quoted 18 lines
lib/librte_eal/common/eal_common_dev.c +18
-0+continue ; + +/* +* if this callback is not executing right now, +* then remove it. +*/ +if (event_cb->active ==0 ) { +TAILQ_REMOVE (&(dev_event_cbs), event_cb, next); +rte_free (event_cb); + }else { + ret = -EAGAIN ; + } + } + +rte_spinlock_unlock (&rte_dev_event_lock); +return ret; +} +
[......]
Quoted 29 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +29
-0+int +rte_dev_event_monitor_start (void ) +{ +int ret; +struct rte_service_spec service; +uint32_t id; +const uint32_t sid =0 ; + +if (!service_no_init) +return 0 ; + +uint32_t slcore_1 =rte_get_next_lcore (/* start core */ -1 , +/* skip master */ 1 , +/* wrap */ 0 ); + + ret =rte_service_lcore_add (slcore_1); +if (ret) { +RTE_LOG (ERR ,EAL ,"dev event monitor lcore add fail" ); +return ret; + } + +memset (&service,0 ,sizeof (service)); +snprintf (service.name,sizeof (service.name),DEV_EV_MNT_SERVICE_NAME ); + + service.socket_id =rte_socket_id (); + service.callback = dev_uev_monitoring; + service.callback_userdata =NULL ; + service.capabilities =0 ; + ret =rte_service_component_register (&service, &id);
lib/librte_eal/linuxapp/eal/eal_dev.c line 197
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to register service %s " +"err = %" PRId32, + service.name, ret); +return ret; + } + ret =rte_service_runstate_set (sid,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to set the runstate of " +"the service" );
Any rollback need to be done when fails?
Quoted 15 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +15
-0+return ret; + } + ret =rte_service_component_runstate_set (id,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to set the backend runstate" +" of a component" ); +return ret; + } + ret =rte_service_map_lcore_set (sid, slcore_1,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to enable lcore 1 on " +"dev event monitor service" ); +return ret; + } +rte_service_lcore_start (slcore_1);
lib/librte_eal/linuxapp/eal/eal_dev.c line 222
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+ service_no_init = false; +return 0 ; +} + +int +rte_dev_event_monitor_stop (void ) +{ + service_exit = true; + service_no_init = true; +return 0 ;
Are start and stop peer functions to call? If we call rte_dev_event_monitor_start to start monitor and then call rte_dev_event_monitor_stop to stop it, and then how to start again?
Quoted 3 lines
+}
--
2.7.4
Re: [PATCH V12 1/3] eal: add uevent monitor api and callback func
thanks for your review. please check v13.
Quoted 46 lines · Jingjing
Quoted 44 lines
-----Original Message-----
From: Guo, Jia
Sent: Thursday, January 18, 2018 12:12 PM
To: [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Cc: Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; Wu, Jingjing <[email protected]>; [email protected]; Guo, Jia <[email protected]>; [email protected]; Zhang, Helin <[email protected]>; [email protected]
Subject: [PATCH V12 1/3] eal: add uevent monitor api and callback funcThis patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum ofrte_eal_dev_event_typeand struct ofrte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stopSigned-off-by Jeff Guo <[email protected]>---
v12->v11:
identify null param in callback for monitor all devices uevent--- lib/librte_eal/bsdapp/eal/eal_dev.c | 38 ++++++ lib/librte_eal/common/eal_common_dev.c | 128 ++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 119 +++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 223 ++++++++++++++++++++++++++++++++ 5 files changed, 509 insertions(+)create mode 100644
lib/librte_eal/bsdapp/eal/eal_dev.ccreate mode 100644lib/librte_eal/linuxapp/eal/eal_dev.c[......]
Quoted 16 lines
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+int +rte_dev_callback_register (char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg) +{ +struct rte_dev_event_callback *event_cb =NULL ;lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 275
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+ +rte_spinlock_lock (&rte_dev_event_lock); + +if (TAILQ_EMPTY (&(dev_event_cbs))) +TAILQ_INIT (&(dev_event_cbs)); + + TAILQ_FOREACH(event_cb, &(dev_event_cbs), next) { +if (event_cb->cb_fn == cb_fn && + event_cb->cb_arg == cb_arg && + !strcmp (event_cb->dev_name, device_name))
device_name= NULL means means for all devices, right? Can strcmp accept NULL arguments?
got it.
Quoted 5 lines
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+break ; + } + +/* create a new callback. */ +if (event_cb ==NULL ) {
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 287
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+/* allocate a new user callback entity */ + event_cb =malloc (sizeof (struct rte_dev_event_callback )); +if (event_cb !=NULL ) { + event_cb->cb_fn = cb_fn; + event_cb->cb_arg = cb_arg; + event_cb->dev_name = device_name; + }Is that OK to call
TAILQ_INSERT_TAILbelow ifevent_cb== NULL?
yes, that might be wrong.
Quoted 23 lines
Quoted 23 lines
lib/librte_eal/common/eal_common_dev.c +23
-0+TAILQ_INSERT_TAIL (&(dev_event_cbs), event_cb, next); + } + +rte_spinlock_unlock (&rte_dev_event_lock); +return (event_cb ==NULL ) ?-1 :0 ; +} + +int +rte_dev_callback_unregister (char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg) +{ +int ret; +struct rte_dev_event_callback *event_cb, *next; + +if (!cb_fn || device_name ==NULL ) +return -EINVAL ; + +rte_spinlock_lock (&rte_dev_event_lock); + + ret =0 ; + +for (event_cb =TAILQ_FIRST (&(dev_event_cbs)); event_cb !=NULL ; + event_cb = next) {
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 317
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+ + next =TAILQ_NEXT (event_cb, next); + +if (event_cb->cb_fn != cb_fn || + (event_cb->cb_arg != (void *)-1 && + event_cb->cb_arg != cb_arg) || +strcmp (event_cb->dev_name, device_name))The same comments as above.
ok.
Quoted 52 lines
Quoted 18 lines
lib/librte_eal/common/eal_common_dev.c +18
-0+continue ; + +/* +* if this callback is not executing right now, +* then remove it. +*/ +if (event_cb->active ==0 ) { +TAILQ_REMOVE (&(dev_event_cbs), event_cb, next); +rte_free (event_cb); + }else { + ret = -EAGAIN ; + } + } + +rte_spinlock_unlock (&rte_dev_event_lock); +return ret; +} +[......]
Quoted 32 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +32
-0+int +rte_dev_event_monitor_start (void ) +{ +int ret; +struct rte_service_spec service; +uint32_t id; +const uint32_t sid =0 ; + +if (!service_no_init) +return 0 ; + +uint32_t slcore_1 =rte_get_next_lcore (/* start core */ -1 , +/* skip master */ 1 , +/* wrap */ 0 ); + + ret =rte_service_lcore_add (slcore_1); +if (ret) { +RTE_LOG (ERR ,EAL ,"dev event monitor lcore add fail" ); +return ret; + } + +memset (&service,0 ,sizeof (service)); +snprintf (service.name,sizeof (service.name),DEV_EV_MNT_SERVICE_NAME ); + + service.socket_id =rte_socket_id (); + service.callback = dev_uev_monitoring; + service.callback_userdata =NULL ; + service.capabilities =0 ; + ret =rte_service_component_register (&service, &id); +if (ret) { + RTE_LOG(ERR, EAL, "Failed to register service %s " + "err = %" PRId32,
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 197
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +7
-0+ service.name, ret); +return ret; + } + ret =rte_service_runstate_set (sid,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to set the runstate of " +"the service" );Any rollback need to be done when fails?
yes, should be handle fails.
Quoted 18 lines
Quoted 18 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +18
-0+return ret; + } + ret =rte_service_component_runstate_set (id,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to set the backend runstate" +" of a component" ); +return ret; + } + ret =rte_service_map_lcore_set (sid, slcore_1,1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"Failed to enable lcore 1 on " +"dev event monitor service" ); +return ret; + } +rte_service_lcore_start (slcore_1); + service_no_init = false; +return 0 ; +}
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 222
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +7
-0+ +int +rte_dev_event_monitor_stop (void ) +{ + service_exit = true; + service_no_init = true; +return 0 ;Are start and stop peer functions to call? If we call
rte_dev_event_monitor_startto start monitor and then callrte_dev_event_monitor_stopto stop it, and then how to start again?
sure. should peer control.
Quoted 3 lines
Quoted 3 lines
+}
--
2.7.4
Re: [PATCH V11 1/3] eal: add uevent monitor api and callback func
In reply to Jeff Guo15/01/2018 11:48, Jeff Guo:
Quoted 14 lines
+ * It registers the callback for the specific event. Multiple
+ * callbacks cal be registered at the same time.
+ *
+ * @paramdevice_name
+ * The device name.
+ * @paramcb_fn
+ * callback address.
+ * @paramcb_arg
+ * address of parameter for callback.
+ *
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */
Review
Quoted 2 lines
(quoted diff) +2
-0+int rte_dev_callback_register(char *device_name, rte_dev_event_cb_fn cb_fn, + void *cb_arg);
What is the device name?
I think we should register a callback for a rte_device or NULL (all devices).
Re: [PATCH V11 1/3] eal: add uevent monitor api and callback func
Quoted 17 lines · Thomas Monjalon
15/01/2018 11:48, Jeff Guo:
Quoted 14 lines
+ * It registers the callback for the specific event. Multiple
+ * callbacks cal be registered at the same time.
+ *
+ * @paramdevice_name
+ * The device name.
+ * @paramcb_fn
+ * callback address.
+ * @paramcb_arg
+ * address of parameter for callback.
+ *
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */Review
Quoted 2 lines
(quoted diff) +2
-0+int rte_dev_callback_register(char *device_name, rte_dev_event_cb_fn cb_fn, + void *cb_arg);
Quoted 3 lines
What is the device name?
I think we should register a callback for a
rte_deviceor NULL (all devices).
please see my v12 patch, the device name have been info to user.
i think a device name for a callback might be fulfill , since if use NULL for all device, a callback could not belong to a NULL point. if there are any advantage by callback for a rte_device, please explicit outline it. and i think it must be a improvement and anyway if need i will try to make it better. and what ever a callback for a rte_device or a device name for a callback, i think that is not our gap, i guess what you care about is that the new and firstly hot plug in device monitor , so i would add null check for identify these new device callback. am i right?
Re: [PATCH V11 1/3] eal: add uevent monitor api and callback func
18/01/2018 05:23, Guo, Jia:
Quoted 22 lines · Thomas Monjalon
Quoted 17 lines
15/01/2018 11:48, Jeff Guo:
Quoted 14 lines
+ * It registers the callback for the specific event. Multiple
+ * callbacks cal be registered at the same time.
+ *
+ * @paramdevice_name
+ * The device name.
+ * @paramcb_fn
+ * callback address.
+ * @paramcb_arg
+ * address of parameter for callback.
+ *
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */Review
Quoted 2 lines
(quoted diff) +2
-0+int rte_dev_callback_register(char *device_name, rte_dev_event_cb_fn cb_fn, + void *cb_arg);Quoted 3 lines
What is the device name?
I think we should register a callback for a
rte_deviceor NULL (all devices).
Quoted 10 lines
please see my v12 patch, the device name have been info to user. i think a device name for a callback might be fulfill , since if use NULL for all device, a callback could not belong to a NULL point. if there are any advantage by callback for a
rte_device, please explicit outline it. and i think it must be a improvement and anyway if need i will try to make it better.
and what ever a callback for arte_deviceor a device name for a callback, i think that is not our gap, i guess what you care about is that the new and firstly hot plug in device monitor , so i would add null check for identify these new device callback. am i right?
Yes I am looking for new device event.
Re: [PATCH V10 1/2] eal: add uevent monitor api and callback func
In reply to Jeff GuoHi,
11/01/2018 15:05, Jeff Guo:
Quoted 1 line
+/* A genaral callback for all registerd devices */
Typos: genaral, registerd
So the callback is only for registered devices?
What about hotplugged devices?
Quoted 23 lines
lib/librte_eal/common/include/rte_dev.h +23
-0+/** +* It registers the callback for the specific event. Multiple +* callbacks cal be registered at the same time. +* @param event +* The device event type. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int rte_dev_callback_register (char *dev_name, +rte_dev_event_cb_fn cb_fn,void *cb_arg); + +/** +* It unregisters the callback according to the specified event. +* +* @param event +* The event type which corresponding to the callback. +* @param cb_fn
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 351
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h +10
-0+* callback address. +* address of parameter for callback, (void *)-1 means to remove all +* registered which has the same callback address. +* +* @return +* - On success, return the number of callback entities removed. +* - On failure, a negative value. +*/ +int rte_dev_callback_unregister (char *dev_name, +rte_dev_event_cb_fn cb_fn,void *cb_arg);
These new functions should be tagged as experimental.
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 384
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h +10
-0+/** +* Start the device event monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_dev_evt_mntr_start (void );
Should be experimental too, as every new public functions.
Please avoid shortening function name too much. rte_dev_event_monitor_start is more pleasant to read.
Re: [PATCH V10 1/2] eal: add uevent monitor api and callback func
Quoted 8 lines · Thomas Monjalon
Hi,
11/01/2018 15:05, Jeff Guo:
Quoted 1 line
+/* A genaral callback for all registerd devices */
Typos: genaral, registerd
So the callback is only for registered devices?
What about hotplugged devices?
the hotplugged devices is managed by the application, if it prior registered and in the app's hotplug device list, will always be monitor whenever it plug in and out. the eal only care about the registered devices.
Quoted 26 lines
Quoted 26 lines
lib/librte_eal/common/include/rte_dev.h +26
-0+/** +* It registers the callback for the specific event. Multiple +* callbacks cal be registered at the same time. +* @param event +* The device event type. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int rte_dev_callback_register (char *dev_name, +rte_dev_event_cb_fn cb_fn,void *cb_arg); + +/** +* It unregisters the callback according to the specified event. +* +* @param event +* The event type which corresponding to the callback. +* @param cb_fn +* callback address. +* address of parameter for callback, (void *)-1 means to remove all +* registered which has the same callback address.
Quoted 8 lines
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 351
Quoted 7 lines
+ *
+ * @return
+ * - On success, return the number of callback entities removed.
+ * - On failure, a negative value.
+ */lib/librte_eal/common/include/rte_dev.h +2
-0+int rte_dev_callback_unregister (char *dev_name, +rte_dev_event_cb_fn cb_fn,void *cb_arg);These new functions should be tagged as experimental.
got it.
Quoted 12 lines
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 384
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h +10
-0+/** +* Start the device event monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_dev_evt_mntr_start (void );Should be experimental too, as every new public functions.
Quoted 2 lines
Please avoid shortening function name too much.
rte_dev_event_monitor_startis more pleasant to read.
yes , choose the more pleasant way.
Re: [PATCH V10 1/2] eal: add uevent monitor api and callback func
15/01/2018 11:55, Guo, Jia:
Quoted 7 lines · Thomas Monjalon
Quoted 6 lines
Hi,
11/01/2018 15:05, Jeff Guo:
Quoted 1 line
+/* A genaral callback for all registerd devices */
Typos: genaral, registerd
Quoted 7 lines
Quoted 2 lines
So the callback is only for registered devices?
What about hotplugged devices?the hotplugged devices is managed by the application, if it prior registered and in the app's hotplug device list, will always be monitor whenever it plug in and out. the eal only care about the registered devices.
I disagree. The application needs the EAL service to get notified of a new device plugged in.
We should find a way to register the callback for all devices, including new ones.
Re: [PATCH V10 1/2] eal: add uevent monitor api and callback func
Quoted 10 lines · Thomas Monjalon
15/01/2018 11:55, Guo, Jia:
Quoted 9 lines · Thomas Monjalon
Quoted 8 lines
Hi,
11/01/2018 15:05, Jeff Guo:
Quoted 1 line
+/* A genaral callback for all registerd devices */
Typos: genaral, registerd
So the callback is only for registered devices?
What about hotplugged devices?
Quoted 8 lines
Quoted 4 lines
the hotplugged devices is managed by the application, if it prior registered and in the app's hotplug device list, will always be monitor whenever it plug in and out. the eal only care about the registered devices.
I disagree. The application needs the EAL service to get notified of a new device plugged in.
We should find a way to register the callback for all devices, including new ones.
i think the current mechanism would let eal service detect all new device in , but would not notify all to the application. if the application need to monitor specific device , it will prior know the device name. but if notify all in eal service and let application choose it in user side ,that is other story, that is what you want ? but do you think about , if it is need to let user know all device plugin , or just let eal know all info would be better or safer?
PATCH v9 3/5 app/testpmd: use uevent to monitor hotplug
In reply to Jeff Guouse testpmd for example, to show app how to request and use uevent monitoring to handle the hot removal event and the hot insertion event.
---v9->v8:
split the patch set into small and explicit patch
--- app/test-pmd/testpmd.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 9 +++ 2 files changed, 188 insertions(+)
app/test-pmd/testpmd.c +179 -0
@@ -373,6 +373,8 @@ uint8_t bitrate_enabled;struct gro_status gro_ports[RTE_MAX_ETHPORTS ];uint8_t gro_flush_cycles =GRO_DEFAULT_FLUSH_CYCLES ; +static struct hotplug_request_list hp_list; +/* Forward function declarations */ static void map_port_queue_stats_mapping_registers (portid_t pi,struct rte_port *port);
@@ -380,6 +382,13 @@ static void check_all_ports_link_status(uint32_t port_mask);static int eth_event_callback (portid_t port_id,enum rte_eth_event_type type,void *param,void *ret_param); +static int eth_uevent_callback (enum rte_dev_event_type type, +void *param,void *ret_param); +static int eth_uevent_callback_register (portid_t pid); +static int in_hotplug_list (const char *dev_name); + +static int hotplug_list_add (const char *dev_name, +enum rte_dev_event_type event);/* * Check if all the ports are started.
@@ -1729,6 +1738,32 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_uevent_callback_register (portid_t pid) +{ +int diag; +struct rte_eth_dev *dev; +enum rte_dev_event_type dev_event_type; + +/* register the uevent callback */ + dev = &rte_eth_devices[pid]; +for (dev_event_type =RTE_DEV_EVENT_ADD ; + dev_event_type <RTE_DEV_EVENT_CHANGE ; + dev_event_type++) { + diag =rte_dev_callback_register (dev->device, dev_event_type, + eth_uevent_callback, + (void *)(intptr_t )pid); +if (diag) { +printf ("Failed to setup uevent callback for" +" device event %d\n" , + dev_event_type); +return -1 ; + } + } + +return 0 ; +} +void attach_port (char *identifier) {
@@ -1745,6 +1780,8 @@ attach_port(char *identifier)if (rte_eth_dev_attach (identifier, &pi))return ; +eth_uevent_callback_register (pi); + socket_id = (unsigned )rte_eth_dev_socket_id (pi);/* if socket_id is invalid, set to 0 */ if (check_socket_id (socket_id) <0 )
@@ -1756,6 +1793,8 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +hotplug_list_add (identifier,RTE_DEV_EVENT_REMOVE ); +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }
@@ -1782,6 +1821,9 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_ADD ); +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );
@@ -1805,6 +1847,9 @@ pmd_test_exit(void)close_port (pt_id); } } + +rte_dev_monitor_stop (); +printf ("\nBye...\n" ); }
@@ -1889,6 +1934,49 @@ rmv_event_callback(void *arg) dev->device->name); } +static void +rmv_uevent_callback (void *arg) +{ +char name[RTE_ETH_NAME_MAX_LEN ]; +uint8_t port_id = (intptr_t )arg; + +rte_eal_alarm_cancel (rmv_uevent_callback, arg); + +RTE_ETH_VALID_PORTID_OR_RET (port_id); +printf ("removing port id:%u\n" , port_id); + +if (!in_hotplug_list (rte_eth_devices[port_id].device->name)) +return ; + +stop_packet_forwarding (); + +stop_port (port_id); +close_port (port_id); +if (rte_eth_dev_detach (port_id, name)) { +RTE_LOG (ERR ,USER1 ,"Failed to detach port '%s'\n" , name); +return ; + } + + nb_ports =rte_eth_dev_count (); + +printf ("Port '%s' is detached. Now total ports is %d\n" , + name, nb_ports); +} + +static void +add_uevent_callback (void *arg) +{ +char *dev_name = (char *)arg; + +rte_eal_alarm_cancel (add_uevent_callback, arg); + +if (!in_hotplug_list (dev_name)) +return ; + +RTE_LOG (ERR ,EAL ,"add device: %s\n" , dev_name); +attach_port (dev_name); +} +/* This function is used by the interrupt thread */ static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
@@ -1931,6 +2019,88 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, }static int +in_hotplug_list (const char *dev_name) +{ +struct hotplug_request *hp_request =NULL ; + + TAILQ_FOREACH(hp_request, &hp_list, next) { +if (!strcmp (hp_request->dev_name, dev_name)) +break ; + } + +if (hp_request) +return 1 ; + +return 0 ; +} + +static int +hotplug_list_add (const char *dev_name,enum rte_dev_event_type event) +{ +struct hotplug_request *hp_request; + + hp_request =rte_zmalloc ("hoplug request" , +sizeof (*hp_request),0 ); +if (hp_request ==NULL ) { +fprintf (stderr,"%s can not alloc memory\n" , + __func__); +return -ENOMEM ; + } + + hp_request->dev_name = dev_name; + hp_request->event = event; + +TAILQ_INSERT_TAIL (&hp_list, hp_request, next); + +return 0 ; +} + +/* This function is used by the interrupt thread */ +static int +eth_uevent_callback (enum rte_dev_event_type type,void *arg, +void *ret_param) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; +static char *device_name; + +RTE_SET_USED (ret_param); + +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_uevent_callback, arg)) +fprintf (stderr,"Could not set up deferred " +"device removal\n" ); +break ; +case RTE_DEV_EVENT_ADD : + device_name =malloc (strlen ((const char *)ret_param) +1 ); +strcpy (device_name, ret_param); +if (rte_eal_alarm_set (500000 , + add_uevent_callback, device_name)) +fprintf (stderr,"Could not set up deferred " +"device add\n" ); +break ; +default : +break ; + } +return 0 ; +} + +static int set_tx_queue_stats_mapping_registers (portid_t port_id,struct rte_port *port) {uint16_t i;
@@ -2415,6 +2585,15 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +/* enable hot plug monitoring */ +TAILQ_INIT (&hp_list); +rte_dev_monitor_start (); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_REMOVE ); +eth_uevent_callback_register (port_id); + }if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );
app/test-pmd/testpmd.h +9 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_dev_event_type event;/**< device event type */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
Signature · 1 line
2.7.4
PATCH v9 4/5 pci_uio: add uevent hotplug failure handler in pci
In reply to Jeff Guowhen detect hot removal uevent of device, the device resource become invalid, in order to avoid unexpected usage of this resource, remap the device resource to be a fake memory, that would lead the application keep running well but not encounter system core dump.
---v9->v8:
split the patch set into small and explicit patch
--- drivers/bus/pci/bsd/pci.c | 23 ++++++++++++++++++++ drivers/bus/pci/linux/pci.c | 34 ++++++++++++++++++++++++++++++ drivers/bus/pci/pci_common.c | 22 +++++++++++++++++++ drivers/bus/pci/pci_common_uio.c | 28 +++++++++++++++++++++++++ drivers/bus/pci/private.h | 12 +++++++++++ drivers/bus/pci/rte_bus_pci.h | 11 ++++++++++ drivers/bus/vdev/vdev.c | 9 +++++++- lib/librte_eal/common/eal_common_bus.c | 1 + lib/librte_eal/common/include/rte_bus.h | 17 +++++++++++++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 35 ++++++++++++++++++++++++++++--- lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 6 ++++++ lib/librte_pci/rte_pci.c | 20 ++++++++++++++++++ lib/librte_pci/rte_pci.h | 17 +++++++++++++++ 13 files changed, 231 insertions(+), 4 deletions(-)
drivers/bus/pci/bsd/pci.c +23 -0
@@ -97,6 +97,29 @@ rte_pci_unmap_device(struct rte_pci_device *dev) } } +/* re-map pci device */ +int +rte_pci_remap_device (struct rte_pci_device *dev) +{ +int ret; + +if (dev ==NULL ) +return -EINVAL ; + +switch (dev->kdrv) { +case RTE_KDRV_NIC_UIO : + ret =pci_uio_remap_resource (dev); +break ; +default : +RTE_LOG (DEBUG ,EAL , +" Not managed by a supported kernel driver, skipped\n" ); + ret =1 ; +break ; + } + +return ret; +} +void pci_uio_free_resource (struct rte_pci_device *dev,struct mapped_pci_resource *uio_res)
drivers/bus/pci/linux/pci.c +34 -0
@@ -116,6 +116,38 @@ rte_pci_unmap_device(struct rte_pci_device *dev) } } +/* Map pci device */ +int +rte_pci_remap_device (struct rte_pci_device *dev) +{ +int ret =-1 ; + +if (dev ==NULL ) +return -EINVAL ; + +switch (dev->kdrv) { +case RTE_KDRV_VFIO : +#ifdef VFIO_PRESENT +/* no thing to do */ +#endif +break ; +case RTE_KDRV_IGB_UIO : +case RTE_KDRV_UIO_GENERIC : +if (rte_eal_using_phys_addrs ()) { +/* map resources for devices that use uio */ + ret =pci_uio_remap_resource (dev); + } +break ; +default : +RTE_LOG (DEBUG ,EAL , +" Not managed by a supported kernel driver, skipped\n" ); + ret =1 ; +break ; + } + +return ret; +} +void *pci_find_max_end_va (void ) {
@@ -357,6 +389,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)rte_pci_add_device (dev); } + dev->device.state =RTE_DEV_PARSED ; +TAILQ_INIT (&(dev->device.uev_cbs));return 0 ; }
drivers/bus/pci/pci_common.c +22 -0
@@ -282,6 +282,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)if (rc >0 )/* positive value means driver doesn't support it */ continue ; + dev->device.state =RTE_DEV_PROBED ;return 0 ; }return 1 ;
@@ -481,6 +482,7 @@ rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,void rte_pci_remove_device (struct rte_pci_device *pci_dev) { +RTE_LOG (DEBUG ,EAL ," rte_pci_remove_device for device list\n" );TAILQ_REMOVE (&rte_pci_bus.device_list, pci_dev, next); }
@@ -522,6 +524,25 @@ pci_find_device_by_name(const struct rte_device *start, }static int +pci_remap_device (struct rte_device *dev) +{ +struct rte_pci_device *pdev; +int ret; + +if (dev ==NULL ) +return -EINVAL ; + + pdev =RTE_DEV_TO_PCI (dev); + +/* remap resources for devices that use igb_uio */ + ret =rte_pci_remap_device (pdev); +if (ret !=0 ) +RTE_LOG (ERR ,EAL ,"failed to remap device %s" , + dev->name); +return ret; +} + +static int pci_plug (struct rte_device *dev) {return pci_probe_all_drivers (RTE_DEV_TO_PCI (dev));
@@ -552,6 +573,7 @@ struct rte_pci_bus rte_pci_bus = { .unplug = pci_unplug, .parse = pci_parse, .get_iommu_class = rte_pci_get_iommu_class, + .remap_device = pci_remap_device, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
drivers/bus/pci/pci_common_uio.c +28 -0
@@ -147,6 +147,34 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res) } } +/* remap the PCI resource of a PCI device in private virtual memory */ +int +pci_uio_remap_resource (struct rte_pci_device *dev) +{ +int i; +uint64_t phaddr; +void *map_address; + +/* Map all BARs */ +for (i =0 ; i !=PCI_MAX_RESOURCE ; i++) { +/* skip empty BAR */ + phaddr = dev->mem_resource[i].phys_addr; +if (phaddr ==0 ) +continue ; + map_address =pci_map_private_resource ( + dev->mem_resource[i].addr,0 , + (size_t )dev->mem_resource[i].len); +if (map_address ==MAP_FAILED ) + goto error; +memset (map_address,0xFF , (size_t )dev->mem_resource[i].len); + dev->mem_resource[i].addr = map_address; + } + +return 0 ; +error: +return -1 ; +} +static struct mapped_pci_resource *pci_uio_find_resource (struct rte_pci_device *dev) {
drivers/bus/pci/private.h +12 -0
@@ -202,6 +202,18 @@ void pci_uio_free_resource(struct rte_pci_device *dev, struct mapped_pci_resource *uio_res);/** +* remap the pci uio resource.. +* +* @param dev +* Point to the struct rte pci device. +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +pci_uio_remap_resource (struct rte_pci_device *dev); + +/** * Map device memory to uio resource * * This function is private to EAL.
drivers/bus/pci/rte_bus_pci.h +11 -0
@@ -52,6 +52,8 @@ extern "C" {#include <sys/queue.h> #include <stdint.h> #include <inttypes.h> +#include <unistd.h> +#include <fcntl.h> #include <rte_debug.h> #include <rte_interrupts.h>
@@ -197,6 +199,15 @@ int rte_pci_map_device(struct rte_pci_device *dev);void rte_pci_unmap_device (struct rte_pci_device *dev);/** +* Remap this device +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +*/ +int rte_pci_remap_device (struct rte_pci_device *dev); + +/** * Dump the content of the PCI bus. * * @param f
drivers/bus/vdev/vdev.c +8 -1
@@ -323,7 +323,6 @@ vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,return NULL ; } -static struct rte_device * vdev_find_device_by_name(const struct rte_device *start, rte_dev_cmp_name_t cmp_name,
@@ -343,6 +342,13 @@ vdev_find_device_by_name(const struct rte_device *start, }static int +vdev_remap_device (struct rte_device *dev) +{ +RTE_SET_USED (dev); +return 0 ; +} + +static int vdev_plug (struct rte_device *dev) {return vdev_probe_all_drivers (RTE_DEV_TO_VDEV (dev));
@@ -362,6 +368,7 @@ static struct rte_bus rte_vdev_bus = { .plug = vdev_plug, .unplug = vdev_unplug, .parse = vdev_parse, + .remap_device = vdev_remap_device, };RTE_REGISTER_BUS (vdev, rte_vdev_bus);
lib/librte_eal/common/eal_common_bus.c +1 -0
@@ -54,6 +54,7 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->find_device_by_name);/* Buses supporting driver plug also require unplug. */ RTE_VERIFY (!bus->plug || bus->unplug); +RTE_VERIFY (bus->remap_device);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +17 -0
@@ -196,6 +196,22 @@ typedef int (*rte_bus_unplug_t)(struct rte_device *dev);typedef int (*rte_bus_parse_t )(const char *name,void *addr);/** +* Implementation specific remap function which is responsible for +* remmaping devices on that bus from original share memory resource +* to a private memory resource for the sake of device has been removal, +* when detect the device removal event invoke from the kernel side, +* prior to call this function before any operation for device hw. +* +* @param dev +* Device pointer that was returned by a previous call to find_device. +* +* @return +* 0 on success. +* !0 on error. +*/ +typedef int (*rte_bus_remap_device_t )(struct rte_device *dev); + +/** * Bus scan policies */ enum rte_bus_scan_mode {
@@ -239,6 +255,7 @@ struct rte_bus {rte_bus_plug_t plug;/**< Probe single device for drivers */ rte_bus_unplug_t unplug;/**< Remove single device from driver */ rte_bus_parse_t parse;/**< Parse a device name */ +rte_bus_remap_device_t remap_device;/**< remap a device */ struct rte_bus_conf conf;/**< Bus configuration */ rte_bus_get_iommu_class_t get_iommu_class;/**< Get iommu class */ };
lib/librte_eal/linuxapp/eal/eal_dev.c +32 -3
@@ -32,6 +32,12 @@ bool service_no_init = true;#define DEV_EV_MNT_SERVICE_NAME "device_event_monitor_service" +static void sig_handler (int signum) +{ +if (signum ==SIGINT || signum ==SIGTERM ) +rte_dev_monitor_stop (); +} +static int dev_monitor_fd_new (void ) {
@@ -168,6 +174,7 @@ dev_uev_process(struct epoll_event *events, int nfds)struct rte_bus *bus;struct rte_device *dev;struct rte_eal_uevent uevent; +int ret;int i;for (i =0 ; i < nfds; i++) {
@@ -187,9 +194,17 @@ dev_uev_process(struct epoll_event *events, int nfds)if ((!dev) || dev->state ==RTE_DEV_UNDEFINED )return 0 ; -return (_rte_dev_callback_process (dev, -RTE_DEV_EVENT_REMOVE , -NULL )); + dev->state =RTE_DEV_FAULT ; + +/** +* remap the resource to be fake +* before user's removal processing +*/ + ret = bus->remap_device (dev); +if (!ret) +return (_rte_dev_callback_process (dev, +RTE_DEV_EVENT_REMOVE , +NULL )); }else if (uevent.type ==RTE_DEV_EVENT_ADD ) {if (dev ==NULL ) { return(_rte_dev_callback_process(NULL,
@@ -215,12 +230,26 @@ dev_uev_process(struct epoll_event *events, int nfds)*/ static int32_t dev_uev_monitoring(__rte_unused void *arg) { +struct sigaction act; +sigset_t mask;int netlink_fd =-1 ;struct epoll_event ep_kernel;int fd_ep =-1 ; service_exit = false; +/* set signal handlers */ +memset (&act,0x00 ,sizeof (struct sigaction )); + act.sa_handler = sig_handler; +sigemptyset (&act.sa_mask); + act.sa_flags =SA_RESTART ; +sigaction (SIGINT , &act,NULL ); +sigaction (SIGTERM , &act,NULL ); +sigemptyset (&mask); +sigaddset (&mask,SIGINT ); +sigaddset (&mask,SIGTERM ); +sigprocmask (SIG_UNBLOCK , &mask,NULL ); + fd_ep =epoll_create1 (EPOLL_CLOEXEC );if (fd_ep <0 ) {RTE_LOG (ERR ,EAL ,"error creating epoll fd: %m\n" );
lib/librte_eal/linuxapp/igb_uio/igb_uio.c +6 -0
@@ -354,6 +354,12 @@ igbuio_pci_release(struct uio_info *info, struct inode *inode)struct rte_uio_pci_dev *udev = info->priv;struct pci_dev *dev = udev->pdev; +/* check if device have been remove before release */ +if ((&dev->dev.kobj)->state_remove_uevent_sent ==1 ) { +pr_info ("The device have been removed\n" ); +return -1 ; + } +/* disable interrupts */ igbuio_pci_disable_interrupts (udev);
lib/librte_pci/rte_pci.c +20 -0
@@ -172,6 +172,26 @@ rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr)return -1 ; } +/* map a private resource from an address*/ +void * +pci_map_private_resource (void *requested_addr,off_t offset,size_t size) +{ +void *mapaddr; + + mapaddr =mmap (requested_addr, size, +PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_ANONYMOUS |MAP_FIXED ,-1 ,0 ); +if (mapaddr ==MAP_FAILED ) { +RTE_LOG (ERR ,EAL ,"%s(): cannot mmap(%p, 0x%lx, 0x%lx): " +"%s (%p)\n" , + __func__, requested_addr, + (unsigned long )size, (unsigned long )offset, +strerror (errno), mapaddr); + }else +RTE_LOG (DEBUG ,EAL ," PCI memory mapped at %p\n" , mapaddr); + +return mapaddr; +}/* map a particular resource from a file */ void *
lib/librte_pci/rte_pci.h +17 -0
@@ -227,6 +227,23 @@ int rte_pci_addr_cmp(const struct rte_pci_addr *addr,int rte_pci_addr_parse (const char *str,struct rte_pci_addr *addr);/** +* @internal +* Map to a particular private resource. +* +* @param requested_addr +* The starting address for the new mapping range. +* @param offset +* The offset for the mapping range. +* @param size +* The size for the mapping range. +* @return +* - On success, the function returns a pointer to the mapped area. +* - On error, the value MAP_FAILED is returned. +*/ +void *pci_map_private_resource (void *requested_addr,off_t offset, +size_t size); + +/** * Map a particular resource from a file. * * @param requested_addr
Signature · 1 line
2.7.4
PATCH v9 5/5 pci: add driver auto bind for hot insertion
In reply to Jeff GuoNormally we bind nic driver before application running, so if we want to automatically driver binding after application run, need to implement a auto bind function, that would benefit for hot insertion case, when detect hot insertion uevent of device, auto bind the driver according some user policy and then attach device, let app running smoothly and automatically when hotplug behavior occur.
---v9->v8:
split the patch set into small and explicit patch
--- drivers/bus/pci/bsd/pci.c | 7 +++++ drivers/bus/pci/linux/pci.c | 53 +++++++++++++++++++++++++++++++++ drivers/bus/pci/pci_common.c | 1 + drivers/bus/pci/rte_bus_pci.h | 14 +++++++++ drivers/bus/vdev/vdev.c | 9 ++++++ lib/librte_eal/common/eal_common_bus.c | 1 + lib/librte_eal/common/include/rte_bus.h | 18 +++++++++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 7 +++++ 8 files changed, 110 insertions(+)
drivers/bus/pci/bsd/pci.c +7 -0
@@ -672,3 +672,10 @@ rte_pci_ioport_unmap(struct rte_pci_ioport *p)return ret; } + +int +rte_pci_dev_bind_driver (const char *dev_name,const char *drv_type) +{ +return -1 ; +} +
drivers/bus/pci/linux/pci.c +53 -0
56 lines not on this page · raw message
drivers/bus/pci/pci_common.c +1 -0
@@ -574,6 +574,7 @@ struct rte_pci_bus rte_pci_bus = { .parse = pci_parse, .get_iommu_class = rte_pci_get_iommu_class, .remap_device = pci_remap_device, + .bind_driver = rte_pci_dev_bind_driver, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
drivers/bus/pci/rte_bus_pci.h +14 -0
@@ -344,6 +344,20 @@ void rte_pci_ioport_read(struct rte_pci_ioport *p,void rte_pci_ioport_write (struct rte_pci_ioport *p,const void *data,size_t len,off_t offset); +/** +* It can be used to bind a device to a specific type of driver. +* +* @param dev_name +* The device name. +* @param drv_type +* The specific driver's type. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int rte_pci_dev_bind_driver (const char *dev_name,const char *drv_type); + #ifdef __cplusplus }#endif
drivers/bus/vdev/vdev.c +9 -0
@@ -349,6 +349,14 @@ vdev_remap_device(struct rte_device *dev) }static int +vdev_bind_driver (const char *dev_name,const char *drv_type) +{ +RTE_SET_USED (dev_name); +RTE_SET_USED (drv_type); +return 0 ; +} + +static int vdev_plug (struct rte_device *dev) {return vdev_probe_all_drivers (RTE_DEV_TO_VDEV (dev));
@@ -369,6 +377,7 @@ static struct rte_bus rte_vdev_bus = { .unplug = vdev_unplug, .parse = vdev_parse, .remap_device = vdev_remap_device, + .bind_driver = vdev_bind_driver, };RTE_REGISTER_BUS (vdev, rte_vdev_bus);
lib/librte_eal/common/eal_common_bus.c +1 -0
@@ -55,6 +55,7 @@ rte_bus_register(struct rte_bus *bus)/* Buses supporting driver plug also require unplug. */ RTE_VERIFY (!bus->plug || bus->unplug);RTE_VERIFY (bus->remap_device); +RTE_VERIFY (bus->bind_driver);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +18 -0
@@ -212,6 +212,23 @@ typedef int (*rte_bus_parse_t)(const char *name, void *addr);typedef int (*rte_bus_remap_device_t )(struct rte_device *dev);/** +* Implementation specific bind driver function which is responsible for bind +* a explicit type of driver with a devices on that bus. +* +* @param dev_name +* device textual description. +* +* @param drv_type +* driver type textual description. +* +* @return +* 0 on success. +* !0 on error. +*/ +typedef int (*rte_bus_bind_driver_t )(const char *dev_name, +const char *drv_type); + +/** * Bus scan policies */ enum rte_bus_scan_mode {
@@ -256,6 +273,7 @@ struct rte_bus {rte_bus_unplug_t unplug;/**< Remove single device from driver */ rte_bus_parse_t parse;/**< Parse a device name */ rte_bus_remap_device_t remap_device;/**< remap a device */ +rte_bus_bind_driver_t bind_driver;/**< bind a driver for bus device */ struct rte_bus_conf conf;/**< Bus configuration */ rte_bus_get_iommu_class_t get_iommu_class;/**< Get iommu class */ };
lib/librte_eal/linuxapp/eal/eal_dev.c +7 -0
@@ -207,6 +207,13 @@ dev_uev_process(struct epoll_event *events, int nfds) NULL)); }else if (uevent.type ==RTE_DEV_EVENT_ADD ) {if (dev ==NULL ) { +/** +* bind the driver to the device +* before user's add processing +*/ + bus->bind_driver ( + uevent.devname, +"igb_uio" );return (_rte_dev_callback_process (NULL ,RTE_DEV_EVENT_ADD , uevent.devname));
Signature · 1 line
2.7.4
PATCH v15 1/2 pci_uio: add uevent hotplug failure handler in uio
when detect hot removal uevent of device, the device resource become invalid, in order to avoid unexpected usage of this resource, remap the device resource to be a fake memory, that would lead the application keep running well but not encounter system core dump.
---v15->v14:
delete find_by_name in bus ops, it is no used. use additional flag and original pci map resource function to replace of adding a new fixed memory mapping function.
--- app/test-pmd/testpmd.c | 4 +++ drivers/bus/pci/bsd/pci.c | 23 +++++++++++++++++ drivers/bus/pci/linux/pci.c | 33 +++++++++++++++++++++++++ drivers/bus/pci/pci_common.c | 21 ++++++++++++++++ drivers/bus/pci/pci_common_uio.c | 41 +++++++++++++++++++++++++++++++ drivers/bus/pci/private.h | 12 +++++++++ drivers/bus/pci/rte_bus_pci.h | 9 +++++++ drivers/bus/vdev/vdev.c | 7 ++++++ lib/librte_eal/bsdapp/eal/eal_dev.c | 8 ++++++ lib/librte_eal/common/eal_common_bus.c | 1 + lib/librte_eal/common/include/rte_bus.h | 15 +++++++++++ lib/librte_eal/common/include/rte_dev.h | 18 ++++++++++++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 34 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 5 ++++ 14 files changed, 231 insertions(+)
app/test-pmd/testpmd.c +4 -0
@@ -2079,6 +2079,10 @@ rmv_uevent_callback(void *arg)if (!in_hotplug_list (rte_eth_devices[port_id].device->name))return ; +/* do failure handler before stop and close the device */ +rte_dev_failure_handler (rte_eth_devices[port_id].device, + rte_eth_devices[port_id].data->kdrv); +stop_packet_forwarding ();stop_port (port_id);
drivers/bus/pci/bsd/pci.c +23 -0
@@ -97,6 +97,29 @@ rte_pci_unmap_device(struct rte_pci_device *dev) } } +/* re-map pci device */ +int +rte_pci_remap_device (struct rte_pci_device *dev) +{ +int ret; + +if (dev ==NULL ) +return -EINVAL ; + +switch (dev->kdrv) { +case RTE_KDRV_NIC_UIO : + ret =pci_uio_remap_resource (dev); +break ; +default : +RTE_LOG (DEBUG ,EAL , +" Not managed by a supported kernel driver, skipped\n" ); + ret =1 ; +break ; + } + +return ret; +} +void pci_uio_free_resource (struct rte_pci_device *dev,struct mapped_pci_resource *uio_res)
drivers/bus/pci/linux/pci.c +33 -0
@@ -116,6 +116,38 @@ rte_pci_unmap_device(struct rte_pci_device *dev) } } +/* Map pci device */ +int +rte_pci_remap_device (struct rte_pci_device *dev) +{ +int ret =-1 ; + +if (dev ==NULL ) +return -EINVAL ; + +switch (dev->kdrv) { +case RTE_KDRV_VFIO : +#ifdef VFIO_PRESENT +/* no thing to do */ +#endif +break ; +case RTE_KDRV_IGB_UIO : +case RTE_KDRV_UIO_GENERIC : +if (rte_eal_using_phys_addrs ()) { +/* map resources for devices that use uio */ + ret =pci_uio_remap_resource (dev); + } +break ; +default : +RTE_LOG (DEBUG ,EAL , +" Not managed by a supported kernel driver, skipped\n" ); + ret =1 ; +break ; + } + +return ret; +} +void *pci_find_max_end_va (void ) {
@@ -357,6 +389,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)rte_pci_add_device (dev); } + dev->device.state =RTE_DEV_PARSED ;return 0 ; }
drivers/bus/pci/pci_common.c +21 -0
@@ -253,6 +253,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)if (rc >0 )/* positive value means driver doesn't support it */ continue ; + dev->device.state =RTE_DEV_PARSED ;return 0 ; }return 1 ;
@@ -474,6 +475,25 @@ pci_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, }static int +pci_remap_device (struct rte_device *dev) +{ +struct rte_pci_device *pdev; +int ret; + +if (dev ==NULL ) +return -EINVAL ; + + pdev =RTE_DEV_TO_PCI (dev); + +/* remap resources for devices that use igb_uio */ + ret =rte_pci_remap_device (pdev); +if (ret !=0 ) +RTE_LOG (ERR ,EAL ,"failed to remap device %s" , + dev->name); +return ret; +} + +static int pci_plug (struct rte_device *dev) {return pci_probe_all_drivers (RTE_DEV_TO_PCI (dev));
@@ -503,6 +523,7 @@ struct rte_pci_bus rte_pci_bus = { .unplug = pci_unplug, .parse = pci_parse, .get_iommu_class = rte_pci_get_iommu_class, + .remap_device = pci_remap_device, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
drivers/bus/pci/pci_common_uio.c +41 -0
47 lines not on this page · raw message
drivers/bus/pci/private.h +12 -0
@@ -173,6 +173,18 @@ void pci_uio_free_resource(struct rte_pci_device *dev, struct mapped_pci_resource *uio_res);/** +* remap the pci uio resource.. +* +* @param dev +* Point to the struct rte pci device. +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +pci_uio_remap_resource (struct rte_pci_device *dev); + +/** * Map device memory to uio resource * * This function is private to EAL.
drivers/bus/pci/rte_bus_pci.h +9 -0
@@ -168,6 +168,15 @@ int rte_pci_map_device(struct rte_pci_device *dev);void rte_pci_unmap_device (struct rte_pci_device *dev);/** +* Remap this device +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +*/ +int rte_pci_remap_device (struct rte_pci_device *dev); + +/** * Dump the content of the PCI bus. * * @param f
drivers/bus/vdev/vdev.c +7 -0
@@ -400,6 +400,12 @@ vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, }static int +vdev_remap_device (struct rte_device *dev) +{ +RTE_SET_USED (dev); +return 0 ; +} +static int vdev_plug (struct rte_device *dev) {return vdev_probe_all_drivers (RTE_DEV_TO_VDEV (dev));
@@ -418,6 +424,7 @@ static struct rte_bus rte_vdev_bus = { .plug = vdev_plug, .unplug = vdev_unplug, .parse = vdev_parse, + .remap_device = vdev_remap_device, };RTE_REGISTER_BUS (vdev, rte_vdev_bus);
lib/librte_eal/bsdapp/eal/eal_dev.c +8 -0
@@ -31,3 +31,11 @@ rte_dev_event_monitor_stop(void)RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" );return -1 ; } + +int __rte_experimental +rte_dev_failure_handler (struct rte_device *dev, +enum rte_kernel_driver kdrv_type) +{ +RTE_LOG (ERR ,EAL ,"Not support device failure handler for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_bus.c +1 -0
@@ -53,6 +53,7 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->find_device);/* Buses supporting driver plug also require unplug. */ RTE_VERIFY (!bus->plug || bus->unplug); +RTE_VERIFY (bus->remap_device);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
lib/librte_eal/common/include/rte_bus.h +15 -0
@@ -168,6 +168,20 @@ typedef int (*rte_bus_unplug_t)(struct rte_device *dev);typedef int (*rte_bus_parse_t )(const char *name,void *addr);/** +* Implementation specific remap function which is responsible for remmaping +* devices on that bus from original share memory resource to a anonymous +* memory resource for the sake of device has been removal. +* +* @param dev +* Device pointer that was returned by a previous call to find_device. +* +* @return +* 0 on success. +* !0 on error. +*/ +typedef int (*rte_bus_remap_device_t )(struct rte_device *dev); + +/** * Bus scan policies */ enum rte_bus_scan_mode {
@@ -209,6 +223,7 @@ struct rte_bus {rte_bus_plug_t plug;/**< Probe single device for drivers */ rte_bus_unplug_t unplug;/**< Remove single device from driver */ rte_bus_parse_t parse;/**< Parse a device name */ +rte_bus_remap_device_t remap_device;/**< remap a device */ struct rte_bus_conf conf;/**< Bus configuration */ rte_bus_get_iommu_class_t get_iommu_class;/**< Get iommu class */ };
lib/librte_eal/common/include/rte_dev.h +18 -0
@@ -180,6 +180,7 @@ struct rte_device {const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */ +enum rte_dev_state state;/**< Device state */ };/**
@@ -405,4 +406,21 @@ rte_dev_event_monitor_start(void);*/ int __rte_experimentalrte_dev_event_monitor_stop (void); + +/** +* It can be used to do device failure handler to avoid +* system core dump when failure occur. +* +* @param dev +* The prointer to device structure. +* @param kdrv_type +* The specific kernel driver's type. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_failure_handler (struct rte_device *dev, +enum rte_kernel_driver kdrv_type);#endif /* _RTE_DEV_H_ */
lib/librte_eal/linuxapp/eal/eal_dev.c +34 -0
@@ -225,3 +225,37 @@ rte_dev_event_monitor_stop(void) monitor_no_started = true;return 0 ; } + +int __rte_experimental +rte_dev_failure_handler (struct rte_device *dev, +enum rte_kernel_driver kdrv_type) +{ +struct rte_bus *bus =rte_bus_find_by_device_name (dev->name); +int ret; + +switch (kdrv_type) { +case RTE_KDRV_IGB_UIO : +if ((!dev) || dev->state ==RTE_DEV_UNDEFINED ) +return -1 ; + dev->state =RTE_DEV_FAULT ; +/** +* remap the resource to be fake +* before user's removal processing +*/ + ret = bus->remap_device (dev); +if (ret) { +RTE_LOG (ERR ,EAL ,"Driver cannot remap the " +"device (%s)\n" , + dev->name); +return -1 ; + } +break ; +case RTE_KDRV_VFIO : +break ; +case RTE_KDRV_UIO_GENERIC : +break ; +default : +break ; + } +return 0 ; +}
lib/librte_eal/linuxapp/igb_uio/igb_uio.c +5 -0
@@ -350,6 +350,11 @@ igbuio_pci_release(struct uio_info *info, struct inode *inode)return 0 ; } +/* check if device has been remove before release */ +if ((&dev->dev.kobj)->state_remove_uevent_sent ==1 ) { +pr_info ("The device has been removed\n" ); +return -1 ; + }/* disable interrupts */ igbuio_pci_disable_interrupts (udev);
Signature · 1 line
2.7.4
PATCH v15 2/2 pci: add driver auto bind for hot insertion
Normally we use drivectl or dpdk-devbind.py to bind kernel driver before application running, so if we want to automatically driver binding after application run, need to implement a auto bind function, that would benefit for hot insertion case, when detect hot insertion uevent of device, user could auto bind the driver according some user policy and then attach device, let app running smoothly when hotplug behavior occur.
---v15->v14:
delete bind_driver in bus ops, replace to add bind_driver api in eal dev to let app directly call
--- app/test-pmd/testpmd.c | 17 ++++++++++++ lib/librte_eal/bsdapp/eal/eal_dev.c | 7 +++++ lib/librte_eal/common/include/rte_dev.h | 15 ++++++++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 49 +++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+)
app/test-pmd/testpmd.c +17 -0
@@ -2174,6 +2174,18 @@ in_hotplug_list(const char *dev_name)return false; } +static enum rte_kernel_driver +get_hotplug_driver (const char *dev_name) +{ +struct hotplug_request *hp_request =NULL ; + + TAILQ_FOREACH(hp_request, &hp_list, next) { +if (!strcmp (hp_request->dev_name, dev_name)) +return hp_request->dev_kdrv; + } +return -1 ; +} +static int hotplug_list_add (struct rte_device *device,enum rte_kernel_driver device_kdrv) {
@@ -2226,6 +2238,11 @@ eth_uevent_callback(char *device_name, enum rte_dev_event_type type, void *arg) "device removal\n");break ;case RTE_DEV_EVENT_ADD : +/** +* bind the driver to the device +* before process of hot plug adding device +*/ +rte_dev_bind_driver (dev_name,get_hotplug_driver (dev_name));if (rte_eal_alarm_set (100000 , add_uevent_callback, dev_name)) fprintf(stderr, "Could not set up deferred "
lib/librte_eal/bsdapp/eal/eal_dev.c +7 -0
@@ -33,6 +33,13 @@ rte_dev_event_monitor_stop(void) } int __rte_experimental +rte_dev_bind_driver (const char *dev_name,enum rte_kernel_driver kdrv_type) +{ +RTE_LOG (ERR ,EAL ,"Not support device bind driver for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimentalrte_dev_failure_handler (struct rte_device *dev,enum rte_kernel_driver kdrv_type) {
lib/librte_eal/common/include/rte_dev.h +15 -0
@@ -408,6 +408,21 @@ int __rte_experimentalrte_dev_event_monitor_stop (void);/** +* It can be used to bind a device to a specific type of driver. +* +* @param dev_name +* The device name. +* @param kdrv_type +* The specific kernel driver's type. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_bind_driver (const char *dev_name,enum rte_kernel_driver kdrv_type); + +/** * It can be used to do device failure handler to avoid * system core dump when failure occur. *
lib/librte_eal/linuxapp/eal/eal_dev.c +49 -0
55 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH V15 1/2] pci_uio: add uevent hotplug failure handler in uio
In reply to Jeff GuoWe shall split this patch to multiple patches.
- This helper function is not necessarily exposed to users. Whenever there is a device remove event, before invoking the callbacks, we do the remap.
- PCI related code shall be put into librte_pci.
- Personally, I don't think we shall add an ops for bus. We don't know if this necessary for all bus types; at least, vdev does not "remap". Even in future, we need to support new bus types, that's just internal changes, which is acceptable.
- If there is some issue in igb_uio, fix it in another patch.
Thanks,
Jianfeng
Quoted 447 lines · Jeff Guo
when detect hot removal uevent of device, the device resource become invalid, in order to avoid unexpected usage of this resource, remap the device resource to be a fake memory, that would lead the application keep running well but not encounter system core dump.
Signed-off-by Jeff Guo <[email protected]>---
v15->v14:
deletefind_by_namein bus ops, it is no used. use additional flag and original pci map resource function to replace of adding a new fixed memory mapping function.--- app/test-pmd/testpmd.c | 4 +++ drivers/bus/pci/bsd/pci.c | 23 +++++++++++++++++ drivers/bus/pci/linux/pci.c | 33 +++++++++++++++++++++++++ drivers/bus/pci/pci_common.c | 21 ++++++++++++++++ drivers/bus/pci/pci_common_uio.c | 41 +++++++++++++++++++++++++++++++ drivers/bus/pci/private.h | 12 +++++++++ drivers/bus/pci/rte_bus_pci.h | 9 +++++++ drivers/bus/vdev/vdev.c | 7 ++++++ lib/librte_eal/bsdapp/eal/eal_dev.c | 8 ++++++ lib/librte_eal/common/eal_common_bus.c | 1 + lib/librte_eal/common/include/rte_bus.h | 15 +++++++++++ lib/librte_eal/common/include/rte_dev.h | 18 ++++++++++++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 34 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 5 ++++ 14 files changed, 231 insertions(+)app/test-pmd/testpmd.c +4
-0@@ -2079,6 +2079,10 @@ rmv_uevent_callback(void *arg)if (!in_hotplug_list (rte_eth_devices[port_id].device->name))return ; +/* do failure handler before stop and close the device */ +rte_dev_failure_handler (rte_eth_devices[port_id].device, + rte_eth_devices[port_id].data->kdrv); +stop_packet_forwarding ();stop_port (port_id);drivers/bus/pci/bsd/pci.c +23
-0@@ -97,6 +97,29 @@ rte_pci_unmap_device(struct rte_pci_device *dev) } } +/* re-map pci device */ +int +rte_pci_remap_device (struct rte_pci_device *dev) +{ +int ret; + +if (dev ==NULL ) +return -EINVAL ; + +switch (dev->kdrv) { +case RTE_KDRV_NIC_UIO : + ret =pci_uio_remap_resource (dev); +break ; +default : +RTE_LOG (DEBUG ,EAL , +" Not managed by a supported kernel driver, skipped\n" ); + ret =1 ; +break ; + } + +return ret; +} +void pci_uio_free_resource (struct rte_pci_device *dev,struct mapped_pci_resource *uio_res)drivers/bus/pci/linux/pci.c +33
-0@@ -116,6 +116,38 @@ rte_pci_unmap_device(struct rte_pci_device *dev) } } +/* Map pci device */ +int +rte_pci_remap_device (struct rte_pci_device *dev) +{ +int ret =-1 ; + +if (dev ==NULL ) +return -EINVAL ; + +switch (dev->kdrv) { +case RTE_KDRV_VFIO : +#ifdef VFIO_PRESENT +/* no thing to do */ +#endif +break ; +case RTE_KDRV_IGB_UIO : +case RTE_KDRV_UIO_GENERIC : +if (rte_eal_using_phys_addrs ()) { +/* map resources for devices that use uio */ + ret =pci_uio_remap_resource (dev); + } +break ; +default : +RTE_LOG (DEBUG ,EAL , +" Not managed by a supported kernel driver, skipped\n" ); + ret =1 ; +break ; + } + +return ret; +} +void *pci_find_max_end_va (void ) {@@ -357,6 +389,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)rte_pci_add_device (dev); } + dev->device.state =RTE_DEV_PARSED ;return 0 ; }drivers/bus/pci/pci_common.c +21
-0@@ -253,6 +253,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)if (rc >0 )/* positive value means driver doesn't support it */ continue ; + dev->device.state =RTE_DEV_PARSED ;return 0 ; }return 1 ;@@ -474,6 +475,25 @@ pci_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, }static int +pci_remap_device (struct rte_device *dev) +{ +struct rte_pci_device *pdev; +int ret; + +if (dev ==NULL ) +return -EINVAL ; + + pdev =RTE_DEV_TO_PCI (dev); + +/* remap resources for devices that use igb_uio */ + ret =rte_pci_remap_device (pdev); +if (ret !=0 ) +RTE_LOG (ERR ,EAL ,"failed to remap device %s" , + dev->name); +return ret; +} + +static int pci_plug (struct rte_device *dev) {return pci_probe_all_drivers (RTE_DEV_TO_PCI (dev));@@ -503,6 +523,7 @@ struct rte_pci_bus rte_pci_bus = { .unplug = pci_unplug, .parse = pci_parse, .get_iommu_class = rte_pci_get_iommu_class, + .remap_device = pci_remap_device, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),drivers/bus/pci/pci_common_uio.c +41
-0@@ -146,6 +146,47 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res) } } +/* remap the PCI resource of a PCI device in private virtual memory */ +int +pci_uio_remap_resource (struct rte_pci_device *dev) +{ +int i; +uint64_t phaddr; +void *map_address; + +if (dev ==NULL ) +return -1 ; + +close (dev->intr_handle.fd); +if (dev->intr_handle.uio_cfg_fd >=0 ) { +close (dev->intr_handle.uio_cfg_fd); + dev->intr_handle.uio_cfg_fd =-1 ; + } + + dev->intr_handle.fd =-1 ; + dev->intr_handle.type =RTE_INTR_HANDLE_UNKNOWN ; + +/* Map all BARs */ +for (i =0 ; i !=PCI_MAX_RESOURCE ; i++) { +/* skip empty BAR */ + phaddr = dev->mem_resource[i].phys_addr; +if (phaddr ==0 ) +continue ; +pci_unmap_resource (dev->mem_resource[i].addr, + (size_t )dev->mem_resource[i].len); + map_address =pci_map_resource ( + dev->mem_resource[i].addr,-1 ,0 , + (size_t )dev->mem_resource[i].len, +MAP_ANONYMOUS ); +if (map_address ==MAP_FAILED ) +return -1 ; +memset (map_address,0xFF , (size_t )dev->mem_resource[i].len); + dev->mem_resource[i].addr = map_address; + } + +return 0 ; +} +static struct mapped_pci_resource *pci_uio_find_resource (struct rte_pci_device *dev) {drivers/bus/pci/private.h +12
-0@@ -173,6 +173,18 @@ void pci_uio_free_resource(struct rte_pci_device *dev, struct mapped_pci_resource *uio_res);/** +* remap the pci uio resource.. +* +* @param dev +* Point to the struct rte pci device. +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +pci_uio_remap_resource (struct rte_pci_device *dev); + +/** * Map device memory to uio resource * * This function is private to EAL. drivers/bus/pci/rte_bus_pci.h +9
-0@@ -168,6 +168,15 @@ int rte_pci_map_device(struct rte_pci_device *dev);void rte_pci_unmap_device (struct rte_pci_device *dev);/** +* Remap this device +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +*/ +int rte_pci_remap_device (struct rte_pci_device *dev); + +/** * Dump the content of the PCI bus. * * @param f drivers/bus/vdev/vdev.c +7
-0@@ -400,6 +400,12 @@ vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, }static int +vdev_remap_device (struct rte_device *dev) +{ +RTE_SET_USED (dev); +return 0 ; +} +static int vdev_plug (struct rte_device *dev) {return vdev_probe_all_drivers (RTE_DEV_TO_VDEV (dev));@@ -418,6 +424,7 @@ static struct rte_bus rte_vdev_bus = { .plug = vdev_plug, .unplug = vdev_unplug, .parse = vdev_parse, + .remap_device = vdev_remap_device, };RTE_REGISTER_BUS (vdev, rte_vdev_bus);lib/librte_eal/bsdapp/eal/eal_dev.c +8
-0@@ -31,3 +31,11 @@ rte_dev_event_monitor_stop(void)RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" );return -1 ; } + +int __rte_experimental +rte_dev_failure_handler (struct rte_device *dev, +enum rte_kernel_driver kdrv_type) +{ +RTE_LOG (ERR ,EAL ,"Not support device failure handler for FreeBSD\n" ); +return -1 ; +}lib/librte_eal/common/eal_common_bus.c +1
-0@@ -53,6 +53,7 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->find_device);/* Buses supporting driver plug also require unplug. */ RTE_VERIFY (!bus->plug || bus->unplug); +RTE_VERIFY (bus->remap_device);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);lib/librte_eal/common/include/rte_bus.h +15
-0@@ -168,6 +168,20 @@ typedef int (*rte_bus_unplug_t)(struct rte_device *dev);typedef int (*rte_bus_parse_t )(const char *name,void *addr);/** +* Implementation specific remap function which is responsible for remmaping +* devices on that bus from original share memory resource to a anonymous +* memory resource for the sake of device has been removal. +* +* @param dev +* Device pointer that was returned by a previous call to find_device. +* +* @return +* 0 on success. +* !0 on error. +*/ +typedef int (*rte_bus_remap_device_t )(struct rte_device *dev); + +/** * Bus scan policies */ enum rte_bus_scan_mode {@@ -209,6 +223,7 @@ struct rte_bus {rte_bus_plug_t plug;/**< Probe single device for drivers */ rte_bus_unplug_t unplug;/**< Remove single device from driver */ rte_bus_parse_t parse;/**< Parse a device name */ +rte_bus_remap_device_t remap_device;/**< remap a device */ struct rte_bus_conf conf;/**< Bus configuration */ rte_bus_get_iommu_class_t get_iommu_class;/**< Get iommu class */ };lib/librte_eal/common/include/rte_dev.h +18
-0@@ -180,6 +180,7 @@ struct rte_device {const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */ +enum rte_dev_state state;/**< Device state */ };/** @@ -405,4 +406,21 @@ rte_dev_event_monitor_start(void);*/ int __rte_experimentalrte_dev_event_monitor_stop (void); + +/** +* It can be used to do device failure handler to avoid +* system core dump when failure occur. +* +* @param dev +* The prointer to device structure. +* @param kdrv_type +* The specific kernel driver's type. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_failure_handler (struct rte_device *dev, +enum rte_kernel_driver kdrv_type);#endif /* _RTE_DEV_H_ */ lib/librte_eal/linuxapp/eal/eal_dev.c +34
-0@@ -225,3 +225,37 @@ rte_dev_event_monitor_stop(void) monitor_no_started = true;return 0 ; } + +int __rte_experimental +rte_dev_failure_handler (struct rte_device *dev, +enum rte_kernel_driver kdrv_type) +{ +struct rte_bus *bus =rte_bus_find_by_device_name (dev->name); +int ret; + +switch (kdrv_type) { +case RTE_KDRV_IGB_UIO : +if ((!dev) || dev->state ==RTE_DEV_UNDEFINED ) +return -1 ; + dev->state =RTE_DEV_FAULT ; +/** +* remap the resource to be fake +* before user's removal processing +*/ + ret = bus->remap_device (dev); +if (ret) { +RTE_LOG (ERR ,EAL ,"Driver cannot remap the " +"device (%s)\n" , + dev->name); +return -1 ; + } +break ; +case RTE_KDRV_VFIO : +break ; +case RTE_KDRV_UIO_GENERIC : +break ; +default : +break ; + } +return 0 ; +}lib/librte_eal/linuxapp/igb_uio/igb_uio.c +5
-0@@ -350,6 +350,11 @@ igbuio_pci_release(struct uio_info *info, struct inode *inode)return 0 ; } +/* check if device has been remove before release */ +if ((&dev->dev.kobj)->state_remove_uevent_sent ==1 ) { +pr_info ("The device has been removed\n" ); +return -1 ; + }/* disable interrupts */ igbuio_pci_disable_interrupts (udev);
Re: [PATCH v6 0/2] add uevent monitor for hot plug
In reply to Jeff GuoHello,
I would like to apply this patch in order to review it.
Trying to apply it on 17.11 (and latest) fails due to missing lib/librte_eal/common/eal_common_vdev.c Trying to apply it on 17.08.1 fails on missing drivers/bus/pci/bsd/pci.c file
So, on what DPDK version should I apply it ?
Or maybe there is a bunch of other patches I have to apply in order to use this patch ?
Thanks
Moti H.
Quoted 124 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Jeff Guo
Sent: Wednesday, November 1, 2017 10:17 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; Thomas Monjalon <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [dpdk-dev] [PATCH v6 0/2] add uevent monitor for hot plugSo far, about hot plug in dpdk, we already have hot plug add/remove api and fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general event api, since the interrupt event, which hot plug related with, is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring which will be useful. remove@/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:8 4:00.2/uio/uio2
ACTION=remove DEVPATH=/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:
84:00.2/uio/uio2
SUBSYSTEM=uio
MAJOR=243
MINOR=2
DEVNAME=uio2
SEQNUM=11366b.add uevent monitoring machanism:
add several general api to enable uevent monitoring.c.add common uevent handler and uevent failure handler uevent of device should be handler at bus or device layer, and the memory read and write failure when hot removal should be handle correctly before detach behaviors.
d.show example how to use uevent monitor enable uevent monitoring in testpmd or fail-safe to show usage.
patchset history:
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug. 2.modify to manage event callback in each device.
3.fix some system hung issue whenigb_uiorelease.
4.modify the pci part to the bus-pci base on the bus rework. 5.add hot plug policy in app, show example to use hotplug list to manage to deside which device need to hot plug.
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer. 2.Redefine the eal device API for common, and distinguish between linux and bsd 3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device.
5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue 7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables ofhotplug_fd, adduevent_fdinrte_intr_handleto let each pci device self maintain it fd, to fix dual device fd issue. 2.refine some typo error.Jeff Guo (2):
eal: add uevent monitor for hot plug
app/testpmd: use uevent to monitor hotplugapp/test-pmd/testpmd.c | 172 ++++++++++ app/test-pmd/testpmd.h | 9 + drivers/bus/pci/bsd/pci.c | 23 ++ drivers/bus/pci/linux/pci.c | 34 ++ drivers/bus/pci/linux/pci_init.h | 1 + drivers/bus/pci/pci_common.c | 42 +++ drivers/bus/pci/pci_common_uio.c | 28 ++ drivers/bus/pci/private.h | 12 + drivers/bus/pci/rte_bus_pci.h | 9 + lib/librte_eal/bsdapp/eal/eal_dev.c | 64 ++++ .../bsdapp/eal/include/exec-env/rte_dev.h | 105 ++++++ lib/librte_eal/common/eal_common_bus.c | 29 ++ lib/librte_eal/common/eal_common_dev.c | 222 +++++++++++++ lib/librte_eal/common/eal_common_vdev.c | 27 ++ lib/librte_eal/common/include/rte_bus.h | 51 +++ lib/librte_eal/common/include/rte_dev.h | 107 ++++++- lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_dev.c | 353 +++++++++++++++++++++ .../linuxapp/eal/include/exec-env/rte_dev.h | 105 ++++++ lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 6 + lib/librte_pci/rte_pci.c | 20 ++ lib/librte_pci/rte_pci.h | 17 + 22 files changed, 1437 insertions(+), 2 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h--
2.7.4
Re: [PATCH v6 0/2] add uevent monitor for hot plug
Hello Moti,
Quoted 3 lines · Mordechay Haimovsky
Hello,
I would like to apply this patch in order to review it.
In absence of answer from Jeff,
Those two paths were modified during the 17.08 release: both pci and vdev buses have been moved to drivers/bus.
Quoted 3 lines
Trying to apply it on 17.11 (and latest) fails due to missing
lib/librte_eal/common/eal_common_vdev.cTrying to apply it on 17.08.1 fails on missingdrivers/bus/pci/bsd/pci.cfile
Only the pci bus move was integrated by Jeff to this version of the udev monitor. The vdev bus move however came later and should be rebased upon.
Quoted 3 lines
So, on what DPDK version should I apply it ?
Or maybe there is a bunch of other patches I have to apply in order to use this patch ?
You should apply it on 17.11 IMO.
Either you take upon yourself to make it work with the new tree, or wait for Jeff to send a new version.
Signature · 2 lines
Gaëtan Rivet 6WIND
Re: [PATCH v6 0/2] add uevent monitor for hot plug
Moti, Hello and sorry for be reply late until now, definitely as gaetan said that there might be some change after the version, anyway I will create a new version to benefit you all to review and further test.
Best regards,
Jeff Guo
-----Original Message-----
From: Gaëtan Rivet [mailto:[email protected]]
Sent: Thursday, December 14, 2017 6:21 PM
To: Mordechay Haimovsky <[email protected]>
Cc: Guo, Jia <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 0/2] add uevent monitor for hot plug
Hello Moti,
Quoted 3 lines · Mordechay Haimovsky
Hello,
I would like to apply this patch in order to review it.
In absence of answer from Jeff,
Those two paths were modified during the 17.08 release: both pci and vdev buses have been moved to drivers/bus.
Quoted 4 lines
Trying to apply it on 17.11 (and latest) fails due to missing
lib/librte_eal/common/eal_common_vdev.cTrying to apply it on 17.08.1 fails on missingdrivers/bus/pci/bsd/pci.cfile
Only the pci bus move was integrated by Jeff to this version of the udev monitor. The vdev bus move however came later and should be rebased upon.
Quoted 3 lines
So, on what DPDK version should I apply it ?
Or maybe there is a bunch of other patches I have to apply in order to use this patch ?
You should apply it on 17.11 IMO.
Either you take upon yourself to make it work with the new tree, or wait for Jeff to send a new version.
--
Gaëtan Rivet
6WIND
Re: [PATCH v6 0/2] add uevent monitor for hot plug
Thanks Jeff,
Do you have an estimation on when will these patches be ready ?
Moti H.
Quoted 56 lines
-----Original Message-----
From: Guo, Jia [mailto:[email protected]]
Sent: Friday, December 22, 2017 2:16 AM
To: Gaëtan Rivet <[email protected]>; Mordechay Haimovsky <[email protected]>
Cc: [email protected]
Subject: RE: [dpdk-dev] [PATCH v6 0/2] add uevent monitor for hot plugMoti, Hello and sorry for be reply late until now, definitely as gaetan said that there might be some change after the version, anyway I will create a new version to benefit you all to review and further test.
Best regards,
Jeff Guo-----Original Message-----
From: Gaëtan Rivet [mailto:[email protected]]
Sent: Thursday, December 14, 2017 6:21 PM
To: Mordechay Haimovsky <[email protected]>
Cc: Guo, Jia <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 0/2] add uevent monitor for hot plugHello Moti,
Quoted 3 lines · Mordechay Haimovsky
Hello,
I would like to apply this patch in order to review it.In absence of answer from Jeff,
Those two paths were modified during the 17.08 release: both pci and vdev buses have been moved to
drivers/bus.Quoted 1 line
Trying to apply it on 17.11 (and latest) fails due to missing
lib/librte_eal/common/eal_common_vdev.cQuoted 3 lines
Trying to apply it on 17.08.1 fails on missing
drivers/bus/pci/bsd/pci.cfileOnly the pci bus move was integrated by Jeff to this version of the udev monitor. The vdev bus move however came later and should be rebased upon.
Quoted 2 lines
So, on what DPDK version should I apply it ?
Or maybe there is a bunch of other patches I have to apply in order to usethis patch ?
Quoted 1 line
You should apply it on 17.11 IMO.
Either you take upon yourself to make it work with the new tree, or wait for Jeff to send a new version.--
Gaëtan Rivet
6WIND
Re: [PATCH v6 0/2] add uevent monitor for hot plug
hi,moti
please see v7 patch set , thanks.
Quoted 57 lines · Mordechay Haimovsky
Thanks Jeff,
Do you have an estimation on when will these patches be ready ?Moti H.
Quoted 52 lines
-----Original Message-----
From: Guo, Jia [mailto:[email protected]]
Sent: Friday, December 22, 2017 2:16 AM
To: Gaëtan Rivet <[email protected]>; Mordechay Haimovsky <[email protected]>
Cc: [email protected]
Subject: RE: [dpdk-dev] [PATCH v6 0/2] add uevent monitor for hot plugMoti, Hello and sorry for be reply late until now, definitely as gaetan said that there might be some change after the version, anyway I will create a new version to benefit you all to review and further test.
Best regards,
Jeff Guo-----Original Message-----
From: Gaëtan Rivet [mailto:[email protected]]
Sent: Thursday, December 14, 2017 6:21 PM
To: Mordechay Haimovsky <[email protected]>
Cc: Guo, Jia <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 0/2] add uevent monitor for hot plugHello Moti,
Quoted 3 lines · Mordechay Haimovsky
Hello,
I would like to apply this patch in order to review it.In absence of answer from Jeff,
Those two paths were modified during the 17.08 release: both pci and vdev buses have been moved to
drivers/bus.Quoted 1 line
Trying to apply it on 17.11 (and latest) fails due to missing
lib/librte_eal/common/eal_common_vdev.cQuoted 3 lines
Trying to apply it on 17.08.1 fails on missing
drivers/bus/pci/bsd/pci.cfileOnly the pci bus move was integrated by Jeff to this version of the udev monitor. The vdev bus move however came later and should be rebased upon.
Quoted 2 lines
So, on what DPDK version should I apply it ?
Or maybe there is a bunch of other patches I have to apply in order to usethis patch ?
You should apply it on 17.11 IMO.
Either you take upon yourself to make it work with the new tree, or wait for Jeff to send a new version.--
Gaëtan Rivet
6WIND
Re: [PATCH v5 0/2] add uevent monitor for hot plug
In reply to Jeff GuoQuoted 11 lines · Jeff Guo
So far, about hot plug in dpdk, we already have hot plug add/remove api and fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general event api, since the interrupt event, which hot plug related with, is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Quoted 7 lines
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
Jeff,
We already have libudev. Sorry for catching it that late but I don't believe that replicating the uevent handling belongs in the DPDK. You might want to look into a helper to find the corresponding rte_device for a given devnode though.
Also the remap_device function should get removed. There is no synchronization between the polling for the uevent and the rest of the drivers. Therefore there is no guarantee that you can remap to "safe" memory. You should fix the drivers instead.
Thanks,
Jan
Quoted 77 lines
a.The uevent message form FD monitoring which will be useful. remove@/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 ACTION=remove DEVPATH=/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 SUBSYSTEM=uio
MAJOR=243
MINOR=2
DEVNAME=uio2
SEQNUM=11366b.add uevent monitoring machanism:
add several general api to enable uevent monitoring.c.add common uevent handler and uevent failure handler
uevent of device should be handler at bus or device layer, and the memory read and write failure when hot removal should be handle correctly before detach behaviors.d.show example how to use uevent monitor
enable uevent monitoring in testpmd or fail-safe to show usage.patchset history:
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer.
2.Redefine the eal device API for common, and distinguish between linux and bsd
3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device. 5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue
7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables ofhotplug_fd, adduevent_fdinrte_intr_handleto let each pci device self maintain it fd, to fix dual device fd issue.
2.refine some typo error.Jeff Guo (2):
eal: add uevent monitor for hot plug
app/testpmd: use uevent to monitor hot removalapp/test-pmd/testpmd.c | 90 ++++++ lib/librte_eal/bsdapp/eal/eal_dev.c | 64 ++++ .../bsdapp/eal/include/exec-env/rte_dev.h | 105 ++++++ lib/librte_eal/common/eal_common_bus.c | 31 ++ lib/librte_eal/common/eal_common_dev.c | 223 ++++++++++++- lib/librte_eal/common/eal_common_pci.c | 69 +++- lib/librte_eal/common/eal_common_pci_uio.c | 31 +- lib/librte_eal/common/eal_common_vdev.c | 29 +- lib/librte_eal/common/eal_private.h | 13 +- lib/librte_eal/common/include/rte_bus.h | 52 +++ lib/librte_eal/common/include/rte_dev.h | 102 +++++- lib/librte_eal/common/include/rte_pci.h | 26 ++ lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_dev.c | 351 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 33 ++ .../linuxapp/eal/include/exec-env/rte_dev.h | 105 ++++++ 16 files changed, 1318 insertions(+), 9 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h--
2.7.4
Re: [PATCH v5 0/2] add uevent monitor for hot plug
hi,jan
Quoted 17 lines · Jan Blunck
Quoted 16 lines · Jeff Guo
So far, about hot plug in dpdk, we already have hot plug add/remove api and fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general event api, since the interrupt event, which hot plug related with, is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
Quoted 8 lines
Quoted 2 lines
The idea is comming as bellow.
Jeff,
We already have libudev. Sorry for catching it that late but I don't believe that replicating the uevent handling belongs in the DPDK. You might want to look into a helper to find the corresponding
rte_devicefor a given devnode though.
i think the kobject netlink message could be used by bunch of app,such as customize hotplug app or libudev, off course it could used by dpdk, and since it would related with some different behaviors of diversity drivers and user space complex device management. so aim to let dpdk user easy to develop hotplug , we want to offload the monitoring work and coherenceprocession into eal layer.
Quoted 4 lines
Also the
remap_devicefunction should get removed. There is no synchronization between the polling for the uevent and the rest of the drivers. Therefore there is no guarantee that you can remap to "safe" memory. You should fix the drivers instead.
agree with you that would no have sync guarantee, maybe we could add the sigaction or other sync condition in drivers to handle the signal bus error when unsafe memory control occur. but i think it is the sync problem , would not affect the remap_device functional, and would not affect to use a common bus layer memory control to let caller to use to remap to "safe". am i right? also i want to collect info that it there any other conversion about that remap_device api?
Quoted 80 lines
Thanks,
JanQuoted 77 lines
a.The uevent message form FD monitoring which will be useful. remove@/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 ACTION=remove DEVPATH=/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 SUBSYSTEM=uio
MAJOR=243
MINOR=2
DEVNAME=uio2
SEQNUM=11366b.add uevent monitoring machanism:
add several general api to enable uevent monitoring.c.add common uevent handler and uevent failure handler
uevent of device should be handler at bus or device layer, and the memory read and write failure when hot removal should be handle correctly before detach behaviors.d.show example how to use uevent monitor
enable uevent monitoring in testpmd or fail-safe to show usage.patchset history:
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer.
2.Redefine the eal device API for common, and distinguish between linux and bsd
3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device. 5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue
7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables ofhotplug_fd, adduevent_fdinrte_intr_handleto let each pci device self maintain it fd, to fix dual device fd issue.
2.refine some typo error.Jeff Guo (2):
eal: add uevent monitor for hot plug
app/testpmd: use uevent to monitor hot removalapp/test-pmd/testpmd.c | 90 ++++++ lib/librte_eal/bsdapp/eal/eal_dev.c | 64 ++++ .../bsdapp/eal/include/exec-env/rte_dev.h | 105 ++++++ lib/librte_eal/common/eal_common_bus.c | 31 ++ lib/librte_eal/common/eal_common_dev.c | 223 ++++++++++++- lib/librte_eal/common/eal_common_pci.c | 69 +++- lib/librte_eal/common/eal_common_pci_uio.c | 31 +- lib/librte_eal/common/eal_common_vdev.c | 29 +- lib/librte_eal/common/eal_private.h | 13 +- lib/librte_eal/common/include/rte_bus.h | 52 +++ lib/librte_eal/common/include/rte_dev.h | 102 +++++- lib/librte_eal/common/include/rte_pci.h | 26 ++ lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_dev.c | 351 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 33 ++ .../linuxapp/eal/include/exec-env/rte_dev.h | 105 ++++++ 16 files changed, 1318 insertions(+), 9 deletions(-)create mode 100644
lib/librte_eal/bsdapp/eal/eal_dev.c
create mode 100644lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.hcreate mode 100644lib/librte_eal/linuxapp/eal/eal_dev.ccreate mode 100644lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h--
2.7.4
PATCH v3 2/2 net/i40e: add hot plug monitor in i40e
In reply to Jeff GuoFrom: "Guo, Jia" <[email protected]>
This patch enable the hot plug feature in i40e, by monitoring the hot plug uevent of the device. When remove event got, call the app callback function to handle the detach process.
---v3->v2: refine the return issue if device remove
--- drivers/net/i40e/i40e_ethdev.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/net/i40e/i40e_ethdev.c +19 -0
@@ -1283,6 +1283,7 @@ static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)/* enable uio intr after callback register */ rte_intr_enable (intr_handle); +/* * Add an ethertype filter to drop all flow control frames transmitted * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
@@ -5832,11 +5833,29 @@ struct i40e_vsi * {struct rte_eth_dev *dev = (struct rte_eth_dev *)param;struct i40e_hw *hw =I40E_DEV_PRIVATE_TO_HW (dev->data->dev_private); +struct rte_uevent event;uint32_t icr0; +struct rte_pci_device *pci_dev; +struct rte_intr_handle *intr_handle; + + pci_dev =RTE_ETH_DEV_TO_PCI (dev); + intr_handle = &pci_dev->intr_handle;/* Disable interrupt */ i40e_pf_disable_irq0 (hw); +/* check device uevent */ +if (rte_uevent_get (intr_handle->uevent_fd, &event) ==0 ) { +if (event.subsystem ==RTE_UEVENT_SUBSYSTEM_UIO ) { +if (event.action ==RTE_UEVENT_REMOVE ) { +_rte_eth_dev_callback_process (dev, +RTE_ETH_EVENT_INTR_RMV ,NULL ); +return ; + } + } + goto done; + } +/* read out interrupt causes */ icr0 =I40E_READ_REG (hw,I40E_PFINT_ICR0 );
Signature · 1 line
1.8.3.1
Re: [PATCH v3 2/2] net/i40e: add hot plug monitor in i40e
Quoted 13 lines
-----Original Message-----
From: Guo, Jia
Sent: Thursday, June 29, 2017 1:02 PM
To: Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>
Cc: [email protected]; Guo, Jia <[email protected]>; Richardson, Bruce <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; Yigit, Ferruh <[email protected]>
Subject: [PATCH v3 2/2] net/i40e: add hot plug monitor in i40e
Quoted 7 lines
From: "Guo, Jia" <[email protected]>
This patch enable the hot plug feature in i40e, by monitoring the hot plug uevent of the device. When remove event got, call the app callback function to handle the detach process.
Signed-off-by Guo, Jia <[email protected]>
Re: [PATCH v3 2/2] net/i40e: add hot plug monitor in i40e
In reply to Jeff Guo29/06/2017 07:01, Jeff Guo:
Quoted 26 lines
drivers/net/i40e/i40e_ethdev.c +8
-0@@ -1283,6 +1283,7 @@ static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)/* enable uio intr after callback register */ rte_intr_enable (intr_handle); +/* * Add an ethertype filter to drop all flow control frames transmitted * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC @@ -5832,11 +5833,29 @@ struct i40e_vsi * {struct rte_eth_dev *dev = (struct rte_eth_dev *)param;struct i40e_hw *hw =I40E_DEV_PRIVATE_TO_HW (dev->data->dev_private); +struct rte_uevent event;uint32_t icr0; +struct rte_pci_device *pci_dev; +struct rte_intr_handle *intr_handle; + + pci_dev =RTE_ETH_DEV_TO_PCI (dev); + intr_handle = &pci_dev->intr_handle;/* Disable interrupt */ i40e_pf_disable_irq0 (hw); +/* check device uevent */
drivers/net/i40e/i40e_ethdev.c struct i40e_vsi * · line 5857
Quoted 10 lines
drivers/net/i40e/i40e_ethdev.c +10
-0+if (rte_uevent_get (intr_handle->uevent_fd, &event) ==0 ) { +if (event.subsystem ==RTE_UEVENT_SUBSYSTEM_UIO ) { +if (event.action ==RTE_UEVENT_REMOVE ) { +_rte_eth_dev_callback_process (dev, +RTE_ETH_EVENT_INTR_RMV ,NULL ); +return ; + } + } + goto done; + }
There is nothing specific to i40e in this patch. It seems wrong to add such generic code in every drivers.
Re: [PATCH v3 2/2] net/i40e: add hot plug monitor in i40e
07/07/2017 09:56, Thomas Monjalon:
Quoted 26 lines
29/06/2017 07:01, Jeff Guo:
Quoted 25 lines
drivers/net/i40e/i40e_ethdev.c +7
-0@@ -1283,6 +1283,7 @@ static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)/* enable uio intr after callback register */ rte_intr_enable (intr_handle); +/* * Add an ethertype filter to drop all flow control frames transmitted * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC @@ -5832,11 +5833,29 @@ struct i40e_vsi * {struct rte_eth_dev *dev = (struct rte_eth_dev *)param;struct i40e_hw *hw =I40E_DEV_PRIVATE_TO_HW (dev->data->dev_private); +struct rte_uevent event;uint32_t icr0; +struct rte_pci_device *pci_dev; +struct rte_intr_handle *intr_handle; + + pci_dev =RTE_ETH_DEV_TO_PCI (dev); + intr_handle = &pci_dev->intr_handle;/* Disable interrupt */ i40e_pf_disable_irq0 (hw);
Quoted 14 lines
drivers/net/i40e/i40e_ethdev.c struct i40e_vsi * · line 5857
Quoted 11 lines
drivers/net/i40e/i40e_ethdev.c +11
-0+/* check device uevent */ +if (rte_uevent_get (intr_handle->uevent_fd, &event) ==0 ) { +if (event.subsystem ==RTE_UEVENT_SUBSYSTEM_UIO ) { +if (event.action ==RTE_UEVENT_REMOVE ) { +_rte_eth_dev_callback_process (dev, +RTE_ETH_EVENT_INTR_RMV ,NULL ); +return ; + } + } + goto done; + }There is nothing specific to i40e in this patch. It seems wrong to add such generic code in every drivers.
It should be managed at bus layer and not be specific to ethdev only.
Re: [PATCH v3 2/2] net/i40e: add hot plug monitor in i40e
Quoted 40 lines · Thomas Monjalon
07/07/2017 09:56, Thomas Monjalon:
Quoted 26 lines
29/06/2017 07:01, Jeff Guo:
Quoted 25 lines
drivers/net/i40e/i40e_ethdev.c +7
-0@@ -1283,6 +1283,7 @@ static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)/* enable uio intr after callback register */ rte_intr_enable (intr_handle); +/* * Add an ethertype filter to drop all flow control frames transmitted * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC @@ -5832,11 +5833,29 @@ struct i40e_vsi * {struct rte_eth_dev *dev = (struct rte_eth_dev *)param;struct i40e_hw *hw =I40E_DEV_PRIVATE_TO_HW (dev->data->dev_private); +struct rte_uevent event;uint32_t icr0; +struct rte_pci_device *pci_dev; +struct rte_intr_handle *intr_handle; + + pci_dev =RTE_ETH_DEV_TO_PCI (dev); + intr_handle = &pci_dev->intr_handle;/* Disable interrupt */ i40e_pf_disable_irq0 (hw);Quoted 13 lines
drivers/net/i40e/i40e_ethdev.c struct i40e_vsi * · line 5857
Quoted 11 lines
drivers/net/i40e/i40e_ethdev.c +11
-0+/* check device uevent */ +if (rte_uevent_get (intr_handle->uevent_fd, &event) ==0 ) { +if (event.subsystem ==RTE_UEVENT_SUBSYSTEM_UIO ) { +if (event.action ==RTE_UEVENT_REMOVE ) { +_rte_eth_dev_callback_process (dev, +RTE_ETH_EVENT_INTR_RMV ,NULL ); +return ; + } + }if + goto done; + }There is nothing specific to i40e in this patch. It seems wrong to add such generic code in every drivers.
Quoted 1 line
It should be managed at bus layer and not be specific to ethdev only.
if all could managed at bus layer might also be what i want to see,
but that would not so economical at currently. because of the event need to exposure to driver to use app's callback to handle it by detach/attach device. mlx driver also go through this path to show the rmv event usege. we just add uevent for pci uio device. Anyway, i think the uevent must be useful for future PF/VFIO live migration. if there are not other concern about the other patch that added uevent api in eal([PATCH v3 1/2] eal: add uevent api for hot plug), i suggest to merge it at first. Then we could go next to enhancement it with the 6wind hot plug feature.
Re: [PATCH v3 2/2] net/i40e: add hot plug monitor in i40e
07/07/2017 16:08, Guo, Jia:
Quoted 43 lines · Thomas Monjalon
Quoted 40 lines
07/07/2017 09:56, Thomas Monjalon:
Quoted 26 lines
29/06/2017 07:01, Jeff Guo:
Quoted 25 lines
drivers/net/i40e/i40e_ethdev.c +7
-0@@ -1283,6 +1283,7 @@ static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)/* enable uio intr after callback register */ rte_intr_enable (intr_handle); +/* * Add an ethertype filter to drop all flow control frames transmitted * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC @@ -5832,11 +5833,29 @@ struct i40e_vsi * {struct rte_eth_dev *dev = (struct rte_eth_dev *)param;struct i40e_hw *hw =I40E_DEV_PRIVATE_TO_HW (dev->data->dev_private); +struct rte_uevent event;uint32_t icr0; +struct rte_pci_device *pci_dev; +struct rte_intr_handle *intr_handle; + + pci_dev =RTE_ETH_DEV_TO_PCI (dev); + intr_handle = &pci_dev->intr_handle;/* Disable interrupt */ i40e_pf_disable_irq0 (hw);Quoted 13 lines
drivers/net/i40e/i40e_ethdev.c struct i40e_vsi * · line 5857
Quoted 11 lines
drivers/net/i40e/i40e_ethdev.c +11
-0+/* check device uevent */ +if (rte_uevent_get (intr_handle->uevent_fd, &event) ==0 ) { +if (event.subsystem ==RTE_UEVENT_SUBSYSTEM_UIO ) { +if (event.action ==RTE_UEVENT_REMOVE ) { +_rte_eth_dev_callback_process (dev, +RTE_ETH_EVENT_INTR_RMV ,NULL ); +return ; + } + }if + goto done; + }There is nothing specific to i40e in this patch. It seems wrong to add such generic code in every drivers.
Quoted 1 line
It should be managed at bus layer and not be specific to ethdev only.
Quoted 10 lines
if all could managed at bus layer might also be what i want to see,
but that would not so economical at currently. because of the event need to exposure to driver to use app's callback to handle it by detach/attach device. mlx driver also go through this path to show the rmv event usege. we just add uevent for pci uio device. Anyway, i think the uevent must be useful for future PF/VFIO live migration. if there are not other concern about the other patch that added uevent api ineal([PATCH v3 1/2] eal: add uevent api for hot plug), i suggest to merge it at first. Then we could go next to enhancement it with the 6wind hot plug feature.
Sorry it looks wrong to apply half of this patchset, given we are not sure how the remaining part should be implemented.
Let's take time for a better solution and try to gather more opinions. It will be highlighted as one of the next priorities, after the bus rework in progress.
Re: [PATCH v3 2/2] net/i40e: add hot plug monitor in i40e
Quoted 53 lines · Thomas Monjalon
07/07/2017 16:08, Guo, Jia:
Quoted 42 lines · Thomas Monjalon
Quoted 40 lines
07/07/2017 09:56, Thomas Monjalon:
Quoted 26 lines
29/06/2017 07:01, Jeff Guo:
Quoted 25 lines
drivers/net/i40e/i40e_ethdev.c +7
-0@@ -1283,6 +1283,7 @@ static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)/* enable uio intr after callback register */ rte_intr_enable (intr_handle); +/* * Add an ethertype filter to drop all flow control frames transmitted * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC @@ -5832,11 +5833,29 @@ struct i40e_vsi * {struct rte_eth_dev *dev = (struct rte_eth_dev *)param;struct i40e_hw *hw =I40E_DEV_PRIVATE_TO_HW (dev->data->dev_private); +struct rte_uevent event;uint32_t icr0; +struct rte_pci_device *pci_dev; +struct rte_intr_handle *intr_handle; + + pci_dev =RTE_ETH_DEV_TO_PCI (dev); + intr_handle = &pci_dev->intr_handle;/* Disable interrupt */ i40e_pf_disable_irq0 (hw);Quoted 13 lines
drivers/net/i40e/i40e_ethdev.c struct i40e_vsi * · line 5857
Quoted 11 lines
drivers/net/i40e/i40e_ethdev.c +11
-0+/* check device uevent */ +if (rte_uevent_get (intr_handle->uevent_fd, &event) ==0 ) { +if (event.subsystem ==RTE_UEVENT_SUBSYSTEM_UIO ) { +if (event.action ==RTE_UEVENT_REMOVE ) { +_rte_eth_dev_callback_process (dev, +RTE_ETH_EVENT_INTR_RMV ,NULL ); +return ; + } + }if + goto done; + }There is nothing specific to i40e in this patch. It seems wrong to add such generic code in every drivers.
Quoted 1 line
It should be managed at bus layer and not be specific to ethdev only.
Quoted 10 lines
if all could managed at bus layer might also be what i want to see,
but that would not so economical at currently. because of the event need to exposure to driver to use app's callback to handle it by detach/attach device. mlx driver also go through this path to show the rmv event usege. we just add uevent for pci uio device. Anyway, i think the uevent must be useful for future PF/VFIO live migration. if there are not other concern about the other patch that added uevent api ineal([PATCH v3 1/2] eal: add uevent api for hot plug), i suggest to merge it at first. Then we could go next to enhancement it with the 6wind hot plug feature.
Quoted 5 lines
Sorry it looks wrong to apply half of this patchset, given we are not sure how the remaining part should be implemented.
Let's take time for a better solution and try to gather more opinions. It will be highlighted as one of the next priorities, after the bus rework in progress.
some how i agree with your concern, maybe we could find a better option to handle that.
1) about bus layer , as we know , recently the pci uio api be moved out of the eal bus, but not for the eal interrupt. so that would not affect if we add uio api in, just like the exist api "uio_intr_enable" , i could modify the api name into "uio_uevent_get", "uio_uevent_connnect" for better identify. But it still in eal interrupt layer before we decide to modify the eal interrupt layer.
2) about the uevent callback handler, fail-safe driver solution said that fail-safe driver register the callback into device, and device interrupt handler identify the event and callback fail-safe to switch sub-device to process hot plug out case. so if the event process not place in device(mlx driver handle it in device driver), it maybe place in eal. To be generic for all pci uio driver. i could add "uio_uevent_handler" api into eal interrupt. but it will bring some ethdev process into eal. other wise we still need to add the handler in all device driver like this patch here. Any comment about it?
3) the patch set here is about uevent monitoring for pci uio driver. the hot plug remove event processing is depend on the failsave driver. bellow for ref.
http://dpdk.org/dev/patchwork/patch/26842/
Re: [PATCH v2 1/2] eal: add uevent api for hot plug
In reply to Jeff GuoQuoted 16 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +15
-0+ +int +rte_uevent_connect (void ) +{ +struct sockaddr_nl addr; +int ret; +int netlink_fd =-1 ; +int size =64 *1024 ; +int nonblock =1 ; +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + netlink_fd = socket(PF_NETLINK, SOCK_DGRAM,
NETLINK_KOBJECT_UEVENT);
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1304
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +5
-0+if (netlink_fd <0 ) +return -1 ; + +RTE_LOG (ERR ,EAL , +"netlink_fd is %d\n" , netlink_fd);
Is this a ERR log?
Quoted 38 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +38
-0+ +setsockopt (netlink_fd,SOL_SOCKET ,SO_RCVBUFFORCE , &size, +sizeof (size)); + + ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL , +"ioctl(FIONBIO) failed\n" ); +close (netlink_fd); +return -1 ; + } + +if (bind (netlink_fd, (struct sockaddr *) &addr,sizeof (addr)) <0 ) { +close (netlink_fd); +return -1 ; + } + +return netlink_fd; +} + +static int +parse_event (const char *buf,struct rte_uevent *event) { +char action[RTE_UEVENT_MSG_LEN ]; +char subsystem[RTE_UEVENT_MSG_LEN ]; +char dev_path[RTE_UEVENT_MSG_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_UEVENT_MSG_LEN ); +memset (subsystem,0 ,RTE_UEVENT_MSG_LEN ); +memset (dev_path,0 ,RTE_UEVENT_MSG_LEN ); + +while (*buf && i <RTE_UEVENT_MSG_LEN ) { +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; +snprintf (dev_path,sizeof (dev_path),"%s" , buf);
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1352
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10
-0+ }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + } +while (*buf++) + i++; +while (*buf =='\0' ) { + buf++; + i++; + }
++ until to the end? The logic looks wrong. Please check carefully.
Quoted 18 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +18
-0+ } + +if (!strncmp (subsystem,"uio" ,3 )) { + + event->subsystem =RTE_UEVENT_SUBSYSTEM_UIO ; +if (!strncmp (action,"add" ,3 )) + event->action =RTE_UEVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->action =RTE_UEVENT_REMOVE ; +return 0 ; + } + +return -1 ; +} + +int +rte_uevent_get (int fd,struct rte_uevent *uevent) { +int ret;
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1381
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10
-0+char buf[RTE_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_uevent )); +memset (buf,0 ,RTE_UEVENT_MSG_LEN ); + + ret =recv (fd, buf,RTE_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT ); +if (ret >0 ) +return parse_event (buf, uevent); + +if (ret <0 ) {
Meaningless check.
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (errno == EAGAIN || errno == EWOULDBLOCK) { + return 0;
Return -1? The function is declared as 0 means success.
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1387
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +4
-0+ }else { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s\n" , + errno,strerror (errno));
Why not return?
Quoted 34 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +9
-0+ } + } + +/* connection closed */ +if (ret ==0 ) +return -1 ; + +return 0 ; +}lib/librte_eal/linuxapp/eal/eal_pci_uio.c +5
-0@@ -231,6 +231,10 @@close (dev->intr_handle.uio_cfg_fd); dev->intr_handle.uio_cfg_fd =-1 ; } +if (dev->intr_handle.uevent_fd >=0 ) { +close (dev->intr_handle.uevent_fd); + dev->intr_handle.uevent_fd =-1 ; + }if (dev->intr_handle.fd >=0 ) {close (dev->intr_handle.fd); dev->intr_handle.fd =-1 ;@@ -245,6 +249,7 @@char dirname[PATH_MAX ];char cfgname[PATH_MAX ];char devname[PATH_MAX ];/* contains the /dev/uioX */ +char uevtname[PATH_MAX ];int uio_num;struct rte_pci_addr *loc;
lib/librte_eal/linuxapp/eal/eal_pci_uio.c line 288
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +5
-0@@ -276,6 +281,13 @@ goto error; } + dev->intr_handle.uevent_fd =rte_uevent_connect (); +if (dev->intr_handle.uevent_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + uevtname,strerror (errno)); + goto error;
It seems uevtname is not assigned at all. Do we need it? And the log may means "cannot connect the event fd", right?. And even the event fd is failed to create, should it block the process?
Thanks
Jingjing
Re: [PATCH v2 1/2] eal: add uevent api for hot plug
The buf have contain lot of consistent '/0', so it is why I need to check that. anyway I will refine that and other return issue in v3.
Thanks jingjing .
Best regards,
Jeff Guo
-----Original Message-----
From: Wu, Jingjing
Sent: Thursday, June 29, 2017 10:25 AM
To: Guo, Jia <[email protected]>; Zhang, Helin <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v2 1/2] eal: add uevent api for hot plug
Quoted 16 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +15
-0+ +int +rte_uevent_connect (void ) +{ +struct sockaddr_nl addr; +int ret; +int netlink_fd =-1 ; +int size =64 *1024 ; +int nonblock =1 ; +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ; + + netlink_fd = socket(PF_NETLINK, SOCK_DGRAM,
NETLINK_KOBJECT_UEVENT);
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1304
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +5
-0+if (netlink_fd <0 ) +return -1 ; + +RTE_LOG (ERR ,EAL , +"netlink_fd is %d\n" , netlink_fd);
Is this a ERR log?
Quoted 38 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +38
-0+ +setsockopt (netlink_fd,SOL_SOCKET ,SO_RCVBUFFORCE , &size, +sizeof (size)); + + ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL , +"ioctl(FIONBIO) failed\n" ); +close (netlink_fd); +return -1 ; + } + +if (bind (netlink_fd, (struct sockaddr *) &addr,sizeof (addr)) <0 ) { +close (netlink_fd); +return -1 ; + } + +return netlink_fd; +} + +static int +parse_event (const char *buf,struct rte_uevent *event) { +char action[RTE_UEVENT_MSG_LEN ]; +char subsystem[RTE_UEVENT_MSG_LEN ]; +char dev_path[RTE_UEVENT_MSG_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_UEVENT_MSG_LEN ); +memset (subsystem,0 ,RTE_UEVENT_MSG_LEN ); +memset (dev_path,0 ,RTE_UEVENT_MSG_LEN ); + +while (*buf && i <RTE_UEVENT_MSG_LEN ) { +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; +snprintf (dev_path,sizeof (dev_path),"%s" , buf);
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1352
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10
-0+ }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + } +while (*buf++) + i++; +while (*buf =='\0' ) { + buf++; + i++; + }
++ until to the end? The logic looks wrong. Please check carefully.
Quoted 18 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +18
-0+ } + +if (!strncmp (subsystem,"uio" ,3 )) { + + event->subsystem =RTE_UEVENT_SUBSYSTEM_UIO ; +if (!strncmp (action,"add" ,3 )) + event->action =RTE_UEVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->action =RTE_UEVENT_REMOVE ; +return 0 ; + } + +return -1 ; +} + +int +rte_uevent_get (int fd,struct rte_uevent *uevent) { +int ret;
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1381
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10
-0+char buf[RTE_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_uevent )); +memset (buf,0 ,RTE_UEVENT_MSG_LEN ); + + ret =recv (fd, buf,RTE_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT ); +if (ret >0 ) +return parse_event (buf, uevent); + +if (ret <0 ) {
Meaningless check.
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (errno == EAGAIN || errno == EWOULDBLOCK) { + return 0;
Return -1? The function is declared as 0 means success.
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1387
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +4
-0+ }else { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s\n" , + errno,strerror (errno));
Why not return?
Quoted 34 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +9
-0+ } + } + +/* connection closed */ +if (ret ==0 ) +return -1 ; + +return 0 ; +}lib/librte_eal/linuxapp/eal/eal_pci_uio.c +5
-0@@ -231,6 +231,10 @@close (dev->intr_handle.uio_cfg_fd); dev->intr_handle.uio_cfg_fd =-1 ; } +if (dev->intr_handle.uevent_fd >=0 ) { +close (dev->intr_handle.uevent_fd); + dev->intr_handle.uevent_fd =-1 ; + }if (dev->intr_handle.fd >=0 ) {close (dev->intr_handle.fd); dev->intr_handle.fd =-1 ;@@ -245,6 +249,7 @@char dirname[PATH_MAX ];char cfgname[PATH_MAX ];char devname[PATH_MAX ];/* contains the /dev/uioX */ +char uevtname[PATH_MAX ];int uio_num;struct rte_pci_addr *loc;
lib/librte_eal/linuxapp/eal/eal_pci_uio.c line 288
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +5
-0@@ -276,6 +281,13 @@ goto error; } + dev->intr_handle.uevent_fd =rte_uevent_connect (); +if (dev->intr_handle.uevent_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + uevtname,strerror (errno)); + goto error;
It seems uevtname is not assigned at all. Do we need it? And the log may means "cannot connect the event fd", right?. And even the event fd is failed to create, should it block the process?
Thanks
Jingjing
Re: [PATCH v2 1/2] eal: add uevent api for hot plug
In reply to Jeff GuoHi,
This is an interesting step for hotplug in DPDK.
28/06/2017 13:07, Jeff Guo:
Quoted 1 line
+
netlink_fd=socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
It is monitoring the whole system...
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1377
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10
-0+int +rte_uevent_get (int fd,struct rte_uevent *uevent) +{ +int ret; +char buf[RTE_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_uevent )); +memset (buf,0 ,RTE_UEVENT_MSG_LEN ); + + ret =recv (fd, buf,RTE_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT );
... and it is read from this function called by one driver. It cannot work without a global dispatch.
It must be a global mechanism, probably a service core. The question is also to know whether it should be a mandatory service in DPDK or an optional helper?
Re: [PATCH v2 1/2] eal: add uevent api for hot plug
hi, thomas
Quoted 8 lines · Thomas Monjalon
Hi,
This is an interesting step for hotplug in DPDK.
28/06/2017 13:07, Jeff Guo:
Quoted 1 line
+
netlink_fd=socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);It is monitoring the whole system...
Quoted 12 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1377
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10
-0+int +rte_uevent_get (int fd,struct rte_uevent *uevent) +{ +int ret; +char buf[RTE_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_uevent )); +memset (buf,0 ,RTE_UEVENT_MSG_LEN ); + + ret =recv (fd, buf,RTE_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT );... and it is read from this function called by one driver. It cannot work without a global dispatch.
the rte_uevent-connect is called in func of pci_uio_alloc_resource, so each socket is created by by each uio device. so i think that would not affect each driver isolate to use it.
Quoted 3 lines
It must be a global mechanism, probably a service core. The question is also to know whether it should be a mandatory service in DPDK or an optional helper?
a global mechanism would be good, but so far, include mlx driver, we all handle the hot plug event in driver by app's registered callback. maybe a better global would be try in the future. but now is would work for all pci uio device.
and more, if in pci uio device to use hot plug , i think it might be mandatory.
Re: [PATCH v2 1/2] eal: add uevent api for hot plug
05/07/2017 05:02, Guo, Jia:
Quoted 24 lines
hi, thomas
Quoted 8 lines · Thomas Monjalon
Hi,
This is an interesting step for hotplug in DPDK.
28/06/2017 13:07, Jeff Guo:
Quoted 1 line
+
netlink_fd=socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);It is monitoring the whole system...
Quoted 12 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1377
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10
-0+int +rte_uevent_get (int fd,struct rte_uevent *uevent) +{ +int ret; +char buf[RTE_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_uevent )); +memset (buf,0 ,RTE_UEVENT_MSG_LEN ); + + ret =recv (fd, buf,RTE_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT );... and it is read from this function called by one driver. It cannot work without a global dispatch.
Quoted 3 lines
the rte_uevent-connect is called in func of
pci_uio_alloc_resource, so each socket is created by by each uio device. so i think that would not affect each driver isolate to use it.
Ah OK, I missed it.
Quoted 7 lines
Quoted 3 lines
It must be a global mechanism, probably a service core. The question is also to know whether it should be a mandatory service in DPDK or an optional helper?
a global mechanism would be good, but so far, include mlx driver, we all handle the hot plug event in driver by app's registered callback. maybe a better global would be try in the future. but now is would work for all pci uio device.
mlx drivers have a special connection to the kernel through the associated mlx kernel drivers. That's why the PMD handle the events in a specific way.
You are adding event handling for UIO.
Now we need also VFIO.
I am wondering how it could be better integrated in the bus layer.
Quoted 2 lines
and more, if in pci uio device to use hot plug , i think it might be mandatory.
Re: [PATCH v2 1/2] eal: add uevent api for hot plug
Quoted 37 lines · Thomas Monjalon
05/07/2017 05:02, Guo, Jia:
Quoted 24 lines
hi, thomas
Quoted 8 lines · Thomas Monjalon
Hi,
This is an interesting step for hotplug in DPDK.
28/06/2017 13:07, Jeff Guo:
Quoted 1 line
+
netlink_fd=socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);It is monitoring the whole system...
Quoted 12 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1377
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10
-0+int +rte_uevent_get (int fd,struct rte_uevent *uevent) +{ +int ret; +char buf[RTE_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_uevent )); +memset (buf,0 ,RTE_UEVENT_MSG_LEN ); + + ret =recv (fd, buf,RTE_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT );... and it is read from this function called by one driver. It cannot work without a global dispatch.
Quoted 3 lines
the rte_uevent-connect is called in func of
pci_uio_alloc_resource, so each socket is created by by each uio device. so i think that would not affect each driver isolate to use it.Ah OK, I missed it.
Quoted 7 lines
Quoted 3 lines
It must be a global mechanism, probably a service core. The question is also to know whether it should be a mandatory service in DPDK or an optional helper?
a global mechanism would be good, but so far, include mlx driver, we all handle the hot plug event in driver by app's registered callback. maybe a better global would be try in the future. but now is would work for all pci uio device.
Quoted 7 lines
mlx drivers have a special connection to the kernel through the associated mlx kernel drivers. That's why the PMD handle the events in a specific way.
You are adding event handling for UIO.
Now we need also VFIO.I am wondering how it could be better integrated in the bus layer.
absolutely, hot plug for VFIO must be request more for the live migration, and we plan to add it at next level, when we go thought all uio hot plug feature integration done. so, could i expect an ack if there aren't other concern about uio uevent here. thanks.
Quoted 2 lines
Quoted 2 lines
and more, if in pci uio device to use hot plug , i think it might be mandatory.
Re: [PATCH v2 1/2] eal: add uevent api for hot plug
a. about uevent mechanism
As we know, uevent is come from the kobject of the kernel side, every kobject would have its own uevent, and a sysfs folder identify a kobject, such as cpu,usb,pci,pci-express,virio, these bus component all have uevent. I agree that uevent would be the best if it could integrated in the bus layer. I check the kernel src code , the uevent related is in lib/koject_uvent.c, and only for linux not for bsp, both support uio and vfio, so where shoud dpdk uevent be location? I come to my mind 4 option below, and I propose 2) and 4).
1)Eal_bus: (but uevent like netlink socket thing and event polling not related with bus behavior) 2)eal_dev: (just considerate it like kernel's udev, and create new epoll, uevent handler) 3)add new file eal_udev.c
4)eal_interrupt. (add into the interrupt epoll, use interrupt handler)
Shreyansh & jblunck & gaetan
Since you recently work on pci bus layer and expert on that, I want to ask you that if you plan about any other bus layer rework would be conflict my proposer, or would let me modify to compatibility with the next architect? If you have, please let me know. thanks.
b. about pci uevent handler.
I suppose 2 option:
1)use a common interrupt handler for pci pmd to let app or fail-safe pmd to register. 2)use a common uevent handler for pci pmd to let app or fail-safe pmd register.
Community, are there any good comment about that ?
Best regards,
Jeff Guo
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Guo, Jia
Sent: Wednesday, July 5, 2017 5:04 PM
To: Thomas Monjalon <[email protected]>
Cc: [email protected]; Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v2 1/2] eal: add uevent api for hot plug
Quoted 37 lines · Thomas Monjalon
05/07/2017 05:02, Guo, Jia:
Quoted 24 lines
hi, thomas
Quoted 9 lines · Thomas Monjalon
Hi,
This is an interesting step for hotplug in DPDK.
28/06/2017 13:07, Jeff Guo:
Quoted 2 lines
+
netlink_fd= socket(PF_NETLINK,SOCK_DGRAM,
+NETLINK_KOBJECT_UEVENT);It is monitoring the whole system...
Quoted 11 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1377
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +9
-0+int +rte_uevent_get (int fd,struct rte_uevent *uevent) { +int ret; +char buf[RTE_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_uevent )); +memset (buf,0 ,RTE_UEVENT_MSG_LEN ); + + ret =recv (fd, buf,RTE_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT );... and it is read from this function called by one driver. It cannot work without a global dispatch.
Quoted 3 lines
the rte_uevent-connect is called in func of
pci_uio_alloc_resource, so each socket is created by by each uio device. so i think that would not affect each driver isolate to use it.Ah OK, I missed it.
Quoted 7 lines
Quoted 3 lines
It must be a global mechanism, probably a service core. The question is also to know whether it should be a mandatory service in DPDK or an optional helper?
a global mechanism would be good, but so far, include mlx driver, we all handle the hot plug event in driver by app's registered callback. maybe a better global would be try in the future. but now is would work for all pci uio device.
Quoted 7 lines
mlx drivers have a special connection to the kernel through the associated mlx kernel drivers. That's why the PMD handle the events in a specific way.
You are adding event handling for UIO.
Now we need also VFIO.I am wondering how it could be better integrated in the bus layer.
absolutely, hot plug for VFIO must be request more for the live migration, and we plan to add it at next level, when we go thought all uio hot plug feature integration done. so, could i expect an ack if there aren't other concern about uio uevent here. thanks.
Quoted 2 lines
Quoted 2 lines
and more, if in pci uio device to use hot plug , i think it might be mandatory.
Re: [PATCH v2 1/2] eal: add uevent api for hot plug
Hi Jeff,
Quoted 12 lines · Jia
a. about uevent mechanism
As we know, uevent is come from the kobject of the kernel side, every kobject would have its own uevent, and a sysfs folder identify a kobject, such as cpu,usb,pci,pci-express,virio, these bus component all have uevent. I agree that uevent would be the best if it could integrated in the bus layer. I check the kernel src code , the uevent related is in
lib/koject_uvent.c, and only for linux not for bsp, both support uio and vfio, so where shoud dpdk uevent be location? I come to my mind 4 option below, and I propose 2) and 4).1)Eal_bus: (but uevent like netlink socket thing and event polling not related with bus behavior) 2)eal_dev: (just considerate it like kernel's udev, and create new epoll, uevent handler) 3)add new file
eal_udev.c
4)eal_interrupt. (add into the interrupt epoll, use interrupt handler)
Quoted 5 lines
Shreyansh & jblunck & gaetan
Since you recently work on pci bus layer and expert on that, I want to ask you that if you plan about any other bus layer rework would be conflict my proposer, or would let me modify to compatibility with the next architect? If you have, please let me know. thanks.
Yes, some work is planned at least from my side.
I am moving the PCI bus out of the EAL:
http://dpdk.org/ml/archives/dev/2017-August/073512.html
The current proposal is not yet complete. Some filesystem functions might need to be exposed.
However, it has not functional impact: functions may move, but they do the same thing. But even so, the uevent_fd that you add within eal_common_uio will probably have to be moved (eal_common_pci_uio.c is going out of the EAL), nothing dramatic.
That's all I can think of from my PoV that might be in conflict with your work.
Quoted 68 lines
b. about pci uevent handler.
I suppose 2 option:
1)use a common interrupt handler for pci pmd to let app or fail-safe pmd to register. 2)use a common uevent handler for pci pmd to let app or fail-safe pmd register.Community, are there any good comment about that ?
Best regards,
Jeff Guo-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Guo, Jia
Sent: Wednesday, July 5, 2017 5:04 PM
To: Thomas Monjalon <[email protected]>
Cc: [email protected]; Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v2 1/2] eal: add uevent api for hot plugQuoted 37 lines · Thomas Monjalon
05/07/2017 05:02, Guo, Jia:
Quoted 24 lines
hi, thomas
Quoted 9 lines · Thomas Monjalon
Hi,
This is an interesting step for hotplug in DPDK.
28/06/2017 13:07, Jeff Guo:
Quoted 2 lines
+
netlink_fd= socket(PF_NETLINK,SOCK_DGRAM,
+NETLINK_KOBJECT_UEVENT);It is monitoring the whole system...
Quoted 11 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c static __attribute__((noreturn)) void * · line 1377
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_interrupts.c +9
-0+int +rte_uevent_get (int fd,struct rte_uevent *uevent) { +int ret; +char buf[RTE_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_uevent )); +memset (buf,0 ,RTE_UEVENT_MSG_LEN ); + + ret =recv (fd, buf,RTE_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT );... and it is read from this function called by one driver. It cannot work without a global dispatch.
Quoted 3 lines
the rte_uevent-connect is called in func of
pci_uio_alloc_resource, so each socket is created by by each uio device. so i think that would not affect each driver isolate to use it.Ah OK, I missed it.
Quoted 7 lines
Quoted 3 lines
It must be a global mechanism, probably a service core. The question is also to know whether it should be a mandatory service in DPDK or an optional helper?
a global mechanism would be good, but so far, include mlx driver, we all handle the hot plug event in driver by app's registered callback. maybe a better global would be try in the future. but now is would work for all pci uio device.
Quoted 7 lines
mlx drivers have a special connection to the kernel through the associated mlx kernel drivers. That's why the PMD handle the events in a specific way.
You are adding event handling for UIO.
Now we need also VFIO.I am wondering how it could be better integrated in the bus layer.
absolutely, hot plug for VFIO must be request more for the live migration, and we plan to add it at next level, when we go thought all uio hot plug feature integration done. so, could i expect an ack if there aren't other concern about uio uevent here. thanks.
Quoted 2 lines
Quoted 2 lines
and more, if in pci uio device to use hot plug , i think it might be mandatory.
Signature · 2 lines
Gaëtan Rivet 6WIND