fix: allow lazy TLS init for threads started before profiling#531
fix: allow lazy TLS init for threads started before profiling#531
Conversation
5ae34ef to
780ea42
Compare
Benchmark results for collatzParameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. See unchanged results
|
Benchmark results for BadBoggleSolver_runParameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. See unchanged results
|
| return &state; | ||
| } | ||
| if (!state.initialized && !state.reentry_guard) { | ||
| // We are not inside pthread_getattr_np, so we can initialize the state |
There was a problem hiding this comment.
I think the state.reentry_guard captures also when we are in an allocation hook ?
There was a problem hiding this comment.
although this should not happen as we should never enter without a state, though this is a shared reentry mechanism
There was a problem hiding this comment.
I reused state.reentry_guard since we don't use it when state is not yet initialized and the purpose is similar
|
Nicolas had a smart idea, the scenario we are worried about is doing an init while we already have a lock (allocation) held. This can happens when you are doing an mmap within a malloc (especially as we can not hook all mallocs). |
When profiling starts on a process with already-running threads calling pthread_getattr_np, the allocation tracker's TLS state may not be initialized yet. This adds a pthread_getattr_np hook that guards against deadlock withthe following sequence: (pthread_getattr_np -> malloc -> tracker -> init_tl_state -> save_context -> pthread_getattr_np deadlock) and enables lazy TLS init in get_tl_state() when safe.
780ea42 to
a9d5823
Compare
What does this PR do?
When profiling starts on a process with already-running threads calling pthread_getattr_np, the allocation tracker's TLS state may not be initialized yet. This adds a pthread_getattr_np hook that guards against deadlock withthe following sequence:
(pthread_getattr_np -> malloc -> tracker -> init_tl_state -> save_context -> pthread_getattr_np deadlock) and enables lazy TLS init in get_tl_state() when safe.
Motivation
Allow allocation profiling of existing threads when profiler is not started at process startup.