From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 7F0CD100C for ; Wed, 8 Aug 2018 09:00:08 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Aug 2018 00:00:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,456,1526367600"; d="scan'208";a="79500694" Received: from dpdk51.sh.intel.com ([10.67.110.190]) by fmsmga001.fm.intel.com with ESMTP; 08 Aug 2018 00:00:06 -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, beilei.xing@intel.com, wenzhuo.lu@intel.com, 0000-cover-letter.patch, Qi Zhang Date: Wed, 8 Aug 2018 15:00:45 +0800 Message-Id: <20180808070045.13334-4-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180808070045.13334-1-qi.z.zhang@intel.com> References: <20180808070045.13334-1-qi.z.zhang@intel.com> Subject: [dpdk-dev] [RFC 4/4] 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: , X-List-Received-Date: Wed, 08 Aug 2018 07:00:09 -0000 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 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index ee48db2a3..24d5c5d9c 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1918,6 +1918,59 @@ close_port(portid_t pid) printf("Done\n"); } +static pthread_mutex_t dev_reset_lock; +static pthread_cond_t dev_reset_cond; +static int reset_status; + +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); + + pthread_cond_broadcast(&dev_reset_cond); + + reset_status = *(int *)ret_param; + return 0; +} + +static int +do_dev_reset_sync(portid_t pid) +{ + int ret; + + pthread_mutex_init(&dev_reset_lock, NULL); + pthread_cond_init(&dev_reset_cond, NULL); + + 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; + } + + ret = rte_eth_dev_reset(pid); + if (ret) + goto finish; + + pthread_mutex_lock(&dev_reset_lock); + pthread_cond_wait(&dev_reset_cond, &dev_reset_lock); + pthread_mutex_unlock(&dev_reset_lock); + + ret = reset_status; + +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 +1999,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; -- 2.13.6