diff options
| author | babenko <[email protected]> | 2026-06-19 14:27:43 +0300 |
|---|---|---|
| committer | babenko <[email protected]> | 2026-06-19 15:12:00 +0300 |
| commit | 89c0e29c8f9ba29ecdc736fefda87286482ac213 (patch) | |
| tree | 1adfbcd839240d8d0155771c6b775fa00a3e5f32 /library/cpp/yt/rseq/rseq.cpp | |
| parent | 824b32f6aab5c67b2d39288b1d229eb257f248f0 (diff) | |
Add lock-free per-CPU primitives to library/cpp/yt/rseq
Introduce AddPerCpu and StorePerCpu over an rseq-sharded per-CPU array.
On the x86-64 Linux fast path the update is committed by a hand-rolled
rseq critical section (non-atomic, migration-safe): addq for the 8-byte
accumulate, movq / movdqu for the 8- or 16-byte store. The kernel
restarts the sequence on preemption or migration, and only one thread
runs on a CPU at a time, so no atomic or lock is needed. Off the fast
path (other arches, no kernel rseq) the operation falls back to an
atomic on the slot indexed by sched_getcpu().
A naturally-aligned 8-byte store is single-copy atomic on x86-64, so it
is never observed torn; the 16-byte store may be, which is acceptable for
a last-writer-wins gauge.
commit_hash:6250f6e9e35cf3895ebafe0b534ec12cca50b03b
Diffstat (limited to 'library/cpp/yt/rseq/rseq.cpp')
| -rw-r--r-- | library/cpp/yt/rseq/rseq.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/library/cpp/yt/rseq/rseq.cpp b/library/cpp/yt/rseq/rseq.cpp index 9ebcb4f45ef..c2098d16d11 100644 --- a/library/cpp/yt/rseq/rseq.cpp +++ b/library/cpp/yt/rseq/rseq.cpp @@ -77,9 +77,10 @@ bool OwnsRegistration = false; bool RegisterCurrentThread() { // flags = 0. We pass the shared signature and the standard size so that whoever of - // {us, tcmalloc, librseq} runs first registers __rseq_abi and the rest get EBUSY, - // which is success for our read-only use (we never run rseq critical sections, so the - // signature only ever matters for matching this registration call). + // {us, tcmalloc, librseq} runs first registers __rseq_abi and the rest get EBUSY + // (success). The signature must be 0x53053053: it is the value emitted before abort_ip + // in the per_cpu rseq critical sections (see per_cpu-inl.h), and on a kernel abort the + // signature must match the registered one or the kernel delivers SIGSEGV. if (::syscall(RseqSyscallNumber, &__rseq_abi, RseqRegistrationSize, 0u, RseqSignature) == 0) { return true; } |
