Skip to contentSkip to conversation

sched_football: isolcpus handling

PATCH Superseded Attila Fazekas 2 participants 2 messages Jan 13, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched_football: isolcpus handling

sched_football expects each player thread is scheduleable to all of the physical CPU threads, however for example when you are using isolcpus by default you threads are not scheduled to some CPU. It leads to the test hangs. 591c56b045b2d44a0f4ba1a13545420b23e909b5solved was asimilar issue in realtime/prio-preempt .

---
 .../realtime/func/sched_football/sched_football.c  | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
testcases/realtime/func/sched_football/sched_football.c +13 -1
index 763b41f23..e4ae6a027 100644
@@ -133,6 +133,18 @@ void referee(int game_length)
 	TST_EXP_EXPR(final_ball == 0);
 }
 
+static inline 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);
+}
+
 static void do_test(void)
 {
 	struct sched_param param;
@@ -140,7 +152,7 @@ static void do_test(void)
 	int i;
 
 	if (players_per_team == 0)
-		players_per_team = sysconf(_SC_NPROCESSORS_ONLN);
+		players_per_team = get_numcpus();
 
 	tst_atomic_store(0, &players_ready);
 
Signature · 5 lines
2.47.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Attila,

Quoted 5 lines

sched_football expects each player thread is scheduleable to all of the physical CPU threads, however for example when you are using isolcpus by default you threads are not scheduled to some CPU. It leads to the test hangs. 591c56b045b2d44a0f4ba1a13545420b23e909b5solved was asimilar issue

nit: missing spaces:
591c56b045b2d44a0f4ba1a13545420b23e909b5 solved was a similar issue

Quoted 16 lines

in realtime/prio-preempt .

---
 .../realtime/func/sched_football/sched_football.c  | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
testcases/realtime/func/sched_football/sched_football.c +1 -0
index 763b41f23..e4ae6a027 100644
@@ -133,6 +133,18 @@ void referee(int game_length)
 	TST_EXP_EXPR(final_ball == 0);
 }
 
+static inline int get_numcpus(void)

testcases/realtime/func/sched_football/sched_football.c void referee(int game_length) · line 146

Quoted 10 lines
testcases/realtime/func/sched_football/sched_football.c +10 -0
+{
+	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);
+}

Can't we unify these get_numcpus() functions and move to librttest.[ch]?

Also we have similar code in testcases/kernel/sched/cfs-scheduler/starvation.c added in 1800e635783b69cacdce9f654ecd730a8f30915b (uses code from lib/tst_cpu.c), but that's outside of testcases/realtime/, thus let's keep it untouched.

Kind regards,
Petr

Quoted 12 lines
testcases/realtime/func/sched_football/sched_football.c +2 -1
+
 static void do_test(void)
 {
 	struct sched_param param;
@@ -140,7 +152,7 @@ static void do_test(void)
 	int i;
 
 	if (players_per_team == 0)
-		players_per_team = sysconf(_SC_NPROCESSORS_ONLN);
+		players_per_team = get_numcpus();
 
 	tst_atomic_store(0, &players_ready);
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp