+quark_get_boottime returns the internal boottime epoch:
+ the wallclock time of boot in nanoseconds since the Unix epoch, as fetched
+ from the btime field of /proc/stat. btime has a
+ resolution of one second.
+
The epoch is fetched when the first queue is opened and refetched
+ only by
+ quark_update_boottime(3).
+ It is what
+ quark_time_to_wallclock(3)
+ adds to a time since boot, exposed for users that prefer to do the
+ translation themselves.
quark_get_boottime appeared in quark 0.8,
+ when all times handed out by quark switched from nanoseconds since the Unix
+ epoch to nanoseconds since boot.
+quark_time_to_wallclock translates
+ time_since_boot from nanoseconds since boot to
+ nanoseconds since the Unix epoch by adding the internal boottime epoch, see
+ quark_get_boottime(3).
+
All times handed out by quark are suitable inputs:
+ time of
+ quark_event,
+ proc_time_boot
+ and
+ exit_time_event
+ of quark_process, as well as
+ established_time
+ and
+ close_time
+ of quark_socket. These fields are expressed as
+ nanoseconds since boot since quark 0.8, in earlier versions they were
+ nanoseconds since the Unix epoch and needed no translation.
+
Times since boot are immune to system clock changes, wallclock
+ times are not. Translate at the last moment, when a time leaves the system
+ for display or storage, and keep the epoch fresh with
+ quark_update_boottime(3)
+ if the clock may be stepped while running.
quark_time_to_wallclock appeared in quark
+ 0.8, when all times handed out by quark switched from nanoseconds since the
+ Unix epoch to nanoseconds since boot.
+All times handed out by quark are expressed in nanoseconds since boot:
+ time of
+ quark_event,
+ proc_time_boot
+ and
+ exit_time_event
+ of quark_process, as well as
+ established_time
+ and
+ close_time
+ of quark_socket. Translation to wallclock is done at the
+ last moment via
+ quark_time_to_wallclock(3),
+ which adds an internal boottime epoch: the wallclock time of boot, fetched
+ from the btime field of /proc/stat when the first
+ queue is opened.
+
btime is derived from the current system clock, so it moves if the
+ clock is stepped, as when NTP corrects a clock that was wrong at boot. Since
+ quark has no event loop, it can not detect a step on its own: the user
+ should call quark_update_boottime, which refetches
+ btime, whenever the clock might have changed. As quark never bakes the epoch
+ into the times it stores or hands out, an update also corrects the
+ translation of times acquired before the step.
+
Two common ways of detecting a step:
+
+
Poll the delta of CLOCK_REALTIME minus
+ CLOCK_BOOTTIME: slewing adjusts both clocks at the
+ same rate, so the delta only moves when the clock is stepped.
+
Wait on a timerfd_create(2)
+ descriptor of CLOCK_REALTIME armed with
+ TFD_TIMER_CANCEL_ON_SET, which becomes readable
+ when the clock is stepped.
quark_update_boottime appeared in quark
+ 0.8, when all times handed out by quark switched from nanoseconds since the
+ Unix epoch to nanoseconds since boot.
+
+
+
+
+
August 5, 2026
+
Linux
+
+
+
+
diff --git a/quark.7 b/quark.7
index 67004226..20916cf6 100644
--- a/quark.7
+++ b/quark.7
@@ -454,6 +454,12 @@ get a descriptor suitable for blocking.
block for an unspecified amount of time.
.It Xr quark_queue_get_stats 3
basic queue statistics.
+.It Xr quark_time_to_wallclock 3
+translate a time since boot to wallclock.
+.It Xr quark_update_boottime 3
+refetch the boottime epoch after a system clock change.
+.It Xr quark_get_boottime 3
+get the boottime epoch.
.It Xr quark_queue_close 3
close a queue.
.El
@@ -469,6 +475,7 @@ is the easiest way to get started with
describes initialization options that can be useful.
.Sh SEE ALSO
.Xr quark_event_dump 3 ,
+.Xr quark_get_boottime 3 ,
.Xr quark_process_iter 3 ,
.Xr quark_process_lookup 3 ,
.Xr quark_queue_block 3 ,
@@ -477,6 +484,8 @@ describes initialization options that can be useful.
.Xr quark_queue_get_event 3 ,
.Xr quark_queue_get_stats 3 ,
.Xr quark_queue_open 3 ,
+.Xr quark_time_to_wallclock 3 ,
+.Xr quark_update_boottime 3 ,
.Xr quark-btf 8 ,
.Xr quark-mon 8 ,
.Xr quark-test 8
diff --git a/quark_get_boottime.3 b/quark_get_boottime.3
new file mode 100644
index 00000000..149acc98
--- /dev/null
+++ b/quark_get_boottime.3
@@ -0,0 +1,48 @@
+.Dd $Mdocdate$
+.Dt QUARK_GET_BOOTTIME 3
+.Os
+.Sh NAME
+.Nm quark_get_boottime
+.Nd get the boottime epoch used for wallclock translation
+.Sh SYNOPSIS
+.In quark.h
+.Ft u64
+.Fn quark_get_boottime "void"
+.Sh DESCRIPTION
+.Nm
+returns the internal boottime epoch: the wallclock time of boot in
+nanoseconds since the Unix epoch, as fetched from the btime field of
+.Pa /proc/stat .
+btime has a resolution of one second.
+.Pp
+The epoch is fetched when the first queue is opened and refetched only
+by
+.Xr quark_update_boottime 3 .
+It is what
+.Xr quark_time_to_wallclock 3
+adds to a time since boot, exposed for users that prefer to do the
+translation themselves.
+.Sh RETURN VALUES
+The boottime epoch in nanoseconds since the Unix epoch, zero if a
+queue was never opened.
+.Sh SEE ALSO
+.Xr quark_event_dump 3 ,
+.Xr quark_process_iter 3 ,
+.Xr quark_process_lookup 3 ,
+.Xr quark_queue_block 3 ,
+.Xr quark_queue_close 3 ,
+.Xr quark_queue_default_attr 3 ,
+.Xr quark_queue_get_epollfd 3 ,
+.Xr quark_queue_get_event 3 ,
+.Xr quark_queue_get_stats 3 ,
+.Xr quark_queue_open 3 ,
+.Xr quark_time_to_wallclock 3 ,
+.Xr quark_update_boottime 3 ,
+.Xr quark 7 ,
+.Xr quark-btf 8 ,
+.Xr quark-mon 8 ,
+.Xr quark-test 8
+.Sh HISTORY
+.Nm
+appeared in quark 0.8, when all times handed out by quark switched
+from nanoseconds since the Unix epoch to nanoseconds since boot.
diff --git a/quark_time_to_wallclock.3 b/quark_time_to_wallclock.3
new file mode 100644
index 00000000..72f4e1a2
--- /dev/null
+++ b/quark_time_to_wallclock.3
@@ -0,0 +1,67 @@
+.Dd $Mdocdate$
+.Dt QUARK_TIME_TO_WALLCLOCK 3
+.Os
+.Sh NAME
+.Nm quark_time_to_wallclock
+.Nd translate a time since boot to wallclock
+.Sh SYNOPSIS
+.In quark.h
+.Ft u64
+.Fn quark_time_to_wallclock "u64 time_since_boot"
+.Sh DESCRIPTION
+.Nm
+translates
+.Fa time_since_boot
+from nanoseconds since boot to nanoseconds since the Unix epoch by
+adding the internal boottime epoch, see
+.Xr quark_get_boottime 3 .
+.Pp
+All times handed out by quark are suitable inputs:
+.Em time
+of
+.Vt quark_event ,
+.Em proc_time_boot
+and
+.Em exit_time_event
+of
+.Vt quark_process ,
+as well as
+.Em established_time
+and
+.Em close_time
+of
+.Vt quark_socket .
+These fields are expressed as nanoseconds since boot since quark 0.8,
+in earlier versions they were nanoseconds since the Unix epoch and
+needed no translation.
+.Pp
+Times since boot are immune to system clock changes, wallclock times
+are not.
+Translate at the last moment, when a time leaves the system for
+display or storage, and keep the epoch fresh with
+.Xr quark_update_boottime 3
+if the clock may be stepped while running.
+.Sh RETURN VALUES
+.Fa time_since_boot
+expressed in nanoseconds since the Unix epoch.
+.Sh SEE ALSO
+.Xr quark_event_dump 3 ,
+.Xr quark_get_boottime 3 ,
+.Xr quark_process_iter 3 ,
+.Xr quark_process_lookup 3 ,
+.Xr quark_queue_block 3 ,
+.Xr quark_queue_close 3 ,
+.Xr quark_queue_default_attr 3 ,
+.Xr quark_queue_get_epollfd 3 ,
+.Xr quark_queue_get_event 3 ,
+.Xr quark_queue_get_stats 3 ,
+.Xr quark_queue_open 3 ,
+.Xr quark_update_boottime 3 ,
+.Xr quark 7 ,
+.Xr quark-btf 8 ,
+.Xr quark-mon 8 ,
+.Xr quark-test 8
+.Sh HISTORY
+.Nm
+appeared in quark 0.8, when all times handed out by quark switched
+from nanoseconds since the Unix epoch to nanoseconds since boot.
diff --git a/quark_update_boottime.3 b/quark_update_boottime.3
new file mode 100644
index 00000000..f81535ef
--- /dev/null
+++ b/quark_update_boottime.3
@@ -0,0 +1,87 @@
+.Dd $Mdocdate$
+.Dt QUARK_UPDATE_BOOTTIME 3
+.Os
+.Sh NAME
+.Nm quark_update_boottime
+.Nd refetch the boottime epoch used for wallclock translation
+.Sh SYNOPSIS
+.In quark.h
+.Ft int
+.Fn quark_update_boottime "void"
+.Sh DESCRIPTION
+All times handed out by quark are expressed in nanoseconds since boot:
+.Em time
+of
+.Vt quark_event ,
+.Em proc_time_boot
+and
+.Em exit_time_event
+of
+.Vt quark_process ,
+as well as
+.Em established_time
+and
+.Em close_time
+of
+.Vt quark_socket .
+Translation to wallclock is done at the last moment via
+.Xr quark_time_to_wallclock 3 ,
+which adds an internal boottime epoch: the wallclock time of boot,
+fetched from the btime field of
+.Pa /proc/stat
+when the first queue is opened.
+.Pp
+btime is derived from the current system clock, so it moves if the
+clock is stepped, as when NTP corrects a clock that was wrong at boot.
+Since quark has no event loop, it can not detect a step on its own:
+the user should call
+.Nm ,
+which refetches btime, whenever the clock might have changed.
+As quark never bakes the epoch into the times it stores or hands out,
+an update also corrects the translation of times acquired before the
+step.
+.Pp
+Two common ways of detecting a step:
+.Bl -bullet
+.It
+Poll the delta of
+.Dv CLOCK_REALTIME
+minus
+.Dv CLOCK_BOOTTIME :
+slewing adjusts both clocks at the same rate, so the delta only moves
+when the clock is stepped.
+.It
+Wait on a
+.Xr timerfd_create 2
+descriptor of
+.Dv CLOCK_REALTIME
+armed with
+.Dv TFD_TIMER_CANCEL_ON_SET ,
+which becomes readable when the clock is stepped.
+.El
+.Sh RETURN VALUES
+Returns 0 on success, -1 if btime could not be refetched, in which
+case the previous epoch is retained and
+.Va errno
+is set.
+.Sh SEE ALSO
+.Xr quark_event_dump 3 ,
+.Xr quark_get_boottime 3 ,
+.Xr quark_process_iter 3 ,
+.Xr quark_process_lookup 3 ,
+.Xr quark_queue_block 3 ,
+.Xr quark_queue_close 3 ,
+.Xr quark_queue_default_attr 3 ,
+.Xr quark_queue_get_epollfd 3 ,
+.Xr quark_queue_get_event 3 ,
+.Xr quark_queue_get_stats 3 ,
+.Xr quark_queue_open 3 ,
+.Xr quark_time_to_wallclock 3 ,
+.Xr quark 7 ,
+.Xr quark-btf 8 ,
+.Xr quark-mon 8 ,
+.Xr quark-test 8
+.Sh HISTORY
+.Nm
+appeared in quark 0.8, when all times handed out by quark switched
+from nanoseconds since the Unix epoch to nanoseconds since boot.
From adbdacf6187e01b8f2c15e5a335f25b7d8afb3f4 Mon Sep 17 00:00:00 2001
From: Nicholas Berlin
Date: Fri, 14 Aug 2026 12:59:53 -0400
Subject: [PATCH 2/4] Document thread-safety of the boottime calls
The boottime epoch is process-wide, shared by every queue, and
auditbeat updates it from one thread while others translate
timestamps, which no caller-side lock can span. State explicitly that
quark_update_boottime(), quark_get_boottime() and
quark_time_to_wallclock() may be called from any thread without
synchronization, as an exception to the queue synchronization
convention in quark(7).
Only true once the boottime-atomics branch merges, which makes the
epoch access atomic.
---
README.md | 2 +-
docs/index.html | 9 +++++++--
docs/quark.7.html | 9 +++++++--
docs/quark_update_boottime.3.html | 9 ++++++++-
quark.7 | 6 ++++++
quark_update_boottime.3 | 9 +++++++++
6 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index bbdca317..53609136 100644
--- a/README.md
+++ b/README.md
@@ -250,7 +250,7 @@ These scripts require KVM access and therefore must be executed on a host kernel
- Library calls fail with -1 unless otherwise stated, and `errno` is set.
- Quark returns pointers to internal state, which must not be modified and/or stored. In the case of multithreading, these pointers should not be accessed if another thread is driving quark through [quark\_queue\_get\_event(3)](https://elastic.github.io/quark/quark_queue_get_event.3.html).
- No threads are created, the library is driven solely through [quark\_queue\_get\_event(3)](https://elastic.github.io/quark/quark_queue_get_event.3.html).
-- Access to a `quark_queue` must be synchronized by the user in the case of multithreading.
+- Access to a `quark_queue` must be synchronized by the user in the case of multithreading. The boottime epoch is the exception: [quark\_update\_boottime(3)](https://elastic.github.io/quark/quark_update_boottime.3.html), [quark\_get\_boottime(3)](https://elastic.github.io/quark/quark_get_boottime.3.html) and [quark\_time\_to\_wallclock(3)](https://elastic.github.io/quark/quark_time_to_wallclock.3.html) may be called from any thread without synchronization.
# [BASIC USAGE](#BASIC_USAGE)
diff --git a/docs/index.html b/docs/index.html
index cdccefeb..270f8763 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -335,7 +335,12 @@
diff --git a/quark.7 b/quark.7
index 20916cf6..97489df8 100644
--- a/quark.7
+++ b/quark.7
@@ -379,6 +379,12 @@ No threads are created, the library is driven solely through
Access to a
.Vt quark_queue
must be synchronized by the user in the case of multithreading.
+The boottime epoch is the exception:
+.Xr quark_update_boottime 3 ,
+.Xr quark_get_boottime 3
+and
+.Xr quark_time_to_wallclock 3
+may be called from any thread without synchronization.
.El
.Sh BASIC USAGE
The ball starts with
diff --git a/quark_update_boottime.3 b/quark_update_boottime.3
index f81535ef..fc2eeb4b 100644
--- a/quark_update_boottime.3
+++ b/quark_update_boottime.3
@@ -59,6 +59,15 @@ armed with
.Dv TFD_TIMER_CANCEL_ON_SET ,
which becomes readable when the clock is stepped.
.El
+.Pp
+The boottime epoch is shared by every queue in the process.
+.Nm ,
+.Xr quark_get_boottime 3
+and
+.Xr quark_time_to_wallclock 3
+may be called from any thread without synchronization:
+the epoch is updated atomically and a concurrent reader observes
+either the previous or the new value.
.Sh RETURN VALUES
Returns 0 on success, -1 if btime could not be refetched, in which
case the previous epoch is retained and
From 6d114fa5357088177c0f1d0c4efd480faa9a23a6 Mon Sep 17 00:00:00 2001
From: Nicholas Berlin
Date: Fri, 14 Aug 2026 16:15:39 -0400
Subject: [PATCH 3/4] Document wallclock translation on QQ_MONOTONIC queues
The kprobe backend stamps times with a monotonic clock that does not
advance during suspend. quark_time_to_wallclock() applies unchanged,
but the result lags the wallclock by the total suspended time, exactly
as it did before 0.8. Spell this out in quark_time_to_wallclock(3) and
point QQ_MONOTONIC in quark_queue_open(3) at it, so kprobe users know
the boottime calls treat both backends the same and how to compensate
if they care about suspend.
---
docs/quark_queue_open.3.html | 6 ++++--
docs/quark_time_to_wallclock.3.html | 13 ++++++++++++-
quark_queue_open.3 | 3 +++
quark_time_to_wallclock.3 | 17 +++++++++++++++++
4 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/docs/quark_queue_open.3.html b/docs/quark_queue_open.3.html
index e66c27bd..12e96e59 100644
--- a/docs/quark_queue_open.3.html
+++ b/docs/quark_queue_open.3.html
@@ -94,7 +94,9 @@
The KPROBE backend stamps times with a monotonic clock
+ that does not advance during suspend, relayed as
+ QQ_MONOTONIC on the opened queue's
+ flags, see
+ quark_queue_open(3).
+ quark_time_to_wallclock applies unchanged, but the
+ result lags the wallclock by the total suspended time, exactly as it did
+ before quark 0.8. Users that care about suspend can detect
+ QQ_MONOTONIC and compensate with the difference
+ between CLOCK_BOOTTIME and
+ CLOCK_MONOTONIC.
diff --git a/quark_queue_open.3 b/quark_queue_open.3
index 3626bad6..ba2e6ebd 100644
--- a/quark_queue_open.3
+++ b/quark_queue_open.3
@@ -101,6 +101,9 @@ when its event times are CLOCK_MONOTONIC instead of CLOCK_BOOTTIME, which
only the KPROBE backend does.
Monotonic times undercount by the total suspended time, users that care
about suspend must compensate.
+See
+.Xr quark_time_to_wallclock 3
+for the effect on wallclock translation.
.It Dv QQ_THREAD_EVENTS
Include per-thread events, instead of per-process events.
This option will be removed in the future, but it may be useful for debugging.
diff --git a/quark_time_to_wallclock.3 b/quark_time_to_wallclock.3
index 72f4e1a2..4fe4c972 100644
--- a/quark_time_to_wallclock.3
+++ b/quark_time_to_wallclock.3
@@ -41,6 +41,23 @@ Translate at the last moment, when a time leaves the system for
display or storage, and keep the epoch fresh with
.Xr quark_update_boottime 3
if the clock may be stepped while running.
+.Pp
+The KPROBE backend stamps times with a monotonic clock that does not
+advance during suspend, relayed as
+.Dv QQ_MONOTONIC
+on the opened queue's
+.Em flags ,
+see
+.Xr quark_queue_open 3 .
+.Nm
+applies unchanged, but the result lags the wallclock by the total
+suspended time, exactly as it did before quark 0.8.
+Users that care about suspend can detect
+.Dv QQ_MONOTONIC
+and compensate with the difference between
+.Dv CLOCK_BOOTTIME
+and
+.Dv CLOCK_MONOTONIC .
.Sh RETURN VALUES
.Fa time_since_boot
expressed in nanoseconds since the Unix epoch.
From b639b7bf8d65d51fea0fb9952d6ef46cd7dfb2be Mon Sep 17 00:00:00 2001
From: Nicholas Berlin
Date: Fri, 14 Aug 2026 16:31:08 -0400
Subject: [PATCH 4/4] Contrast slewing with steps in quark_time_to_wallclock(3)
Review feedback: make explicit which clock problem the epoch refresh
solves. Slewing adjusts the wallclock and the boot clock at the same
rate so the epoch never moves, only a step does.
---
docs/quark_time_to_wallclock.3.html | 4 +++-
quark_time_to_wallclock.3 | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/docs/quark_time_to_wallclock.3.html b/docs/quark_time_to_wallclock.3.html
index a64bfff7..fec2d0ff 100644
--- a/docs/quark_time_to_wallclock.3.html
+++ b/docs/quark_time_to_wallclock.3.html
@@ -51,7 +51,9 @@
The KPROBE backend stamps times with a monotonic clock
that does not advance during suspend, relayed as
QQ_MONOTONIC on the opened queue's
diff --git a/quark_time_to_wallclock.3 b/quark_time_to_wallclock.3
index 4fe4c972..fee8e558 100644
--- a/quark_time_to_wallclock.3
+++ b/quark_time_to_wallclock.3
@@ -41,6 +41,8 @@ Translate at the last moment, when a time leaves the system for
display or storage, and keep the epoch fresh with
.Xr quark_update_boottime 3
if the clock may be stepped while running.
+Gradual corrections (slewing) adjust the wallclock and the boot clock
+at the same rate, leaving the epoch untouched, only a step moves it.
.Pp
The KPROBE backend stamps times with a monotonic clock that does not
advance during suspend, relayed as