Add hot plug event in rte eal interrupt and inplement it in i40e driver.
Subsystems (2)
RFC 1/1 Add hot plug event in rte eal interrupt and inplement it in i40e driver.
For HW hotplug feature, we had already got upstream that removal event adding from 6wind as bellow.
dependency of “add device removal event” patch set:
http://dpdk.org/dev/patchwork/patch/23693/
[dpdk-dev,v2,1/5] ethdev: introduce device removal event
http://dpdk.org/dev/patchwork/patch/23694/
[dpdk-dev,v2,2/5] net/mlx4: device removal event support
http://dpdk.org/dev/patchwork/patch/23695/
[dpdk-dev,v2,3/5] app/testpmd: generic event handler
http://dpdk.org/dev/patchwork/patch/23696/
[dpdk-dev,v2,4/5] app/testpmd: request link status interrupt
http://dpdk.org/dev/patchwork/patch/23697/
[dpdk-dev,v2,5/5] app/testpmd: request device removal interrupt
Quoted 1 line
From the patches, we can see a new event type “RTE_ETH_DEV_INTR_RMV” has been added into the ethdev, and the event has been implemented in mlx4 driver, and Testpmd be use for testing purposes and as a practical usage example for how to use these event. The progress is use the mlx4 driver to register interrupt callback function to rte eal interrupt source, and when rte epolling detect the
IBV_EVENT_DEVICE_FATAL, which is identify the device remove behavior, it will callback into the driver’s interrupt handle to handle it, and then callback to the user app, such as testpmd, to detach the pci device.
So far, except the mlx4 driver, other driver like i40, that not have the remove interrupt from hw, will not be able to monitoring the remove behavior, so in order to expand the hot plug feature for all driver cases, something must be done ot detect the remove event at the kernel level and offer a new line of interrupt to the userland. The idea is coming as below.
Use I40e as example, we know that the rmv interrupt is not added in hw, but we could monitor the uio file descriptor to catch the device remove event as bellow.
The info of uevent form FD monitoring:
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
Firstly, in order to monitor the uio file descriptor, we need to create socket to monitor the uio fd, that is defined as “hotplug_fd”, and then add the uio fd into the epoll fd list, rte eal could epoll all of the interrupt event from hw interrupt and also include the uevent from hotplug_fd.
Secondly, in order to read out the uevent that monitoring, we need to add uevent API in rte layer. We plan add 2 , rte_uevent_connect and rte_get_uevent. All driver interrupt handler could use these API to enable the uevent monitoring, and read out the uevent type , then corresponding to handle these uevent, such as detach the device when get the remove type.
--- drivers/net/i40e/i40e_ethdev.c | 15 +++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 146 ++++++++++++++++++++- .../linuxapp/eal/include/exec-env/rte_interrupts.h | 32 +++++ 3 files changed, 191 insertions(+), 2 deletions(-)
drivers/net/i40e/i40e_ethdev.c +15 -0
@@ -66,6 +66,8 @@#include "i40e_pf.h" #include "i40e_regs.h" +extern int hotplug_fd; +#define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"#define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"
@@ -5808,8 +5810,21 @@ i40e_dev_interrupt_handler(void *param) {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; +/* check device uevent */ +while (rte_get_uevent (hotplug_fd, &event) >0 ) { +if (event.subsystem ==1 ) { +if (event.action ==RTE_UEVENT_ADD ) { +//do nothing here + }else if (event.action ==RTE_UEVENT_REMOVE ) { +_rte_eth_dev_callback_process (dev, +RTE_ETH_EVENT_INTR_RMV ,NULL ); + } + } + } +/* Disable interrupt */ i40e_pf_disable_irq0 (hw);
lib/librte_eal/linuxapp/eal/eal_interrupts.c +144 -2
182 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +32 -0
@@ -99,6 +99,16 @@ struct rte_intr_handle {int *intr_vec;/**< intr vector number array */ }; +enum rte_uevent_action { +RTE_UEVENT_ADD =0 ,/**< uevent type of device add */ +RTE_UEVENT_REMOVE =1 ,/**< uevent type of device remove*/ +}; + +struct rte_uevent { +enum rte_uevent_action action;/**< uevent action type */ +int subsystem;/**< subsystem id */ +}; +#define RTE_EPOLL_PER_THREAD -1/**< to hint using per thread epfd */ /**
@@ -236,4 +246,26 @@ rte_intr_allow_others(struct rte_intr_handle *intr_handle);int rte_intr_cap_multiple (struct rte_intr_handle *intr_handle); +/** +* It read out the uevent from the specific file descriptor. +* +* @param fd +* The fd which the uevent associated to +* @param uevent +* Pointer to the uevent which read from the monitoring fd. +* @return +* - On success, one. +* - On failure, zeor or a negative value. +*/ +int +rte_get_uevent (int fd,struct rte_uevent *uevent); + +/** +* Connect to the device uevent file descriptor. +* @return +* return the connected uevent fd. +*/ +int +rte_uevent_connect (void ); +#endif /* _RTE_LINUXAPP_INTERRUPTS_H_ */
Signature · 1 line
2.7.4
Hi Jeff,
A few comments below:
Quoted 14 lines · Jeff Guo
For HW hotplug feature, we had already got upstream that removal event adding from 6wind as bellow.
dependency of “add device removal event” patch set:
http://dpdk.org/dev/patchwork/patch/23693/
[dpdk-dev,v2,1/5] ethdev: introduce device removal event
http://dpdk.org/dev/patchwork/patch/23694/
[dpdk-dev,v2,2/5] net/mlx4: device removal event support
http://dpdk.org/dev/patchwork/patch/23695/
[dpdk-dev,v2,3/5] app/testpmd: generic event handler
http://dpdk.org/dev/patchwork/patch/23696/
[dpdk-dev,v2,4/5] app/testpmd: request link status interrupt
http://dpdk.org/dev/patchwork/patch/23697/
[dpdk-dev,v2,5/5] app/testpmd: request device removal interrupt
Quoted 4 lines
From the patches, we can see a new event type “RTE_ETH_DEV_INTR_RMV” has been added into the ethdev, and the event has been implemented in mlx4 driver, and Testpmd be use for testing purposes and as a practical usage example for how to use these event. The progress is use the mlx4 driver to register interrupt callback function to rte eal interrupt source, and when rte epolling detect the
IBV_EVENT_DEVICE_FATAL, which is identify the device remove behavior, it will callback into the driver’s interrupt handle to handle it, and then callback to the user app, such as testpmd, to detach the pci device.So far, except the mlx4 driver, other driver like i40, that not have the remove interrupt from hw, will not be able to monitoring the remove behavior, so in order to expand the hot plug feature for all driver cases, something must be done ot detect the remove event at the kernel level and offer a new line of interrupt to the userland. The idea is coming as below.
It's nice that this event is extended to other drivers.
Quoted 12 lines
Use I40e as example, we know that the rmv interrupt is not added in hw, but we could monitor the uio file descriptor to catch the device remove event as bellow.
The info of uevent form FD monitoring:
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
Quoted 4 lines
Firstly, in order to monitor the uio file descriptor, we need to create socket to monitor the uio fd, that is defined as “hotplug_fd”, and then add the uio fd into the epoll fd list, rte eal could epoll all of the interrupt event from hw interrupt and also include the uevent from
hotplug_fd.Secondly, in order to read out the uevent that monitoring, we need to add uevent API in rte layer. We plan add 2 ,
rte_uevent_connectandrte_get_uevent. All driver interrupt handler could use these API to enable the uevent monitoring, and read out the uevent type , then corresponding to handle these uevent, such as detach the device when get the remove type.
I find having a generic uevent API interesting.
However, all specifics pertaining to UIO use (hotplug_fd, subsystem enum) should stay in UIO specific code (eal_pci_uio.c?).
I am currently moving the PCI bus out of the EAL. EAL subsystems should not rely on PCI specifics, as they won't be available afterward.
It should also allow you to clean up your API. Exposing hotplug_fd and requiring PMDs to link it can be avoided and should result in a simpler API.
Quoted 285 lines
Signed-off-by Jeff Guo <[email protected]>---
drivers/net/i40e/i40e_ethdev.c | 15 +++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 146 ++++++++++++++++++++- .../linuxapp/eal/include/exec-env/rte_interrupts.h | 32 +++++ 3 files changed, 191 insertions(+), 2 deletions(-)drivers/net/i40e/i40e_ethdev.c +15
-0@@ -66,6 +66,8 @@#include "i40e_pf.h" #include "i40e_regs.h" +extern int hotplug_fd; +#define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"#define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"@@ -5808,8 +5810,21 @@ i40e_dev_interrupt_handler(void *param) {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; +/* check device uevent */ +while (rte_get_uevent (hotplug_fd, &event) >0 ) { +if (event.subsystem ==1 ) { +if (event.action ==RTE_UEVENT_ADD ) { +//do nothing here + }else if (event.action ==RTE_UEVENT_REMOVE ) { +_rte_eth_dev_callback_process (dev, +RTE_ETH_EVENT_INTR_RMV ,NULL ); + } + } + } +/* Disable interrupt */ i40e_pf_disable_irq0 (hw);lib/librte_eal/linuxapp/eal/eal_interrupts.c +4
-0@@ -65,6 +65,10 @@#include <rte_errno.h> #include <rte_spinlock.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <sys/epoll.h> +#include "eal_private.h" #include "eal_vfio.h" #include "eal_thread.h" @@ -74,6 +78,11 @@static
RTE_DEFINE_PER_LCORE(int, _epfd)= -1; /**< epoll fd per thread */lib/librte_eal/linuxapp/eal/eal_interrupts.c +5
-0+#define RTE_UEVENT_MSG_LEN 4096 +#define RTE_UEVENT_SUBSYSTEM_UIO 1 + +int hotplug_fd =-1 ; +/**
* union for pipe fds.
*/lib/librte_eal/linuxapp/eal/eal_interrupts.c +135
-2@@ -669,10 +678,13 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)RTE_SET_USED (r);return -1 ; } +rte_spinlock_lock (&intr_lock); TAILQ_FOREACH(src, &intr_sources, next) -if (src->intr_handle.fd == - events[n].data.fd) +if ((src->intr_handle.fd == + events[n].data.fd) || + (hotplug_fd == + events[n].data.fd))break ;if (src ==NULL ){rte_spinlock_unlock (&intr_lock);@@ -858,7 +870,24 @@ eal_intr_thread_main(__rte_unused void *arg) }else numfds++; + +/** +* add device uevent file descriptor +* into wait list for hot plug. +*/ + ev.events =EPOLLIN |EPOLLPRI |EPOLLRDHUP |EPOLLHUP ; + ev.data.fd = hotplug_fd; +if (epoll_ctl (pfd,EPOLL_CTL_ADD , + hotplug_fd, &ev) <0 ){ +rte_panic ("Error adding hotplug_fd %d epoll_ctl, %s\n" , + hotplug_fd,strerror (errno)); + } +else + numfds++; + } + +rte_spinlock_unlock (&intr_lock);/* serve the interrupt */ eal_intr_handle_interrupts (pfd, numfds);@@ -877,6 +906,9 @@ rte_eal_intr_init(void)int ret =0 , ret_1 =0 ;char thread_name[RTE_MAX_THREAD_NAME_LEN ]; +/* connect to monitor device uevent */ +rte_uevent_connect (); +/* init the global interrupt source head */ TAILQ_INIT (&intr_sources);@@ -1255,3 +1287,113 @@ rte_intr_cap_multiple(struct rte_intr_handle *intr_handle)return 0 ; } + +int +rte_uevent_connect (void ) +{ +struct sockaddr_nl addr; +int ret; +int netlink_fd; +int size =64 *1024 ; +int nonblock =1 ; +memset (&addr,0 ,sizeof (addr)); + addr.nl_family =AF_NETLINK ; + addr.nl_pid =getpid (); + addr.nl_groups =0xffffffff ; + + netlink_fd =socket (PF_NETLINK ,SOCK_DGRAM ,NETLINK_KOBJECT_UEVENT ); +if (netlink_fd <0 ) +return -1 ; + +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 ; + } + + hotplug_fd = netlink_fd; + +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 ]; + +memset (action,0 ,RTE_UEVENT_MSG_LEN ); +memset (subsystem,0 ,RTE_UEVENT_MSG_LEN ); +memset (dev_path,0 ,RTE_UEVENT_MSG_LEN ); + +while (*buf) { +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); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + } +while (*buf++) + ; + } + +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 1 ; + } + +return -1 ; +} + +int +rte_get_uevent (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 ); +if (ret >0 ) { +return parse_event (buf, uevent); + } + +if (ret <0 ) { +if (errno ==EAGAIN || errno ==EWOULDBLOCK ) { +return 0 ; + }else { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s\n" , + errno,strerror (errno)); + } + } + +/* connection closed */ +if (ret ==0 ) { +return -1 ; + } + +return 0 ; +}lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +10
-0@@ -99,6 +99,16 @@ struct rte_intr_handle {int *intr_vec;/**< intr vector number array */ }; +enum rte_uevent_action { +RTE_UEVENT_ADD =0 ,/**< uevent type of device add */ +RTE_UEVENT_REMOVE =1 ,/**< uevent type of device remove*/ +}; + +struct rte_uevent { +enum rte_uevent_action action;/**< uevent action type */ +int subsystem;/**< subsystem id */ +}; +#define RTE_EPOLL_PER_THREAD -1/**< to hint using per thread epfd */ /** @@ -236,4 +246,26 @@ rte_intr_allow_others(struct rte_intr_handle *intr_handle);int
rte_intr_cap_multiple(struct rte_intr_handle *intr_handle);lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +22
-0+/** +* It read out the uevent from the specific file descriptor. +* +* @param fd +* The fd which the uevent associated to +* @param uevent +* Pointer to the uevent which read from the monitoring fd. +* @return +* - On success, one. +* - On failure, zeor or a negative value. +*/ +int +rte_get_uevent (int fd,struct rte_uevent *uevent); + +/** +* Connect to the device uevent file descriptor. +* @return +* return the connected uevent fd. +*/ +int +rte_uevent_connect (void ); +#endif /* _RTE_LINUXAPP_INTERRUPTS_H_ */
Signature · 1 line
2.7.4
Signature · 2 lines
Gaëtan Rivet 6WIND
Quoted 65 lines
-----Original Message-----
From: Guo, Jia
Sent: Sunday, May 28, 2017 11:45 PM
To: Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>; Richardson, Bruce <[email protected]>; Ananyev, Konstantin <[email protected]>; Liu, Yuanhan <[email protected]>; [email protected]
Cc: [email protected]; Guo, Jia <[email protected]>
Subject: [dpdk-dev] [RFC] Add hot plug event in rte eal interrupt and inplement it in i40e driver.For HW hotplug feature, we had already got upstream that removal event adding from 6wind as bellow.
dependency of “add device removal event” patch set:
http://dpdk.org/dev/patchwork/patch/23693/
[dpdk-dev,v2,1/5] ethdev: introduce device removal event
http://dpdk.org/dev/patchwork/patch/23694/
[dpdk-dev,v2,2/5] net/mlx4: device removal event support
http://dpdk.org/dev/patchwork/patch/23695/
[dpdk-dev,v2,3/5] app/testpmd: generic event handler
http://dpdk.org/dev/patchwork/patch/23696/
[dpdk-dev,v2,4/5] app/testpmd: request link status interrupt
http://dpdk.org/dev/patchwork/patch/23697/
[dpdk-dev,v2,5/5] app/testpmd: request device removal interruptFrom the patches, we can see a new event type “RTE_ETH_DEV_INTR_RMV” has been added into the ethdev, and the event has been implemented in mlx4 driver, and Testpmd be use for testing purposes and as a practical usage example for how to use these event. The progress is use the mlx4 driver to register interrupt callback function to rte eal interrupt source, and when rte epolling detect the
IBV_EVENT_DEVICE_FATAL, which is identify the device remove behavior, it will callback into the driver’s interrupt handle to handle it, and then callback to the user app, such as testpmd, to detach the pci device.So far, except the mlx4 driver, other driver like i40, that not have the remove interrupt from hw, will not be able to monitoring the remove behavior, so in order to expand the hot plug feature for all driver cases, something must be done ot detect the remove event at the kernel level and offer a new line of interrupt to the userland. The idea is coming as below.
Use I40e as example, we know that the rmv interrupt is not added in hw, but we could monitor the uio file descriptor to catch the device remove event as bellow.
The info of uevent form FD monitoring:
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/ui o/uio2
SUBSYSTEM=uio
MAJOR=243
MINOR=2
DEVNAME=uio2
SEQNUM=11366Firstly, in order to monitor the uio file descriptor, we need to create socket to monitor the uio fd, that is defined as “hotplug_fd”, and then add the uio fd into the epoll fd list, rte eal could epoll all of the interrupt event from hw interrupt and also include the uevent from
hotplug_fd.Secondly, in order to read out the uevent that monitoring, we need to add uevent API in rte layer. We plan add 2 ,
rte_uevent_connectandrte_get_uevent. All driver interrupt handler could use these API to enable the uevent monitoring, and read out the uevent type , then corresponding to handle these uevent, such as detach the device when get the remove type.
Quoted 7 lines
Signed-off-by Jeff Guo <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 15 +++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 146 ++++++++++++++++++++- .../linuxapp/eal/include/exec-env/rte_interrupts.h | 32 +++++ 3 files changed, 191 insertions(+), 2 deletions(-)
It will be better to split the patch to two sub patches, one is for eal change, the other is for driver enabling.
Quoted 14 lines
drivers/net/i40e/i40e_ethdev.c +2
-0@@ -66,6 +66,8 @@#include "i40e_pf.h" #include "i40e_regs.h" +extern int hotplug_fd; +#define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"#define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"
drivers/net/i40e/i40e_ethdev.c i40e_dev_interrupt_handler(void *param) · line 5817
Quoted 8 lines
drivers/net/i40e/i40e_ethdev.c +3
-0@@ -5808,8 +5810,21 @@ i40e_dev_interrupt_handler(void *param) {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; +/* check device uevent */ +while (rte_get_uevent (hotplug_fd, &event) >0 ) {
The hotplug_fd is used as uevent fd for all devices, right? but in i40e driver, how distinguish the event is to this dev? I saw you check the src in eal_intr_process_interrupts, but you didn't assign the fd in i40e device's intr_handle. Is that to say all driver's callback will be triggered?
drivers/net/i40e/i40e_ethdev.c i40e_dev_interrupt_handler(void *param) · line 5818
Quoted 1 line
drivers/net/i40e/i40e_ethdev.c +1
-0+if (event.subsystem ==1 ) {
What is the 1 meaning?
drivers/net/i40e/i40e_ethdev.c i40e_dev_interrupt_handler(void *param) · line 5820
Quoted 2 lines
drivers/net/i40e/i40e_ethdev.c +2
-0+if (event.action ==RTE_UEVENT_ADD ) { +//do nothing here
Will you plan do anything later? Such as RTE_ETH_EVENT_INTR_NEW? If no, please remove it. And {} can be omit.
drivers/net/i40e/i40e_ethdev.c i40e_dev_interrupt_handler(void *param)
Quoted 12 lines
drivers/net/i40e/i40e_ethdev.c +10
-0+ }else if (event.action ==RTE_UEVENT_REMOVE ) { +_rte_eth_dev_callback_process (dev, +RTE_ETH_EVENT_INTR_RMV ,NULL ); + } + } + +/* connection closed */ +if (ret ==0 ) { +return -1 ; + }
{} can be omit. Serval in this patch. Please check.
Quoted 10 lines
+/**
+ * It read out the uevent from the specific file descriptor.
+ *
+ * @param fd
+ * The fd which the uevent associated to
+ * @param uevent
+ * Pointer to the uevent which read from the monitoring fd.
+ * @return
+ * - On success, one.
+ * - On failure, zeor or a negative value.
Zeor -> zero
Generally speaking, we are using negative value to indicate failure, and 0 indicate success. Expect the result has more than two options (success, failure).
drivers/net/i40e/i40e_ethdev.c
Quoted 8 lines
drivers/net/i40e/i40e_ethdev.c +8
-0+int +rte_get_uevent (int fd,struct rte_uevent *uevent); + +/** +* Connect to the device uevent file descriptor. +* @return +* return the connected uevent fd. +*/
Any return code for failure?
Thanks
Jingjing
Quoted 7 lines
Quoted 2 lines
Secondly, in order to read out the uevent that monitoring, we need to add uevent API in rte
layer. We plan add 2 ,
rte_uevent_connectandrte_get_uevent. All driver interrupt handler could use these API to enable the uevent monitoring, and read out the uevent type , then corresponding to handle these uevent, such as detach the device when get the remove type.Quoted 1 line
Quoted 5 lines
I find having a generic uevent API interesting.
However, all specifics pertaining to UIO use (
hotplug_fd, subsystem enum) should stay in UIO specific code (eal_pci_uio.c?).
Yes, but it can be also considered as interrupt mechanism, right?
Quoted 2 lines
I am currently moving the PCI bus out of the EAL. EAL subsystems should not rely on PCI specifics, as they won't be available afterward.
Will the interrupt handling be kept in EAL, right?
Quoted 3 lines
It should also allow you to clean up your API. Exposing
hotplug_fdand requiring PMDs to link it can be avoided and should result in a simpler API.
Didn't get the idea. Why it will result in a simpler API? Is there any patch help Me to understand?
Thanks
Jingjing
Hi Jingjing,
Quoted 7 lines · Jingjing
Quoted 7 lines
Quoted 2 lines
Secondly, in order to read out the uevent that monitoring, we need to add uevent API in rte
layer. We plan add 2 ,
rte_uevent_connectandrte_get_uevent. All driver interrupt handler could use these API to enable the uevent monitoring, and read out the uevent type , then corresponding to handle these uevent, such as detach the device when get the remove type.Quoted 1 line
Quoted 7 lines
Quoted 5 lines
I find having a generic uevent API interesting.
However, all specifics pertaining to UIO use (
hotplug_fd, subsystem enum) should stay in UIO specific code (eal_pci_uio.c?).Yes, but it can be also considered as interrupt mechanism, right?
Sure.
Quoted 5 lines
Quoted 2 lines
I am currently moving the PCI bus out of the EAL. EAL subsystems should not rely on PCI specifics, as they won't be available afterward.
Will the interrupt handling be kept in EAL, right?
Ah yes, I was actually mistaken and thought more UIO parts would be moving.
Quoted 6 lines
Quoted 3 lines
It should also allow you to clean up your API. Exposing
hotplug_fdand requiring PMDs to link it can be avoided and should result in a simpler API.Didn't get the idea. Why it will result in a simpler API? Is there any patch help Me to understand?
How do you demux the hotplug_fd for several drivers / device?
Signature · 2 lines
Gaëtan Rivet 6WIND
hi,gaetan
Quoted 14 lines · Gaëtan Rivet
Hi Jingjing,
Quoted 11 lines · Jingjing
Quoted 9 lines
Quoted 1 line
Secondly, in order to read out the uevent that monitoring, we need to add uevent API in rte
layer. We plan add 2 ,
rte_uevent_connectandrte_get_uevent. All driver interrupt handler could use these API to enable the uevent monitoring, and read out the uevent type , then corresponding to handle these uevent, such as detach the device when get the remove type. I find having a generic uevent API interesting.However, all specifics pertaining to UIO use (
hotplug_fd, subsystem enum) should stay in UIO specific code (eal_pci_uio.c?).Yes, but it can be also considered as interrupt mechanism, right?
Quoted 8 lines
Sure.
Quoted 4 lines
Quoted 2 lines
I am currently moving the PCI bus out of the EAL. EAL subsystems should not rely on PCI specifics, as they won't be available afterward.
Will the interrupt handling be kept in EAL, right?
Ah yes, I was actually mistaken and thought more UIO parts would be moving.
so , i assumption that the interrupt handling still be kept in EAL, so that would not affect my adding the uevent in the eal interrupt part, right? so if it have any other dependency, please shout to let me know.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
It should also allow you to clean up your API. Exposing
hotplug_fdand requiring PMDs to link it can be avoided and should result in a simpler API.Didn't get the idea. Why it will result in a simpler API? Is there any patch help Me to understand?
How do you demux the
hotplug_fdfor several drivers / device?
it is related with the dual port/device/driver problem, i think what should be some mapping of the dev_path there, i will refine the part to handle it in v2. Thanks.
PATCH v2 1/2 eal: add uevent api for hot plug
In reply to Jeff GuoFrom: "Guo, Jia" <[email protected]>
This patch aim to add a variable "uevent_fd" in structure "rte_intr_handle" for enable kernel object uevent monitoring, and add some uevent API in rte eal interrupt, that is “rte_uevent_connect” and “rte_uevent_get”, so that all driver could use these API to monitor and read out the uevent, then corresponding to handle these uevent, such as detach or attach the device.
---v2->v1: remove global variables of hotplug_fd, add uevent_fd
in rte_intr_handle to let each pci device self maintain to fix dual device fd issue. refine some typo error.
--- lib/librte_eal/common/eal_common_pci_uio.c | 6 +- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 143 ++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 12 ++ .../linuxapp/eal/include/exec-env/rte_interrupts.h | 34 +++++ 4 files changed, 192 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_pci_uio.c +5 -1
@@ -117,6 +117,7 @@ dev->intr_handle.fd =-1 ; dev->intr_handle.uio_cfg_fd =-1 ; + dev->intr_handle.uevent_fd =-1 ; dev->intr_handle.type =RTE_INTR_HANDLE_UNKNOWN ;/* secondary processes - use already recorded details */
@@ -227,7 +228,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 ; + } dev->intr_handle.fd =-1 ; dev->intr_handle.type =RTE_INTR_HANDLE_UNKNOWN ; }
lib/librte_eal/linuxapp/eal/eal_interrupts.c +141 -2
173 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +12 -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;
@@ -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; + } +if (dev->kdrv ==RTE_KDRV_IGB_UIO ) dev->intr_handle.type =RTE_INTR_HANDLE_UIO ;else {
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +34 -0
@@ -90,6 +90,7 @@ struct rte_intr_handle {for uio_pci_generic */ };int fd;/**< interrupt event file descriptor */ +int uevent_fd;/**< uevent file descriptor */ enum rte_intr_handle_type type;/**< handle type */ uint32_t max_intr;/**< max interrupt requested */ uint32_t nb_efd;/**< number of available efd(event fd) */
@@ -99,6 +100,16 @@ struct rte_intr_handle {int *intr_vec;/**< intr vector number array */ }; +enum rte_uevent_action { +RTE_UEVENT_ADD =0 ,/**< uevent type of device add */ +RTE_UEVENT_REMOVE =1 ,/**< uevent type of device remove*/ +}; + +struct rte_uevent { +enum rte_uevent_action action;/**< uevent action type */ +int subsystem;/**< subsystem id */ +}; +#define RTE_EPOLL_PER_THREAD -1/**< to hint using per thread epfd */ /**
@@ -236,4 +247,27 @@ struct rte_intr_handle {int rte_intr_cap_multiple (struct rte_intr_handle *intr_handle); +/** +* It read out the uevent from the specific file descriptor. +* +* @param fd +* The fd which the uevent associated to +* @param uevent +* Pointer to the uevent which read from the monitoring fd. +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_uevent_get (int fd,struct rte_uevent *uevent); + +/** +* Connect to the device uevent file descriptor. +* @return +* - On success, the connected uevent fd. +* - On failure, a negative value. +*/ +int +rte_uevent_connect (void ); +#endif /* _RTE_LINUXAPP_INTERRUPTS_H_ */
Signature · 1 line
1.8.3.1
PATCH v2 2/2 net/i40e: add hot plug monitor in i40e
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.
---v2->v1: remove unused part for current stage.
--- drivers/net/i40e/i40e_ethdev.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/net/i40e/i40e_ethdev.c +18 -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,28 @@ 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 ); + } + } + goto done; + } +/* read out interrupt causes */ icr0 =I40E_READ_REG (hw,I40E_PFINT_ICR0 );
Signature · 1 line
1.8.3.1
Re: [PATCH v2 2/2] net/i40e: add hot plug monitor in i40e
Quoted 43 lines
-----Original Message-----
From: Guo, Jia
Sent: Wednesday, June 28, 2017 7:07 PM
To: Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>
Cc: [email protected]; Guo, Jia <[email protected]>
Subject: [PATCH v2 2/2] net/i40e: add hot plug monitor in i40eFrom: "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]>---
v2->v1: remove unused part for current stage.--- drivers/net/i40e/i40e_ethdev.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/net/i40e/i40e_ethdev.c +1
-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 drivers/net/i40e/i40e_ethdev.c +2
-0* from VSIs. By doing so, we stop VF from sending out PAUSE or PFC @@ -5832,11 +5833,28 @@ 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;
drivers/net/i40e/i40e_ethdev.c struct i40e_vsi * { · line 5848
Quoted 10 lines
drivers/net/i40e/i40e_ethdev.c +6
-0+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 ) {
You declare the rte_uevnet_get like
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */
+int
+rte_uevent_get(int fd, struct rte_uevent *uevent);
But here you check if it > 0?
drivers/net/i40e/i40e_ethdev.c struct i40e_vsi * · line 5855
Quoted 7 lines
drivers/net/i40e/i40e_ethdev.c +7
-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 ); + } + } + goto done;
I think when the remove happen, no need to goto done, you can just return.
Quoted 7 lines
drivers/net/i40e/i40e_ethdev.c +2
-1+ } +/* read out interrupt causes */ icr0 =I40E_READ_REG (hw,I40E_PFINT_ICR0 ); --1.8.3.1
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 2/2] net/i40e: add hot plug monitor in i40e
In reply to Jeff GuoQuoted 8 lines · On Wed, 28 Jun 2017 19:07:24 +0800 Jeff Guo <[email protected]> wrote:
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]>---
Hot plug is good and needed.
But it needs to be done in a generic fashion in the bus layer. There is nothing about uevents that are unique to i40e or even Intel devices. Plus the way hotplug is handled is OS specific, so this isn't going to work well on BSD.
Sorry if I sound like a broken record but there has been a repeated pattern of Intel developers putting their head down (or in the sand) and creating functionality inside device driver.
Re: [PATCH v2 1/2] eal: add uevent api for hot plug
In reply to Wu, JingjingThe 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 2/2] net/i40e: add hot plug monitor in i40e
In reply to Wu, JingjingYes, if got remove uevent might be directly return to avoid invalid i/o. but if got other uevent such as add and change, must be go done to keep the interrupt process in device. I will refine this part, thanks.
Best regards,
Jeff Guo
-----Original Message-----
From: Wu, Jingjing
Sent: Thursday, June 29, 2017 9:42 AM
To: Guo, Jia <[email protected]>; Zhang, Helin <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v2 2/2] net/i40e: add hot plug monitor in i40e
Quoted 42 lines
-----Original Message-----
From: Guo, Jia
Sent: Wednesday, June 28, 2017 7:07 PM
To: Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>
Cc: [email protected]; Guo, Jia <[email protected]>
Subject: [PATCH v2 2/2] net/i40e: add hot plug monitor in i40eFrom: "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]>---
v2->v1: remove unused part for current stage.--- drivers/net/i40e/i40e_ethdev.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex 4ee1113..122187e 100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -1283,6 +1283,7 @@ static inline void i40e_GLQF_reg_init(struct
i40e_hw
*hw)drivers/net/i40e/i40e_ethdev.c +3
-0/* 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,28 @@ 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;
drivers/net/i40e/i40e_ethdev.c struct i40e_vsi * { · line 5848
Quoted 10 lines
drivers/net/i40e/i40e_ethdev.c +6
-0+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 ) {
You declare the rte_uevnet_get like
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */
+int
+rte_uevent_get(int fd, struct rte_uevent *uevent);
But here you check if it > 0?
drivers/net/i40e/i40e_ethdev.c struct i40e_vsi * · line 5855
Quoted 7 lines
drivers/net/i40e/i40e_ethdev.c +7
-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 ); + } + } + goto done;
I think when the remove happen, no need to goto done, you can just return.
Quoted 7 lines
drivers/net/i40e/i40e_ethdev.c +2
-1+ } +/* read out interrupt causes */ icr0 =I40E_READ_REG (hw,I40E_PFINT_ICR0 ); --1.8.3.1
v3 cover add uevent api for hot plug
In reply to Jeff GuoFrom: "Guo, Jia" <[email protected]>
This patch set aim to add a variable "uevent_fd" in structure "rte_intr_handle" for enable kernel object uevent monitoring, and add some uevent API in rte eal interrupt, that is “rte_uevent_connect” and “rte_uevent_get”. The patch use i40e for example, the driver could use these API to monitor and read out the uevent, then corresponding to handle these uevent, such as detach or attach the device.
Guo, Jia (2):
eal: add uevent api for hot plug
net/i40e: add hot plug monitor in i40e
drivers/net/i40e/i40e_ethdev.c | 19 +++ lib/librte_eal/common/eal_common_pci_uio.c | 6 +- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 136 ++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 + .../linuxapp/eal/include/exec-env/rte_interrupts.h | 37 ++++++ 5 files changed, 201 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v3 1/2 eal: add uevent api for hot plug
From: "Guo, Jia" <[email protected]>
This patch aim to add a variable "uevent_fd" in structure "rte_intr_handle" for enable kernel object uevent monitoring, and add some uevent API in rte eal interrupt, that is “rte_uevent_connect” and “rte_uevent_get”, so that all driver could use these API to monitor and read out the uevent, then corresponding to handle these uevent, such as detach or attach the device.
---v3->v2: refine some return error
refine the string searching logic to aviod memory issue
--- lib/librte_eal/common/eal_common_pci_uio.c | 6 +- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 136 ++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 + .../linuxapp/eal/include/exec-env/rte_interrupts.h | 37 ++++++ 4 files changed, 182 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_pci_uio.c +5 -1
@@ -117,6 +117,7 @@ dev->intr_handle.fd =-1 ; dev->intr_handle.uio_cfg_fd =-1 ; + dev->intr_handle.uevent_fd =-1 ; dev->intr_handle.type =RTE_INTR_HANDLE_UNKNOWN ;/* secondary processes - use already recorded details */
@@ -227,7 +228,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 ; + } dev->intr_handle.fd =-1 ; dev->intr_handle.type =RTE_INTR_HANDLE_UNKNOWN ; }
lib/librte_eal/linuxapp/eal/eal_interrupts.c +134 -2
160 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +6 -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 ;
@@ -276,6 +280,8 @@ goto error; } + dev->intr_handle.uevent_fd =rte_uevent_connect (); +if (dev->kdrv ==RTE_KDRV_IGB_UIO ) dev->intr_handle.type =RTE_INTR_HANDLE_UIO ;else {
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +37 -0
@@ -90,6 +90,7 @@ struct rte_intr_handle {for uio_pci_generic */ };int fd;/**< interrupt event file descriptor */ +int uevent_fd;/**< uevent file descriptor */ enum rte_intr_handle_type type;/**< handle type */ uint32_t max_intr;/**< max interrupt requested */ uint32_t nb_efd;/**< number of available efd(event fd) */
@@ -99,6 +100,19 @@ struct rte_intr_handle {int *intr_vec;/**< intr vector number array */ }; +#define RTE_UEVENT_MSG_LEN 4096 +#define RTE_UEVENT_SUBSYSTEM_UIO 1 + +enum rte_uevent_action { +RTE_UEVENT_ADD =0 ,/**< uevent type of device add */ +RTE_UEVENT_REMOVE =1 ,/**< uevent type of device remove*/ +}; + +struct rte_uevent { +enum rte_uevent_action action;/**< uevent action type */ +int subsystem;/**< subsystem id */ +}; +#define RTE_EPOLL_PER_THREAD -1/**< to hint using per thread epfd */ /**
@@ -236,4 +250,27 @@ struct rte_intr_handle {int rte_intr_cap_multiple (struct rte_intr_handle *intr_handle); +/** +* It read out the uevent from the specific file descriptor. +* +* @param fd +* The fd which the uevent associated to +* @param uevent +* Pointer to the uevent which read from the monitoring fd. +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_uevent_get (int fd,struct rte_uevent *uevent); + +/** +* Connect to the device uevent file descriptor. +* @return +* - On success, the connected uevent fd. +* - On failure, a negative value. +*/ +int +rte_uevent_connect (void ); +#endif /* _RTE_LINUXAPP_INTERRUPTS_H_ */
Signature · 1 line
1.8.3.1
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 v2 2/2] net/i40e: add hot plug monitor in i40e
In reply to Stephen HemmingerQuoted 22 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, June 29, 2017 11:35 AM
To: Guo, Jia <[email protected]>
Cc: Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v2 2/2] net/i40e: add hot plug monitor in i40eQuoted 8 lines · On Wed, 28 Jun 2017 19:07:24 +0800 Jeff Guo <[email protected]> wrote:
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]>---
Quoted 7 lines
Hot plug is good and needed.
But it needs to be done in a generic fashion in the bus layer.
There is nothing about uevents that are unique to i40e or even Intel devices. Plus the way hotplug is handled is OS specific, so this isn't going to work well on BSD.
This patch is not a way to full support hut plug. And we know it is handled in OS specific. This patch just provides a way to tell DPDK user the remove happened on this device (DPDK dev).
And Mlx driver already supports that with patch
http://dpdk.org/dev/patchwork/patch/23695/
What GuoJia did is just making the EVENT can be process by application through interrupt callback Mechanisms.
Quoted 3 lines
Sorry if I sound like a broken record but there has been a repeated pattern of Intel developers putting their head down (or in the sand) and creating functionality inside device driver.
Sorry, I cannot agree.
Thanks
Jingjing
v3 cover add uevent api for hot plug
In reply to Jeff GuoFrom: "Guo, Jia" <[email protected]>
This patch set aim to add a variable "uevent_fd" in structure "rte_intr_handle" for enable kernel object uevent monitoring, and add some uevent API in rte eal interrupt, that is “rte_uevent_connect” and “rte_uevent_get”. The patch use i40e for example, the driver could use these API to monitor and read out the uevent, then corresponding to handle these uevent, such as detach or attach the device.
Guo, Jia (2):
eal: add uevent api for hot plug
net/i40e: add hot plug monitor in i40e
drivers/net/i40e/i40e_ethdev.c | 19 +++ lib/librte_eal/common/eal_common_pci_uio.c | 6 +- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 136 ++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 + .../linuxapp/eal/include/exec-env/rte_interrupts.h | 37 ++++++ 5 files changed, 201 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v3 1/2 eal: add uevent api for hot plug
From: "Guo, Jia" <[email protected]>
This patch aim to add a variable "uevent_fd" in structure "rte_intr_handle" for enable kernel object uevent monitoring, and add some uevent API in rte eal interrupt, that is “rte_uevent_connect” and “rte_uevent_get”, so that all driver could use these API to monitor and read out the uevent, then corresponding to handle these uevent, such as detach or attach the device.
---v3->v2: refine some return error
refine the string searching logic to aviod memory issue
--- lib/librte_eal/common/eal_common_pci_uio.c | 6 +- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 136 ++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 + .../linuxapp/eal/include/exec-env/rte_interrupts.h | 37 ++++++ 4 files changed, 182 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_pci_uio.c +5 -1
@@ -117,6 +117,7 @@ dev->intr_handle.fd =-1 ; dev->intr_handle.uio_cfg_fd =-1 ; + dev->intr_handle.uevent_fd =-1 ; dev->intr_handle.type =RTE_INTR_HANDLE_UNKNOWN ;/* secondary processes - use already recorded details */
@@ -227,7 +228,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 ; + } dev->intr_handle.fd =-1 ; dev->intr_handle.type =RTE_INTR_HANDLE_UNKNOWN ; }
lib/librte_eal/linuxapp/eal/eal_interrupts.c +134 -2
160 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +6 -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 ;
@@ -276,6 +280,8 @@ goto error; } + dev->intr_handle.uevent_fd =rte_uevent_connect (); +if (dev->kdrv ==RTE_KDRV_IGB_UIO ) dev->intr_handle.type =RTE_INTR_HANDLE_UIO ;else {
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +37 -0
@@ -90,6 +90,7 @@ struct rte_intr_handle {for uio_pci_generic */ };int fd;/**< interrupt event file descriptor */ +int uevent_fd;/**< uevent file descriptor */ enum rte_intr_handle_type type;/**< handle type */ uint32_t max_intr;/**< max interrupt requested */ uint32_t nb_efd;/**< number of available efd(event fd) */
@@ -99,6 +100,19 @@ struct rte_intr_handle {int *intr_vec;/**< intr vector number array */ }; +#define RTE_UEVENT_MSG_LEN 4096 +#define RTE_UEVENT_SUBSYSTEM_UIO 1 + +enum rte_uevent_action { +RTE_UEVENT_ADD =0 ,/**< uevent type of device add */ +RTE_UEVENT_REMOVE =1 ,/**< uevent type of device remove*/ +}; + +struct rte_uevent { +enum rte_uevent_action action;/**< uevent action type */ +int subsystem;/**< subsystem id */ +}; +#define RTE_EPOLL_PER_THREAD -1/**< to hint using per thread epfd */ /**
@@ -236,4 +250,27 @@ struct rte_intr_handle {int rte_intr_cap_multiple (struct rte_intr_handle *intr_handle); +/** +* It read out the uevent from the specific file descriptor. +* +* @param fd +* The fd which the uevent associated to +* @param uevent +* Pointer to the uevent which read from the monitoring fd. +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_uevent_get (int fd,struct rte_uevent *uevent); + +/** +* Connect to the device uevent file descriptor. +* @return +* - On success, the connected uevent fd. +* - On failure, a negative value. +*/ +int +rte_uevent_connect (void ); +#endif /* _RTE_LINUXAPP_INTERRUPTS_H_ */
Signature · 1 line
1.8.3.1
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 v2 2/2] net/i40e: add hot plug monitor in i40e
In reply to Wu, JingjingAgree with jingjing.
That patch is definitely not for generic fashion of hot plug, the uevent just give the adding approach to monitor the remove event even if the driver not add it as interrupt , we know mlx driver have already implement the event of remove interrupt into their infinite framework driver, but other driver maybe not yet. So uevent is not unique for i40e or other intel nic, the aim just let more diversity drivers which use pci-uio framework to use the common hot plug feature in DPDK.
Best regards,
Jeff Guo
-----Original Message-----
From: Wu, Jingjing
Sent: Thursday, June 29, 2017 12:48 PM
To: Stephen Hemminger <[email protected]>; Guo, Jia <[email protected]>
Cc: Zhang, Helin <[email protected]>; [email protected]; Chang, Cunyin <[email protected]>; Liang, Cunming <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v2 2/2] net/i40e: add hot plug monitor in i40e
Quoted 21 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, June 29, 2017 11:35 AM
To: Guo, Jia <[email protected]>
Cc: Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v2 2/2] net/i40e: add hot plug monitor in i40eQuoted 8 lines · On Wed, 28 Jun 2017 19:07:24 +0800 Jeff Guo <[email protected]> wrote:
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]>---
Quoted 7 lines
Hot plug is good and needed.
But it needs to be done in a generic fashion in the bus layer. There is nothing about uevents that are unique to i40e or even Intel devices. Plus the way hotplug is handled is OS specific, so this isn't going to work well on BSD.
This patch is not a way to full support hut plug. And we know it is handled in OS specific. This patch just provides a way to tell DPDK user the remove happened on this device (DPDK dev).
And Mlx driver already supports that with patch http://dpdk.org/dev/patchwork/patch/23695/
What GuoJia did is just making the EVENT can be process by application through interrupt callback Mechanisms.
Quoted 3 lines
Sorry if I sound like a broken record but there has been a repeated pattern of Intel developers putting their head down (or in the sand) and creating functionality inside device driver.
Sorry, I cannot agree.
Thanks
Jingjing
Quoted 12 lines · Jingjing
Quoted 7 lines
Quoted 2 lines
Secondly, in order to read out the uevent that monitoring, we need to add uevent API in rte
layer. We plan add 2 ,
rte_uevent_connectandrte_get_uevent. All driver interrupt handler could use these API to enable the uevent monitoring, and read out the uevent type , then corresponding to handle these uevent, such as detach the device when get the remove type.Quoted 1 line
Quoted 5 lines
I find having a generic uevent API interesting.
However, all specifics pertaining to UIO use (
hotplug_fd, subsystem enum) should stay in UIO specific code (eal_pci_uio.c?).
Quoted 10 lines
Yes, but it can be also considered as interrupt mechanism, right?
Quoted 2 lines
I am currently moving the PCI bus out of the EAL. EAL subsystems should not rely on PCI specifics, as they won't be available afterward.
Will the interrupt handling be kept in EAL, right?
Quoted 3 lines
It should also allow you to clean up your API. Exposing
hotplug_fdand requiring PMDs to link it can be avoided and should result in a simpler API.
You were right given the current model this is the correct way to do it. It would be good if the interrupt model stuff could be moved back into EAL so that if device is removed, no code in driver needs to be added.
All the bus -> device -> interrupt state is visible, and EAL should be able to unwind from there. Thinking more of the Linux model where there is no need (in general) for hot plug specific code in each driver.
Quoted 36 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, June 30, 2017 1:28 AM
To: Wu, Jingjing <[email protected]>
Cc: Gaëtan Rivet <[email protected]>; Guo, Jia <[email protected]>; Zhang, Helin <[email protected]>; Richardson, Bruce <[email protected]>; Ananyev, Konstantin <[email protected]>; Liu, Yuanhan <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [RFC] Add hot plug event in rte eal interrupt and inplement it in i40e driver.Quoted 6 lines · Jingjing
Quoted 6 lines
Quoted 3 lines
Secondly, in order to read out the uevent that monitoring, we need to add uevent API in rte
layer. We plan add 2 ,
rte_uevent_connectandrte_get_uevent. All driver interrupt handler could use these API to enable the uevent monitoring, and read out the uevent type , then corresponding to handlethese uevent, such as detach the device when get the remove type.
Quoted 12 lines
Quoted 7 lines
Quoted 1 line
I find having a generic uevent API interesting.
However, all specifics pertaining to UIO use (
hotplug_fd, subsystem enum) should stay in UIO specific code (eal_pci_uio.c?).Yes, but it can be also considered as interrupt mechanism, right?
Quoted 2 lines
I am currently moving the PCI bus out of the EAL. EAL subsystems should not rely on PCI specifics, as they won't be available afterward.
Quoted 7 lines
Quoted 5 lines
Will the interrupt handling be kept in EAL, right?
Quoted 3 lines
It should also allow you to clean up your API. Exposing
hotplug_fdand requiring PMDs to link it can be avoided and should result in a simpler API.You were right given the current model this is the correct way to do it.
Does it mean this way in this RFC is reasonable given the current model?
Quoted 3 lines
It would be good if the interrupt model stuff could be moved back into EAL so that if device is removed, no code in driver needs to be added.
At list we still need expose some interrupt/event by drivers. Such as LSC, Rx interrupt.
Quoted 3 lines
All the bus -> device -> interrupt state is visible, and EAL should be able to unwind from there. Thinking more of the Linux model where there is no need (in general) for hot plug specific code in each driver.
Yes, such simpler API is what I like to see too. But now, the remove event report by this way is more economical.
Thanks
Jingjing
Re: [PATCH v3 1/2] eal: add uevent api for hot plug
In reply to Jeff GuoQuoted 12 lines
-----Original Message-----
From: Guo, Jia
Sent: Thursday, June 29, 2017 12:38 PM
To: Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>
Cc: [email protected]; Guo, Jia <[email protected]>
Subject: [PATCH v3 1/2] eal: add uevent api for hot plugFrom: "Guo, Jia" <[email protected]>
Quoted 7 lines
This patch aim to add a variable "
uevent_fd" in structure "rte_intr_handle" for enable kernel object uevent monitoring, and add some uevent API in rte eal interrupt, that is “rte_uevent_connect” and “rte_uevent_get”, so that all driver could use these API to monitor and read out the uevent, then corresponding to handle these uevent, such as detach or attach the device.Signed-off-by Guo, Jia <[email protected]>
Looks fine from me.
Re: [PATCH v3 2/2] net/i40e: add hot plug monitor in i40e
In reply to Jeff GuoQuoted 10 lines
-----Original Message-----
From: Guo, Jia
Sent: Thursday, June 29, 2017 12:38 PM
To: Zhang, Helin <[email protected]>; Wu, Jingjing <[email protected]>
Cc: [email protected]; Guo, Jia <[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 GuoQuoted 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 1/2] eal: add uevent api for hot plug
In reply to Jeff GuoQuoted 15 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 1/2] eal: add uevent api for hot plugFrom: "Guo, Jia" <[email protected]>
Quoted 7 lines
This patch aim to add a variable "
uevent_fd" in structure "rte_intr_handle" for enable kernel object uevent monitoring, and add some uevent API in rte eal interrupt, that is “rte_uevent_connect” and “rte_uevent_get”, so that all driver could use these API to monitor and read out the uevent, then corresponding to handle these uevent, such as detach or attach the device.Signed-off-by Guo, Jia <[email protected]>
Looks fine from me.
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 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 Guo, Jiaa. 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
v4 cover add uevent monitor for hot plug
In reply to Jeff GuoSo 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: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 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:v4->v3:
move uevent monitor api from eal interrupt to eal device layer. create uevent type and struct in eal device.
move uevent handler for each driver to eal layer.
add uevent failure handler to process signal fault issue. add example for request and use uevent monitoring in testpmd.
v3->v2:
refine some return error
refine the string searching logic to avoid memory issue
v2->v1:
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. refine some typo error.
Jeff Guo (2):
eal: add uevent monitor for hot plug
app/testpmd: use uevent to monitor hot removal
app/test-pmd/testpmd.c | 62 ++++++ lib/librte_eal/common/eal_common_dev.c | 248 ++++++++++++++++++++- lib/librte_eal/common/eal_common_pci.c | 20 ++ lib/librte_eal/common/eal_private.h | 14 ++ lib/librte_eal/common/include/rte_dev.h | 136 +++++++++++ lib/librte_eal/common/include/rte_pci.h | 17 ++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 28 ++- lib/librte_eal/linuxapp/eal/eal_pci_init.h | 4 + lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 62 ++++++ .../linuxapp/eal/include/exec-env/rte_interrupts.h | 2 +- 10 files changed, 586 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
PATCH v4 1/2 eal: add uevent monitor for hot plug
This patch aim to add a general uevent mechanism in eal device layer, to enable all kernel object hot plug monitoring, so user could use these API to monitor and read out the device status info sent from the kernel side, then corresponding to handle it, such as detach or attach the device, and even benefit to use it for do smoothly fail safe work.
1) About uevent monitoring:
a: add uevent_fd in struct rte_intr_handle, and use eal interrupt
epolling to monitoring the netlink of uevent_fd.
b: add enum of rte_eal_uevent_type and struct of rte_eal_uevent.
c: add below API in rte eal device layer.
rte_eal_uev_fd_new
rte_eal_uev_enable
rte_eal_uev_receive
rte_eal_uev_callback_register rte_eal_uev_callback_unregister
2) About uevent handler and failure handler, use pci uio for example, add below API to process it:
pci_uio_uev_handler
pci_uio_remap_resource
pci_map_private_resource
---v4->v3:
move uevent monitor api from eal interrupt to eal device layer. create uevent type and struct in eal device.
move uevent handler for each driver to eal layer.
add uevent failure handler to process signal fault issue. add example for request and use uevent monitoring in testpmd.
--- lib/librte_eal/common/eal_common_dev.c | 248 ++++++++++++++++++++- lib/librte_eal/common/eal_common_pci.c | 20 ++ lib/librte_eal/common/eal_private.h | 14 ++ lib/librte_eal/common/include/rte_dev.h | 136 +++++++++++ lib/librte_eal/common/include/rte_pci.h | 17 ++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 28 ++- lib/librte_eal/linuxapp/eal/eal_pci_init.h | 4 + lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 62 ++++++ .../linuxapp/eal/include/exec-env/rte_interrupts.h | 2 +- 9 files changed, 524 insertions(+), 7 deletions(-)
lib/librte_eal/common/eal_common_dev.c +247 -1
@@ -36,15 +36,41 @@#include <string.h> #include <inttypes.h> #include <sys/queue.h> - +#include <sys/signalfd.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <sys/epoll.h> +#include <unistd.h> + +#include <rte_malloc.h> #include <rte_bus.h> #include <rte_dev.h> #include <rte_devargs.h> #include <rte_debug.h> #include <rte_log.h> +#include <rte_spinlock.h> #include "eal_private.h" +/* spinlock for uevent callbacks */ +static rte_spinlock_t rte_eal_uev_cb_lock =RTE_SPINLOCK_INITIALIZER ; + +/** +* The user application callback description. +* +* It contains callback address to be registered by user application, +* the pointer to the parameters for callback, and the event type. +*/ +struct rte_eal_uev_callback { +TAILQ_ENTRY (rte_eal_uev_callback) next;/**< Callbacks list */ +rte_eal_uev_cb_fn cb_fn;/**< Callback address */ +void *cb_arg;/**< Parameter for callback */ +void *ret_param;/**< Return parameter */ +enum rte_eal_uevent_type event;/**< Interrupt event type */ +uint32_t active;/**< Callback is executing */ +}; +static int cmp_detached_dev_name (const struct rte_device *dev,const void *_name) {
@@ -244,3 +270,223 @@ int rte_eal_hotplug_remove(const char *busname, const char *devname)rte_eal_devargs_remove (busname, devname);return ret; } + +int +rte_eal_uev_fd_new (void ) +{ + +int netlink_fd =-1 ; + + netlink_fd =socket (PF_NETLINK ,SOCK_DGRAM ,NETLINK_KOBJECT_UEVENT ); +if (netlink_fd <0 ) +return -1 ; + +return netlink_fd; +} + +int +rte_eal_uev_enable (int netlink_fd) +{ +struct sockaddr_nl addr; +int ret; +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 ; + +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 0 ; +} + +static int +rte_eal_uev_parse (const char *buf,struct rte_eal_uevent *event) +{ +char action[RTE_EAL_UEVENT_MSG_LEN ]; +char subsystem[RTE_EAL_UEVENT_MSG_LEN ]; +char dev_path[RTE_EAL_UEVENT_MSG_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (subsystem,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (dev_path,0 ,RTE_EAL_UEVENT_MSG_LEN ); + +while (i <RTE_EAL_UEVENT_MSG_LEN ) { +for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ; +snprintf (dev_path,sizeof (dev_path),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + } +for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +if ((!strncmp (subsystem,"uio" ,3 )) || + (!strncmp (subsystem,"pci" ,3 ))) { + event->subsystem =RTE_EAL_UEVENT_SUBSYSTEM_UIO ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_EAL_UEVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_EAL_UEVENT_REMOVE ; +return 0 ; + } + +return -1 ; +} + +int +rte_eal_uev_receive (int fd,struct rte_eal_uevent *uevent) +{ +int ret; +char buf[RTE_EAL_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_eal_uevent )); +memset (buf,0 ,RTE_EAL_UEVENT_MSG_LEN ); + + ret =recv (fd, buf,RTE_EAL_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT ); +if (ret >0 ) +return rte_eal_uev_parse (buf, uevent); +else if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s\n" , + errno,strerror (errno)); +return -1 ; + }else +/* connection closed */ +return -1 ; +} + +int +rte_eal_uev_callback_register (struct rte_device *dev, +enum rte_eal_uevent_type event, +rte_eal_uev_cb_fn cb_fn,void *cb_arg) +{ +struct rte_eal_uev_callback *user_cb; + +if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&rte_eal_uev_cb_lock); + + TAILQ_FOREACH(user_cb, &(dev->uev_cbs), next) { +if (user_cb->cb_fn == cb_fn && + user_cb->cb_arg == cb_arg && + user_cb->event == event) { +break ; + } + } + +/* create a new callback. */ +if (user_cb ==NULL ) { + user_cb =rte_zmalloc ("EAL_UEV_CALLBACK" , +sizeof (struct rte_eal_uev_callback ),0 ); +if (user_cb !=NULL ) { + user_cb->cb_fn = cb_fn; + user_cb->cb_arg = cb_arg; + user_cb->event = event; +TAILQ_INSERT_TAIL (&(dev->uev_cbs), user_cb, next); + } + } + +rte_spinlock_unlock (&rte_eal_uev_cb_lock); +return (user_cb ==NULL ) ? -ENOMEM :0 ; +} + +int +rte_eal_uev_callback_unregister (struct rte_device *dev, +enum rte_eal_uevent_type event, +rte_eal_uev_cb_fn cb_fn,void *cb_arg) +{ +int ret; +struct rte_eal_uev_callback *cb, *next; + +if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&rte_eal_uev_cb_lock); + + ret =0 ; +for (cb =TAILQ_FIRST (&dev->uev_cbs); cb !=NULL ; cb = next) { + + next =TAILQ_NEXT (cb, next); + +if (cb->cb_fn != cb_fn || cb->event != event || + (cb->cb_arg != (void *)-1 && + cb->cb_arg != cb_arg)) +continue ; + +/* +* if this callback is not executing right now, +* then remove it. +*/ +if (cb->active ==0 ) { +TAILQ_REMOVE (&(dev->uev_cbs), cb, next); +rte_free (cb); + }else { + ret = -EAGAIN ; + } + } + +rte_spinlock_unlock (&rte_eal_uev_cb_lock); +return ret; +} + +int +_rte_eal_uev_callback_process (struct rte_device *dev, +enum rte_eal_uevent_type event,void *cb_arg,void *ret_param) +{ +struct rte_eal_uev_callback *cb_lst; +struct rte_eal_uev_callback dev_cb; +int rc =0 ; + +rte_spinlock_lock (&rte_eal_uev_cb_lock); + TAILQ_FOREACH(cb_lst, &(dev->uev_cbs), next) { +if (cb_lst->cb_fn ==NULL || cb_lst->event != event) +continue ; + dev_cb = *cb_lst; + cb_lst->active =1 ; +if (cb_arg !=NULL ) + dev_cb.cb_arg = cb_arg; +if (ret_param !=NULL ) + dev_cb.ret_param = ret_param; + +rte_spinlock_unlock (&rte_eal_uev_cb_lock); + rc = dev_cb.cb_fn (dev, dev_cb.event, + dev_cb.cb_arg, dev_cb.ret_param); +rte_spinlock_lock (&rte_eal_uev_cb_lock); + cb_lst->active =0 ; + } +rte_spinlock_unlock (&rte_eal_uev_cb_lock); +return rc; +}
lib/librte_eal/common/eal_common_pci.c +20 -0
@@ -110,6 +110,26 @@ pci_name_set(struct rte_pci_device *dev) dev->device.name = dev->name; } +/* 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 * pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
lib/librte_eal/common/eal_private.h +14 -0
@@ -192,6 +192,8 @@ int pci_uio_map_resource(struct rte_pci_device *dev);*/ void pci_uio_unmap_resource (struct rte_pci_device *dev); +void pci_uio_uev_handler (void *parm); +/** * Allocate uio resource for PCI device *
@@ -222,6 +224,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.
lib/librte_eal/common/include/rte_dev.h +136 -0
154 lines not on this page · raw message
lib/librte_eal/common/include/rte_pci.h +17 -0
@@ -394,6 +394,23 @@ void rte_pci_unmap_device(struct rte_pci_device *dev);/** * @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); + +/** +* @internal * Map a particular resource from a file. * * @param requested_addr
lib/librte_eal/linuxapp/eal/eal_interrupts.c +23 -5
@@ -670,11 +670,16 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)RTE_SET_USED (r);return -1 ; } +rte_spinlock_lock (&intr_lock); - TAILQ_FOREACH(src, &intr_sources, next) + TAILQ_FOREACH(src, &intr_sources, next) {if (src->intr_handle.fd == events[n].data.fd)break ; +else if (src->intr_handle.uevent_fd == + events[n].data.fd) +break ; + }if (src ==NULL ){rte_spinlock_unlock (&intr_lock);continue ;
@@ -736,17 +741,13 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)rte_spinlock_lock (&intr_lock);if (call) { -/* Finally, call all callbacks. */ TAILQ_FOREACH(cb, &src->callbacks, next) { -/* make a copy and unlock. */ active_cb = *cb;rte_spinlock_unlock (&intr_lock); -/* call the actual callback */ active_cb.cb_fn (active_cb.cb_arg); -/*get the lock back. */ rte_spinlock_lock (&intr_lock); }
@@ -859,7 +860,24 @@ eal_intr_thread_main(__rte_unused void *arg) }else numfds++; + +/** +* add device uevent file descriptor +* into wait list for uevent monitoring. +*/ + ev.events =EPOLLIN |EPOLLPRI |EPOLLRDHUP |EPOLLHUP ; + ev.data.fd = src->intr_handle.uevent_fd; +if (epoll_ctl (pfd,EPOLL_CTL_ADD , + src->intr_handle.uevent_fd, &ev) <0 ){ +rte_panic ("Error adding uevent_fd %d epoll_ctl" +", %s\n" , + src->intr_handle.uevent_fd, +strerror (errno)); + }else + numfds++; } + +rte_spinlock_unlock (&intr_lock);/* serve the interrupt */ eal_intr_handle_interrupts (pfd, numfds);
lib/librte_eal/linuxapp/eal/eal_pci_init.h +4 -0
@@ -52,10 +52,14 @@ void *pci_find_max_end_va(void);int pci_parse_one_sysfs_resource (char *line,size_t len,uint64_t *phys_addr,uint64_t *end_addr,uint64_t *flags); +void pci_uio_uev_handler (void *param);int pci_uio_alloc_resource (struct rte_pci_device *dev,struct mapped_pci_resource **uio_res);void pci_uio_free_resource (struct rte_pci_device *dev,struct mapped_pci_resource *uio_res); + +int pci_uio_remap_resource (struct rte_pci_device *dev); +int pci_uio_map_resource_by_index (struct rte_pci_device *dev,int res_idx,struct mapped_pci_resource *uio_res,int map_idx);
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +62 -0
86 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +1 -1
@@ -90,6 +90,7 @@ struct rte_intr_handle {for uio_pci_generic */ };int fd;/**< interrupt event file descriptor */ +int uevent_fd;/**< uevent file descriptor */ enum rte_intr_handle_type type;/**< handle type */ uint32_t max_intr;/**< max interrupt requested */ uint32_t nb_efd;/**< number of available efd(event fd) */
@@ -235,5 +236,4 @@ rte_intr_allow_others(struct rte_intr_handle *intr_handle);*/ int rte_intr_cap_multiple (struct rte_intr_handle *intr_handle); -#endif /* _RTE_LINUXAPP_INTERRUPTS_H_ */
Signature · 1 line
2.7.4
PATCH v4 2/2 app/testpmd: use uevent to monitor hot removal
In reply to Jeff Guouse testpmd for example, to show app how to request and use uevent monitoring to handle an event of device hot removal.
--- app/test-pmd/testpmd.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
app/test-pmd/testpmd.c +62 -0
@@ -393,6 +393,10 @@ static void check_all_ports_link_status(uint32_t port_mask);static int eth_event_callback (uint8_t port_id,enum rte_eth_event_type type,void *param,void *ret_param); +static int eth_uevent_callback (struct rte_device *dev, +enum rte_eal_uevent_type type, +void *param,void *ret_param); +/* * Check if all the ports are started.
@@ -1413,6 +1417,7 @@ start_port(portid_t pid)struct rte_port *port;struct ether_addr mac_addr;enum rte_eth_event_type event_type; +enum rte_eal_uevent_type uevent_type;if (port_id_is_invalid (pid,ENABLED_WARN ))return 0 ;
@@ -1548,6 +1553,18 @@ start_port(portid_t pid) } } +for (uevent_type =RTE_EAL_UEVENT_UNKNOWN ; + uevent_type <RTE_EAL_UEVENT_MAX ; + uevent_type++) { + diag =rte_eal_uev_callback_register (&port->dev_info.pci_dev->device,uevent_type, + eth_uevent_callback,NULL ); +if (diag) { +printf ("Failed to setup uevent callback for uevent %d\n" , + uevent_type); +return -1 ; + } + } +/* start port */ if (rte_eth_dev_start (pi) <0 ) {printf ("Fail to start port %d\n" , pi);
@@ -1842,6 +1859,16 @@ rmv_event_callback(void *arg) dev->device->name); } +static void +rmv_uevent_callback (void *arg) +{ +struct rte_device *dev = (struct rte_device *)arg; +printf ("removing device %s\n" , dev->name); +if (rte_eal_dev_detach (dev)) +RTE_LOG (ERR ,USER1 ,"Failed to detach device %s\n" , + dev->name); +} +/* This function is used by the interrupt thread */ static int eth_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param,
@@ -1883,6 +1910,41 @@ eth_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param,return 0 ; } +/* This function is used by the interrupt thread */ +static int +eth_uevent_callback (struct rte_device *dev,enum rte_eal_uevent_type type,void *param, +void *ret_param) +{ +static const char *const event_desc[] = { + [RTE_EAL_UEVENT_UNKNOWN ] ="Unknown" , + [RTE_EAL_UEVENT_REMOVE ] ="remove" , + }; + +RTE_SET_USED (param); +RTE_SET_USED (ret_param); + +if (type >=RTE_EAL_UEVENT_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_EAL_UEVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_uevent_callback, (void *)dev)) +fprintf (stderr,"Could not set up deferred device removal\n" ); +break ; +default : +break ; + } +return 0 ; +} +static int set_tx_queue_stats_mapping_registers (uint8_t port_id,struct rte_port *port) {
Signature · 1 line
2.7.4
Re: [PATCH v4 1/2] eal: add uevent monitor for hot plug
In reply to Jeff Guolib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname)
Quoted 7 lines · On Sun, 3 Sep 2017 23:49:44 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/common/eal_common_dev.c +7
-0+int +rte_eal_uev_fd_new (void ) +{ + +int netlink_fd =-1 ; + + netlink_fd = socket(PF
Please don't use the "initialize everything" style of programming.
Gcc has good detection and warning about uninitalized variables, and this style defeats that.
Re: [PATCH v4 1/2] eal: add uevent monitor for hot plug
In reply to Jeff Guolib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 294
Quoted 8 lines · On Sun, 3 Sep 2017 23:49:44 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/common/eal_common_dev.c +8
-0+int +rte_eal_uev_enable (int netlink_fd) +{ +struct sockaddr_nl addr; +int ret; +int size =64 *1024 ; +int nonblock =1 ; +memset (&addr,0 ,sizeof (addr));
Blank line between declarations and code.
Also use C99 style intializations not memset.
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 297
Quoted 3 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+ addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ;
You don't need or want all events. specify which group you want.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + setsockopt(netlink_fd, SOL_SOCKET, SO_RCVBUFFORCE, &size, sizeof(size));
Don't user BUFFORCE, that is only available as root. Just doing SO_RCVBUF is enough.
Re: [PATCH v4 1/2] eal: add uevent monitor for hot plug
In reply to Jeff Guolib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 375
Quoted 4 lines · On Sun, 3 Sep 2017 23:49:44 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/common/eal_common_dev.c +4
-0+char buf[RTE_EAL_UEVENT_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_eal_uevent )); +memset (buf,0 ,RTE_EAL_UEVENT_MSG_LEN );
Please don't initialize everything all the time; you are even initializing receive data.
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 380
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +4
-0+ ret =recv (fd, buf,RTE_EAL_UEVENT_MSG_LEN -1 ,MSG_DONTWAIT ); +if (ret >0 ) +return rte_eal_uev_parse (buf, uevent); +else if (ret <0 ) {
else is unnecessary after return.
Checkpatch would have told you that if you ran it.
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname)
Quoted 3 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+ RTE_LOG(ERR, EAL, + "Socket read error(%d): %s\n", + errno, strerror(er
Please indent arguements to match the first line:
RTE_LOG(ERR, EAL,
"Socket read error ...
Re: [PATCH v4 1/2] eal: add uevent monitor for hot plug
In reply to Jeff Guolib/librte_eal/linuxapp/eal/eal_interrupts.c eal_intr_thread_main(__rte_unused void *arg) · line 875
Quoted 12 lines · On Sun, 3 Sep 2017 23:49:44 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_interrupts.c +12
-0+/** +* add device uevent file descriptor +* into wait list for uevent monitoring. +*/ + ev.events =EPOLLIN |EPOLLPRI |EPOLLRDHUP |EPOLLHUP ; + ev.data.fd = src->intr_handle.uevent_fd; +if (epoll_ctl (pfd,EPOLL_CTL_ADD , + src->intr_handle.uevent_fd, &ev) <0 ){ +rte_panic ("Error adding uevent_fd %d epoll_ctl" +", %s\n" , + src->intr_handle.uevent_fd, +strerror (errno));
Panicing a user application under load is not going to make people happy
Re: [PATCH v4 1/2] eal: add uevent monitor for hot plug
In reply to Stephen HemmingerThanks Stephen for your review and suggestion, I will involve them in next version.
Best regards,
Jeff Guo
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, September 4, 2017 12:12 AM
To: Guo, Jia <[email protected]>
Cc: Richardson, Bruce <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Zhang, Helin <[email protected]>; Yigit, Ferruh <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; Wu, Jingjing <[email protected]>
Subject: Re: [PATCH v4 1/2] eal: add uevent monitor for hot plug
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 294
Quoted 8 lines · On Sun, 3 Sep 2017 23:49:44 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/common/eal_common_dev.c +8
-0+int +rte_eal_uev_enable (int netlink_fd) +{ +struct sockaddr_nl addr; +int ret; +int size =64 *1024 ; +int nonblock =1 ; +memset (&addr,0 ,sizeof (addr));
Blank line between declarations and code.
Also use C99 style intializations not memset.
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 297
Quoted 3 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+ addr.nl_family =AF_NETLINK ; + addr.nl_pid =0 ; + addr.nl_groups =0xffffffff ;
You don't need or want all events. specify which group you want.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + setsockopt(netlink_fd, SOL_SOCKET, SO_RCVBUFFORCE, &size, sizeof(size));
Don't user BUFFORCE, that is only available as root. Just doing SO_RCVBUF is enough.
v5 cover add uevent monitor for hot plug
In reply to Jeff GuoSo 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: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 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 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 (2):
eal: add uevent monitor for hot plug
app/testpmd: use uevent to monitor hot removal
app/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
Signature · 1 line
2.7.4
PATCH v5 1/2 eal: add uevent monitor for hot plug
This patch aim to add a general uevent mechanism in eal device layer, to enable all kernel object hot plug monitoring, so user could use these API to monitor and read out the device status info sent from the kernel side, then corresponding to handle it, such as detach or attach the device, and even benefit to use it for do smoothly fail safe work.
1) About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device, add device_state in struct of rte_device, to identify the device state machine.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below API in rte eal device common layer.
rte_eal_dev_monitor_enable
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_bind_driver
rte_dev_monitor_start
rte_dev_monitor_stop
2) About failure handler, use pci uio for example,
add pci_remap_device in bus layer and below function to process it:
rte_pci_remap_device
pci_uio_remap_resource
pci_map_private_resource
---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
--- 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 ++++++ 15 files changed, 1228 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
lib/librte_eal/bsdapp/eal/eal_dev.c new file +64 -0
@@ -0,0 +1,64 @@ +/*- +* Copyright(c) 2010-2017 Intel Corporation. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <sys/signalfd.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <sys/epoll.h> +#include <unistd.h> +#include <signal.h> +#include <stdbool.h> + +#include <rte_malloc.h> +#include <rte_bus.h> +#include <rte_dev.h> +#include <rte_devargs.h> +#include <rte_debug.h> +#include <rte_log.h> + +#include "eal_thread.h" + +int +rte_dev_monitor_start (void ) +{ +return -1 ; +} + +int +rte_dev_monitor_stop (void ) +{ +return -1 ; +}
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +105 -0
105 lines not on this page · raw message
lib/librte_eal/common/eal_common_bus.c +31 -0
@@ -50,8 +50,10 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->scan);RTE_VERIFY (bus->probe);RTE_VERIFY (bus->find_device); +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);
@@ -174,6 +176,15 @@ cmp_rte_device(const struct rte_device *dev1, const void *_dev2) }static int +cmp_rte_device_name (const char *dev_name1,const void *_dev_name2) +{ +const char *dev_name2 = _dev_name2; + +return strcmp (dev_name1, dev_name2); +} + + +static int bus_find_device (const struct rte_bus *bus,const void *_dev) {struct rte_device *dev;
@@ -182,6 +193,26 @@ bus_find_device(const struct rte_bus *bus, const void *_dev)return dev ==NULL ; } +static struct rte_device * +bus_find_device_by_name (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev = bus->find_device_by_name (NULL , cmp_rte_device_name, _dev_name); +return dev; +} + + +struct rte_device * + +rte_bus_find_device (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev =bus_find_device_by_name (bus, _dev_name); +return dev; +} +struct rte_bus *rte_bus_find_by_device (const struct rte_device *dev) {
lib/librte_eal/common/eal_common_dev.c +222 -1
247 lines not on this page · raw message
lib/librte_eal/common/eal_common_pci.c +66 -3
102 lines not on this page · raw message
lib/librte_eal/common/eal_common_pci_uio.c +30 -1
@@ -174,6 +174,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) {
@@ -222,7 +250,8 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)rte_free (uio_res);/* close fd if in primary process */ -close (dev->intr_handle.fd); +if (dev->device.state !=DEVICE_FAULT ) +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 ;
lib/librte_eal/common/eal_common_vdev.c +28 -1
@@ -303,7 +303,7 @@ vdev_probe(void)static struct rte_device *vdev_find_device (const struct rte_device *start,rte_dev_cmp_t cmp, -const void *data) +const void *data) {struct rte_vdev_device *dev;
@@ -318,6 +318,31 @@ 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, +const void *data) +{ +struct rte_vdev_device *dev; + + TAILQ_FOREACH(dev, &vdev_device_list, next) { +if (start && &dev->device == start) { + start =NULL ; +continue ; + } +if (cmp_name (dev->device.name, data) ==0 ) +return &dev->device; + } +return NULL ; +} + +static int +vdev_remap_device (struct rte_device *dev) +{ +RTE_SET_USED (dev); +return 0 ; +} +static int vdev_plug (struct rte_device *dev) {
@@ -334,9 +359,11 @@ static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, .find_device = vdev_find_device, + .find_device_by_name = vdev_find_device_by_name, .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_private.h +12 -1
@@ -222,6 +222,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.
@@ -354,5 +366,4 @@ bool rte_eal_using_phys_addrs(void);* NULL if no bus is able to parse this device. */ struct rte_bus *rte_bus_find_by_device_name (const char *str); -#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_bus.h +52 -0
79 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +101 -1
129 lines not on this page · raw message
lib/librte_eal/common/include/rte_pci.h +26 -0
@@ -393,6 +393,32 @@ 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); + +/** +* @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); + +/** * @internal * Map a particular resource from a file. *
lib/librte_eal/linuxapp/eal/Makefile +2 -1
@@ -73,6 +73,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
@@ -130,7 +131,7 @@ ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) CFLAGS_eal_thread.o += -Wno-return-type endif -INC := rte_interrupts.h rte_kni_common.h rte_dom0_common.h +INC := rte_interrupts.h rte_kni_common.h rte_dom0_common.h rte_dev.h SYMLINK-$(CONFIG_RTE_EXEC_ENV_LINUXAPP)-include/exec-env := \ $(addprefix include/exec-env/,$(INC))
lib/librte_eal/linuxapp/eal/eal_dev.c new file +351 -0
351 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci.c +33 -0
@@ -141,6 +141,39 @@ 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 ; + +/* try mapping the NIC resources using VFIO if it exists */ +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 ) {
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v5 2/2 app/testpmd: use uevent to monitor hot removal
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.
---v5->v4:
add new callback to process hot insertion
--- app/test-pmd/testpmd.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)
app/test-pmd/testpmd.c +90 -0
@@ -393,6 +393,9 @@ static void check_all_ports_link_status(uint32_t port_mask);static int eth_event_callback (uint8_t port_id,enum rte_eth_event_type type,void *param,void *ret_param); +static int eth_uevent_callback (enum rte_eal_dev_event_type type, +void *param,void *ret_param); +/* * Check if all the ports are started.
@@ -1413,6 +1416,7 @@ start_port(portid_t pid)struct rte_port *port;struct ether_addr mac_addr;enum rte_eth_event_type event_type; +enum rte_eal_dev_event_type dev_event_type;if (port_id_is_invalid (pid,ENABLED_WARN ))return 0 ;
@@ -1547,6 +1551,21 @@ start_port(portid_t pid)return -1 ; } } +rte_eal_dev_monitor_enable (); + +for (dev_event_type =RTE_EAL_DEV_EVENT_UNKNOWN ; + dev_event_type <RTE_EAL_DEV_EVENT_MAX ; + dev_event_type++) { + diag =rte_dev_callback_register (dev_event_type, + eth_uevent_callback, + &pi); +if (diag) { +printf ("Failed to setup uevent callback for" +" device event %d\n" , + dev_event_type); +return -1 ; + } + }/* start port */ if (rte_eth_dev_start (pi) <0 ) {
@@ -1883,6 +1902,35 @@ 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 = *(uint8_t *)arg; + +printf ("removing device port_id:%u\n" , 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; + +printf ("adding device %s\n" , dev_name); +attach_port (dev_name); +} +/* This function is used by the interrupt thread */ static int eth_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param,
@@ -1924,6 +1972,48 @@ eth_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param,return 0 ; } +/* This function is used by the interrupt thread */ +static int +eth_uevent_callback (enum rte_eal_dev_event_type type,void *arg, +void *ret_param) +{ +static const char *const event_desc[] = { + [RTE_EAL_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_EAL_DEV_EVENT_ADD ] ="add" , + [RTE_EAL_DEV_EVENT_REMOVE ] ="remove" , + }; + +RTE_SET_USED (ret_param); + +if (type >=RTE_EAL_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_EAL_DEV_EVENT_ADD : +if (rte_eal_alarm_set (2000000 , + add_uevent_callback, (void *)arg)) +fprintf (stderr,"Could not set up deferred " +"device removal\n" ); +break ; +case RTE_EAL_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_uevent_callback, (void *)arg)) +fprintf (stderr,"Could not set up deferred " +"device removal\n" ); +break ; +default : +break ; + } +return 0 ; +} +static int set_tx_queue_stats_mapping_registers (uint8_t port_id,struct rte_port *port) {
Signature · 1 line
2.7.4
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
v6 cover add uevent monitor for hot plug
In reply to Jeff GuoSo 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: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 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 when igb_uio 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 (2):
eal: add uevent monitor for hot plug
app/testpmd: use uevent to monitor hotplug
app/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
Signature · 1 line
2.7.4
PATCH v6 1/2 eal: add uevent monitor for hot plug
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object hot plug monitoring, so 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 detach or attach the device, and even benefit to use it to do smoothly fail safe work.
1) About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device, add device_state in struct of rte_device, to identify the device state machine.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below API in rte eal device common layer.
rte_eal_dev_monitor_enable
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_bind_driver
rte_dev_monitor_start
rte_dev_monitor_stop
2) About failure handler, use pci uio for example,
add pci_remap_device in bus layer and below function to process it:
rte_pci_remap_device
pci_uio_remap_resource
pci_map_private_resource
---v6->v5:
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.
modify to manage event callback in each device.
fix some system hung issue when igb_uio release.
modify the pci part to the bus-pci base on the bus rework.
--- 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 + 20 files changed, 1256 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
drivers/bus/pci/bsd/pci.c +23 -0
@@ -127,6 +127,29 @@ 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_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
@@ -145,6 +145,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 ) {
@@ -386,6 +418,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)rte_pci_add_device (dev); } + dev->device.state =DEVICE_PARSED ; +TAILQ_INIT (&(dev->device.uev_cbs));return 0 ; }
drivers/bus/pci/linux/pci_init.h +1 -0
@@ -58,6 +58,7 @@ int pci_uio_alloc_resource(struct rte_pci_device *dev, struct mapped_pci_resource **uio_res);void pci_uio_free_resource (struct rte_pci_device *dev,struct mapped_pci_resource *uio_res); +int pci_uio_remap_resource (struct rte_pci_device *dev);int pci_uio_map_resource_by_index (struct rte_pci_device *dev,int res_idx,struct mapped_pci_resource *uio_res,int map_idx);
drivers/bus/pci/pci_common.c +42 -0
70 lines not on this page · raw message
drivers/bus/pci/pci_common_uio.c +28 -0
@@ -176,6 +176,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 +9 -0
@@ -197,6 +197,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
lib/librte_eal/bsdapp/eal/eal_dev.c new file +64 -0
64 lines not on this page · raw message
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +105 -0
105 lines not on this page · raw message
lib/librte_eal/common/eal_common_bus.c +29 -0
@@ -51,8 +51,10 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->scan);RTE_VERIFY (bus->probe);RTE_VERIFY (bus->find_device); +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);
@@ -170,6 +172,14 @@ cmp_rte_device(const struct rte_device *dev1, const void *_dev2) }static int +cmp_rte_device_name (const char *dev_name1,const void *_dev_name2) +{ +const char *dev_name2 = _dev_name2; + +return strcmp (dev_name1, dev_name2); +} + +static int bus_find_device (const struct rte_bus *bus,const void *_dev) {struct rte_device *dev;
@@ -178,6 +188,25 @@ bus_find_device(const struct rte_bus *bus, const void *_dev)return dev ==NULL ; } +static struct rte_device * +bus_find_device_by_name (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev = bus->find_device_by_name (NULL , cmp_rte_device_name, _dev_name); +return dev; +} + +struct rte_device * + +rte_bus_find_device (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev =bus_find_device_by_name (bus, _dev_name); +return dev; +} +struct rte_bus *rte_bus_find_by_device (const struct rte_device *dev) {
lib/librte_eal/common/eal_common_dev.c +222 -0
240 lines not on this page · raw message
lib/librte_eal/common/eal_common_vdev.c +27 -0
@@ -318,6 +318,31 @@ 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, +const void *data) +{ +struct rte_vdev_device *dev; + + TAILQ_FOREACH(dev, &vdev_device_list, next) { +if (start && &dev->device == start) { + start =NULL ; +continue ; + } +if (cmp_name (dev->device.name, data) ==0 ) +return &dev->device; + } +return NULL ; +} + +static int +vdev_remap_device (struct rte_device *dev) +{ +RTE_SET_USED (dev); +return 0 ; +} +static int vdev_plug (struct rte_device *dev) {
@@ -334,9 +359,11 @@ static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, .find_device = vdev_find_device, + .find_device_by_name = vdev_find_device_by_name, .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/include/rte_bus.h +51 -0
78 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +106 -1
134 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +2 -1
@@ -67,6 +67,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
@@ -139,7 +140,7 @@ ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) CFLAGS_eal_thread.o += -Wno-return-type endif -INC := rte_kni_common.h +INC := rte_kni_common.h rte_dev.h SYMLINK-$(CONFIG_RTE_EXEC_ENV_LINUXAPP)-include/exec-env := \ $(addprefix include/exec-env/,$(INC))
lib/librte_eal/linuxapp/eal/eal_dev.c new file +353 -0
353 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +105 -0
105 lines not on this page · raw message
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
@@ -180,6 +180,26 @@ 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
@@ -243,6 +243,23 @@ int pci_addr_cmp(const struct rte_pci_addr *addr,int 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 v6 2/2 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.
---v6->v5:
add hot plug policy in app, show example to use hotplug list to manage to deside which device need to hot plug.
--- app/test-pmd/testpmd.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 9 +++ 2 files changed, 181 insertions(+)
app/test-pmd/testpmd.c +172 -0
@@ -402,6 +402,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);
@@ -409,6 +411,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_eal_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_eal_dev_event_type event);/* * Check if all the ports are started.
@@ -1758,6 +1767,31 @@ 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_eal_dev_event_type dev_event_type; + +/* register the uevent callback */ + dev = &rte_eth_devices[pid]; +for (dev_event_type =RTE_EAL_DEV_EVENT_ADD ; + dev_event_type <RTE_EAL_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) {
@@ -1774,6 +1808,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 )
@@ -1785,6 +1821,8 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +hotplug_list_add (identifier,RTE_EAL_DEV_EVENT_REMOVE ); +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }
@@ -1811,6 +1849,9 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_EAL_DEV_EVENT_ADD ); +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );
@@ -1834,6 +1875,9 @@ pmd_test_exit(void)close_port (pt_id); } } + +rte_dev_monitor_stop (); +printf ("\nBye...\n" ); }
@@ -1918,6 +1962,43 @@ 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_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_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; + +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,
@@ -1960,6 +2041,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_eal_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_eal_dev_event_type type,void *arg, +void *ret_param) +{ +static const char *const event_desc[] = { + [RTE_EAL_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_EAL_DEV_EVENT_ADD ] ="add" , + [RTE_EAL_DEV_EVENT_REMOVE ] ="remove" , + }; +static char *device_name; + +RTE_SET_USED (ret_param); + +if (type >=RTE_EAL_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_EAL_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_EAL_DEV_EVENT_ADD : + device_name =malloc (strlen ((const char *)arg) +1 ); +strcpy (device_name, arg); +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;
@@ -2439,6 +2602,15 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +/* enable hot plug monitoring */ +TAILQ_INIT (&hp_list); +rte_eal_dev_monitor_enable (); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_EAL_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
@@ -92,6 +92,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_eal_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
Re: [PATCH v6 1/2] eal: add uevent monitor for hot plug
In reply to Jeff Guodrivers/bus/pci/bsd/pci.c rte_pci_unmap_device(struct rte_pci_device *dev) · line 134
Quoted 6 lines · On Thu, 2 Nov 2017 04:16:44 +0800 Jeff Guo <[email protected]> wrote:
drivers/bus/pci/bsd/pci.c +5
-0+/* Map pci device */ +int +rte_pci_remap_device (struct rte_pci_device *dev) +{ +int ret =-1 ;
Please don't always initialize variables. It is unnecessary, and with modern compilers a bad habit since it defeats the uninitailized variable warning message which is useful to detect buggy code paths.
Quoted 17 lines
drivers/bus/pci/bsd/pci.c +17
-0+ +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; +}
Re: [PATCH v6 1/2] eal: add uevent monitor for hot plug
In reply to Jeff GuoQuoted 6 lines · On Thu, 2 Nov 2017 04:16:44 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c new file +6
-0+ +static int +dev_uev_parse (const char *buf,struct rte_eal_uevent *event) +{ +char action[RTE_EAL_UEVENT_MSG_LEN ]; +char subsystem[RTE_EAL_UEVENT_MSG_LEN ];
lib/librte_eal/linuxapp/eal/eal_dev.c line 128
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+char dev_path[RTE_EAL_UEVENT_MSG_LEN ]; +char pci_slot_name[RTE_EAL_UEVENT_MSG_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (subsystem,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (dev_path,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (pci_slot_name,0 ,RTE_EAL_UEVENT_MSG_LEN ); + +while (i <RTE_EAL_UEVENT_MSG_LEN ) {
Might be simpler, safer, clearer to use rte_strsplit here.
And then have a table of fields rather than open coding the parsing.
Quoted 33 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +33
-0+for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; + event->group =UEV_MONITOR_UDEV ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ; +snprintf (dev_path,sizeof (dev_path),"%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); + } +for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + }
lib/librte_eal/linuxapp/eal/eal_dev.c line 171
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+ +if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =UEV_SUBSYSTEM_PCI ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_EAL_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_EAL_DEV_EVENT_REMOVE ; + event->devname = pci_slot_name; + +return 0 ;
Function always returns 0, why is it not void?
Re: [PATCH v6 1/2] eal: add uevent monitor for hot plug
Thanks Stephen for your eye on review, would collect other comment and refine it better in next version.
Best regards,
Jeff Guo
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, November 2, 2017 5:42 AM
To: Guo, Jia <[email protected]>
Cc: Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; Wu, Jingjing <[email protected]>; [email protected]; Zhang, Helin <[email protected]>
Subject: Re: [PATCH v6 1/2] eal: add uevent monitor for hot plug
Quoted 5 lines · On Thu, 2 Nov 2017 04:16:44 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c new file +5
-0+ +static int +dev_uev_parse (const char *buf,struct rte_eal_uevent *event) { +char action[RTE_EAL_UEVENT_MSG_LEN ]; +char subsystem[RTE_EAL_UEVENT_MSG_LEN ];
lib/librte_eal/linuxapp/eal/eal_dev.c line 128
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+char dev_path[RTE_EAL_UEVENT_MSG_LEN ]; +char pci_slot_name[RTE_EAL_UEVENT_MSG_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (subsystem,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (dev_path,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (pci_slot_name,0 ,RTE_EAL_UEVENT_MSG_LEN ); + +while (i <RTE_EAL_UEVENT_MSG_LEN ) {
Might be simpler, safer, clearer to use rte_strsplit here.
And then have a table of fields rather than open coding the parsing.
Quoted 33 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +33
-0+for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; + event->group =UEV_MONITOR_UDEV ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ; +snprintf (dev_path,sizeof (dev_path),"%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); + } +for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + }
lib/librte_eal/linuxapp/eal/eal_dev.c line 171
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+ +if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =UEV_SUBSYSTEM_PCI ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_EAL_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_EAL_DEV_EVENT_REMOVE ; + event->devname = pci_slot_name; + +return 0 ;
Function always returns 0, why is it not void?
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 1/2] eal: add uevent monitor for hot plug
In reply to Stephen HemmingerQuoted 21 lines · Stephen Hemminger
Quoted 6 lines · On Thu, 2 Nov 2017 04:16:44 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c new file +6
-0+ +static int +dev_uev_parse (const char *buf,struct rte_eal_uevent *event) +{ +char action[RTE_EAL_UEVENT_MSG_LEN ]; +char subsystem[RTE_EAL_UEVENT_MSG_LEN ];lib/librte_eal/linuxapp/eal/eal_dev.c line 128
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+char dev_path[RTE_EAL_UEVENT_MSG_LEN ]; +char pci_slot_name[RTE_EAL_UEVENT_MSG_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (subsystem,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (dev_path,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (pci_slot_name,0 ,RTE_EAL_UEVENT_MSG_LEN ); + +while (i <RTE_EAL_UEVENT_MSG_LEN ) {Might be simpler, safer, clearer to use
rte_strsplithere.
Quoted 2 lines
And then have a table of fields rather than open coding the parsing.
i think your point must be make sense , but it hardly use rte_strsplit here , because the tokens which need to parse is splited by '\0', even more multi adjacent '\0' in the buf witch come from the uevent massage.
Quoted 44 lines
Quoted 33 lines
f+ for (; i <
RTE_EAL_UEVENT_MSG_LEN; i++) {lib/librte_eal/linuxapp/eal/eal_dev.c new file +32
-0+if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; + event->group =UEV_MONITOR_UDEV ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ; +snprintf (dev_path,sizeof (dev_path),"%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); + } +for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + }lib/librte_eal/linuxapp/eal/eal_dev.c line 171
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+ +if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =UEV_SUBSYSTEM_PCI ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_EAL_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_EAL_DEV_EVENT_REMOVE ; + event->devname = pci_slot_name; + +return 0 ;Function always returns 0, why is it not void?
Re: [PATCH v6 1/2] eal: add uevent monitor for hot plug
In reply to Jeff GuoReview
Quoted 2 lines · On Thu, 2 Nov 2017 04:16:44 +0800 Jeff Guo <[email protected]> wrote:
(quoted diff) +2
-0+int +rte_dev_bind_driver(const char *dev_name, const char *drv_type) {
Bracket left after declaration.
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 437
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+snprintf (drv_override_path,sizeof (drv_override_path), +"/sys/bus/pci/devices/%s/driver_override" , dev_name); + +/* specify the driver for a device by writing to driver_override */ + drv_override_fd =open (drv_override_path,O_WRONLY ); +if (drv_override_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + drv_override_path,strerror (errno)); + goto err; + }
You should not have dev functions that assume PCI. Please split into common and bus specific code.
Quoted 19 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +19
-0+static int +dev_uev_parse (const char *buf,struct rte_eal_uevent *event) +{ +char action[RTE_EAL_UEVENT_MSG_LEN ]; +char subsystem[RTE_EAL_UEVENT_MSG_LEN ]; +char dev_path[RTE_EAL_UEVENT_MSG_LEN ]; +char pci_slot_name[RTE_EAL_UEVENT_MSG_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (subsystem,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (dev_path,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (pci_slot_name,0 ,RTE_EAL_UEVENT_MSG_LEN ); + +while (i <RTE_EAL_UEVENT_MSG_LEN ) { +for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf) +break ; + buf++;
lib/librte_eal/linuxapp/eal/eal_dev.c line 142
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+ } +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; + event->group =UEV_MONITOR_UDEV ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf);
Why snprintf rather than strncpy?
Quoted 17 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +17
-0+ }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ; +snprintf (dev_path,sizeof (dev_path),"%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); + } +for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf =='\0' ) +break ; + buf++;
lib/librte_eal/linuxapp/eal/eal_dev.c line 169
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+ } + } + +if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =UEV_SUBSYSTEM_PCI ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_EAL_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_EAL_DEV_EVENT_REMOVE ; + event->devname = pci_slot_name;
Why do you need to first capture the strings, then set state variables? Instead why not update event->xxx directly?
Re: [PATCH v6 1/2] eal: add uevent monitor for hot plug
Quoted 6 lines · Stephen Hemminger
Review
Quoted 2 lines · On Thu, 2 Nov 2017 04:16:44 +0800 Jeff Guo <[email protected]> wrote:
(quoted diff) +2
-0+int +rte_dev_bind_driver(const char *dev_name, const char *drv_type) {Bracket left after declaration.
thanks.
Quoted 17 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 437
Quoted 12 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+snprintf (drv_override_path,sizeof (drv_override_path), +"/sys/bus/pci/devices/%s/driver_override" , dev_name); + +/* specify the driver for a device by writing to driver_override */ + drv_override_fd =open (drv_override_path,O_WRONLY ); +if (drv_override_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + drv_override_path,strerror (errno)); + goto err; + }You should not have dev functions that assume PCI. Please split into common and bus specific code.
make sense, will modify it into bus specific code.
Quoted 22 lines
Quoted 22 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +22
-0+static int +dev_uev_parse (const char *buf,struct rte_eal_uevent *event) +{ +char action[RTE_EAL_UEVENT_MSG_LEN ]; +char subsystem[RTE_EAL_UEVENT_MSG_LEN ]; +char dev_path[RTE_EAL_UEVENT_MSG_LEN ]; +char pci_slot_name[RTE_EAL_UEVENT_MSG_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (subsystem,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (dev_path,0 ,RTE_EAL_UEVENT_MSG_LEN ); +memset (pci_slot_name,0 ,RTE_EAL_UEVENT_MSG_LEN ); + +while (i <RTE_EAL_UEVENT_MSG_LEN ) { +for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ;
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 142
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +7
-0+ i +=7 ; + event->group =UEV_MONITOR_UDEV ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf);Why snprintf rather than strncpy?
snprintf would no need manual write '\0' and the src length is not explicit, and if concern about the efficiency of the snprintf scan, i will constrain the value of dest buf length.
Quoted 21 lines
Quoted 21 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +21
-0+ }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ; +snprintf (dev_path,sizeof (dev_path),"%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); + } +for (; i <RTE_EAL_UEVENT_MSG_LEN ; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +if (!strncmp (subsystem,"pci" ,3 ))
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 169
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +6
-0+ event->subsystem =UEV_SUBSYSTEM_PCI ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_EAL_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_EAL_DEV_EVENT_REMOVE ; + event->devname = pci_slot_name;Why do you need to first capture the strings, then set state variables? Instead why not update
event->xxxdirectly?
i think that would be more benefit to read and manage out of the loop.
v7 cover add uevent monitor for hot plug
In reply to Jeff GuoSo 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: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 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: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_uio 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 (2):
eal: add uevent monitor for hot plug
app/testpmd: use uevent to monitor hotplug
app/test-pmd/testpmd.c | 178 +++++++++++ app/test-pmd/testpmd.h | 9 + drivers/bus/pci/bsd/pci.c | 30 ++ drivers/bus/pci/linux/pci.c | 87 +++++ drivers/bus/pci/linux/pci_init.h | 1 + drivers/bus/pci/pci_common.c | 43 +++ drivers/bus/pci/pci_common_uio.c | 28 ++ drivers/bus/pci/private.h | 12 + drivers/bus/pci/rte_bus_pci.h | 25 ++ drivers/bus/vdev/vdev.c | 36 +++ lib/librte_eal/bsdapp/eal/eal_dev.c | 64 ++++ .../bsdapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/common/eal_common_bus.c | 30 ++ lib/librte_eal/common/eal_common_dev.c | 169 ++++++++++ lib/librte_eal/common/include/rte_bus.h | 69 ++++ lib/librte_eal/common/include/rte_dev.h | 89 ++++++ lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_alarm.c | 5 + lib/librte_eal/linuxapp/eal/eal_dev.c | 356 +++++++++++++++++++++ .../linuxapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 6 + lib/librte_pci/rte_pci.c | 20 ++ lib/librte_pci/rte_pci.h | 17 + 23 files changed, 1488 insertions(+), 1 deletion(-) 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
Signature · 1 line
2.7.4
PATCH v7 1/2 eal: add uevent monitor for hot plug
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object hot plug monitoring, so 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 detach or attach the device, and even benefit to use it to do smoothly fail safe work.
1) About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device, add device_state in struct of rte_device, to identify the device state machine.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below API in rte eal device common layer.
rte_eal_dev_monitor_enable
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_monitor_start
rte_dev_monitor_stop
2) About failure handler, use pci uio for example,
add pci_remap_device in bus layer and below function to process it:
rte_pci_remap_device
pci_uio_remap_resource
pci_map_private_resource
add rte_pci_dev_bind_driver to bind pci device with explicit driver.
---v7->v6:
a.modify vdev part according to the vdev rework b.re-define and split the func into common and bus specific code c.fix some incorrect issue.
b.fix the system hung after send packcet issue.
--- drivers/bus/pci/bsd/pci.c | 30 ++ drivers/bus/pci/linux/pci.c | 87 +++++ drivers/bus/pci/linux/pci_init.h | 1 + drivers/bus/pci/pci_common.c | 43 +++ drivers/bus/pci/pci_common_uio.c | 28 ++ drivers/bus/pci/private.h | 12 + drivers/bus/pci/rte_bus_pci.h | 25 ++ drivers/bus/vdev/vdev.c | 36 +++ lib/librte_eal/bsdapp/eal/eal_dev.c | 64 ++++ .../bsdapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/common/eal_common_bus.c | 30 ++ lib/librte_eal/common/eal_common_dev.c | 169 ++++++++++ lib/librte_eal/common/include/rte_bus.h | 69 ++++ lib/librte_eal/common/include/rte_dev.h | 89 ++++++ lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_alarm.c | 5 + lib/librte_eal/linuxapp/eal/eal_dev.c | 356 +++++++++++++++++++++ .../linuxapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 6 + lib/librte_pci/rte_pci.c | 20 ++ lib/librte_pci/rte_pci.h | 17 + 21 files changed, 1301 insertions(+), 1 deletion(-) 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
drivers/bus/pci/bsd/pci.c +30 -0
@@ -126,6 +126,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)
@@ -678,3 +701,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 +87 -0
102 lines not on this page · raw message
drivers/bus/pci/linux/pci_init.h +1 -0
@@ -58,6 +58,7 @@ int pci_uio_alloc_resource(struct rte_pci_device *dev, struct mapped_pci_resource **uio_res);void pci_uio_free_resource (struct rte_pci_device *dev,struct mapped_pci_resource *uio_res); +int pci_uio_remap_resource (struct rte_pci_device *dev);int pci_uio_map_resource_by_index (struct rte_pci_device *dev,int res_idx,struct mapped_pci_resource *uio_res,int map_idx);
drivers/bus/pci/pci_common.c +43 -0
71 lines not on this page · raw message
drivers/bus/pci/pci_common_uio.c +28 -0
@@ -176,6 +176,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 +25 -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
@@ -333,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 +36 -0
@@ -323,6 +323,39 @@ 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, +const void *data) +{ +struct rte_vdev_device *dev; + + TAILQ_FOREACH(dev, &vdev_device_list, next) { +if (start && &dev->device == start) { + start =NULL ; +continue ; + } +if (cmp_name (dev->device.name, data) ==0 ) +return &dev->device; + } +return NULL ; +} + +static int +vdev_remap_device (struct rte_device *dev) +{ +RTE_SET_USED (dev); +return 0 ; +} + +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) {
@@ -339,9 +372,12 @@ static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, .find_device = vdev_find_device, + .find_device_by_name = vdev_find_device_by_name, .plug = vdev_plug, .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/bsdapp/eal/eal_dev.c new file +64 -0
64 lines not on this page · raw message
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +106 -0
106 lines not on this page · raw message
lib/librte_eal/common/eal_common_bus.c +30 -0
@@ -51,8 +51,11 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->scan);RTE_VERIFY (bus->probe);RTE_VERIFY (bus->find_device); +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); +RTE_VERIFY (bus->bind_driver);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);
@@ -170,6 +173,14 @@ cmp_rte_device(const struct rte_device *dev1, const void *_dev2) }static int +cmp_rte_device_name (const char *dev_name1,const void *_dev_name2) +{ +const char *dev_name2 = _dev_name2; + +return strcmp (dev_name1, dev_name2); +} + +static int bus_find_device (const struct rte_bus *bus,const void *_dev) {struct rte_device *dev;
@@ -178,6 +189,25 @@ bus_find_device(const struct rte_bus *bus, const void *_dev)return dev ==NULL ; } +static struct rte_device * +bus_find_device_by_name (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev = bus->find_device_by_name (NULL , cmp_rte_device_name, _dev_name); +return dev; +} + +struct rte_device * + +rte_bus_find_device (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev =bus_find_device_by_name (bus, _dev_name); +return dev; +} +struct rte_bus *rte_bus_find_by_device (const struct rte_device *dev) {
lib/librte_eal/common/eal_common_dev.c +169 -0
181 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +69 -0
96 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +89 -0
117 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +2 -1
@@ -67,6 +67,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
@@ -120,7 +121,7 @@ ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) CFLAGS_eal_thread.o += -Wno-return-type endif -INC := rte_kni_common.h +INC := rte_kni_common.h rte_dev.h SYMLINK-$(CONFIG_RTE_EXEC_ENV_LINUXAPP)-include/exec-env := \ $(addprefix include/exec-env/,$(INC))
lib/librte_eal/linuxapp/eal/eal_alarm.c +5 -0
@@ -209,6 +209,7 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)int count =0 ;int err =0 ;int executing; +int ret;if (!cb_fn) { rte_errno =EINVAL ;
@@ -259,6 +260,10 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) } ap_prev = ap; } + + ret |=rte_intr_callback_unregister (&intr_handle, + eal_alarm_callback,NULL ); +rte_spinlock_unlock (&alarm_list_lk); }while (executing !=0 );
lib/librte_eal/linuxapp/eal/eal_dev.c new file +356 -0
356 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +106 -0
106 lines not on this page · raw message
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 v7 2/2 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.
---v7->v6:
fix the system hung after send packcet issue.
--- app/test-pmd/testpmd.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 9 +++ 2 files changed, 187 insertions(+)
app/test-pmd/testpmd.c +178 -0
@@ -401,6 +401,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);
@@ -408,6 +410,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_eal_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_eal_dev_event_type event);/* * Check if all the ports are started.
@@ -1757,6 +1766,31 @@ 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_eal_dev_event_type dev_event_type; + +/* register the uevent callback */ + dev = &rte_eth_devices[pid]; +for (dev_event_type =RTE_EAL_DEV_EVENT_ADD ; + dev_event_type <RTE_EAL_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) {
@@ -1773,6 +1807,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 )
@@ -1784,6 +1820,8 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +hotplug_list_add (identifier,RTE_EAL_DEV_EVENT_REMOVE ); +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }
@@ -1810,6 +1848,9 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_EAL_DEV_EVENT_ADD ); +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );
@@ -1833,6 +1874,9 @@ pmd_test_exit(void)close_port (pt_id); } } + +rte_dev_monitor_stop (); +printf ("\nBye...\n" ); }
@@ -1917,6 +1961,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,
@@ -1959,6 +2046,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_eal_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_eal_dev_event_type type,void *arg, +void *ret_param) +{ +static const char *const event_desc[] = { + [RTE_EAL_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_EAL_DEV_EVENT_ADD ] ="add" , + [RTE_EAL_DEV_EVENT_REMOVE ] ="remove" , + }; +static char *device_name; + +RTE_SET_USED (ret_param); + +if (type >=RTE_EAL_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_EAL_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_EAL_DEV_EVENT_ADD : + device_name =malloc (strlen ((const char *)arg) +1 ); +strcpy (device_name, arg); +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;
@@ -2438,6 +2607,15 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +/* enable hot plug monitoring */ +TAILQ_INIT (&hp_list); +rte_eal_dev_monitor_enable (); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_EAL_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
@@ -92,6 +92,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_eal_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
Re: [PATCH v6 0/2] add uevent monitor for hot plug
In reply to Mordechay Haimovskyhi,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 v7 1/2] eal: add uevent monitor for hot plug
In reply to Jeff GuoHi Jeff
Maybe I'm touching in previous discussions but please see some comments\questions.
From: Jeff Guo:
Quoted 812 lines
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object hot plug monitoring, so 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 detach or attach the device, and even benefit to use it to do smoothly fail safe work.
1) About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device, adddevice_statein struct ofrte_device, to identify the device state machine.
b: add enum ofrte_eal_dev_event_typeand struct ofrte_eal_uevent.
c: add below API in rte eal device common layer.
rte_eal_dev_monitor_enable
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_monitor_start
rte_dev_monitor_stop2) About failure handler, use pci uio for example,
addpci_remap_devicein bus layer and below function to process it:
rte_pci_remap_device
pci_uio_remap_resource
pci_map_private_resource
addrte_pci_dev_bind_driverto bind pci device with explicit driver.Signed-off-by Jeff Guo <[email protected]>---
v7->v6:
a.modify vdev part according to the vdev rework b.re-define and split the func into common and bus specific code c.fix some incorrect issue.
b.fix the system hung after send packcet issue.--- drivers/bus/pci/bsd/pci.c | 30 ++ drivers/bus/pci/linux/pci.c | 87 +++++ drivers/bus/pci/linux/pci_init.h | 1 + drivers/bus/pci/pci_common.c | 43 +++ drivers/bus/pci/pci_common_uio.c | 28 ++ drivers/bus/pci/private.h | 12 + drivers/bus/pci/rte_bus_pci.h | 25 ++ drivers/bus/vdev/vdev.c | 36 +++ lib/librte_eal/bsdapp/eal/eal_dev.c | 64 ++++ .../bsdapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/common/eal_common_bus.c | 30 ++ lib/librte_eal/common/eal_common_dev.c | 169 ++++++++++ lib/librte_eal/common/include/rte_bus.h | 69 ++++ lib/librte_eal/common/include/rte_dev.h | 89 ++++++ lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_alarm.c | 5 + lib/librte_eal/linuxapp/eal/eal_dev.c | 356 +++++++++++++++++++++ .../linuxapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 6 + lib/librte_pci/rte_pci.c | 20 ++ lib/librte_pci/rte_pci.h | 17 + 21 files changed, 1301 insertions(+), 1 deletion(-) 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.hdrivers/bus/pci/bsd/pci.c +23
-0@@ -126,6 +126,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,drivers/bus/pci/bsd/pci.c +7
-0struct mapped_pci_resource *uio_res)@@ -678,3 +701,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 +32
-0@@ -145,6 +145,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 ){
drivers/bus/pci/linux/pci.c +55
-0@@ -386,6 +418,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)rte_pci_add_device (dev ); } + dev->device.state =DEVICE_PARSED ; +TAILQ_INIT (&(dev->device.uev_cbs));return 0 ; }@@ -854,3 +888,56 @@ 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) +{ +char drv_bind_path[1024 ]; +char drv_override_path[1024 ];/* contains the /dev/uioX */ +int drv_override_fd; +int drv_bind_fd; + +RTE_SET_USED (drv_type); + +snprintf (drv_override_path,sizeof (drv_override_path), +"/sys/bus/pci/devices/%s/driver_override" , dev_name); + +/* specify the driver for a device by writing to driver_override */ + drv_override_fd =open (drv_override_path,O_WRONLY ); +if (drv_override_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + drv_override_path,strerror (errno)); + goto err; + } + +if (write (drv_override_fd, drv_type,sizeof (drv_type)) <0 ) { +RTE_LOG (ERR ,EAL , +"Error: bind failed - Cannot write " +"driver %s to device %s\n" , drv_type, dev_name); + goto err; + } + +close (drv_override_fd); + +snprintf (drv_bind_path,sizeof (drv_bind_path), +"/sys/bus/pci/drivers/%s/bind" , drv_type); + +/* do the bind by writing device to the specific driver */ + drv_bind_fd =open (drv_bind_path,O_WRONLY |O_APPEND ); +if (drv_bind_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + drv_bind_path,strerror (errno)); + goto err; + } + +if (write (drv_bind_fd, dev_name,sizeof (dev_name)) <0 ) + goto err; + +close (drv_bind_fd); +return 0 ; +err: +close (drv_override_fd); +close (drv_bind_fd); +return -1 ; +} +drivers/bus/pci/linux/pci_init.h +1
-0@@ -58,6 +58,7 @@ int pci_uio_alloc_resource(struct rte_pci_device *dev, struct mapped_pci_resource **uio_res);void pci_uio_free_resource (struct rte_pci_device *dev,struct mapped_pci_resource *uio_res); +int pci_uio_remap_resource (struct rte_pci_device *dev);int pci_uio_map_resource_by_index (struct rte_pci_device *dev,int res_idx,struct mapped_pci_resource *uio_res,int map_idx);drivers/bus/pci/pci_common.c +40
-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 =DEVICE_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); }@@ -502,6 +504,44 @@ pci_find_device(const struct rte_device *start,rte_dev_cmp_t cmp, return NULL; } +static struct rte_device * +pci_find_device_by_name (const struct rte_device *start, +rte_dev_cmp_name_t cmp_name, +const void *data) +{ +struct rte_pci_device *dev; + +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (start && &dev->device == start) { + start =NULL ;/* starting point found */ +continue ; + } +if (cmp_name (dev->device.name, data) ==0 ) +return &dev->device; + } + +return NULL ; +} + +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){
drivers/bus/pci/pci_common.c +3
-0@@ -528,10 +568,13 @@ struct rte_pci_bus rte_pci_bus = { .scan = rte_pci_scan, .probe = rte_pci_probe, .find_device = pci_find_device, + .find_device_by_name = pci_find_device_by_name, .plug = pci_plug, .unplug = pci_unplug, .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/pci_common_uio.c +28
-0@@ -176,6 +176,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 +25
-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 @@ -333,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 +33
-0@@ -323,6 +323,39 @@ 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, +const void *data) +{ +struct rte_vdev_device *dev; + + TAILQ_FOREACH(dev, &vdev_device_list, next) { +if (start && &dev->device == start) { + start =NULL ; +continue ; + } +if (cmp_name (dev->device.name, data) ==0 ) +return &dev->device; + } +return NULL ; +} + +static int +vdev_remap_device (struct rte_device *dev) +{ +RTE_SET_USED (dev); +return 0 ; +} + +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){
drivers/bus/vdev/vdev.c +3
-0@@ -339,9 +372,12 @@ static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, .find_device = vdev_find_device, + .find_device_by_name = vdev_find_device_by_name, .plug = vdev_plug, .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/bsdapp/eal/eal_dev.c new file +19
-0@@ -0,0 +1,64 @@ +/*- +* Copyright(c) 2010-2017 Intel Corporation. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/bsdapp/eal/eal_dev.c new file +34
-0+ +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <sys/signalfd.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <sys/epoll.h> +#include <unistd.h> +#include <signal.h> +#include <stdbool.h> + +#include <rte_malloc.h> +#include <rte_bus.h> +#include <rte_dev.h> +#include <rte_devargs.h> +#include <rte_debug.h> +#include <rte_log.h> + +#include "eal_thread.h" + +int +rte_dev_monitor_start (void ) +{ +return -1 ; +} + +int +rte_dev_monitor_stop (void ) +{ +return -1 ; +}lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +21
-0@@ -0,0 +1,106 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +38
-0+ +#ifndef _RTE_DEV_H_ +#error "don't include this file directly, please include generic <rte_dev.h>" +#endif + +#ifndef _RTE_LINUXAPP_DEV_H_ +#define _RTE_LINUXAPP_DEV_H_ + +#include <stdio.h> + +#include <rte_dev.h> + +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum uev_subsystem { +UEV_SUBSYSTEM_UIO , +UEV_SUBSYSTEM_VFIO , +UEV_SUBSYSTEM_PCI , +UEV_SUBSYSTEM_MAX +}; + +enum uev_monitor_netlink_group { +UEV_MONITOR_KERNEL , +UEV_MONITOR_UDEV , +}; + +/** +* The device event type. +*/ +enum rte_eal_dev_event_type { +RTE_EAL_DEV_EVENT_UNKNOWN ,/**< unknown event type */ +RTE_EAL_DEV_EVENT_ADD ,/**< device adding event */ +RTE_EAL_DEV_EVENT_REMOVE , +/**< device removing event */ +RTE_EAL_DEV_EVENT_CHANGE , +/**< device status change event */ +RTE_EAL_DEV_EVENT_MOVE ,/**< device sys path move event */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +3
-0+RTE_EAL_DEV_EVENT_ONLINE ,/**< device online event */ +RTE_EAL_DEV_EVENT_OFFLINE ,/**< device offline event */ +RTE_EAL_DEV_EVENT_MAX /**< max value of this enum */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +7
-0+}; + +struct rte_eal_uevent { +enum rte_eal_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +enum uev_monitor_netlink_group group;/**< device netlink group */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +26
-0+}; + +/** +* Start the device uevent monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_dev_monitor_start (void ); + +/** +* Stop the device uevent monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ + +int +rte_dev_monitor_stop (void ); + +#endif /* _RTE_LINUXAPP_DEV_H_ */ lib/librte_eal/common/eal_common_bus.c +11
-0@@ -51,8 +51,11 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->scan);RTE_VERIFY (bus->probe);RTE_VERIFY (bus->find_device); +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); +RTE_VERIFY (bus->bind_driver);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);@@ -170,6 +173,14 @@ cmp_rte_device(const struct rte_device *dev1, const void *_dev2) }static int +cmp_rte_device_name (const char *dev_name1,const void *_dev_name2) +{ +const char *dev_name2 = _dev_name2; + +return strcmp (dev_name1, dev_name2); +} + +static int bus_find_device (const struct rte_bus *bus,const void *_dev) {lib/librte_eal/common/eal_common_bus.c +19
-0struct rte_device *dev;@@ -178,6 +189,25 @@ bus_find_device(const struct rte_bus *bus, const void *_dev)return dev ==NULL ; } +static struct rte_device * +bus_find_device_by_name (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev = bus->find_device_by_name (NULL , cmp_rte_device_name, _dev_name); +return dev; +} + +struct rte_device * + +rte_bus_find_device (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev =bus_find_device_by_name (bus, _dev_name); +return dev; +} +struct
rte_bus*rte_bus_find_by_device(const struct rte_device *dev){lib/librte_eal/common/eal_common_dev.c +34
-0@@ -42,9 +42,31 @@#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 */ +static rte_spinlock_t rte_dev_cb_lock =RTE_SPINLOCK_INITIALIZER ; + +/** +* The user application callback description. +* +* It contains callback address to be registered by user application, +* the pointer to the parameters for callback, and the event type. +*/ +struct rte_eal_dev_callback { +TAILQ_ENTRY (rte_eal_dev_callback) next;/**< Callbacks list */ +rte_eal_dev_cb_fn cb_fn;/**< Callback address */ +void *cb_arg;/**< Parameter for callback */ +void *ret_param;/**< Return parameter */ +enum rte_eal_dev_event_type event;/**< device event type */ +uint32_t active;/**< Callback is executing */ +}; + +static struct rte_eal_dev_callback *dev_add_cb; +static int cmp_detached_dev_name (const struct rte_device *dev,const void *_name) {@@ -234,3 +256,150 @@ int rte_eal_hotplug_remove(const char *busname, const char *devname)rte_eal_devargs_remove (busname ,devname );return ret; } + +int +rte_eal_dev_monitor_enable (void ) +{ +int ret; + + ret =rte_dev_monitor_start (); +if (ret) +RTE_LOG (ERR ,EAL ,"Can not init device monitor\n" ); +return ret; +} +
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, · line 280
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+int +rte_dev_callback_register (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg) +{ +struct rte_eal_dev_callback *user_cb; + +if (!cb_fn) +return -EINVAL ; +
What's about checking the device pointer is not NULL ?
Quoted 14 lines
lib/librte_eal/common/eal_common_dev.c +14
-0+rte_spinlock_lock (&rte_dev_cb_lock); + +if (TAILQ_EMPTY (&(device->uev_cbs))) +TAILQ_INIT (&(device->uev_cbs)); + +if (event ==RTE_EAL_DEV_EVENT_ADD ) { + user_cb =NULL ; + }else { + TAILQ_FOREACH(user_cb, &(device->uev_cbs), next) { +if (user_cb->cb_fn == cb_fn && + user_cb->cb_arg == cb_arg && + user_cb->event == event) { +break ; + }
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 304
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+ } + } + +/* create a new callback. */ +if (user_cb ==NULL ) { +/* allocate a new interrupt callback entity */ + user_cb =rte_zmalloc ("eal device event" , +sizeof (*user_cb),0 ); +if (user_cb ==NULL ) { +RTE_LOG (ERR ,EAL ,"Can not allocate memory\n" );
Missing rte_spinlock_unlock.
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 311
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+return -ENOMEM ; + } + user_cb->cb_fn = cb_fn; + user_cb->cb_arg = cb_arg; + user_cb->event = event; +if (event ==RTE_EAL_DEV_EVENT_ADD ) + dev_add_cb = user_cb;
Only one dpdk entity can register to ADD callback?
I suggest to add option to register all devices maybe by using dummy device which will include all the "ALL_DEVICES" callbacks per event. All means past, present and future devices, by this way 1 callback can be called for all the devices and more than one dpdk entity could register to an ADD\NEW event. What's about NEW instead of ADD?
I also suggest to add the device pointer as a parameter to the callback(which will be managed by EAL).
Quoted 17 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+else + TAILQ_INSERT_TAIL(&(device->uev_cbs), user_cb,next);
lib/librte_eal/common/eal_common_dev.c +14
-0+ } + +rte_spinlock_unlock (&rte_dev_cb_lock); +return 0 ; +} + +int +rte_dev_callback_unregister (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg) +{ +int ret; +struct rte_eal_dev_callback *cb, *next; +
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 337
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&rte_dev_cb_lock); + + ret =0 ; +if (event ==RTE_EAL_DEV_EVENT_ADD ) { +rte_free (dev_add_cb); + dev_add_cb =NULL ; + }else {
Device NULL checking?
Quoted 35 lines
lib/librte_eal/common/eal_common_dev.c +16
-0+for (cb =TAILQ_FIRST (&(device->uev_cbs)); cb !=NULL ; + cb = next) { + + next =TAILQ_NEXT (cb, next); + +if (cb->cb_fn != cb_fn || cb->event != event || + (cb->cb_arg != (void *)-1 && + cb->cb_arg != cb_arg)) +continue ; + +/* +* if this callback is not executing right now, +* then remove it. +*/ +if (cb->active ==0 ) { + TAILQ_REMOVE(&(device->uev_cbs), cb,next);
lib/librte_eal/common/eal_common_dev.c +18
-0+rte_free (cb); + }else { + ret = -EAGAIN ; + } + } + } +rte_spinlock_unlock (&rte_dev_cb_lock); +return ret; +} + +int +_rte_dev_callback_process (struct rte_device *device, +enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param) +{ +struct rte_eal_dev_callback dev_cb; +struct rte_eal_dev_callback *cb_lst; +int rc =0 ;
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 381
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+ +rte_spinlock_lock (&rte_dev_cb_lock); +if (event ==RTE_EAL_DEV_EVENT_ADD ) { +if (cb_arg !=NULL ) + dev_add_cb->cb_arg = cb_arg; + +if (ret_param !=NULL ) + dev_add_cb->ret_param = ret_param; + +rte_spinlock_unlock (&rte_dev_cb_lock);
Can't someone free it when it running?
I suggest to keep the lock locked.
Callbacks are not allowed to use this mechanism to prevent deadlock.
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+ rc = dev_add_cb->cb_fn(dev_add_cb->event, + dev_add_cb->cb_arg, dev_add_cb-Quoted 1 line
ret_param);lib/librte_eal/common/eal_common_dev.c +3
-0+rte_spinlock_lock (&rte_dev_cb_lock); + }else { + TAILQ_FOREACH(cb_lst, &(device->uev_cbs), next) {
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 396
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (cb_lst->cb_fn ==NULL || cb_lst->event != event) +continue ; + dev_cb = *cb_lst; + cb_lst->active =1 ; +if (cb_arg !=NULL ) + dev_cb.cb_arg = cb_arg; +if (ret_param !=NULL ) + dev_cb.ret_param = ret_param; + +rte_spinlock_unlock (&rte_dev_cb_lock);
The current active flag doesn't do it thread safe here, I suggest to keep the lock locked. Scenario:
1. Thread A see active = 0 in unregister function.
2. Context switch.
3. Thread B start the callback.
4. Context switch.
5. Thread A free it.
6. Context switch.
7. Seg fault in Thread B.
Quoted 554 lines
lib/librte_eal/common/eal_common_dev.c +9
-0+ rc = dev_cb.cb_fn (dev_cb.event, + dev_cb.cb_arg, dev_cb.ret_param); +rte_spinlock_lock (&rte_dev_cb_lock); + cb_lst->active =0 ; + } + } +rte_spinlock_unlock (&rte_dev_cb_lock); +return rc; +}lib/librte_eal/common/include/rte_bus.h +7
-0@@ -122,6 +122,34 @@ typedef struct rte_device * const void *data);/** +* Device iterator to find a device on a bus. +* +* This function returns an rte_device if one of those held by the bus +* matches the data passed as parameter. +* +* If the comparison function returns zero this function should stop iterating +* over any more devices. To continue a search the device of a previous search
+ * can be passed via the start parameter.
+ *
+ * @param cmp
+ * the device name comparison function.
+ *
+ * @param data
+ * Data to compare each device against.
+ *
+ * @param start
+ * starting point for the iteration
+ *
+ * @return
+ * The first device matching the data, NULL if none exists.
+ */lib/librte_eal/common/include/rte_bus.h +8
-0+typedef struct rte_device * +(*rte_bus_find_device_by_name_t )(const struct rte_device *start, +rte_dev_cmp_name_t cmp, +const void *data); + + +/** * Implementation specific probe function which is responsible for linking * devices on that bus with applicable drivers. * @@ -168,6 +196,37 @@ 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.
+ *
+ * @param dev
+ * Device pointer that was returned by a previous call tofind_device.
+ *
+ * @return
+ * 0 on success.
+ * !0 on error.
+ */lib/librte_eal/common/include/rte_bus.h +24
-0+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 {@@ -206,9 +265,13 @@ struct rte_bus {rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ rte_bus_find_device_t find_device;/**< Find a device on the bus */ +rte_bus_find_device_by_name_t find_device_by_name; +/**< Find a device on the 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 */ +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_tget_iommu_class; /**< Get iommu
class */
};lib/librte_eal/common/include/rte_bus.h +6
-0@@ -306,6 +369,12 @@ struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);/** +* Find the registered bus for a particular device. +*/ +struct rte_device *rte_bus_find_device (const struct rte_bus *bus, +const void *dev_name); + +/** * Find the registered bus for a given name. */ struct
rte_bus*rte_bus_find_by_name(const char *busname);lib/librte_eal/common/include/rte_dev.h +21
-0@@ -51,6 +51,15 @@ extern "C" {#include <rte_log.h> +#include <exec-env/rte_dev.h> + +typedef int (*rte_eal_dev_cb_fn )(enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param); + +struct rte_eal_dev_callback ; +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (rte_eal_dev_cb_list, rte_eal_dev_callback); + __attribute__((format (printf,2 ,0 )))static inline void rte_pmd_debug_trace (const char *func_name,const char *fmt, ...)@@ -157,6 +166,13 @@ struct rte_driver {*/ #define RTE_DEV_NAME_MAX_LEN 64 +enum device_state { +DEVICE_UNDEFINED , +DEVICE_FAULT , +DEVICE_PARSED , +DEVICE_PROBED , +}; +/** * A structure describing a generic device. */ @@ -166,6 +182,9 @@ struct rte_device {const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */ +enum device_state state;/**< Device state */ +/** User application callbacks for device event */ +struct rte_eal_dev_cb_list uev_cbs; };/** @@ -248,6 +267,8 @@ int rte_eal_hotplug_remove(const char *busname,const char *devname); */ typedef int (*rte_dev_cmp_t )(const struct rte_device *dev,const void *data); +typedef int (*rte_dev_cmp_name_t )(const char *dev_name,const void *data); +#define
RTE_PMD_EXPORT_NAME_ARRAY(n, idx)n##idx[]#define
RTE_PMD_EXPORT_NAME(name, idx)\lib/librte_eal/common/include/rte_dev.h +68
-0@@ -293,4 +314,72 @@ __attribute__((used)) = str }#endif +/** +* It enable the device event monitoring for a specific event. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_eal_dev_monitor_enable (void ); +/** +* 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 (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_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. +* +* @return +* - On success, return the number of callback entities removed. +* - On failure, a negative value. +*/ +int rte_dev_callback_unregister (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg); + +/** +* @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 event +* The device event type. +* @param cb_arg +* callback parameter. +* @param ret_param +* To pass data back to user application. +* This allows the user application to decide if a particular function +* is permitted or not. +* +* @return +* - On success, return zero. +* - On failure, a negative value. +*/ +int +_rte_dev_callback_process (struct rte_device *device, +enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param);#endif /* _RTE_DEV_H_ */ lib/librte_eal/linuxapp/eal/Makefile +0
-0@@ -67,6 +67,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 +2
-1+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c@@ -120,7 +121,7 @@ ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) CFLAGS_eal_thread.o += -Wno-return-type endif -INC := rte_kni_common.h +INC := rte_kni_common.h rte_dev.h SYMLINK-$(CONFIG_RTE_EXEC_ENV_LINUXAPP)-include/exec-env := \ $(addprefix include/exec-env/,$(INC))lib/librte_eal/linuxapp/eal/eal_alarm.c +1
-0@@ -209,6 +209,7 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)int count =0 ;int err =0 ;int executing; +int ret;if (!cb_fn) {lib/librte_eal/linuxapp/eal/eal_alarm.c +4
-0rte_errno =EINVAL ;@@ -259,6 +260,10 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) } ap_prev = ap; } + + ret |=rte_intr_callback_unregister (&intr_handle, + eal_alarm_callback,NULL ); +rte_spinlock_unlock (&alarm_list_lk); }while (executing !=0 );lib/librte_eal/linuxapp/eal/eal_dev.c new file +19
-0@@ -0,0 +1,356 @@ +/*- +* Copyright(c) 2010-2017 Intel Corporation. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/linuxapp/eal/eal_dev.c new file +71
-0+ +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <sys/signalfd.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <sys/epoll.h> +#include <unistd.h> +#include <signal.h> +#include <stdbool.h> + +#include <rte_malloc.h> +#include <rte_bus.h> +#include <rte_dev.h> +#include <rte_devargs.h> +#include <rte_debug.h> +#include <rte_log.h> + +#include "eal_thread.h" + +/* uev monitoring thread */ +static pthread_t uev_monitor_thread; + +bool udev_exit = true; + +bool no_request_thread = true; + +static void sig_handler (int signum) +{ +if (signum ==SIGINT || signum ==SIGTERM ) +rte_dev_monitor_stop (); +} + +static int +dev_monitor_fd_new (void ) +{ + +int uevent_fd; + + uevent_fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (uevent_fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed\n" ); +return -1 ; + } +return uevent_fd; +} + +static int +dev_monitor_enable (int netlink_fd) +{ +struct sockaddr_nl addr; +int ret; +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 ; + +if (bind (netlink_fd, (struct sockaddr *) &addr,sizeof (addr)) <0 ) { +RTE_LOG (ERR ,EAL ,"bind failed\n" ); + goto err; + } + + setsockopt(netlink_fd, SOL_SOCKET, SO_PASSCRED, &size,sizeof(size));
lib/librte_eal/linuxapp/eal/eal_dev.c new file +53
-0+ + ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"ioctl(FIONBIO) failed\n" ); + goto err; + } +return 0 ; +err: +close (netlink_fd); +return -1 ; +} + +static void +dev_uev_parse (const char *buf,struct rte_eal_uevent *event) +{ +char action[RTE_EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[RTE_EAL_UEV_MSG_ELEM_LEN ]; +char dev_path[RTE_EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[RTE_EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); +memset (dev_path,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); + +while (i <RTE_EAL_UEV_MSG_LEN ) { +for (; i <RTE_EAL_UEV_MSG_LEN ; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; + event->group =UEV_MONITOR_UDEV ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ; +snprintf (dev_path,sizeof (dev_path),"%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);
lib/librte_eal/linuxapp/eal/eal_dev.c new file +67
-0+ event->devname = pci_slot_name; + } + for (; i < RTE_EAL_UEV_MSG_LEN; i++) { + if (*buf == '\0') + break; + buf++; + } + } + + if (!strncmp(subsystem, "pci", 3)) + event->subsystem = UEV_SUBSYSTEM_PCI; + if (!strncmp(action, "add", 3)) + event->type = RTE_EAL_DEV_EVENT_ADD; + if (!strncmp(action, "remove", 6)) + event->type = RTE_EAL_DEV_EVENT_REMOVE; + event->devname = pci_slot_name; +} + +static int +dev_uev_receive(int fd, struct rte_eal_uevent *uevent) +{ + int ret; + char buf[RTE_EAL_UEV_MSG_LEN]; + + memset(uevent, 0, sizeof(struct rte_eal_uevent)); + memset(buf, 0, RTE_EAL_UEV_MSG_LEN); + + ret = recv(fd, buf, RTE_EAL_UEV_MSG_LEN - 1, 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); + + return 0; +} + +static int +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++) { + /** + * check device uevent from kernel side, no need to check + * uevent from udev. + */ + if ((dev_uev_receive(events[i].data.fd, &uevent)) || + (uevent.group == UEV_MONITOR_UDEV)) + return 0; + + /* default handle all pci devcie when is being hot plug */ + if (uevent.subsystem == UEV_SUBSYSTEM_PCI) { + bus = rte_bus_find_by_name("pci"); + dev = rte_bus_find_device(bus, uevent.devname); + if (uevent.type == RTE_EAL_DEV_EVENT_REMOVE) { + + if ((!dev) || dev->state ==
DEVICE_UNDEFINED)lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+return 0 ; + dev->state =DEVICE_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,
lib/librte_eal/linuxapp/eal/eal_dev.c line 233
Quoted 2 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +2
-0+RTE_EAL_DEV_EVENT_REMOVE , + NULL, NULL));
What is the reason to keep this device in EAL device list after the removal?
I suggest to remove it (driver remove, bus remove and EAL remove) after the callbacks running. By this way EAL can initiate all device removals.
lib/librte_eal/linuxapp/eal/eal_dev.c line 252
Quoted 11 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +1
-0+ }else if (uevent.type ==RTE_EAL_DEV_EVENT_ADD ){
lib/librte_eal/linuxapp/eal/eal_dev.c new file +9
-0+if (dev ==NULL ) { +/** +* bind the driver to the device +* before user's add processing +*/ + bus->bind_driver ( + uevent.devname, +"igb_uio" ); +
Similar comments here:
EAL can initiate all device probe operations by adding the device and probing it here before the callback running. Then, also the device pointer can be passed to the callbacks.
Quoted 86 lines
return(_rte_dev_callback_process(NULL,
lib/librte_eal/linuxapp/eal/eal_dev.c new file +80
-0+RTE_EAL_DEV_EVENT_ADD , + uevent.devname, NULL)); + } + } + } + } +return 0 ; +} + +/** +* It builds/rebuilds up the epoll file descriptor with all the +* file descriptors being waited on. Then handles the interrupts. +* +* @param arg +* pointer. (unused) +* +* @return +* never return; +*/ +static __attribute__((noreturn))void * +dev_uev_monitoring(__rte_unused void *arg) +{ +struct sigaction act; +sigset_t mask; +int netlink_fd; +struct epoll_event ep_kernel; +int fd_ep; + + udev_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" ); + goto out; + } + + netlink_fd =dev_monitor_fd_new (); + +if (dev_monitor_enable (netlink_fd) <0 ) { +RTE_LOG (ERR ,EAL ,"error subscribing to kernel events\n" ); + goto out; + } + +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 (!udev_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 ) { +if (errno !=EINTR ) + RTE_LOG(ERR, EAL, "error processing uevent"
lib/librte_eal/linuxapp/eal/eal_dev.c new file +4
-0+ "message: %m\n"); + } + } +out:
lib/librte_eal/linuxapp/eal/eal_dev.c line 337
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+if (fd_ep >=0 ) +close (fd_ep); +if (netlink_fd >=0 ) +close (netlink_fd); +rte_panic ("uev monitoring fail\n" ); +} + +int +rte_dev_monitor_start (void ) +{
Maybe add option to run it also by new EAL command line parameter?
lib/librte_eal/linuxapp/eal/eal_dev.c line 346
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +9
-0+int ret; + +if (!no_request_thread) +return 0 ; + no_request_thread = false; + +/* create the host thread to wait/handle the uevent from kernel */ + ret =pthread_create (&uev_monitor_thread,NULL , + dev_uev_monitoring,NULL );
What is the reason to open new thread for hotplug?
Why not to use the current dpdk host thread by the alarm mechanism?
Quoted 221 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+return ret; +} + +int +rte_dev_monitor_stop (void ) +{ + udev_exit = true; + no_request_thread = true; +return 0 ; +}lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +21
-0@@ -0,0 +1,106 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +38
-0+ +#ifndef _RTE_DEV_H_ +#error "don't include this file directly, please include generic <rte_dev.h>" +#endif + +#ifndef _RTE_LINUXAPP_DEV_H_ +#define _RTE_LINUXAPP_DEV_H_ + +#include <stdio.h> + +#include <rte_dev.h> + +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum uev_subsystem { +UEV_SUBSYSTEM_UIO , +UEV_SUBSYSTEM_VFIO , +UEV_SUBSYSTEM_PCI , +UEV_SUBSYSTEM_MAX +}; + +enum uev_monitor_netlink_group { +UEV_MONITOR_KERNEL , +UEV_MONITOR_UDEV , +}; + +/** +* The device event type. +*/ +enum rte_eal_dev_event_type { +RTE_EAL_DEV_EVENT_UNKNOWN ,/**< unknown event type */ +RTE_EAL_DEV_EVENT_ADD ,/**< device adding event */ +RTE_EAL_DEV_EVENT_REMOVE , +/**< device removing event */ +RTE_EAL_DEV_EVENT_CHANGE , +/**< device status change event */ +RTE_EAL_DEV_EVENT_MOVE ,/**< device sys path move event */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +3
-0+RTE_EAL_DEV_EVENT_ONLINE ,/**< device online event */ +RTE_EAL_DEV_EVENT_OFFLINE ,/**< device offline event */ +RTE_EAL_DEV_EVENT_MAX /**< max value of this enum */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +7
-0+}; + +struct rte_eal_uevent { +enum rte_eal_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +enum uev_monitor_netlink_group group;/**< device netlink group */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +26
-0+}; + +/** +* Start the device uevent monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_dev_monitor_start (void ); + +/** +* Stop the device uevent monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ + +int +rte_dev_monitor_stop (void ); + +#endif /* _RTE_LINUXAPP_DEV_H_ */ 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
-1@@ -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
--
2.7.4
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
thanks , matan
Quoted 820 lines · Matan Azrad
Hi Jeff
Maybe I'm touching in previous discussions but please see some comments\questions.
From: Jeff Guo:
Quoted 815 lines
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object hot plug monitoring, so 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 detach or attach the device, and even benefit to use it to do smoothly fail safe work.
1) About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device, adddevice_statein struct ofrte_device, to identify the device state machine.
b: add enum ofrte_eal_dev_event_typeand struct ofrte_eal_uevent.
c: add below API in rte eal device common layer.
rte_eal_dev_monitor_enable
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_monitor_start
rte_dev_monitor_stop2) About failure handler, use pci uio for example,
addpci_remap_devicein bus layer and below function to process it:
rte_pci_remap_device
pci_uio_remap_resource
pci_map_private_resource
addrte_pci_dev_bind_driverto bind pci device with explicit driver.Signed-off-by Jeff Guo <[email protected]>---
v7->v6:
a.modify vdev part according to the vdev rework b.re-define and split the func into common and bus specific code c.fix some incorrect issue.
b.fix the system hung after send packcet issue.--- drivers/bus/pci/bsd/pci.c | 30 ++ drivers/bus/pci/linux/pci.c | 87 +++++ drivers/bus/pci/linux/pci_init.h | 1 + drivers/bus/pci/pci_common.c | 43 +++ drivers/bus/pci/pci_common_uio.c | 28 ++ drivers/bus/pci/private.h | 12 + drivers/bus/pci/rte_bus_pci.h | 25 ++ drivers/bus/vdev/vdev.c | 36 +++ lib/librte_eal/bsdapp/eal/eal_dev.c | 64 ++++ .../bsdapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/common/eal_common_bus.c | 30 ++ lib/librte_eal/common/eal_common_dev.c | 169 ++++++++++ lib/librte_eal/common/include/rte_bus.h | 69 ++++ lib/librte_eal/common/include/rte_dev.h | 89 ++++++ lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_alarm.c | 5 + lib/librte_eal/linuxapp/eal/eal_dev.c | 356 +++++++++++++++++++++ .../linuxapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 6 + lib/librte_pci/rte_pci.c | 20 ++ lib/librte_pci/rte_pci.h | 17 + 21 files changed, 1301 insertions(+), 1 deletion(-)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.hdrivers/bus/pci/bsd/pci.c +23
-0@@ -126,6 +126,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/bsd/pci.c +7
-0@@ -678,3 +701,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 +32
-0@@ -145,6 +145,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 ){drivers/bus/pci/linux/pci.c +55
-0@@ -386,6 +418,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)rte_pci_add_device (dev ); } + dev->device.state =DEVICE_PARSED ; +TAILQ_INIT (&(dev->device.uev_cbs));return 0 ; }@@ -854,3 +888,56 @@ 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) +{ +char drv_bind_path[1024 ]; +char drv_override_path[1024 ];/* contains the /dev/uioX */ +int drv_override_fd; +int drv_bind_fd; + +RTE_SET_USED (drv_type); + +snprintf (drv_override_path,sizeof (drv_override_path), +"/sys/bus/pci/devices/%s/driver_override" , dev_name); + +/* specify the driver for a device by writing to driver_override */ + drv_override_fd =open (drv_override_path,O_WRONLY ); +if (drv_override_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + drv_override_path,strerror (errno)); + goto err; + } + +if (write (drv_override_fd, drv_type,sizeof (drv_type)) <0 ) { +RTE_LOG (ERR ,EAL , +"Error: bind failed - Cannot write " +"driver %s to device %s\n" , drv_type, dev_name); + goto err; + } + +close (drv_override_fd); + +snprintf (drv_bind_path,sizeof (drv_bind_path), +"/sys/bus/pci/drivers/%s/bind" , drv_type); + +/* do the bind by writing device to the specific driver */ + drv_bind_fd =open (drv_bind_path,O_WRONLY |O_APPEND ); +if (drv_bind_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + drv_bind_path,strerror (errno)); + goto err; + } + +if (write (drv_bind_fd, dev_name,sizeof (dev_name)) <0 ) + goto err; + +close (drv_bind_fd); +return 0 ; +err: +close (drv_override_fd); +close (drv_bind_fd); +return -1 ; +} +drivers/bus/pci/linux/pci_init.h +1
-0@@ -58,6 +58,7 @@ int pci_uio_alloc_resource(struct rte_pci_device *dev, struct mapped_pci_resource **uio_res);void pci_uio_free_resource (struct rte_pci_device *dev,struct mapped_pci_resource *uio_res); +int pci_uio_remap_resource (struct rte_pci_device *dev);int pci_uio_map_resource_by_index (struct rte_pci_device *dev,int res_idx,struct mapped_pci_resource *uio_res,int map_idx);drivers/bus/pci/pci_common.c +40
-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 =DEVICE_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); }@@ -502,6 +504,44 @@ pci_find_device(const struct rte_device *start,rte_dev_cmp_t cmp, return NULL; } +static struct rte_device * +pci_find_device_by_name (const struct rte_device *start, +rte_dev_cmp_name_t cmp_name, +const void *data) +{ +struct rte_pci_device *dev; + +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (start && &dev->device == start) { + start =NULL ;/* starting point found */ +continue ; + } +if (cmp_name (dev->device.name, data) ==0 ) +return &dev->device; + } + +return NULL ; +} + +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){drivers/bus/pci/pci_common.c +3
-0@@ -528,10 +568,13 @@ struct rte_pci_bus rte_pci_bus = { .scan = rte_pci_scan, .probe = rte_pci_probe, .find_device = pci_find_device, + .find_device_by_name = pci_find_device_by_name, .plug = pci_plug, .unplug = pci_unplug, .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/pci_common_uio.c +28
-0@@ -176,6 +176,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 +25
-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 @@ -333,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 +33
-0@@ -323,6 +323,39 @@ 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, +const void *data) +{ +struct rte_vdev_device *dev; + + TAILQ_FOREACH(dev, &vdev_device_list, next) { +if (start && &dev->device == start) { + start =NULL ; +continue ; + } +if (cmp_name (dev->device.name, data) ==0 ) +return &dev->device; + } +return NULL ; +} + +static int +vdev_remap_device (struct rte_device *dev) +{ +RTE_SET_USED (dev); +return 0 ; +} + +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){drivers/bus/vdev/vdev.c +3
-0@@ -339,9 +372,12 @@ static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, .find_device = vdev_find_device, + .find_device_by_name = vdev_find_device_by_name, .plug = vdev_plug, .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/bsdapp/eal/eal_dev.c new file +19
-0@@ -0,0 +1,64 @@ +/*- +* Copyright(c) 2010-2017 Intel Corporation. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/bsdapp/eal/eal_dev.c new file +34
-0+ +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <sys/signalfd.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <sys/epoll.h> +#include <unistd.h> +#include <signal.h> +#include <stdbool.h> + +#include <rte_malloc.h> +#include <rte_bus.h> +#include <rte_dev.h> +#include <rte_devargs.h> +#include <rte_debug.h> +#include <rte_log.h> + +#include "eal_thread.h" + +int +rte_dev_monitor_start (void ) +{ +return -1 ; +} + +int +rte_dev_monitor_stop (void ) +{ +return -1 ; +}lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +21
-0@@ -0,0 +1,106 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +38
-0+ +#ifndef _RTE_DEV_H_ +#error "don't include this file directly, please include generic <rte_dev.h>" +#endif + +#ifndef _RTE_LINUXAPP_DEV_H_ +#define _RTE_LINUXAPP_DEV_H_ + +#include <stdio.h> + +#include <rte_dev.h> + +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum uev_subsystem { +UEV_SUBSYSTEM_UIO , +UEV_SUBSYSTEM_VFIO , +UEV_SUBSYSTEM_PCI , +UEV_SUBSYSTEM_MAX +}; + +enum uev_monitor_netlink_group { +UEV_MONITOR_KERNEL , +UEV_MONITOR_UDEV , +}; + +/** +* The device event type. +*/ +enum rte_eal_dev_event_type { +RTE_EAL_DEV_EVENT_UNKNOWN ,/**< unknown event type */ +RTE_EAL_DEV_EVENT_ADD ,/**< device adding event */ +RTE_EAL_DEV_EVENT_REMOVE , +/**< device removing event */ +RTE_EAL_DEV_EVENT_CHANGE , +/**< device status change event */ +RTE_EAL_DEV_EVENT_MOVE ,/**< device sys path move event */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +3
-0+RTE_EAL_DEV_EVENT_ONLINE ,/**< device online event */ +RTE_EAL_DEV_EVENT_OFFLINE ,/**< device offline event */ +RTE_EAL_DEV_EVENT_MAX /**< max value of this enum */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +7
-0+}; + +struct rte_eal_uevent { +enum rte_eal_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +enum uev_monitor_netlink_group group;/**< device netlink group */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +26
-0+}; + +/** +* Start the device uevent monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_dev_monitor_start (void ); + +/** +* Stop the device uevent monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ + +int +rte_dev_monitor_stop (void ); + +#endif /* _RTE_LINUXAPP_DEV_H_ */ lib/librte_eal/common/eal_common_bus.c +11
-0@@ -51,8 +51,11 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->scan);RTE_VERIFY (bus->probe);RTE_VERIFY (bus->find_device); +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); +RTE_VERIFY (bus->bind_driver);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);@@ -170,6 +173,14 @@ cmp_rte_device(const struct rte_device *dev1, const void *_dev2) }static int +cmp_rte_device_name (const char *dev_name1,const void *_dev_name2) +{ +const char *dev_name2 = _dev_name2; + +return strcmp (dev_name1, dev_name2); +} + +static int bus_find_device (const struct rte_bus *bus,const void *_dev) {struct
rte_device*dev;lib/librte_eal/common/eal_common_bus.c +19
-0@@ -178,6 +189,25 @@ bus_find_device(const struct rte_bus *bus, const void *_dev)return dev ==NULL ; } +static struct rte_device * +bus_find_device_by_name (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev = bus->find_device_by_name (NULL , cmp_rte_device_name, _dev_name); +return dev; +} + +struct rte_device * + +rte_bus_find_device (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev =bus_find_device_by_name (bus, _dev_name); +return dev; +} +struct rte_bus * rte_bus_find_by_device(const struct rte_device *dev) {lib/librte_eal/common/eal_common_dev.c +37
-0@@ -42,9 +42,31 @@#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 */ +static rte_spinlock_t rte_dev_cb_lock =RTE_SPINLOCK_INITIALIZER ; + +/** +* The user application callback description. +* +* It contains callback address to be registered by user application, +* the pointer to the parameters for callback, and the event type. +*/ +struct rte_eal_dev_callback { +TAILQ_ENTRY (rte_eal_dev_callback) next;/**< Callbacks list */ +rte_eal_dev_cb_fn cb_fn;/**< Callback address */ +void *cb_arg;/**< Parameter for callback */ +void *ret_param;/**< Return parameter */ +enum rte_eal_dev_event_type event;/**< device event type */ +uint32_t active;/**< Callback is executing */ +}; + +static struct rte_eal_dev_callback *dev_add_cb; +static int cmp_detached_dev_name (const struct rte_device *dev,const void *_name) {@@ -234,3 +256,150 @@ int rte_eal_hotplug_remove(const char *busname, const char *devname)rte_eal_devargs_remove (busname ,devname );return ret; } + +int +rte_eal_dev_monitor_enable (void ) +{ +int ret; + + ret =rte_dev_monitor_start (); +if (ret) +RTE_LOG (ERR ,EAL ,"Can not init device monitor\n" ); +return ret; +} + +int +rte_dev_callback_register(struct rte_device *device, + enum rte_eal_dev_event_type event,
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 280
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+ rte_eal_dev_cb_fn cb_fn, void *cb_arg) +{ + struct rte_eal_dev_callback *user_cb; + +if (!cb_fn) +return -EINVAL ; +What's about checking the device pointer is not NULL ?
sure.
Quoted 18 lines
Quoted 18 lines
lib/librte_eal/common/eal_common_dev.c +17
-0+rte_spinlock_lock (&rte_dev_cb_lock); + +if (TAILQ_EMPTY (&(device->uev_cbs))) +TAILQ_INIT (&(device->uev_cbs)); + +if (event ==RTE_EAL_DEV_EVENT_ADD ) { + user_cb =NULL ; + }else { + TAILQ_FOREACH(user_cb, &(device->uev_cbs), next) { +if (user_cb->cb_fn == cb_fn && + user_cb->cb_arg == cb_arg && + user_cb->event == event) { +break ; + } + } + } +
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 304
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+/* create a new callback. */ +if (user_cb ==NULL ) { +/* allocate a new interrupt callback entity */ + user_cb =rte_zmalloc ("eal device event" , +sizeof (*user_cb),0 ); +if (user_cb ==NULL ) { +RTE_LOG (ERR ,EAL ,"Can not allocate memory\n" );Missing
rte_spinlock_unlock.
got it.
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 311
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+return -ENOMEM ; + } + user_cb->cb_fn = cb_fn; + user_cb->cb_arg = cb_arg; + user_cb->event = event; +if (event ==RTE_EAL_DEV_EVENT_ADD ) + dev_add_cb = user_cb;Only one dpdk entity can register to ADD callback?
Quoted 5 lines
I suggest to add option to register all devices maybe by using dummy device which will include all the "
ALL_DEVICES" callbacks per event. All means past, present and future devices, by this way 1 callback can be called for all the devices and more than one dpdk entity could register to an ADD\NEW event. What's about NEW instead of ADD?I also suggest to add the device pointer as a parameter to the callback(which will be managed by EAL).
if you talk about dev_add_cb, the add means device add not cb add, if you talk about dev event type, the ADD type is consistent with the type form kernel side, anyway could be find a better. but for 1 callback for all device, it is make sense , i will think about that.
Quoted 20 lines
Quoted 20 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+else + TAILQ_INSERT_TAIL(&(device->uev_cbs), user_cb,next);
lib/librte_eal/common/eal_common_dev.c +17
-0+ } + +rte_spinlock_unlock (&rte_dev_cb_lock); +return 0 ; +} + +int +rte_dev_callback_unregister (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg) +{ +int ret; +struct rte_eal_dev_callback *cb, *next; + +if (!cb_fn) +return -EINVAL ; +
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 337
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+rte_spinlock_lock (&rte_dev_cb_lock); + + ret =0 ; +if (event ==RTE_EAL_DEV_EVENT_ADD ) { +rte_free (dev_add_cb); + dev_add_cb =NULL ; + }else {Device NULL checking?
yes.
Quoted 40 lines
Quoted 40 lines
lib/librte_eal/common/eal_common_dev.c +16
-0+for (cb =TAILQ_FIRST (&(device->uev_cbs)); cb !=NULL ; + cb = next) { + + next =TAILQ_NEXT (cb, next); + +if (cb->cb_fn != cb_fn || cb->event != event || + (cb->cb_arg != (void *)-1 && + cb->cb_arg != cb_arg)) +continue ; + +/* +* if this callback is not executing right now, +* then remove it. +*/ +if (cb->active ==0 ) { + TAILQ_REMOVE(&(device->uev_cbs), cb,next);
lib/librte_eal/common/eal_common_dev.c +23
-0+rte_free (cb); + }else { + ret = -EAGAIN ; + } + } + } +rte_spinlock_unlock (&rte_dev_cb_lock); +return ret; +} + +int +_rte_dev_callback_process (struct rte_device *device, +enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param) +{ +struct rte_eal_dev_callback dev_cb; +struct rte_eal_dev_callback *cb_lst; +int rc =0 ; + +rte_spinlock_lock (&rte_dev_cb_lock); +if (event ==RTE_EAL_DEV_EVENT_ADD ) { +if (cb_arg !=NULL ) + dev_add_cb->cb_arg = cb_arg;
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 381
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+ +if (ret_param !=NULL ) + dev_add_cb->ret_param = ret_param; + +rte_spinlock_unlock (&rte_dev_cb_lock);Can't someone free it when it running?
I suggest to keep the lock locked.
Callbacks are not allowed to use this mechanism to prevent deadlock.
seems it would bring some deadlock here, let's check it more.
Quoted 17 lines
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+ rc = dev_add_cb->cb_fn(dev_add_cb->event, + dev_add_cb->cb_arg, dev_add_cb-Quoted 1 line
ret_param);lib/librte_eal/common/eal_common_dev.c +3
-0+rte_spinlock_lock (&rte_dev_cb_lock); + }else { + TAILQ_FOREACH(cb_lst, &(device->uev_cbs), next) {lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 396
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (cb_lst->cb_fn ==NULL || cb_lst->event != event) +continue ; + dev_cb = *cb_lst; + cb_lst->active =1 ; +if (cb_arg !=NULL ) + dev_cb.cb_arg = cb_arg; +if (ret_param !=NULL ) + dev_cb.ret_param = ret_param; + +rte_spinlock_unlock (&rte_dev_cb_lock);The current active flag doesn't do it thread safe here, I suggest to keep the lock locked.
Quoted 8 lines
Scenario:
1. Thread A see active = 0 in unregister function.
2. Context switch.
3. Thread B start the callback.
4. Context switch.
5. Thread A free it.
6. Context switch.
7. Seg fault in Thread B.
the same as above.
Quoted 551 lines
Quoted 551 lines
lib/librte_eal/common/eal_common_dev.c +9
-0+ rc = dev_cb.cb_fn (dev_cb.event, + dev_cb.cb_arg, dev_cb.ret_param); +rte_spinlock_lock (&rte_dev_cb_lock); + cb_lst->active =0 ; + } + } +rte_spinlock_unlock (&rte_dev_cb_lock); +return rc; +}lib/librte_eal/common/include/rte_bus.h +7
-0@@ -122,6 +122,34 @@ typedef struct rte_device * const void *data);/** +* Device iterator to find a device on a bus. +* +* This function returns an rte_device if one of those held by the bus +* matches the data passed as parameter. +* +* If the comparison function returns zero this function should stop iterating +* over any more devices. To continue a search the device of a previous search
+ * can be passed via the start parameter.
+ *
+ * @param cmp
+ * the device name comparison function.
+ *
+ * @param data
+ * Data to compare each device against.
+ *
+ * @param start
+ * starting point for the iteration
+ *
+ * @return
+ * The first device matching the data, NULL if none exists.
+ */lib/librte_eal/common/include/rte_bus.h +8
-0+typedef struct rte_device * +(*rte_bus_find_device_by_name_t )(const struct rte_device *start, +rte_dev_cmp_name_t cmp, +const void *data); + + +/** * Implementation specific probe function which is responsible for linking * devices on that bus with applicable drivers. * @@ -168,6 +196,37 @@ 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.
+ *
+ * @param dev
+ * Device pointer that was returned by a previous call tofind_device.
+ *
+ * @return
+ * 0 on success.
+ * !0 on error.
+ */lib/librte_eal/common/include/rte_bus.h +24
-0+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 {@@ -206,9 +265,13 @@ struct rte_bus {rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ rte_bus_find_device_t find_device;/**< Find a device on the bus */ +rte_bus_find_device_by_name_t find_device_by_name; +/**< Find a device on the 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 */ +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_tget_iommu_class; /**< Get iommu
class */
};lib/librte_eal/common/include/rte_bus.h +6
-0@@ -306,6 +369,12 @@ struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);/** +* Find the registered bus for a particular device. +*/ +struct rte_device *rte_bus_find_device (const struct rte_bus *bus, +const void *dev_name); + +/** * Find the registered bus for a given name. */ struct rte_bus *rte_bus_find_by_name(const char *busname);lib/librte_eal/common/include/rte_dev.h +21
-0@@ -51,6 +51,15 @@ extern "C" {#include <rte_log.h> +#include <exec-env/rte_dev.h> + +typedef int (*rte_eal_dev_cb_fn )(enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param); + +struct rte_eal_dev_callback ; +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (rte_eal_dev_cb_list, rte_eal_dev_callback); + __attribute__((format (printf,2 ,0 )))static inline void rte_pmd_debug_trace (const char *func_name,const char *fmt, ...)@@ -157,6 +166,13 @@ struct rte_driver {*/ #define RTE_DEV_NAME_MAX_LEN 64 +enum device_state { +DEVICE_UNDEFINED , +DEVICE_FAULT , +DEVICE_PARSED , +DEVICE_PROBED , +}; +/** * A structure describing a generic device. */ @@ -166,6 +182,9 @@ struct rte_device {const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */ +enum device_state state;/**< Device state */ +/** User application callbacks for device event */ +struct rte_eal_dev_cb_list uev_cbs; };/** @@ -248,6 +267,8 @@ int rte_eal_hotplug_remove(const char *busname,const char *devname); */ typedef int (*rte_dev_cmp_t )(const struct rte_device *dev,const void *data); +typedef int (*rte_dev_cmp_name_t )(const char *dev_name,const void *data); +#define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[] #define RTE_PMD_EXPORT_NAME(name, idx) \lib/librte_eal/common/include/rte_dev.h +68
-0@@ -293,4 +314,72 @@ __attribute__((used)) = str }#endif +/** +* It enable the device event monitoring for a specific event. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_eal_dev_monitor_enable (void ); +/** +* 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 (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_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. +* +* @return +* - On success, return the number of callback entities removed. +* - On failure, a negative value. +*/ +int rte_dev_callback_unregister (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg); + +/** +* @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 event +* The device event type. +* @param cb_arg +* callback parameter. +* @param ret_param +* To pass data back to user application. +* This allows the user application to decide if a particular function +* is permitted or not. +* +* @return +* - On success, return zero. +* - On failure, a negative value. +*/ +int +_rte_dev_callback_process (struct rte_device *device, +enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param);#endif /* _RTE_DEV_H_ */ lib/librte_eal/linuxapp/eal/Makefile +0
-0@@ -67,6 +67,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 +2
-1+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c@@ -120,7 +121,7 @@ ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) CFLAGS_eal_thread.o += -Wno-return-type endif -INC := rte_kni_common.h +INC := rte_kni_common.h rte_dev.h SYMLINK-$(CONFIG_RTE_EXEC_ENV_LINUXAPP)-include/exec-env := \ $(addprefix include/exec-env/,$(INC))lib/librte_eal/linuxapp/eal/eal_alarm.c +1
-0@@ -209,6 +209,7 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)int count =0 ;int err =0 ;int executing; +int ret;if (!cb_fn) {rte_errno = EINVAL;lib/librte_eal/linuxapp/eal/eal_alarm.c +4
-0@@ -259,6 +260,10 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) } ap_prev = ap; } + + ret |=rte_intr_callback_unregister (&intr_handle, + eal_alarm_callback,NULL ); +rte_spinlock_unlock (&alarm_list_lk); }while (executing !=0 );lib/librte_eal/linuxapp/eal/eal_dev.c new file +19
-0@@ -0,0 +1,356 @@ +/*- +* Copyright(c) 2010-2017 Intel Corporation. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/linuxapp/eal/eal_dev.c new file +71
-0+ +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <sys/signalfd.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <sys/epoll.h> +#include <unistd.h> +#include <signal.h> +#include <stdbool.h> + +#include <rte_malloc.h> +#include <rte_bus.h> +#include <rte_dev.h> +#include <rte_devargs.h> +#include <rte_debug.h> +#include <rte_log.h> + +#include "eal_thread.h" + +/* uev monitoring thread */ +static pthread_t uev_monitor_thread; + +bool udev_exit = true; + +bool no_request_thread = true; + +static void sig_handler (int signum) +{ +if (signum ==SIGINT || signum ==SIGTERM ) +rte_dev_monitor_stop (); +} + +static int +dev_monitor_fd_new (void ) +{ + +int uevent_fd; + + uevent_fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (uevent_fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed\n" ); +return -1 ; + } +return uevent_fd; +} + +static int +dev_monitor_enable (int netlink_fd) +{ +struct sockaddr_nl addr; +int ret; +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 ; + +if (bind (netlink_fd, (struct sockaddr *) &addr,sizeof (addr)) <0 ) { +RTE_LOG (ERR ,EAL ,"bind failed\n" ); + goto err; + } + + setsockopt(netlink_fd, SOL_SOCKET, SO_PASSCRED, &size,sizeof(size));
lib/librte_eal/linuxapp/eal/eal_dev.c new file +53
-0+ + ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"ioctl(FIONBIO) failed\n" ); + goto err; + } +return 0 ; +err: +close (netlink_fd); +return -1 ; +} + +static void +dev_uev_parse (const char *buf,struct rte_eal_uevent *event) +{ +char action[RTE_EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[RTE_EAL_UEV_MSG_ELEM_LEN ]; +char dev_path[RTE_EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[RTE_EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); +memset (dev_path,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); + +while (i <RTE_EAL_UEV_MSG_LEN ) { +for (; i <RTE_EAL_UEV_MSG_LEN ; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; + event->group =UEV_MONITOR_UDEV ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ; +snprintf (dev_path,sizeof (dev_path),"%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);
lib/librte_eal/linuxapp/eal/eal_dev.c new file +67
-0+ event->devname = pci_slot_name; + } + for (; i < RTE_EAL_UEV_MSG_LEN; i++) { + if (*buf == '\0') + break; + buf++; + } + } + + if (!strncmp(subsystem, "pci", 3)) + event->subsystem = UEV_SUBSYSTEM_PCI; + if (!strncmp(action, "add", 3)) + event->type = RTE_EAL_DEV_EVENT_ADD; + if (!strncmp(action, "remove", 6)) + event->type = RTE_EAL_DEV_EVENT_REMOVE; + event->devname = pci_slot_name; +} + +static int +dev_uev_receive(int fd, struct rte_eal_uevent *uevent) +{ + int ret; + char buf[RTE_EAL_UEV_MSG_LEN]; + + memset(uevent, 0, sizeof(struct rte_eal_uevent)); + memset(buf, 0, RTE_EAL_UEV_MSG_LEN); + + ret = recv(fd, buf, RTE_EAL_UEV_MSG_LEN - 1, 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); + + return 0; +} + +static int +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++) { + /** + * check device uevent from kernel side, no need to check + * uevent from udev. + */ + if ((dev_uev_receive(events[i].data.fd, &uevent)) || + (uevent.group == UEV_MONITOR_UDEV)) + return 0; + + /* default handle all pci devcie when is being hot plug */ + if (uevent.subsystem == UEV_SUBSYSTEM_PCI) { + bus = rte_bus_find_by_name("pci"); + dev = rte_bus_find_device(bus, uevent.devname); + if (uevent.type == RTE_EAL_DEV_EVENT_REMOVE) { + + if ((!dev) || dev->state ==
DEVICE_UNDEFINED)lib/librte_eal/linuxapp/eal/eal_dev.c new file +8
-0+return 0 ; + dev->state =DEVICE_FAULT ; + +/** +* remap the resource to be fake +* before user's removal processing +*/ + ret = bus->remap_device (dev);
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 233
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +2
-0+if (!ret) +return(_rte_dev_callback_process(dev,
lib/librte_eal/linuxapp/eal/eal_dev.c new file +2
-0+RTE_EAL_DEV_EVENT_REMOVE , + NULL, NULL));What is the reason to keep this device in EAL device list after the removal?
I suggest to remove it (driver remove, bus remove and EAL remove) after the callbacks running. By this way EAL can initiate all device removals.
agree, device should be remove from the eal device list after the removal.
Quoted 6 lines
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +1
-0+ }else if (uevent.type ==RTE_EAL_DEV_EVENT_ADD ){
lib/librte_eal/linuxapp/eal/eal_dev.c new file +4
-0+if (dev ==NULL ) { +/** +* bind the driver to the device +* before user's add processing
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 252
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +5
-0+*/ + bus->bind_driver ( + uevent.devname, +"igb_uio" ); +Similar comments here:
EAL can initiate all device probe operations by adding the device and probing it here before the callback running. Then, also the device pointer can be passed to the callbacks.
pass a device pointer could be bring some more change, let's think about more.
Quoted 89 lines
Quoted 89 lines
return(_rte_dev_callback_process(NULL,
lib/librte_eal/linuxapp/eal/eal_dev.c new file +80
-0+RTE_EAL_DEV_EVENT_ADD , + uevent.devname, NULL)); + } + } + } + } +return 0 ; +} + +/** +* It builds/rebuilds up the epoll file descriptor with all the +* file descriptors being waited on. Then handles the interrupts. +* +* @param arg +* pointer. (unused) +* +* @return +* never return; +*/ +static __attribute__((noreturn))void * +dev_uev_monitoring(__rte_unused void *arg) +{ +struct sigaction act; +sigset_t mask; +int netlink_fd; +struct epoll_event ep_kernel; +int fd_ep; + + udev_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" ); + goto out; + } + + netlink_fd =dev_monitor_fd_new (); + +if (dev_monitor_enable (netlink_fd) <0 ) { +RTE_LOG (ERR ,EAL ,"error subscribing to kernel events\n" ); + goto out; + } + +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 (!udev_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 ) { +if (errno !=EINTR ) + RTE_LOG(ERR, EAL, "error processing uevent"
lib/librte_eal/linuxapp/eal/eal_dev.c new file +7
-0+ "message: %m\n"); + } + } +out: +if (fd_ep >=0 ) +close (fd_ep); +if (netlink_fd >=0 )
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 337
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +7
-0+close (netlink_fd); +rte_panic ("uev monitoring fail\n" ); +} + +int +rte_dev_monitor_start (void ) +{Maybe add option to run it also by new EAL command line parameter?
good idea.
Quoted 11 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 346
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +9
-0+int ret; + +if (!no_request_thread) +return 0 ; + no_request_thread = false; + +/* create the host thread to wait/handle the uevent from kernel */ + ret =pthread_create (&uev_monitor_thread,NULL , + dev_uev_monitoring,NULL );What is the reason to open new thread for hotplug?
Why not to use the current dpdk host thread by the alarm mechanism?
appropriate if you could talk about what you mean the disadvantage of new thread here and the advantage of alarm mechanism at the case?
Quoted 221 lines
Quoted 221 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+return ret; +} + +int +rte_dev_monitor_stop (void ) +{ + udev_exit = true; + no_request_thread = true; +return 0 ; +}lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +21
-0@@ -0,0 +1,106 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +38
-0+ +#ifndef _RTE_DEV_H_ +#error "don't include this file directly, please include generic <rte_dev.h>" +#endif + +#ifndef _RTE_LINUXAPP_DEV_H_ +#define _RTE_LINUXAPP_DEV_H_ + +#include <stdio.h> + +#include <rte_dev.h> + +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum uev_subsystem { +UEV_SUBSYSTEM_UIO , +UEV_SUBSYSTEM_VFIO , +UEV_SUBSYSTEM_PCI , +UEV_SUBSYSTEM_MAX +}; + +enum uev_monitor_netlink_group { +UEV_MONITOR_KERNEL , +UEV_MONITOR_UDEV , +}; + +/** +* The device event type. +*/ +enum rte_eal_dev_event_type { +RTE_EAL_DEV_EVENT_UNKNOWN ,/**< unknown event type */ +RTE_EAL_DEV_EVENT_ADD ,/**< device adding event */ +RTE_EAL_DEV_EVENT_REMOVE , +/**< device removing event */ +RTE_EAL_DEV_EVENT_CHANGE , +/**< device status change event */ +RTE_EAL_DEV_EVENT_MOVE ,/**< device sys path move event */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +3
-0+RTE_EAL_DEV_EVENT_ONLINE ,/**< device online event */ +RTE_EAL_DEV_EVENT_OFFLINE ,/**< device offline event */ +RTE_EAL_DEV_EVENT_MAX /**< max value of this enum */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +7
-0+}; + +struct rte_eal_uevent { +enum rte_eal_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +enum uev_monitor_netlink_group group;/**< device netlink group */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +26
-0+}; + +/** +* Start the device uevent monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_dev_monitor_start (void ); + +/** +* Stop the device uevent monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ + +int +rte_dev_monitor_stop (void ); + +#endif /* _RTE_LINUXAPP_DEV_H_ */ 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
-1@@ -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
--
2.7.4
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
In reply to Matan Azradadd one more comment.
Quoted 1,525 lines · Matan Azrad
Hi Jeff
Maybe I'm touching in previous discussions but please see some comments\questions.
From: Jeff Guo:
Quoted 812 lines
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object hot plug monitoring, so 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 detach or attach the device, and even benefit to use it to do smoothly fail safe work.
1) About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device, adddevice_statein struct ofrte_device, to identify the device state machine.
b: add enum ofrte_eal_dev_event_typeand struct ofrte_eal_uevent.
c: add below API in rte eal device common layer.
rte_eal_dev_monitor_enable
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_monitor_start
rte_dev_monitor_stop2) About failure handler, use pci uio for example,
addpci_remap_devicein bus layer and below function to process it:
rte_pci_remap_device
pci_uio_remap_resource
pci_map_private_resource
addrte_pci_dev_bind_driverto bind pci device with explicit driver.Signed-off-by Jeff Guo <[email protected]>---
v7->v6:
a.modify vdev part according to the vdev rework b.re-define and split the func into common and bus specific code c.fix some incorrect issue.
b.fix the system hung after send packcet issue.--- drivers/bus/pci/bsd/pci.c | 30 ++ drivers/bus/pci/linux/pci.c | 87 +++++ drivers/bus/pci/linux/pci_init.h | 1 + drivers/bus/pci/pci_common.c | 43 +++ drivers/bus/pci/pci_common_uio.c | 28 ++ drivers/bus/pci/private.h | 12 + drivers/bus/pci/rte_bus_pci.h | 25 ++ drivers/bus/vdev/vdev.c | 36 +++ lib/librte_eal/bsdapp/eal/eal_dev.c | 64 ++++ .../bsdapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/common/eal_common_bus.c | 30 ++ lib/librte_eal/common/eal_common_dev.c | 169 ++++++++++ lib/librte_eal/common/include/rte_bus.h | 69 ++++ lib/librte_eal/common/include/rte_dev.h | 89 ++++++ lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_alarm.c | 5 + lib/librte_eal/linuxapp/eal/eal_dev.c | 356 +++++++++++++++++++++ .../linuxapp/eal/include/exec-env/rte_dev.h | 106 ++++++ lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 6 + lib/librte_pci/rte_pci.c | 20 ++ lib/librte_pci/rte_pci.h | 17 + 21 files changed, 1301 insertions(+), 1 deletion(-)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.hdrivers/bus/pci/bsd/pci.c +23
-0@@ -126,6 +126,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/bsd/pci.c +7
-0@@ -678,3 +701,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 +32
-0@@ -145,6 +145,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 ){drivers/bus/pci/linux/pci.c +55
-0@@ -386,6 +418,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)rte_pci_add_device (dev ); } + dev->device.state =DEVICE_PARSED ; +TAILQ_INIT (&(dev->device.uev_cbs));return 0 ; }@@ -854,3 +888,56 @@ 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) +{ +char drv_bind_path[1024 ]; +char drv_override_path[1024 ];/* contains the /dev/uioX */ +int drv_override_fd; +int drv_bind_fd; + +RTE_SET_USED (drv_type); + +snprintf (drv_override_path,sizeof (drv_override_path), +"/sys/bus/pci/devices/%s/driver_override" , dev_name); + +/* specify the driver for a device by writing to driver_override */ + drv_override_fd =open (drv_override_path,O_WRONLY ); +if (drv_override_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + drv_override_path,strerror (errno)); + goto err; + } + +if (write (drv_override_fd, drv_type,sizeof (drv_type)) <0 ) { +RTE_LOG (ERR ,EAL , +"Error: bind failed - Cannot write " +"driver %s to device %s\n" , drv_type, dev_name); + goto err; + } + +close (drv_override_fd); + +snprintf (drv_bind_path,sizeof (drv_bind_path), +"/sys/bus/pci/drivers/%s/bind" , drv_type); + +/* do the bind by writing device to the specific driver */ + drv_bind_fd =open (drv_bind_path,O_WRONLY |O_APPEND ); +if (drv_bind_fd <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot open %s: %s\n" , + drv_bind_path,strerror (errno)); + goto err; + } + +if (write (drv_bind_fd, dev_name,sizeof (dev_name)) <0 ) + goto err; + +close (drv_bind_fd); +return 0 ; +err: +close (drv_override_fd); +close (drv_bind_fd); +return -1 ; +} +drivers/bus/pci/linux/pci_init.h +1
-0@@ -58,6 +58,7 @@ int pci_uio_alloc_resource(struct rte_pci_device *dev, struct mapped_pci_resource **uio_res);void pci_uio_free_resource (struct rte_pci_device *dev,struct mapped_pci_resource *uio_res); +int pci_uio_remap_resource (struct rte_pci_device *dev);int pci_uio_map_resource_by_index (struct rte_pci_device *dev,int res_idx,struct mapped_pci_resource *uio_res,int map_idx);drivers/bus/pci/pci_common.c +40
-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 =DEVICE_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); }@@ -502,6 +504,44 @@ pci_find_device(const struct rte_device *start,rte_dev_cmp_t cmp, return NULL; } +static struct rte_device * +pci_find_device_by_name (const struct rte_device *start, +rte_dev_cmp_name_t cmp_name, +const void *data) +{ +struct rte_pci_device *dev; + +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (start && &dev->device == start) { + start =NULL ;/* starting point found */ +continue ; + } +if (cmp_name (dev->device.name, data) ==0 ) +return &dev->device; + } + +return NULL ; +} + +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){drivers/bus/pci/pci_common.c +3
-0@@ -528,10 +568,13 @@ struct rte_pci_bus rte_pci_bus = { .scan = rte_pci_scan, .probe = rte_pci_probe, .find_device = pci_find_device, + .find_device_by_name = pci_find_device_by_name, .plug = pci_plug, .unplug = pci_unplug, .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/pci_common_uio.c +28
-0@@ -176,6 +176,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 +25
-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 @@ -333,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 +33
-0@@ -323,6 +323,39 @@ 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, +const void *data) +{ +struct rte_vdev_device *dev; + + TAILQ_FOREACH(dev, &vdev_device_list, next) { +if (start && &dev->device == start) { + start =NULL ; +continue ; + } +if (cmp_name (dev->device.name, data) ==0 ) +return &dev->device; + } +return NULL ; +} + +static int +vdev_remap_device (struct rte_device *dev) +{ +RTE_SET_USED (dev); +return 0 ; +} + +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){drivers/bus/vdev/vdev.c +3
-0@@ -339,9 +372,12 @@ static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, .find_device = vdev_find_device, + .find_device_by_name = vdev_find_device_by_name, .plug = vdev_plug, .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/bsdapp/eal/eal_dev.c new file +19
-0@@ -0,0 +1,64 @@ +/*- +* Copyright(c) 2010-2017 Intel Corporation. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/bsdapp/eal/eal_dev.c new file +34
-0+ +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <sys/signalfd.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <sys/epoll.h> +#include <unistd.h> +#include <signal.h> +#include <stdbool.h> + +#include <rte_malloc.h> +#include <rte_bus.h> +#include <rte_dev.h> +#include <rte_devargs.h> +#include <rte_debug.h> +#include <rte_log.h> + +#include "eal_thread.h" + +int +rte_dev_monitor_start (void ) +{ +return -1 ; +} + +int +rte_dev_monitor_stop (void ) +{ +return -1 ; +}lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +21
-0@@ -0,0 +1,106 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +38
-0+ +#ifndef _RTE_DEV_H_ +#error "don't include this file directly, please include generic <rte_dev.h>" +#endif + +#ifndef _RTE_LINUXAPP_DEV_H_ +#define _RTE_LINUXAPP_DEV_H_ + +#include <stdio.h> + +#include <rte_dev.h> + +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum uev_subsystem { +UEV_SUBSYSTEM_UIO , +UEV_SUBSYSTEM_VFIO , +UEV_SUBSYSTEM_PCI , +UEV_SUBSYSTEM_MAX +}; + +enum uev_monitor_netlink_group { +UEV_MONITOR_KERNEL , +UEV_MONITOR_UDEV , +}; + +/** +* The device event type. +*/ +enum rte_eal_dev_event_type { +RTE_EAL_DEV_EVENT_UNKNOWN ,/**< unknown event type */ +RTE_EAL_DEV_EVENT_ADD ,/**< device adding event */ +RTE_EAL_DEV_EVENT_REMOVE , +/**< device removing event */ +RTE_EAL_DEV_EVENT_CHANGE , +/**< device status change event */ +RTE_EAL_DEV_EVENT_MOVE ,/**< device sys path move event */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +3
-0+RTE_EAL_DEV_EVENT_ONLINE ,/**< device online event */ +RTE_EAL_DEV_EVENT_OFFLINE ,/**< device offline event */ +RTE_EAL_DEV_EVENT_MAX /**< max value of this enum */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +7
-0+}; + +struct rte_eal_uevent { +enum rte_eal_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +enum uev_monitor_netlink_group group;/**< device netlink group */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +26
-0+}; + +/** +* Start the device uevent monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_dev_monitor_start (void ); + +/** +* Stop the device uevent monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ + +int +rte_dev_monitor_stop (void ); + +#endif /* _RTE_LINUXAPP_DEV_H_ */ lib/librte_eal/common/eal_common_bus.c +11
-0@@ -51,8 +51,11 @@ rte_bus_register(struct rte_bus *bus)RTE_VERIFY (bus->scan);RTE_VERIFY (bus->probe);RTE_VERIFY (bus->find_device); +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); +RTE_VERIFY (bus->bind_driver);TAILQ_INSERT_TAIL (&rte_bus_list, bus, next);RTE_LOG (DEBUG ,EAL ,"Registered [%s] bus.\n" , bus->name);@@ -170,6 +173,14 @@ cmp_rte_device(const struct rte_device *dev1, const void *_dev2) }static int +cmp_rte_device_name (const char *dev_name1,const void *_dev_name2) +{ +const char *dev_name2 = _dev_name2; + +return strcmp (dev_name1, dev_name2); +} + +static int bus_find_device (const struct rte_bus *bus,const void *_dev) {struct
rte_device*dev;lib/librte_eal/common/eal_common_bus.c +19
-0@@ -178,6 +189,25 @@ bus_find_device(const struct rte_bus *bus, const void *_dev)return dev ==NULL ; } +static struct rte_device * +bus_find_device_by_name (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev = bus->find_device_by_name (NULL , cmp_rte_device_name, _dev_name); +return dev; +} + +struct rte_device * + +rte_bus_find_device (const struct rte_bus *bus,const void *_dev_name) +{ +struct rte_device *dev; + + dev =bus_find_device_by_name (bus, _dev_name); +return dev; +} +struct rte_bus * rte_bus_find_by_device(const struct rte_device *dev) {lib/librte_eal/common/eal_common_dev.c +34
-0@@ -42,9 +42,31 @@#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 */ +static rte_spinlock_t rte_dev_cb_lock =RTE_SPINLOCK_INITIALIZER ; + +/** +* The user application callback description. +* +* It contains callback address to be registered by user application, +* the pointer to the parameters for callback, and the event type. +*/ +struct rte_eal_dev_callback { +TAILQ_ENTRY (rte_eal_dev_callback) next;/**< Callbacks list */ +rte_eal_dev_cb_fn cb_fn;/**< Callback address */ +void *cb_arg;/**< Parameter for callback */ +void *ret_param;/**< Return parameter */ +enum rte_eal_dev_event_type event;/**< device event type */ +uint32_t active;/**< Callback is executing */ +}; + +static struct rte_eal_dev_callback *dev_add_cb; +static int cmp_detached_dev_name (const struct rte_device *dev,const void *_name) {@@ -234,3 +256,150 @@ int rte_eal_hotplug_remove(const char *busname, const char *devname)rte_eal_devargs_remove (busname ,devname );return ret; } + +int +rte_eal_dev_monitor_enable (void ) +{ +int ret; + + ret =rte_dev_monitor_start (); +if (ret) +RTE_LOG (ERR ,EAL ,"Can not init device monitor\n" ); +return ret; +} +lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, · line 280
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+int +rte_dev_callback_register (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg) +{ +struct rte_eal_dev_callback *user_cb; + +if (!cb_fn) +return -EINVAL ; +What's about checking the device pointer is not NULL ?
Quoted 14 lines
lib/librte_eal/common/eal_common_dev.c +14
-0+rte_spinlock_lock (&rte_dev_cb_lock); + +if (TAILQ_EMPTY (&(device->uev_cbs))) +TAILQ_INIT (&(device->uev_cbs)); + +if (event ==RTE_EAL_DEV_EVENT_ADD ) { + user_cb =NULL ; + }else { + TAILQ_FOREACH(user_cb, &(device->uev_cbs), next) { +if (user_cb->cb_fn == cb_fn && + user_cb->cb_arg == cb_arg && + user_cb->event == event) { +break ; + }lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 304
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+ } + } + +/* create a new callback. */ +if (user_cb ==NULL ) { +/* allocate a new interrupt callback entity */ + user_cb =rte_zmalloc ("eal device event" , +sizeof (*user_cb),0 ); +if (user_cb ==NULL ) { +RTE_LOG (ERR ,EAL ,"Can not allocate memory\n" );Missing
rte_spinlock_unlock.lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 311
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+return -ENOMEM ; + } + user_cb->cb_fn = cb_fn; + user_cb->cb_arg = cb_arg; + user_cb->event = event; +if (event ==RTE_EAL_DEV_EVENT_ADD ) + dev_add_cb = user_cb;Only one dpdk entity can register to ADD callback?
I suggest to add option to register all devices maybe by using dummy device which will include all the "
ALL_DEVICES" callbacks per event. All means past, present and future devices, by this way 1 callback can be called for all the devices and more than one dpdk entity could register to an ADD\NEW event. What's about NEW instead of ADD?I also suggest to add the device pointer as a parameter to the callback(which will be managed by EAL).
Quoted 17 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+else + TAILQ_INSERT_TAIL(&(device->uev_cbs), user_cb,next);
lib/librte_eal/common/eal_common_dev.c +14
-0+ } + +rte_spinlock_unlock (&rte_dev_cb_lock); +return 0 ; +} + +int +rte_dev_callback_unregister (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg) +{ +int ret; +struct rte_eal_dev_callback *cb, *next; +lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 337
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&rte_dev_cb_lock); + + ret =0 ; +if (event ==RTE_EAL_DEV_EVENT_ADD ) { +rte_free (dev_add_cb); + dev_add_cb =NULL ; + }else {Device NULL checking?
Quoted 35 lines
lib/librte_eal/common/eal_common_dev.c +16
-0+for (cb =TAILQ_FIRST (&(device->uev_cbs)); cb !=NULL ; + cb = next) { + + next =TAILQ_NEXT (cb, next); + +if (cb->cb_fn != cb_fn || cb->event != event || + (cb->cb_arg != (void *)-1 && + cb->cb_arg != cb_arg)) +continue ; + +/* +* if this callback is not executing right now, +* then remove it. +*/ +if (cb->active ==0 ) { + TAILQ_REMOVE(&(device->uev_cbs), cb,next);
lib/librte_eal/common/eal_common_dev.c +18
-0+rte_free (cb); + }else { + ret = -EAGAIN ; + } + } + } +rte_spinlock_unlock (&rte_dev_cb_lock); +return ret; +} + +int +_rte_dev_callback_process (struct rte_device *device, +enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param) +{ +struct rte_eal_dev_callback dev_cb; +struct rte_eal_dev_callback *cb_lst; +int rc =0 ;lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 381
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+ +rte_spinlock_lock (&rte_dev_cb_lock); +if (event ==RTE_EAL_DEV_EVENT_ADD ) { +if (cb_arg !=NULL ) + dev_add_cb->cb_arg = cb_arg; + +if (ret_param !=NULL ) + dev_add_cb->ret_param = ret_param; + +rte_spinlock_unlock (&rte_dev_cb_lock);Can't someone free it when it running?
I suggest to keep the lock locked.
Callbacks are not allowed to use this mechanism to prevent deadlock.Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+ rc = dev_add_cb->cb_fn(dev_add_cb->event, + dev_add_cb->cb_arg, dev_add_cb-Quoted 1 line
ret_param);lib/librte_eal/common/eal_common_dev.c +3
-0+rte_spinlock_lock (&rte_dev_cb_lock); + }else { + TAILQ_FOREACH(cb_lst, &(device->uev_cbs), next) {lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 396
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (cb_lst->cb_fn ==NULL || cb_lst->event != event) +continue ; + dev_cb = *cb_lst; + cb_lst->active =1 ; +if (cb_arg !=NULL ) + dev_cb.cb_arg = cb_arg; +if (ret_param !=NULL ) + dev_cb.ret_param = ret_param; + +rte_spinlock_unlock (&rte_dev_cb_lock);The current active flag doesn't do it thread safe here, I suggest to keep the lock locked. Scenario:
1. Thread A see active = 0 in unregister function.
2. Context switch.
3. Thread B start the callback.
4. Context switch.
5. Thread A free it.
6. Context switch.
7. Seg fault in Thread B.Quoted 551 lines
lib/librte_eal/common/eal_common_dev.c +9
-0+ rc = dev_cb.cb_fn (dev_cb.event, + dev_cb.cb_arg, dev_cb.ret_param); +rte_spinlock_lock (&rte_dev_cb_lock); + cb_lst->active =0 ; + } + } +rte_spinlock_unlock (&rte_dev_cb_lock); +return rc; +}lib/librte_eal/common/include/rte_bus.h +7
-0@@ -122,6 +122,34 @@ typedef struct rte_device * const void *data);/** +* Device iterator to find a device on a bus. +* +* This function returns an rte_device if one of those held by the bus +* matches the data passed as parameter. +* +* If the comparison function returns zero this function should stop iterating +* over any more devices. To continue a search the device of a previous search
+ * can be passed via the start parameter.
+ *
+ * @param cmp
+ * the device name comparison function.
+ *
+ * @param data
+ * Data to compare each device against.
+ *
+ * @param start
+ * starting point for the iteration
+ *
+ * @return
+ * The first device matching the data, NULL if none exists.
+ */lib/librte_eal/common/include/rte_bus.h +8
-0+typedef struct rte_device * +(*rte_bus_find_device_by_name_t )(const struct rte_device *start, +rte_dev_cmp_name_t cmp, +const void *data); + + +/** * Implementation specific probe function which is responsible for linking * devices on that bus with applicable drivers. * @@ -168,6 +196,37 @@ 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.
+ *
+ * @param dev
+ * Device pointer that was returned by a previous call tofind_device.
+ *
+ * @return
+ * 0 on success.
+ * !0 on error.
+ */lib/librte_eal/common/include/rte_bus.h +24
-0+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 {@@ -206,9 +265,13 @@ struct rte_bus {rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ rte_bus_find_device_t find_device;/**< Find a device on the bus */ +rte_bus_find_device_by_name_t find_device_by_name; +/**< Find a device on the 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 */ +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_tget_iommu_class; /**< Get iommu
class */
};lib/librte_eal/common/include/rte_bus.h +6
-0@@ -306,6 +369,12 @@ struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp, struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);/** +* Find the registered bus for a particular device. +*/ +struct rte_device *rte_bus_find_device (const struct rte_bus *bus, +const void *dev_name); + +/** * Find the registered bus for a given name. */ struct rte_bus *rte_bus_find_by_name(const char *busname);lib/librte_eal/common/include/rte_dev.h +21
-0@@ -51,6 +51,15 @@ extern "C" {#include <rte_log.h> +#include <exec-env/rte_dev.h> + +typedef int (*rte_eal_dev_cb_fn )(enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param); + +struct rte_eal_dev_callback ; +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (rte_eal_dev_cb_list, rte_eal_dev_callback); + __attribute__((format (printf,2 ,0 )))static inline void rte_pmd_debug_trace (const char *func_name,const char *fmt, ...)@@ -157,6 +166,13 @@ struct rte_driver {*/ #define RTE_DEV_NAME_MAX_LEN 64 +enum device_state { +DEVICE_UNDEFINED , +DEVICE_FAULT , +DEVICE_PARSED , +DEVICE_PROBED , +}; +/** * A structure describing a generic device. */ @@ -166,6 +182,9 @@ struct rte_device {const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */ +enum device_state state;/**< Device state */ +/** User application callbacks for device event */ +struct rte_eal_dev_cb_list uev_cbs; };/** @@ -248,6 +267,8 @@ int rte_eal_hotplug_remove(const char *busname,const char *devname); */ typedef int (*rte_dev_cmp_t )(const struct rte_device *dev,const void *data); +typedef int (*rte_dev_cmp_name_t )(const char *dev_name,const void *data); +#define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[] #define RTE_PMD_EXPORT_NAME(name, idx) \lib/librte_eal/common/include/rte_dev.h +68
-0@@ -293,4 +314,72 @@ __attribute__((used)) = str }#endif +/** +* It enable the device event monitoring for a specific event. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_eal_dev_monitor_enable (void ); +/** +* 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 (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_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. +* +* @return +* - On success, return the number of callback entities removed. +* - On failure, a negative value. +*/ +int rte_dev_callback_unregister (struct rte_device *device, +enum rte_eal_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg); + +/** +* @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 event +* The device event type. +* @param cb_arg +* callback parameter. +* @param ret_param +* To pass data back to user application. +* This allows the user application to decide if a particular function +* is permitted or not. +* +* @return +* - On success, return zero. +* - On failure, a negative value. +*/ +int +_rte_dev_callback_process (struct rte_device *device, +enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param);#endif /* _RTE_DEV_H_ */ lib/librte_eal/linuxapp/eal/Makefile +0
-0@@ -67,6 +67,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 +2
-1+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c@@ -120,7 +121,7 @@ ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) CFLAGS_eal_thread.o += -Wno-return-type endif -INC := rte_kni_common.h +INC := rte_kni_common.h rte_dev.h SYMLINK-$(CONFIG_RTE_EXEC_ENV_LINUXAPP)-include/exec-env := \ $(addprefix include/exec-env/,$(INC))lib/librte_eal/linuxapp/eal/eal_alarm.c +1
-0@@ -209,6 +209,7 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)int count =0 ;int err =0 ;int executing; +int ret;if (!cb_fn) {rte_errno = EINVAL;lib/librte_eal/linuxapp/eal/eal_alarm.c +4
-0@@ -259,6 +260,10 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) } ap_prev = ap; } + + ret |=rte_intr_callback_unregister (&intr_handle, + eal_alarm_callback,NULL ); +rte_spinlock_unlock (&alarm_list_lk); }while (executing !=0 );lib/librte_eal/linuxapp/eal/eal_dev.c new file +19
-0@@ -0,0 +1,356 @@ +/*- +* Copyright(c) 2010-2017 Intel Corporation. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/linuxapp/eal/eal_dev.c new file +71
-0+ +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <sys/signalfd.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <sys/epoll.h> +#include <unistd.h> +#include <signal.h> +#include <stdbool.h> + +#include <rte_malloc.h> +#include <rte_bus.h> +#include <rte_dev.h> +#include <rte_devargs.h> +#include <rte_debug.h> +#include <rte_log.h> + +#include "eal_thread.h" + +/* uev monitoring thread */ +static pthread_t uev_monitor_thread; + +bool udev_exit = true; + +bool no_request_thread = true; + +static void sig_handler (int signum) +{ +if (signum ==SIGINT || signum ==SIGTERM ) +rte_dev_monitor_stop (); +} + +static int +dev_monitor_fd_new (void ) +{ + +int uevent_fd; + + uevent_fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (uevent_fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed\n" ); +return -1 ; + } +return uevent_fd; +} + +static int +dev_monitor_enable (int netlink_fd) +{ +struct sockaddr_nl addr; +int ret; +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 ; + +if (bind (netlink_fd, (struct sockaddr *) &addr,sizeof (addr)) <0 ) { +RTE_LOG (ERR ,EAL ,"bind failed\n" ); + goto err; + } + + setsockopt(netlink_fd, SOL_SOCKET, SO_PASSCRED, &size,sizeof(size));
lib/librte_eal/linuxapp/eal/eal_dev.c new file +53
-0+ + ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"ioctl(FIONBIO) failed\n" ); + goto err; + } +return 0 ; +err: +close (netlink_fd); +return -1 ; +} + +static void +dev_uev_parse (const char *buf,struct rte_eal_uevent *event) +{ +char action[RTE_EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[RTE_EAL_UEV_MSG_ELEM_LEN ]; +char dev_path[RTE_EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[RTE_EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); +memset (dev_path,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,RTE_EAL_UEV_MSG_ELEM_LEN ); + +while (i <RTE_EAL_UEV_MSG_LEN ) { +for (; i <RTE_EAL_UEV_MSG_LEN ; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"libudev" ,7 )) { + buf +=7 ; + i +=7 ; + event->group =UEV_MONITOR_UDEV ; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ; +snprintf (dev_path,sizeof (dev_path),"%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);
lib/librte_eal/linuxapp/eal/eal_dev.c new file +67
-0+ event->devname = pci_slot_name; + } + for (; i < RTE_EAL_UEV_MSG_LEN; i++) { + if (*buf == '\0') + break; + buf++; + } + } + + if (!strncmp(subsystem, "pci", 3)) + event->subsystem = UEV_SUBSYSTEM_PCI; + if (!strncmp(action, "add", 3)) + event->type = RTE_EAL_DEV_EVENT_ADD; + if (!strncmp(action, "remove", 6)) + event->type = RTE_EAL_DEV_EVENT_REMOVE; + event->devname = pci_slot_name; +} + +static int +dev_uev_receive(int fd, struct rte_eal_uevent *uevent) +{ + int ret; + char buf[RTE_EAL_UEV_MSG_LEN]; + + memset(uevent, 0, sizeof(struct rte_eal_uevent)); + memset(buf, 0, RTE_EAL_UEV_MSG_LEN); + + ret = recv(fd, buf, RTE_EAL_UEV_MSG_LEN - 1, 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); + + return 0; +} + +static int +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++) { + /** + * check device uevent from kernel side, no need to check + * uevent from udev. + */ + if ((dev_uev_receive(events[i].data.fd, &uevent)) || + (uevent.group == UEV_MONITOR_UDEV)) + return 0; + + /* default handle all pci devcie when is being hot plug */ + if (uevent.subsystem == UEV_SUBSYSTEM_PCI) { + bus = rte_bus_find_by_name("pci"); + dev = rte_bus_find_device(bus, uevent.devname); + if (uevent.type == RTE_EAL_DEV_EVENT_REMOVE) { + + if ((!dev) || dev->state ==
DEVICE_UNDEFINED)lib/librte_eal/linuxapp/eal/eal_dev.c new file +8
-0+return 0 ; + dev->state =DEVICE_FAULT ; + +/** +* remap the resource to be fake +* before user's removal processing +*/ + ret = bus->remap_device (dev);
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 233
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +2
-0+if (!ret) +return(_rte_dev_callback_process(dev,
lib/librte_eal/linuxapp/eal/eal_dev.c new file +2
-0+RTE_EAL_DEV_EVENT_REMOVE , + NULL, NULL));What is the reason to keep this device in EAL device list after the removal?
I suggest to remove it (driver remove, bus remove and EAL remove) after the callbacks running. By this way EAL can initiate all device removals.
it will do device removal from the device list by the eal device detach function in the call backs running. does it fulfill your concerns.
Quoted 346 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 252
Quoted 11 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +1
-0+ }else if (uevent.type ==RTE_EAL_DEV_EVENT_ADD ){
lib/librte_eal/linuxapp/eal/eal_dev.c new file +9
-0+if (dev ==NULL ) { +/** +* bind the driver to the device +* before user's add processing +*/ + bus->bind_driver ( + uevent.devname, +"igb_uio" ); +Similar comments here:
EAL can initiate all device probe operations by adding the device and probing it here before the callback running. Then, also the device pointer can be passed to the callbacks.Quoted 86 lines
return(_rte_dev_callback_process(NULL,
lib/librte_eal/linuxapp/eal/eal_dev.c new file +80
-0+RTE_EAL_DEV_EVENT_ADD , + uevent.devname, NULL)); + } + } + } + } +return 0 ; +} + +/** +* It builds/rebuilds up the epoll file descriptor with all the +* file descriptors being waited on. Then handles the interrupts. +* +* @param arg +* pointer. (unused) +* +* @return +* never return; +*/ +static __attribute__((noreturn))void * +dev_uev_monitoring(__rte_unused void *arg) +{ +struct sigaction act; +sigset_t mask; +int netlink_fd; +struct epoll_event ep_kernel; +int fd_ep; + + udev_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" ); + goto out; + } + + netlink_fd =dev_monitor_fd_new (); + +if (dev_monitor_enable (netlink_fd) <0 ) { +RTE_LOG (ERR ,EAL ,"error subscribing to kernel events\n" ); + goto out; + } + +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 (!udev_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 ) { +if (errno !=EINTR ) + RTE_LOG(ERR, EAL, "error processing uevent"
lib/librte_eal/linuxapp/eal/eal_dev.c new file +4
-0+ "message: %m\n"); + } + } +out:lib/librte_eal/linuxapp/eal/eal_dev.c line 337
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+if (fd_ep >=0 ) +close (fd_ep); +if (netlink_fd >=0 ) +close (netlink_fd); +rte_panic ("uev monitoring fail\n" ); +} + +int +rte_dev_monitor_start (void ) +{Maybe add option to run it also by new EAL command line parameter?
lib/librte_eal/linuxapp/eal/eal_dev.c line 346
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +9
-0+int ret; + +if (!no_request_thread) +return 0 ; + no_request_thread = false; + +/* create the host thread to wait/handle the uevent from kernel */ + ret =pthread_create (&uev_monitor_thread,NULL , + dev_uev_monitoring,NULL );What is the reason to open new thread for hotplug?
Why not to use the current dpdk host thread by the alarm mechanism?Quoted 221 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+return ret; +} + +int +rte_dev_monitor_stop (void ) +{ + udev_exit = true; + no_request_thread = true; +return 0 ; +}lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +21
-0@@ -0,0 +1,106 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +38
-0+ +#ifndef _RTE_DEV_H_ +#error "don't include this file directly, please include generic <rte_dev.h>" +#endif + +#ifndef _RTE_LINUXAPP_DEV_H_ +#define _RTE_LINUXAPP_DEV_H_ + +#include <stdio.h> + +#include <rte_dev.h> + +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum uev_subsystem { +UEV_SUBSYSTEM_UIO , +UEV_SUBSYSTEM_VFIO , +UEV_SUBSYSTEM_PCI , +UEV_SUBSYSTEM_MAX +}; + +enum uev_monitor_netlink_group { +UEV_MONITOR_KERNEL , +UEV_MONITOR_UDEV , +}; + +/** +* The device event type. +*/ +enum rte_eal_dev_event_type { +RTE_EAL_DEV_EVENT_UNKNOWN ,/**< unknown event type */ +RTE_EAL_DEV_EVENT_ADD ,/**< device adding event */ +RTE_EAL_DEV_EVENT_REMOVE , +/**< device removing event */ +RTE_EAL_DEV_EVENT_CHANGE , +/**< device status change event */ +RTE_EAL_DEV_EVENT_MOVE ,/**< device sys path move event */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +3
-0+RTE_EAL_DEV_EVENT_ONLINE ,/**< device online event */ +RTE_EAL_DEV_EVENT_OFFLINE ,/**< device offline event */ +RTE_EAL_DEV_EVENT_MAX /**< max value of this enum */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +7
-0+}; + +struct rte_eal_uevent { +enum rte_eal_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +enum uev_monitor_netlink_group group;/**< device netlink group */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +26
-0+}; + +/** +* Start the device uevent monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int +rte_dev_monitor_start (void ); + +/** +* Stop the device uevent monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ + +int +rte_dev_monitor_stop (void ); + +#endif /* _RTE_LINUXAPP_DEV_H_ */ 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
-1@@ -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
--
2.7.4
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
In reply to Guo, JiaHi Guo
I answered for the 2 threads here.
From: Guo, Jia, Monday, January 8, 2018 7:27 AM
Quoted 36 lines · Matan Azrad
Quoted 3 lines
Hi Jeff
Maybe I'm touching in previous discussions but please see some
comments\questions.
Quoted 4 lines
From: Jeff Guo:
Quoted 2 lines
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object hot plug monitoring, so user could use
these
Quoted 1 line
Quoted 1 line
APIs to monitor and read out the device status info that sent from the
kernel
Quoted 24 lines
Quoted 24 lines
side, then corresponding to handle it, such as detach or attach the device, and even benefit to use it to do smoothly fail safe work.
1) About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device, adddevice_statein struct ofrte_device, to identify the device state machine.
b: add enum ofrte_eal_dev_event_typeand struct ofrte_eal_uevent.
c: add below API in rte eal device common layer.
rte_eal_dev_monitor_enable
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_monitor_start
rte_dev_monitor_stop2) About failure handler, use pci uio for example,
addpci_remap_devicein bus layer and below function to process it:
rte_pci_remap_device
pci_uio_remap_resource
pci_map_private_resource
addrte_pci_dev_bind_driverto bind pci device with explicit driver.Signed-off-by Jeff Guo <[email protected]>
<snip>
Quoted 11 lines
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 311
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +4
-0+ user_cb->cb_arg = cb_arg; + user_cb->event = event; +if (event ==RTE_EAL_DEV_EVENT_ADD ) + dev_add_cb = user_cb;Only one dpdk entity can register to ADD callback?
I suggest to add option to register all devices maybe by using dummy
device which will include all the "
ALL_DEVICES" callbacks per event.Quoted 1 line
All means past, present and future devices, by this way 1 callback can be
called for all the devices and more than one dpdk entity could register to an ADD\NEW event.
Quoted 7 lines
Quoted 3 lines
What's about NEW instead of ADD?
I also suggest to add the device pointer as a parameter to the
callback(which will be managed by EAL).
if you talk aboutdev_add_cb, the add means device add not cb add, if you talk about dev event type, the ADD type is consistent with the type form kernel side, anyway could be find a better.
I'm talking about next:
1. dev_add_cb can hold only 1 callback, why? Can't 2 callbacks to be registered to RTE_EAL_DEV_EVENT_ADD event? (actually there is memory leak in this case)
2. Suggestion to register same callback to "all" devices by 1 call.
3. Suggestion to add parameter for the callback functions - the device pointer.
4. Suggestion to change name from RTE_EAL_DEV_EVENT_ADD to RTE_EAL_DEV_EVENT_NEW.
5. Clue how to implement 1,2 by dummy device.
Quoted 9 lines
but for 1 callback for all device, it is make sense , i will think about that.
Quoted 8 lines
Quoted 8 lines
(quoted diff) +2
-0+ else + TAILQ_INSERT_TAIL(&(device->uev_cbs), user_cb,next);
lib/librte_eal/common/eal_common_dev.c +5
-0+ } + +rte_spinlock_unlock (&rte_dev_cb_lock); +return 0 ; +}
<snip>
Quoted 21 lines
Quoted 13 lines
Quoted 13 lines
lib/librte_eal/common/eal_common_dev.c +13
-0+int +_rte_dev_callback_process (struct rte_device *device, +enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param) +{ +struct rte_eal_dev_callback dev_cb; +struct rte_eal_dev_callback *cb_lst; +int rc =0 ; + +rte_spinlock_lock (&rte_dev_cb_lock); +if (event ==RTE_EAL_DEV_EVENT_ADD ) { +if (cb_arg !=NULL ) + dev_add_cb->cb_arg = cb_arg;Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 381
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+ +if (ret_param !=NULL ) + dev_add_cb->ret_param = ret_param; + +rte_spinlock_unlock (&rte_dev_cb_lock);Can't someone free it when it running?
I suggest to keep the lock locked.
Callbacks are not allowed to use this mechanism to prevent deadlock.
Quoted 1 line
seems it would bring some deadlock here, let's check it more.
A deadlock should occur only when a callback tries to use this mechanism - I think it is OK, you just need to document it for the user.
Quoted 26 lines
Quoted 17 lines
Quoted 6 lines
(quoted diff) +2
-0+ rc = dev_add_cb->cb_fn(dev_add_cb->event, + dev_add_cb->cb_arg, dev_add_cb-Quoted 1 line
ret_param);lib/librte_eal/common/eal_common_dev.c +3
-0+rte_spinlock_lock (&rte_dev_cb_lock); + }else { + TAILQ_FOREACH(cb_lst, &(device->uev_cbs), next) {lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 396
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (cb_lst->cb_fn ==NULL || cb_lst->event != event) +continue ; + dev_cb = *cb_lst; + cb_lst->active =1 ; +if (cb_arg !=NULL ) + dev_cb.cb_arg = cb_arg; +if (ret_param !=NULL ) + dev_cb.ret_param = ret_param; + +rte_spinlock_unlock (&rte_dev_cb_lock);The current active flag doesn't do it thread safe here, I suggest to keep the
lock locked.
Quoted 8 lines
Scenario:
1. Thread A see active = 0 in unregister function.
2. Context switch.
3. Thread B start the callback.
4. Context switch.
5. Thread A free it.
6. Context switch.
7. Seg fault in Thread B.
Quoted 1 line
the same as above.
The same as above, and I think the active flag doesn't solve the race and you must solve it for the both cases. I suggest just to keep the lock locked and document the optional deadlock by the callback code.
<snip>
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +6
-0+ rc = dev_cb.cb_fn (dev_cb.event, + dev_cb.cb_arg, dev_cb.ret_param); +rte_spinlock_lock (&rte_dev_cb_lock); + cb_lst->active =0 ; + } + }Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 233
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+rte_spinlock_unlock (&rte_dev_cb_lock); +return rc; +}return(_rte_dev_callback_process(dev,
lib/librte_eal/linuxapp/eal/eal_dev.c new file +2
-0+RTE_EAL_DEV_EVENT_REMOVE , + NULL, NULL));What is the reason to keep this device in EAL device list after the removal? I suggest to remove it (driver remove, bus remove and EAL remove) after
Quoted 3 lines
the callbacks running.
Quoted 1 line
By this way EAL can initiate all device removals.
agree, device should be remove from the eal device list after the removal.
I suggest using rte_eal_hotplug_remove().
<Bring from the second thread>
Quoted 2 lines
it will do device removal from the device list by the eal device detach function in the call backs running. does it fulfill your concerns.
I mean the removal\probe should be initiated by the EAL and not by the users callbacks.
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +1
-0+ } else if (uevent.type == RTE_EAL_DEV_EVENT_ADD){
lib/librte_eal/linuxapp/eal/eal_dev.c new file +3
-0+if (dev ==NULL ) { +/** +* bind the driver to the device Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 252
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +6
-0+* before user's add processing +*/ + bus->bind_driver ( + uevent.devname, +"igb_uio" ); +Similar comments here:
EAL can initiate all device probe operations by adding the device and
Quoted 4 lines
probing it here before the callback running.
Quoted 1 line
Then, also the device pointer can be passed to the callbacks.
pass a device pointer could be bring some more change, let's think about more.
Yes, I know, it will help to the user especially in ADD(NEW) and REMOVE events.
Here you can use rte_eal_hotplug_add().
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
return(_rte_dev_callback_process(NULL,
lib/librte_eal/linuxapp/eal/eal_dev.c new file +8
-0+RTE_EAL_DEV_EVENT_ADD , + uevent.devname, NULL)); + } + } + } + } +return 0 ; +}
<snip>
Quoted 9 lines
Quoted 4 lines
lib/librte_eal/bsdapp/eal/eal_dev.c line 56
Quoted 3 lines
lib/librte_eal/bsdapp/eal/eal_dev.c new file +3
-0+int +rte_dev_monitor_start (void ) +{Maybe add option to run it also by new EAL command line parameter?
good idea.
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 341
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +4
-0+int ret; + +if (!no_request_thread) +return 0 ;
Look, also here there is race, no_request_thread doesn't solve it.
Maybe the EAL parameter should be the only way to run it(just don't expose this API), I think the default should be TRUE.
Quoted 9 lines
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 346
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +5
-0+ no_request_thread = false; + +/* create the host thread to wait/handle the uevent from kernel */ + ret =pthread_create (&uev_monitor_thread,NULL , + dev_uev_monitoring,NULL );What is the reason to open new thread for hotplug?
Why not to use the current dpdk host thread by the alarm mechanism?appropriate if you could talk about what you mean the disadvantage of new thread here and the advantage of alarm mechanism at the case?
One more thread can complicate things - the user will need to synchronize his alarm\interrupt callbacks code(host thread) with his hotplug callbacks code(hotplug thread).
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+return ret; +} + +int +rte_dev_monitor_stop (void ) +{ + udev_exit = true; + no_request_thread = true; +return 0 ; +}
<snip>
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
In reply to Jeff GuoHi Jeff,
I am surprised that there is not a lot of review of these very important patches. Maybe it is not easy to review. Let's try to progress in the following days.
This patch is really too big with a lot of concepts spread in separate files, so it is difficult to properly review. Please, try to split in several patches, bringing only one concept per patch.
At first, you can introduce the new events and the callback API. The second patch (and the most important one) would be to bring the uevent parsing for Linux (and void implementation for BSD). Then you can add and explain some patches around PCI mapping.
At last there is the kernel binding effort - this one will probably be ignored for 18.02, because it is another huge topic. Without bothering with kernel binding, we can at least remove a device, get a notification, and eventually re-add it. It is a good first step. Anyway your testpmd patch tests exactly this scenario (totally new devices are not seen).
More comments below:
03/01/2018 02:42, Jeff Guo:
lib/librte_eal/bsdapp/eal/eal_dev.c line 7
Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal_dev.c new file +7
-0@@ -0,0 +1,64 @@ +/*- +* Copyright(c) 2010-2017 Intel Corporation. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met:
Please check how Intel Copyright and BSD license is newly formatted with SPDX tag.
Quoted 4 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +2
-0+enum rte_eal_dev_event_type { +RTE_EAL_DEV_EVENT_UNKNOWN ,/**< unknown event type */
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h line 74
Quoted 10 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +10
-0+RTE_EAL_DEV_EVENT_ADD ,/**< device adding event */ +RTE_EAL_DEV_EVENT_REMOVE , +/**< device removing event */ +RTE_EAL_DEV_EVENT_CHANGE , +/**< device status change event */ +RTE_EAL_DEV_EVENT_MOVE ,/**< device sys path move event */ +RTE_EAL_DEV_EVENT_ONLINE ,/**< device online event */ +RTE_EAL_DEV_EVENT_OFFLINE ,/**< device offline event */ + RTE_EAL_DEV_EVENT_MAX /**< max value of this enum */ +};
The comments are not useful.
Please better explain what is change, move, online, etc.
The shorter prefix RTE_DEV is preferred over RTE_EAL_DEV.
This file is full of definitions which must be common, not specific to BSD or Linux. Please move it.
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h
Quoted 4 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +4
-0+int +_rte_dev_callback_process (struct rte_device *device, +enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param)
cb_arg must be an opaque parameter which is registered with the callback and passed later. No need as parameter of this function.
ret_param is not needed at all. The kernel event will be just translated as rte_eal_dev_event_type (rte_dev_event after rename).
Quoted 18 lines
lib/librte_eal/common/include/rte_bus.h +15
-0/** +* Device iterator to find a device on a bus. +* +* This function returns an rte_device if one of those held by the bus +* matches the data passed as parameter. +* +* If the comparison function returns zero this function should stop iterating +* over any more devices. To continue a search the device of a previous search +* can be passed via the start parameter. +* +* @param cmp +* the device name comparison function. +* +* @param data +* Data to compare each device against. +*
lib/librte_eal/common/include/rte_bus.h typedef struct rte_device * · line 149
Quoted 10 lines
lib/librte_eal/common/include/rte_bus.h +10
-0+* @param start +* starting point for the iteration +* +* @return +* The first device matching the data, NULL if none exists. +*/ +typedef struct rte_device * +(*rte_bus_find_device_by_name_t )(const struct rte_device *start, +rte_dev_cmp_name_t cmp, +const void *data);
Why is it needed? There is already rte_bus_find_device_t.
lib/librte_eal/common/include/rte_bus.h typedef int (*rte_bus_unplug_t)(struct rte_device *dev); · line 210
Quoted 13 lines
lib/librte_eal/common/include/rte_bus.h +13
-0+/** +* 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. +* +* @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);
You need to better explain why this remap op is needed, and when it is called exactly?
Quoted 4 lines
lib/librte_eal/common/include/rte_bus.h +0
-0@@ -206,9 +265,13 @@ struct rte_bus {rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ rte_bus_find_device_t find_device;/**< Find a device on the bus */
lib/librte_eal/common/include/rte_bus.h struct rte_bus { · line 277
Quoted 10 lines
lib/librte_eal/common/include/rte_bus.h +4
-0+rte_bus_find_device_by_name_t find_device_by_name; +/**< Find a device on the 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 */ +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 */ };
Every new op must be introduced in a separate patch (if not completely removed).
lib/librte_eal/common/include/rte_dev.h struct rte_driver { · line 174
Quoted 8 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum device_state { +DEVICE_UNDEFINED , +DEVICE_FAULT , +DEVICE_PARSED , +DEVICE_PROBED , +};
These constants must prefixed with RTE_
and documented with doxygen please.
Quoted 2 lines
+/**
+ * It enable the device event monitoring for a specific event.
This comment must be reworded.
Quoted 2 lines
+ *
+ * @param none
useless
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 326
Quoted 6 lines
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */lib/librte_eal/common/include/rte_dev.h +2
-0+int +rte_eal_dev_monitor_enable (void );
I suggest to drop this function which is just calling rte_dev_monitor_start.
lib/librte_eal/linuxapp/eal/eal_alarm.c rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) · line 268
Quoted 12 lines
lib/librte_eal/linuxapp/eal/eal_alarm.c +4
-0@@ -259,6 +260,10 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) } ap_prev = ap; } + + ret |=rte_intr_callback_unregister (&intr_handle, + eal_alarm_callback,NULL ); +rte_spinlock_unlock (&alarm_list_lk); }while (executing !=0 );
Looks to be unrelated.
If it is a fix, please do a separate patch.
lib/librte_eal/linuxapp/eal/eal_dev.c
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +2
-0+int +rte_dev_monitor_start (void )
What about adding "event" in the name of this function?
rte_dev_event_monitor_start
lib/librte_eal/linuxapp/eal/eal_dev.c line 348
Quoted 12 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +12
-0+{ +int ret; + +if (!no_request_thread) +return 0 ; + no_request_thread = false; + +/* create the host thread to wait/handle the uevent from kernel */ + ret =pthread_create (&uev_monitor_thread,NULL , + dev_uev_monitoring,NULL ); +return ret; +}
I think you should use rte_service for thread management.
lib/librte_eal/linuxapp/igb_uio/igb_uio.c igbuio_pci_release(struct uio_info *info, struct inode *inode) · line 361
Quoted 11 lines
lib/librte_eal/linuxapp/igb_uio/igb_uio.c +5
-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 ; + }
This looks to be unrelated. Separate patch please.
End of first pass review. There are some basic requirements that other maintainers (especially at Intel) could have reviewed earlier. Let's try to improve it quickly for 18.02, thanks.
If we are short in time, we should at least focus on adding the events/callback API and the Linux events implementation.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
Quoted 16 lines · Thomas Monjalon
Hi Jeff,
I am surprised that there is not a lot of review of these very important patches. Maybe it is not easy to review. Let's try to progress in the following days.
This patch is really too big with a lot of concepts spread in separate files, so it is difficult to properly review. Please, try to split in several patches, bringing only one concept per patch.
At first, you can introduce the new events and the callback API. The second patch (and the most important one) would be to bring the uevent parsing for Linux (and void implementation for BSD). Then you can add and explain some patches around PCI mapping.
Quoted 6 lines
At last there is the kernel binding effort - this one will probably be ignored for 18.02, because it is another huge topic. Without bothering with kernel binding, we can at least remove a device, get a notification, and eventually re-add it. It is a good first step. Anyway your testpmd patch tests exactly this scenario (totally new devices are not seen).
i will separate it for you all to benefit for review. for kernel binding, i just let it automatically compare with the first time manually binding, and it is the part of he hot plug flow. so i suggest to review more about that if it is not side effect and workable, beg for keep on.
Quoted 16 lines
More comments below:
03/01/2018 02:42, Jeff Guo:
lib/librte_eal/bsdapp/eal/eal_dev.c line 7
Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal_dev.c new file +7
-0@@ -0,0 +1,64 @@ +/*- +* Copyright(c) 2010-2017 Intel Corporation. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: Please check how Intel Copyright and BSD license is newly formatted with SPDX tag.
got it.
Quoted 17 lines
Quoted 4 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +2
-0+enum rte_eal_dev_event_type { +RTE_EAL_DEV_EVENT_UNKNOWN ,/**< unknown event type */ lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h line 74
Quoted 10 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +10
-0+RTE_EAL_DEV_EVENT_ADD ,/**< device adding event */ +RTE_EAL_DEV_EVENT_REMOVE , +/**< device removing event */ +RTE_EAL_DEV_EVENT_CHANGE , +/**< device status change event */ +RTE_EAL_DEV_EVENT_MOVE ,/**< device sys path move event */ +RTE_EAL_DEV_EVENT_ONLINE ,/**< device online event */ +RTE_EAL_DEV_EVENT_OFFLINE ,/**< device offline event */ + RTE_EAL_DEV_EVENT_MAX /**< max value of this enum */ +};The comments are not useful.
Please better explain what is change, move, online, etc.
Quoted 4 lines
The shorter prefix
RTE_DEVis preferred overRTE_EAL_DEV.This file is full of definitions which must be common, not specific to BSD or Linux. Please move it.
will move it to the better place.
Quoted 9 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h
Quoted 4 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +4
-0+int +_rte_dev_callback_process (struct rte_device *device, +enum rte_eal_dev_event_type event, +void *cb_arg,void *ret_param)
cb_argmust be an opaque parameter which is registered with the callback and passed later. No need as parameter of this function.
ret_paramis not needed at all. The kernel event will be just translated asrte_eal_dev_event_type(rte_dev_eventafter rename).
suggest hold one to let new param, such as device info, add by ret_param, so cb_arg have set when register and no use anymore, delete it.
Quoted 21 lines
Quoted 21 lines
lib/librte_eal/common/include/rte_bus.h +18
-0/** +* Device iterator to find a device on a bus. +* +* This function returns an rte_device if one of those held by the bus +* matches the data passed as parameter. +* +* If the comparison function returns zero this function should stop iterating +* over any more devices. To continue a search the device of a previous search +* can be passed via the start parameter. +* +* @param cmp +* the device name comparison function. +* +* @param data +* Data to compare each device against. +* +* @param start +* starting point for the iteration +*
Quoted 8 lines
lib/librte_eal/common/include/rte_bus.h typedef struct rte_device * · line 149
Quoted 7 lines
+ * @return
+ * The first device matching the data, NULL if none exists.
+ */lib/librte_eal/common/include/rte_bus.h +4
-0+typedef struct rte_device * +(*rte_bus_find_device_by_name_t )(const struct rte_device *start, +rte_dev_cmp_name_t cmp, +const void *data);Why is it needed? There is already
rte_bus_find_device_t.
because the rte_bus_find_device_t just find a device structure in the device list, but here need to find a device structure by device name which come from uevent info.
Quoted 7 lines
Quoted 7 lines
+/**
+ * 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.
+ *
+ * @param dev
+ * Device pointer that was returned by a previous call tofind_device.
Quoted 8 lines
Quoted 6 lines
+ *
+ * @return
+ * 0 on success.
+ * !0 on error.
+ */
+typedef int (*rte_bus_remap_device_t)(structrte_device*dev);You need to better explain why this remap op is needed, and when it is called exactly?
sure.
Quoted 8 lines
Quoted 8 lines
lib/librte_eal/common/include/rte_bus.h +2
-0@@ -206,9 +265,13 @@ struct rte_bus {rte_bus_scan_t scan;/**< Scan for devices attached to bus */ rte_bus_probe_t probe;/**< Probe devices on bus */ rte_bus_find_device_t find_device;/**< Find a device on the bus */ +rte_bus_find_device_by_name_t find_device_by_name; +/**< Find a device on the bus */ rte_bus_plug_t plug;/**< Probe single device for drivers */ rte_bus_unplug_t unplug;/**< Remove single device from driver */
Quoted 8 lines
lib/librte_eal/common/include/rte_bus.h struct rte_bus { · line 277
Quoted 6 lines
lib/librte_eal/common/include/rte_bus.h +2
-0rte_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 */ };Every new op must be introduced in a separate patch (if not completely removed).
make sense.
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h struct rte_driver { · line 174
Quoted 8 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum device_state { +DEVICE_UNDEFINED , +DEVICE_FAULT , +DEVICE_PARSED , +DEVICE_PROBED , +};These constants must prefixed with
RTE_
and documented with doxygen please.
got it.
Quoted 3 lines
Quoted 2 lines
+/**
+ * It enable the device event monitoring for a specific event.This comment must be reworded.
ok.
Quoted 3 lines
Quoted 2 lines
+ *
+ * @param noneuseless
thanks.
Quoted 7 lines
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 326
Quoted 6 lines
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */lib/librte_eal/common/include/rte_dev.h +2
-0+int +rte_eal_dev_monitor_enable (void );I suggest to drop this function which is just calling
rte_dev_monitor_start.
more discuss, i suggest keep on it , let rte_dev_monitor_start separately stay on the platform code and let user commonly call rte_eal_dev_monitor_enable.
Quoted 6 lines
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_alarm.c +0
-0@@ -259,6 +260,10 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) } ap_prev = ap; }
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_alarm.c rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) · line 268
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_alarm.c +4
-0+ + ret |=rte_intr_callback_unregister (&intr_handle, + eal_alarm_callback,NULL ); +rte_spinlock_unlock (&alarm_list_lk); }while (executing !=0 );Looks to be unrelated.
If it is a fix, please do a separate patch.
ok.
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +2
-0+int +rte_dev_monitor_start (void )What about adding "event" in the name of this function?
rte_dev_event_monitor_start
dev monitor sounds shock, agree.
Quoted 5 lines
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +5
-0+{ +int ret; + +if (!no_request_thread) +return 0 ;
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 348
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c new file +7
-0+ no_request_thread = false; + +/* create the host thread to wait/handle the uevent from kernel */ + ret =pthread_create (&uev_monitor_thread,NULL , + dev_uev_monitoring,NULL ); +return ret; +}I think you should use
rte_servicefor thread management.
thanks for your info, such a good mechanism to use that i even not know that before. i will study and use it.
Quoted 6 lines
Quoted 6 lines
lib/librte_eal/linuxapp/igb_uio/igb_uio.c +0
-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;
Quoted 7 lines
lib/librte_eal/linuxapp/igb_uio/igb_uio.c igbuio_pci_release(struct uio_info *info, struct inode *inode) · line 361
Quoted 5 lines
lib/librte_eal/linuxapp/igb_uio/igb_uio.c +5
-0+/* 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 ; + }This looks to be unrelated. Separate patch please.
got it.
Quoted 5 lines
End of first pass review. There are some basic requirements that other maintainers (especially at Intel) could have reviewed earlier. Let's try to improve it quickly for 18.02, thanks.
If we are short in time, we should at least focus on adding the events/callback API and the Linux events implementation.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
Hi Jeff,
The following will not work for Mellanox devices (see inline)
"i will separate it for you all to benefit for review. for kernel binding, i just let it automatically compare with the first time manually binding, and it is the part of he hot plug flow. so i suggest to review more about that if it is not side effect and workable, beg for keep on. " Also please note the following compilation warnings,
... lib/librte_eal/linuxapp/eal/eal_dev.c: In function 'dev_uev_monitoring':
.. lib/librte_eal/linuxapp/eal/eal_dev.c:331:8: error: 'netlink_fd' may be used uninitialized in this function [-Werror=maybe-uninit
... drivers/bus/pci/linux/pci.c: In function 'rte_pci_dev_bind_driver':
... /drivers/bus/pci/linux/pci.c:940:7: error: 'drv_bind_fd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
You are releasing uninitialized FDs in the error path of both routines.
Moti H.
From: Guo, Jia [mailto:[email protected]]
Sent: Tuesday, January 9, 2018 10:26 AM
To: Thomas Monjalon <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Mordechay Haimovsky <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v7 1/2] eal: add uevent monitor for hot plug
On 1/9/2018 8:39 AM, Thomas Monjalon wrote:
Hi Jeff,
I am surprised that there is not a lot of review of these very
important patches. Maybe it is not easy to review.
Let's try to progress in the following days.
This patch is really too big with a lot of concepts spread
in separate files, so it is difficult to properly review.
Please, try to split in several patches, bringing only one concept
per patch.
At first, you can introduce the new events and the callback API.
The second patch (and the most important one) would be to bring
the uevent parsing for Linux (and void implementation for BSD).
Then you can add and explain some patches around PCI mapping.
At last there is the kernel binding effort - this one will probably
be ignored for 18.02, because it is another huge topic.
Without bothering with kernel binding, we can at least remove a device,
get a notification, and eventually re-add it. It is a good first step.
Anyway your testpmd patch tests exactly this scenario (totally new
devices are not seen).
i will separate it for you all to benefit for review. for kernel binding, i just let it automatically compare with the first time manually binding, and it is the part of he hot plug flow. so i suggest to review more about that if it is not side effect and workable, beg for keep on. This will not work for Mellanox which uses several drivers and services in order to map the device and device queues to user space.
For example, the mlx4 PMD (PMD for ConnectX-3 devices) requires that mlx4_core mlx4_en and mlx4_ib drivers to be loaded, and
for RDM -core user-space libraries and daemons to be loaded.
More comments below:
03/01/2018 02:42, Jeff Guo:
--- /dev/null
+++ b/lib/librte_eal/bsdapp/eal/eal_dev.c
@@ -0,0 +1,64 @@
+/*-
+ * Copyright(c) 2010-2017 Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
Please check how Intel Copyright and BSD license is newly formatted
with SPDX tag.
got it.
--- /dev/null
+++ b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h
+enum rte_eal_dev_event_type {
+ RTE_EAL_DEV_EVENT_UNKNOWN, /**< unknown event type */
+ RTE_EAL_DEV_EVENT_ADD, /**< device adding event */
+ RTE_EAL_DEV_EVENT_REMOVE,
+ /**< device removing event */
+ RTE_EAL_DEV_EVENT_CHANGE,
+ /**< device status change event */
+ RTE_EAL_DEV_EVENT_MOVE, /**< device sys path move event */
+ RTE_EAL_DEV_EVENT_ONLINE, /**< device online event */
+ RTE_EAL_DEV_EVENT_OFFLINE, /**< device offline event */
+ RTE_EAL_DEV_EVENT_MAX /**< max value of this enum */
+};
The comments are not useful.
Please better explain what is change, move, online, etc.
The shorter prefix RTE_DEV is preferred over RTE_EAL_DEV.
This file is full of definitions which must be common, not specific
to BSD or Linux. Please move it.
will move it to the better place.
+int
+_rte_dev_callback_process(struct rte_device *device,
+ enum rte_eal_dev_event_type event,
+ void *cb_arg, void *ret_param)
cb_arg must be an opaque parameter which is registered with the
callback and passed later. No need as parameter of this function.
ret_param is not needed at all. The kernel event will be just
translated as rte_eal_dev_event_type (rte_dev_event after rename).
suggest hold one to let new param, such as device info, add by ret_param, so cb_arg have set when register and no use anymore, delete it.
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
/**
+ * Device iterator to find a device on a bus.
+ *
+ * This function returns an rte_device if one of those held by the bus
+ * matches the data passed as parameter.
+ *
+ * If the comparison function returns zero this function should stop iterating
+ * over any more devices. To continue a search the device of a previous search
+ * can be passed via the start parameter.
+ *
+ * @param cmp
+ * the device name comparison function.
+ *
+ * @param data
+ * Data to compare each device against.
+ *
+ * @param start
+ * starting point for the iteration
+ *
+ * @return
+ * The first device matching the data, NULL if none exists.
+ */
+typedef struct rte_device *
+(*rte_bus_find_device_by_name_t)(const struct rte_device *start,
+ rte_dev_cmp_name_t cmp,
+ const void *data);
Why is it needed? There is already rte_bus_find_device_t.
because the rte_bus_find_device_t just find a device structure in the device list, but here need to find a device structure by device name which come from uevent info.
+/**
+ * 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.
+ *
+ * @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);
You need to better explain why this remap op is needed,
and when it is called exactly?
sure.
@@ -206,9 +265,13 @@ struct rte_bus {
rte_bus_scan_t scan; /**< Scan for devices attached to bus */
rte_bus_probe_t probe; /**< Probe devices on bus */
rte_bus_find_device_t find_device; /**< Find a device on the bus */
+ rte_bus_find_device_by_name_t find_device_by_name;
+ /**< Find a device on the 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 */
+ 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 */
};
Every new op must be introduced in a separate patch
(if not completely removed).
make sense.
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
+enum device_state {
+ DEVICE_UNDEFINED,
+ DEVICE_FAULT,
+ DEVICE_PARSED,
+ DEVICE_PROBED,
+};
These constants must prefixed with RTE_
and documented with doxygen please.
got it.
+/**
+ * It enable the device event monitoring for a specific event.
This comment must be reworded.
ok.
+ *
+ * @param none
useless
thanks.
+ * @return
+ * - On success, zero.
+ * - On failure, a negative value.
+ */
+int
+rte_eal_dev_monitor_enable(void);
I suggest to drop this function which is just calling rte_dev_monitor_start.
more discuss, i suggest keep on it , let rte_dev_monitor_start separately stay on the platform code and let user commonly call rte_eal_dev_monitor_enable.
--- a/lib/librte_eal/linuxapp/eal/eal_alarm.c
+++ b/lib/librte_eal/linuxapp/eal/eal_alarm.c
@@ -259,6 +260,10 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)
}
ap_prev = ap;
}+
+ ret |= rte_intr_callback_unregister(&intr_handle,
+ eal_alarm_callback, NULL);
+
rte_spinlock_unlock(&alarm_list_lk);
} while (executing != 0);
Looks to be unrelated.
If it is a fix, please do a separate patch.
ok.
--- /dev/null
+++ b/lib/librte_eal/linuxapp/eal/eal_dev.c
+int
+rte_dev_monitor_start(void)
What about adding "event" in the name of this function?
rte_dev_event_monitor_start
dev monitor sounds shock, agree.
+{
+ int ret;
+
+ if (!no_request_thread)
+ return 0;
+ no_request_thread = false;
+
+ /* create the host thread to wait/handle the uevent from kernel */
+ ret = pthread_create(&uev_monitor_thread, NULL,
+ dev_uev_monitoring, NULL);
+ return ret;
+}
I think you should use rte_service for thread management.
thanks for your info, such a good mechanism to use that i even not know that before. i will study and use it.
--- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
+++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
@@ -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;
+ }
This looks to be unrelated. Separate patch please.
got it.
End of first pass review. There are some basic requirements that other
maintainers (especially at Intel) could have reviewed earlier.
Let's try to improve it quickly for 18.02, thanks.
If we are short in time, we should at least focus on adding the
events/callback API and the Linux events implementation.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
09/01/2018 11:31, Mordechay Haimovsky:
Quoted 14 lines
From: Guo, Jia [mailto:[email protected]]
Quoted 8 lines · Thomas Monjalon
Quoted 6 lines
At last there is the kernel binding effort - this one will probably be ignored for 18.02, because it is another huge topic. Without bothering with kernel binding, we can at least remove a device, get a notification, and eventually re-add it. It is a good first step. Anyway your testpmd patch tests exactly this scenario (totally new devices are not seen).
Quoted 4 lines
i will separate it for you all to benefit for review. for kernel binding, i just let it automatically compare with the first time manually binding, and it is the part of he hot plug flow. so i suggest to review more about that if it is not side effect and workable, beg for keep on.
Quoted 5 lines
This will not work for Mellanox which uses several drivers and services in order to map the device and device queues to user space. For example, the mlx4 PMD (PMD for ConnectX-3 devices) requires that
mlx4_coremlx4_enandmlx4_ibdrivers to be loaded, and for RDM -core user-space libraries and daemons to be loaded.
Yes automatic binding is a feature which requires more work. It cannot be ready for 18.02.
v8 cover add uevent mechanism in eal framework
In reply to Jeff GuoSo 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: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 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: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_uio 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 (3):
eal: add uevent monitor for hot plug
igb_uio: fix device removal issuse for hotplug
app/testpmd: use uevent to monitor hotplug
app/test-pmd/testpmd.c | 178 ++++++++++ app/test-pmd/testpmd.h | 9 + drivers/bus/pci/bsd/pci.c | 30 ++ drivers/bus/pci/linux/pci.c | 87 +++++ drivers/bus/pci/pci_common.c | 43 +++ drivers/bus/pci/pci_common_uio.c | 28 ++ drivers/bus/pci/private.h | 12 + drivers/bus/pci/rte_bus_pci.h | 25 ++ drivers/bus/vdev/vdev.c | 36 ++ lib/librte_eal/bsdapp/eal/eal_dev.c | 37 ++ .../bsdapp/eal/include/exec-env/rte_dev.h | 39 +++ lib/librte_eal/common/eal_common_bus.c | 30 ++ lib/librte_eal/common/eal_common_dev.c | 160 +++++++++ lib/librte_eal/common/include/rte_bus.h | 71 ++++ lib/librte_eal/common/include/rte_dev.h | 128 +++++++ lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_dev.c | 375 +++++++++++++++++++++ .../linuxapp/eal/include/exec-env/rte_dev.h | 39 +++ lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 6 + lib/librte_pci/rte_pci.c | 20 ++ lib/librte_pci/rte_pci.h | 17 + 21 files changed, 1372 insertions(+), 1 deletion(-) 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
Signature · 1 line
2.7.4