Repository navigation
Worker index from the thread's TLS slot in place on Windows - #242
Merged
Merged
Conversation
Every per-worker scratch block and the speculative distance are chosen through the calling worker's index, tens of millions of times a run of the convex pile (85 million) and trees25 (11 million). On Windows it is a native TLS slot, and every read was TlsGetValue, a call into kernel32 of 1.14 ns. For an index under 64 TlsGetValue reads the thread's TEB.TlsSlots[index]: aephysics_worker_index_inline (aephysics_inline.h) reads it in place with one load from gs, 0.28 ns, the offset checked against winternl.h when aephysics_native.c compiles; a slot not yet made, an index past 64 or a thread that has not claimed one still goes through the function. Elsewhere nothing changes. Pinned, best of five: the convex pile 9.71 to 9.62 ms a step, trees25 1.381 to 1.371 (median 1.414 to 1.394), sleep 1.925 to 1.908. Bits unchanged.
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.
Progress at a glance
aephysics_worker_index_inline: onegsload on 64-bit Windows, with the existing function as fallbackwinternl.hat compile timenative.worker_index()andnative.scratch()use it; Linux and macOS unchangedWhy
Every per-worker scratch block and the speculative distance are chosen through the calling worker's index. That's 85 million lookups in a convex pile run and 11 million in trees25 (counted). On Windows the index lives in a native TLS slot, and each read was a
TlsGetValuecall into kernel32 at 1.14 ns. Compiler thread-locals aren't an option, because MinGW emulates them through__emutls_get_address(aefd8c9).For an index under 64,
TlsGetValuejust reads the calling thread'sTEB.TlsSlots[index], which Microsoft documents inwinternl.h. The inline version reads it in place: 0.28 ns per lookup. Three cases still go through the original function: a slot not yet created, an index of 64 or more, and a thread that hasn't claimed a slot.Numbers
Pinned, best of five (median), ms per step: