1

Does Linux have any way to obtain a milli or microsecond precision time for boot time, for converting boot time-relative timestamps into something like a Unix timestamp? The closest I've found is /proc/uptime (as suggested in places like this answer), but unfortunately this only gets you to 10ms precision best-case. For context, I've got a camera being used with v4l that provides microsecond precision timestamps, but they're in time since boot. I need to convert these to Unix timestamps as they're being sent to another computer. Is this a hard thing to provide in some way that I'm unaware of? And if so, why do so many things use time since boot?

rdelfin
  • 819
  • 2
  • 13
  • 31
  • 1
    Alternatively, on a modern x64 (and perhaps others) with monotonic TSC you can use TSC counter and divide it by cpu frequency. – SergeyA Jul 23 '21 at 12:37
  • For what purpose? FWIW, modern processors "boot" is a multistep process. The x86 cores are initialized and released from reset a somewhat significant time after the actual power-up when some other components are already being "booted". – Eugene Sh. Jul 23 '21 at 13:58
  • @EugeneSh. basically, as mentioned above, I'm working with a set of cameras that, due to how the drivers work, gives me frame timestamps (i.e. timestamps for when the image arrived on Linux) as time since boot. While "boot time" does have an unclear definition, I'm trying to figure out what Linux uses to define that boot time clock. I'm guessing this is when the kernel first gets control, not necessarily when the hardware itself powers up – rdelfin Jul 23 '21 at 16:18

1 Answers1

5

Use clock_gettime(CLOCK_BOOTTIME, &ts).