From patchwork Mon Sep 10 13:51:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zhang X-Patchwork-Id: 44513 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 411154CA7; Mon, 10 Sep 2018 15:50:20 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 522C511A4 for ; Mon, 10 Sep 2018 15:50:16 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 06:50:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,355,1531810800"; d="scan'208";a="261342418" Received: from dpdk51.sh.intel.com ([10.67.110.190]) by fmsmga005.fm.intel.com with ESMTP; 10 Sep 2018 06:50:11 -0700 From: Qi Zhang To: thomas@monjalon.net, konstantin.ananyev@intel.com, declan.doherty@intel.com, ferruh.yigit@intel.com Cc: dev@dpdk.org, benjamin.h.shelton@intel.com, narender.vangati@intel.com, Qi Zhang Date: Mon, 10 Sep 2018 21:51:06 +0800 Message-Id: <20180910135107.6286-2-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180910135107.6286-1-qi.z.zhang@intel.com> References: <20180910135107.6286-1-qi.z.zhang@intel.com> Subject: [dpdk-dev] [RFC v2 1/2] ethdev: claim device reset as async X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" rte_eth_dev_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 claims rte_eth_dev_reset is an async function 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. Signed-off-by: Qi Zhang --- lib/librte_ethdev/rte_ethdev.c | 48 ++++++++++++++++++++++++++++++++++++++++-- lib/librte_ethdev/rte_ethdev.h | 48 ++++++++++++++++++++++++++---------------- 2 files changed, 76 insertions(+), 20 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 4c3202505..4c07dabcf 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -1374,10 +1374,38 @@ rte_eth_dev_close(uint16_t port_id) dev->data->tx_queues = NULL; } +struct dev_reset_args { + struct rte_eth_dev *dev; + enum rte_eth_dev_state pre_state; +}; + +static void * +do_dev_reset(void *args) +{ + struct dev_reset_args *reset_args = args; + struct rte_eth_dev *dev = reset_args->dev; + int ret; + + ret = dev->dev_ops->dev_reset(dev); + + /*restore previous device state */ + dev->state = reset_args->pre_state; + + /* notify users */ + _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_RESET_COMPLETE, + &ret); + + free(args); + return NULL; +} + int rte_eth_dev_reset(uint16_t port_id) { struct rte_eth_dev *dev; + struct dev_reset_args *args; + char pthread_name[20]; + pthread_t tid; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); @@ -1385,10 +1413,26 @@ rte_eth_dev_reset(uint16_t port_id) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP); + /* already on resetting */ + if (dev->state == RTE_ETH_DEV_RESETTING) + return 0; + + args = calloc(1, sizeof(struct dev_reset_args)); + if (!args) + return -ENOMEM; + rte_eth_dev_stop(port_id); - ret = dev->dev_ops->dev_reset(dev); - return eth_err(port_id, ret); + /* store previous device state temporary */ + args->pre_state = dev->state; + + dev->state = RTE_ETH_DEV_RESETTING; + snprintf(pthread_name, sizeof(pthread_name), + "do_dev_reset_%d", port_id); + ret = rte_ctrl_thread_create(&tid, pthread_name, NULL, + do_dev_reset, args); + + return ret; } int __rte_experimental diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index 7070e9ab4..0739d9fe7 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -1239,6 +1239,8 @@ enum rte_eth_dev_state { RTE_ETH_DEV_DEFERRED, /** Device is in removed state when plug-out is detected. */ RTE_ETH_DEV_REMOVED, + /** Device is on resetting when rte_eth_dev_reset is called. */ + RTE_ETH_DEV_RESETTING, }; struct rte_eth_dev_sriov { @@ -1814,21 +1816,31 @@ void rte_eth_dev_close(uint16_t port_id); * RTE_ETH_EVENT_INTR_RESET event is detected, but can also use it to start * a port reset in other circumstances. * - * When this function is called, it first stops the port and then calls the - * PMD specific dev_uninit( ) and dev_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 calling rte_eth_dev_reset( ), the application should use - * 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. - * - * Note: To avoid unexpected behavior, the application should stop calling - * Tx and Rx functions before calling rte_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. + * + * So we claimed rte_eth_dev_reset as an async API, that makes things easy + * for an application that what to reset the device from the interrupt + * thread since typically a RTE_ETH_EVENT_INTR_RESET handler is invoked in + * interrupt thread. + * + * rte_eth_dev_reset will spawn a new thread to call ops->dev_reset, once it + * is finished, it will raise the RTE_ETH_EVENT_RESET_COMPLETE event to notify + * the application. + * + * Application should not assume device reset is finished after + * rte_eth_dev_reset 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. + * + * @Note + * To avoid unexpected behavior, the application should stop calling + * Tx and Rx functions before calling rte_eth_dev_reset( ). * * @param port_id * The port identifier of the Ethernet device. @@ -1837,10 +1849,8 @@ void rte_eth_dev_close(uint16_t port_id); * - (0) if successful. * - (-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); @@ -2574,6 +2584,8 @@ enum rte_eth_event_type { /**< queue state event (enabled/disabled) */ RTE_ETH_EVENT_INTR_RESET, /**< reset interrupt event, sent to VF on PF reset */ + RTE_ETH_EVENT_RESET_COMPLETE, + /**< inform application that reset is completed */ RTE_ETH_EVENT_VF_MBOX, /**< message from the VF received by PF */ RTE_ETH_EVENT_MACSEC, /**< MACsec offload related event */ RTE_ETH_EVENT_INTR_RMV, /**< device removal event */ From patchwork Mon Sep 10 13:51:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zhang X-Patchwork-Id: 44514 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E8EC44CC3; Mon, 10 Sep 2018 15:50:21 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id D0EF61B19 for ; Mon, 10 Sep 2018 15:50:16 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 06:50:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,355,1531810800"; d="scan'208";a="261342422" Received: from dpdk51.sh.intel.com ([10.67.110.190]) by fmsmga005.fm.intel.com with ESMTP; 10 Sep 2018 06:50:13 -0700 From: Qi Zhang To: thomas@monjalon.net, konstantin.ananyev@intel.com, declan.doherty@intel.com, ferruh.yigit@intel.com Cc: dev@dpdk.org, benjamin.h.shelton@intel.com, narender.vangati@intel.com, Qi Zhang Date: Mon, 10 Sep 2018 21:51:07 +0800 Message-Id: <20180910135107.6286-3-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180910135107.6286-1-qi.z.zhang@intel.com> References: <20180910135107.6286-1-qi.z.zhang@intel.com> Subject: [dpdk-dev] [RFC v2 2/2] testpmd: enable async device reset X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" rte_eth_dev_reset is claimed as an async API, so re-work on the device reset handling. Signed-off-by: Qi Zhang --- app/test-pmd/testpmd.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index ee48db2a3..8d4d7b4f9 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1918,6 +1918,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(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) { @@ -1946,7 +1994,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;