Add hot plug event in rte eal interrupt and inplement it in i40e driver.
Subsystems (2)
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
In reply to Thomas MonjalonQuoted 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.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
So, how can separate the patch into more small patch, use stake or null implement in function. I think we should consider if it is a economic way now, if I could explain more detail in code for you all not very familiar the background? I have sent v8, please check, thanks all.
Best regards,
Jeff Guo
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, January 9, 2018 6:48 PM
To: Guo, Jia <[email protected]>
Cc: Mordechay Haimovsky <[email protected]>; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; Wu, Jingjing <[email protected]>; Zhang, Helin <[email protected]>; Van Haaren, Harry <[email protected]>
Subject: Re: [dpdk-dev] [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.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
09/01/2018 12:39, Guo, Jia:
Quoted 1 line
So, how can separate the patch into more small patch, use stake or null implement in function. I think we should consider if it is a economic way now, if I could explain more detail in code for you all not very familiar the background? I have sent v8, please check, thanks all.
The v8 is not split enough.
Please try to address all my comments.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
Your comments about split it totally make sense ,no doubt that, but my question is that if split api with the funcational , so the function part should be set null implement or stake. Any other good idea or tip for that.
Best regards,
Jeff Guo
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, January 9, 2018 7:45 PM
To: Guo, Jia <[email protected]>
Cc: Mordechay Haimovsky <[email protected]>; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; Wu, Jingjing <[email protected]>; Zhang, Helin <[email protected]>; Van Haaren, Harry <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v7 1/2] eal: add uevent monitor for hot plug
09/01/2018 12:39, Guo, Jia:
Quoted 1 line
So, how can separate the patch into more small patch, use stake or null implement in function. I think we should consider if it is a economic way now, if I could explain more detail in code for you all not very familiar the background? I have sent v8, please check, thanks all.
The v8 is not split enough.
Please try to address all my comments.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
Hi Jeff,
Quoted 2 lines · Jia
Your comments about split it totally make sense ,no doubt that, but my question is that if split api with the funcational , so the function part should be set null implement or stake. Any other good idea or tip for that.
Please avoid top-posting on the mailing list, it is confusing when reading a thread intertwined with inner-posted mails.
Regarding your issue, it is fine to propose a first skeleton API with bare implementations, then progressively use your new functions where relevant.
It is only necessary to ensure compilation is always possible between each patch. The API itself need not be usable, as long as the patch order remains coherent and meaningful for review.
Otherwise, sorry about not doing a review earlier, I didn't think I knew enough about uevent to provide useful comments. However after a quick reading I may be able to provide a few remarks.
I will wait for your split before doing so.
Quoted 16 lines
Best regards,
Jeff Guo-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, January 9, 2018 7:45 PM
To: Guo, Jia <[email protected]>
Cc: Mordechay Haimovsky <[email protected]>; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; Wu, Jingjing <[email protected]>; Zhang, Helin <[email protected]>; Van Haaren, Harry <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v7 1/2] eal: add uevent monitor for hot plug09/01/2018 12:39, Guo, Jia:
Quoted 1 line
So, how can separate the patch into more small patch, use stake or null implement in function. I think we should consider if it is a economic way now, if I could explain more detail in code for you all not very familiar the background? I have sent v8, please check, thanks all.
The v8 is not split enough.
Please try to address all my comments.
Signature · 2 lines
Gaëtan Rivet 6WIND
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
Quoted 16 lines · Gaëtan Rivet
Hi Jeff,
Quoted 2 lines · Jia
Your comments about split it totally make sense ,no doubt that, but my question is that if split api with the funcational , so the function part should be set null implement or stake. Any other good idea or tip for that.
Please avoid top-posting on the mailing list, it is confusing when reading a thread intertwined with inner-posted mails.
Regarding your issue, it is fine to propose a first skeleton API with bare implementations, then progressively use your new functions where relevant.
It is only necessary to ensure compilation is always possible between each patch. The API itself need not be usable, as long as the patch order remains coherent and meaningful for review.
Quoted 5 lines
Otherwise, sorry about not doing a review earlier, I didn't think I knew enough about uevent to provide useful comments. However after a quick reading I may be able to provide a few remarks.
I will wait for your split before doing so.
make sense, new patch set version have been sent, for you reference.
Quoted 15 lines
Quoted 15 lines
Best regards,
Jeff Guo-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, January 9, 2018 7:45 PM
To: Guo, Jia <[email protected]>
Cc: Mordechay Haimovsky <[email protected]>; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; Wu, Jingjing <[email protected]>; Zhang, Helin <[email protected]>; Van Haaren, Harry <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v7 1/2] eal: add uevent monitor for hot plug09/01/2018 12:39, Guo, Jia:
Quoted 1 line
So, how can separate the patch into more small patch, use stake or null implement in function. I think we should consider if it is a economic way now, if I could explain more detail in code for you all not very familiar the background? I have sent v8, please check, thanks all.
The v8 is not split enough.
Please try to address all my comments.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
In reply to Guo, Jia09/01/2018 13:08, Guo, Jia:
Quoted 1 line
Your comments about split it totally make sense ,no doubt that, but my question is that if split api with the funcational , so the function part should be set null implement or stake. Any other good idea or tip for that.
Yes when introducing the callback API first, there will be no implementation, so the callbacks are not called.
If needed you can have some empty functions.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
Quoted 5 lines · Thomas Monjalon
09/01/2018 13:08, Guo, Jia:
Quoted 1 line
Your comments about split it totally make sense ,no doubt that, but my question is that if split api with the funcational , so the function part should be set null implement or stake. Any other good idea or tip for that.
Yes when introducing the callback API first, there will be no implementation, so the callbacks are not called.
If needed you can have some empty functions.
i think we all want to make review more effective in any good way, so the v9 patch set have been sent, please check.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
In reply to Mordechay HaimovskyGot it, seems that would be more complex work to do later, still need to debugging the feature more to fulfill for more driver. Best regards,
Jeff Guo
From: Mordechay Haimovsky [mailto:[email protected]]
Sent: Tuesday, January 9, 2018 6:32 PM
To: Guo, Jia <[email protected]>; Thomas Monjalon <[email protected]>
Cc: [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; Wu, Jingjing <[email protected]>; Zhang, Helin <[email protected]>; Van Haaren, Harry <[email protected]>
Subject: RE: [dpdk-dev] [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]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; Mordechay Haimovsky <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[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
In reply to Guo, Jia09/01/2018 09:25, Guo, Jia:
Quoted 9 lines · Thomas Monjalon
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 367
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +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.
Quoted 5 lines
Quoted 2 lines
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, socb_arghave set when register and no use anymore, delete it.
Sorry I don't understand. Please rephrase.
Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
lib/librte_eal/common/include/rte_bus.h +19
-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 +* +* @return Quoted 8 lines
lib/librte_eal/common/include/rte_bus.h typedef struct rte_device * · line 149
Quoted 6 lines
+ * 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.
Quoted 3 lines
because the
rte_bus_find_device_tjust find a device structure in the device list, but here need to find a device structure by device name which come from uevent info.
I don't understand how it is different?
Looking at the code, it is a copy/paste except it is dedicated to name comparison.
You can remove rte_bus_find_device_by_name_t and provide a comparison function which looks at name.
Quoted 8 lines
Quoted 4 lines
lib/librte_eal/common/include/rte_bus.h
Quoted 2 lines
lib/librte_eal/common/include/rte_bus.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_startseparately stay on the platform code and let user commonly callrte_eal_dev_monitor_enable.
Then you may need a disable function.
It will end up to be like start/stop.
I think it is just redundant.
If kept, please rename it to rte_dev_event_monitor_enable.
Quoted 10 lines
Quoted 7 lines
lib/librte_eal/common/include/rte_bus.h
Quoted 5 lines
lib/librte_eal/common/include/rte_bus.h +5
-0+/* 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.
OK, good.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
Quoted 9 lines · Thomas Monjalon
09/01/2018 09:25, Guo, Jia:
Quoted 8 lines · Thomas Monjalon
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 367
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +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.
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
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, socb_arghave set when register and no use anymore, delete it.Sorry I don't understand. Please rephrase.
please see v8 part of it. i need ret_param to pass the device name by the call back to the user.
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
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.
Quoted 8 lines
Quoted 3 lines
because the
rte_bus_find_device_tjust find a device structure in the device list, but here need to find a device structure by device name which come from uevent info.I don't understand how it is different?
Looking at the code, it is a copy/paste except it is dedicated to name comparison.
You can removerte_bus_find_device_by_name_tand provide a comparison function which looks at name.
i mean that if the device have been remove and then insertion, the device have not construct when just got the device name from the uevent massage, so this case could i use the original find device function?
Quoted 21 lines
Quoted 6 lines
Quoted 3 lines
lib/librte_eal/common/include/rte_bus.h
Quoted 2 lines
lib/librte_eal/common/include/rte_bus.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_startseparately stay on the platform code and let user commonly callrte_eal_dev_monitor_enable.Then you may need a disable function.
It will end up to be like start/stop.
I think it is just redundant.If kept, please rename it to
rte_dev_event_monitor_enable.Quoted 8 lines
Quoted 6 lines
lib/librte_eal/common/include/rte_bus.h
Quoted 5 lines
lib/librte_eal/common/include/rte_bus.h +5
-0+/* 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.
OK, good.
Re: [PATCH v7 1/2] eal: add uevent monitor for hot plug
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
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_tjust 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 8 lines
Quoted 5 lines
I don't understand how it is different?
Looking at the code, it is a copy/paste except it is dedicated to name comparison.
You can removerte_bus_find_device_by_name_tand provide a comparison function which looks at name.i mean that if the device have been remove and then insertion, the device have not construct when just got the device name from the uevent massage, so this case could i use the original find device function?
The device won't be in the list if it is not yet scanned. Anyway your function checks the same list.
Let's stop this discussion for now and continue when the need for this function is better explained in a separate patch. You really need to introduce things one patch at a time and explain why you introduce them in the message of each patch. Thanks
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
v8 cover add uevent mechanism in eal framework
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.
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
PATCH v8 1/3 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_dev_evt_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.
---v8->v7:
a.use rte_service to replace pthread management.
b.fix defind issue and copyright issue
c.fix some lock issue
--- 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_pci/rte_pci.c | 20 ++ lib/librte_pci/rte_pci.h | 17 + 18 files changed, 1179 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/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 +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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 +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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> + +/** +* 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 +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 +160 -0
172 lines not on this page · raw message
lib/librte_eal/common/include/rte_bus.h +71 -0
98 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +128 -0
150 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_dev.c new file +375 -0
375 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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> + +/** +* 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_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 v8 2/3 igb_uio: fix device removal issuse for hotplug
In reply to Jeff Guowhen the hot plug out of the device, the uio resource have been invalid, so to avoid the system hung, no need to do the invalid operation in igb_uio pci release function.
--- lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 6 ++++++ 1 file changed, 6 insertions(+)
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);
Signature · 1 line
2.7.4
PATCH v8 3/3 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.
---v8->v7:
fix some defind 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_dev_event_type type, +void *param,void *ret_param); +static int eth_uevent_callback_register (portid_t pid); +static int in_hotplug_list (const char *dev_name); + +static int hotplug_list_add (const char *dev_name, +enum rte_dev_event_type event);/* * Check if all the ports are started.
@@ -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_dev_event_type dev_event_type; + +/* register the uevent callback */ + dev = &rte_eth_devices[pid]; +for (dev_event_type =RTE_DEV_EVENT_ADD ; + dev_event_type <RTE_DEV_EVENT_CHANGE ; + dev_event_type++) { + diag =rte_dev_callback_register (dev->device, dev_event_type, + eth_uevent_callback, + (void *)(intptr_t )pid); +if (diag) { +printf ("Failed to setup uevent callback for" +" device event %d\n" , + dev_event_type); +return -1 ; + } + } + +return 0 ; +} +void attach_port (char *identifier) {
@@ -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_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_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_dev_event_type event) +{ +struct hotplug_request *hp_request; + + hp_request =rte_zmalloc ("hoplug request" , +sizeof (*hp_request),0 ); +if (hp_request ==NULL ) { +fprintf (stderr,"%s can not alloc memory\n" , + __func__); +return -ENOMEM ; + } + + hp_request->dev_name = dev_name; + hp_request->event = event; + +TAILQ_INSERT_TAIL (&hp_list, hp_request, next); + +return 0 ; +} + +/* This function is used by the interrupt thread */ +static int +eth_uevent_callback (enum rte_dev_event_type type,void *arg, +void *ret_param) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; +static char *device_name; + +RTE_SET_USED (ret_param); + +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_uevent_callback, arg)) +fprintf (stderr,"Could not set up deferred " +"device removal\n" ); +break ; +case RTE_DEV_EVENT_ADD : + device_name =malloc (strlen ((const char *)ret_param) +1 ); +strcpy (device_name, ret_param); +if (rte_eal_alarm_set (500000 , + add_uevent_callback, device_name)) +fprintf (stderr,"Could not set up deferred " +"device add\n" ); +break ; +default : +break ; + } +return 0 ; +} + +static int set_tx_queue_stats_mapping_registers (portid_t port_id,struct rte_port *port) {uint16_t i;
@@ -2438,6 +2607,15 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +/* enable hot plug monitoring */ +TAILQ_INIT (&hp_list); +rte_dev_evt_monitor_enable (); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_REMOVE ); +eth_uevent_callback_register (port_id); + }if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );
app/test-pmd/testpmd.h +9 -0
@@ -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_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
v9 cover add uevent mechanism in eal framework
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 to detect all hotplug event for all driver,now the hotplug interrupt event is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring 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:v9->v8:
split the patch set into small and explicit patch
v8->v7:
1.use rte_service to replace pthread management.
2.fix defind issue and copyright issue
3.fix some lock issue
v7->v6:
1.modify vdev part according to the vdev rework 2.re-define and split the func into common and bus specific code 3.fix some incorrect issue.
4.fix the system hung after send packcet issue.
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug.
2.modify to manage event callback in each device.
3.fix some system hung issue when igb_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 (5):
eal: add uevent monitor api and callback func
eal: add uevent pass and process function app/testpmd: use uevent to monitor hotplug
pci_uio: add uevent hotplug failure handler in pci
pci: add driver auto bind for hot insertion
app/test-pmd/testpmd.c | 179 ++++++++++ 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 | 36 ++ .../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 | 150 +++++++++ lib/librte_eal/common/include/rte_bus.h | 71 ++++ lib/librte_eal/common/include/rte_dev.h | 119 +++++++ 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, 1353 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 v9 1/5 eal: add uevent monitor api and callback func
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_monitor_start
rte_dev_monitor_stop
---v9->v8:
split the patch set into small and explicit patch
--- lib/librte_eal/bsdapp/eal/eal_dev.c | 36 ++++ .../bsdapp/eal/include/exec-env/rte_dev.h | 39 ++++ lib/librte_eal/common/eal_common_dev.c | 150 ++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 98 +++++++++ lib/librte_eal/linuxapp/eal/Makefile | 3 +- lib/librte_eal/linuxapp/eal/eal_dev.c | 223 +++++++++++++++++++++ .../linuxapp/eal/include/exec-env/rte_dev.h | 39 ++++ 7 files changed, 587 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
lib/librte_eal/bsdapp/eal/eal_dev.c new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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 <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 +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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> + +/** +* 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_dev.c +150 -0
162 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +98 -0
114 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +2 -1
@@ -39,6 +39,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
@@ -92,7 +93,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 +223 -0
223 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/include/exec-env/rte_dev.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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> + +/** +* 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_ */
Signature · 1 line
2.7.4
Re: [PATCH V9 1/5] eal: add uevent monitor api and callback func
lib/librte_eal/linuxapp/eal/eal_dev.c line 44
Quoted 10 lines · On Wed, 10 Jan 2018 17:12:20 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c new file +10
-0+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 ) {
If you used a blocking socket, then epoll would not be necessary. There is one netlink socket for whole system, and the thread is only reading from one fd.
Re: [PATCH V9 1/5] eal: add uevent monitor api and callback func
In reply to Jeff GuoHi,
Thanks for splitting the patches.
I will review the first one today. Please see below.
10/01/2018 10:12, Jeff Guo:
lib/librte_eal/bsdapp/eal/eal_dev.c line 36
Quoted 13 lines
lib/librte_eal/bsdapp/eal/eal_dev.c new file +11
-0+int +rte_dev_monitor_start (void ) +{ +return -1 ; +} + +int +rte_dev_monitor_stop (void ) +{ +return -1 ; +}
You should add a log to show it is not supported.
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h line 7
Quoted 5 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +3
-0+#ifndef _RTE_DEV_H_ +#error "don't include this file directly, please include generic <rte_dev.h>" +#endif
Why creating different rte_dev.h for BSD and Linux? This is an API, it should be the same.
Quoted 26 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +22
-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 );
lib/librte_eal/common/eal_common_dev.c line 51
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +4
-0@@ -42,9 +42,32 @@#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 ;
Please rename to rte_dev_event_lock.
Let's use rte_dev_event_ prefix consistently.
lib/librte_eal/common/eal_common_dev.c line 59
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +6
-0+* 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 {
Rename to rte_dev_event?
lib/librte_eal/common/eal_common_dev.c line 61
Quoted 2 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+TAILQ_ENTRY (rte_eal_dev_callback) next;/**< Callbacks list */ +rte_eal_dev_cb_fn cb_fn;/**< Callback address */
Rename to rte_dev_event_callback?
lib/librte_eal/common/eal_common_dev.c line 62
Quoted 1 line
lib/librte_eal/common/eal_common_dev.c +1
-0+void *cb_arg;/**< Parameter for callback */
Comment should be about opaque context.
lib/librte_eal/common/eal_common_dev.c line 65
Quoted 3 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+void *ret_param;/**< Return parameter */ +enum rte_dev_event_type event;/**< device event type */ +uint32_t active;/**< Callback is executing */
Why active is needed?
lib/librte_eal/common/eal_common_dev.c line 69
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +4
-0+}; + +/* A genaral callback for all new devices be added onto the bus */ +static struct rte_eal_dev_callback *dev_add_cb;
It should not be a different callback for new devices. You must allow registering the callback for all and new devices. Please look how it's done for ethdev:
https://dpdk.org/patch/32900/
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 265
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+int +rte_dev_callback_register (struct rte_device *device, +enum rte_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg) +{
Why passing an event type at registration?
I think the event processing dispatch must be done in the callback, not at registration.
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 292
Quoted 3 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+/* allocate a new interrupt callback entity */ + user_cb =rte_zmalloc ("eal device event" , +sizeof (*user_cb),0 );
No need to use rte_malloc here.
Please check this callback API patch:
https://dpdk.org/patch/33144/
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 59
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +4
-0+enum uev_monitor_netlink_group { +UEV_MONITOR_KERNEL , +UEV_MONITOR_UDEV , +};
Please keep a namespace prefix like RTE_DEV_EVENT_ (same for enum name). Some comments are missing for these constants.
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 71
Quoted 12 lines
lib/librte_eal/common/include/rte_dev.h +12
-0+/** +* The device event type. +*/ +enum rte_dev_event_type { +RTE_DEV_EVENT_UNKNOWN ,/**< unknown event type */ +RTE_DEV_EVENT_ADD ,/**< device being added */ +RTE_DEV_EVENT_REMOVE , +/**< device being removed */ +RTE_DEV_EVENT_CHANGE , +/**< device status being changed, +* etc charger percent +*/
What means status changed?
What means charger percent?
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 72
Quoted 1 line
lib/librte_eal/common/include/rte_dev.h +1
-0+ RTE_DEV_EVENT_MOVE, /**< device sysfs path being moved */
sysfs is Linux specific
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 73
Quoted 1 line
lib/librte_eal/common/include/rte_dev.h +1
-0+ RTE_DEV_EVENT_ONLINE, /**< device being enable */
You mean a device can be added but not enabled?
So enabling is switching it on by a register? or something else?
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 83
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h +10
-0+RTE_DEV_EVENT_OFFLINE ,/**< device being disable */ + RTE_DEV_EVENT_MAX /**< max value of this enum */ +}; + +struct rte_eal_uevent { +enum rte_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +enum uev_monitor_netlink_group group;/**< device netlink group */ +};
I don't understand why this struct is exposed in the public API. Please rename from rte_eal_ to rte_dev_.
lib/librte_eal/common/include/rte_dev.h struct rte_device { · line 208
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +2
-0@@ -166,6 +204,8 @@ struct rte_device {const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */ +/** User application callbacks for device event */ +struct rte_eal_dev_cb_list uev_cbs;
Do not use uev word in API, it refers to uevent which is implementation specific. You can name it event_callbacks.
I am afraid this change is breaking the ABI.
For the first time, 18.02 will be ABI stable.
Quoted 25 lines
lib/librte_eal/common/include/rte_dev.h +25
-0+/** +* It registers the callback for the specific event. Multiple +* callbacks cal be registered at the same time. +* @param event +* The device event type. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int rte_dev_callback_register (struct rte_device *device, +enum rte_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.
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 370
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h +10
-0+* 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_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg);
Such new functions should be added as experimental.
There will be probably more to review in this patch. Let's progress on these comments please.
Re: [PATCH V9 1/5] eal: add uevent monitor api and callback func
Quoted 6 lines · Thomas Monjalon
Hi,
Thanks for splitting the patches.
I will review the first one today. Please see below.10/01/2018 10:12, Jeff Guo:
Quoted 14 lines
lib/librte_eal/bsdapp/eal/eal_dev.c line 36
Quoted 13 lines
lib/librte_eal/bsdapp/eal/eal_dev.c new file +11
-0+int +rte_dev_monitor_start (void ) +{ +return -1 ; +} + +int +rte_dev_monitor_stop (void ) +{ +return -1 ; +}You should add a log to show it is not supported.
ok.
Quoted 7 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h line 7
Quoted 5 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +3
-0+#ifndef _RTE_DEV_H_ +#error "don't include this file directly, please include generic <rte_dev.h>" +#endif Why creating different
rte_dev.hfor BSD and Linux? This is an API, it should be the same.
if no need at this time, combine it to a file.
Quoted 31 lines
Quoted 31 lines
lib/librte_eal/bsdapp/eal/include/exec-env/rte_dev.h new file +22
-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 );lib/librte_eal/common/eal_common_dev.c +2
-0@@ -42,9 +42,32 @@#include <rte_devargs.h> #include <rte_debug.h> #include <rte_log.h> +#include <rte_spinlock.h> +#include <rte_malloc.h>
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c line 51
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +2
-0#include "eal_private.h" +/* spinlock for device callbacks */ +static rte_spinlock_t rte_dev_cb_lock =RTE_SPINLOCK_INITIALIZER ;Please rename to
rte_dev_event_lock.
Let's userte_dev_event_prefix consistently.
make consistently, agree.
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c line 59
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +6
-0+* 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 {Rename to
rte_dev_event?lib/librte_eal/common/eal_common_dev.c line 61
Quoted 2 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+TAILQ_ENTRY (rte_eal_dev_callback) next;/**< Callbacks list */ +rte_eal_dev_cb_fn cb_fn;/**< Callback address */ Rename to
rte_dev_event_callback?
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c line 62
Quoted 1 line
lib/librte_eal/common/eal_common_dev.c +1
-0+void *cb_arg;/**< Parameter for callback */ Comment should be about opaque context.
lib/librte_eal/common/eal_common_dev.c line 65
Quoted 3 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+void *ret_param;/**< Return parameter */ +enum rte_dev_event_type event;/**< device event type */ +uint32_t active;/**< Callback is executing */ Why active is needed?
avoid the lock when unregistered callback.
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c line 69
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +4
-0+}; + +/* A genaral callback for all new devices be added onto the bus */ +static struct rte_eal_dev_callback *dev_add_cb;It should not be a different callback for new devices. You must allow registering the callback for all and new devices. Please look how it's done for ethdev:
https://dpdk.org/patch/32900/
the aim to use this special callback is because when new device add onto the bus, no device instance to store the callback. i saw ethdev solution, that is base on port but that would not make sense in rte device layer. so i try to abandon add callback in rte device, replace of add device name into callback , please see my v10 patch.
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 265
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+int +rte_dev_callback_register (struct rte_device *device, +enum rte_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg) +{Why passing an event type at registration?
I think the event processing dispatch must be done in the callback, not at registration.
make sense, just register all type for device ,and let eal to pass the event.
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c int rte_eal_hotplug_remove(const char *busname, const char *devname) · line 292
Quoted 3 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+/* allocate a new interrupt callback entity */ + user_cb =rte_zmalloc ("eal device event" , +sizeof (*user_cb),0 );No need to use
rte_mallochere.
Please check this callback API patch:https://dpdk.org/patch/33144/
could be better to concentration the code. but if you could tell me why not use rte_zmalloc.
Quoted 8 lines
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 59
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +4
-0+enum uev_monitor_netlink_group { +UEV_MONITOR_KERNEL , +UEV_MONITOR_UDEV , +};Please keep a namespace prefix like
RTE_DEV_EVENT_(same for enum name). Some comments are missing for these constants.
Quoted 14 lines
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 71
Quoted 12 lines
lib/librte_eal/common/include/rte_dev.h +12
-0+/** +* The device event type. +*/ +enum rte_dev_event_type { +RTE_DEV_EVENT_UNKNOWN ,/**< unknown event type */ +RTE_DEV_EVENT_ADD ,/**< device being added */ +RTE_DEV_EVENT_REMOVE , +/**< device being removed */ +RTE_DEV_EVENT_CHANGE , +/**< device status being changed, +* etc charger percent +*/ What means status changed?
What means charger percent?
status changed means that object path change or other more, charger percent just a example for some kobject status. so i don't think we should explicit identify all , i will delete it until we want to use it.
Quoted 7 lines
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 72
Quoted 1 line
lib/librte_eal/common/include/rte_dev.h +1
-0+ RTE_DEV_EVENT_MOVE, /**< device sysfs path being moved */sysfs is Linux specific
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 73
Quoted 1 line
lib/librte_eal/common/include/rte_dev.h +1
-0+ RTE_DEV_EVENT_ONLINE, /**< device being enable */You mean a device can be added but not enabled?
So enabling is switching it on by a register? or something else?
Quoted 12 lines
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 83
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h +10
-0+RTE_DEV_EVENT_OFFLINE ,/**< device being disable */ + RTE_DEV_EVENT_MAX /**< max value of this enum */ +}; + +struct rte_eal_uevent { +enum rte_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +enum uev_monitor_netlink_group group;/**< device netlink group */ +};I don't understand why this struct is exposed in the public API. Please rename from
rte_eal_torte_dev_.
will modify the uevent to event.
Quoted 11 lines
lib/librte_eal/common/include/rte_dev.h struct rte_device { · line 208
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +2
-0@@ -166,6 +204,8 @@ struct rte_device {const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */ +/** User application callbacks for device event */ +struct rte_eal_dev_cb_list uev_cbs;Do not use uev word in API, it refers to uevent which is implementation specific. You can name it
event_callbacks.I am afraid this change is breaking the ABI.
For the first time, 18.02 will be ABI stable.
will not modify rte device struct in v10.
Quoted 37 lines
Quoted 25 lines
lib/librte_eal/common/include/rte_dev.h +25
-0+/** +* It registers the callback for the specific event. Multiple +* callbacks cal be registered at the same time. +* @param event +* The device event type. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int rte_dev_callback_register (struct rte_device *device, +enum rte_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. lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 370
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h +10
-0+* 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_dev_event_type event, +rte_eal_dev_cb_fn cb_fn,void *cb_arg);Such new functions should be added as experimental.
Quoted 2 lines
There will be probably more to review in this patch. Let's progress on these comments please.
thanks for your review!
PATCH v9 2/5 eal: add uevent pass and process function
In reply to Jeff GuoIn order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function. a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_process
---v9->v8:
split the patch set into small and explicit patch
--- drivers/bus/pci/pci_common.c | 20 ++++++ drivers/bus/vdev/vdev.c | 20 ++++++ lib/librte_eal/common/eal_common_bus.c | 28 ++++++++ lib/librte_eal/common/include/rte_bus.h | 36 ++++++++++ lib/librte_eal/common/include/rte_dev.h | 21 ++++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 120 +++++++++++++++++++++++++++++++- 6 files changed, 243 insertions(+), 2 deletions(-)
drivers/bus/pci/pci_common.c +20 -0
@@ -502,6 +502,25 @@ 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_plug (struct rte_device *dev) {
@@ -528,6 +547,7 @@ 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,
drivers/bus/vdev/vdev.c +20 -0
@@ -323,6 +323,25 @@ 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_plug (struct rte_device *dev) {
@@ -339,6 +358,7 @@ 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,
lib/librte_eal/common/eal_common_bus.c +28 -0
@@ -51,6 +51,7 @@ 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);
@@ -170,6 +171,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 +187,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/include/rte_bus.h +36 -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. +*/ +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. *
@@ -206,6 +234,8 @@ 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 */
@@ -306,6 +336,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
@@ -53,10 +53,28 @@ extern "C" {#include <exec-env/rte_dev.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device have been parsed on bus*/ +RTE_DEV_PROBED ,/**< devcie have been probed driver */ +}; + +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. */
@@ -204,6 +222,7 @@ struct rte_device {const struct rte_driver *driver;/**< Associated driver */ int numa_node;/**< NUMA node connection */ struct rte_devargs *devargs;/**< Device user arguments */ +enum rte_dev_state state;/**< Device state */ /** User application callbacks for device event */ struct rte_eal_dev_cb_list uev_cbs; };
@@ -288,6 +307,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/linuxapp/eal/eal_dev.c +118 -2
128 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v10 1/2 eal: add uevent monitor api and callback func
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_evt_mntr_start
rte_dev_evt_mntr_stop
---V10->V9:
a.fix prefix issue.
b.use a common callback lists for all device and all type to replace add callback parameter into device struct.
c.delete some unuse part.
--- lib/librte_eal/bsdapp/eal/eal_dev.c | 38 ++++++ lib/librte_eal/common/eal_common_dev.c | 124 ++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 101 +++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 223 ++++++++++++++++++++++++++++++++ 5 files changed, 487 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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 <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_evt_mntr_start (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +} + +int +rte_dev_evt_mntr_stop (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_dev.c +124 -0
136 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +101 -0
111 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -39,6 +39,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v10 2/2 eal: add uevent pass and process function
In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_process
---V10->V9:
delete some unuse part
--- lib/librte_eal/common/include/rte_dev.h | 23 +++++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 109 +++++++++++++++++++++++++++++++- 2 files changed, 130 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/rte_dev.h +23 -0
@@ -51,6 +51,23 @@ extern "C" {#include <rte_log.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device have been parsed on bus*/ +RTE_DEV_PROBED ,/**< devcie have been probed driver */ +}; + +enum rte_dev_subsystem { +RTE_DEV_SUBSYSTEM_UIO , +RTE_DEV_SUBSYSTEM_VFIO , +RTE_DEV_SUBSYSTEM_PCI , +RTE_DEV_SUBSYSTEM_MAX +}; +/** * The device event type. */
@@ -61,10 +78,16 @@ enum rte_dev_event_type {RTE_DEV_EVENT_MAX /**< max value of this enum */ }; +enum event_monitor_netlink_group { +RTE_DEV_EVENT_MONITOR_KERNEL , +RTE_DEV_EVENT_MONITOR_UDEV , +}; +struct rte_dev_event {enum rte_dev_event_type type;/**< device event type */ int subsystem;/**< subsystem id */ char *devname;/**< device name */ +enum event_monitor_netlink_group group;/**< device netlink group */ }; typedef int (*rte_dev_event_cb_fn)(enum rte_dev_event_type event,
lib/librte_eal/linuxapp/eal/eal_dev.c +107 -2
117 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH V10 2/2] eal: add uevent pass and process function
11/01/2018 15:05, Jeff Guo:
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 62
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device have been parsed on bus*/ +RTE_DEV_PROBED ,/**< devcie have been probed driver */ +};
Let's start with nitpicks: please be careful with spacing in comments.
+ typo: devcie
+ grammar: device has
What means parsed on bus? Is it "scanned"?
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 69
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum rte_dev_subsystem { +RTE_DEV_SUBSYSTEM_UIO , +RTE_DEV_SUBSYSTEM_VFIO , +RTE_DEV_SUBSYSTEM_PCI , +RTE_DEV_SUBSYSTEM_MAX +};
I don't think PCI and UIO/VFIO should be described at the same level. Can you re-use the enum rte_kernel_driver?
lib/librte_eal/common/include/rte_dev.h enum rte_dev_event_type { · line 84
Quoted 4 lines
lib/librte_eal/common/include/rte_dev.h +4
-0+enum event_monitor_netlink_group { +RTE_DEV_EVENT_MONITOR_KERNEL , +RTE_DEV_EVENT_MONITOR_UDEV , +};
This enum should be prefixed with rte_
lib/librte_eal/common/include/rte_dev.h enum rte_dev_event_type { · line 90
Quoted 1 line
lib/librte_eal/common/include/rte_dev.h +1
-0+enum event_monitor_netlink_group group;/**< device netlink group */
netlink is specific to Linux.
I don't think it should be in a generic API struct.
Re: [PATCH V10 2/2] eal: add uevent pass and process function
Quoted 11 lines · Thomas Monjalon
11/01/2018 15:05, Jeff Guo:
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 62
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device have been parsed on bus*/ +RTE_DEV_PROBED ,/**< devcie have been probed driver */ +};Let's start with nitpicks: please be careful with spacing in comments.
+ typo: devcie
+ grammar: device has
Quoted 1 line
What means parsed on bus? Is it "scanned"?
absolutely what i mean is scanned.
Quoted 8 lines
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 69
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum rte_dev_subsystem { +RTE_DEV_SUBSYSTEM_UIO , +RTE_DEV_SUBSYSTEM_VFIO , +RTE_DEV_SUBSYSTEM_PCI , +RTE_DEV_SUBSYSTEM_MAX +};I don't think PCI and UIO/VFIO should be described at the same level. Can you re-use the enum
rte_kernel_driver?
rte_kernel_driver might be not qualify for that use, since that is the event sumsystem, it include pci/uio/vfio, such strings to identify each subsystem. i will modify it to be rte_dev_event_subsystem.
Quoted 5 lines
lib/librte_eal/common/include/rte_dev.h enum rte_dev_event_type { · line 84
Quoted 4 lines
lib/librte_eal/common/include/rte_dev.h +4
-0+enum event_monitor_netlink_group { +RTE_DEV_EVENT_MONITOR_KERNEL , +RTE_DEV_EVENT_MONITOR_UDEV , +};This enum should be prefixed with
rte_
sure.
Quoted 3 lines
lib/librte_eal/common/include/rte_dev.h enum rte_dev_event_type { · line 90
Quoted 1 line
lib/librte_eal/common/include/rte_dev.h +1
-0+enum event_monitor_netlink_group group;/**< device netlink group */ netlink is specific to Linux.
I don't think it should be in a generic API struct.
agree.
Re: [PATCH V10 2/2] eal: add uevent pass and process function
15/01/2018 11:52, Guo, Jia:
Quoted 12 lines · Thomas Monjalon
Quoted 10 lines
11/01/2018 15:05, Jeff Guo:
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 69
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum rte_dev_subsystem { +RTE_DEV_SUBSYSTEM_UIO , +RTE_DEV_SUBSYSTEM_VFIO , +RTE_DEV_SUBSYSTEM_PCI , +RTE_DEV_SUBSYSTEM_MAX +};I don't think PCI and UIO/VFIO should be described at the same level. Can you re-use the enum
rte_kernel_driver?
Quoted 1 line
rte_kernel_drivermight be not qualify for that use, since that is the event sumsystem, it include pci/uio/vfio, such strings to identify each subsystem. i will modify it to berte_dev_event_subsystem.
I don't understand this classification.
A device can be both PCI and VFIO.
Re: [PATCH V10 2/2] eal: add uevent pass and process function
Quoted 15 lines · Thomas Monjalon
15/01/2018 11:52, Guo, Jia:
Quoted 14 lines · Thomas Monjalon
Quoted 9 lines
11/01/2018 15:05, Jeff Guo:
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 69
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum rte_dev_subsystem { +RTE_DEV_SUBSYSTEM_UIO , +RTE_DEV_SUBSYSTEM_VFIO , +RTE_DEV_SUBSYSTEM_PCI , +RTE_DEV_SUBSYSTEM_MAX +};I don't think PCI and UIO/VFIO should be described at the same level. Can you re-use the enum
rte_kernel_driver?
rte_kernel_drivermight be not qualify for that use, since that is the event sumsystem, it include pci/uio/vfio, such strings to identify each subsystem. i will modify it to berte_dev_event_subsystem.I don't understand this classification.
A device can be both PCI and VFIO.
yes , i think that might be a little strange, but what i saw in the uevent message is that , the item of subsystem info from kernel side is pci sometimes, but some time is uio, i don't know if it is good to defferentiy them by "subsystem " or "driver" or other. let me think about it more.
PATCH v11 1/3 eal: add uevent monitor api and callback func
In reply to Jeff GuoThis patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stop
---v11->v10:
modify some typo and add experimental tag in new file.
--- lib/librte_eal/bsdapp/eal/eal_dev.c | 38 ++++++ lib/librte_eal/common/eal_common_dev.c | 125 ++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 117 +++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 223 ++++++++++++++++++++++++++++++++ 5 files changed, 504 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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 <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_event_monitor_start (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +} + +int +rte_dev_event_monitor_stop (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_dev.c +125 -0
137 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +117 -0
127 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -39,6 +39,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v11 2/3 eal: add uevent pass and process function
In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_process
---v11->v10:
fix some typo issue.
--- lib/librte_eal/common/include/rte_dev.h | 17 +++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 110 +++++++++++++++++++++++++++++++- 2 files changed, 125 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/rte_dev.h +17 -0
@@ -51,6 +51,23 @@ extern "C" {#include <rte_log.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device has been scanned on bus*/ +RTE_DEV_PROBED ,/**< device has been probed driver */ +}; + +enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UIO , +RTE_DEV_EVENT_SUBSYSTEM_VFIO , +RTE_DEV_EVENT_SUBSYSTEM_PCI , +RTE_DEV_EVENT_SUBSYSTEM_MAX +}; +/** * The device event type. */
lib/librte_eal/linuxapp/eal/eal_dev.c +108 -2
118 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH V11 2/3] eal: add uevent pass and process function
15/01/2018 11:48, Jeff Guo:
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 69
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UIO , +RTE_DEV_EVENT_SUBSYSTEM_VFIO , +RTE_DEV_EVENT_SUBSYSTEM_PCI , +RTE_DEV_EVENT_SUBSYSTEM_MAX +};
I still don't understand this classification, mixing PCI and VFIO at the same level.
Re: [PATCH V11 2/3] eal: add uevent pass and process function
Quoted 9 lines · Thomas Monjalon
15/01/2018 11:48, Jeff Guo:
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 69
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UIO , +RTE_DEV_EVENT_SUBSYSTEM_VFIO , +RTE_DEV_EVENT_SUBSYSTEM_PCI , +RTE_DEV_EVENT_SUBSYSTEM_MAX +};I still don't understand this classification, mixing PCI and VFIO at the same level.
ok, so let me explicit explain that that is because the deference kernel version would poke deference subsystem info from the net link message. so just forcus on the new kernel version would be fine and delete pci item.
PATCH v11 3/3 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.
---v11->v10:
modify callback register calling.
--- app/test-pmd/testpmd.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 9 +++ 2 files changed, 177 insertions(+)
app/test-pmd/testpmd.c +168 -0
@@ -373,6 +373,8 @@ uint8_t bitrate_enabled;struct gro_status gro_ports[RTE_MAX_ETHPORTS ];uint8_t gro_flush_cycles =GRO_DEFAULT_FLUSH_CYCLES ; +static struct hotplug_request_list hp_list; +/* Forward function declarations */ static void map_port_queue_stats_mapping_registers (portid_t pi,struct rte_port *port);
@@ -380,6 +382,13 @@ static void check_all_ports_link_status(uint32_t port_mask);static int eth_event_callback (portid_t port_id,enum rte_eth_event_type type,void *param,void *ret_param); +static int eth_uevent_callback (char *device_name,enum rte_dev_event_type type, +void *param); +static int eth_uevent_callback_register (portid_t port_id); +static int in_hotplug_list (const char *dev_name); + +static int hotplug_list_add (const char *dev_name, +enum rte_dev_event_type event);/* * Check if all the ports are started.
@@ -1729,6 +1738,27 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_uevent_callback_register (portid_t port_id) +{ +int diag; +char device_name[128 ]; + +snprintf (device_name,sizeof (device_name), +"%s" , rte_eth_devices[port_id].device->name); + +/* register the uevent callback */ + + diag =rte_dev_callback_register (device_name, + eth_uevent_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup uevent callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {
@@ -1745,6 +1775,8 @@ attach_port(char *identifier)if (rte_eth_dev_attach (identifier, &pi))return ; +eth_uevent_callback_register (pi); + socket_id = (unsigned )rte_eth_dev_socket_id (pi);/* if socket_id is invalid, set to 0 */ if (check_socket_id (socket_id) <0 )
@@ -1756,6 +1788,8 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +hotplug_list_add (identifier,RTE_DEV_EVENT_REMOVE ); +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }
@@ -1782,6 +1816,9 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_ADD ); +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );
@@ -1805,6 +1842,9 @@ pmd_test_exit(void)close_port (pt_id); } } + +rte_dev_event_monitor_stop (); +printf ("\nBye...\n" ); }
@@ -1889,6 +1929,49 @@ rmv_event_callback(void *arg) dev->device->name); } +static void +rmv_uevent_callback (void *arg) +{ +char name[RTE_ETH_NAME_MAX_LEN ]; +uint8_t port_id = (intptr_t )arg; + +rte_eal_alarm_cancel (rmv_uevent_callback, arg); + +RTE_ETH_VALID_PORTID_OR_RET (port_id); +printf ("removing port id:%u\n" , port_id); + +if (!in_hotplug_list (rte_eth_devices[port_id].device->name)) +return ; + +stop_packet_forwarding (); + +stop_port (port_id); +close_port (port_id); +if (rte_eth_dev_detach (port_id, name)) { +RTE_LOG (ERR ,USER1 ,"Failed to detach port '%s'\n" , name); +return ; + } + + nb_ports =rte_eth_dev_count (); + +printf ("Port '%s' is detached. Now total ports is %d\n" , + name, nb_ports); +} + +static void +add_uevent_callback (void *arg) +{ +char *dev_name = (char *)arg; + +rte_eal_alarm_cancel (add_uevent_callback, arg); + +if (!in_hotplug_list (dev_name)) +return ; + +RTE_LOG (ERR ,EAL ,"add device: %s\n" , dev_name); +attach_port (dev_name); +} +/* This function is used by the interrupt thread */ static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
@@ -1931,6 +2014,82 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, }static int +in_hotplug_list (const char *dev_name) +{ +struct hotplug_request *hp_request =NULL ; + + TAILQ_FOREACH(hp_request, &hp_list, next) { +if (!strcmp (hp_request->dev_name, dev_name)) +break ; + } + +if (hp_request) +return 1 ; + +return 0 ; +} + +static int +hotplug_list_add (const char *dev_name,enum rte_dev_event_type event) +{ +struct hotplug_request *hp_request; + + hp_request =rte_zmalloc ("hoplug request" , +sizeof (*hp_request),0 ); +if (hp_request ==NULL ) { +fprintf (stderr,"%s can not alloc memory\n" , + __func__); +return -ENOMEM ; + } + + hp_request->dev_name = dev_name; + hp_request->event = event; + +TAILQ_INSERT_TAIL (&hp_list, hp_request, next); + +return 0 ; +} + +/* This function is used by the interrupt thread */ +static int +eth_uevent_callback (char *device_name,enum rte_dev_event_type type,void *arg) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; + +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_uevent_callback, arg)) +fprintf (stderr,"Could not set up deferred " +"device removal\n" ); +break ; +case RTE_DEV_EVENT_ADD : +if (rte_eal_alarm_set (500000 , + add_uevent_callback, (void *)device_name)) +fprintf (stderr,"Could not set up deferred " +"device add\n" ); +break ; +default : +break ; + } +return 0 ; +} + +static int set_tx_queue_stats_mapping_registers (portid_t port_id,struct rte_port *port) {uint16_t i;
@@ -2415,6 +2574,15 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +/* enable hot plug monitoring */ +TAILQ_INIT (&hp_list); +rte_dev_event_monitor_start (); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_REMOVE ); +eth_uevent_callback_register (port_id); + }if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );
app/test-pmd/testpmd.h +9 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_dev_event_type event;/**< device event type */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
Signature · 1 line
2.7.4
PATCH v12 1/3 eal: add uevent monitor api and callback func
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stop
---v12->v11:
identify null param in callback for monitor all devices uevent
--- lib/librte_eal/bsdapp/eal/eal_dev.c | 38 ++++++ lib/librte_eal/common/eal_common_dev.c | 128 ++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 119 +++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 223 ++++++++++++++++++++++++++++++++ 5 files changed, 509 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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 <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_event_monitor_start (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +} + +int +rte_dev_event_monitor_stop (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_dev.c +128 -0
140 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +119 -0
129 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -39,6 +39,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v12 2/3 eal: add uevent pass and process function
In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_process
---v12->v11:
base on newer kernel driver, delete some unuse param in event subsystem
--- lib/librte_eal/common/include/rte_dev.h | 16 +++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 110 +++++++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/rte_dev.h +16 -0
@@ -51,6 +51,22 @@ extern "C" {#include <rte_log.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device has been scanned on bus*/ +RTE_DEV_PROBED ,/**< device has been probed driver */ +}; + +enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UIO , +RTE_DEV_EVENT_SUBSYSTEM_VFIO , +RTE_DEV_EVENT_SUBSYSTEM_MAX +}; +/** * The device event type. */
lib/librte_eal/linuxapp/eal/eal_dev.c +108 -2
118 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH V12 2/3] eal: add uevent pass and process function
Quoted 17 lines
-----Original Message-----
From: Guo, Jia
Sent: Thursday, January 18, 2018 12:12 PM
To: [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Cc: Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; Wu, Jingjing <[email protected]>; [email protected]; Guo, Jia <[email protected]>; [email protected]; Zhang, Helin <[email protected]>; [email protected]
Subject: [PATCH V12 2/3] eal: add uevent pass and process functionIn order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
Quoted 8 lines
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_processSigned-off-by Jeff Guo <[email protected]>
PATCH v12 3/3 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.
---v12->v11:
no change
--- app/test-pmd/testpmd.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 9 +++ 2 files changed, 177 insertions(+)
app/test-pmd/testpmd.c +168 -0
@@ -373,6 +373,8 @@ uint8_t bitrate_enabled;struct gro_status gro_ports[RTE_MAX_ETHPORTS ];uint8_t gro_flush_cycles =GRO_DEFAULT_FLUSH_CYCLES ; +static struct hotplug_request_list hp_list; +/* Forward function declarations */ static void map_port_queue_stats_mapping_registers (portid_t pi,struct rte_port *port);
@@ -380,6 +382,13 @@ static void check_all_ports_link_status(uint32_t port_mask);static int eth_event_callback (portid_t port_id,enum rte_eth_event_type type,void *param,void *ret_param); +static int eth_uevent_callback (char *device_name,enum rte_dev_event_type type, +void *param); +static int eth_uevent_callback_register (portid_t port_id); +static int in_hotplug_list (const char *dev_name); + +static int hotplug_list_add (const char *dev_name, +enum rte_dev_event_type event);/* * Check if all the ports are started.
@@ -1729,6 +1738,27 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_uevent_callback_register (portid_t port_id) +{ +int diag; +char device_name[128 ]; + +snprintf (device_name,sizeof (device_name), +"%s" , rte_eth_devices[port_id].device->name); + +/* register the uevent callback */ + + diag =rte_dev_callback_register (device_name, + eth_uevent_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup uevent callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {
@@ -1745,6 +1775,8 @@ attach_port(char *identifier)if (rte_eth_dev_attach (identifier, &pi))return ; +eth_uevent_callback_register (pi); + socket_id = (unsigned )rte_eth_dev_socket_id (pi);/* if socket_id is invalid, set to 0 */ if (check_socket_id (socket_id) <0 )
@@ -1756,6 +1788,8 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +hotplug_list_add (identifier,RTE_DEV_EVENT_REMOVE ); +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }
@@ -1782,6 +1816,9 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_ADD ); +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );
@@ -1805,6 +1842,9 @@ pmd_test_exit(void)close_port (pt_id); } } + +rte_dev_event_monitor_stop (); +printf ("\nBye...\n" ); }
@@ -1889,6 +1929,49 @@ rmv_event_callback(void *arg) dev->device->name); } +static void +rmv_uevent_callback (void *arg) +{ +char name[RTE_ETH_NAME_MAX_LEN ]; +uint8_t port_id = (intptr_t )arg; + +rte_eal_alarm_cancel (rmv_uevent_callback, arg); + +RTE_ETH_VALID_PORTID_OR_RET (port_id); +printf ("removing port id:%u\n" , port_id); + +if (!in_hotplug_list (rte_eth_devices[port_id].device->name)) +return ; + +stop_packet_forwarding (); + +stop_port (port_id); +close_port (port_id); +if (rte_eth_dev_detach (port_id, name)) { +RTE_LOG (ERR ,USER1 ,"Failed to detach port '%s'\n" , name); +return ; + } + + nb_ports =rte_eth_dev_count (); + +printf ("Port '%s' is detached. Now total ports is %d\n" , + name, nb_ports); +} + +static void +add_uevent_callback (void *arg) +{ +char *dev_name = (char *)arg; + +rte_eal_alarm_cancel (add_uevent_callback, arg); + +if (!in_hotplug_list (dev_name)) +return ; + +RTE_LOG (ERR ,EAL ,"add device: %s\n" , dev_name); +attach_port (dev_name); +} +/* This function is used by the interrupt thread */ static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
@@ -1931,6 +2014,82 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, }static int +in_hotplug_list (const char *dev_name) +{ +struct hotplug_request *hp_request =NULL ; + + TAILQ_FOREACH(hp_request, &hp_list, next) { +if (!strcmp (hp_request->dev_name, dev_name)) +break ; + } + +if (hp_request) +return 1 ; + +return 0 ; +} + +static int +hotplug_list_add (const char *dev_name,enum rte_dev_event_type event) +{ +struct hotplug_request *hp_request; + + hp_request =rte_zmalloc ("hoplug request" , +sizeof (*hp_request),0 ); +if (hp_request ==NULL ) { +fprintf (stderr,"%s can not alloc memory\n" , + __func__); +return -ENOMEM ; + } + + hp_request->dev_name = dev_name; + hp_request->event = event; + +TAILQ_INSERT_TAIL (&hp_list, hp_request, next); + +return 0 ; +} + +/* This function is used by the interrupt thread */ +static int +eth_uevent_callback (char *device_name,enum rte_dev_event_type type,void *arg) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; + +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_uevent_callback, arg)) +fprintf (stderr,"Could not set up deferred " +"device removal\n" ); +break ; +case RTE_DEV_EVENT_ADD : +if (rte_eal_alarm_set (500000 , + add_uevent_callback, (void *)device_name)) +fprintf (stderr,"Could not set up deferred " +"device add\n" ); +break ; +default : +break ; + } +return 0 ; +} + +static int set_tx_queue_stats_mapping_registers (portid_t port_id,struct rte_port *port) {uint16_t i;
@@ -2415,6 +2574,15 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +/* enable hot plug monitoring */ +TAILQ_INIT (&hp_list); +rte_dev_event_monitor_start (); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_REMOVE ); +eth_uevent_callback_register (port_id); + }if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );
app/test-pmd/testpmd.h +9 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_dev_event_type event;/**< device event type */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
Signature · 1 line
2.7.4
Re: [PATCH V12 3/3] app/testpmd: use uevent to monitor hotplug
app/test-pmd/testpmd.c rmv_event_callback(void *arg) · line 1971
Quoted 12 lines
app/test-pmd/testpmd.c +12
-0+ +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);
It's not an error, replace by printf?
Quoted 13 lines
app/test-pmd/testpmd.c +5
-0+attach_port (dev_name); +} +/* This function is used by the interrupt thread */ static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,@@ -1931,6 +2014,82 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, } static int +in_hotplug_list(const char *dev_name) +{
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum · line 2029
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+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 ; +
Is it better to use TRUE and FALSE?
Re: [PATCH V12 3/3] app/testpmd: use uevent to monitor hotplug
Quoted 5 lines · Jingjing
Quoted 5 lines
app/test-pmd/testpmd.c +5
-0+ +static void +add_uevent_callback (void *arg) +{ +char *dev_name = (char *)arg;
Quoted 8 lines
app/test-pmd/testpmd.c rmv_event_callback(void *arg) · line 1971
Quoted 7 lines
app/test-pmd/testpmd.c +7
-0+ +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);It's not an error, replace by printf?
sure.
Quoted 10 lines
Quoted 10 lines
app/test-pmd/testpmd.c +3
-0+attach_port (dev_name); +} +/* This function is used by the interrupt thread */ static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,@@ -1931,6 +2014,82 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, }
Quoted 14 lines
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2028
Quoted 13 lines
app/test-pmd/testpmd.c +12
-0static 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 ; +Is it better to use TRUE and FALSE?
ok,make sense.
PATCH v13 1/3 eal: add uevent monitor api and callback func
In reply to Jeff GuoThis patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stop
---v13->v12:
fix some logic issue and null check issue
fix monitor stop func issue
--- lib/librte_eal/bsdapp/eal/eal_dev.c | 38 +++++ lib/librte_eal/common/eal_common_dev.c | 132 +++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 119 ++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 243 ++++++++++++++++++++++++++++++++ 5 files changed, 533 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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 <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_event_monitor_start (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +} + +int +rte_dev_event_monitor_stop (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_dev.c +132 -0
144 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +119 -0
129 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -39,6 +39,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +243 -0
243 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v13 2/3 eal: add uevent pass and process function
In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_process
---v13->v12:
fix some event parse issue
--- lib/librte_eal/common/include/rte_dev.h | 16 +++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 105 +++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/rte_dev.h +16 -0
@@ -52,6 +52,22 @@ extern "C" {#include <rte_config.h> #include <rte_log.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device has been scanned on bus*/ +RTE_DEV_PROBED ,/**< device has been probed driver */ +}; + +enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UIO , +RTE_DEV_EVENT_SUBSYSTEM_VFIO , +RTE_DEV_EVENT_SUBSYSTEM_MAX +}; +/** * The device event type. */
lib/librte_eal/linuxapp/eal/eal_dev.c +103 -2
113 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v13 3/3 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.
---v13->v12:
refine some code style
--- app/test-pmd/testpmd.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 9 +++ 2 files changed, 178 insertions(+)
app/test-pmd/testpmd.c +169 -0
@@ -12,6 +12,7 @@#include <sys/mman.h> #include <sys/types.h> #include <errno.h> +#include <stdbool.h> #include <sys/queue.h> #include <sys/stat.h>
@@ -367,6 +368,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);
@@ -374,6 +377,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 (char *device_name,enum rte_dev_event_type type, +void *param); +static int eth_uevent_callback_register (portid_t port_id); +static bool in_hotplug_list (const char *dev_name); + +static int hotplug_list_add (const char *dev_name, +enum rte_dev_event_type event);/* * Check if all the ports are started.
@@ -1835,6 +1845,27 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_uevent_callback_register (portid_t port_id) +{ +int diag; +char device_name[128 ]; + +snprintf (device_name,sizeof (device_name), +"%s" , rte_eth_devices[port_id].device->name); + +/* register the uevent callback */ + + diag =rte_dev_callback_register (device_name, + eth_uevent_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup uevent callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {
@@ -1851,6 +1882,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 )
@@ -1862,6 +1895,8 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +hotplug_list_add (identifier,RTE_DEV_EVENT_REMOVE ); +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }
@@ -1888,6 +1923,9 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_ADD ); +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );
@@ -1911,6 +1949,9 @@ pmd_test_exit(void)close_port (pt_id); } } + +rte_dev_event_monitor_stop (); +printf ("\nBye...\n" ); }
@@ -1995,6 +2036,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)) { +TESTPMD_LOG (ERR ,"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 ; + +printf ("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,
@@ -2038,6 +2122,82 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,return 0 ; } +static bool +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 true; + +return false; +} + +static int +hotplug_list_add (const char *dev_name,enum rte_dev_event_type event) +{ +struct hotplug_request *hp_request; + + hp_request =rte_zmalloc ("hoplug request" , +sizeof (*hp_request),0 ); +if (hp_request ==NULL ) { +fprintf (stderr,"%s can not alloc memory\n" , + __func__); +return -ENOMEM ; + } + + hp_request->dev_name = dev_name; + hp_request->event = event; + +TAILQ_INSERT_TAIL (&hp_list, hp_request, next); + +return 0 ; +} + +/* This function is used by the interrupt thread */ +static int +eth_uevent_callback (char *device_name,enum rte_dev_event_type type,void *arg) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; + +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_uevent_callback, arg)) +fprintf (stderr,"Could not set up deferred " +"device removal\n" ); +break ; +case RTE_DEV_EVENT_ADD : +if (rte_eal_alarm_set (500000 , + add_uevent_callback, (void *)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) {
@@ -2519,6 +2679,15 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +/* enable hot plug monitoring */ +TAILQ_INIT (&hp_list); +rte_dev_event_monitor_start (); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_REMOVE ); +eth_uevent_callback_register (port_id); + }if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );
app/test-pmd/testpmd.h +9 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_dev_event_type event;/**< device event type */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
Signature · 1 line
2.7.4
PATCH v13 1/3 eal: add uevent monitor api and callback func
In reply to Jeff GuoThis patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stop
---v13->v12:
fix some logic issue and null check issue
fix monitor stop func issue and bsp build issue
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 38 +++++ lib/librte_eal/common/eal_common_dev.c | 133 +++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 119 ++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 243 ++++++++++++++++++++++++++++++++ 6 files changed, 535 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -32,6 +32,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#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 <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_event_monitor_start (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +} + +int +rte_dev_event_monitor_stop (void ) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_dev.c +133 -0
145 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +119 -0
129 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -39,6 +39,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +243 -0
243 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v13 2/3 eal: add uevent pass and process function
In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_process
---v13->v12:
fix some event parse issue
--- lib/librte_eal/common/include/rte_dev.h | 16 +++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 105 +++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/rte_dev.h +16 -0
@@ -52,6 +52,22 @@ extern "C" {#include <rte_config.h> #include <rte_log.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device has been scanned on bus*/ +RTE_DEV_PROBED ,/**< device has been probed driver */ +}; + +enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UIO , +RTE_DEV_EVENT_SUBSYSTEM_VFIO , +RTE_DEV_EVENT_SUBSYSTEM_MAX +}; +/** * The device event type. */
lib/librte_eal/linuxapp/eal/eal_dev.c +103 -2
113 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v13 3/3 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.
---v13->v12:
refine some code style
--- app/test-pmd/testpmd.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 9 +++ 2 files changed, 178 insertions(+)
app/test-pmd/testpmd.c +169 -0
@@ -12,6 +12,7 @@#include <sys/mman.h> #include <sys/types.h> #include <errno.h> +#include <stdbool.h> #include <sys/queue.h> #include <sys/stat.h>
@@ -367,6 +368,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);
@@ -374,6 +377,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 (char *device_name,enum rte_dev_event_type type, +void *param); +static int eth_uevent_callback_register (portid_t port_id); +static bool in_hotplug_list (const char *dev_name); + +static int hotplug_list_add (const char *dev_name, +enum rte_dev_event_type event);/* * Check if all the ports are started.
@@ -1835,6 +1845,27 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_uevent_callback_register (portid_t port_id) +{ +int diag; +char device_name[128 ]; + +snprintf (device_name,sizeof (device_name), +"%s" , rte_eth_devices[port_id].device->name); + +/* register the uevent callback */ + + diag =rte_dev_callback_register (device_name, + eth_uevent_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup uevent callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {
@@ -1851,6 +1882,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 )
@@ -1862,6 +1895,8 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +hotplug_list_add (identifier,RTE_DEV_EVENT_REMOVE ); +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }
@@ -1888,6 +1923,9 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_ADD ); +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );
@@ -1911,6 +1949,9 @@ pmd_test_exit(void)close_port (pt_id); } } + +rte_dev_event_monitor_stop (); +printf ("\nBye...\n" ); }
@@ -1995,6 +2036,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)) { +TESTPMD_LOG (ERR ,"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 ; + +printf ("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,
@@ -2038,6 +2122,82 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,return 0 ; } +static bool +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 true; + +return false; +} + +static int +hotplug_list_add (const char *dev_name,enum rte_dev_event_type event) +{ +struct hotplug_request *hp_request; + + hp_request =rte_zmalloc ("hoplug request" , +sizeof (*hp_request),0 ); +if (hp_request ==NULL ) { +fprintf (stderr,"%s can not alloc memory\n" , + __func__); +return -ENOMEM ; + } + + hp_request->dev_name = dev_name; + hp_request->event = event; + +TAILQ_INSERT_TAIL (&hp_list, hp_request, next); + +return 0 ; +} + +/* This function is used by the interrupt thread */ +static int +eth_uevent_callback (char *device_name,enum rte_dev_event_type type,void *arg) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; + +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_uevent_callback, arg)) +fprintf (stderr,"Could not set up deferred " +"device removal\n" ); +break ; +case RTE_DEV_EVENT_ADD : +if (rte_eal_alarm_set (500000 , + add_uevent_callback, (void *)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) {
@@ -2519,6 +2679,15 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +/* enable hot plug monitoring */ +TAILQ_INIT (&hp_list); +rte_dev_event_monitor_start (); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_REMOVE ); +eth_uevent_callback_register (port_id); + }if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );
app/test-pmd/testpmd.h +9 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_dev_event_type event;/**< device event type */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
Signature · 1 line
2.7.4
PATCH v14 1/3 eal: add uevent monitor api and callback func
This patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could use these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device, and more it benefit to use to do smoothly fail safe work.
About uevent monitoring:
a: add one epolling to poll the netlink socket, to monitor the uevent of
the device.
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below APIs in rte eal device layer.
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stop
---v14->v13:
add __rte_experimental on function defind and fix bsd build issue
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 33 +++++ lib/librte_eal/common/eal_common_dev.c | 132 +++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 121 ++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 243 ++++++++++++++++++++++++++++++++ 6 files changed, 531 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <stdio.h> +#include <string.h> +#include <inttypes.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_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_dev.c +132 -0
144 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +121 -0
131 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +243 -0
243 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v14 2/3 eal: add uevent pass and process function
In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_process
---v14->v13:
no change.
--- lib/librte_eal/common/include/rte_dev.h | 16 +++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 105 +++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/rte_dev.h +16 -0
@@ -53,6 +53,22 @@ extern "C" {#include <rte_compat.h> #include <rte_log.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device has been scanned on bus*/ +RTE_DEV_PROBED ,/**< device has been probed driver */ +}; + +enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UIO , +RTE_DEV_EVENT_SUBSYSTEM_VFIO , +RTE_DEV_EVENT_SUBSYSTEM_MAX +}; +/** * The device event type. */
lib/librte_eal/linuxapp/eal/eal_dev.c +103 -2
113 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v14 3/3 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.
---v14->v13:
no change
--- app/test-pmd/testpmd.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 9 +++ 2 files changed, 178 insertions(+)
app/test-pmd/testpmd.c +169 -0
@@ -12,6 +12,7 @@#include <sys/mman.h> #include <sys/types.h> #include <errno.h> +#include <stdbool.h> #include <sys/queue.h> #include <sys/stat.h>
@@ -368,6 +369,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);
@@ -375,6 +378,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 (char *device_name,enum rte_dev_event_type type, +void *param); +static int eth_uevent_callback_register (portid_t port_id); +static bool in_hotplug_list (const char *dev_name); + +static int hotplug_list_add (const char *dev_name, +enum rte_dev_event_type event);/* * Check if all the ports are started.
@@ -1838,6 +1848,27 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_uevent_callback_register (portid_t port_id) +{ +int diag; +char device_name[128 ]; + +snprintf (device_name,sizeof (device_name), +"%s" , rte_eth_devices[port_id].device->name); + +/* register the uevent callback */ + + diag =rte_dev_callback_register (device_name, + eth_uevent_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup uevent callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {
@@ -1854,6 +1885,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 )
@@ -1865,6 +1898,8 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +hotplug_list_add (identifier,RTE_DEV_EVENT_REMOVE ); +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }
@@ -1891,6 +1926,9 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_ADD ); +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );
@@ -1914,6 +1952,9 @@ pmd_test_exit(void)close_port (pt_id); } } + +rte_dev_event_monitor_stop (); +printf ("\nBye...\n" ); }
@@ -1998,6 +2039,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)) { +TESTPMD_LOG (ERR ,"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 ; + +printf ("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,
@@ -2041,6 +2125,82 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,return 0 ; } +static bool +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 true; + +return false; +} + +static int +hotplug_list_add (const char *dev_name,enum rte_dev_event_type event) +{ +struct hotplug_request *hp_request; + + hp_request =rte_zmalloc ("hoplug request" , +sizeof (*hp_request),0 ); +if (hp_request ==NULL ) { +fprintf (stderr,"%s can not alloc memory\n" , + __func__); +return -ENOMEM ; + } + + hp_request->dev_name = dev_name; + hp_request->event = event; + +TAILQ_INSERT_TAIL (&hp_list, hp_request, next); + +return 0 ; +} + +/* This function is used by the interrupt thread */ +static int +eth_uevent_callback (char *device_name,enum rte_dev_event_type type,void *arg) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; + +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_uevent_callback, arg)) +fprintf (stderr,"Could not set up deferred " +"device removal\n" ); +break ; +case RTE_DEV_EVENT_ADD : +if (rte_eal_alarm_set (500000 , + add_uevent_callback, (void *)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) {
@@ -2522,6 +2682,15 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +/* enable hot plug monitoring */ +TAILQ_INIT (&hp_list); +rte_dev_event_monitor_start (); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device->name, +RTE_DEV_EVENT_REMOVE ); +eth_uevent_callback_register (port_id); + }if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );
app/test-pmd/testpmd.h +9 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_dev_event_type event;/**< device event type */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
Signature · 1 line
2.7.4
Re: [PATCH V14 3/3] app/testpmd: use uevent to monitor hotplug
Quoted 15 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, January 30, 2018 8:21 PM
To: [email protected]; Richardson, Bruce <[email protected]>; [email protected]; Wu, Jingjing <[email protected]>; [email protected]; [email protected]
Cc: Yigit, Ferruh <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; [email protected]; Guo, Jia <[email protected]>; Zhang, Helin <[email protected]>; Van Haaren, Harry <[email protected]>; Tan, Jianfeng <[email protected]>
Subject: [PATCH V14 3/3] app/testpmd: use uevent to monitor hotplug
Quoted 5 lines
use testpmd for example, to show app how to request and use uevent monitoring to handle the hot removal event and the hot insertion event.
Signed-off-by Jeff Guo <[email protected]>
PATCH v15 1/5 eal: add uevent monitor api and callback func
In reply to Jeff GuoThis patch aim to add a general uevent mechanism in eal device layer, to enable all linux kernel object uevent monitoring, user could call these APIs to monitor and read out the device status info that sent from the kernel side, then corresponding to handle it, such as when detect hotplug uevent type, user could detach or attach the device.
About uevent monitoring:
a: add new device event handle type in eal interrupt, it could be register
for uevent interrupt
b: add enum of rte_eal_dev_event_type and struct of rte_eal_uevent.
c: add below APIs in rte eal device layer for enable monitor and cb register
rte_dev_callback_register
rte_dev_callback_unregister
_rte_dev_callback_process
rte_dev_event_monitor_start
rte_dev_event_monitor_stop
---v15->v14:
use exist eal interrupt epoll to replace of rte service usage for monitor thread, add new device event handle type in eal interrupt
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 33 +++++ lib/librte_eal/common/eal_common_dev.c | 132 ++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 121 +++++++++++++++++++ lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 134 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 5 +- 8 files changed, 427 insertions(+), 1 deletion(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <stdio.h> +#include <string.h> +#include <inttypes.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_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Not support event monitor for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_dev.c +132 -0
144 lines not on this page · raw message
lib/librte_eal/common/include/rte_dev.h +121 -0
131 lines not on this page · raw message
lib/librte_eal/common/include/rte_eal_interrupts.h +1 -0
@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +134 -0
134 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_interrupts.c +4 -1
@@ -674,7 +674,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
Signature · 1 line
2.7.4
PATCH v15 2/5 eal: add uevent pass and process function
In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_process
---v15->v14:
remove the uevent type check and any policy from eal, let it check and management in user's callback.
--- lib/librte_eal/common/include/rte_dev.h | 17 ++++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 95 ++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/rte_dev.h +17 -0
@@ -24,6 +24,23 @@ extern "C" {#include <rte_compat.h> #include <rte_log.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device has been scanned on bus*/ +RTE_DEV_PROBED ,/**< device has been probed driver */ +}; + +enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UNKNOWN , +RTE_DEV_EVENT_SUBSYSTEM_UIO , +RTE_DEV_EVENT_SUBSYSTEM_VFIO , +RTE_DEV_EVENT_SUBSYSTEM_MAX +}; +/** * The device event type. */
lib/librte_eal/linuxapp/eal/eal_dev.c +94 -1
103 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH V15 2/5] eal: add uevent pass and process function
Quoted 3 lines · Jeff Guo
In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
In fact, how to pass the uevent to eal/linux for processing, is already done by last patch, by registering a callback into interrupt thread.
In this patch, we are actually showing how to process the uevent, and translate it into RTE_DEV_EVENT_ADD, RTE_DEV_EVENT_DEL, etc.
So the title would be something like:
eal/linux: translate uevent to dev event
Quoted 7 lines
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_process
We already have dummy rte_dev_event_monitor_start and rte_dev_event_monitor_stop, we don't need to have those dummy internal functions any more. Actually, you did not implement those dummy functions.
Quoted 8 lines
Signed-off-by Jeff Guo <[email protected]>---
v15->v14:
remove the uevent type check and any policy from eal, let it check and management in user's callback.--- lib/librte_eal/common/include/rte_dev.h | 17 ++++++
And if you agree with me in the above, we shall not touch this file. Move the definition into the previous patch.
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 28
Quoted 13 lines
lib/librte_eal/linuxapp/eal/eal_dev.c | 95 ++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 1 deletion(-)lib/librte_eal/common/include/rte_dev.h +2
-0@@ -24,6 +24,23 @@ extern "C" {#include <rte_compat.h> #include <rte_log.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128
Such macro shall be linux uevent specific, so put them in linuxapp folder.
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 35
Quoted 7 lines
lib/librte_eal/common/include/rte_dev.h +7
-0+ +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device has been scanned on bus*/ +RTE_DEV_PROBED ,/**< device has been probed driver */ +};
This enum is not used in this patch series, I do see it's used in the other series. So put the definition there.
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 38
Quoted 3 lines
lib/librte_eal/common/include/rte_dev.h +3
-0+ +enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UNKNOWN ,
I don't see where we use this macro. Seems that we now only implement UIO, so I suppose, we shall set the other cases to this UNKNOWN.
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 40
Quoted 2 lines
lib/librte_eal/common/include/rte_dev.h +2
-0+RTE_DEV_EVENT_SUBSYSTEM_UIO , + RTE_DEV_EVENT_SUBSYSTEM_VFIO,
If we don't support VFIO now, I prefer not defining it now.
Quoted 18 lines
lib/librte_eal/common/include/rte_dev.h +3
-0+ RTE_DEV_EVENT_SUBSYSTEM_MAX +}; +/** * The device event type. */lib/librte_eal/linuxapp/eal/eal_dev.c +3
-0@@ -78,9 +78,102 @@ dev_uev_monitor_create(int netlink_fd) }static void +dev_uev_parse (const char *buf,struct rte_dev_event *event) +{ +char action[RTE_EAL_UEV_MSG_ELEM_LEN ];
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 93
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+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 ); +
Maybe we can put an example here for better understanding.
And if this buf can contain multiple events? If yes, the implementation is not correct, we will only record one event; if no, we can simplify it a little bit.
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 99
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+while (i <RTE_EAL_UEV_MSG_LEN ) { +for (; i <RTE_EAL_UEV_MSG_LEN ; i++) { +if (*buf) +break ; + buf++; + }
If we pass in the length of the buf, we don't have to skip "\0"?
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 104
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +5
-0+/** +* check device uevent from kernel side, no need to check +* uevent from udev. +*/ +if (!strncmp (buf,"libudev" ,7 )) {
Use strcmp is enough. And we actually need to check left length enough for strlen("libudev").
Quoted 17 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +17
-0+ buf +=7 ; + i +=7 ; +return ; + } +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 )) {
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 131
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname = pci_slot_name; + } +for (; i <RTE_EAL_UEV_MSG_LEN ; i++) { +if (*buf =='\0' ) +break ; + buf++; + }
As we already check '\0' in the begin of the loop, we don't need it at the end any more.
Quoted 19 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +19
-0+ } + +if ((!strncmp (subsystem,"uio" ,3 )) || + (!strncmp (subsystem,"pci" ,3 ))) + event->subsystem =RTE_DEV_EVENT_SUBSYSTEM_UIO ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +} + +static int +dev_uev_receive (int fd,struct rte_dev_event *uevent) +{ +int ret; +char buf[RTE_EAL_UEV_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,RTE_EAL_UEV_MSG_LEN );
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 160
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ + 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 ;
So we are sure how many bytes shall be parsed, we can pass the length into dev_uev_parse().
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +4
-0+ +dev_uev_parse (buf, uevent); + +return 0 ;
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 173
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +7
-1+} + +static void dev_uev_process(__rte_unused void *param) { -/* TODO: device uevent processing */ +struct rte_dev_event uevent; + +if (dev_uev_receive (intr_handle.fd, &uevent)) +return ;
We don't use uevent->subsystem below, why we have to define it in first place?
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +3
-0+ +if (uevent.devname) +_rte_dev_callback_process (uevent.devname, uevent.type,NULL ); }int __rte_experimental
Re: [PATCH V15 2/5] eal: add uevent pass and process function
jianfeng, thanks for your review. almost make sense and comment as bellow.
Quoted 7 lines · Jianfeng
Quoted 3 lines · Jeff Guo
In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent.
Quoted 9 lines
In fact, how to pass the uevent to eal/linux for processing, is already done by last patch, by registering a callback into interrupt thread.
In this patch, we are actually showing how to process the uevent, and translate it into
RTE_DEV_EVENT_ADD,RTE_DEV_EVENT_DEL, etc.So the title would be something like:
eal/linux: translate uevent to dev event
sorry, that what i mean should be uevent message parse but not pass, and what you say make sense.
Quoted 10 lines
Quoted 7 lines
About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function.
a.dev_uev_parse
b.dev_uev_receive
c.dev_uev_processWe already have dummy
rte_dev_event_monitor_startandrte_dev_event_monitor_stop, we don't need to have those dummy internal functions any more. Actually, you did not implement those dummy functions.
yes, not dummy just internal function.
Quoted 11 lines
Quoted 8 lines
Signed-off-by Jeff Guo <[email protected]>---
v15->v14:
remove the uevent type check and any policy from eal, let it check and management in user's callback.--- lib/librte_eal/common/include/rte_dev.h | 17 ++++++And if you agree with me in the above, we shall not touch this file. Move the definition into the previous patch.
will check and split the definition more explicit.
Quoted 4 lines
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c | 95 ++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 1 deletion(-)
Quoted 12 lines
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 27
Quoted 9 lines
lib/librte_eal/common/include/rte_dev.h +1
-0@@ -24,6 +24,23 @@ extern "C" {#include <rte_compat.h> #include <rte_log.h> +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128Such macro shall be linux uevent specific, so put them in linuxapp folder.
agree.
Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 35
Quoted 7 lines
lib/librte_eal/common/include/rte_dev.h +7
-0+ +enum rte_dev_state { +RTE_DEV_UNDEFINED ,/**< unknown device state */ +RTE_DEV_FAULT ,/**< device fault or error */ +RTE_DEV_PARSED ,/**< device has been scanned on bus*/ +RTE_DEV_PROBED ,/**< device has been probed driver */ +};This enum is not used in this patch series, I do see it's used in the other series. So put the definition there.
yes.
Quoted 6 lines
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 38
Quoted 3 lines
lib/librte_eal/common/include/rte_dev.h +3
-0+ +enum rte_dev_event_subsystem { +RTE_DEV_EVENT_SUBSYSTEM_UNKNOWN ,I don't see where we use this macro. Seems that we now only implement UIO, so I suppose, we shall set the other cases to this UNKNOWN.
ok.
Quoted 5 lines
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 40
Quoted 2 lines
lib/librte_eal/common/include/rte_dev.h +2
-0+RTE_DEV_EVENT_SUBSYSTEM_UIO , + RTE_DEV_EVENT_SUBSYSTEM_VFIO,If we don't support VFIO now, I prefer not defining it now.
will remove it at this stage and add later.
Quoted 30 lines
Quoted 17 lines
lib/librte_eal/common/include/rte_dev.h +3
-0+ RTE_DEV_EVENT_SUBSYSTEM_MAX +}; +/** * The device event type. */ lib/librte_eal/linuxapp/eal/eal_dev.c +3
-0@@ -78,9 +78,102 @@ dev_uev_monitor_create(int netlink_fd) }static void +dev_uev_parse (const char *buf,struct rte_dev_event *event) +{ +char action[RTE_EAL_UEV_MSG_ELEM_LEN ];lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 92
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+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 ); +Maybe we can put an example here for better understanding.
Quoted 2 lines
And if this buf can contain multiple events? If yes, the implementation is not correct, we will only record one event; if no, we can simplify it a little bit.
the buf do not contain multiple event but will involve more string split by several "/0" , so need check that by bellow code.
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 99
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+while (i <RTE_EAL_UEV_MSG_LEN ) { +for (; i <RTE_EAL_UEV_MSG_LEN ; i++) { +if (*buf) +break ; + buf++; + }If we pass in the length of the buf, we don't have to skip "\0"?
the reason is show as above.
Quoted 36 lines
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 104
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +5
-0+/** +* check device uevent from kernel side, no need to check +* uevent from udev. +*/ +if (!strncmp (buf,"libudev" ,7 )) {Use strcmp is enough. And we actually need to check left length enough for
strlen("libudev").Quoted 17 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +17
-0+ buf +=7 ; + i +=7 ; +return ; + } +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 )) {lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 131
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname = pci_slot_name; + } +for (; i <RTE_EAL_UEV_MSG_LEN ; i++) { +if (*buf =='\0' ) +break ; + buf++; + }
Quoted 2 lines
As we already check '\0' in the begin of the loop, we don't need it at the end any more.
the reason is show as above.
Quoted 23 lines
Quoted 23 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +23
-0+ } + +if ((!strncmp (subsystem,"uio" ,3 )) || + (!strncmp (subsystem,"pci" ,3 ))) + event->subsystem =RTE_DEV_EVENT_SUBSYSTEM_UIO ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +} + +static int +dev_uev_receive (int fd,struct rte_dev_event *uevent) +{ +int ret; +char buf[RTE_EAL_UEV_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_dev_event )); +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,
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 160
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+"Socket read error(%d): %s\n" , + errno, strerror(errno)); +return -1 ; + }else if (ret ==0 ) +/* connection closed */ +return -1 ;So we are sure how many bytes shall be parsed, we can pass the length into
dev_uev_parse().
might be better from what you said.
Quoted 8 lines
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +7
-0+ +dev_uev_parse (buf, uevent); + +return 0 ; +} + +static void dev_uev_process(__rte_unused void *param)
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c dev_uev_monitor_create(int netlink_fd) · line 173
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +4
-1{ -/* TODO: device uevent processing */ +struct rte_dev_event uevent; + +if (dev_uev_receive (intr_handle.fd, &uevent)) +return ;We don't use
uevent->subsystembelow, why we have to define it in first place?
could check here and i will add that check only for uio now.
Quoted 6 lines
Quoted 5 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +3
-0+ +if (uevent.devname) +_rte_dev_callback_process (uevent.devname, uevent.type,NULL ); }int __rte_experimental
PATCH v15 3/5 app/testpmd: use uevent to monitor hotplug
In reply to Jeff Guouse testpmd for example, to show app how to request and use uevent monitoring to handle the hot removal event and the hot insertion event.
---v15->v14:
add "--hot-plug" configure parameter in testpmd to switch the hotplug feature
--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 194 +++++++++++++++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 11 +++ 3 files changed, 208 insertions(+), 2 deletions(-)
app/test-pmd/parameters.c +4 -1
@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enalbe hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE
@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };
@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);
app/test-pmd/testpmd.c +193 -1
273 lines not on this page · raw message
app/test-pmd/testpmd.h +11 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_kernel_driver dev_kdrv;/* kernel driver binded */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
@@ -319,6 +328,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
Signature · 1 line
2.7.4
v16 cover add device event monitor framework
About hot plug in dpdk, We already have proactive way to add/remove devices through APIs (rte_eal_hotplug_add/remove), and also have fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general mechanism to monitor hotplug event for all driver, now the hotplug interrupt event is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring 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:v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
v15->v14:
1.use exist eal interrupt epoll to replace of rte service usage for monitor thread, 2.add new device event handle type in eal interrupt.
3.remove the uevent type check and any policy from eal,
let it check and management in user's callback.
4.add "--hot-plug" configure parameter in testpmd to switch the hotplug feature.
v14->v13:
1.add __rte_experimental on function defind and fix bsd build issue
v13->v12:
1.fix some logic issue and null check issue
2.fix monitor stop func issue
v12->v11:
1.identify null param in callback for monitor all devices uevent
v11->v10:
1:modify some typo and add experimental tag in new file. 2:modify callback register calling.
v10->v9:
1.fix prefix issue.
2.use a common callback lists for all device and all type to replace add callback parameter into device struct.
3.delete some unuse part.
v9->v8:
split the patch set into small and explicit patch
v8->v7:
1.use rte_service to replace pthread management.
2.fix defind issue and copyright issue
3.fix some lock issue
v7->v6:
1.modify vdev part according to the vdev rework 2.re-define and split the func into common and bus specific code 3.fix some incorrect issue.
4.fix the system hung after send packcet issue.
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug.
2.modify to manage event callback in each device.
3.fix some system hung issue when igb_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 device event handle in interrupt thread
eal: add device event monitor framework app/testpmd: enable device hotplug monitoring
app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 195 ++++++++++++++++++++- app/test-pmd/testpmd.h | 11 ++ lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 19 ++ lib/librte_eal/common/eal_common_dev.c | 145 +++++++++++++++ lib/librte_eal/common/eal_private.h | 24 +++ lib/librte_eal/common/include/rte_dev.h | 92 ++++++++++ lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 20 +++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 5 +- 12 files changed, 516 insertions(+), 3 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
Signature · 1 line
2.7.4
PATCH v16 1/3 eal: add device event handle in interrupt thread
Add new interrupt handle type of RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.
---v16->v15:
split into small patch base on the function
--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/rte_eal_interrupts.h +1 -0
@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };
lib/librte_eal/linuxapp/eal/eal_interrupts.c +4 -1
@@ -674,7 +674,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
Signature · 1 line
2.7.4
PATCH v16 2/3 eal: add device event monitor framework
In reply to Jeff GuoThis patch aims to add a general device event monitor mechanism at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other type of device event monitor, but not in this scope at the stage.
To get started, users firstly register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_callback_register
-rte_dev_callback_unregister
Then application shall call below new added APIs to enable/disable the mechanism:
- rte_dev_event_monitor_start
- rte_dev_event_monitor_stop
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could be benifit for futher fail-safe or live-migration.
---v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 19 +++++ lib/librte_eal/common/eal_common_dev.c | 145 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 24 ++++++ lib/librte_eal/common/include/rte_dev.h | 92 ++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 20 +++++ 7 files changed, 302 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_dev.c +145 -0
157 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +24 -0
@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). *
@@ -205,4 +207,26 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type +* @param cb_arg +* callback parameter. +* +* @return +* - On success, return zero. +* - On failure, a negative value. +*/ +int __rte_experimental +dev_callback_process (char *device_name,enum rte_dev_event_type event, +void *cb_arg);#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +92 -0
102 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}
Signature · 1 line
2.7.4
PATCH v16 3/3 app/testpmd: enable device hotplug monitoring
In reply to Jeff GuoUse testpmd for example, to show an application how to use device event mechanism to monitor the hotplug event, involve both hot removal event and the hot insertion event.
The process is that, testpmd first enable hotplug monitoring and register the user's callback, when device being hotplug insertion or hotplug removal, the eal monitor the event and call user's callbacks, the application according their hot plug policy to detach or attach the device from the bus.
---v16->v15:
1.modify log and patch description.
--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 195 +++++++++++++++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 11 +++ 3 files changed, 209 insertions(+), 2 deletions(-)
app/test-pmd/parameters.c +4 -1
@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enalbe hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE
@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };
@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);
app/test-pmd/testpmd.c +194 -1
274 lines not on this page · raw message
app/test-pmd/testpmd.h +11 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_kernel_driver dev_kdrv;/* kernel driver binded */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
@@ -319,6 +328,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
Signature · 1 line
2.7.4
v16 cover add device event monitor framework
In reply to Jeff GuoAbout hot plug in dpdk, We already have proactive way to add/remove devices through APIs (rte_eal_hotplug_add/remove), and also have fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general mechanism to monitor hotplug event for all driver, now the hotplug interrupt event is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring 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:v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
v15->v14:
1.use exist eal interrupt epoll to replace of rte service usage for monitor thread, 2.add new device event handle type in eal interrupt.
3.remove the uevent type check and any policy from eal,
let it check and management in user's callback.
4.add "--hot-plug" configure parameter in testpmd to switch the hotplug feature.
v14->v13:
1.add __rte_experimental on function defind and fix bsd build issue
v13->v12:
1.fix some logic issue and null check issue
2.fix monitor stop func issue
v12->v11:
1.identify null param in callback for monitor all devices uevent
v11->v10:
1:modify some typo and add experimental tag in new file. 2:modify callback register calling.
v10->v9:
1.fix prefix issue.
2.use a common callback lists for all device and all type to replace add callback parameter into device struct.
3.delete some unuse part.
v9->v8:
split the patch set into small and explicit patch
v8->v7:
1.use rte_service to replace pthread management.
2.fix defind issue and copyright issue
3.fix some lock issue
v7->v6:
1.modify vdev part according to the vdev rework 2.re-define and split the func into common and bus specific code 3.fix some incorrect issue.
4.fix the system hung after send packcet issue.
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug.
2.modify to manage event callback in each device.
3.fix some system hung issue when igb_uioome typo error.release. 4.modify the pci part to the bus-pci base on the bus rework. 5.add hot plug policy in app, show example to use hotplug list to manage to deside which device need to hot plug.
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer.
2.Redefine the eal device API for common, and distinguish between linux and bsd
3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device. 5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue
7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables of hotplug_fd, add uevent_fd in rte_intr_handle to let each pci device self maintain it fd, to fix dual device fd issue.
2.refine some typo error.
Jeff Guo (4):
eal: add device event handle in interrupt thread
eal: add device event monitor framework eal/linux: uevent parse and process app/testpmd: enable device hotplug monitoring
app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 195 +++++++++++++++++- app/test-pmd/testpmd.h | 11 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 19 ++ lib/librte_eal/common/eal_common_dev.c | 145 +++++++++++++ lib/librte_eal/common/eal_private.h | 24 +++ lib/librte_eal/common/include/rte_dev.h | 92 +++++++++ lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 228 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 5 +- 12 files changed, 724 insertions(+), 3 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
Signature · 1 line
2.7.4
PATCH v16 1/4 eal: add device event handle in interrupt thread
Add new interrupt handle type of RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.
---v16->v15:
split into small patch base on the function
--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
lib/librte_eal/common/include/rte_eal_interrupts.h +1 -0
@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };
lib/librte_eal/linuxapp/eal/eal_interrupts.c +4 -1
@@ -674,7 +674,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
Signature · 1 line
2.7.4
Re: [PATCH V16 1/4] eal: add device event handle in interrupt thread
Hi,
Quoted 2 lines · Jeff Guo
Add new interrupt handle type of
RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.
A simple search of RTE_INTR_HANDLE_ALARM, we can see that we still need to update rte_intr_enable()/rte_intr_disable(), and test_interrupt_init().
Thanks,
Jianfeng
Quoted 38 lines
Signed-off-by Jeff Guo <[email protected]>---
v16->v15:
split into small patch base on the function--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)lib/librte_eal/common/include/rte_eal_interrupts.h +1
-0@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };lib/librte_eal/linuxapp/eal/eal_interrupts.c +4
-1@@ -674,7 +674,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
Re: [PATCH V16 1/4] eal: add device event handle in interrupt thread
jianfeng
Quoted 9 lines · Jianfeng
Hi,
Quoted 2 lines · Jeff Guo
Add new interrupt handle type of
RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.A simple search of
RTE_INTR_HANDLE_ALARM, we can see that we still need to update rte_intr_enable()/rte_intr_disable(), andtest_interrupt_init().
you are right about that.
Quoted 43 lines
Thanks,
JianfengQuoted 39 lines
Signed-off-by Jeff Guo <[email protected]>---
v16->v15:
split into small patch base on the function--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)lib/librte_eal/common/include/rte_eal_interrupts.h +1
-0@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ }; diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c
b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
index f86f22f..842acaa 100644lib/librte_eal/linuxapp/eal/eal_interrupts.c +4
-1@@ -674,7 +674,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break;
PATCH v16 2/4 eal: add device event monitor framework
In reply to Jeff GuoThis patch aims to add a general device event monitor mechanism at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other type of device event monitor, but not in this scope at the stage.
To get started, users firstly register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_callback_register
-rte_dev_callback_unregister
Then application shall call below new added APIs to enable/disable the mechanism:
- rte_dev_event_monitor_start
- rte_dev_event_monitor_stop
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could be benifit for futher fail-safe or live-migration.
---v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 19 +++++ lib/librte_eal/common/eal_common_dev.c | 145 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 24 ++++++ lib/librte_eal/common/include/rte_dev.h | 92 ++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 20 +++++ 7 files changed, 302 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_common_dev.c +145 -0
157 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +24 -0
@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). *
@@ -205,4 +207,26 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type +* @param cb_arg +* callback parameter. +* +* @return +* - On success, return zero. +* - On failure, a negative value. +*/ +int __rte_experimental +dev_callback_process (char *device_name,enum rte_dev_event_type event, +void *cb_arg);#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +92 -0
102 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}
Signature · 1 line
2.7.4
Re: [PATCH V16 2/4] eal: add device event monitor framework
Quoted 13 lines
-----Original Message-----
From: Guo, Jia
Sent: Monday, March 26, 2018 7:21 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V16 2/4] eal: add device event monitor framework
Quoted 1 line
This patch aims to add a general device event monitor mechanism at
mechanism -> framework?
Linux uevent is a mechanism.
Quoted 10 lines
EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other type of device event monitor, but not in this scope at the stage.
To get started, users firstly register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_callback_register
-rte_dev_callback_unregister
New APIs shall be added into rte_eal_version.map.
And also, we shall update the release note.
Quoted 4 lines
Then application shall call below new added APIs to enable/disable the mechanism:
-rte_dev_event_monitor_start
-rte_dev_event_monitor_stop
Do we really have the use case to keep the callbacks, but stop monitoring? I don't think we really need these two APIs to enable/disable.
Instead, if we have a callback registered, then enable it; if we don't have any callbacks, then it's definitely disabled.
Quoted 5 lines
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could be benifit for futher fail-safe or live-migration.
Typo: "be benifit " -> "benefit"
Typo: " futher" -> "further"
Quoted 87 lines
Signed-off-by Jeff Guo <[email protected]>---
v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 19 +++++ lib/librte_eal/common/eal_common_dev.c | 145 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 24 ++++++ lib/librte_eal/common/include/rte_dev.h | 92 ++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 20 +++++ 7 files changed, 302 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.clib/librte_eal/bsdapp/eal/Makefile +0
-0@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=
eal_lcore.c
SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_timer.cSRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_interrupts.cSRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_alarm.clib/librte_eal/bsdapp/eal/Makefile +1
-0+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.clib/librte_eal/bsdapp/eal/eal_dev.c new file +19
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}lib/librte_eal/common/eal_common_dev.c +16
-0@@ -14,9 +14,34 @@#include <rte_devargs.h> #include <rte_debug.h> #include <rte_log.h> +#include <rte_spinlock.h> +#include <rte_malloc.h> #include "eal_private.h" +/* spinlock for device callbacks */ +static rte_spinlock_t dev_event_lock =RTE_SPINLOCK_INITIALIZER ; + +/** +* The device event callback description. +* +* It contains callback address to be registered by user application, +* the pointer to the parameters for callback, and the device name. +*/ +struct dev_event_callback { +TAILQ_ENTRY (dev_event_callback) next;/**< Callbacks list */ +rte_dev_event_cb_fn cb_fn;/**< Callback address */ +void *cb_arg;/**< Callback parameter */ +char *dev_name;/**< Callback devcie name, NULL is for all
Quoted 1 line
device */
Typo: " devcie" -> "device"
Quoted 13 lines
lib/librte_eal/common/eal_common_dev.c +9
-0+uint32_t active;/**< Callback is executing */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (dev_event_cb_list, dev_event_callback); + +/* The device event callback list for all registered callbacks. */ +static struct dev_event_cb_list dev_event_cbs; +static int cmp_detached_dev_name (const struct rte_device *dev,const void *_name) {
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, · line 236
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +2
-0@@ -207,3 +232,123 @@ rte_eal_hotplug_remove(const char *busname, const char *devname)rte_eal_devargs_remove (busname ,devname );return ret; } + +static struct dev_event_callback * __rte_experimental
We don't have to flag an internal function as " __rte_experimental ".
Quoted 11 lines
lib/librte_eal/common/eal_common_dev.c +11
-0+dev_event_cb_find(const char *device_name, rte_dev_event_cb_fn cb_fn, + void *cb_arg) +{ + struct dev_event_callback *event_cb = NULL; + + TAILQ_FOREACH(event_cb, &(dev_event_cbs), next) { +if (event_cb->cb_fn == cb_fn && event_cb->cb_arg == cb_arg) { +if (device_name ==NULL && event_cb->dev_name ==NULL ) +break ; +if (device_name ==NULL || event_cb->dev_name ==NULL ) +continue ;
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 257
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (!strcmp (event_cb->dev_name, device_name)) +break ; + } + } +return event_cb; +} + +int __rte_experimental +rte_dev_callback_register (const char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg)
"rte_dev_event_callback_register" sounds more reasonable?
lib/librte_eal/common/eal_common_dev.c
Quoted 2 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+{ +struct dev_event_callback *event_cb =NULL ;
We don't need to initialize it to NULL.
Quoted 14 lines
lib/librte_eal/common/eal_common_dev.c +14
-0+ +if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&dev_event_lock); + +if (TAILQ_EMPTY (&(dev_event_cbs))) +TAILQ_INIT (&(dev_event_cbs)); + + event_cb =dev_event_cb_find (device_name, cb_fn, cb_arg); + +/* create a new callback. */ +if (event_cb ==NULL ) { + event_cb =malloc (sizeof (struct dev_event_callback ));
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 283
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (event_cb !=NULL ) { + event_cb->cb_fn = cb_fn; + event_cb->cb_arg = cb_arg; + event_cb->dev_name =strdup (device_name); +if (event_cb->dev_name ==NULL ) +return -EINVAL ; +TAILQ_INSERT_TAIL (&(dev_event_cbs), event_cb, next); + }else { +RTE_LOG (ERR ,EAL , +"Failed to allocate memory for device event callback" );
Miss the unlock here.
Quoted 17 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+return -ENOMEM ; + } + } + +rte_spinlock_unlock (&dev_event_lock); +return (event_cb ==NULL ) ? -EEXIST :0 ; +} + +int __rte_experimental +rte_dev_callback_unregister(const char *device_name,
rte_dev_event_cb_fncb_fn,lib/librte_eal/common/eal_common_dev.c +6
-0+ void *cb_arg) +{ +int ret =-1 ; +struct dev_event_callback *event_cb =NULL ; + +if (!cb_fn)
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 309
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+return -EINVAL ; + +rte_spinlock_lock (&dev_event_lock); + + event_cb =dev_event_cb_find (device_name, cb_fn, cb_arg); + +/* +* if this callback is not executing right now, +* then remove it. +*/
This note is not in right place.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 316
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+if (event_cb !=NULL ) { +if (event_cb->active ==0 ) { +TAILQ_REMOVE (&(dev_event_cbs), event_cb, next); +rte_free (event_cb); + ret =0 ; + } + ret = -EBUSY ;
Miss "else" for busy cb.
lib/librte_eal/common/eal_common_dev.c
Quoted 1 line
lib/librte_eal/common/eal_common_dev.c +1
-0+ }
Miss "else" for a cb which is not existed. And print an error log here.
Quoted 11 lines
lib/librte_eal/common/eal_common_dev.c +8
-0+ +rte_spinlock_unlock (&dev_event_lock); +return ret; +} + +int __rte_experimental +dev_callback_process (char *device_name,enum rte_dev_event_type event, +void *cb_arg)From interrupt thread, there is no
cb_arg.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 333
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c +8
-0+{ +struct dev_event_callback *cb_lst; +int rc =0 ; + +rte_spinlock_lock (&dev_event_lock); + +if (device_name ==NULL ) +return -EINVAL ;
Put such check out of lock. Or it's very easy to miss the unlock which is happening now.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 340
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+ + TAILQ_FOREACH(cb_lst, &dev_event_cbs, next) { +if (!cb_lst->dev_name) +break ; +else if (!strcmp (cb_lst->dev_name, device_name)) +break ; + }
We invoke only one callback. But for this device, we could have many callback to call.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 344
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +4
-0+if (cb_lst) { + cb_lst->active =1 ; +if (cb_arg) + cb_lst->cb_arg = cb_arg;
What's the reason of overwriting this cb_arg?
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 353
Quoted 9 lines
lib/librte_eal/common/eal_common_dev.c +9
-0+rte_spinlock_unlock (&dev_event_lock); + rc = cb_lst->cb_fn (device_name, event, + cb_lst->cb_arg); +rte_spinlock_lock (&dev_event_lock); + cb_lst->active =0 ; + } + +rte_spinlock_unlock (&dev_event_lock); +return rc;
What's the reason of returning the ret of a callback? I don't think we need to return anything here.
Quoted 16 lines
lib/librte_eal/common/eal_common_dev.c +1
-0+}lib/librte_eal/common/eal_private.h +2
-0@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). *
lib/librte_eal/common/eal_private.h struct rte_bus · line 213
Quoted 7 lines
lib/librte_eal/common/eal_private.h +3
-0@@ -205,4 +207,26 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice
It's not an API. We don't need this.
Quoted 7 lines
lib/librte_eal/common/eal_private.h +7
-0+* +* internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name.
lib/librte_eal/common/eal_private.h struct rte_bus *rte_bus_find_by_device_name(const char *str); · line 229
Quoted 10 lines
lib/librte_eal/common/eal_private.h +10
-0+* @param event +* the device event type +* @param cb_arg +* callback parameter. +* +* @return +* - On success, return zero. +* - On failure, a negative value. +*/ +int __rte_experimental
It's not an API, so don't add "__rte_experimental" flag.
lib/librte_eal/common/eal_private.h
Quoted 3 lines
lib/librte_eal/common/eal_private.h +1
-0+dev_callback_process(char *device_name, enum rte_dev_event_typeevent,
lib/librte_eal/common/eal_private.h +1
-0+ void *cb_arg);
As mentioned above, we don't have cb_arg from interrupt thread.
Quoted 7 lines
#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +0
-0
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 31
Quoted 8 lines
lib/librte_eal/common/include/rte_dev.h +5
-0@@ -24,6 +24,26 @@ extern "C" {#include <rte_compat.h> #include <rte_log.h> +/** +* The device event type. +*/ +enum rte_dev_event_type { +RTE_DEV_EVENT_UNKNOWN ,/**< unknown event type */
Again, why do we report an "unknown" event to applications?
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 40
Quoted 9 lines
lib/librte_eal/common/include/rte_dev.h +9
-0+RTE_DEV_EVENT_ADD ,/**< device being added */ +RTE_DEV_EVENT_REMOVE ,/**< device being removed */ +RTE_DEV_EVENT_MAX /**< max value of this enum */ +}; + +struct rte_dev_event { +enum rte_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */
I prefer to remove such note if we can already get the information from the variable name.
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 45
Quoted 5 lines
lib/librte_eal/common/include/rte_dev.h +5
-0+}; + +typedef int (*rte_dev_event_cb_fn )(char *device_name, +enum rte_dev_event_type event, +void *cb_arg);
"rte_dev_event_callback" sounds better than "rte_dev_event_cb_fn" to me.
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 294
Quoted 13 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+ __attribute__((format (printf,2 ,0 )))static inline void rte_pmd_debug_trace (const char *func_name,const char *fmt, ...)@@ -267,4 +287,76 @@ __attribute__((used)) = str }#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It registers the callback for the specific device.
"the" -> "a"
Besides, "It registers a callback for the specific device or all devices"
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 295
Quoted 1 line
lib/librte_eal/common/include/rte_dev.h +1
-0+* Multiple callbacks cal be registered at the same time.
"cal" -> "can"
Besides, above sentence sounds like this API can register multiple callbacks. Change to:
"Users can call this API multiple times to register multiple callbacks."
Quoted 112 lines
lib/librte_eal/common/include/rte_dev.h +37
-0+* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_callback_register (const char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It unregisters the callback according to the specified device. +* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, return the number of callback entities removed. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_callback_unregister(const char *device_name,
rte_dev_event_cb_fncb_fn,lib/librte_eal/common/include/rte_dev.h +29
-0+ void *cb_arg); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Start the device event monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_start (void); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Stop the device event monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_stop (void);#endif /* _RTE_DEV_H_ */ lib/librte_eal/linuxapp/eal/Makefile +0
-0@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=
eal_lcore.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_timer.cSRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_interrupts.cSRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_alarm.clib/librte_eal/linuxapp/eal/Makefile +1
-0+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.clib/librte_eal/linuxapp/eal/eal_dev.c new file +20
-1@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +} --2.7.4
Re: [PATCH V16 2/4] eal: add device event monitor framework
jianfeng
will correct every typo, and comment inline.
Quoted 29 lines · Jianfeng
Quoted 12 lines
-----Original Message-----
From: Guo, Jia
Sent: Monday, March 26, 2018 7:21 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V16 2/4] eal: add device event monitor frameworkQuoted 1 line
This patch aims to add a general device event monitor mechanism at
mechanism -> framework?
Linux uevent is a mechanism.Quoted 10 lines
EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other type of device event monitor, but not in this scope at the stage.
To get started, users firstly register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_callback_register
-rte_dev_callback_unregisterNew APIs shall be added into rte_eal_version.map.
And also, we shall update the release note.
Quoted 7 lines
Quoted 4 lines
Then application shall call below new added APIs to enable/disable the mechanism:
-rte_dev_event_monitor_start
-rte_dev_event_monitor_stopDo we really have the use case to keep the callbacks, but stop monitoring? I don't think we really need these two APIs to enable/disable.
Instead, if we have a callback registered, then enable it; if we don't have any callbacks, then it's definitely disabled.
you raise a good question, but if it is good readable to enable the monitor into the register function or let register into the enable function, should let we think about that.
Quoted 239 lines
Quoted 4 lines
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could be benifit for futher fail-safe or live-migration.
Typo: "be benifit " -> "benefit"
Typo: " futher" -> "further"Quoted 86 lines
Signed-off-by Jeff Guo <[email protected]>---
v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 19 +++++ lib/librte_eal/common/eal_common_dev.c | 145 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 24 ++++++ lib/librte_eal/common/include/rte_dev.h | 92 ++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 20 +++++ 7 files changed, 302 insertions(+)create mode 100644
lib/librte_eal/bsdapp/eal/eal_dev.ccreate mode 100644lib/librte_eal/linuxapp/eal/eal_dev.clib/librte_eal/bsdapp/eal/Makefile +0
-0@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=
eal_lcore.c
SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_timer.cSRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_interrupts.cSRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_alarm.clib/librte_eal/bsdapp/eal/Makefile +1
-0+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.clib/librte_eal/bsdapp/eal/eal_dev.c new file +19
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}lib/librte_eal/common/eal_common_dev.c +16
-0@@ -14,9 +14,34 @@#include <rte_devargs.h> #include <rte_debug.h> #include <rte_log.h> +#include <rte_spinlock.h> +#include <rte_malloc.h> #include "eal_private.h" +/* spinlock for device callbacks */ +static rte_spinlock_t dev_event_lock =RTE_SPINLOCK_INITIALIZER ; + +/** +* The device event callback description. +* +* It contains callback address to be registered by user application, +* the pointer to the parameters for callback, and the device name. +*/ +struct dev_event_callback { +TAILQ_ENTRY (dev_event_callback) next;/**< Callbacks list */ +rte_dev_event_cb_fn cb_fn;/**< Callback address */ +void *cb_arg;/**< Callback parameter */ +char *dev_name;/**< Callback devcie name, NULL is for all Quoted 1 line
device */
Typo: " devcie" -> "device"
Quoted 13 lines
lib/librte_eal/common/eal_common_dev.c +9
-0+uint32_t active;/**< Callback is executing */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (dev_event_cb_list, dev_event_callback); + +/* The device event callback list for all registered callbacks. */ +static struct dev_event_cb_list dev_event_cbs; +static int cmp_detached_dev_name (const struct rte_device *dev,const void *_name) {lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, · line 236
Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +2
-0@@ -207,3 +232,123 @@ rte_eal_hotplug_remove(const char *busname, const char *devname)rte_eal_devargs_remove (busname ,devname );return ret; } + +static struct dev_event_callback * __rte_experimentalWe don't have to flag an internal function as "
__rte_experimental".Quoted 11 lines
lib/librte_eal/common/eal_common_dev.c +11
-0+dev_event_cb_find(const char *device_name, rte_dev_event_cb_fn cb_fn, + void *cb_arg) +{ + struct dev_event_callback *event_cb = NULL; + + TAILQ_FOREACH(event_cb, &(dev_event_cbs), next) { +if (event_cb->cb_fn == cb_fn && event_cb->cb_arg == cb_arg) { +if (device_name ==NULL && event_cb->dev_name ==NULL ) +break ; +if (device_name ==NULL || event_cb->dev_name ==NULL ) +continue ;lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 257
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (!strcmp (event_cb->dev_name, device_name)) +break ; + } + } +return event_cb; +} + +int __rte_experimental +rte_dev_callback_register (const char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg)"
rte_dev_event_callback_register" sounds more reasonable?lib/librte_eal/common/eal_common_dev.c
Quoted 2 lines
lib/librte_eal/common/eal_common_dev.c +2
-0+{ +struct dev_event_callback *event_cb =NULL ;We don't need to initialize it to NULL.
Quoted 14 lines
lib/librte_eal/common/eal_common_dev.c +14
-0+ +if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&dev_event_lock); + +if (TAILQ_EMPTY (&(dev_event_cbs))) +TAILQ_INIT (&(dev_event_cbs)); + + event_cb =dev_event_cb_find (device_name, cb_fn, cb_arg); + +/* create a new callback. */ +if (event_cb ==NULL ) { + event_cb =malloc (sizeof (struct dev_event_callback ));lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 283
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+if (event_cb !=NULL ) { + event_cb->cb_fn = cb_fn; + event_cb->cb_arg = cb_arg; + event_cb->dev_name =strdup (device_name); +if (event_cb->dev_name ==NULL ) +return -EINVAL ; +TAILQ_INSERT_TAIL (&(dev_event_cbs), event_cb, next); + }else { +RTE_LOG (ERR ,EAL , +"Failed to allocate memory for device event callback" );Miss the unlock here.
Quoted 17 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+return -ENOMEM ; + } + } + +rte_spinlock_unlock (&dev_event_lock); +return (event_cb ==NULL ) ? -EEXIST :0 ; +} + +int __rte_experimental +rte_dev_callback_unregister(const char *device_name,
rte_dev_event_cb_fncb_fn,lib/librte_eal/common/eal_common_dev.c +6
-0+ void *cb_arg) +{ +int ret =-1 ; +struct dev_event_callback *event_cb =NULL ; + +if (!cb_fn)lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 309
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+return -EINVAL ; + +rte_spinlock_lock (&dev_event_lock); + + event_cb =dev_event_cb_find (device_name, cb_fn, cb_arg); + +/* +* if this callback is not executing right now, +* then remove it. +*/ This note is not in right place.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 316
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+if (event_cb !=NULL ) { +if (event_cb->active ==0 ) { +TAILQ_REMOVE (&(dev_event_cbs), event_cb, next); +rte_free (event_cb); + ret =0 ; + } + ret = -EBUSY ;Miss "else" for busy cb.
lib/librte_eal/common/eal_common_dev.c
Quoted 1 line
lib/librte_eal/common/eal_common_dev.c +1
-0+ }Miss "else" for a cb which is not existed. And print an error log here.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 325
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c +8
-0+ +rte_spinlock_unlock (&dev_event_lock); +return ret; +} + +int __rte_experimental +dev_callback_process (char *device_name,enum rte_dev_event_type event, +void *cb_arg)From interrupt thread, there is no
cb_arg.lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 333
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c +8
-0+{ +struct dev_event_callback *cb_lst; +int rc =0 ; + +rte_spinlock_lock (&dev_event_lock); + +if (device_name ==NULL ) +return -EINVAL ;Put such check out of lock. Or it's very easy to miss the unlock which is happening now.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 340
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +7
-0+ + TAILQ_FOREACH(cb_lst, &dev_event_cbs, next) { +if (!cb_lst->dev_name) +break ; +else if (!strcmp (cb_lst->dev_name, device_name)) +break ; + }We invoke only one callback. But for this device, we could have many callback to call.
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 344
Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +4
-0+if (cb_lst) { + cb_lst->active =1 ; +if (cb_arg) + cb_lst->cb_arg = cb_arg;What's the reason of overwriting this
cb_arg?
it is no used anymore here.
Quoted 230 lines
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 353
Quoted 9 lines
lib/librte_eal/common/eal_common_dev.c +9
-0+rte_spinlock_unlock (&dev_event_lock); + rc = cb_lst->cb_fn (device_name, event, + cb_lst->cb_arg); +rte_spinlock_lock (&dev_event_lock); + cb_lst->active =0 ; + } + +rte_spinlock_unlock (&dev_event_lock); +return rc;What's the reason of returning the ret of a callback? I don't think we need to return anything here.
Quoted 16 lines
lib/librte_eal/common/eal_common_dev.c +1
-0+}lib/librte_eal/common/eal_private.h +2
-0@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). * lib/librte_eal/common/eal_private.h struct rte_bus · line 213
Quoted 7 lines
lib/librte_eal/common/eal_private.h +3
-0@@ -205,4 +207,26 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice It's not an API. We don't need this.
Quoted 7 lines
lib/librte_eal/common/eal_private.h +7
-0+* +* internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. lib/librte_eal/common/eal_private.h struct rte_bus *rte_bus_find_by_device_name(const char *str); · line 229
Quoted 10 lines
lib/librte_eal/common/eal_private.h +10
-0+* @param event +* the device event type +* @param cb_arg +* callback parameter. +* +* @return +* - On success, return zero. +* - On failure, a negative value. +*/ +int __rte_experimentalIt's not an API, so don't add "
__rte_experimental" flag.lib/librte_eal/common/eal_private.h
Quoted 3 lines
lib/librte_eal/common/eal_private.h +1
-0+dev_callback_process(char *device_name, enum rte_dev_event_typeevent,
lib/librte_eal/common/eal_private.h +1
-0+ void *cb_arg);As mentioned above, we don't have
cb_argfrom interrupt thread.Quoted 7 lines
#endif /* _EAL_PRIVATE_H_ */lib/librte_eal/common/include/rte_dev.h +0
-0lib/librte_eal/common/include/rte_dev.h extern "C" { · line 31
Quoted 8 lines
lib/librte_eal/common/include/rte_dev.h +5
-0@@ -24,6 +24,26 @@ extern "C" {#include <rte_compat.h> #include <rte_log.h> +/** +* The device event type. +*/ +enum rte_dev_event_type { +RTE_DEV_EVENT_UNKNOWN ,/**< unknown event type */ Again, why do we report an "unknown" event to applications?
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 40
Quoted 9 lines
lib/librte_eal/common/include/rte_dev.h +9
-0+RTE_DEV_EVENT_ADD ,/**< device being added */ +RTE_DEV_EVENT_REMOVE ,/**< device being removed */ +RTE_DEV_EVENT_MAX /**< max value of this enum */ +}; + +struct rte_dev_event { +enum rte_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ I prefer to remove such note if we can already get the information from the variable name.
lib/librte_eal/common/include/rte_dev.h extern "C" { · line 45
Quoted 5 lines
lib/librte_eal/common/include/rte_dev.h +5
-0+}; + +typedef int (*rte_dev_event_cb_fn )(char *device_name, +enum rte_dev_event_type event, +void *cb_arg);"
rte_dev_event_callback" sounds better than "rte_dev_event_cb_fn" to me.lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 294
Quoted 13 lines
lib/librte_eal/common/include/rte_dev.h +6
-0+ __attribute__((format (printf,2 ,0 )))static inline void rte_pmd_debug_trace (const char *func_name,const char *fmt, ...)@@ -267,4 +287,76 @@ __attribute__((used)) = str }#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It registers the callback for the specific device. "the" -> "a"
Besides, "It registers a callback for the specific device or all devices"
lib/librte_eal/common/include/rte_dev.h __attribute__((used)) = str · line 295
Quoted 1 line
lib/librte_eal/common/include/rte_dev.h +1
-0+* Multiple callbacks cal be registered at the same time. "cal" -> "can"
Besides, above sentence sounds like this API can register multiple callbacks. Change to:
"Users can call this API multiple times to register multiple callbacks."Quoted 112 lines
lib/librte_eal/common/include/rte_dev.h +37
-0+* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_callback_register (const char *device_name,rte_dev_event_cb_fn cb_fn, +void *cb_arg); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It unregisters the callback according to the specified device. +* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, return the number of callback entities removed. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_callback_unregister(const char *device_name,
rte_dev_event_cb_fncb_fn,lib/librte_eal/common/include/rte_dev.h +29
-0+ void *cb_arg); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Start the device event monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_start (void); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Stop the device event monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_stop (void);#endif /* _RTE_DEV_H_ */ lib/librte_eal/linuxapp/eal/Makefile +0
-0@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=
eal_lcore.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_timer.cSRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_interrupts.cSRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_alarm.clib/librte_eal/linuxapp/eal/Makefile +1
-0+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.clib/librte_eal/linuxapp/eal/eal_dev.c new file +20
-1@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +} --2.7.4
PATCH v16 3/4 eal/linux: uevent parse and process
In reply to Jeff GuoIn order to handle the uevent which have been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribe to monitor.
---
1.move all linux specific together
--- lib/librte_eal/linuxapp/eal/eal_dev.c | 214 +++++++++++++++++++++++++++++++++- 1 file changed, 211 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal_dev.c +211 -3
@@ -2,19 +2,227 @@* Copyright(c) 2018 Intel Corporation */ -#include <rte_log.h> +#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 <fcntl.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_interrupts.h> + +#include "eal_private.h" +#include "eal_thread.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_not_started = true; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which event exposure from */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_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_uev_monitor_create (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)); + + 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_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char dev_path[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (dev_path,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"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); + event->devname = pci_slot_name; + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +} + +static int +dev_uev_receive (int fd,struct rte_dev_event *uevent) +{ +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s\n" , + errno,strerror (errno)); +return -1 ; + }else if (ret ==0 ) +/* connection closed */ +return -1 ; + +dev_uev_parse (buf, uevent,EAL_UEV_MSG_LEN ); + +return 0 ; +} + +static void +dev_uev_process(__rte_unused void *param) +{ +struct rte_dev_event uevent; + +if (dev_uev_receive (intr_handle.fd, &uevent)) +return ; + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type,NULL ); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (!monitor_not_started) +return 0 ; + + intr_handle.fd =dev_uev_monitor_fd_new (); + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + + ret =dev_uev_monitor_create (intr_handle.fd); + +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event monitor\n" ); +return -1 ; + } + + ret =rte_intr_callback_register (&intr_handle, dev_uev_process,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback\n" ); +return -1 ; + } + + monitor_not_started = false; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (monitor_not_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_process,NULL ); +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_not_started = true;return 0 ; }
Signature · 1 line
2.7.4
Re: [PATCH V16 3/4] eal/linux: uevent parse and process
BTW, adding new .c file needs to update meson.build now.
Quoted 21 lines · Jeff Guo
In order to handle the uevent which have been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribe to monitor.
Signed-off-by Jeff Guo <[email protected]>---
1.move all linux specific together--- lib/librte_eal/linuxapp/eal/eal_dev.c | 214 +++++++++++++++++++++++++++++++++- 1 file changed, 211 insertions(+), 3 deletions(-)lib/librte_eal/linuxapp/eal/eal_dev.c +1
-1@@ -2,19 +2,227 @@* Copyright(c) 2018 Intel Corporation */ -#include <rte_log.h> +#include <stdio.h>
lib/librte_eal/linuxapp/eal/eal_dev.c line 15
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+#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>
Some header files are not necessary, the above one for example.
lib/librte_eal/linuxapp/eal/eal_dev.c line 22
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+#include <stdbool.h> +#include <fcntl.h> + +#include <rte_malloc.h> +#include <rte_bus.h> #include <rte_dev.h> +#include <rte_devargs.h>
We don't need this one neither.
lib/librte_eal/linuxapp/eal/eal_dev.c line 28
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+#include <rte_debug.h> +#include <rte_log.h> +#include <rte_interrupts.h> + +#include "eal_private.h" +#include "eal_thread.h"
Ditto.
lib/librte_eal/linuxapp/eal/eal_dev.c line 30
Quoted 2 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +2
-0+ +static struct rte_intr_handle intr_handle = {.fd =-1 };
I don't think we need a static intr_handle, what we need is the monitor fd.
Quoted 19 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +19
-0+static bool monitor_not_started = true; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which event exposure from */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_monitor_fd_new (void ) +{ +int uevent_fd; + + uevent_fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC | + SOCK_NONBLOCK,
lib/librte_eal/linuxapp/eal/eal_dev.c line 59
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ NETLINK_KOBJECT_UEVENT); +if (uevent_fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed\n" ); +return -1 ; + } +return uevent_fd; +} + +static int +dev_uev_monitor_create (int netlink_fd)
I think we should merge this function with above function. I don't see a reason to split into two functions.
lib/librte_eal/linuxapp/eal/eal_dev.c line 72
Quoted 13 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +13
-0+{ +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" );
Please print more information here, so that we don't have to check the code if we really encounter such an error.
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +8
-0+ goto err; + } + +setsockopt (netlink_fd,SOL_SOCKET ,SO_PASSCRED , &size,sizeof (size)); + + ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"ioctl(FIONBIO) failed\n" );
lib/librte_eal/linuxapp/eal/eal_dev.c line 90
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ goto err; + } +return 0 ; +err: +close (netlink_fd); +return -1 ; +} + +static void +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length)
We always get an event we care? If no, we need return something so that the caller can skip this event.
lib/librte_eal/linuxapp/eal/eal_dev.c line 101
Quoted 11 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +11
-0+{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char dev_path[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (dev_path,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN );
I did not see you need dev_path, why do we care to parse it?
Quoted 14 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +14
-0+ +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ;
lib/librte_eal/linuxapp/eal/eal_dev.c line 125
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+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); + event->devname = pci_slot_name;
You are assigning a stack pointer for the caller to use; this is dangerous, we should never do that.
Quoted 22 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +22
-0+ } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +} + +static int +dev_uev_receive (int fd,struct rte_dev_event *uevent) +{ +int ret;
lib/librte_eal/linuxapp/eal/eal_dev.c line 157
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+char buf[EAL_UEV_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s\n" , + errno,strerror (errno));
The above three lines are in bad format.
Quoted 73 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +59
-2+return -1 ; + }else if (ret ==0 ) +/* connection closed */ +return -1 ; + +dev_uev_parse (buf, uevent,EAL_UEV_MSG_LEN ); + +return 0 ; +} + +static void +dev_uev_process(__rte_unused void *param) +{ +struct rte_dev_event uevent; + +if (dev_uev_receive (intr_handle.fd, &uevent)) +return ; + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type,NULL ); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (!monitor_not_started) +return 0 ; + + intr_handle.fd =dev_uev_monitor_fd_new (); + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + + ret =dev_uev_monitor_create (intr_handle.fd); + +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event monitor\n" ); +return -1 ; + } + + ret =rte_intr_callback_register (&intr_handle, dev_uev_process,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback\n" ); +return -1 ; + } + + monitor_not_started = false; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (monitor_not_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_process,NULL ); +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_not_started = true;return 0 ; }
Re: [PATCH V16 3/4] eal/linux: uevent parse and process
Two additional input along with Jianfeng's existing comments;
Quoted 24 lines
-----Original Message-----
From: Tan, Jianfeng
Sent: Wednesday, March 28, 2018 5:16 PM
To: Guo, Jia <[email protected]>; [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; Wu, Jingjing <[email protected]>; [email protected]; [email protected]; Van Haaren, Harry <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Zhang, Helin <[email protected]>
Subject: Re: [PATCH V16 3/4] eal/linux: uevent parse and processBTW, adding new .c file needs to update meson.build now.
Quoted 9 lines · Jeff Guo
In order to handle the uevent which have been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribe to monitor.
Signed-off-by Jeff Guo <[email protected]>---
1.move all linux specific together--- lib/librte_eal/linuxapp/eal/eal_dev.c | 214
Quoted 7 lines
+++++++++++++++++++++++++++++++++-
Review
Quoted 3 lines
1 file changed, 211 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/lib/librte_eal/linuxapp/eal/eal_dev.cQuoted 1 line
+static bool
monitor_not_started= true;
This variable should be named "monitor_started", as it is a static var it will be zero by default, and the following code is easier to read:
if ( !not_started ) becomes if (started)
Quoted 11 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 189
Quoted 11 lines
int __rte_experimental rte_dev_event_monitor_start(void) {lib/librte_eal/linuxapp/eal/eal_dev.c +7
-1-/* TODO: start uevent monitor for linux */ +int ret; + +if (!monitor_not_started) +return 0 ; + + intr_handle.fd =dev_uev_monitor_fd_new (); + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ;
dev_uev_monitor_fd_new() can return -1 on error, we should check for that case here.
Re: [PATCH V16 3/4] eal/linux: uevent parse and process
hi, harry
thanks for your review.
Quoted 29 lines · Harry
Two additional input along with Jianfeng's existing comments;
Quoted 27 lines
-----Original Message-----
From: Tan, Jianfeng
Sent: Wednesday, March 28, 2018 5:16 PM
To: Guo, Jia <[email protected]>; [email protected]; Richardson, Bruce <[email protected]>; Yigit, Ferruh <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; Wu, Jingjing <[email protected]>; [email protected]; [email protected]; Van Haaren, Harry <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Zhang, Helin <[email protected]>
Subject: Re: [PATCH V16 3/4] eal/linux: uevent parse and processBTW, adding new .c file needs to update meson.build now.
Quoted 9 lines · Jeff Guo
In order to handle the uevent which have been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribe to monitor.
Signed-off-by Jeff Guo <[email protected]>---
1.move all linux specific together--- lib/librte_eal/linuxapp/eal/eal_dev.c | 214+++++++++++++++++++++++++++++++++-
Quoted 2 lines
1 file changed, 211 insertions(+), 3 deletions(-)
Quoted 9 lines
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +0
-0
b/lib/librte_eal/linuxapp/eal/eal_dev.cQuoted 1 line
+static bool
monitor_not_started= true;This variable should be named "
monitor_started", as it is a static var it will be zero by default, and the following code is easier to read:if ( !not_started ) becomes if (started)
make sense.
Quoted 14 lines
Quoted 12 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 189
Quoted 12 lines
int __rte_experimental rte_dev_event_monitor_start(void) {lib/librte_eal/linuxapp/eal/eal_dev.c +7
-1-/* TODO: start uevent monitor for linux */ +int ret; + +if (!monitor_not_started) +return 0 ; + + intr_handle.fd =dev_uev_monitor_fd_new (); + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ;
dev_uev_monitor_fd_new()can return -1 on error, we should check for that case here.
you are right.
Re: [PATCH V16 3/4] eal/linux: uevent parse and process
In reply to Tan, Jianfengjianfeng
Quoted 2 lines · Jianfeng
BTW, adding new .c file needs to update meson.build now.
thanks for your info .
Quoted 82 lines · Jeff Guo
Quoted 21 lines
In order to handle the uevent which have been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribe to monitor.
Signed-off-by Jeff Guo <[email protected]>---
1.move all linux specific together--- lib/librte_eal/linuxapp/eal/eal_dev.c | 214 +++++++++++++++++++++++++++++++++- 1 file changed, 211 insertions(+), 3 deletions(-)lib/librte_eal/linuxapp/eal/eal_dev.c +1
-0@@ -2,19 +2,227 @@* Copyright(c) 2018 Intel Corporation */ -#include <rte_log.h> +#include <stdio.h> lib/librte_eal/linuxapp/eal/eal_dev.c line 15
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+#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> Some header files are not necessary, the above one for example.
lib/librte_eal/linuxapp/eal/eal_dev.c line 22
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+#include <stdbool.h> +#include <fcntl.h> + +#include <rte_malloc.h> +#include <rte_bus.h> #include <rte_dev.h> +#include <rte_devargs.h> We don't need this one neither.
lib/librte_eal/linuxapp/eal/eal_dev.c line 28
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+#include <rte_debug.h> +#include <rte_log.h> +#include <rte_interrupts.h> + +#include "eal_private.h" +#include "eal_thread.h" Ditto.
lib/librte_eal/linuxapp/eal/eal_dev.c line 30
Quoted 2 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +2
-0+ +static struct rte_intr_handle intr_handle = {.fd =-1 };I don't think we need a static
intr_handle, what we need is the monitor fd.Quoted 23 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +23
-0+static bool monitor_not_started = true; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which event exposure from */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_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 ;
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 59
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+ } +return uevent_fd; +} + +static int +dev_uev_monitor_create (int netlink_fd)I think we should merge this function with above function. I don't see a reason to split into two functions.
make sense.
Quoted 30 lines
Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +4
-0+{ +struct sockaddr_nl addr; +int ret; +int size =64 *1024 ;lib/librte_eal/linuxapp/eal/eal_dev.c line 72
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +9
-0+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" );Please print more information here, so that we don't have to check the code if we really encounter such an error.
Quoted 13 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +12
-0+ goto err; + } + +setsockopt (netlink_fd,SOL_SOCKET ,SO_PASSCRED , &size,sizeof (size)); + + ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"ioctl(FIONBIO) failed\n" ); + goto err; + } +return 0 ; +err:
Quoted 9 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 90
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+close (netlink_fd); +return -1 ; +} + +static void +dev_uev_parse (const char *buf,struct rte_dev_event *event,int length)We always get an event we care? If no, we need return something so that the caller can skip this event.
this function do no filter the event.
Quoted 39 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 101
Quoted 11 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +11
-0+{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char dev_path[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (dev_path,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN );I did not see you need
dev_path, why do we care to parse it?Quoted 14 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +14
-0+ +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"DEVPATH=" ,8 )) { + buf +=8 ; + i +=8 ;lib/librte_eal/linuxapp/eal/eal_dev.c line 125
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+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); + event->devname = pci_slot_name;
Quoted 2 lines
You are assigning a stack pointer for the caller to use; this is dangerous, we should never do that.
make sense.
Quoted 109 lines
Quoted 22 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +22
-0+ } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +} + +static int +dev_uev_receive (int fd,struct rte_dev_event *uevent) +{ +int ret;lib/librte_eal/linuxapp/eal/eal_dev.c line 157
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+char buf[EAL_UEV_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s\n" , + errno,strerror (errno));The above three lines are in bad format.
Quoted 73 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +59
-2+return -1 ; + }else if (ret ==0 ) +/* connection closed */ +return -1 ; + +dev_uev_parse (buf, uevent,EAL_UEV_MSG_LEN ); + +return 0 ; +} + +static void +dev_uev_process(__rte_unused void *param) +{ +struct rte_dev_event uevent; + +if (dev_uev_receive (intr_handle.fd, &uevent)) +return ; + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type,NULL ); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (!monitor_not_started) +return 0 ; + + intr_handle.fd =dev_uev_monitor_fd_new (); + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + + ret =dev_uev_monitor_create (intr_handle.fd); + +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event monitor\n" ); +return -1 ; + } + + ret =rte_intr_callback_register (&intr_handle, dev_uev_process,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback\n" ); +return -1 ; + } + + monitor_not_started = false; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (monitor_not_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_process,NULL ); +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback" ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_not_started = true;return 0 ; }
PATCH v16 4/4 app/testpmd: enable device hotplug monitoring
In reply to Jeff GuoUse testpmd for example, to show an application how to use device event mechanism to monitor the hotplug event, involve both hot removal event and the hot insertion event.
The process is that, testpmd first enable hotplug monitoring and register the user's callback, when device being hotplug insertion or hotplug removal, the eal monitor the event and call user's callbacks, the application according their hot plug policy to detach or attach the device from the bus.
---
1.modify log and patch description.
--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 195 +++++++++++++++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 11 +++ 3 files changed, 209 insertions(+), 2 deletions(-)
app/test-pmd/parameters.c +4 -1
@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enalbe hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE
@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };
@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);
app/test-pmd/testpmd.c +194 -1
274 lines not on this page · raw message
app/test-pmd/testpmd.h +11 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_kernel_driver dev_kdrv;/* kernel driver binded */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
@@ -319,6 +328,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
Signature · 1 line
2.7.4
Re: [PATCH V16 4/4] app/testpmd: enable device hotplug monitoring
Quoted 2 lines · Jeff Guo
Use testpmd for example, to show an application how to use device event mechanism to monitor the hotplug event, involve both hot removal event
involve -> including
Quoted 7 lines
and the hot insertion event.
The process is that, testpmd first enable hotplug monitoring and register the user's callback, when device being hotplug insertion or hotplug removal, the eal monitor the event and call user's callbacks, the application according their hot plug policy to detach or attach the device from the bus.
You are not exactly describing what's done in this example. From what I see, you only implement hot-unplug. For hot-plug, we will need to register callback with dev_name of NULL.
And without the other patch series, this only works without starting datapath.
Quoted 115 lines
Signed-off-by Jeff Guo <[email protected]>---
1.modify log and patch description.--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 195 +++++++++++++++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 11 +++ 3 files changed, 209 insertions(+), 2 deletions(-)app/test-pmd/parameters.c +4
-1@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enalbe hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE @@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);app/test-pmd/testpmd.c +35
-0@@ -12,6 +12,7 @@#include <sys/mman.h> #include <sys/types.h> #include <errno.h> +#include <stdbool.h> #include <sys/queue.h> #include <sys/stat.h> @@ -284,6 +285,9 @@ uint8_t lsc_interrupt = 1; /* enabled by default */*/ uint8_t rmv_interrupt =1 ;/* enabled by default */ + +uint8_t hot_plug =0 ;/**< hotplug disabled by default. */ +/* * Display or mask ether events * Default to all events except VF_MBOX @@ -384,6 +388,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);@@ -391,6 +397,14 @@ static void check_all_ports_link_status(uint32_t port_mask);static int eth_event_callback (portid_t port_id,enum rte_eth_event_type type,void *param,void *ret_param); +static int eth_dev_event_callback (char *device_name, +enum rte_dev_event_type type, +void *param); +static int eth_dev_event_callback_register (portid_t port_id); +static bool in_hotplug_list (const char *dev_name); + +static int hotplug_list_add (struct rte_device *device, +enum rte_kernel_driver device_kdrv);/* * Check if all the ports are started. @@ -1853,6 +1867,27 @@ reset_port(portid_t pid)printf ("Done\n" ); } +static int +eth_dev_event_callback_register (portid_t port_id) +{ +int diag; +char device_name[128 ]; + +snprintf (device_name,sizeof (device_name), +"%s" , rte_eth_devices[port_id].device->name); + +/* register the dev_event callback */ + + diag =rte_dev_callback_register (device_name, + eth_dev_event_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +return 0 ; +} +void attach_port (char *identifier) {
app/test-pmd/testpmd.c attach_port(char *identifier) · line 1907
Quoted 4 lines
app/test-pmd/testpmd.c +1
-0@@ -1869,6 +1904,8 @@ attach_port(char *identifier)if (rte_eth_dev_attach (identifier, &pi))return ; +eth_dev_event_callback_register (pi);
What's the difference with below one?
Quoted 134 lines
app/test-pmd/testpmd.c +99
-0+ socket_id = (unsigned )rte_eth_dev_socket_id (pi);/* if socket_id is invalid, set to 0 */ if (check_socket_id (socket_id) <0 )@@ -1880,6 +1917,12 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +if (hot_plug) { +hotplug_list_add (rte_eth_devices[pi].device, + rte_eth_devices[pi].data->kdrv); +eth_dev_event_callback_register (pi); + } +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }@@ -1906,6 +1949,12 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +if (hot_plug) { +hotplug_list_add (rte_eth_devices[port_id].device, + rte_eth_devices[port_id].data->kdrv); +eth_dev_event_callback_register (port_id); + } +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );@@ -1929,6 +1978,9 @@ pmd_test_exit(void)close_port (pt_id); } } + +rte_dev_event_monitor_stop (); +printf ("\nBye...\n" ); }@@ -2013,6 +2065,49 @@ rmv_event_callback(void *arg) dev->device->name); } +static void +rmv_dev_event_callback (void *arg) +{ +char name[RTE_ETH_NAME_MAX_LEN ]; +uint8_t port_id = (intptr_t )arg; + +rte_eal_alarm_cancel (rmv_dev_event_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_dev_event_callback (void *arg) +{ +char *dev_name = (char *)arg; + +rte_eal_alarm_cancel (add_dev_event_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,@@ -2059,6 +2154,86 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,return 0 ; } +static bool +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 true; + +return false; +} + +static int +hotplug_list_add (struct rte_device *device,enum rte_kernel_driver device_kdrv) +{ +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 = device->name; + hp_request->dev_kdrv = device_kdrv; + +TAILQ_INSERT_TAIL (&hp_list, hp_request, next); + +return 0 ; +} + +/* This function is used by the interrupt thread */ +static int +eth_dev_event_callback(char *device_name, enum rte_dev_event_type type,
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2206
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+ void *arg) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_UNKNOWN ] ="Unknown" , + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; +char *dev_name =malloc (strlen (device_name) +1 ); + +strcpy (dev_name, device_name);
strdup is easier?
Quoted 5 lines
app/test-pmd/testpmd.c +5
-0+ +if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr);
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2221
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+ }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_dev_event_callback, arg))
Why not rmv_dev_event_callback directly?
Besides, the name of rmv_dev_event_callback is really confusing. It's not a dev event callback.
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2229
Quoted 8 lines
app/test-pmd/testpmd.c +8
-0+fprintf (stderr, +"Could not set up deferred device removal\n" ); +break ; +case RTE_DEV_EVENT_ADD : +if (rte_eal_alarm_set (100000 , + add_dev_event_callback, dev_name)) +fprintf (stderr, +"Could not set up deferred device add\n" );
Ditto.
Quoted 30 lines
app/test-pmd/testpmd.c +14
-1+break ; +default : +break ; + } +return 0 ; +} +static int set_tx_queue_stats_mapping_registers (portid_t port_id,struct rte_port *port) {@@ -2474,8 +2649,9 @@ signal_handler(int signum)int main (int argc,char ** argv) { -int diag; +int diag;portid_t port_id; +int ret;signal (SIGINT , signal_handler);signal (SIGTERM , signal_handler);@@ -2543,6 +2719,23 @@ main(int argc, char** argv) nb_rxq, nb_txq);init_config (); + +if (hot_plug) { +/* enable hot plug monitoring */ + ret =rte_dev_event_monitor_start (); +if (ret) {
app/test-pmd/testpmd.c main(int argc, char** argv) · line 2736
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+ rte_errno =EINVAL ; +return -1 ; + } +if (TAILQ_EMPTY (&hp_list)) +TAILQ_INIT (&hp_list); +RTE_ETH_FOREACH_DEV (port_id) { +hotplug_list_add (rte_eth_devices[port_id].device, + rte_eth_devices[port_id].data->kdrv); +eth_dev_event_callback_register (port_id); + }
Why not monitoring all devices with dev_name of NULL? It makes things much easier. And we can also monitor the hot-plug event.
Quoted 34 lines
app/test-pmd/testpmd.c +2
-0+ } +if (start_port (RTE_PORT_ALL ) !=0 )rte_exit (EXIT_FAILURE ,"Start ports failed\n" );app/test-pmd/testpmd.h +11
-0@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_kernel_driver dev_kdrv;/* kernel driver binded */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,@@ -319,6 +328,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
v17 cover add device event monitor framework
In reply to Jeff GuoAbout hot plug in dpdk, We already have proactive way to add/remove devices through APIs (rte_eal_hotplug_add/remove), and also have fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general mechanism to monitor hotplug event for all driver, now the hotplug interrupt event is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring 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:v17->v16:
1.add related part of the interrupt handle type adding.
2.add new API into map, fix typo issue, add (void*)-1 value for unregister all callback 3.add new file into meson.build, modify coding sytle and add print info, delete unused part. 4.unregister all user's callback when stop event monitor
v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
v15->v14:
1.use exist eal interrupt epoll to replace of rte service usage for monitor thread, 2.add new device event handle type in eal interrupt.
3.remove the uevent type check and any policy from eal,
let it check and management in user's callback.
4.add "--hot-plug" configure parameter in testpmd to switch the hotplug feature.
v14->v13:
1.add __rte_experimental on function defind and fix bsd build issue
v13->v12:
1.fix some logic issue and null check issue
2.fix monitor stop func issue
v12->v11:
1.identify null param in callback for monitor all devices uevent
v11->v10:
1:modify some typo and add experimental tag in new file. 2:modify callback register calling.
v10->v9:
1.fix prefix issue.
2.use a common callback lists for all device and all type to replace add callback parameter into device struct.
3.delete some unuse part.
v9->v8:
split the patch set into small and explicit patch
v8->v7:
1.use rte_service to replace pthread management.
2.fix defind issue and copyright issue
3.fix some lock issue
v7->v6:
1.modify vdev part according to the vdev rework 2.re-define and split the func into common and bus specific code 3.fix some incorrect issue.
4.fix the system hung after send packcet issue.
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug.
2.modify to manage event callback in each device.
3.fix some system hung issue when igb_uioome typo error.release. 4.modify the pci part to the bus-pci base on the bus rework. 5.add hot plug policy in app, show example to use hotplug list to manage to deside which device need to hot plug.
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer.
2.Redefine the eal device API for common, and distinguish between linux and bsd
3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device. 5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue
7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables of hotplug_fd, add uevent_fd in rte_intr_handle to let each pci device self maintain it fd, to fix dual device fd issue.
2.refine some typo error.
Jeff Guo (4):
eal: add device event handle in interrupt thread
eal: add device event monitor framework eal/linux: uevent parse and process app/testpmd: enable device hotplug monitoring
app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 242 ++++++++++++++++++++- app/test-pmd/testpmd.h | 11 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 19 ++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 149 +++++++++++++ lib/librte_eal/common/eal_private.h | 15 ++ lib/librte_eal/common/include/rte_dev.h | 94 ++++++++ lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 205 +++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +- lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 2 + test/test/test_interrupts.c | 39 +++- 16 files changed, 792 insertions(+), 5 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
Signature · 1 line
2.7.4
PATCH v17 1/4 eal: add device event handle in interrupt thread
Add new interrupt handle type of RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.
---v17->v16:
add related part of the interrupt handle type adding.
--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++- test/test/test_interrupts.c | 39 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_eal_interrupts.h +1 -0
@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10 -1
@@ -559,6 +559,9 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -606,6 +609,9 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -674,7 +680,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
test/test/test_interrupts.c +37 -2
@@ -20,6 +20,7 @@ enum test_interrupt_handle_type {TEST_INTERRUPT_HANDLE_VALID ,TEST_INTERRUPT_HANDLE_VALID_UIO ,TEST_INTERRUPT_HANDLE_VALID_ALARM , +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ,TEST_INTERRUPT_HANDLE_CASE1 , TEST_INTERRUPT_HANDLE_MAX };
@@ -80,6 +81,10 @@ test_interrupt_init(void) intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM ].type =RTE_INTR_HANDLE_ALARM ; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].fd = pfds.readfd; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].type = +RTE_INTR_HANDLE_DEV_EVENT ; + intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].fd = pfds.writefd; intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].type =RTE_INTR_HANDLE_UIO ;
@@ -250,6 +255,14 @@ test_interrupt_enable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_enable (&test_intr_handle) ==0 ) { +printf ("unexpectedly enable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_enable (&test_intr_handle) <0 ) {
@@ -306,6 +319,14 @@ test_interrupt_disable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_disable (&test_intr_handle) ==0 ) { +printf ("unexpectedly disable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_disable (&test_intr_handle) <0 ) {
@@ -393,9 +414,17 @@ test_interrupt(void) goto out; } +printf ("Check valid device event interrupt full path\n" ); +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEVICE_EVENT ) <0 ) { +printf ("failure occurred during checking valid device event " +"interrupt full path\n" ); + goto out; + } +printf ("Check valid alarm interrupt full path\n" ); -if (test_interrupt_full_path_check (TEST_INTERRUPT_HANDLE_VALID_ALARM ) - <0 ) { +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) {printf ("failure occurred during checking valid alarm " "interrupt full path\n" ); goto out;
@@ -513,6 +542,12 @@ test_interrupt(void)rte_intr_callback_unregister (&test_intr_handle, test_interrupt_callback_1, (void *)-1 ); + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback, (void *)-1 ); +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback_1, (void *)-1 ); +rte_delay_ms (2 *TEST_INTERRUPT_CHECK_INTERVAL );/* deinit */ test_interrupt_deinit ();
Signature · 1 line
2.7.4
PATCH v17 2/4 eal: add device event monitor framework
In reply to Jeff GuoThis patch aims to add a general device event monitor framework at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other type of device event monitor, but not in this scope at the stage.
To get started, users firstly call below new added APIs to enable/disable the device event monitor mechanism:
- rte_dev_event_monitor_start
- rte_dev_event_monitor_stop
Then users shell register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_event_callback_register -rte_dev_event_callback_unregister
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could benefit for further fail-safe or live-migration.
---v17->v16:
add new API into map, fix typo issue, add (void*)-1 value for unregister all callback
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 19 ++++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 149 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 ++++ lib/librte_eal/common/include/rte_dev.h | 94 ++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 20 +++++ lib/librte_eal/rte_eal_version.map | 2 + 9 files changed, 302 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/bsdapp/eal/meson.build +1 -0
@@ -12,4 +12,5 @@ env_sources = files('eal_alarm.c', 'eal_timer.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c' )
lib/librte_eal/common/eal_common_dev.c +149 -0
161 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +15 -0
@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). *
@@ -205,4 +207,17 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* Internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type. +* +*/ +void +dev_callback_process (char *device_name,enum rte_dev_event_type event);#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +94 -0
104 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}
lib/librte_eal/rte_eal_version.map +2 -0
@@ -254,5 +254,7 @@ EXPERIMENTAL { rte_service_set_runstate_mapped_check; rte_service_set_stats_enable; rte_service_start_with_defaults; + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; } DPDK_18.02;
Signature · 1 line
2.7.4
PATCH v17 3/4 eal/linux: uevent parse and process
In reply to Jeff GuoIn order to handle the uevent which have been detected from the kernel side, add uevent parse and process function to translate the uevent into device event, which user has subscribe to monitor.
---v17->v16:
add new file into meson.build, modify coding sytle and add print info, delete unused part.
--- lib/librte_eal/linuxapp/eal/eal_dev.c | 191 +++++++++++++++++++++++++++++++- lib/librte_eal/linuxapp/eal/meson.build | 1 + 2 files changed, 189 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal_dev.c +188 -3
@@ -2,19 +2,204 @@* Copyright(c) 2018 Intel Corporation */ -#include <rte_log.h> +#include <stdio.h> +#include <stdbool.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/netlink.h> +#include <rte_dev.h> +#include <rte_log.h> +#include <rte_malloc.h> +#include <rte_interrupts.h> + +#include "eal_private.h" + +static struct rte_intr_handle intr_handle = {.fd =-1 }; +static bool monitor_started; + +#define EAL_UEV_MSG_LEN 4096 +#define EAL_UEV_MSG_ELEM_LEN 128 + +/* identify the system layer which event exposure from */ +enum eal_dev_event_subsystem { +EAL_DEV_EVENT_SUBSYSTEM_PCI ,/* PCI bus device event */ +EAL_DEV_EVENT_SUBSYSTEM_UIO ,/* UIO driver device event */ +EAL_DEV_EVENT_SUBSYSTEM_MAX +}; + +static int +dev_uev_monitor_create (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 ,"Failed to bind socket for netlink fd.\n" ); + goto err; + } + +setsockopt (netlink_fd,SOL_SOCKET ,SO_PASSCRED , &size,sizeof (size)); + + 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_dev_event *event,int length) +{ +char action[EAL_UEV_MSG_ELEM_LEN ]; +char subsystem[EAL_UEV_MSG_ELEM_LEN ]; +char pci_slot_name[EAL_UEV_MSG_ELEM_LEN ]; +int i =0 ; + +memset (action,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (subsystem,0 ,EAL_UEV_MSG_ELEM_LEN ); +memset (pci_slot_name,0 ,EAL_UEV_MSG_ELEM_LEN ); + +while (i < length) { +for (; i < length; i++) { +if (*buf) +break ; + buf++; + } +if (!strncmp (buf,"ACTION=" ,7 )) { + buf +=7 ; + i +=7 ; +snprintf (action,sizeof (action),"%s" , buf); + }else if (!strncmp (buf,"SUBSYSTEM=" ,10 )) { + buf +=10 ; + i +=10 ; +snprintf (subsystem,sizeof (subsystem),"%s" , buf); + }else if (!strncmp (buf,"PCI_SLOT_NAME=" ,14 )) { + buf +=14 ; + i +=14 ; +snprintf (pci_slot_name,sizeof (subsystem),"%s" , buf); + event->devname =strdup (pci_slot_name); + } +for (; i < length; i++) { +if (*buf =='\0' ) +break ; + buf++; + } + } + +if (!strncmp (subsystem,"uio" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_UIO ; +else if (!strncmp (subsystem,"pci" ,3 )) + event->subsystem =EAL_DEV_EVENT_SUBSYSTEM_PCI ; +if (!strncmp (action,"add" ,3 )) + event->type =RTE_DEV_EVENT_ADD ; +if (!strncmp (action,"remove" ,6 )) + event->type =RTE_DEV_EVENT_REMOVE ; +} + +static int +dev_uev_receive (int fd,struct rte_dev_event *uevent) +{ +int ret; +char buf[EAL_UEV_MSG_LEN ]; + +memset (uevent,0 ,sizeof (struct rte_dev_event )); +memset (buf,0 ,EAL_UEV_MSG_LEN ); + + ret =recv (fd, buf,EAL_UEV_MSG_LEN ,MSG_DONTWAIT ); +if (ret <0 ) { +RTE_LOG (ERR ,EAL , +"Socket read error(%d): %s.\n" , + errno,strerror (errno)); +return -1 ; + }else if (ret ==0 ) +/* connection closed */ +return -1 ; + +dev_uev_parse (buf, uevent,EAL_UEV_MSG_LEN ); + +return 0 ; +} + +static void +dev_uev_process(__rte_unused void *param) +{ +struct rte_dev_event uevent; + +if (dev_uev_receive (intr_handle.fd, &uevent)) +return ; + +if (uevent.devname) +dev_callback_process (uevent.devname, uevent.type); +} int __rte_experimentalrte_dev_event_monitor_start (void) { -/* TODO: start uevent monitor for linux */ +int ret; + +if (monitor_started) +return 0 ; + + intr_handle.fd =socket (PF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC | +SOCK_NONBLOCK , +NETLINK_KOBJECT_UEVENT ); +if (intr_handle.fd <0 ) { +RTE_LOG (ERR ,EAL ,"create uevent fd failed.\n" ); +return -1 ; + } + intr_handle.type =RTE_INTR_HANDLE_DEV_EVENT ; + + ret =dev_uev_monitor_create (intr_handle.fd); + +if (ret) { +RTE_LOG (ERR ,EAL ,"error create device event monitor.\n" ); +return -1 ; + } + + ret =rte_intr_callback_register (&intr_handle, dev_uev_process,NULL ); + +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to register uevent callback.\n" ); +return -1 ; + } + + monitor_started = true; +return 0 ; } int __rte_experimentalrte_dev_event_monitor_stop (void) { -/* TODO: stop uevent monitor for linux */ +int ret; + +if (!monitor_started) +return 0 ; + + ret =rte_intr_callback_unregister (&intr_handle, dev_uev_process, + (void *)-1 ); +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to unregister uevent callback." ); +return ret; + } + +close (intr_handle.fd); + intr_handle.fd =-1 ; + monitor_started = false;return 0 ; }
lib/librte_eal/linuxapp/eal/meson.build +1 -0
@@ -18,6 +18,7 @@ env_sources = files('eal_alarm.c', 'eal_vfio_mp_sync.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c', ) if has_libnuma == 1
Signature · 1 line
2.7.4
Re: [PATCH V17 3/4] eal/linux: uevent parse and process
lib/librte_eal/linuxapp/eal/eal_dev.c
Quoted 6 lines · On Fri, 30 Mar 2018 00:00:04 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+ ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"ioctl(FIONBIO) failed.\n" ); + goto err; + } + retu
Since you use NOWAIT option, this is unnecessary.
Re: [PATCH V17 3/4] eal/linux: uevent parse and process
Quoted 10 lines · Stephen Hemminger
lib/librte_eal/linuxapp/eal/eal_dev.c
Quoted 6 lines · On Fri, 30 Mar 2018 00:00:04 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c +6
-0+ ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"ioctl(FIONBIO) failed.\n" ); + goto err; + } + retuSince you use NOWAIT option, this is unnecessary.
i think you are right.
Re: [PATCH V17 3/4] eal/linux: uevent parse and process
In reply to Jeff GuoQuoted 16 lines · On Fri, 30 Mar 2018 00:00:04 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c +16
-0+dev_uev_monitor_create(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 ,"Failed to bind socket for netlink fd.\n" ); + goto err; + }
lib/librte_eal/linuxapp/eal/eal_dev.c line 60
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +10
-0+ +setsockopt (netlink_fd,SOL_SOCKET ,SO_PASSCRED , &size,sizeof (size)); + + ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"ioctl(FIONBIO) failed.\n" ); + goto err; + } +return 0 ; +err:
You should set close on exec for this fd (with fcntl).
Re: [PATCH V17 3/4] eal/linux: uevent parse and process
Quoted 22 lines · Stephen Hemminger
Quoted 19 lines · On Fri, 30 Mar 2018 00:00:04 +0800 Jeff Guo <[email protected]> wrote:
lib/librte_eal/linuxapp/eal/eal_dev.c +19
-0+dev_uev_monitor_create(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 ,"Failed to bind socket for netlink fd.\n" ); + goto err; + } + +setsockopt (netlink_fd,SOL_SOCKET ,SO_PASSCRED , &size,sizeof (size)); +
Quoted 8 lines
lib/librte_eal/linuxapp/eal/eal_dev.c line 60
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_dev.c +7
-0+ ret =ioctl (netlink_fd,FIONBIO , &nonblock); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"ioctl(FIONBIO) failed.\n" ); + goto err; + } +return 0 ; +err:You should set close on exec for this fd (with fcntl).
yes, but i have already set it when fd creation time by SOCK_CLOEXEC.
PATCH v17 4/4 app/testpmd: enable device hotplug monitoring
In reply to Jeff GuoUse testpmd for example, to show an application how to use device event mechanism to monitor the hotplug event, involve both hot removal event and the hot insertion event.
The process is that, testpmd first enable hotplug monitoring and register the user's callback, when device being hotplug insertion or hotplug removal, the eal monitor the event and call user's callbacks, the application according their hot plug policy to detach or attach the device from the bus.
---v17->v16:
unregister all user's callback when stop event monitor
--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 242 +++++++++++++++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 11 +++ 3 files changed, 256 insertions(+), 2 deletions(-)
app/test-pmd/parameters.c +4 -1
@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enalbe hot plug for device.\n" ); }#ifdef RTE_LIBRTE_CMDLINE
@@ -621,6 +622,7 @@ launch_args_parse(int argc, char** argv) { "print-event", 1, 0, 0 }, { "mask-event", 1, 0, 0 }, { "tx-offloads", 1, 0, 0 }, + { "hot-plug", 0, 0, 0 }, { 0, 0, 0, 0 }, };
@@ -1102,7 +1104,8 @@ launch_args_parse(int argc, char** argv)rte_exit (EXIT_FAILURE ,"invalid mask-event argument\n" ); } - +if (!strcmp (lgopts[opt_idx].name,"hot-plug" )) + hot_plug =1 ;break ;case 'h' :usage (argv[0 ]);
app/test-pmd/testpmd.c +241 -1
327 lines not on this page · raw message
app/test-pmd/testpmd.h +11 -0
@@ -63,6 +63,15 @@ typedef uint16_t streamid_t;#define TM_MODE 0#endif +struct hotplug_request { +TAILQ_ENTRY (hotplug_request) next;/**< Callbacks list */ +const char *dev_name;/* request device name */ +enum rte_kernel_driver dev_kdrv;/* kernel driver binded */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (hotplug_request_list, hotplug_request); +enum {PORT_TOPOLOGY_PAIRED ,PORT_TOPOLOGY_CHAINED ,
@@ -319,6 +328,8 @@ extern volatile int test_done; /* stop packet forwarding when set to 1. */extern uint8_t lsc_interrupt;/**< disabled by "--no-lsc-interrupt" parameter */ extern uint8_t rmv_interrupt;/**< disabled by "--no-rmv-interrupt" parameter */ extern uint32_t event_print_mask; +extern uint8_t hot_plug;/**< enable by "--hot-plug" parameter */ +/**< set by "--print-event xxxx" and "--mask-event xxxx parameters */ #ifdef RTE_LIBRTE_IXGBE_BYPASS
Signature · 1 line
2.7.4
Re: [PATCH V17 4/4] app/testpmd: enable device hotplug monitoring
Quoted 25 lines · On Fri, 30 Mar 2018 00:00:05 +0800 Jeff Guo <[email protected]> wrote:
Use testpmd for example, to show an application how to use device event mechanism to monitor the hotplug event, involve both hot removal event and the hot insertion event.
The process is that, testpmd first enable hotplug monitoring and register the user's callback, when device being hotplug insertion or hotplug removal, the eal monitor the event and call user's callbacks, the application according their hot plug policy to detach or attach the device from the bus.
Signed-off-by Jeff Guo <[email protected]>---
v17->v16:
unregister all user's callback when stop event monitor--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 242 +++++++++++++++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 11 +++ 3 files changed, 256 insertions(+), 2 deletions(-)app/test-pmd/parameters.c +0
-0
app/test-pmd/parameters.c usage(char* progname) · line 189
Quoted 4 lines
app/test-pmd/parameters.c +1
-0@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enalbe hot plug for device.\n" )
s/enalbe/enable/
Re: [PATCH V17 4/4] app/testpmd: enable device hotplug monitoring
Quoted 23 lines · Stephen Hemminger
Quoted 20 lines · On Fri, 30 Mar 2018 00:00:05 +0800 Jeff Guo <[email protected]> wrote:
Use testpmd for example, to show an application how to use device event mechanism to monitor the hotplug event, involve both hot removal event and the hot insertion event.
The process is that, testpmd first enable hotplug monitoring and register the user's callback, when device being hotplug insertion or hotplug removal, the eal monitor the event and call user's callbacks, the application according their hot plug policy to detach or attach the device from the bus.
Signed-off-by Jeff Guo <[email protected]>---
v17->v16:
unregister all user's callback when stop event monitor--- app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 242 +++++++++++++++++++++++++++++++++++++++++++++- app/test-pmd/testpmd.h | 11 +++ 3 files changed, 256 insertions(+), 2 deletions(-)
Quoted 10 lines
app/test-pmd/parameters.c usage(char* progname) · line 189
Quoted 9 lines
app/test-pmd/parameters.c +1
-0@@ -186,6 +186,7 @@ usage(char* progname)printf (" --flow-isolate-all: " "requests flow API isolated mode on all ports at initialization time.\n" );printf (" --tx-offloads=0xXXXXXXXX: hexadecimal bitmask of TX queue offloads\n" ); +printf (" --hot-plug: enalbe hot plug for device.\n" )s/enalbe/enable/
will correct it.
Re: [PATCH V17 4/4] app/testpmd: enable device hotplug monitoring
In reply to Jeff GuoQuoted 4 lines
app/test-pmd/testpmd.c +3
-0+static int +eth_dev_event_callback_register (portid_t port_id) +{
app/test-pmd/testpmd.c reset_port(portid_t pid) · line 1882
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+int diag; +char *device_name; + +/* if port id equal -1, unregister all device event callbacks */ +if (port_id == (portid_t )HOT_PLUG_FOR_ALL_DEVICE ) { + device_name =NULL ; + }else { + device_name =strdup (rte_eth_devices[port_id].device->name); +if (!device_name) { +free (device_name);
If device_name is NULL, no memory allocated, why free?
Quoted 19 lines
app/test-pmd/testpmd.c +19
-0+return -1 ; + } + } +/* register the dev_event callback */ + diag =rte_dev_event_callback_register (device_name, + eth_dev_event_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +free (device_name); +return 0 ; +} + + +static int +eth_dev_event_callback_unregister (portid_t port_id) +{
app/test-pmd/testpmd.c reset_port(portid_t pid) · line 1911
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+int diag; +char *device_name; + +/* if port id equal -1, unregister all device event callbacks */ +if (port_id == (portid_t )HOT_PLUG_FOR_ALL_DEVICE ) { + device_name =NULL ; + }else { + device_name =strdup (rte_eth_devices[port_id].device->name); +if (!device_name) { +free (device_name);
Same as above.
Quoted 63 lines
app/test-pmd/testpmd.c +31
-0+return -1 ; + } + } + +/* unregister the dev_event callback */ + diag =rte_dev_event_callback_unregister (device_name, + eth_dev_event_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +free (device_name); +return 0 ; +} +void attach_port (char *identifier) {@@ -1869,6 +1941,8 @@ attach_port(char *identifier)if (rte_eth_dev_attach (identifier, &pi))return ; +eth_dev_event_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 )@@ -1880,6 +1954,12 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +if (hot_plug) { +hotplug_list_add (rte_eth_devices[pi].device, + rte_eth_devices[pi].data->kdrv); +eth_dev_event_callback_register (pi); + } +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }@@ -1906,6 +1986,12 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +if (hot_plug) { +hotplug_list_add (rte_eth_devices[port_id].device, + rte_eth_devices[port_id].data->kdrv); +eth_dev_event_callback_register (port_id); + } +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );@@ -1916,6 +2002,7 @@ voidpmd_test_exit (void) {portid_t pt_id; +int ret;if (test_done ==0 )stop_packet_forwarding ();
app/test-pmd/testpmd.c pmd_test_exit(void) · line 2019
Quoted 4 lines
app/test-pmd/testpmd.c +1
-0@@ -1929,6 +2016,19 @@ pmd_test_exit(void)close_port (pt_id); } } +
Need to check if hot_plug is enabled?
Quoted 11 lines
app/test-pmd/testpmd.c +11
-0+ ret =rte_dev_event_monitor_stop (); +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to stop device event monitor." ); +return ; + } + + ret =eth_dev_event_callback_unregister (HOT_PLUG_FOR_ALL_DEVICE ); +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to unregister all event callbacks." ); +return ; + }
<...>
app/test-pmd/testpmd.c rmv_event_callback(void *arg) · line 2152
Quoted 8 lines
app/test-pmd/testpmd.c +8
-0+static void +add_dev_event_callback (void *arg) +{ +char *dev_name = (char *)arg; + +rte_eal_alarm_cancel (add_dev_event_callback, arg); + +if (!in_hotplug_list (dev_name))
Remove "!" in the check
app/test-pmd/testpmd.c rmv_event_callback(void *arg) · line 2155
Quoted 3 lines
app/test-pmd/testpmd.c +3
-0+return ; + +RTE_LOG (ERR ,EAL ,"add device: %s\n" , dev_name);
It is not ERR, please make the log aligned with remove device.
Quoted 3 lines
app/test-pmd/testpmd.c +3
-0+attach_port (dev_name); +} +
<...>
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2253
Quoted 13 lines
app/test-pmd/testpmd.c +13
-0+ +/* This function is used by the interrupt thread */ +static int +eth_dev_event_callback (char *device_name,enum rte_dev_event_type type, +void *arg) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; +char *dev_name =malloc (strlen (device_name) +1 ); + +strcpy (dev_name, device_name);
Why not use strdup as above?
Quoted 17 lines
app/test-pmd/testpmd.c +17
-0+if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_dev_event_callback, arg)) +fprintf (stderr, +"Could not set up deferred device removal\n" ); +break ;
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2281
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+case RTE_DEV_EVENT_ADD : +if (rte_eal_alarm_set (100000 , + add_dev_event_callback, dev_name)) +fprintf (stderr, +"Could not set up deferred device add\n" ); +break ; +default : +break ; + } +return 0 ;
Always 0, even alarm set fails?
Thanks
Jingjing
Re: [PATCH V17 4/4] app/testpmd: enable device hotplug monitoring
hi,jingjing
Quoted 6 lines · Jingjing
Quoted 6 lines
app/test-pmd/testpmd.c +6
-0+static int +eth_dev_event_callback_register (portid_t port_id) +{ +int diag; +char *device_name; +
Quoted 8 lines
app/test-pmd/testpmd.c reset_port(portid_t pid) · line 1882
Quoted 7 lines
app/test-pmd/testpmd.c +7
-0+/* if port id equal -1, unregister all device event callbacks */ +if (port_id == (portid_t )HOT_PLUG_FOR_ALL_DEVICE ) { + device_name =NULL ; + }else { + device_name =strdup (rte_eth_devices[port_id].device->name); +if (!device_name) { +free (device_name);If
device_nameis NULL, no memory allocated, why free?
you are right.
Quoted 91 lines
Quoted 19 lines
app/test-pmd/testpmd.c +19
-0+return -1 ; + } + } +/* register the dev_event callback */ + diag =rte_dev_event_callback_register (device_name, + eth_dev_event_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +free (device_name); +return 0 ; +} + + +static int +eth_dev_event_callback_unregister (portid_t port_id) +{app/test-pmd/testpmd.c reset_port(portid_t pid) · line 1911
Quoted 10 lines
app/test-pmd/testpmd.c +10
-0+int diag; +char *device_name; + +/* if port id equal -1, unregister all device event callbacks */ +if (port_id == (portid_t )HOT_PLUG_FOR_ALL_DEVICE ) { + device_name =NULL ; + }else { + device_name =strdup (rte_eth_devices[port_id].device->name); +if (!device_name) { +free (device_name);Same as above.
Quoted 60 lines
app/test-pmd/testpmd.c +31
-0+return -1 ; + } + } + +/* unregister the dev_event callback */ + diag =rte_dev_event_callback_unregister (device_name, + eth_dev_event_callback, (void *)(intptr_t )port_id); +if (diag) { +printf ("Failed to setup dev_event callback\n" ); +return -1 ; + } + +free (device_name); +return 0 ; +} +void attach_port (char *identifier) {@@ -1869,6 +1941,8 @@ attach_port(char *identifier)if (rte_eth_dev_attach (identifier, &pi))return ; +eth_dev_event_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 )@@ -1880,6 +1954,12 @@ attach_port(char *identifier) ports[pi].port_status =RTE_PORT_STOPPED ; +if (hot_plug) { +hotplug_list_add (rte_eth_devices[pi].device, + rte_eth_devices[pi].data->kdrv); +eth_dev_event_callback_register (pi); + } +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports);printf ("Done\n" ); }@@ -1906,6 +1986,12 @@ detach_port(portid_t port_id) nb_ports =rte_eth_dev_count (); +if (hot_plug) { +hotplug_list_add (rte_eth_devices[port_id].device, + rte_eth_devices[port_id].data->kdrv); +eth_dev_event_callback_register (port_id); + } +printf ("Port '%s' is detached. Now total ports is %d\n" , name, nb_ports);printf ("Done\n" );@@ -1916,6 +2002,7 @@ voidpmd_test_exit (void) {portid_t pt_id; +int ret;
Quoted 8 lines
app/test-pmd/testpmd.c pmd_test_exit(void) · line 2019
Quoted 7 lines
app/test-pmd/testpmd.c +1
-0if (test_done ==0 )stop_packet_forwarding ();@@ -1929,6 +2016,19 @@ pmd_test_exit(void)close_port (pt_id); } } +Need to check if
hot_plugis enabled?
sure.
Quoted 14 lines
Quoted 11 lines
app/test-pmd/testpmd.c +11
-0+ ret =rte_dev_event_monitor_stop (); +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to stop device event monitor." ); +return ; + } + + ret =eth_dev_event_callback_unregister (HOT_PLUG_FOR_ALL_DEVICE ); +if (ret) { +RTE_LOG (ERR ,EAL ,"fail to unregister all event callbacks." ); +return ; + }<...>
Quoted 9 lines
app/test-pmd/testpmd.c rmv_event_callback(void *arg) · line 2152
Quoted 8 lines
app/test-pmd/testpmd.c +8
-0+static void +add_dev_event_callback (void *arg) +{ +char *dev_name = (char *)arg; + +rte_eal_alarm_cancel (add_dev_event_callback, arg); + +if (!in_hotplug_list (dev_name))Remove "!" in the check
the hot plug list is for hot plug in and hot plug out device, that is management by app, when remove a device will add into the hotplug list for the future adding.
Quoted 4 lines
app/test-pmd/testpmd.c rmv_event_callback(void *arg) · line 2155
Quoted 3 lines
app/test-pmd/testpmd.c +3
-0+return ; + +RTE_LOG (ERR ,EAL ,"add device: %s\n" , dev_name);It is not ERR, please make the log aligned with remove device.
yes.
Quoted 4 lines
Quoted 3 lines
app/test-pmd/testpmd.c +3
-0+attach_port (dev_name); +} +<...>
Quoted 14 lines
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2253
Quoted 13 lines
app/test-pmd/testpmd.c +13
-0+ +/* This function is used by the interrupt thread */ +static int +eth_dev_event_callback (char *device_name,enum rte_dev_event_type type, +void *arg) +{ +static const char *const event_desc[] = { + [RTE_DEV_EVENT_ADD ] ="add" , + [RTE_DEV_EVENT_REMOVE ] ="remove" , + }; +char *dev_name =malloc (strlen (device_name) +1 ); + +strcpy (dev_name, device_name);Why not use strdup as above?
ok.
Quoted 20 lines
Quoted 20 lines
app/test-pmd/testpmd.c +20
-0+if (type >=RTE_DEV_EVENT_MAX ) { +fprintf (stderr,"%s called upon invalid event %d\n" , + __func__, type); +fflush (stderr); + }else if (event_print_mask & (UINT32_C (1 ) << type)) { +printf ("%s event\n" , + event_desc[type]); +fflush (stdout); + } + +switch (type) { +case RTE_DEV_EVENT_REMOVE : +if (rte_eal_alarm_set (100000 , + rmv_dev_event_callback, arg)) +fprintf (stderr, +"Could not set up deferred device removal\n" ); +break ; +case RTE_DEV_EVENT_ADD : +if (rte_eal_alarm_set (100000 , + add_dev_event_callback, dev_name))
Quoted 9 lines
app/test-pmd/testpmd.c eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, · line 2281
Quoted 7 lines
app/test-pmd/testpmd.c +7
-0+fprintf (stderr, +"Could not set up deferred device add\n" ); +break ; +default : +break ; + } +return 0 ;Always 0, even alarm set fails?
should check the alarm fails.
Quoted 2 lines
Thanks
Jingjing
v18 cover add device event monitor framework
In reply to Jeff GuoAbout hot plug in dpdk, We already have proactive way to add/remove devices through APIs (rte_eal_hotplug_add/remove), and also have fail-safe driver to offload the fail-safe work from the app user. But there are still lack of a general mechanism to monitor hotplug event for all driver, now the hotplug interrupt event is diversity between each device and driver, such as mlx4, pci driver and others.
Use the hot removal event for example, pci drivers not all exposure the remove interrupt, so in order to make user to easy use the hot plug feature for pci driver, something must be done to detect the remove event at the kernel level and offer a new line of interrupt to the user land.
Base on the uevent of kobject mechanism in kernel, we could use it to benefit for monitoring the hot plug status of the device which not only uio/vfio of pci bus devices, but also other, such as cpu/usb/pci-express bus devices.
The idea is comming as bellow.
a.The uevent message form FD monitoring like below. remove@/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 ACTION=remove DEVPATH=/devices/pci0000:80/0000:80:02.2/0000:82:00.0/0000:83:03.0/0000:84:00.2/uio/uio2 SUBSYSTEM=uio
MAJOR=243
MINOR=2
DEVNAME=uio2
SEQNUM=11366
b.add device event monitor framework:
add several general api to enable uevent monitoring.
c.show example how to use uevent monitor
enable uevent monitoring in testpmd to show device event monitor machenism usage.
TODO: failure handler mechanism for hot plug and driver auto bind for hot insertion. that would let the next hot plug patch set to cover.
patchset history:v18->v17:
1.add feature announcement in release document, fix bsp compile issue. 2.refine socket configuration.
3.remove hotplug policy and detach/attach process from testpmd, let it focus on the device event monitoring which the patch set introduced.
v17->v16:
1.add related part of the interrupt handle type adding.
2.add new API into map, fix typo issue, add (void*)-1 value for unregister all callback 3.add new file into meson.build, modify coding sytle and add print info, delete unused part. 4.unregister all user's callback when stop event monitor
v16->v15:
1.remove some linux related code out of eal common layer 2.fix some uneasy readble issue.
v15->v14:
1.use exist eal interrupt epoll to replace of rte service usage for monitor thread, 2.add new device event handle type in eal interrupt.
3.remove the uevent type check and any policy from eal,
let it check and management in user's callback.
4.add "--hot-plug" configure parameter in testpmd to switch the hotplug feature.
v14->v13:
1.add __rte_experimental on function defind and fix bsd build issue
v13->v12:
1.fix some logic issue and null check issue
2.fix monitor stop func issue
v12->v11:
1.identify null param in callback for monitor all devices uevent
v11->v10:
1:modify some typo and add experimental tag in new file. 2:modify callback register calling.
v10->v9:
1.fix prefix issue.
2.use a common callback lists for all device and all type to replace add callback parameter into device struct.
3.delete some unuse part.
v9->v8:
split the patch set into small and explicit patch
v8->v7:
1.use rte_service to replace pthread management.
2.fix defind issue and copyright issue
3.fix some lock issue
v7->v6:
1.modify vdev part according to the vdev rework 2.re-define and split the func into common and bus specific code 3.fix some incorrect issue.
4.fix the system hung after send packcet issue.
v6->v5:
1.add hot plug policy, in eal, default handle to prepare hot plug work for all pci device, then let app to manage to deside which device need to hot plug.
2.modify to manage event callback in each device.
3.fix some system hung issue when igb_uioome typo error.release. 4.modify the pci part to the bus-pci base on the bus rework. 5.add hot plug policy in app, show example to use hotplug list to manage to deside which device need to hot plug.
v5->v4:
1.Move uevent monitor epolling from eal interrupt to eal device layer.
2.Redefine the eal device API for common, and distinguish between linux and bsd
3.Add failure handler helper api in bus layer.Add function of find device by name.
4.Replace of individual fd bind with single device, use a common fd to polling all device. 5.Add to register hot insertion monitoring and process, add function to auto bind driver befor user add device 6.Refine some coding style and typos issue
7.add new callback to process hot insertion
v4->v3:
1.move uevent monitor api from eal interrupt to eal device layer. 2.create uevent type and struct in eal device.
3.move uevent handler for each driver to eal layer. 4.add uevent failure handler to process signal fault issue. 5.add example for request and use uevent monitoring in testpmd.
v3->v2:
1.refine some return error
2.refine the string searching logic to avoid memory issue
v2->v1:
1.remove global variables of hotplug_fd, add uevent_fd in rte_intr_handle to let each pci device self maintain it fd, to fix dual device fd issue.
2.refine some typo error.
Jeff Guo (4):
eal: add device event handle in interrupt thread
eal: add device event monitor framework eal/linux: uevent parse and process app/testpmd: enable device hotplug monitoring
app/test-pmd/parameters.c | 5 +- app/test-pmd/testpmd.c | 112 +++++++++++- app/test-pmd/testpmd.h | 2 + doc/guides/rel_notes/release_18_05.rst | 9 + doc/guides/testpmd_app_ug/run_app.rst | 4 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 +++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 168 ++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 ++ lib/librte_eal/common/include/rte_dev.h | 94 ++++++++++ lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 196 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +- lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 8 + test/test/test_interrupts.c | 39 +++- 18 files changed, 684 insertions(+), 5 deletions(-) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
Signature · 1 line
2.7.4
PATCH v18 1/4 eal: add device event handle in interrupt thread
Add new interrupt handle type of RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.
---v18->v17:
no change.
--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++- test/test/test_interrupts.c | 39 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_eal_interrupts.h +1 -0
@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };
lib/librte_eal/linuxapp/eal/eal_interrupts.c +10 -1
@@ -559,6 +559,9 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -606,6 +609,9 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default : RTE_LOG(ERR, EAL,
@@ -674,7 +680,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break ;
test/test/test_interrupts.c +37 -2
@@ -20,6 +20,7 @@ enum test_interrupt_handle_type {TEST_INTERRUPT_HANDLE_VALID ,TEST_INTERRUPT_HANDLE_VALID_UIO ,TEST_INTERRUPT_HANDLE_VALID_ALARM , +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ,TEST_INTERRUPT_HANDLE_CASE1 , TEST_INTERRUPT_HANDLE_MAX };
@@ -80,6 +81,10 @@ test_interrupt_init(void) intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM ].type =RTE_INTR_HANDLE_ALARM ; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].fd = pfds.readfd; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].type = +RTE_INTR_HANDLE_DEV_EVENT ; + intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].fd = pfds.writefd; intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].type =RTE_INTR_HANDLE_UIO ;
@@ -250,6 +255,14 @@ test_interrupt_enable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_enable (&test_intr_handle) ==0 ) { +printf ("unexpectedly enable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_enable (&test_intr_handle) <0 ) {
@@ -306,6 +319,14 @@ test_interrupt_disable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_disable (&test_intr_handle) ==0 ) { +printf ("unexpectedly disable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_disable (&test_intr_handle) <0 ) {
@@ -393,9 +414,17 @@ test_interrupt(void) goto out; } +printf ("Check valid device event interrupt full path\n" ); +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEVICE_EVENT ) <0 ) { +printf ("failure occurred during checking valid device event " +"interrupt full path\n" ); + goto out; + } +printf ("Check valid alarm interrupt full path\n" ); -if (test_interrupt_full_path_check (TEST_INTERRUPT_HANDLE_VALID_ALARM ) - <0 ) { +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ) <0 ) {printf ("failure occurred during checking valid alarm " "interrupt full path\n" ); goto out;
@@ -513,6 +542,12 @@ test_interrupt(void)rte_intr_callback_unregister (&test_intr_handle, test_interrupt_callback_1, (void *)-1 ); + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback, (void *)-1 ); +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback_1, (void *)-1 ); +rte_delay_ms (2 *TEST_INTERRUPT_CHECK_INTERVAL );/* deinit */ test_interrupt_deinit ();
Signature · 1 line
2.7.4
Re: [PATCH V18 1/4] eal: add device event handle in interrupt thread
Quoted 13 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 1/4] eal: add device event handle in interrupt thread
Quoted 4 lines
Add new interrupt handle type of
RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.Signed-off-by Jeff Guo <[email protected]>
After fixing a typo below, you can carry my:
Quoted 120 lines
---
v18->v17:
no change.--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++- test/test/test_interrupts.c | 39 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-)lib/librte_eal/common/include/rte_eal_interrupts.h +1
-0@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };lib/librte_eal/linuxapp/eal/eal_interrupts.c +3
-0@@ -559,6 +559,9 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default :lib/librte_eal/linuxapp/eal/eal_interrupts.c +3
-0RTE_LOG(ERR, EAL,@@ -606,6 +609,9 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default :lib/librte_eal/linuxapp/eal/eal_interrupts.c +4
-1RTE_LOG(ERR, EAL,@@ -674,7 +680,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;lib/librte_eal/linuxapp/eal/eal_interrupts.c +0
-0break ;test/test/test_interrupts.c +5
-0@@ -20,6 +20,7 @@ enum test_interrupt_handle_type {TEST_INTERRUPT_HANDLE_VALID ,TEST_INTERRUPT_HANDLE_VALID_UIO ,TEST_INTERRUPT_HANDLE_VALID_ALARM , +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ,TEST_INTERRUPT_HANDLE_CASE1 , TEST_INTERRUPT_HANDLE_MAX };@@ -80,6 +81,10 @@ test_interrupt_init(void) intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM ].type =RTE_INTR_HANDLE_ALARM ; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].fd = pfds.readfd; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].type = +RTE_INTR_HANDLE_DEV_EVENT ; + intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].fd = pfds.writefd; intr_handles[TEST_INTERRUPT_HANDLE_CASE1].type =
RTE_INTR_HANDLE_UIO;test/test/test_interrupts.c +8
-0@@ -250,6 +255,14 @@ test_interrupt_enable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_enable (&test_intr_handle) ==0 ) { +printf ("unexpectedly enable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];test/test/test_interrupts.c +8
-0if (rte_intr_enable (&test_intr_handle) <0 ) {@@ -306,6 +319,14 @@ test_interrupt_disable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_disable (&test_intr_handle) ==0 ) { +printf ("unexpectedly disable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];test/test/test_interrupts.c +0
-0if (rte_intr_disable (&test_intr_handle) <0 ) {
test/test/test_interrupts.c test_interrupt(void) · line 419
Quoted 6 lines
test/test/test_interrupts.c +3
-0@@ -393,9 +414,17 @@ test_interrupt(void) goto out; } +printf ("Check valid device event interrupt full path\n" ); +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEVICE_EVENT ) <0 ) {
Here is a typo which brings below compile error:
dpdk/test/test/test_interrupts.c:419:3: error: 'TEST_INTERRUPT_HANDLE_VALID_DEVICE_EVENT' undeclared (first use in this function)
TEST_INTERRUPT_HANDLE_VALID_DEVICE_EVENT) < 0) {Thanks,
Jianfeng
Quoted 30 lines
test/test/test_interrupts.c +7
-2+printf ("failure occurred during checking valid device event " +"interrupt full path\n" ); + goto out; + } +printf ("Check valid alarm interrupt full path\n" ); -if (test_interrupt_full_path_check(TEST_INTERRUPT_HANDLE_VALID_ALARM) - <0 ) { + if (test_interrupt_full_path_check( + TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT) < 0) { printf("failure occurred during checking valid alarm " "interrupt full path\n");test/test/test_interrupts.c +6
-0goto out;@@ -513,6 +542,12 @@ test_interrupt(void)rte_intr_callback_unregister (&test_intr_handle, test_interrupt_callback_1, (void *)-1 ); + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback, (void *)-1 ); +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback_1, (void *)-1 ); +rte_delay_ms (2 *TEST_INTERRUPT_CHECK_INTERVAL );/* deinit */
test_interrupt_deinit();
--
2.7.4
Re: [PATCH V18 1/4] eal: add device event handle in interrupt thread
Quoted 148 lines · Jianfeng
Quoted 12 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 1/4] eal: add device event handle in interrupt threadQuoted 4 lines
Add new interrupt handle type of
RTE_INTR_HANDLE_DEV_EVENT, for device event interrupt monitor.Signed-off-by Jeff Guo <[email protected]>After fixing a typo below, you can carry my:
Reviewed-by Jianfeng Tan <[email protected]>Quoted 120 lines
---
v18->v17:
no change.--- lib/librte_eal/common/include/rte_eal_interrupts.h | 1 + lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 +++++- test/test/test_interrupts.c | 39 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-)lib/librte_eal/common/include/rte_eal_interrupts.h +1
-0@@ -34,6 +34,7 @@ enum rte_intr_handle_type {RTE_INTR_HANDLE_ALARM ,/**< alarm handle */ RTE_INTR_HANDLE_EXT ,/**< external handler */ RTE_INTR_HANDLE_VDEV ,/**< virtual device */ +RTE_INTR_HANDLE_DEV_EVENT ,/**< device event handle */ RTE_INTR_HANDLE_MAX /**< count of elements */ };lib/librte_eal/linuxapp/eal/eal_interrupts.c +3
-0@@ -559,6 +559,9 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default :RTE_LOG(ERR, EAL,
lib/librte_eal/linuxapp/eal/eal_interrupts.c +3
-0@@ -606,6 +609,9 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)return -1 ;break ;#endif +/* not used at this moment */ +case RTE_INTR_HANDLE_DEV_EVENT : +return -1 ;/* unknown handle type */ default :RTE_LOG(ERR, EAL,
lib/librte_eal/linuxapp/eal/eal_interrupts.c +4
-1@@ -674,7 +680,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read =0 ; call = true;break ; - +case RTE_INTR_HANDLE_DEV_EVENT : + bytes_read =0 ; + call = true; +break ;default : bytes_read =1 ;break;
test/test/test_interrupts.c +5
-0@@ -20,6 +20,7 @@ enum test_interrupt_handle_type {TEST_INTERRUPT_HANDLE_VALID ,TEST_INTERRUPT_HANDLE_VALID_UIO ,TEST_INTERRUPT_HANDLE_VALID_ALARM , +TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ,TEST_INTERRUPT_HANDLE_CASE1 , TEST_INTERRUPT_HANDLE_MAX };@@ -80,6 +81,10 @@ test_interrupt_init(void) intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM ].type =RTE_INTR_HANDLE_ALARM ; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].fd = pfds.readfd; + intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ].type = +RTE_INTR_HANDLE_DEV_EVENT ; + intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ].fd = pfds.writefd; intr_handles[TEST_INTERRUPT_HANDLE_CASE1].type =
RTE_INTR_HANDLE_UIO;test/test/test_interrupts.c +8
-0@@ -250,6 +255,14 @@ test_interrupt_enable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_enable (&test_intr_handle) ==0 ) { +printf ("unexpectedly enable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_enable(&test_intr_handle) < 0) {test/test/test_interrupts.c +8
-0@@ -306,6 +319,14 @@ test_interrupt_disable(void)return -1 ; } +/* check with specific valid intr_handle */ + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +if (rte_intr_disable (&test_intr_handle) ==0 ) { +printf ("unexpectedly disable a specific intr_handle " +"successfully\n" ); +return -1 ; + } +/* check with valid handler and its type */ test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1 ];if (rte_intr_disable(&test_intr_handle) < 0) {test/test/test_interrupts.c test_interrupt(void) · line 419
Quoted 6 lines
test/test/test_interrupts.c +3
-0@@ -393,9 +414,17 @@ test_interrupt(void) goto out; } +printf ("Check valid device event interrupt full path\n" ); +if (test_interrupt_full_path_check ( +TEST_INTERRUPT_HANDLE_VALID_DEVICE_EVENT ) <0 ) {Here is a typo which brings below compile error:
Quoted 5 lines
dpdk/test/test/test_interrupts.c:419:3: error: 'TEST_INTERRUPT_HANDLE_VALID_DEVICE_EVENT' undeclared (first use in this function) TEST_INTERRUPT_HANDLE_VALID_DEVICE_EVENT) < 0) {Thanks,
Jianfeng
thanks, will correct it.
Quoted 30 lines
Quoted 30 lines
test/test/test_interrupts.c +7
-2+printf ("failure occurred during checking valid device event " +"interrupt full path\n" ); + goto out; + } +printf ("Check valid alarm interrupt full path\n" ); -if (test_interrupt_full_path_check(TEST_INTERRUPT_HANDLE_VALID_ALARM) - <0 ) { + if (test_interrupt_full_path_check( + TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT) < 0) { printf("failure occurred during checking valid alarm " "interrupt full path\n");goto out;
test/test/test_interrupts.c +6
-0@@ -513,6 +542,12 @@ test_interrupt(void)rte_intr_callback_unregister (&test_intr_handle, test_interrupt_callback_1, (void *)-1 ); + test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT ]; +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback, (void *)-1 ); +rte_intr_callback_unregister (&test_intr_handle, + test_interrupt_callback_1, (void *)-1 ); +rte_delay_ms (2 *TEST_INTERRUPT_CHECK_INTERVAL );/* deinit */
test_interrupt_deinit();
--
2.7.4
PATCH v18 2/4 eal: add device event monitor framework
In reply to Jeff GuoThis patch aims to add a general device event monitor framework at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other types of device event monitor, but not in this scope at the stage.
To get started, users firstly call below new added APIs to enable/disable the device event monitor mechanism:
- rte_dev_event_monitor_start
- rte_dev_event_monitor_stop
Then users shell register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_event_callback_register -rte_dev_event_callback_unregister
Use hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could benefit further fail-safe or live-migration.
---v18->v17:
add feature announcement in release document, fix bsp compile issue.
--- doc/guides/rel_notes/release_18_05.rst | 9 ++ lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 ++++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 168 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 +++ lib/librte_eal/common/include/rte_dev.h | 94 ++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 22 +++++ lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 8 ++ 11 files changed, 341 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.c
doc/guides/rel_notes/release_18_05.rst +9 -0
@@ -41,6 +41,15 @@ New Features Also, make sure to start the actual text at the margin. ========================================================= +* **Added device event monitor framework.** + + Added a general device event monitor framework at EAL, for device dynamic management. + Such as device hotplug awareness and actions adopted accordingly. The list of new APIs: + + * ``rte_dev_event_monitor_start`` and ``rte_dev_event_monitor_stop`` are for + the event monitor enable and disable. + * ``rte_dev_event_callback_register`` and ``rte_dev_event_callback_unregister`` + are for the user's callbacks register and unregister. API Changes -----------
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
lib/librte_eal/bsdapp/eal/eal_dev.c new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/bsdapp/eal/meson.build +1 -0
@@ -12,4 +12,5 @@ env_sources = files('eal_alarm.c', 'eal_timer.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c' )
lib/librte_eal/common/eal_common_dev.c +168 -0
180 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +15 -0
@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). *
@@ -205,4 +207,17 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* Internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User +* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type. +* +*/ +void +dev_callback_process (char *device_name,enum rte_dev_event_type event);#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +94 -0
104 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
lib/librte_eal/linuxapp/eal/eal_dev.c new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}
lib/librte_eal/linuxapp/eal/meson.build +1 -0
@@ -18,6 +18,7 @@ env_sources = files('eal_alarm.c', 'eal_vfio_mp_sync.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c', ) if has_libnuma == 1
lib/librte_eal/rte_eal_version.map +8 -0
@@ -256,3 +256,11 @@ EXPERIMENTAL { rte_service_start_with_defaults; } DPDK_18.02; + +EXPERIMENTAL { + global: + + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; + +} DPDK_18.05;
Signature · 1 line
2.7.4
Re: [PATCH V18 2/4] eal: add device event monitor framework
Quoted 139 lines
-----Original Message-----
From: Guo, Jia
Sent: Tuesday, April 3, 2018 6:34 PM
To: [email protected]; Richardson, Bruce; Yigit, Ferruh; Ananyev, Konstantin; [email protected]; Wu, Jingjing; [email protected]; [email protected]; Van Haaren, Harry; Tan, Jianfeng
Cc: [email protected]; [email protected]; [email protected]; Guo, Jia; Zhang, Helin
Subject: [PATCH V18 2/4] eal: add device event monitor frameworkThis patch aims to add a general device event monitor framework at EAL device layer, for device hotplug awareness and actions adopted accordingly. It could also expand for all other types of device event monitor, but not in this scope at the stage.
To get started, users firstly call below new added APIs to enable/disable the device event monitor mechanism:
-rte_dev_event_monitor_start
-rte_dev_event_monitor_stopThen users shell register or unregister callbacks through the new added APIs. Callbacks can be some device specific, or for all devices.
-rte_dev_event_callback_register -rte_dev_event_callback_unregisterUse hotplug case for example, when device hotplug insertion or hotplug removal, we will get notified from kernel, then call user's callbacks accordingly to handle it, such as detach or attach the device from the bus, and could benefit further fail-safe or live-migration.
Signed-off-by Jeff Guo <[email protected]>---
v18->v17:
add feature announcement in release document, fix bsp compile issue.--- doc/guides/rel_notes/release_18_05.rst | 9 ++ lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_dev.c | 21 ++++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_common_dev.c | 168 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 15 +++ lib/librte_eal/common/include/rte_dev.h | 94 ++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_dev.c | 22 +++++ lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 8 ++ 11 files changed, 341 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_dev.c create mode 100644 lib/librte_eal/linuxapp/eal/eal_dev.cdoc/guides/rel_notes/release_18_05.rst +0
-0@@ -41,6 +41,15 @@ New Features Also, make sure to start the actual text at the margin.=========================================================
doc/guides/rel_notes/release_18_05.rst +3
-0+* **Added device event monitor framework.** + + Added a general device event monitor framework at EAL, for devicedynamic management.
+ Such as device hotplug awareness and actions adopted accordingly. The list of new APIs:doc/guides/rel_notes/release_18_05.rst +2
-0+ + * ``rte_dev_event_monitor_start`` and ``rte_dev_event_monitor_stop``are for
doc/guides/rel_notes/release_18_05.rst +2
-0+ the event monitor enable and disable. + * ``rte_dev_event_callback_register`` and``rte_dev_event_callback_unregister``
doc/guides/rel_notes/release_18_05.rst +1
-0+ are for the user's callbacks register and unregister. API Changes -----------lib/librte_eal/bsdapp/eal/Makefile +0
-0@@ -33,6 +33,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=
eal_lcore.c
SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_timer.cSRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_interrupts.cSRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=eal_alarm.clib/librte_eal/bsdapp/eal/Makefile +1
-0+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.clib/librte_eal/bsdapp/eal/eal_dev.c new file +21
-0@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +RTE_LOG (ERR ,EAL ,"Device event is not supported for FreeBSD\n" ); +return -1 ; +}lib/librte_eal/bsdapp/eal/meson.build +1
-0@@ -12,4 +12,5 @@ env_sources = files('eal_alarm.c', 'eal_timer.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c' )lib/librte_eal/common/eal_common_dev.c +0
-0
lib/librte_eal/common/eal_common_dev.c line 22
Quoted 9 lines
lib/librte_eal/common/eal_common_dev.c +3
-0@@ -14,9 +14,34 @@#include <rte_devargs.h> #include <rte_debug.h> #include <rte_log.h> +#include <rte_spinlock.h> +#include <rte_malloc.h> #include "eal_private.h" +/* spinlock for device callbacks */
It's for protect callback list.
lib/librte_eal/common/eal_common_dev.c line 23
Quoted 1 line
lib/librte_eal/common/eal_common_dev.c +1
-0+static rte_spinlock_t dev_event_lock =RTE_SPINLOCK_INITIALIZER ;
Put this spinlock where the list locates.
Quoted 83 lines
lib/librte_eal/common/eal_common_dev.c +12
-0+ +/** +* The device event callback description. +* +* It contains callback address to be registered by user application, +* the pointer to the parameters for callback, and the device name. +*/ +struct dev_event_callback { +TAILQ_ENTRY (dev_event_callback) next;/**< Callbacks list */ +rte_dev_event_cb_fn cb_fn;/**< Callback address */ +void *cb_arg;/**< Callback parameter */ +char *dev_name;/**< Callback device name, NULL is for all device */
lib/librte_eal/common/eal_common_dev.c +28
-0+uint32_t active;/**< Callback is executing */ +}; + +/** @internal Structure to keep track of registered callbacks */ +TAILQ_HEAD (dev_event_cb_list, dev_event_callback); + +/* The device event callback list for all registered callbacks. */ +static struct dev_event_cb_list dev_event_cbs; +static int cmp_detached_dev_name (const struct rte_device *dev,const void *_name) {@@ -207,3 +232,146 @@ rte_eal_hotplug_remove(const char *busname, const char *devname)rte_eal_devargs_remove (busname ,devname );return ret; } + +int __rte_experimental +rte_dev_event_callback_register(const char *device_name, + rte_dev_event_cb_fn cb_fn, + void *cb_arg) +{ + struct dev_event_callback *event_cb; + int ret; + + if (!cb_fn) + return -EINVAL; + + rte_spinlock_lock(&dev_event_lock); + + if (TAILQ_EMPTY(&dev_event_cbs)) + TAILQ_INIT(&dev_event_cbs); + + TAILQ_FOREACH(event_cb, &dev_event_cbs, next) { + if (event_cb->cb_fn == cb_fn && event_cb->cb_arg ==
cb_arg) {lib/librte_eal/common/eal_common_dev.c +1
-0+ if (device_name == NULL && event_cb->dev_name== NULL)
lib/librte_eal/common/eal_common_dev.c +2
-0+break ; + if (device_name == NULL || event_cb->dev_name== NULL)
lib/librte_eal/common/eal_common_dev.c +17
-0+continue ; +if (!strcmp (event_cb->dev_name, device_name)) +break ; + } + } + +/* create a new callback. */ +if (event_cb ==NULL ) { + event_cb =malloc (sizeof (struct dev_event_callback )); +if (event_cb !=NULL ) { + event_cb->cb_fn = cb_fn; + event_cb->cb_arg = cb_arg; + event_cb->active =0 ; +if (!device_name) { + event_cb->dev_name =NULL ; + }else { + event_cb->dev_name =
strdup(device_name);lib/librte_eal/common/eal_common_dev.c +6
-0+if (event_cb->dev_name ==NULL ) { + ret = -ENOMEM ; + goto error; + } + } + TAILQ_INSERT_TAIL(&dev_event_cbs, event_cb,next);
lib/librte_eal/common/eal_common_dev.c +3
-0+ }else { +RTE_LOG (ERR ,EAL , + "Failed to allocate memory for device "
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 292
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+ "event callback."); + ret = -ENOMEM ; + goto error; + } + }else { +RTE_LOG (ERR ,EAL , +"The callback is already exist, no need " +"to register again.\n" ); + ret = -EEXIST ; + goto error;
Here is a bug that you will free an existing callback entry.
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+ } + +rte_spinlock_unlock (&dev_event_lock); +return 0 ; +error:
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 307
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+free (event_cb); +rte_spinlock_unlock (&dev_event_lock); +return ret; +} + +int __rte_experimental +rte_dev_event_callback_unregister (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg) +{
Let's clearly define the behavior and return of this API. If I understand it correctly,
If cb_arg != -1, we use (dev_name, cb_fn, cb_arg) as the key to look up the registered API.
If cb_arg == -1, we use (cb_fn) as the key to look up the registered API.For return value, we want to return the number of callbacks being removed. It could be:
Quoted 1 line
=0, number of callbacks been removed. (When we encounter an active callback, we shall skip it or just return
-EAGAIN, neither sounds good to me actually)
<0, error encountered.
If you agree with above statement, below implementation has lots of issues.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 320
Quoted 13 lines
lib/librte_eal/common/eal_common_dev.c +13
-0+int ret =0 ; +struct dev_event_callback *event_cb, *next; + +if (!cb_fn) +return -EINVAL ; + +rte_spinlock_lock (&dev_event_lock); + +/*walk through the callbacks and remove all that match. */ +for (event_cb =TAILQ_FIRST (&dev_event_cbs); event_cb !=NULL ; + event_cb = next) { + + next =TAILQ_NEXT (event_cb, next);
First of all, if cb_fn != event_cb->cb_fn, we shall continue.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 331
Quoted 11 lines
lib/librte_eal/common/eal_common_dev.c +11
-0+ +if (device_name !=NULL && event_cb->dev_name !=NULL ) { +if (!strcmp (event_cb->dev_name, device_name)) { +if (event_cb->cb_fn != cb_fn || + (cb_arg != (void *)-1 && + event_cb->cb_arg != cb_arg)) +continue ; + } + }else if (device_name !=NULL ) { +continue ; + }
What about device_name == NULL && event_cb->dev_name != NULL && cb_arg == -1?
What about device_name == NULL && event_cb->dev_name == NULL && cb_arg != -1 && cb_arg != event_cb->cb_arg?
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 342
Quoted 11 lines
lib/librte_eal/common/eal_common_dev.c +11
-0+ +/* +* if this callback is not executing right now, +* then remove it. +*/ +if (event_cb->active ==0 ) { +TAILQ_REMOVE (&dev_event_cbs, event_cb, next); +free (event_cb); + ret++; + }else { + ret = -EAGAIN ;
If you don't break here, next time you find another satisfied callback, you will ret++ on a (-EAGAIN) value.
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 301
Quoted 5 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+ } + } +rte_spinlock_unlock (&dev_event_lock); +return ret; +}
BTW, don't know why DPDK has the tradition of using cb_arg==-1 to stand for multiple callbacks, it's not a good API design to me. Would like as others' opinions, shall we continue this?
Quoted 16 lines
lib/librte_eal/common/eal_common_dev.c +3
-0+ +void +dev_callback_process(char *device_name, enum rte_dev_event_typeevent)
lib/librte_eal/common/eal_common_dev.c +12
-0+{ +struct dev_event_callback *cb_lst; +int rc; + +if (device_name ==NULL ) +return ; + +rte_spinlock_lock (&dev_event_lock); + + TAILQ_FOREACH(cb_lst, &dev_event_cbs, next) { +if (cb_lst->dev_name) { +if (strcmp (cb_lst->dev_name, device_name))
lib/librte_eal/common/eal_common_dev.c rte_eal_hotplug_remove(const char *busname, const char *devname) · line 372
Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +10
-0+continue ; + } + cb_lst->active =1 ; +rte_spinlock_unlock (&dev_event_lock); + rc = cb_lst->cb_fn (device_name, event, + cb_lst->cb_arg); +if (rc) { +RTE_LOG (ERR ,EAL , +"Failed to process callback function." ); + }
I don't see a reason why we need the return value from callbacks. Probably, define it as void type.
Quoted 27 lines
lib/librte_eal/common/eal_common_dev.c +5
-0+rte_spinlock_lock (&dev_event_lock); + cb_lst->active =0 ; + } +rte_spinlock_unlock (&dev_event_lock); +}lib/librte_eal/common/eal_private.h +5
-0@@ -9,6 +9,8 @@#include <stdint.h> #include <stdio.h> +#include <rte_dev.h> +/** * Initialize the memzone subsystem (private to eal). * @@ -205,4 +207,17 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str);int rte_mp_channel_init (void ); +/** +* Internal Executes all the user application registered callbacks for +* the specific device. It is for DPDK internal user only. User
lib/librte_eal/common/eal_private.h struct rte_bus · line 223
Quoted 10 lines
lib/librte_eal/common/eal_private.h +10
-0+* application should not call it directly. +* +* @param device_name +* The device name. +* @param event +* the device event type. +* +*/ +void +dev_callback_process (char *device_name,enum rte_dev_event_type event);
Too many *_process functions in this patch. Let's avoid using such ambiguous words.
For example, you can rename this function to dev_event_callback_invoke().
Quoted 187 lines
#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_dev.h +94
-0@@ -24,6 +24,25 @@ extern "C" {#include <rte_compat.h> #include <rte_log.h> +/** +* The device event type. +*/ +enum rte_dev_event_type { +RTE_DEV_EVENT_ADD ,/**< device being added */ +RTE_DEV_EVENT_REMOVE ,/**< device being removed */ +RTE_DEV_EVENT_MAX /**< max value of this enum */ +}; + +struct rte_dev_event { +enum rte_dev_event_type type;/**< device event type */ +int subsystem;/**< subsystem id */ +char *devname;/**< device name */ +}; + +typedef int (*rte_dev_event_cb_fn )(char *device_name, +enum rte_dev_event_type event, +void *cb_arg); + __attribute__((format (printf,2 ,0 )))static inline void rte_pmd_debug_trace (const char *func_name,const char *fmt, ...)@@ -267,4 +286,79 @@ __attribute__((used)) = str }#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It registers the callback for the specific device. +* Multiple callbacks cal be registered at the same time. +* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback. +* +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_callback_register (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* It unregisters the callback according to the specified device. +* +* @param device_name +* The device name, that is the param name of the struct rte_device, +* null value means for all devices. +* @param cb_fn +* callback address. +* @param cb_arg +* address of parameter for callback, (void *)-1 means to remove all +* registered which has the same callback address. +* +* @return +* - On success, return the number of callback entities removed. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_callback_unregister (const char *device_name, +rte_dev_event_cb_fn cb_fn, +void *cb_arg); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Start the device event monitoring. +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_start (void); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Stop the device event monitoring . +* +* @param none +* @return +* - On success, zero. +* - On failure, a negative value. +*/ +int __rte_experimental +rte_dev_event_monitor_stop (void);#endif /* _RTE_DEV_H_ */ lib/librte_eal/linuxapp/eal/Makefile +0
-0@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=
eal_lcore.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_timer.cSRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_interrupts.cSRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=eal_alarm.clib/librte_eal/linuxapp/eal/Makefile +1
-0+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_dev.c # from common dir SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.clib/librte_eal/linuxapp/eal/eal_dev.c new file +22
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018 Intel Corporation +*/ + +#include <rte_log.h> +#include <rte_compat.h> +#include <rte_dev.h> + + +int __rte_experimental +rte_dev_event_monitor_start (void) +{ +/* TODO: start uevent monitor for linux */ +return 0 ; +} + +int __rte_experimental +rte_dev_event_monitor_stop (void) +{ +/* TODO: stop uevent monitor for linux */ +return 0 ; +}lib/librte_eal/linuxapp/eal/meson.build +1
-0@@ -18,6 +18,7 @@ env_sources = files('eal_alarm.c', 'eal_vfio_mp_sync.c', 'eal.c', 'eal_memory.c', + 'eal_dev.c', ) if has_libnuma == 1lib/librte_eal/rte_eal_version.map +8
-1@@ -256,3 +256,11 @@ EXPERIMENTAL { rte_service_start_with_defaults; } DPDK_18.02; + +EXPERIMENTAL { + global: + + rte_dev_event_callback_register; + rte_dev_event_callback_unregister; + +} DPDK_18.05; --2.7.4