During early boot, the pointer hash key may not be initialized when PR_SCHED_CORE_GET is called. With the preceding kernel fix, GET reports EBUSY until the pointer hash key becomes available.
Retry the operation for up to one second when it returns EBUSY. Report other errors immediately, instead of describing every failed GET as an unsupported core scheduling system. cs_prctl_test passes on x86_64 QEMU with normal random initialization. A targeted early-boot probe also confirmed that the fixed kernel returns EBUSY while pointer hashing is unavailable. Signed-off-by: Hui Su <[email protected]> --- tools/testing/selftests/sched/cs_prctl_test.c | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/sched/cs_prctl_test.c b/tools/testing/selftests/sched/cs_prctl_test.c index 52d97fae4dbd..dcb661cace5e 100644 --- a/tools/testing/selftests/sched/cs_prctl_test.c +++ b/tools/testing/selftests/sched/cs_prctl_test.c @@ -51,6 +51,8 @@ static pid_t gettid(void) #define MAX_PROCESSES 128 #define MAX_THREADS 128 +#define CORE_COOKIE_RETRIES 100 +#define CORE_COOKIE_RETRY_US 10000 static const char USAGE[] = "cs_prctl_test [options]\n" " options:\n" @@ -112,16 +114,27 @@ static void handle_usage(int rc, char *msg) static unsigned long get_cs_cookie(int pid) { unsigned long long cookie; - int ret; + int i, ret, err = 0; + + for (i = 0; i < CORE_COOKIE_RETRIES; i++) { + ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID, + (unsigned long)&cookie); + if (!ret) + return cookie; + + err = errno; + if (err != EBUSY) + break; - ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID, - (unsigned long)&cookie); - if (ret) { - printf("Not a core sched system\n"); - return -1UL; + usleep(CORE_COOKIE_RETRY_US); } - return cookie; + if (err == EBUSY) + printf("Timed out waiting for core sched cookie\n"); + else + printf("Failed to get core sched cookie: %s\n", strerror(err)); + + return -1UL; } static int child_func_thread(void __attribute__((unused))*arg) -- 2.55.0

