Skip to contentSkip to conversation

test/service: fix race condition on stopping lcore

PATCH In review Kevin Laatz 3 participants 5 messages Oct 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test/service: fix race condition on stopping lcore

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.

---
 app/test/test_service_cores.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
app/test/test_service_cores.c +14 -5
index 5d92bea8af..44b6fc3624 100644
@@ -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.");
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines

-----Original Message-----
From: Laatz, Kevin <[email protected]>
Sent: Friday, October 16, 2020 10:08 AM
To: [email protected]
Cc: Van Haaren, Harry <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Laatz, Kevin <[email protected]>
Subject: [PATCH] test/service: fix race condition on stopping lcore

Quoted 8 lines

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.

Thanks Kevin for handling; can't reproduce race-cond here, but by code review this is the correct fix, thanks also for refactoring the wait into its own function.

#2 lore raw
Quoted 8 lines · Harry
Quoted 8 lines

Subject: [PATCH] test/service: fix race condition on stopping lcore

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.

Fixes 4d55194d76a4 ("service: add attribute get function")
Quoted 2 lines
Quoted 1 line

Thanks Kevin, Harry, applied.

Signature · 1 line
David Marchand
#3 lore raw
In reply to Kevin Laatz
Quoted 7 lines · Kevin Laatz

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.

We won't backport it, since we need a new API, but I would flag it for info as:

Fixes 4d55194d76a4 ("service: add attribute get function")

Ok for you?

--
David Marchand

#4 lore raw
Quoted 17 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, October 16, 2020 12:50 PM
To: Laatz, Kevin <[email protected]>; Van Haaren, Harry <[email protected]>
Cc: dev <[email protected]>; Lukasz Wojciechowski <[email protected]>; Honnappa Nagarahalli <[email protected]>; Phil Yang <[email protected]>; Aaron Conole <[email protected]>
Subject: Re: [PATCH] test/service: fix race condition on stopping lcore

Quoted 5 lines · Kevin Laatz

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.

Quoted 7 lines
Quoted 2 lines

This patch fixes the race condition by waiting for the service core thread to stop before continuing with the unit test checks.

We won't backport it, since we need a new API, but I would flag it for info as:

Fixes 4d55194d76a4 ("service: add attribute get function")

Ok for you?

Yes - thanks.

Quoted 1 line

David Marchand