Commit bbd4b0a
Resolve tstate TLS offset for general-dynamic libpython
Summary:
`initThreadStateOffset()` only recognized the initial-exec shape of
`_PyThreadState_GetCurrent` (`movq %fs:OFFSET,%rax`). When libpython is built
as a shared library the function is compiled with the general-dynamic TLS model
instead, `lea &tls_index; call __tls_get_addr; mov disp(%rax),%rax`, so the
pattern match failed and `translateLoadThreadState` fell back to emitting a
`call _PyThreadState_GetCurrent` and called `__tls_get_addr`) on every
thread-state load in JIT-compiled code. Profiling the `inference_pipeline`
benchmark showed `__tls_get_addr` accounting for 4-6% of samples in every
workload, attributed directly to JIT frames and runtime helpers like
`batchDecref`.
This adds an x86-64/Linux `decodeGeneralDynamicTstateOffset()` fallback that
decodes the general-dynamic sequence, resolves the module TLS block once via
`__tls_get_addr`, and computes a thread-pointer-relative offset (the `%fs` base
is the thread pointer, and `%fs:0` holds its value). The offset is
self-verified against `_PyThreadState_GetCurrent()` before use; on any mismatch
it returns `-1` and the existing `call` fallback is kept, so the change is
strictly safe. This mirrors the existing aarch64 TLSDESC fallback. With the
offset resolved, the fast path emits a single `mov dst, %fs:[offset]`.
Reviewed By: mpage
Differential Revision: D110197544
fbshipit-source-id: b73c49209667228b25664551842a0ca785879fc81 parent ca791c3 commit bbd4b0a
1 file changed
Lines changed: 64 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
15 | 71 | | |
16 | 72 | | |
17 | 73 | | |
| |||
32 | 88 | | |
33 | 89 | | |
34 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
35 | 99 | | |
36 | 100 | | |
37 | 101 | | |
| |||
0 commit comments