[Devel] [PATCH vz10 3/3] selftests: timers: measure the cpu timers on the clock they count
Vasileios Almpanis
vasileios.almpanis at virtuozzo.com
Fri Sep 18 13:44:19 MSK 2026
> 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.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-143363
> Feature: fix selftests
> Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
>
> diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
> index 077a98fb1b1d..66993bd632ec 100644
> --- a/tools/testing/selftests/timers/posix_timers.c
> +++ b/tools/testing/selftests/timers/posix_timers.c
> @@ -112,9 +112,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);
> }
ITIMER_REAL is measured with CLOCK_REALTIME but the kernel arms it with
CLOCK_MONOTONIC.
hrtimer_setup(&sig->real_timer, it_real_fn, CLOCK_MONOTONIC, HRTIMER_MODE_REL)
in kernel/fork.c
Set it for this arm too. Since realtime will also get
its own clock maybe it would read better to have a switch instead of an
if/else if/else if.
--
Vasileios Almpanis <vasileios.almpanis at virtuozzo.com>
More information about the Devel
mailing list