Skip to contentSkip to conversation

sched/starvation: Choose from available cpus

PATCH In review Edward Liaw via ltp 2 participants 4 messages Jun 19, 2024

lore
Share & tools
lore
#0 lore raw

v5 cover sched/starvation: Choose from available cpus

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

v1: https://lore.kernel.org/ltp/[email protected]/

v2: https://lore.kernel.org/ltp/[email protected]/
Made these substitutions based on Wei's suggestions:
s/TST_EXP_POSITIVE/TST_EXP_PASS
s/TCONF/TBROK

v3: https://lore.kernel.org/ltp/[email protected]/
Substituted test macros with check based on Petr's suggestions. Split commit into two: first to fix the return code check on sched_setaffinity. Second to choose the cpu.

v4: https://lore.kernel.org/ltp/[email protected]/
Fixed some typos and commit tags.

v5:
Got the return code check reversed again. Fixed it.

Edward Liaw via ltp (2):
sched/starvation: Fix sched_setaffinity return check sched/starvation: Choose from available cpus

 .../kernel/sched/cfs-scheduler/starvation.c   | 21 +++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

--
2.45.2.627.g7a2c4fd464-goog

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

PATCH v5 1/2 sched/starvation: Fix sched_setaffinity return check

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

TST_EXP_POSITIVE to check the return value is incorrect because sched_setaffinity returns 0 on success / -1 on failure.

---
 testcases/kernel/sched/cfs-scheduler/starvation.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
testcases/kernel/sched/cfs-scheduler/starvation.c +2 -1
index eb9fd6ff5..c845af849 100644
@@ -54,7 +54,8 @@ static void setup(void)
 
 	CPU_SET(0, &mask);
 
-	TST_EXP_POSITIVE(sched_setaffinity(0, sizeof(mask), &mask));
+	if (sched_setaffinity(0, sizeof(mask), &mask) < 0)
+		tst_brk(TBROK | TERRNO, "sched_setaffinity() failed");
 
 	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.2.627.g7a2c4fd464-goog


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

PATCH v5 2/2 sched/starvation: Choose from available cpus

In reply to Edward Liaw via ltp

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    | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
testcases/kernel/sched/cfs-scheduler/starvation.c +17 -1
index c845af849..9ac388fdc 100644
@@ -49,10 +49,26 @@ 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 */
+	if (sched_getaffinity(0, sizeof(mask), &mask) < 0)
+		tst_brk(TBROK | TERRNO, "sched_getaffinity() failed");
+
+	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_res(TINFO, "Setting affinity to CPU %d", cpu);
 
 	if (sched_setaffinity(0, sizeof(mask), &mask) < 0)
 		tst_brk(TBROK | TERRNO, "sched_setaffinity() failed");
Signature · 5 lines
2.45.2.627.g7a2c4fd464-goog


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

Hi Edward,

Thanks a lot for spotting reversed return code check in v4. merged, thank you!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp