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

Li Wang liwang@redhat.com
Mon Mar 28 11:54:55 CEST 2022


On Mon, Mar 28, 2022 at 4:56 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> 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.
>

Ok, I'd like to multiply 5 in case VM needs more.


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

Yes, quite enough for the rest.
For precise clock, the second part will be zero since divided by 1000000.

    delta = 5 + (res.tv_nsec / 1000000) * 5;


Test data from aarch4 (kernel-5.14) FYI:
===================
clock_gettime04.c:108: TINFO: CLOCK_REALTIME: resolution is 1ns
...
clock_gettime04.c:108: TINFO: CLOCK_REALTIME_COARSE: resolution is
10000000ns
clock_gettime04.c:108: TINFO: CLOCK_MONOTONIC: resolution is 1ns
clock_gettime04.c:108: TINFO: CLOCK_MONOTONIC_COARSE: resolution is
10000000ns
clock_gettime04.c:108: TINFO: CLOCK_MONOTONIC_RAW: resolution is 1ns
clock_gettime04.c:108: TINFO: CLOCK_BOOTTIME: resolution is 1ns


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220328/e220a556/attachment.htm>


More information about the ltp mailing list