[go: up one dir, main page]

|
|
Log in / Subscribe / Register

Possible side-effects of CLOCK_MONOTONIC change?

Possible side-effects of CLOCK_MONOTONIC change?

Posted Apr 17, 2018 5:51 UTC (Tue) by epa (subscriber, #39769)
In reply to: Possible side-effects of CLOCK_MONOTONIC change? by glenn
Parent article: The second half of the 4.17 merge window

If I read the article correctly, it could be summarized as “CLOCK_MONOTONIC has been renamed to CLOCK_MONOTONIC_ACTIVE, but the old name has now become an alias for something else”. It all seems a bit strange, especially given the declared intention never to break user space.


to post comments

Possible side-effects of CLOCK_MONOTONIC change?

Posted Apr 17, 2018 9:05 UTC (Tue) by tglx (subscriber, #31301) [Link] (4 responses)

We are well aware of the fact that it might break user space and prepared for reverting it. In hindsight we should have never introduced CLOCK_BOOTTIME, but back in the days not all architectures were converted to the generic timekeeping infrastructure.

We have discussed that back and forth and finally decided to give it a try. If you or anyone else observes wreckage please let us know immediately.

Possible side-effects of CLOCK_MONOTONIC change?

Posted Apr 17, 2018 9:18 UTC (Tue) by epa (subscriber, #39769) [Link]

OK, makes sense. Maybe the unambiguous new CLOCK_MONOTONIC_ACTIVE should be added first (and backported to stable kernels) so applications that really want that can be prepared for the change. But this is just an ignorant suggestion.

Possible side-effects of CLOCK_MONOTONIC change?

Posted Apr 19, 2018 12:47 UTC (Thu) by lynxeye (subscriber, #90890) [Link]

I didn't observe it yet, but I definitely can see a place where things will break: Most DRM drivers are specifying IOCTL timeouts as absolute timeouts in terms of CLOCK_MONOTONIC. So if GPU operations get suspended and only submitted to the hardware after resume, the userspace will see a lot of its waits time out, while the GPU is still happily working through it's queue of work.

This is unexpected and I bet most of the graphics userspace will fall over if it hits such a condition.

Possible side-effects of CLOCK_MONOTONIC change?

Posted Apr 27, 2018 3:38 UTC (Fri) by njs (subscriber, #40338) [Link] (1 responses)

Traditionally nanosleep() and the timeouts in select(), epoll_wait(), etc., have all used the CLOCK_MONOTONIC clock, so that if you sleep for 10 seconds, and after 5 seconds the system is suspended for an hour, then after it wakes up again the process keeps sleeping for another 5 seconds.

Did you keep the relationship between sleeping syscalls and CLOCK_MONOTONIC – so that e.g. a nanosleep() before suspend will now wake up immediately on resume? Or did you keep the old sleeping syscall semantics, and break the relationship with CLOCK_MONOTONIC?

As far as I know, all correct event loops currently depend on the assumption that sleeping syscalls and CLOCK_MONOTONIC match each other. For example, if I set a timeout for T seconds from now, the event loop will:

- use (clock_gettime(CLOCK_MONOTONIC) + T) to calculate the absolute time of the timeout
- later, when it calls epoll_wait(), it'll choose the timeout by doing (deadline - clock_gettime(CLOCK_MONOTONIC))
- then it passes that timeout to epoll_wait()

Right now that's sufficient to ensure that epoll_wait() will return when clock_gettime(CLOCK_MONOTONIC) == deadline, or thereabouts... but if CLOCK_MONOTONIC starts counting suspend time, while epoll_wait() doesn't, then we'll start sleeping too long and missing our deadlines by an arbitrary amount.

Or at least, that's what the event loop I maintain does, which is why I want to know :-).

(As an added bonus, if I *do* have to switch to CLOCK_MONOTONIC_ACTIVE, that's going to be a hassle. Currently the event loop is implemented in Python, and the Python standard library obviously doesn't yet have any bindings for CLOCK_MONOTONIC_ACTIVE. Given where we are in the release cycle, the earliest they could be added is 1.5-2 years from now. In the mean time I guess it becomes temporarily impossible to implement an event loop in Python on Linux; you have to write part of it in C, and that's a huge obstacle for distribution :-(.)

Possible side-effects of CLOCK_MONOTONIC change?

Posted Apr 27, 2018 3:52 UTC (Fri) by njs (subscriber, #40338) [Link]

> In the mean time I guess it becomes temporarily impossible to implement an event loop in Python on Linux; you have to write part of it in C, and that's a huge obstacle for distribution :-(.

On further investigation, it looks like it's not quite as bad as I thought – CLOCK_MONOTONIC_ACTIVE can be queried from Python with:

time.clock_gettime(12)

(Untested, since I don't have a kernel with CLOCK_MONOTONIC_ACTIVE support).


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds