<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Cyril Hrubis <<a href="mailto:chrubis@suse.cz">chrubis@suse.cz</a>> wrote:</div></div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> --- a/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c<br>
> +++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c<br>
> @@ -35,7 +35,7 @@ clockid_t clks[] = {<br>
> };<br>
> <br>
> static gettime_t ptr_vdso_gettime, ptr_vdso_gettime64;<br>
> -static long long delta = 5;<br>
> +static long long delta;<br>
> <br>
> static inline int do_vdso_gettime(gettime_t vdso, clockid_t clk_id, void *ts)<br>
> {<br>
> @@ -92,6 +92,7 @@ static struct time64_variants variants[] = {<br>
> <br>
> static void setup(void)<br>
> {<br>
> + delta = 1000/sysconf(_SC_CLK_TCK) + 5;<br>
<br>
This does not look correct to me. The sysconf(_SC_CLK_TCK) returns 100<br>
on systems where the test was working fine with 5 second delta. I think<br>
that the difference is that _SC_CLK_TCK returns how fast are the jiffies<br>
incremented which does not really matter for most of the modern hardware<br>
that uses high resolution harware for timers.<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">You're right, I checked some documents and confirmed this.</div>There I used the system tick rate (in the worst situations) that<br><div class="gmail_default" style="font-size:small">seemed a bit loose to other clockids.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I think that we should really use whatever is returned by the<br>
clock_getres(CLOCK_REALTIME_COARSE, &res), as long as high resolution<br>
timers are not available this call will return resolution in miliseconds<br>
and with high resolution timers available the reported resolution will<br>
be in nanosecond range, so it should probably be something as:<br>
<br>
clock_getres(CLOCK_REALTIME_COARSE, &res);<br>
<br>
delta = 5 + (res.tv_nsec / 1000000) * 5;<br></blockquote><div><br></div>Sounds reasonable.<span class="gmail_default" style="font-size:small"> </span></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small"><br></span></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small"></span>But I<span class="gmail_default" style="font-size:small"> don't understand</span> why you multiply 5 for the resolution<span class="gmail_default" style="font-size:small"> </span></div><div class="gmail_quote">(in milliseconds) here.<span class="gmail_default" style="font-size:small"> </span><span class="gmail_default">Or,</span> a wiser choice is to get the real<span class="gmail_default"> </span></div><div class="gmail_quote">resolution for each clockid?<span class="gmail_default" style="font-size:small"> i.e.</span></div><div class="gmail_quote"><br></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small"></span>--- a/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c<br>+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c<br>@@ -92,23 +92,27 @@ static struct time64_variants variants[] = {<br> <br> static void setup(void)<br> {<br>- delta = 1000/sysconf(_SC_CLK_TCK) + 5;<br>- if (tst_is_virt(VIRT_ANY)) {<br>- tst_res(TINFO, "Running in a virtual machine, multiply the delta by 10.");<br>- delta *= 10;<br>- }<br>-<br> find_clock_gettime_vdso(&ptr_vdso_gettime, &ptr_vdso_gettime64);<br> }<br> <br> static void run(unsigned int i)<br> {<br> struct tst_ts ts;<br>+ struct timespec res;<br> long long start, end = 0, diff, slack;<br> struct time64_variants *tv;<br> int count = 10000, ret;<br> unsigned int j;<br> <br>+ clock_getres(clks[i], &res);<br>+ tst_res(TINFO, "%s: resolution is %ldns", tst_clock_name(clks[i]), res.tv_nsec);<br>+<br>+ delta = 5 + res.tv_nsec/1000000;<br>+ if (tst_is_virt(VIRT_ANY)) {<br>+ delta *= 10;<br>+ tst_res(TINFO, "Multiply the delta by 10 in virtual machine: %lld", delta);<br>+ }<br>+<br> do {<br> for (j = 0; j < ARRAY_SIZE(variants); j++) {<br> /* Refresh time in start */<br><div class="gmail_default" style="font-size:small"></div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>