[PATCH v2] tests: posix: use cpu clock for sleep
Yury Khrustalev
yury.khrustalev@arm.com
Tue Feb 17 09:51:23 GMT 2026
On Thu, Feb 12, 2026 at 12:29:24PM -0500, DJ Delorie wrote:
> Yury Khrustalev <yury.khrustalev@arm.com> writes:
> >> If all we need to do is ensure that ctime changes, could we instead call
> >> time(), then call sleep(1) until time() changes?
> >
> > Unfortunately, this doesn't work. Emulated systems that prioritise
> > performance in terms of user's time lapsed have effect of sleep()
> > or any variant of it returning immediately (with observable effect
> > that the result of time() has changed correctly).
>
> In that case, it would busy loop calling usleep() until time() changes,
> no different than what you had.
I believe that your solution with sleep() or usleep() would be the same as
what I have if I used CLOCK_MONOTONIC instead of CLOCK_PROCESS_CPUTIME_ID.
> But on non-embedded platforms, usleep()
> would not be a busy loop.
>
> >> Busy-waiting may affect how long it takes to run other tests, if "make
> >> -j" is used.
> >
> > I'm sure the effect would be negligible,
>
> I agree, but that doesn't mean we can't try to do better ;-)
>
> (and if you have thousands of tests that each think "it's only a
> second"... it's many minutes)
I don't see any better solution. This test was originally designed to
sleep for 2 seconds (in total) and it does the same now (save for some
nanoseconds inaccuracy) with the exception that now it works on a wider
variety of targets, and on normal systems there is going to be no
difference in neither behaviour nor time taken to run the tests, so I
don't see what's wrong here. Please elaborate.
Thanks,
Yury
More information about the Libc-alpha
mailing list