Skip to contentSkip to conversation

sched/starvation: Choose from available cpus

PATCH Superseded Edward Liaw via ltp 2 participants 2 messages Jun 6, 2024

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sched/starvation: Choose from available cpus

From: Edward Liaw via ltp <[email protected]>

Use the first available cpu in the sched_getaffinity set.

This test was failing as a 32bit test for some arm architectures where cpu 0 does not support 32bit applications.

---
 .../kernel/sched/cfs-scheduler/starvation.c   | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
testcases/kernel/sched/cfs-scheduler/starvation.c +17 -2
index eb9fd6ff5..0fd45e281 100644
@@ -49,12 +49,27 @@ again:
 static void setup(void)
 {
 	cpu_set_t mask;
+	int cpu = 0;
+	long ncpus = tst_ncpus_conf();
 
 	CPU_ZERO(&mask);
 
-	CPU_SET(0, &mask);
+	/* Restrict test to a single cpu */
+	TST_EXP_PASS(sched_getaffinity(0, sizeof(mask), &mask));
 
-	TST_EXP_POSITIVE(sched_setaffinity(0, sizeof(mask), &mask));
+	if (CPU_COUNT(&mask) == 0)
+		tst_brk(TBROK, "No cpus available");
+
+	while (CPU_ISSET(cpu, &mask) == 0 && cpu < ncpus)
+		cpu++;
+
+	CPU_ZERO(&mask);
+
+	CPU_SET(cpu, &mask);
+
+	TST_EXP_PASS(sched_setaffinity(0, sizeof(mask), &mask));
+
+	tst_res(TINFO, "Set affinity to CPU %d", cpu);
 
 	if (tst_parse_long(str_loop, &loop, 1, LONG_MAX))
 		tst_brk(TBROK, "Invalid number of loop number '%s'", str_loop);
Signature · 5 lines
2.45.1.467.gbab1589fc0-goog


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

Hi Edward, Wei,

Quoted 19 lines

Use the first available cpu in the sched_getaffinity set.

This test was failing as a 32bit test for some arm architectures where cpu 0 does not support 32bit applications.

---
 .../kernel/sched/cfs-scheduler/starvation.c   | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
testcases/kernel/sched/cfs-scheduler/starvation.c +0 -0
index eb9fd6ff5..0fd45e281 100644
@@ -49,12 +49,27 @@ again:
 static void setup(void)
 {
 	cpu_set_t mask;

testcases/kernel/sched/cfs-scheduler/starvation.c again: · line 57

Quoted 10 lines
testcases/kernel/sched/cfs-scheduler/starvation.c +4 -2
+	int cpu = 0;
+	long ncpus = tst_ncpus_conf();
 
 	CPU_ZERO(&mask);
 
-	CPU_SET(0, &mask);
+	/* Restrict test to a single cpu */
+	TST_EXP_PASS(sched_getaffinity(0, sizeof(mask), &mask));
 
-	TST_EXP_POSITIVE(sched_setaffinity(0, sizeof(mask), &mask));

Yeah, Wei was correct that both sched_getaffinity() and sched_setaffinity() should use TST_EXP_PASS() because return only 0 on success (non-zero value is in the mask, thus using TST_EXP_POSITIVE() was wrong. Ideally this would be in a separate commit (before your changes), but I'm ok just to note it in the commit message.

I was also thinking why test macros are used in setup() function (completely unrelated to the change), I would just use plain code:

if (!sched_getaffinity(0, sizeof(mask), &mask))

	tst_brk(TBROK | TERRNO, "sched_getaffinity() failed");

testcases/kernel/sched/cfs-scheduler/starvation.c again: · line 61

Quoted 2 lines
testcases/kernel/sched/cfs-scheduler/starvation.c +2 -0
+	if (CPU_COUNT(&mask) == 0)
+		tst_brk(TBROK, "No cpus available");

I was thinking a while and looking in other software which uses CPU_COUNT(). And agree this should be probably tst_brk(TBROK)

Kind regards,
Petr

Quoted 14 lines
testcases/kernel/sched/cfs-scheduler/starvation.c +11 -0
+
+	while (CPU_ISSET(cpu, &mask) == 0 && cpu < ncpus)
+		cpu++;
+
+	CPU_ZERO(&mask);
+
+	CPU_SET(cpu, &mask);
+
+	TST_EXP_PASS(sched_setaffinity(0, sizeof(mask), &mask));
+
+	tst_res(TINFO, "Set affinity to CPU %d", cpu);
 
 	if (tst_parse_long(str_loop, &loop, 1, LONG_MAX))
 		tst_brk(TBROK, "Invalid number of loop number '%s'", str_loop);
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp