public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] selftests: sched: Add default target support for sched
@ 2025-02-21 11:57 Sinadin Shan
  2025-02-21 11:57 ` [PATCH v2 1/2] selftests: sched: add sched as a default selftest target Sinadin Shan
  2025-02-21 11:57 ` [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled Sinadin Shan
  0 siblings, 2 replies; 7+ messages in thread
From: Sinadin Shan @ 2025-02-21 11:57 UTC (permalink / raw)
  To: shuah; +Cc: linux-kselftest, linux-kernel, chris.hyser, sshegde, 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.

For example, such a test skip would look like:
TAP version 13
1..1
 timeout set to 45
 selftests: sched: cs_prctl_test
 Checking for CONFIG_SCHED_CORE support
 Core scheduling not enabled in kernel, hence skipping tests
ok 1 selftests: sched: cs_prctl_test # SKIP

and a successful run:
TAP version 13
1..1
 timeout set to 45
 selftests: sched: cs_prctl_test
 Checking for CONFIG_SCHED_CORE support
 CONFIG_SCHED_CORE=y
.
.
.
 SUCCESS !!!
ok 1 selftests: sched: cs_prctl_test

Signed-off-by: Sinadin Shan <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 | 29 ++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

-- 
2.43.5


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] selftests: sched: add sched as a default selftest target
  2025-02-21 11:57 [PATCH v2 0/2] selftests: sched: Add default target support for sched Sinadin Shan
@ 2025-02-21 11:57 ` Sinadin Shan
  2025-02-21 11:57 ` [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled Sinadin Shan
  1 sibling, 0 replies; 7+ messages in thread
From: Sinadin Shan @ 2025-02-21 11:57 UTC (permalink / raw)
  To: shuah; +Cc: linux-kselftest, linux-kernel, chris.hyser, sshegde, 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] 7+ messages in thread

* [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled
  2025-02-21 11:57 [PATCH v2 0/2] selftests: sched: Add default target support for sched Sinadin Shan
  2025-02-21 11:57 ` [PATCH v2 1/2] selftests: sched: add sched as a default selftest target Sinadin Shan
@ 2025-02-21 11:57 ` Sinadin Shan
  2025-02-24  8:19   ` Shrikanth Hegde
  1 sibling, 1 reply; 7+ messages in thread
From: Sinadin Shan @ 2025-02-21 11:57 UTC (permalink / raw)
  To: shuah; +Cc: linux-kselftest, linux-kernel, chris.hyser, sshegde, 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 due to the config.

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 | 29 ++++++++++++++++++-
 1 file changed, 28 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..60fd657b56c84 100644
--- a/tools/testing/selftests/sched/cs_prctl_test.c
+++ b/tools/testing/selftests/sched/cs_prctl_test.c
@@ -23,6 +23,7 @@
 #include <sys/eventfd.h>
 #include <sys/wait.h>
 #include <sys/types.h>
+#include <sys/utsname.h>
 #include <sched.h>
 #include <sys/prctl.h>
 #include <unistd.h>
@@ -109,6 +110,30 @@ static void handle_usage(int rc, char *msg)
 	exit(rc);
 }
 
+static void check_core_sched_support(void)
+{
+	char config[128] = "/proc/config.gz";
+	char cmd[128];
+	struct utsname kernel;
+
+	printf("## Checking for CONFIG_SCHED_CORE support\n");
+
+	if (access(config, F_OK) != 0)
+		if (uname(&kernel) == 0)
+			snprintf(config, sizeof(config), "/boot/config-%s", kernel.release);
+
+	if (access(config, F_OK) != 0) {
+		printf("Cannot find kernel config in /proc or /boot\n");
+		exit(EXIT_FAILURE);
+	}
+
+	snprintf(cmd, sizeof(cmd), "zgrep CONFIG_SCHED_CORE=[ym] %s", config);
+	if (system(cmd)) {
+		printf("Core scheduling not enabled in kernel, hence skipping tests\n");
+		exit(4);
+	}
+}
+
 static unsigned long get_cs_cookie(int pid)
 {
 	unsigned long long cookie;
@@ -117,7 +142,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 +295,8 @@ int main(int argc, char *argv[])
 	if (keypress)
 		delay = -1;
 
+	check_core_sched_support();
+
 	srand(time(NULL));
 
 	/* put into separate process group */
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled
  2025-02-21 11:57 ` [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled Sinadin Shan
@ 2025-02-24  8:19   ` Shrikanth Hegde
  2025-02-24 12:10     ` Sinadin Shan
  0 siblings, 1 reply; 7+ messages in thread
From: Shrikanth Hegde @ 2025-02-24  8:19 UTC (permalink / raw)
  To: Sinadin Shan, shuah; +Cc: linux-kselftest, linux-kernel, chris.hyser



On 2/21/25 17:27, 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 due to the config.
> 
> Skip cs_prctl_test for systems with CONFIG_SCHED_CORE=n

I tried this on kernel built with CONFIG_SCHED_CORE=y.
I did make, make modules_install and make install and reboot.

./cs_prctl_test
## Checking for CONFIG_SCHED_CORE support
Cannot find kernel config in /proc or /boot

This happens because, make install wouldnt copy the .config to 
/boot/config-<kernel-release>.

If the self-tests are to be used in development flow, these checks may 
not be sufficient.

Not sure if i have missed any steps in building process.


> 
> Signed-off-by: Sinadin Shan <sinadin.shan@oracle.com>
> ---
>   tools/testing/selftests/sched/cs_prctl_test.c | 29 ++++++++++++++++++-
>   1 file changed, 28 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..60fd657b56c84 100644
> --- a/tools/testing/selftests/sched/cs_prctl_test.c
> +++ b/tools/testing/selftests/sched/cs_prctl_test.c
> @@ -23,6 +23,7 @@
>   #include <sys/eventfd.h>
>   #include <sys/wait.h>
>   #include <sys/types.h>
> +#include <sys/utsname.h>
>   #include <sched.h>
>   #include <sys/prctl.h>
>   #include <unistd.h>
> @@ -109,6 +110,30 @@ static void handle_usage(int rc, char *msg)
>   	exit(rc);
>   }
>   
> +static void check_core_sched_support(void)
> +{
> +	char config[128] = "/proc/config.gz";
> +	char cmd[128];
> +	struct utsname kernel;
> +
> +	printf("## Checking for CONFIG_SCHED_CORE support\n");
> +
> +	if (access(config, F_OK) != 0)
> +		if (uname(&kernel) == 0)
> +			snprintf(config, sizeof(config), "/boot/config-%s", kernel.release);
> +
> +	if (access(config, F_OK) != 0) {
> +		printf("Cannot find kernel config in /proc or /boot\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	snprintf(cmd, sizeof(cmd), "zgrep CONFIG_SCHED_CORE=[ym] %s", config);
> +	if (system(cmd)) {
> +		printf("Core scheduling not enabled in kernel, hence skipping tests\n");
> +		exit(4);
> +	}
> +}
> +
>   static unsigned long get_cs_cookie(int pid)
>   {
>   	unsigned long long cookie;
> @@ -117,7 +142,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 +295,8 @@ int main(int argc, char *argv[])
>   	if (keypress)
>   		delay = -1;
>   
> +	check_core_sched_support();
> +
>   	srand(time(NULL));
>   
>   	/* put into separate process group */


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled
  2025-02-24  8:19   ` Shrikanth Hegde
@ 2025-02-24 12:10     ` Sinadin Shan
  2025-02-24 23:02       ` Chris Hyser
  0 siblings, 1 reply; 7+ messages in thread
From: Sinadin Shan @ 2025-02-24 12:10 UTC (permalink / raw)
  To: Shrikanth Hegde, shuah; +Cc: linux-kselftest, linux-kernel, chris.hyser



On 24-02-2025 01:49 pm, Shrikanth Hegde wrote:
> 
> 
> On 2/21/25 17:27, 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 due to the config.
>>
>> Skip cs_prctl_test for systems with CONFIG_SCHED_CORE=n
> 
> I tried this on kernel built with CONFIG_SCHED_CORE=y.
> I did make, make modules_install and make install and reboot.
> 
> ./cs_prctl_test
> ## Checking for CONFIG_SCHED_CORE support
> Cannot find kernel config in /proc or /boot
> 
> This happens because, make install wouldnt copy the .config to /boot/ 
> config-<kernel-release>.
> 
> If the self-tests are to be used in development flow, these checks may 
> not be sufficient.

Right, this particular case was overlooked. To handle this, the test 
could take a path to the custom config as an argument. I shall work on 
getting this fixed.

Regards,
Shan
> 
> Not sure if i have missed any steps in building process.
> 
> 
>>
>> Signed-off-by: Sinadin Shan <sinadin.shan@oracle.com>
>> ---
>>   tools/testing/selftests/sched/cs_prctl_test.c | 29 ++++++++++++++++++-
>>   1 file changed, 28 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..60fd657b56c84 100644
>> --- a/tools/testing/selftests/sched/cs_prctl_test.c
>> +++ b/tools/testing/selftests/sched/cs_prctl_test.c
>> @@ -23,6 +23,7 @@
>>   #include <sys/eventfd.h>
>>   #include <sys/wait.h>
>>   #include <sys/types.h>
>> +#include <sys/utsname.h>
>>   #include <sched.h>
>>   #include <sys/prctl.h>
>>   #include <unistd.h>
>> @@ -109,6 +110,30 @@ static void handle_usage(int rc, char *msg)
>>       exit(rc);
>>   }
>> +static void check_core_sched_support(void)
>> +{
>> +    char config[128] = "/proc/config.gz";
>> +    char cmd[128];
>> +    struct utsname kernel;
>> +
>> +    printf("## Checking for CONFIG_SCHED_CORE support\n");
>> +
>> +    if (access(config, F_OK) != 0)
>> +        if (uname(&kernel) == 0)
>> +            snprintf(config, sizeof(config), "/boot/config-%s", 
>> kernel.release);
>> +
>> +    if (access(config, F_OK) != 0) {
>> +        printf("Cannot find kernel config in /proc or /boot\n");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    snprintf(cmd, sizeof(cmd), "zgrep CONFIG_SCHED_CORE=[ym] %s", 
>> config);
>> +    if (system(cmd)) {
>> +        printf("Core scheduling not enabled in kernel, hence skipping 
>> tests\n");
>> +        exit(4);
>> +    }
>> +}
>> +
>>   static unsigned long get_cs_cookie(int pid)
>>   {
>>       unsigned long long cookie;
>> @@ -117,7 +142,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 +295,8 @@ int main(int argc, char *argv[])
>>       if (keypress)
>>           delay = -1;
>> +    check_core_sched_support();
>> +
>>       srand(time(NULL));
>>       /* put into separate process group */
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled
  2025-02-24 12:10     ` Sinadin Shan
@ 2025-02-24 23:02       ` Chris Hyser
  2025-02-25  8:54         ` Sinadin Shan
  0 siblings, 1 reply; 7+ messages in thread
From: Chris Hyser @ 2025-02-24 23:02 UTC (permalink / raw)
  To: Sinadin Shan, Shrikanth Hegde, shuah@kernel.org
  Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org

>From: Sinadin Shan <sinadin.shan@oracle.com>
>Sent: Monday, February 24, 2025 7:10 AM
>To: Shrikanth Hegde; shuah@kernel.org
>Cc: linux-kselftest@vger.kernel.org; linux-kernel@vger.kernel.org; Chris Hyser
>Subject: Re: [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled
>
>On 24-02-2025 01:49 pm, Shrikanth Hegde wrote:
...
>> If the self-tests are to be used in development flow, these checks may
>> not be sufficient.
>
>Right, this particular case was overlooked. To handle this, the test
>could take a path to the custom config as an argument. I shall work on
>getting this fixed.

I was thinking something along the lines of just calling the prctl. 

If you call it and SCHED_CORE is not configured, you will get an EINVAL. Unfortunately,
passing other bad values in the other prctl args will also give an EINVAL, but if you call it with a
non-existent PID (say max_pid + 1) it will generate an ESRCH if the code is present.

So something like (and I'd look up the maxpid on the actual system):

int check_core_sched()
{
        ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, 32769, PIDTYPE_PID,                                                                                                                                                         
                         (unsigned long)&cookie);                                                                                                                                                                            

        printf("ret = %d\n", ret);                                                                                                                                                                             
        perror("Error:\n");     
}

-chrish

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled
  2025-02-24 23:02       ` Chris Hyser
@ 2025-02-25  8:54         ` Sinadin Shan
  0 siblings, 0 replies; 7+ messages in thread
From: Sinadin Shan @ 2025-02-25  8:54 UTC (permalink / raw)
  To: Chris Hyser, Shrikanth Hegde, shuah@kernel.org
  Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org



On 25-02-2025 04:32 am, Chris Hyser wrote:
>> From: Sinadin Shan <sinadin.shan@oracle.com>
>> Sent: Monday, February 24, 2025 7:10 AM
>> To: Shrikanth Hegde; shuah@kernel.org
>> Cc: linux-kselftest@vger.kernel.org; linux-kernel@vger.kernel.org; Chris Hyser
>> Subject: Re: [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled
>>
>> On 24-02-2025 01:49 pm, Shrikanth Hegde wrote:
> ...
>>> If the self-tests are to be used in development flow, these checks may
>>> not be sufficient.
>>
>> Right, this particular case was overlooked. To handle this, the test
>> could take a path to the custom config as an argument. I shall work on
>> getting this fixed.
> 
> I was thinking something along the lines of just calling the prctl.
> 
> If you call it and SCHED_CORE is not configured, you will get an EINVAL. Unfortunately,
> passing other bad values in the other prctl args will also give an EINVAL, but if you call it with a
> non-existent PID (say max_pid + 1) it will generate an ESRCH if the code is present.
> 
> So something like (and I'd look up the maxpid on the actual system):
> 
> int check_core_sched()
> {
>          ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, 32769, PIDTYPE_PID,
>                           (unsigned long)&cookie);
> 
>          printf("ret = %d\n", ret);
>          perror("Error:\n");
> }
> 

Thanks for the suggestion Chris, this indeed would be a better method 
and also fit in well with the development workflow. I'll give this a try 
and send out the updated patch soon.

Regards,
Shan

> -chrish


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-02-25  8:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-21 11:57 [PATCH v2 0/2] selftests: sched: Add default target support for sched Sinadin Shan
2025-02-21 11:57 ` [PATCH v2 1/2] selftests: sched: add sched as a default selftest target Sinadin Shan
2025-02-21 11:57 ` [PATCH v2 2/2] selftests: sched: skip cs_prctl_test for systems with core scheduling disabled Sinadin Shan
2025-02-24  8:19   ` Shrikanth Hegde
2025-02-24 12:10     ` Sinadin Shan
2025-02-24 23:02       ` Chris Hyser
2025-02-25  8:54         ` Sinadin Shan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox