Skip to contentSkip to conversation

selftests/sched: add proxy execution mutex tests

PATCH New [email protected] 1 participant 1 message Mar 9 Kselftest

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/sched: add proxy execution mutex tests

From: zhidao su <[email protected]>

Add basic selftests for the Proxy Execution (PE) feature (CONFIG_SCHED_PROXY_EXEC). Three test cases exercise the single-CPU PE path which is present in the current upstream kernel independently of the donor migration series (v24).

TC-1: Single-level mutex blocking
A SCHED_FIFO prio=80 thread blocks on a mutex held by a SCHED_OTHER thread doing CPU-intensive work. Verifies that the holder accumulates significant CPU time (>= 50ms out of 200ms hold period), confirming PE is running the holder as proxy for the high-priority waiter.

TC-2: blocked_on lifetime - no voluntary context switches
While a high-priority thread is PE-blocked on a mutex, its voluntary_ctxt_switches count must not increase. PE keeps the donor on the runqueue rather than doing a voluntary sleep, so no voluntary switch should occur during the block period.

TC-3: Two-level mutex chain traversal
A (prio=80) -> mutex1 -> B (prio=50) -> mutex2 -> C (SCHED_OTHER). Verifies PE traverses the full chain and runs C as proxy, confirmed by C accumulating >= 50ms CPU time while A and B are both blocked.

The test skips gracefully when:
- CONFIG_SCHED_PROXY_EXEC is not compiled in
- sched_proxy_exec=0 is set on the kernel command line
- not running as root (SCHED_FIFO requires CAP_SYS_NICE)

These tests cover the single-CPU PE base functionality and are orthogonal to the cross-CPU donor migration work (v24). They should remain valid after donor migration lands, as the single-CPU path is preserved.

Tested on Linux 7.0-rc2 with CONFIG_SCHED_PROXY_EXEC=y via virtme-ng on Intel Core i7-10700 @ 2.90GHz:
sched_proxy_exec=1: TC-1 PASS, TC-2 PASS, TC-3 PASS sched_proxy_exec=0: all SKIP

---
 tools/testing/selftests/sched/Makefile        |   6 +-
 tools/testing/selftests/sched/pe_mutex_test.c | 508 ++++++++++++++++++
 2 files changed, 511 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/sched/pe_mutex_test.c
tools/testing/selftests/sched/Makefile +3 -3
index 099ee921355..5ecfa45a103 100644
@@ -6,9 +6,9 @@ endif
 
 CFLAGS += -O2 -Wall -g -I./ $(KHDR_INCLUDES) -Wl,-rpath=./ \
 	  $(CLANG_FLAGS)
-LDLIBS += -lpthread
+LDLIBS += -lpthread -lrt
 
-TEST_GEN_FILES := cs_prctl_test
-TEST_PROGS := cs_prctl_test
+TEST_GEN_FILES := cs_prctl_test pe_mutex_test
+TEST_PROGS := cs_prctl_test pe_mutex_test
 
 include ../lib.mk
tools/testing/selftests/sched/pe_mutex_test.c new file +508 -0

508 lines not on this page · raw message

Signature · 1 line
2.43.0