Make boottime and hz access atomic - #393
Open
nicholasberlin wants to merge 1 commit into
Open
Conversation
nicholasberlin
force-pushed
the
boottime-atomics
branch
2 times, most recently
from
August 14, 2026 19:52
d753d21 to
74ca4af
Compare
quark.boottime and quark.hz live in a process-wide global shared by every queue. quark_update_boottime() may be called from one thread while another converts timestamps through quark_time_to_wallclock(), as auditbeat does with two independent quark consumers in the same process, which no caller-side lock can span. The plain u64 loads and stores were a data race. Route all access through static inline helpers that use __atomic_load_n/__atomic_store_n with relaxed ordering. Relaxed is sufficient since boottime is a single self-contained value with no ordering dependency on other data; readers just need an untorn value and tolerate a stale epoch for one cycle. On x86-64 and aarch64 the generated code is unchanged (plain mov/ldr/str, no libatomic), and the builtins compile back to gcc 4.8.5 on centos7. quark_update_boottime(), quark_get_boottime() and quark_time_to_wallclock() are now safe to call from any thread.
nicholasberlin
force-pushed
the
boottime-atomics
branch
from
August 14, 2026 20:17
74ca4af to
4ea61db
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
quark.boottimeandquark.hzlive in a process-wide global shared by every queue.quark_update_boottime()may be called from one thread while another converts timestamps throughquark_time_to_wallclock()— as auditbeat does with two independent quark consumers in the same process — which no caller-side lock can span. By the letter of C11 the plain u64 loads and stores are a data race.Route all access through
static inlinehelpers that use__atomic_load_n/__atomic_store_nwith relaxed ordering. Relaxed is sufficient since boottime is a single self-contained value with no ordering dependency on other data; readers just need an untorn value and tolerate a stale epoch for one cycle.To be clear about what this does and doesn't change: the compiled code is identical before and after — on x86-64 and aarch64 an aligned 8-byte access is already a single atomic
mov/ldr/str, the helpers inline away, and there is no libatomic dependency (nmclean). Nothing misbehaves today and this fixes no observed bug. What the change buys:Also verified to build on centos7 gcc 4.8.5 — the
__atomicbuiltins date to gcc 4.7, whereas C11_Atomic/stdatomic.hwould need 4.9, hence the builtins.Must merge before #388, which documents the thread-safety this change provides.