[LTP] [PATCH] clock_gettime04: set threshold based on the clock tick rate

Cyril Hrubis chrubis@suse.cz
Mon Mar 28 10:58:13 CEST 2022


Hi!
> >         clock_getres(CLOCK_REALTIME_COARSE, &res);
> >
> >         delta = 5 + (res.tv_nsec / 1000000) * 5;
> >
> 
> Sounds reasonable.
> 
> But I don't understand why you multiply 5 for the resolution
> (in milliseconds) here. Or, a wiser choice is to get the real
> resolution for each clockid? i.e.

I did multiply it with 5 just to add some error margin. I guess that we
can as well multiply it with 2 if that works well enough.

I do not think that we should get resolution for each clock, the COARSE
clock should have the worst resolution of all clocks.

> --- a/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c
> +++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c
> @@ -92,23 +92,27 @@ static struct time64_variants variants[] = {
> 
>  static void setup(void)
>  {
> -       delta = 1000/sysconf(_SC_CLK_TCK) + 5;
> -       if (tst_is_virt(VIRT_ANY)) {
> -               tst_res(TINFO, "Running in a virtual machine, multiply the
> delta by 10.");
> -               delta *= 10;
> -       }
> -
>         find_clock_gettime_vdso(&ptr_vdso_gettime, &ptr_vdso_gettime64);
>  }
> 
>  static void run(unsigned int i)
>  {
>         struct tst_ts ts;
> +       struct timespec res;
>         long long start, end = 0, diff, slack;
>         struct time64_variants *tv;
>         int count = 10000, ret;
>         unsigned int j;
> 
> +       clock_getres(clks[i], &res);
> +       tst_res(TINFO, "%s: resolution is %ldns", tst_clock_name(clks[i]),
> res.tv_nsec);
> +
> +       delta = 5 + res.tv_nsec/1000000;
> +       if (tst_is_virt(VIRT_ANY)) {
> +               delta *= 10;
> +               tst_res(TINFO, "Multiply the delta by 10 in virtual
> machine: %lld", delta);
> +       }
> +
>         do {
>                 for (j = 0; j < ARRAY_SIZE(variants); j++) {
>                         /* Refresh time in start */
> 
> -- 
> Regards,
> Li Wang

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list