* [PATCH v3 0/2] selftests: sched: Add default target support for sched
@ 2025-02-25 20:09 Sinadin Shan
2025-02-25 20:09 ` [PATCH v3 1/2] selftests: sched: add sched as a default selftest target Sinadin Shan
2025-02-25 20:09 ` [PATCH v3 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled Sinadin Shan
0 siblings, 2 replies; 5+ messages in thread
From: Sinadin Shan @ 2025-02-25 20:09 UTC (permalink / raw)
To: shuah, sshegde, chris.hyser; +Cc: linux-kselftest, linux-kernel, Sinadin Shan
This patch series introduces changes to add default build support for
the sched tests in selftests.
The only test under sched is cs_prctl_test which validates cookies when
core scheduling is in effect. This test fails on systems where core
scheduling is disabled. The patch series also modifies this behaviour to
gracefully skip the test on such systems.
A system with core scheduling disabled would skip the test like:
~# ./run_kselftest.sh
TAP version 13
1..1
timeout set to 45
selftests: sched: cs_prctl_test
prctl failed: Invalid argument
Core sched not supported, hence skipping tests
ok 1 selftests: sched: cs_prctl_test # SKIP
Signed-off-by: Sinadin Shan <sinadin.shan@oracle.com>
---
v3:
* Use prctl to check core sched support instead of config
* v2 link: https://lore.kernel.org/all/20250221115750.631990-1-sinadin.shan@oracle.com/
v2:
* Add patch to skip cs_prctl_test on core scheduling disabled systems
* v1 link: https://lore.kernel.org/all/20250219064658.449069-1-sinadin.shan@oracle.com
---
Sinadin Shan (2):
selftests: sched: add sched as a default selftest target
selftests: sched: skip cs_prctl_test for systems with core scheduling
disabled
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/sched/cs_prctl_test.c | 34 ++++++++++++++++++-
2 files changed, 34 insertions(+), 1 deletion(-)
--
2.43.5
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v3 1/2] selftests: sched: add sched as a default selftest target 2025-02-25 20:09 [PATCH v3 0/2] selftests: sched: Add default target support for sched Sinadin Shan @ 2025-02-25 20:09 ` Sinadin Shan 2025-02-25 20:09 ` [PATCH v3 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled Sinadin Shan 1 sibling, 0 replies; 5+ messages in thread From: Sinadin Shan @ 2025-02-25 20:09 UTC (permalink / raw) To: shuah, sshegde, chris.hyser; +Cc: linux-kselftest, linux-kernel, Sinadin Shan The sched tests are missing a target entry and hence out-of-tree build support. For instance: make -C tools/testing/selftests install INSTALL_PATH=/foo/bar is expected to build the sched tests and place them at /foo/bar. But this is not observed since a TARGET entry is not present for sched. This was suggested by Shuah in this conversation Link: https://lore.kernel.org/linux-kselftest/60dd0240-8e45-4958-acf2-7eeee917785b@linuxfoundation.org/ Add support for sched selftests by adding sched as a default TARGET Signed-off-by: Sinadin Shan <sinadin.shan@oracle.com> --- tools/testing/selftests/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 8daac70c2f9d2..e2d0d389ad912 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -91,6 +91,7 @@ TARGETS += rlimits TARGETS += rseq TARGETS += rtc TARGETS += rust +TARGETS += sched TARGETS += sched_ext TARGETS += seccomp TARGETS += sgx -- 2.43.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled 2025-02-25 20:09 [PATCH v3 0/2] selftests: sched: Add default target support for sched Sinadin Shan 2025-02-25 20:09 ` [PATCH v3 1/2] selftests: sched: add sched as a default selftest target Sinadin Shan @ 2025-02-25 20:09 ` Sinadin Shan 2025-02-26 13:05 ` Shrikanth Hegde 1 sibling, 1 reply; 5+ messages in thread From: Sinadin Shan @ 2025-02-25 20:09 UTC (permalink / raw) To: shuah, sshegde, chris.hyser; +Cc: linux-kselftest, linux-kernel, Sinadin Shan For kernels with CONFIG_SCHED_CORE=n, the sched selftest cs_prctl_test fails with "Not a core sched system" error. Change this to gracefully skip the test for systems with core scheduling disabled. Exiting early would also ensure failures reported in obtaining cookie are valid failures and not because core scheduling isn't supported. Skip cs_prctl_test for systems with CONFIG_SCHED_CORE=n Signed-off-by: Sinadin Shan <sinadin.shan@oracle.com> --- tools/testing/selftests/sched/cs_prctl_test.c | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/sched/cs_prctl_test.c b/tools/testing/selftests/sched/cs_prctl_test.c index 52d97fae4dbd8..5b0047b50e640 100644 --- a/tools/testing/selftests/sched/cs_prctl_test.c +++ b/tools/testing/selftests/sched/cs_prctl_test.c @@ -109,6 +109,36 @@ static void handle_usage(int rc, char *msg) exit(rc); } +static void check_core_sched(void) +{ + unsigned long long cookie; + int ret, num_max_process; + char buffer[32]; + + FILE *fp = fopen("/proc/sys/kernel/pid_max", "r"); + + if (fp == NULL) { + perror("Failed to obtain max process number"); + exit(EXIT_FAILURE); + } + + if (fgets(buffer, sizeof(buffer), fp) == NULL) { + fclose(fp); + exit(EXIT_FAILURE); + } + + num_max_process = atoi(buffer); + fclose(fp); + + ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, num_max_process+1, PIDTYPE_PID, + (unsigned long)&cookie); + if (ret == -1 && errno != ESRCH) { + perror("prctl failed"); + printf("Core sched not supported, hence skipping tests\n"); + exit(4); + } +} + static unsigned long get_cs_cookie(int pid) { unsigned long long cookie; @@ -117,7 +147,7 @@ static unsigned long get_cs_cookie(int pid) ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID, (unsigned long)&cookie); if (ret) { - printf("Not a core sched system\n"); + printf("Failed to get cookie\n"); return -1UL; } @@ -270,6 +300,8 @@ int main(int argc, char *argv[]) if (keypress) delay = -1; + check_core_sched(); + srand(time(NULL)); /* put into separate process group */ -- 2.43.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled 2025-02-25 20:09 ` [PATCH v3 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled Sinadin Shan @ 2025-02-26 13:05 ` Shrikanth Hegde 2025-02-26 17:01 ` Chris Hyser 0 siblings, 1 reply; 5+ messages in thread From: Shrikanth Hegde @ 2025-02-26 13:05 UTC (permalink / raw) To: Sinadin Shan, shuah, chris.hyser; +Cc: linux-kselftest, linux-kernel On 2/26/25 01:39, Sinadin Shan wrote: > For kernels with CONFIG_SCHED_CORE=n, the sched selftest cs_prctl_test > fails with "Not a core sched system" error. Change this to gracefully > skip the test for systems with core scheduling disabled. Exiting early > would also ensure failures reported in obtaining cookie are valid > failures and not because core scheduling isn't supported. > > Skip cs_prctl_test for systems with CONFIG_SCHED_CORE=n > > Signed-off-by: Sinadin Shan <sinadin.shan@oracle.com> > --- > tools/testing/selftests/sched/cs_prctl_test.c | 34 ++++++++++++++++++- > 1 file changed, 33 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/sched/cs_prctl_test.c b/tools/testing/selftests/sched/cs_prctl_test.c > index 52d97fae4dbd8..5b0047b50e640 100644 > --- a/tools/testing/selftests/sched/cs_prctl_test.c > +++ b/tools/testing/selftests/sched/cs_prctl_test.c > @@ -109,6 +109,36 @@ static void handle_usage(int rc, char *msg) > exit(rc); > } > > +static void check_core_sched(void) > +{ > + unsigned long long cookie; > + int ret, num_max_process; > + char buffer[32]; > + > + FILE *fp = fopen("/proc/sys/kernel/pid_max", "r"); > + > + if (fp == NULL) { > + perror("Failed to obtain max process number"); > + exit(EXIT_FAILURE); > + } > + > + if (fgets(buffer, sizeof(buffer), fp) == NULL) { > + fclose(fp); > + exit(EXIT_FAILURE); > + } > + > + num_max_process = atoi(buffer); > + fclose(fp); > + > + ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, num_max_process+1, PIDTYPE_PID, > + (unsigned long)&cookie); > + if (ret == -1 && errno != ESRCH) { > + perror("prctl failed"); > + printf("Core sched not supported, hence skipping tests\n"); > + exit(4); > + } > +} > + > static unsigned long get_cs_cookie(int pid) > { > unsigned long long cookie; > @@ -117,7 +147,7 @@ static unsigned long get_cs_cookie(int pid) > ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID, > (unsigned long)&cookie); > if (ret) { > - printf("Not a core sched system\n"); > + printf("Failed to get cookie\n"); > return -1UL; > } > > @@ -270,6 +300,8 @@ int main(int argc, char *argv[]) > if (keypress) > delay = -1; > > + check_core_sched(); > + > srand(time(NULL)); > > /* put into separate process group */ This works for me in my workflow. I don't know full selftest framework or how to trigger it. When CONFIG_SCHED_CORE=n ----------------------------- ./cs_prctl_test prctl failed: Invalid argument Core sched not supported, hence skipping tests When CONFIG_SCHED_CORE=y ----------------------------- ./cs_prctl_test (369) PASSED: _prctl(PR_SCHED_CORE, PR_SCHED_CORE_MAX, 0, PIDTYPE_PGID, 0) < 0 && errno == EINVAL -1 = prctl(62, 2, 0, 2, 1) (372) PASSED: _prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, 0, PIDTYPE_PGID, 1) < 0 && errno == EINVAL SUCCESS !!! So for this patch, Tested-by: Shrikanth Hegde <sshegde@linux.ibm.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled 2025-02-26 13:05 ` Shrikanth Hegde @ 2025-02-26 17:01 ` Chris Hyser 0 siblings, 0 replies; 5+ messages in thread From: Chris Hyser @ 2025-02-26 17:01 UTC (permalink / raw) To: Shrikanth Hegde, Sinadin Shan, shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org On 2/26/25 01:39, Sinadin Shan wrote: > For kernels with CONFIG_SCHED_CORE=n, the sched selftest cs_prctl_test > fails with "Not a core sched system" error. Change this to gracefully > skip the test for systems with core scheduling disabled. Exiting early > would also ensure failures reported in obtaining cookie are valid > failures and not because core scheduling isn't supported. > > Skip cs_prctl_test for systems with CONFIG_SCHED_CORE=n > > Signed-off-by: Sinadin Shan <sinadin.shan@oracle.com> > --- > tools/testing/selftests/sched/cs_prctl_test.c | 34 ++++++++++++++++++- > 1 file changed, 33 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/sched/cs_prctl_test.c b/tools/testing/selftests/sched/cs_prctl_test.c > index 52d97fae4dbd8..5b0047b50e640 100644 > --- a/tools/testing/selftests/sched/cs_prctl_test.c > +++ b/tools/testing/selftests/sched/cs_prctl_test.c > @@ -109,6 +109,36 @@ static void handle_usage(int rc, char *msg) > exit(rc); > } > > +static void check_core_sched(void) > +{ > + unsigned long long cookie; > + int ret, num_max_process; > + char buffer[32]; > + > + FILE *fp = fopen("/proc/sys/kernel/pid_max", "r"); > + > + if (fp == NULL) { > + perror("Failed to obtain max process number"); > + exit(EXIT_FAILURE); > + } > + > + if (fgets(buffer, sizeof(buffer), fp) == NULL) { > + fclose(fp); > + exit(EXIT_FAILURE); > + } > + > + num_max_process = atoi(buffer); > + fclose(fp); > + > + ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, num_max_process+1, PIDTYPE_PID, > + (unsigned long)&cookie); > + if (ret == -1 && errno != ESRCH) { > + perror("prctl failed"); > + printf("Core sched not supported, hence skipping tests\n"); > + exit(4); > + } > +} > + > static unsigned long get_cs_cookie(int pid) > { > unsigned long long cookie; > @@ -117,7 +147,7 @@ static unsigned long get_cs_cookie(int pid) > ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID, > (unsigned long)&cookie); > if (ret) { > - printf("Not a core sched system\n"); > + printf("Failed to get cookie\n"); > return -1UL; > } > > @@ -270,6 +300,8 @@ int main(int argc, char *argv[]) > if (keypress) > delay = -1; > > + check_core_sched(); > + > srand(time(NULL)); > > /* put into separate process group */ > -- > 2.43.5 So assuming a return code of 4 means skip (and I believe you stated that affirmatively before), then this should solve the problem. Thanks for fixing this. Reviewed-by: Chris Hyser <chris.hyser@oracle.com> -chrish ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-26 17:01 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-02-25 20:09 [PATCH v3 0/2] selftests: sched: Add default target support for sched Sinadin Shan 2025-02-25 20:09 ` [PATCH v3 1/2] selftests: sched: add sched as a default selftest target Sinadin Shan 2025-02-25 20:09 ` [PATCH v3 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled Sinadin Shan 2025-02-26 13:05 ` Shrikanth Hegde 2025-02-26 17:01 ` Chris Hyser
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox