ethdev: claim device reset as async
PATCH 1/1 ethdev: claim device reset as async
Device reset should be implemented in an async way since it is possible to be invoked in interrupt thread and sometimes to reset a device need to wait for some dependency, for example, a VF expects for PF ready or a NIC function as part of a SOC wait for the whole system reset complete, and all these time-consuming tasks will block the interrupt thread.
The patch rename rte_eth_dev_reset to rte_eth_dev_reset_async and rework the implementation. It will spawn a new thread which will call ops->dev_reset, and when finished it will raise the event RTE_ETH_EVENT_RESET_COMPLETE. The application should always wait for this event before it continues to configure and restart the device.
---
RFC3 -> v1
- fix state check in rte_eth_find_next and rte_eth_find_next_owned_by
- fix compile error in netvsc
- update document and release notes
- improve comments and couple typo fix
app/test-pmd/testpmd.c | 50 +++++++++++++++++++++++++++- doc/guides/prog_guide/poll_mode_drv.rst | 34 ++++++++++++------- doc/guides/rel_notes/release_19_05.rst | 6 ++++ drivers/net/ixgbe/ixgbe_ethdev.c | 4 +-- drivers/net/netvsc/hn_var.h | 2 +- drivers/net/netvsc/hn_vf.c | 4 +-- lib/librte_ethdev/rte_ethdev.c | 56 +++++++++++++++++++++++++++++--- lib/librte_ethdev/rte_ethdev.h | 50 +++++++++++++++++----------- lib/librte_ethdev/rte_ethdev_version.map | 7 ++++ 9 files changed, 171 insertions(+), 42 deletions(-)
app/test-pmd/testpmd.c +49 -1
@@ -2232,6 +2232,54 @@ close_port(portid_t pid)printf ("Done\n" ); } +static int reset_ret; +static int reset_done; + +static int +on_reset_complete(__rte_unused uint16_t port_id, + __rte_unused enum rte_eth_event_type event, + __rte_unused void *cb_arg, +void *ret_param) +{ +RTE_ASSERT (event ==RTE_ETH_EVENT_RESET_COMPLETE ); + + reset_ret = *(int *)ret_param; + reset_done =1 ; +return 0 ; +} + +static int +do_dev_reset_sync (portid_t pid) +{ +int ret; + + ret =rte_eth_dev_callback_register (pid, +RTE_ETH_EVENT_RESET_COMPLETE , + on_reset_complete,NULL ); + +if (ret) { +printf ("Fail to reigster callback function\n" ); +return ret; + } + + reset_done =0 ; + ret =rte_eth_dev_reset_async (pid); +if (ret) + goto finish; + +while (!reset_done) +rte_delay_ms (10 ); + + ret = reset_ret; + +finish: +rte_eth_dev_callback_unregister (pid, +RTE_ETH_EVENT_RESET_COMPLETE , + on_reset_complete,NULL ); + +return ret; +} +void reset_port (portid_t pid) {
@@ -2260,7 +2308,7 @@ reset_port(portid_t pid)continue ; } - diag =rte_eth_dev_reset (pi); + diag =do_dev_reset_sync (pi);if (diag ==0 ) { port = &ports[pi]; port->need_reconfig =1 ;
doc/guides/prog_guide/poll_mode_drv.rst +22 -12
@@ -581,7 +581,7 @@ NIC Reset API .. code-block:: c - int rte_eth_dev_reset(uint16_t port_id); + int rte_eth_dev_reset_sync(uint16_t port_id); Sometimes a port has to be reset passively. For example when a PF is reset, all its VFs should also be reset by the application to make them
@@ -594,7 +594,7 @@ the application should register a callback function to handle these events. When a PMD needs to trigger a reset, it can trigger an RTE_ETH_EVENT_INTR_RESET event. On receiving an RTE_ETH_EVENT_INTR_RESET event, applications can handle it as follows: Stop working queues, stop -calling Rx and Tx functions, and then call rte_eth_dev_reset(). For +calling Rx and Tx functions, and then call rte_eth_dev_reset_sync(). For thread safety all these operations should be called from the same thread. For example when PF is reset, the PF sends a message to notify VFs of
@@ -605,13 +605,23 @@ This means that a PF reset triggers an RTE_ETH_EVENT_INTR_RESET event within VFs. The function _rte_eth_dev_callback_process() will call the registered callback function. The callback function can trigger the application to handle all operations the VF reset requires including -stopping Rx/Tx queues and calling rte_eth_dev_reset(). - -The rte_eth_dev_reset() itself is a generic function which only does -some hardware reset operations through calling dev_unint() and -dev_init(), and itself does not handle synchronization, which is handled -by application. - -The PMD itself should not call rte_eth_dev_reset(). The PMD can trigger -the application to handle reset event. It is duty of application to -handle all synchronization before it calls rte_eth_dev_reset(). +stopping Rx/Tx queues and calling rte_eth_dev_reset_async(). + +As the name, rte_eth_dev_reset_async is an async API, it will spwan a +new thread to call ops->dev_reset, once it is finished, it will raise +the RTE_ETH_EVENT_RESET_COMPLETE event to notify application. That makes +things easy for an application that want to reset the device from the +interrupt thread since typically a RTE_ETH_EVENT_INTR_RESET handler is +invoked in interrupt thread. The typical implementation of ops->dev_reset +will do some hardware reset operations through calling dev_uninit() and +dev_init(). + +Application should not assume device reset is finished after +rte_eth_dev_reset_async return, it should always wait for a +RTE_ETH_EVENT_RESET_COMPLETE event and check the reset result. +If reset success, application should call rte_eth_dev_configure(), +rte_eth_rx_queue_setup(), rte_eth_tx_queue_setup(), +and rte_eth_dev_start() to reconfigure the device as appropriate. + +To avoid unexpected behavior, the application should stop calling +Tx and Rx functions before calling rte_eth_dev_reset_async().
doc/guides/rel_notes/release_19_05.rst +6 -0
@@ -91,6 +91,12 @@ New Features * Added promiscuous mode support. +* **Claim device reset as async API.** + + rte_eth_dev_reset is replaced by rte_eth_dev_reset_async which is implemented + as an async API. Application should wait for RTE_ETH_EVENT_RESET_COMPLETE + event after invoke the API before continues to configure and restart the + device. Removed Items -------------
drivers/net/ixgbe/ixgbe_ethdev.c +2 -2
@@ -1631,8 +1631,8 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)PMD_INIT_LOG (ERR ,"VF Initialization Failure: %d" , diag);/* * This error code will be propagated to the app by -* rte_eth_dev_reset, so use a public error code rather than -* the internal-only IXGBE_ERR_RESET_FAILED +* rte_eth_dev_reset_async, so use a public error code rather +* than the internal-only IXGBE_ERR_RESET_FAILED */ return -EAGAIN ; }
drivers/net/netvsc/hn_var.h +1 -1
@@ -177,7 +177,7 @@ int hn_vf_configure(struct rte_eth_dev *dev, const struct rte_eth_conf *dev_conf);const uint32_t *hn_vf_supported_ptypes (struct rte_eth_dev *dev);int hn_vf_start (struct rte_eth_dev *dev); -void hn_vf_reset (struct rte_eth_dev *dev); +void hn_vf_reset_async (struct rte_eth_dev *dev);void hn_vf_stop (struct rte_eth_dev *dev);void hn_vf_close (struct rte_eth_dev *dev);
drivers/net/netvsc/hn_vf.c +2 -2
@@ -358,9 +358,9 @@ void hn_vf_stop(struct rte_eth_dev *dev)rte_spinlock_unlock (&hv->vf_lock); \ } -void hn_vf_reset (struct rte_eth_dev *dev) +void hn_vf_reset_async (struct rte_eth_dev *dev) { -VF_ETHDEV_FUNC (dev, rte_eth_dev_reset); +VF_ETHDEV_FUNC (dev, rte_eth_dev_reset_async); }void hn_vf_close (struct rte_eth_dev *dev)
lib/librte_ethdev/rte_ethdev.c +51 -5
85 lines not on this page · raw message
lib/librte_ethdev/rte_ethdev.h +31 -19
76 lines not on this page · raw message
lib/librte_ethdev/rte_ethdev_version.map +7 -0
@@ -229,6 +229,13 @@ DPDK_18.11 { } DPDK_18.08; +DPDK_19.05 { + global: + + rte_eth_dev_reset_async; + +} DPDK_18.08; + EXPERIMENTAL { global:
Signature · 1 line
2.13.6
lib/librte_ethdev/rte_ethdev.c rte_eth_dev_reset(uint16_t port_id) · line 1553
Quoted 4 lines · On Wed, 20 Mar 2019 12:54:03 +0800 Qi Zhang <[email protected]> wrote:
lib/librte_ethdev/rte_ethdev.c +4
-0+ ret =rte_ctrl_thread_create (&tid, pthread_name,NULL , + do_dev_reset, args); + +return ret;
combine the ret = and return (ie make it a tail call)
Hi,
You forgot to Cc Andrew, co-maintainer of ethdev.
20/03/2019 05:54, Qi Zhang:
Quoted 59 lines
Device reset should be implemented in an async way since it is possible to be invoked in interrupt thread and sometimes to reset a device need to wait for some dependency, for example, a VF expects for PF ready or a NIC function as part of a SOC wait for the whole system reset complete, and all these time-consuming tasks will block the interrupt thread.
The patch renamerte_eth_dev_resettorte_eth_dev_reset_asyncand rework the implementation. It will spawn a new thread which will callops->dev_reset, and when finished it will raise the eventRTE_ETH_EVENT_RESET_COMPLETE. The application should always wait for this event before it continues to configure and restart the device.Signed-off-by Qi Zhang <[email protected]>---
- * When this function is called, it first stops the port and then calls the
- * PMD specificdev_uninit( )anddev_init( )to return the port to initial
- * state, in which no Tx and Rx queues are setup, as if the port has been
- * reset and not started. The port keeps the port id it had before the
- * function call.
- *
- * After callingrte_eth_dev_reset( ), the application should use
- *rte_eth_dev_configure( ),rte_eth_rx_queue_setup( ),
- *rte_eth_tx_queue_setup( ), andrte_eth_dev_start( )
- * to reconfigure the device as appropriate.
- *
- * Note: To avoid unexpected behavior, the application should stop calling
- * Tx and Rx functions before callingrte_eth_dev_reset( ). For thread
- * safety, all these controlling functions should be called from the same
- * thread.
+ * @note
+ * Device reset may have the dependency, for example, a VF reset expects
+ * PF ready, or a NIC function as a part of a SOC need to wait for other
+ * parts of the system be ready, these are time-consuming tasks and will
+ * block current thread.
+ *
+ * As the name,rte_eth_dev_reset_asyncis an async API, it will spwan a
+ * new thread to callops->dev_reset, once it is finished, it will raise
+ * theRTE_ETH_EVENT_RESET_COMPLETEevent to notify application. That makes
+ * things easy for an application that want to reset the device from the
+ * interrupt thread since typically aRTE_ETH_EVENT_INTR_RESEThandler is
+ * invoked in interrupt thread. The typical implementation ofops->dev_reset
+ * will do some hardware reset operations through callingdev_uninit()and
+ *dev_init().
+ *
+ * Application should not assume device reset is finished after
+ *rte_eth_dev_reset_asyncreturn, it should always wait for a
+ *RTE_ETH_EVENT_RESET_COMPLETEevent and check the reset result.
+ * If reset success, application should callrte_eth_dev_configure( ),
+ *rte_eth_rx_queue_setup( ),rte_eth_tx_queue_setup( ),
+ * andrte_eth_dev_start( )to reconfigure the device as appropriate.
+ *
+ * @Note
+ * To avoid unexpected behavior, the application should stop calling
+ * Tx and Rx functions before callingrte_eth_dev_reset_async( ). *
* @paramport_id
* The port identifier of the Ethernet device.lib/librte_ethdev/rte_ethdev.h +0
-0@@ -1880,12 +1892,10 @@ void rte_eth_dev_close(uint16_t port_id);* - (0) if successful.
lib/librte_ethdev/rte_ethdev.h void rte_eth_dev_close(uint16_t port_id); · line 1898
Quoted 10 lines
lib/librte_ethdev/rte_ethdev.h +2
-4* - (-EINVAL) if port identifier is invalid. * - (-ENOTSUP) if hardware doesn't support this function. -* - (-EPERM) if not ran from the primary process. -* - (-EIO) if re-initialisation failed or device is removed. * - (-ENOMEM) if the reset failed due to OOM. -* - (-EAGAIN) if the reset temporarily failed and should be retried later. +* - (<0) other errors from low level driver. */ -int rte_eth_dev_reset (uint16_t port_id); +int rte_eth_dev_reset_async (uint16_t port_id);
Sorry I didn't check whether this API is better or not,
but I know it cannot be accepted before proposing a deprecation notice. Perhaps you may keep the old API and just add the new one.
Honestly, I never really agreed with the purpose of the reset API. So making it async or not, I have no real opinion...
... but spawning a new thread at each function call, I feel it is bad.
Quoted 78 lines · Thomas Monjalon
Hi,
You forgot to Cc Andrew, co-maintainer of ethdev.
20/03/2019 05:54, Qi Zhang:
Quoted 59 lines
Device reset should be implemented in an async way since it is possible to be invoked in interrupt thread and sometimes to reset a device need to wait for some dependency, for example, a VF expects for PF ready or a NIC function as part of a SOC wait for the whole system reset complete, and all these time-consuming tasks will block the interrupt thread.
The patch renamerte_eth_dev_resettorte_eth_dev_reset_asyncand rework the implementation. It will spawn a new thread which will callops->dev_reset, and when finished it will raise the eventRTE_ETH_EVENT_RESET_COMPLETE. The application should always wait for this event before it continues to configure and restart the device.Signed-off-by Qi Zhang <[email protected]>---
- * When this function is called, it first stops the port and then calls the
- * PMD specificdev_uninit( )anddev_init( )to return the port to initial
- * state, in which no Tx and Rx queues are setup, as if the port has been
- * reset and not started. The port keeps the port id it had before the
- * function call.
- *
- * After callingrte_eth_dev_reset( ), the application should use
- *rte_eth_dev_configure( ),rte_eth_rx_queue_setup( ),
- *rte_eth_tx_queue_setup( ), andrte_eth_dev_start( )
- * to reconfigure the device as appropriate.
- *
- * Note: To avoid unexpected behavior, the application should stop calling
- * Tx and Rx functions before callingrte_eth_dev_reset( ). For thread
- * safety, all these controlling functions should be called from the same
- * thread.
+ * @note
+ * Device reset may have the dependency, for example, a VF reset expects
+ * PF ready, or a NIC function as a part of a SOC need to wait for other
+ * parts of the system be ready, these are time-consuming tasks and will
+ * block current thread.
+ *
+ * As the name,rte_eth_dev_reset_asyncis an async API, it will spwan a
+ * new thread to callops->dev_reset, once it is finished, it will raise
+ * theRTE_ETH_EVENT_RESET_COMPLETEevent to notify application. That makes
+ * things easy for an application that want to reset the device from the
+ * interrupt thread since typically aRTE_ETH_EVENT_INTR_RESEThandler is
+ * invoked in interrupt thread. The typical implementation ofops->dev_reset
+ * will do some hardware reset operations through callingdev_uninit()and
+ *dev_init().
+ *
+ * Application should not assume device reset is finished after
+ *rte_eth_dev_reset_asyncreturn, it should always wait for a
+ *RTE_ETH_EVENT_RESET_COMPLETEevent and check the reset result.
+ * If reset success, application should callrte_eth_dev_configure( ),
+ *rte_eth_rx_queue_setup( ),rte_eth_tx_queue_setup( ),
+ * andrte_eth_dev_start( )to reconfigure the device as appropriate.
+ *
+ * @Note
+ * To avoid unexpected behavior, the application should stop calling
+ * Tx and Rx functions before callingrte_eth_dev_reset_async( ). *
* @paramport_id
* The port identifier of the Ethernet device.lib/librte_ethdev/rte_ethdev.h +0
-0@@ -1880,12 +1892,10 @@ void rte_eth_dev_close(uint16_t port_id);* - (0) if successful. lib/librte_ethdev/rte_ethdev.h void rte_eth_dev_close(uint16_t port_id); · line 1898
Quoted 10 lines
lib/librte_ethdev/rte_ethdev.h +2
-4* - (-EINVAL) if port identifier is invalid. * - (-ENOTSUP) if hardware doesn't support this function. -* - (-EPERM) if not ran from the primary process. -* - (-EIO) if re-initialisation failed or device is removed. * - (-ENOMEM) if the reset failed due to OOM. -* - (-EAGAIN) if the reset temporarily failed and should be retried later. +* - (<0) other errors from low level driver. */ -int rte_eth_dev_reset (uint16_t port_id); +int rte_eth_dev_reset_async (uint16_t port_id);Sorry I didn't check whether this API is better or not,
but I know it cannot be accepted before proposing a deprecation notice. Perhaps you may keep the old API and just add the new one.
Quoted 3 lines
Honestly, I never really agreed with the purpose of the reset API. So making it async or not, I have no real opinion...
... but spawning a new thread at each function call, I feel it is bad.
I agree with Thomas.
It looks very dangerous from locking point of view when a PMD callback is executed from dynamically created thread.