Repository navigation
Commit 87a7a38
gh-162421: Stop the PyMutex spin when yields are slow
On the free-threaded build, a contended _PyMutex_LockTimed() calls
_Py_yield() up to 40 times before parking, without reloading the lock.
On an oversubscribed machine each sched_yield() can give the CPU away
for a whole time slice, so a lock hand-off can take hundreds of
milliseconds.
Time the spin: park once it has lasted longer than 100 us, or at once
when a single yield took longer than 500 us, and then skip the spin in
this thread for the next 10 ms. On an idle machine the limits are never
reached, so the spin is unchanged. The new code only shortens the spin;
the lock word, parking and hand-off logic are untouched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 828c153 commit 87a7a38
2 files changed
Lines changed: 48 additions & 0 deletions
File tree
- Misc/NEWS.d/next/Core_and_Builtins
- Python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
34 | 52 | | |
35 | 53 | | |
36 | 54 | | |
| |||
79 | 97 | | |
80 | 98 | | |
81 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
82 | 109 | | |
83 | 110 | | |
84 | 111 | | |
| |||
92 | 119 | | |
93 | 120 | | |
94 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
95 | 135 | | |
96 | 136 | | |
97 | 137 | | |
| |||
122 | 162 | | |
123 | 163 | | |
124 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
125 | 169 | | |
126 | 170 | | |
127 | 171 | | |
| |||
0 commit comments