Commit b00385b8d081 ("selftests/posix_timers: Use CLOCK_THREAD_CPUTIME_ID
for ITIMER_PROF measurements") gave ITIMER_PROF the clock it counts, as
measuring a CPU timer against the wall says nothing on a machine where
the task does not have a CPU to itself. The other CPU timers are still
measured against CLOCK_REALTIME and fail the same way. With four busy
loops on the two CPUs of a test machine:not ok 2 ITIMER_VIRTUAL not ok 5 timer_create() per CLOCK_THREAD_CPUTIME_ID not ok 6 timer_create() per CLOCK_PROCESS_CPUTIME_ID ITIMER_VIRTUAL counts the time the task spends in userspace, so take CLOCK_THREAD_CPUTIME_ID for it as well; the loop it runs stays in userspace, so what that clock adds for system time is far inside the half a second the check allows. check_timer_create() arms its timer on the clock it is given, so measure on that one. The test then passes whole on that machine, 19 of 19, busy or idle. Signed-off-by: Eva Kurchatova <[email protected]> --- tools/testing/selftests/timers/posix_timers.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c index a92d4b957747..52b7289e1450 100644 --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -113,9 +113,10 @@ static void check_itimer(int which, const char *name) done = 0; - if (which == ITIMER_VIRTUAL) + if (which == ITIMER_VIRTUAL) { + clock_id = CLOCK_THREAD_CPUTIME_ID; signal(SIGVTALRM, sig_handler); - else if (which == ITIMER_PROF) { + } else if (which == ITIMER_PROF) { clock_id = CLOCK_THREAD_CPUTIME_ID; signal(SIGPROF, sig_handler); } @@ -148,7 +149,7 @@ static void check_timer_create(int which) struct itimerspec val = { .it_value.tv_sec = DELAY, }; - int clock_id = CLOCK_REALTIME; + int clock_id = which; timer_t id; done = 0; -- 2.55.0

