|
|
Subscribe / Log in / New account

Why CLOCK_MONOTONIC?

Why CLOCK_MONOTONIC?

Posted Mar 10, 2018 8:17 UTC (Sat) by smurf (subscriber, #17840)
In reply to: Why CLOCK_MONOTONIC? by glenn
Parent article: Time-based packet transmission

Received packets get stamped with REALTIME because that makes sense for time keeping protocols like NTP.
Transmitted packets get tracked with MONOTONIC because that makes sense with a video stream. You don't want your stream to stop when NTP adjusts your clock.


to post comments

Why CLOCK_MONOTONIC?

Posted Mar 10, 2018 20:03 UTC (Sat) by glenn (subscriber, #102223) [Link]

I’ve come around to using CLOCK_REALTIME because so much infrastructure has been built around it; specifically, PTP on Linux. However, I would like to have another clock besides CLOCK_REALTIME and CLOCK_MONOTONIC that could be synced against PTP, read cheaply from userspace, and timestamp received packets.

There are use cases beyond measuring data-center network latency and multimedia. I work on a real-time robotics platform where some network-connected sensors are synchronized with PTP, and timestamp sensors measurements with their PTP-synced clock. A Linux box in this system has to synchronize its CLOCK_REALTIME against the PTP clock in order to reason about these timestamps against its own local timestamps (reading a NIC’s PTP-synced clock is far too expensive). Although the PTP clock need not be synced against a time close to UTC (I only want to be able to reason about the relative age of sensor readings), I must use a UTC-based time if I want to be able to make use of certificates and have reasonable filesystem timestamps. Moreover, having CLOCK_REALTIME synced against PTP provides a mechanism to timestamp received packets with a PTP-synced clock, which helps integrate network-connected sensors that do not support PTP. This all works, but I don’t like the reliance on CLOCK_REALTIME. Anyone with superuser access can come along and manually slam the clock—this action would cause the whole house of cards to collapse. This is not a vulnerability that I like to have in a robotic system.


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