DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kevin Laatz <kevin.laatz@intel.com>
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 <kevin.laatz@intel.com>
Subject: [dpdk-dev] [PATCH] test/service: fix race condition on stopping lcore
Date: Fri, 16 Oct 2020 10:08:04 +0100	[thread overview]
Message-ID: <20201016090804.1242907-1-kevin.laatz@intel.com> (raw)

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 <kevin.laatz@intel.com>
---
 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.");
-- 
2.25.1


             reply	other threads:[~2020-10-16  9:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-16  9:08 Kevin Laatz [this message]
2020-10-16  9:18 ` Van Haaren, Harry
2020-10-16 11:54   ` David Marchand
2020-10-16 11:50 ` David Marchand
2020-10-16 11:51   ` Van Haaren, Harry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201016090804.1242907-1-kevin.laatz@intel.com \
    --to=kevin.laatz@intel.com \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=aconole@redhat.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=harry.van.haaren@intel.com \
    --cc=l.wojciechow@partner.samsung.com \
    --cc=phil.yang@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).