[LTP] [PATCH] syscalls/clock_gettime: Add test to check bug during successive readings
Viresh Kumar
viresh.kumar@linaro.org
Tue Jun 9 09:05:35 CEST 2020
On 08-06-20, 16:51, Arnd Bergmann wrote:
> You already have a special case for gettimeofday(), so just round down
> the 'start' value to the previous microsecond when you are in that
> case.
Since this will also affect the next reading as well (as we will loose
values < 1 us), I tried to do it a bit differently.
@@ -78,6 +78,13 @@ static void run(unsigned int i)
tv->gettime(clks[i], tst_ts_get(&ts));
end = tst_ts_to_ns(ts);
+ /*
+ * gettimeofday() doesn't value less than 1 us, copy
+ * that from start.
+ */
+ if (tv->gettime == my_gettimeofday && end < start)
+ end += start % 1000;
+
/* Skip comparison on first traversal */
if (count == 10000 && !j)
continue;
> > +static void run(unsigned int i)
> > +{
> > + struct tst_ts ts;
> > + long long start, end = 0, diff;
> > + struct test_variants *tv;
> > + int count = 10000;
> > + unsigned int j;
> > +
> > + do {
> > + for (j = 0; j < ARRAY_SIZE(variants); j++) {
> > + /* Refresh time in start */
> > + start = end;
> > +
> > + tv = &variants[j];
> > + ts.type = tv->type;
> > +
> > + /* Do gettimeofday() test only for CLOCK_REALTIME */
> > + if (tv->gettime == my_gettimeofday && clks[i] != CLOCK_REALTIME)
> > + continue;
> > +
> > + tv->gettime(clks[i], tst_ts_get(&ts));
> > + end = tst_ts_to_ns(ts);
> > +
> > + /* Skip comparison on first traversal */
> > + if (count == 10000 && !j)
> > + continue;
I am skipping diff for the first iteration..
> > +
> > + diff = end - start;
>
> I think on the first iteration, 'start' is wrong here as well, and needs to
> be initialized once, as you did in the earlier versions.
And so this won't be a problem.
--
viresh
More information about the ltp
mailing list