[PATCH v2] test/lcores: reduce cpu consumption
David Marchand
david.marchand at redhat.com
Thu Mar 7 15:16:06 CET 2024
Busy looping on RTE_MAX_LCORES threads is too heavy in some CI or build
systems running the fast-test testsuite.
Ask for a reschedule at the threads synchronisation points.
Signed-off-by: David Marchand <david.marchand at redhat.com>
Acked-by: Luca Boccassi <bluca at debian.org>
---
Changes since v1:
- fix build with mingw,
---
app/test/test_lcores.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c
index 22225a9fd3..08c4e8dfba 100644
--- a/app/test/test_lcores.c
+++ b/app/test/test_lcores.c
@@ -2,7 +2,9 @@
* Copyright (c) 2020 Red Hat, Inc.
*/
+#include <sched.h>
#include <string.h>
+#include <unistd.h>
#include <rte_common.h>
#include <rte_errno.h>
@@ -11,6 +13,14 @@
#include "test.h"
+#ifndef _POSIX_PRIORITY_SCHEDULING
+/* sched_yield(2):
+ * POSIX systems on which sched_yield() is available define _POSIX_PRIOR‐
+ * ITY_SCHEDULING in <unistd.h>.
+ */
+#define sched_yield()
+#endif
+
struct thread_context {
enum { Thread_INIT, Thread_ERROR, Thread_DONE } state;
bool lcore_id_any;
@@ -43,7 +53,7 @@ static uint32_t thread_loop(void *arg)
/* Wait for release from the control thread. */
while (__atomic_load_n(t->registered_count, __ATOMIC_ACQUIRE) != 0)
- ;
+ sched_yield();
rte_thread_unregister();
lcore_id = rte_lcore_id();
if (lcore_id != LCORE_ID_ANY) {
@@ -85,7 +95,7 @@ test_non_eal_lcores(unsigned int eal_threads_count)
/* Wait all non-EAL threads to register. */
while (__atomic_load_n(®istered_count, __ATOMIC_ACQUIRE) !=
non_eal_threads_count)
- ;
+ sched_yield();
/* We managed to create the max number of threads, let's try to create
* one more. This will allow one more check.
@@ -101,7 +111,7 @@ test_non_eal_lcores(unsigned int eal_threads_count)
printf("non-EAL threads count: %u\n", non_eal_threads_count);
while (__atomic_load_n(®istered_count, __ATOMIC_ACQUIRE) !=
non_eal_threads_count)
- ;
+ sched_yield();
}
skip_lcore_any:
@@ -267,7 +277,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count)
non_eal_threads_count++;
while (__atomic_load_n(®istered_count, __ATOMIC_ACQUIRE) !=
non_eal_threads_count)
- ;
+ sched_yield();
if (l[0].init != eal_threads_count + 1 ||
l[1].init != eal_threads_count + 1) {
printf("Error: incorrect init calls, expected %u, %u, got %u, %u\n",
@@ -290,7 +300,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count)
non_eal_threads_count++;
while (__atomic_load_n(®istered_count, __ATOMIC_ACQUIRE) !=
non_eal_threads_count)
- ;
+ sched_yield();
if (l[0].init != eal_threads_count + 2 ||
l[1].init != eal_threads_count + 2) {
printf("Error: incorrect init calls, expected %u, %u, got %u, %u\n",
--
2.44.0
More information about the dev
mailing list