Skip to content

[geom] Fix TLS ownership and lifecycle - #1

Closed
agheata wants to merge 4 commits into
trwenz:twenzel/geom-false-sharing-fixesfrom
agheata:geom/pr-22955-followup
Closed

[geom] Fix TLS ownership and lifecycle#1
agheata wants to merge 4 commits into
trwenz:twenzel/geom-false-sharing-fixesfrom
agheata:geom/pr-22955-followup

Conversation

@agheata

@agheata agheata commented Sep 1, 2026

Copy link
Copy Markdown

This follows up the requested changes from the review of
root-project#22955 and is based directly on the current head of
twenzel/geom-false-sharing-fixes (3e31b2338b9). The large navigation
scaling improvement from the original work is preserved; these commits
focus on ownership and lifecycle correctness around the new TLS design.

Changes

  • Register lazy pattern matrices, including identity matrices, with the
    manager owning the divided volume instead of the ambient gGeoManager.
    The existing CreateMatrix() virtual interface is preserved.
  • Add a two-manager regression test that first-touches geometry A while B
    is current, deletes B, and then reuses A.
  • Keep the Pgon/Xtru hot TLS entries as direct non-owning caches while the
    shape owns their large per-thread buffers and polygons. Cleanup and shape
    destruction now reclaim those allocations.
  • Document the quiescent-navigation cleanup contract, the small TLS
    high-water slots retained until thread exit, and that SetMaxThreads()
    remains necessary for manager-level thread safety.
  • Credit Tristan Wenzel in the 6.42 contributor list; Sandro Wenzel was
    already listed there.

The large buffers are still allocated separately on cold first-touch, as
in the optimized branch. Only their ownership changes, so the steady-state
TLS lookup remains unchanged and lock-free. The mutex is used only for cold
allocation registration and cleanup.

Validation

  • Dictionary-aware RelWithDebInfo build:
    cmake --build ... --target onepcm thread_navigation -j2
  • Geometry gtests: 7/7 passed with
    ctest --output-on-failure -R '^gtest-geom-'
  • Compiled and interpreted stressgeometry tests: 2/2 passed.
  • The two-manager and shape-cleanup tests pass under Valgrind with ROOT's
    suppressions and no unsuppressed diagnostics.
  • A 512-Pgon allocation-loop probe (4096 edges) retained about 25.3 MB on
    the reviewed PR head and about 16.5 kB with this follow-up; the remainder
    is the documented small TLS high-water vector.
  • Five alternating, CPU-pinned navigation A/B runs found no regression:
    single-thread medians were 0.763 vs 0.760 million rays/s (-0.3%, within
    dispersion), and 16-thread medians were 11.64 vs 11.85 million rays/s.
    Checksums matched in every run.
  • git clang-format --diff reports no formatting changes for the complete
    follow-up range, using clang-format 18.1.3 and ROOT's .clang-format.

Development and review were assisted by Codex (GPT-5) under direct human
supervision.

Lazy pattern initialization can run while a different geometry
manager is current. Register new matrices, including identity matrices,
with the manager owning the divided volume so deleting an unrelated
manager cannot invalidate the TLS cache.

Preserve the existing CreateMatrix interface and cover the two-manager
lifetime explicitly.
Keep the hot TLS slots for Pgon and Xtru as non-owning caches while
moving their large buffers and polygons under shape ownership.
ClearThreadData and shape destruction can now reclaim these allocations
after navigation is quiescent.

Cover cleanup and lazy rebuilding from stale TLS slots with multiple
worker threads.
Document that monotonic TLS slot vectors retain their high-water size
until the owning thread exits, while the shape-owned large allocations
are reclaimed separately.

Limit lazy-allocation claims to component scratch state and clarify that
SetMaxThreads is still required for thread-safe manager navigation.
Correct the cached pattern-matrix lifetime description as well.
Add Tristan Wenzel to the 6.42 contributor list. Sandro Wenzel is
already present, so both contributors to the navigation optimization
are credited without duplicating an existing entry.
@agheata agheata closed this Sep 1, 2026
@agheata
agheata deleted the geom/pr-22955-followup branch September 1, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant