<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ydb/library/cpp/yt/rseq/unittests, branch main</title>
<subtitle>Mirror of YDB github repos</subtitle>
<id>https://code.mastervirt.ru/ydb/atom?h=main</id>
<link rel='self' href='https://code.mastervirt.ru/ydb/atom?h=main'/>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/'/>
<updated>2026-06-22T21:50:43Z</updated>
<entry>
<title>YT-28458: Make per-CPU rseq fast path dlopen-safe</title>
<updated>2026-06-22T21:50:43Z</updated>
<author>
<name>babenko</name>
<email>babenko@yandex-team.com</email>
</author>
<published>2026-06-22T21:32:05Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=6ce03d8a5070753a84defdb8c4c9b43d852ad65b'/>
<id>urn:sha1:6ce03d8a5070753a84defdb8c4c9b43d852ad65b</id>
<content type='text'>
Hardens `library/cpp/yt/rseq` for the case where it is linked into a dlopen'd,
position-independent module (e.g. a YQL UDF `.so`). Extracted from the profiling
work that enables the rseq fast path by default.

**TLS model.** The weak `__rseq_abi` gets `global-dynamic` linkage under
`__PIC__/__PIE__` (`initial-exec` otherwise), mirroring `contrib/libs/tcmalloc`.
`initial-exec` needs a slot in the static TLS block reserved at startup, which
the loader cannot grant a module dlopen'd later — the module would fail to load
with "cannot allocate memory in static TLS block". This only changes the cold
`&amp;__rseq_abi` accesses; the hot path still reads `*(thread_pointer + CpuIdFieldOffset)`.

**Runtime safety probe `IsPerCpuFastPathSafe()`.** The cached thread-pointer
offset is valid only when `__rseq_abi` sits at a fixed offset from the thread
pointer — a glibc-owned area or the static TLS block (incl. tcmalloc), the common
case. When our `__rseq_abi` instead lands in a dlopen'd module's *dynamically
allocated* TLS, the offset is valid only on the thread that computed it; on other
threads the hot path's first store (`area-&gt;rseq_cs`) would corrupt unrelated
memory. The probe spawns one thread and checks — by pointer comparison, never
dereferencing the suspect offset — that the offset names that thread's rseq area;
if not, callers use the atomic fallback. Decided once and cached (one thread spawn
at first use).=
commit_hash:633f58f500d9d097800da81f526c56283445ffc7
</content>
</entry>
<entry>
<title>Add lock-free per-CPU primitives to library/cpp/yt/rseq</title>
<updated>2026-06-19T12:12:00Z</updated>
<author>
<name>babenko</name>
<email>babenko@yandex-team.com</email>
</author>
<published>2026-06-19T11:27:43Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=89c0e29c8f9ba29ecdc736fefda87286482ac213'/>
<id>urn:sha1:89c0e29c8f9ba29ecdc736fefda87286482ac213</id>
<content type='text'>
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
</content>
</entry>
</feed>
