From patchwork Fri Oct 16 09:08:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Laatz X-Patchwork-Id: 81068 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 595DAA04DB; Fri, 16 Oct 2020 11:13:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 230841EACA; Fri, 16 Oct 2020 11:13:05 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 831581EAA1 for ; Fri, 16 Oct 2020 11:13:02 +0200 (CEST) IronPort-SDR: NzBYWH3gCvfKqu/m1C8hQKqKmudvJ06b78/FuME0crZVllDKSl1saZBeLcBuKUrEgi/ZMC8auN kTj40zONyOQQ== X-IronPort-AV: E=McAfee;i="6000,8403,9775"; a="184126155" X-IronPort-AV: E=Sophos;i="5.77,382,1596524400"; d="scan'208";a="184126155" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2020 02:13:01 -0700 IronPort-SDR: DYKkdg30Pkra7cHobysjXbjPfDVK5RT7NDbArsoi3cQyttEQWMaB2D0E05l8oe5qyfTuwt1owE 44Lpi1gVBWqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,382,1596524400"; d="scan'208";a="314834597" Received: from silpixa00399838.ir.intel.com ([10.237.213.224]) by orsmga003.jf.intel.com with ESMTP; 16 Oct 2020 02:12:58 -0700 From: Kevin Laatz To: dev@dpdk.org Cc: harry.van.haaren@intel.com, david.marchand@redhat.com, l.wojciechow@partner.samsung.com, Honnappa.Nagarahalli@arm.com, phil.yang@arm.com, aconole@redhat.com, Kevin Laatz Date: Fri, 16 Oct 2020 10:08:04 +0100 Message-Id: <20201016090804.1242907-1-kevin.laatz@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] test/service: fix race condition on stopping lcore 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" There is a potential race condition in 'service_attr_get' which will cause test failures since the service core thread is still running while the values are being retrieved/reset. This patch fixes the race condition by waiting for the service core thread to stop before continuing with the unit test checks. Signed-off-by: Kevin Laatz Acked-by: Harry van Haaren --- app/test/test_service_cores.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/test/test_service_cores.c b/app/test/test_service_cores.c index 5d92bea8af..44b6fc3624 100644 --- a/app/test/test_service_cores.c +++ b/app/test/test_service_cores.c @@ -119,6 +119,17 @@ unregister_all(void) return TEST_SUCCESS; } +/* Wait until service lcore not active, or for 100x SERVICE_DELAY */ +static void +wait_slcore_inactive(uint32_t slcore_id) +{ + int i; + + for (i = 0; rte_service_lcore_may_be_active(slcore_id) == 1 && + i < 100; i++) + rte_delay_ms(SERVICE_DELAY); +} + /* register a single dummy service */ static int dummy_register(void) @@ -305,6 +316,8 @@ service_attr_get(void) rte_service_lcore_stop(slcore_id); + wait_slcore_inactive(slcore_id); + TEST_ASSERT_EQUAL(0, rte_service_attr_get(id, attr_calls, &attr_value), "Valid attr_get() call didn't return success"); TEST_ASSERT_EQUAL(1, (attr_value > 0), @@ -394,11 +407,7 @@ service_lcore_attr_get(void) TEST_ASSERT_EQUAL(0, rte_service_lcore_stop(slcore_id), "Failed to stop service lcore"); - /* Wait until service lcore not active, or for 100x SERVICE_DELAY */ - int i; - for (i = 0; rte_service_lcore_may_be_active(slcore_id) == 1 && - i < 100; i++) - rte_delay_ms(SERVICE_DELAY); + wait_slcore_inactive(slcore_id); TEST_ASSERT_EQUAL(0, rte_service_lcore_may_be_active(slcore_id), "Service lcore not stopped after waiting.");