public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] realtime/prio-preempt: take cpu isolation into consideration
@ 2024-07-10  3:24 Shizhao Chen
  2024-07-10  6:13 ` Li Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Shizhao Chen @ 2024-07-10  3:24 UTC (permalink / raw)
  To: ltp, Li Wang, Eder Zulian

By default the test starts N-1 busy threads to monopolize N-1 available CPUs,
where N is the number of all available CPUs. However, when CPU isolation is
applied, this will lead to a hang scenario where all housekeeping CPUs are
hogged as isolated CPUs do not share the N-1 busy threads.

Signed-off-by: Shizhao Chen <shichen@redhat.com>
---
 .../realtime/func/prio-preempt/prio-preempt.c  | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/testcases/realtime/func/prio-preempt/prio-preempt.c b/testcases/realtime/func/prio-preempt/prio-preempt.c
index 9bd5e7ad8..79d2115a7 100644
--- a/testcases/realtime/func/prio-preempt/prio-preempt.c
+++ b/testcases/realtime/func/prio-preempt/prio-preempt.c
@@ -59,6 +59,7 @@
  *
  *****************************************************************************/
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
@@ -287,6 +288,17 @@ void *master_thread(void *arg)
 	return NULL;
 }
 
+int get_numcpus(void)
+{
+	cpu_set_t mask;
+	CPU_ZERO(&mask);
+
+	/* Get the number of cpus accessible to the current process */
+	sched_getaffinity(getpid(), sizeof(mask), &mask);
+
+	return CPU_COUNT(&mask);
+}
+
 int main(int argc, char *argv[])
 {
 	int pri_boost, numcpus;
@@ -295,10 +307,10 @@ int main(int argc, char *argv[])
 	pass_criteria = CHECK_LIMIT;
 	rt_init("hin:", parse_args, argc, argv);
 
-	numcpus = sysconf(_SC_NPROCESSORS_ONLN);
+	numcpus = get_numcpus();
 
-	/* Max no. of busy threads should always be less than/equal the no. of cpus
-	   Otherwise, the box will hang */
+	/* Max no. of busy threads should always be less than/equal the no. of
+	   housekeeping cpus. Otherwise, the box will hang */
 
 	if (rt_threads == -1 || rt_threads > numcpus) {
 		rt_threads = numcpus;
-- 
2.45.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-07-11  6:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-10  3:24 [LTP] [PATCH] realtime/prio-preempt: take cpu isolation into consideration Shizhao Chen
2024-07-10  6:13 ` Li Wang
2024-07-10  6:27   ` Li Wang
2024-07-10 13:12     ` [LTP] [PATCH v2] " Shizhao Chen
2024-07-11  6:56       ` Li Wang
2024-07-10 13:16     ` [LTP] [PATCH] " Shizhao Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox