Skip to content

[Linux] ~3 s freezes: GlobPool worker spin-waits in libanimationsystem (ThreadSpin) while the main thread sleeps on a futex #3558

Closed

Description

@rattones

Your system information

Summary of the relevant parts:

Game Dota 2 native Linux, Vulkan (default), ClientVersion=6941, SourceRevision=11041083 (Sep 25 2026), Steam Linux Runtime 3.0 (sniper)
OS Ubuntu 26.04.1 LTS, kernel 7.0.0-34-generic, X11 + Cinnamon 6.4.13
CPU AMD Ryzen 7 5800H (8C/16T)
GPU NVIDIA GeForce RTX 3050 Laptop 4 GB, driver 595.91.07 (open kernel module), MUX in discrete mode
RAM 16 GB
Launch options gamemoderun %command% -novid -map dota

Please describe your issue in as much detail as possible:

Expected: smooth rendering during a match.

What happens: the game freezes completely (no new frames) for about 3 seconds, then resumes on its own. This repeats roughly once or twice per minute, both while playing and while spectating live games. There are no errors in the kernel log and no NVIDIA Xid messages.

What the profiling shows: during every one of these freezes, one GlobPool/N worker thread spins at 100% of one core in ThreadSpin (libtier0.so), called from libanimationsystem.so. At the same time the main thread (dota2) sleeps on a futex. When the main thread wakes up, the first code it runs is in libanimationsystem.so. The spin ends right after that and rendering resumes. It looks like the worker waits for animation work that only the main thread can complete, while the main thread waits for the worker. The deadlock seems to be broken by a timed wait of about 3 s.

1. Freeze frequency and duration (4 sessions, same day)

Freeze = GPU utilization at 0% for 1 s or more in the middle of a match (the GPU sits at 50–80% otherwise).

Session Length Freezes of 1 s or more Median duration Lasting 2.9–3.6 s
playing 48 min 26 3.0 s 13
playing 38 min 32 3.0 s 23
playing 6 min 13 (8 in-game with the signature below) — 2.0–3.0 s each
spectating 6 min spin signature captured with perf (below) — —

The near-constant 3.0 s duration (3.001–3.007 s at 500 ms sampling) points to a timeout, not to load.

2. What the machine is doing during a freeze

Everything except one thread goes idle. Sampled every 500 ms:

GPU: utilization drops to 0 and power decays, VRAM steady (3.1 of 4 GB)
timestamp                gpu_util%  vram_used_MiB  power_W
2026-09-29T14:10:23.426  76         3159           74.65
2026-09-29T14:10:23.926  0          3159           61.31
2026-09-29T14:10:24.426  0          3159           37.83
2026-09-29T14:10:24.926  0          3159           23.16
2026-09-29T14:10:25.426  0          3159           23.03
2026-09-29T14:10:25.927  0          3159           19.61
2026-09-29T14:10:26.427  0          3159           15.94
2026-09-29T14:10:26.927  72         3156           26.39
CPU: the process drops from ~390% to exactly one core; whole system at ~7%, no CPU pressure
timestamp                cpu_total%  busiest_core%  busiest_core  psi_cpu%  dota_cpu%  dota_running_threads
2026-09-29T14:10:23.334  26.2        49.0           6             0.5       392.0      2
2026-09-29T14:10:23.844  12.3        92.2           0             0.3       160.8      1
2026-09-29T14:10:24.334  7.4         100.0          0             0.0       102.0      1
2026-09-29T14:10:24.834  7.8         100.0          0             0.1       102.0      1
2026-09-29T14:10:25.334  7.4         100.0          0             0.0       102.0      1
2026-09-29T14:10:25.834  7.8         100.0          0             0.0       104.0      1
2026-09-29T14:10:26.334  7.9         100.0          0             0.0       102.0      1
2026-09-29T14:10:26.834  23.1        50.0           0             0.7       340.0      7
Threads (from /proc): one GlobPool worker running, the main thread sleeping on a futex
timestamp                tid    thread       state  cpu%   wchan
2026-09-29T14:10:24.334  82985  dota2        S      0.0    futex_do_wait
2026-09-29T14:10:24.334  82992  GlobPool/2   R      100.0  0

This pattern shows up in all 8 in-game freezes of that session. The spinning worker varies (GlobPool/0, /1, /2, /3, /6). It always runs about 98% in user space, on core 0, with affinity 0-15. In the same freezes there is no I/O wait, no memory pressure (PSI ~0), no major page faults and no D-state threads.

3. Where the worker spins (perf record, 49 Hz, call graphs)

52 of the 58 samples of the spinning worker in one freeze have this exact stack:

ThreadSpin                     libtier0.so
  [unknown]                    libanimationsystem.so
  [unknown]                    libclient.so           (x6 frames)
  [unknown]                    libscenesystem.so      (x3)
  [unknown]                    libtier0.so
  [unknown]                    libscenesystem.so      (x2)
  [unknown]                    libtier0.so            (x2)
  CThread::ThreadProc(void*)   libtier0.so
  libc.so.6 (thread start)

The NVIDIA driver (libnvidia-glcore) accounts for under 2% of the samples inside the freeze windows. The time is spent in the game's own code.

Timeline: the worker spins and the main thread is absent until it wakes up inside libanimationsystem
14:34:56.710 GlobPool/1  ThreadSpin (libtier0) < libanimationsystem < libclient
14:34:56.734 GlobPool/1  ThreadSpin (libtier0) < libanimationsystem < libclient
   ... every sample for 0.7 s: GlobPool/1 in the same stack, no samples from dota2 (sleeping) ...
14:34:57.367 GlobPool/1  ThreadSpin (libtier0) < libanimationsystem < libclient
14:34:57.432 dota2       libanimationsystem < libanimationsystem < libanimationsystem   <- main thread wakes up here
14:34:57.516 dota2       Plat_GetWindowContentsScale (libtier0) < libengine2
14:34:57.683 GlobPool/2  ... < libnvidia-glcore                                          <- rendering resumes
14:34:57.726 dota2       libnvidia-glcore ...

The same happens in the freeze at 14:34:04, this time with GlobPool/2.

4. Already ruled out
  • VRAM: peak 2.8 of 4 GB, with at least 1.2 GB free throughout.

  • Disk: no reads or writes around the freezes.

  • Network: stable during the freezes.

  • Swap: at most 0.26 GB in use during these sessions.

  • NVIDIA driver version: the same symptom on 595.91.07 and 610.57.04. No Xid errors in 12 boots.

  • CPU frequency and power profile: the symptom persists with the GameMode performance governor, the ACPI performance profile and PowerMizer at maximum performance.

  • Xorg: the freezes do not line up with RandR output probes. Xorg and the desktop are idle during them.

  • Steam game recording: disabled for Dota 2.

  • Steam Runtime Diagnostics: the runtime's own x11/vulkan check reports cannot-load, timeout, cannot-draw in every container (scout, soldier, sniper), although the game renders fine with Vulkan. It may be unrelated, but it is included in the gist.

Possibly the same symptom as #1366 (freezes of about 3 s during teamfights on Linux), which never got a root cause.

Steps for reproducing this issue:

  1. Launch Dota 2 on Linux (native, Vulkan) on the machine described above.
  2. Play a match or spectate a live game for a few minutes.
  3. Every minute or two the game freezes for about 3 s and then recovers. At that moment, top -H -p $(pidof dota2) shows a single GlobPool/N thread at 100% while every other thread sleeps.

The data above was collected with monitor, a Linux GPU/CPU/thread sampler written while chasing this bug. To collect the same evidence:

sudo sysctl kernel.perf_event_paranoid=1       # to allow perf without root
monitor all -f pid:$(pidof dota2) -P -o dota.csv
# after a freeze, where the threads spent the time in that window:
tools/perf-window.sh dota 14:34:56 14:34:58 GlobPool

I can provide the full CSVs and the perf.data file (1.4 MB) on request.

— @rattones

Activity

  1. rattones commented on Sep 30, 2026

    @rattones
    Author

    Update: same freeze on a completely different driver stack (nouveau + NVK)

    To rule out the NVIDIA proprietary driver, I switched this machine to the free stack and played again. The freeze is still there, with the same signature.

    Kernel driver nouveau (GSP firmware), Linux 7.0.0-34
    Vulkan driver NVK, Mesa 26.0.8 (deviceName = NVIDIA GeForce RTX 3050 Laptop GPU (NVK GA107))
    Session 77 minutes, 2026-09-29 22:48 → 00:05
    Game build same as the original report (SourceRevision=11041083)

    nouveau exposes no GPU utilization, so I detected the freezes from the thread data instead, using the same signature as in the original report:

    • the process drops to exactly one core;
    • one GlobPool/N thread is running (R) at ≥90% of a core;
    • the main thread dota2 sleeps in futex_do_wait.

    13 freezes matched in 77 minutes, lasting 1.5–3.5 s (four of them ~3.0 s). The spinning worker varied (GlobPool/0 through /6), but it ran on core 0 every time and ~100% of its CPU was user time, just as on the proprietary driver.

    One of them, sampled every 500 ms (23:03:43)
    time          cpu_total%  busiest_core%  core  psi_cpu%  dota_cpu%  | spinning thread (state:cpu%:user%:last core)  | main thread
    23:03:43.328  8.9         60.8           0     0.2       112.0      | GlobPool/6:R:58.0:u58.0:cpu0                   | S:futex_do_wait
    23:03:43.828  8.0         100.0          0     0.2       102.0      | GlobPool/6:R:100.0:u100.0:cpu0                 | S:futex_do_wait
    23:03:44.338  7.8         100.0          0     0.0       102.0      | GlobPool/6:R:98.0:u98.0:cpu0                   | S:futex_do_wait
    23:03:44.828  8.6         100.0          0     0.2       104.1      | GlobPool/6:R:102.0:u102.0:cpu0                 | S:futex_do_wait
    23:03:45.328  7.7         100.0          0     0.0       102.0      | GlobPool/6:R:100.0:u100.0:cpu0                 | S:futex_do_wait
    23:03:45.838  8.0         100.0          0     0.0       100.0      | GlobPool/6:R:98.0:u98.0:cpu0                   | S:futex_do_wait
    23:03:46.338  7.5         100.0          0     0.0       104.0      | GlobPool/6:R:102.0:u102.0:cpu0                 | S:futex_do_wait
    23:03:46.828  9.9         70.8           0     0.4       120.4      | GlobPool/6:S:61.2:u61.2:cpu8                   | S:futex_do_wait
    23:03:47.328  11.1        21.2           6     0.3       134.0      | (spin over)                                    | S:futex_do_wait
    

    Rate of these freezes, measured with the same detector in both setups:

    Driver Length Freezes Per hour Dota CPU (median)
    NVIDIA 595.91.07, playing 6 min 8 ~80 378%
    nouveau + NVK 77 min 13 ~10 141%

    The rate is lower on NVK, but I don't read that as the driver helping. The game used much less CPU in this session, most likely because the frame rate is lower on NVK. Fewer frames means fewer animation jobs, and so fewer chances to hit the deadlock.

    I couldn't record perf in this session, so I don't have the libanimationsystem → ThreadSpin stack on NVK. Everything visible from /proc matches the stack captured on the proprietary driver: the worker spins in user space while the main thread waits on it.

    Since the freeze shows up with the NVIDIA driver and with Mesa/NVK alike, this points to the job system or the animation code in the client rather than to the graphics driver.

    Collected with monitor (monitor all -f pid:$(pidof dota2)). I can share the full CSVs if useful.

    — @rattones

  2. rattones commented on Sep 30, 2026

    @rattones
    Author

    Update: -disable_affinity_preferences doesn't help, and the spin also happens on the main thread

    New session today, back on the proprietary driver, with the launch option usually suggested for thread-scheduling stutter on Linux:

    Driver NVIDIA 595.91.07 (open kernel module)
    Launch options gamemoderun %command% -novid -map dota -disable_affinity_preferences
    Session 53 minutes of play, 2026-09-30 07:58 → 08:51
    Game build same as the original report
    VRAM / swap peak 2914 of 4096 MiB, swap 0: memory is not a factor

    The option makes no difference. Excluding the initial load, the GPU sat at 0% for ≥1 s mid-match 70 times in 53 minutes. In 65 of those, a single thread of the game spins at ~100% of one core in user space, always on core 0, while every other thread is idle. Most last 3.0 s. That is ~74 per hour, the same rate as the ~80/h I measured without the option.

    New: three variants of the same spin

    Splitting those 70 freezes by what the main thread (dota2) is doing at the time:

    Variant Spinning thread Main thread Count Lasting ~3.0 s
    A a GlobPool/N worker futex_do_wait 40 27
    B a GlobPool/N worker ep_poll 18 12
    C the main thread itself spinning (R, 100% user) 7 4
    — none visible futex_do_wait 5 2

    Variant A is the one in the original report. The last row may simply be spins shorter than the 500 ms sampling window can show.

    Variant B, 08:16:51: the worker spins while the main thread sits in epoll
    time          gpu%  cpu_total%  busiest_core%  core  dota_cpu%  | spinning thread (state:cpu%:user%:last core) | main thread
    08:16:51.306  0     -           -              -     -          |                                                |
    08:16:51.466        7.4         100.0          0     102.0      | GlobPool/3:R:100.0:u100.0:cpu0                 | S:ep_poll
    08:16:51.966        8.0         100.0          0     104.0      | GlobPool/3:R:100.0:u100.0:cpu0                 | S:ep_poll
    08:16:52.476        7.5         100.0          0     102.0      | GlobPool/3:R:100.0:u100.0:cpu0                 | S:ep_poll
    08:16:52.976        7.9         100.0          0     102.0      | GlobPool/3:R:100.0:u100.0:cpu0                 | S:ep_poll
    08:16:53.466        7.5         100.0          0     104.1      | GlobPool/3:R:100.0:u100.0:cpu0                 | S:ep_poll
    08:16:53.966        8.2         100.0          0     104.0      | GlobPool/3:R:102.0:u102.0:cpu0                 | S:ep_poll
    08:16:54.311  65                                                |                                                |
    08:16:54.476        23.9        54.0           1     352.9      | (spin over)                                    | R
    

    GPU utilization, from the GPU CSV sampled at slightly different instants: 78% at 08:16:50.8, 0% from 08:16:51.3 through 08:16:53.8, 65% at 08:16:54.3.

    Variant C, 08:21:40: the main thread spins and every worker is idle
    time          cpu_total%  busiest_core%  core  dota_cpu%  | thread          state  cpu%   user%  sys%  last core
    08:21:40.476  7.5         100.0          0     100.0      |
    08:21:40.976  7.8         100.0          0     104.0      | dota2 (main)    R      100.0  100.0  0.0   0
    08:21:41.466                                              | dota2 (main)    R      100.0  100.0  0.0   0
    08:21:41.966                                              | dota2 (main)    R      102.0  102.0  0.0   0
    

    No GlobPool worker is above 1% during this window. The same pattern shows at 08:05:47, 08:27:22 and 08:39:09.

    This changes what I suggested in my previous comment

    In the fix suggestion I described a dependency cycle broken by a timed wait on the main thread. Variants B and C don't fit that:

    • B: the main thread isn't waiting on the job at all. It is in its event loop (epoll), and the worker still spins for ~3 s.
    • C: the main thread is the one spinning, and no other thread is running, so nothing can be holding what it waits for.

    A better fit for all three variants is a spin-wait with a built-in timeout of ~3 s on a condition that, in these cases, nothing ever satisfies. The spin runs on whichever thread executes that code path: a pool worker in A and B, and the main thread in C, probably when it runs the job inline. It ends when the timeout expires, not when the condition becomes true. That explains why the duration is almost always 3.0 s, why the machine is idle meanwhile, and why the main thread can be doing something else entirely.

    So the most useful places to look are:

    1. The condition being waited on in the libanimationsystem path under ThreadSpin (see the stack in the original report). Something that should set or signal it is missing, happens out of order, or targets the wrong object. This looks like a lost wake-up rather than contention.
    2. The ~3 s timeout itself. Wherever it fires, logging which wait expired would identify the condition straight away.
    3. Bounding the spin (spin → yield → block, as in my previous comment) is still worth doing. It won't fix the missing signal, but a thread parked on a futex doesn't burn a core, and the stall becomes visible in a profiler.

    perf was not available in this session, so the ThreadSpin ← libanimationsystem stack is confirmed only for variant A, in the earlier session. Everything visible from /proc for B and C is the same: one thread, ~100% user time, core 0, ~3 s.

    Attached: dota2-linux-freeze-3558-2026-09-30.zip (1.2 MB), with the raw CSVs for this session. The README.txt inside lists example timestamps for each variant.

    — @rattones

    dota2-linux-freeze-3558-2026-09-30.zip

  3. rattones commented on Sep 30, 2026

    @rattones
    Author

    Update: driver 610.57.04 + MangoHud frame times: the freeze is capped at ~3.24 s

    Another session, this time on the newest NVIDIA driver and with MangoHud logging every frame, so the freeze length now comes from the game's own frame times instead of the 500 ms sampling.

    Driver NVIDIA 610.57.04 (open kernel module)
    Launch options gamemoderun mangohud %command% -novid -map dota -disable_affinity_preferences
    Session 34 minutes of play, 2026-09-30 13:00 → 13:34, 199 624 frames
    Frame time median 8.5 ms (~118 fps), p99 18.3 ms, p99.9 42.5 ms
    Game build same as the original report
    The driver update changes nothing

    The monitor saw 43 freezes mid-match, ~76 per hour. That is the same rate as on 595.91.07, with or without -disable_affinity_preferences. The same three variants show up, always with the spinning thread on core 0 at ~100% user time:

    Variant Spinning thread Main thread Count
    A GlobPool/N futex_do_wait 27
    B GlobPool/N ep_poll 7
    C the main thread itself spinning 6
    — none visible — 3
    New: the longest frame is always ~3.24 s

    MangoHud logged 53 frames of 500 ms or more in 34 minutes. The long ones line up with the freezes seen by the monitor (examples below). Their lengths:

    Frame time Frames
    500 ms – 1 s 18
    1 – 2 s 16
    2 – 3 s 8
    ≥ 3 s 11

    Of the 11 frames of 3 s or more, 10 fall between 3240.0 and 3249.0 ms: 3240.0, 3241.5, 3241.6, 3242.8, 3243.7, 3244.0, 3244.1, 3246.3, 3248.9 and 3249.0 ms. The eleventh is 3114.5 ms. No frame in the session is longer than 3249 ms.

    A 9 ms spread on a 3.2 s freeze is not load: it is a hard limit. It fits the earlier observation that most freezes last "3.0 s" at 500 ms sampling, and it sharpens the picture:

    • ~3.24 s frames: the spin-wait runs until its timeout, because the condition it waits for is never met. Roughly 3.0 s of timeout plus the rest of that frame's work.
    • 0.5–3 s frames: the same spin (same variants, same core 0 signature in the monitor), but the condition is met before the timeout fires, so the waited-for work does finish, only late.

    This points to the timeout inside the libanimationsystem wait path (ThreadSpin, see the stack in the original report). Whatever fires at ~3.2 s is the single best place to put a log line. It would name the condition that was never satisfied, and the shorter freezes would show how long it usually takes when it is satisfied.

    Examples: monitor freeze start → MangoHud frame time
    monitor start  length@500ms  variant  core  MangoHud frame
    13:01:34       3.0 s         B        0     3244.1 ms
    13:06:29       3.0 s         A        0     3242.8 ms
    13:08:42       5.0 s         A        0     3241.6 ms
    13:10:00       3.5 s         B        0     3246.3 ms
    13:14:59       3.5 s         A        0     3248.9 ms
    13:19:17       3.0 s         A        0     3249.0 ms
    13:21:59       3.0 s         A        0     3241.5 ms
    13:28:16       3.0 s         B        0     3240.0 ms
    13:31:09       3.5 s         A        0     3243.7 ms
    13:02:32       2.5 s         A        0     2506.3 ms
    13:03:45       2.0 s         A        0     2231.6 ms
    13:07:34       1.5 s         A        0     1826.6 ms
    

    For completeness: swap grew from 0.2 to 2.8 GB during this session, since other applications were open. The freezes above are the same thread signature as in sessions with no swap at all (VRAM peaked at 3231 of 4096 MiB), so I don't think memory plays a part here.

    Attached: dota2-linux-freeze-3558-2026-09-30-610.zip (3.9 MB): the monitor CSVs and the MangoHud per-frame log for this session, with a README.txt.

    — @rattones

    dota2-linux-freeze-3558-2026-09-30-610.zip

  4. rattones commented on Sep 30, 2026

    @rattones
    Author

    Analysis and suggested fix

    This consolidates everything measured in this issue into one explanation and a set of suggested fixes. I don't have the source: the function names come from stripped binaries, and the mechanism is inferred from /proc thread states (500 ms), perf call graphs (49 Hz) and MangoHud per-frame logs. The raw data is in the zips attached to the comments linked below.

    What was measured
    # Observation Where
    1 During a freeze, one thread spins at ~100% of one core, entirely in user space, never blocking or yielding. Every other thread is idle, and the machine sits at ~7% CPU with no CPU, I/O or memory pressure all sessions
    2 The spin is in ThreadSpin (libtier0), called from libanimationsystem ← libclient ← libscenesystem ← CThread::ThreadProc (52 of 58 samples of the spinning thread) perf, original report
    3 Three variants. A: a GlobPool/N worker spins, main thread in futex_do_wait. B: a worker spins, main thread in ep_poll (its event loop). C: the main thread itself spins and the workers are idle 08:51 update, 610 update
    4 In variant A, when the main thread wakes up, the first code it runs is in libanimationsystem, and the spin ends right after perf timeline, original report
    5 Hard cap: of the 11 frames ≥ 3 s in a 34-minute session, 10 are between 3240.0 and 3249.0 ms, and no frame exceeds 3249 ms MangoHud, 610 update
    6 Shorter freezes too: 42 frames between 0.5 and 3 s in the same session, with the same thread signature MangoHud + monitor
    7 The spinning thread is on core 0 in practically every freeze, although its affinity is 0-15. Core 0 is tied for the highest amd_pstate_prefcore_ranking on this Ryzen 7 5800H, so this is most likely just the scheduler's choice, not a cause threads CSV
    8 Not the driver, not thread placement: ~75–80 freezes per hour of play on NVIDIA 595.91.07 and 610.57.04, with and without -disable_affinity_preferences. Also present on nouveau + NVK (Mesa 26.0.8), at a lower rate with lower CPU load NVK update, later updates
    Mechanism

    A spin-wait in the libanimationsystem path waits for a condition that is set late or never, and gives up after a built-in timeout of about 3.2 s:

    • Frames of ~3.24 s: the condition is never met. The spin runs until the timeout, so the frame lasts the timeout plus the rest of its work. The 9 ms spread across 10 such frames rules out load as the cause: it is a fixed limit.
    • Frames of 0.5–3 s: the condition is met, only late, and the spin ends before the timeout.
    • The thread that spins is whichever one runs that code path: a pool worker in A and B, and the main thread in C, probably when it executes the job itself.

    Why it isn't a plain deadlock between the main thread and a job: in B the main thread is not waiting on the job at all, and in C nothing but the spinning thread is running. The timeout therefore sits in the spin path itself, not in whatever the main thread is doing.

    What it looks like: a missing or misordered signal, not lock contention. Candidates are a lost wake-up, a flag set on the wrong object or generation, or a producer that ends up scheduled behind its own consumer.

    Suggested fixes, in order of priority

    1. Find the condition and why it is set late or never (the actual bug). Two handles point at it:

    • the wait under ThreadSpin in libanimationsystem (the stack above);
    • the ~3.2 s timeout: whatever gives up after ~3.2 s is waiting on exactly that condition.

    Logging where the timeout fires (which job, which object, how long it waited), plus a histogram of wait times, would identify it directly. It would also show how often players actually hit it.

    2. Make the producer impossible to starve. If the condition is produced by work queued behind the waiter, in the same pool or on the main thread, make the dependency explicit: schedule the waiter as a continuation of the producer, or pass the data into the job instead of having the job wait for it. Having the waiting thread "help" by running pending jobs is not enough on its own. If it picks up the waiting job instead of the producer, it spins itself, which is exactly variant C. Helping only works if it runs the producer.

    3. Never spin unbounded (defensive). Spin briefly, then yield, then block on something the producer signals:

    for ( int i = 0; !cond(); ++i )
    {
        if ( i < 64 )        ThreadPause();         // _mm_pause
        else if ( i < 1024 ) ThreadSleep( 0 );      // sched_yield
        else                 waitable.Wait( 1 );    // futex/condvar, signaled by the producer
    }

    This frees the core and makes the wait visible in profilers. It does not remove the freeze when the signal never comes: the thread would sleep instead of spin, and the frame would still wait until the timeout. Only fix 1 removes the freeze itself.

    4. Shorten the timeout's fallback, as a stopgap. A frame blocked for 3.2 s is what players see. If the work can be recovered, for example by redoing it inline or skipping that animation update for one frame, a timeout of a few frames would turn the 3 s freeze into a short hitch until the root cause is fixed.

    How to verify a fix

    With the same data collection (monitor all -f pid:$(pidof dota2) -P from monitor, plus MangoHud with log_interval=0), a fixed build should show, over a ~30-minute match:

    • no frames of 3.2 s or more, and no cluster of frames around 3240 ms (currently 10 in 34 minutes);
    • far fewer frames of 0.5 s or more (currently 53 in 34 minutes);
    • none of the three variants: no thread in R at ~100% user time on a single core while the GPU is at 0% and every other thread is idle;
    • no ThreadSpin ← libanimationsystem stacks in perf inside freeze windows (tools/perf-window.sh).

    I'm happy to test a beta or debug build and report back with the same measurements.

    — @rattones

  5. rattones commented on Sep 30, 2026

    @rattones
    Author

    Closing remarks

    To sum up what this issue has established:

    • The symptom: Dota 2 on Linux freezes for up to ~3.2 s, then recovers, about once or twice a minute while playing. It is not a crash and not an FPS drop: rendering stops completely and resumes on its own.
    • Where it happens: in the game's own code. One thread spins in ThreadSpin, called from libanimationsystem, waiting for a condition that arrives late or never, until a built-in timeout of ~3.2 s gives up. The whole machine is idle meanwhile.
    • What it is not: it is not the graphics driver (NVIDIA 595 and 610, and Mesa/NVK), not thread placement (-disable_affinity_preferences), not VRAM, not memory pressure, not disk, not network. Each of these was measured and ruled out.
    • What is still open: which condition the spin waits for, and why it is set late or never. That needs the source, which is why the analysis above stops at the timeout and the ThreadSpin ← libanimationsystem stack.
    If you're seeing this too

    More data from other machines would help tell what is universal and what is specific to mine. Everything here is one laptop: a Ryzen 7 5800H with an RTX 3050. It would be especially useful to know whether it happens on Intel CPUs, AMD GPUs, Wayland, Windows, or with different core counts. If you have freezes of about 3 s in Dota 2, a comment with any of the following would be valuable:

    1. The quickest check: play a match with MangoHud logging every frame (log_interval=0, then start and stop logging with Shift+F2), and report how many frames were ≥ 3 s and how long they were. If they cluster around ~3240 ms, it is this bug.
    2. The thread signature: during a freeze, run top -H -p $(pidof dota2). You should see a single thread (GlobPool/N or dota2) at ~100% while everything else sits near 0.
    3. The full picture: monitor records GPU, CPU, per-thread state and, with -P, perf call graphs in one go:
      sudo sysctl kernel.perf_event_paranoid=1    # lets perf run without root, until reboot
      monitor all -f pid:$(pidof dota2) -P
    4. Your CPU, GPU, driver, distribution, session type (X11/Wayland) and launch options.

    Thank you to everyone who reads this and takes a moment to add data. A single MangoHud log from different hardware can say more than another hour of logs from mine.

    Thank you, Valve

    Thank you, Valve, for keeping a native Linux client and an open tracker where players can report what they measure, and for believing that the community can help build something as good as Dota 2. This investigation was done in that spirit: to hand over as much evidence as possible so the fix is easier to find, not to complain. I'm happy to test a beta or debug build and report back with the same measurements.

    — @rattones

  6. rattones commented on Oct 5, 2026

    @rattones
    Author
  7. rattones commented on Oct 5, 2026

    @rattones
    Author

    Root cause found: CPU 0's TSC runs seconds behind the other cores, and the spin times itself with it. Closing.

    The ~3 s freezes in this issue come from a firmware defect on this laptop: CPU 0's time-stamp counter (TSC) runs a few seconds behind every other core. The spin-wait in ThreadSpin measures its elapsed time with the TSC. When a spinning thread lands on core 0, the counter jumps back by that many seconds, and the thread spins until core 0 catches up. The "hard cap" I reported isn't a timeout in the game: it is that boot's TSC gap, which the kernel measures and logs on every boot.

    It became frequent after an OS upgrade because, since kernel 6.9, amd-pstate's preferred-core ranking makes the scheduler favor core 0 on this CPU. Booting with amd_prefcore=disable made the freezes disappear: 0 frames ≥ 1 s in a 30-minute session, against about 41 per hour before.

    This also replaces some of my earlier conclusions. The corrections are listed at the end.

    1. The kernel reports the gap on every boot
    TSC synchronization [CPU#0 -> CPU#2]:
    Measured 15334739594 cycles TSC warp between CPUs, turning off TSC clock.
    tsc: Marking TSC unstable due to check_tsc_sync_source failed
    clocksource: Switched to clocksource hpet
    

    This happens on all 89 boots since this OS was installed (2026-09-08), across two kernel versions. The gap changes on every boot, from 2.0 to 20.7 s. This CPU (Ryzen 7 5800H) has no TSC_ADJUST, so the kernel can't correct the gap. It can only stop using the TSC as its own clock and fall back to HPET. User-space code that executes RDTSC directly still reads the out-of-sync counters.

    2. Only core 0 is off

    Measured against the kernel's global clock (HPET), with tools/tsc-per-cpu.c from the attachment:

     0:  +0.000s   1:  +3.050s   2:  +3.050s   3:  +3.050s
     4:  +3.050s   5:  +3.050s  ...            15:  +3.050s
    

    CPUs 1–15 agree with each other to well under a millisecond, and CPU 0 is behind by exactly the gap the kernel logged for that boot (9 741 044 935 cycles at 3193.966 MHz = 3.050 s). This is why the spinning thread was on core 0 in practically every freeze. I earlier put that down to the scheduler's preferred-core ranking, and that was wrong.

    3. The freeze cap matches that boot's TSC gap

    Each MangoHud session next to the gap the kernel measured at that session's boot:

    Session Boot TSC gap at boot Frames ≥ 3 s (ms)
    2026-09-30 13:00 09-30 09:32 3.233 s 10 of 11 in 3240.0 – 3249.0
    2026-10-03 21:02 10-03 19:27 3.341 s 18 of 19 in 3345.8 – 3359.1
    2026-10-04 16:07 10-03 19:27 3.341 s 3349.2, 3349.6, 3357.3
    2026-10-04 18:04, 18:23, 20:48 10-04 17:47 3.209 s 19 of 21 in 3215.8 – 3230.5
    2026-10-05 10:00, 10:58 10-05 05:15 4.801 s 5 of 7 in 4809.3 – 4830.3

    In every session, the longest frames are the boot's TSC gap plus 5–30 ms, i.e. the gap plus the rest of the frame's work. Same boot, same cap. New boot, new cap. The shorter frames (0.5–3 s) are spins where the thread moved off core 0 before core 0 caught up.

    4. The main thread never sets a timeout

    To see what the main thread waits for during a freeze, I wrote a bpftrace probe (freeze-probe, listed in the tools below) that records every main-thread futex / epoll_wait longer than 500 ms:

    • Variant B: epoll_wait called from ThreadMultiWait (libtier0, from Source2Main in libengine2). It waits on two eventfds, with timeout −1, and returns when one of them fires.
    • Variant A: FUTEX_WAIT (private) with no timeout, always on the same address in libtier0's data. In all three cases a GlobPool thread issued FUTEX_WAKE on that exact address when the freeze ended.
    • The spinning thread: in 397 of 430 samples of a 4.8 s freeze it was at ThreadSpin+28 (libtier0), on core 0.

    So the cap was never in the main thread. The main thread waits, without a timeout, for a job whose spin is timed with the TSC.

    The mechanism

    This is inferred from stripped binaries, but it is the only explanation consistent with all of the above:

    1. A thread starts a short timed spin. It takes start = RDTSC on core k, whose counter is ahead.
    2. The scheduler moves it to core 0, whose counter is behind by W seconds.
    3. now − start is now about −W, so the spin continues until core 0's counter passes start + limit. That takes W plus the normal spin.
    4. The main thread waits on that job through ThreadMultiWait / a futex, so the entire frame stops for W seconds. If the thread moves off core 0 earlier, the spin, and the freeze, end early.

    This is why nothing else mattered. The NVIDIA 595 and 610 drivers (open and proprietary kernel modules), Mesa/NVK, -disable_affinity_preferences, VRAM, memory, disk and network all freeze the same way. The input lag reported during freezes (keys and clicks not reaching the game) follows directly, because the main thread is the one that reads input.

    Where the gap comes from: the firmware

    tools/tsc-vs-boottime.c compares each core's absolute TSC with the kernel's boot clock:

    cpu0   tsc − boottime = +16.918 s    (= firmware 7.113 s + loader 9.863 s, from systemd-analyze)
    cpu1–15 tsc − boottime = +19.968 s   (started counting ~3 s before CPU 0)
    

    CPU 0's counter starts with the firmware, and the other cores start counting several seconds earlier, during POST. Across 89 boots the gap follows systemd's firmware time, not the bootloader time:

    Firmware time TSC gap
    4.7 s 2.0 s
    7.4 s 3.2 s
    18.1 s (entering BIOS setup / boot menu) 15.7 s
    21.3 s 20.7 s

    This all happens before Linux starts. The BIOS is already the latest available (HHCN37WW). Unsynchronized TSCs from firmware on AMD Ryzen laptops are a known problem in the kernel tracker (216161, 202525, 215037).

    Why it started with the OS upgrade: amd-pstate preferred cores

    The game ran fine on this same laptop, with the same BIOS, until I reinstalled with a newer Ubuntu (24.04 LTS with kernel 6.8 → 26.04 with kernel 7.0). The TSC defect was almost certainly there before too. What changed is how often the game's threads end up on core 0.

    Since kernel 6.9, amd-pstate's preferred core support ranks the cores, and the scheduler packs work onto the highest-ranked ones. On this CPU the ranking (amd_pstate_prefcore_ranking) puts core 0 at the top: cpu0/1 and cpu6/7 at 196, the rest from 191 down to 166. In other words, the kernel prefers exactly the core whose TSC is wrong. Kernel 6.8 didn't have this.

    I booted the same kernel with amd_prefcore=disable, which turns the ranking off and changes nothing else:

    Session Kernel option Length Frames ≥ 0.5 s ≥ 1 s ≥ 3 s
    2026-10-04 20:48 default (prefcore on) 40.6 min 53 (78/h) 28 12
    2026-10-05 14:33 amd_prefcore=disable 30.0 min 2 (836 and 567 ms, at match start and game exit) 0 0

    At the old rate, 30 minutes would have given about 20 frames of 1 s or more. There were none. Note that the share of busy game-thread samples on cpu0 only fell from 7.7% to 4.6% (data/cpu-placement-prefcore.txt), so time spent on core 0 is not the whole story. A freeze needs a thread to move onto core 0 in the middle of a spin. My reading is that preferred-core packing does exactly that, actively migrating running threads to the top-ranked idle CPU. Without the ranking, those mid-spin moves practically stop.

    Suggestion for Valve

    The defect is in the platform, so I'm closing this issue. Still, Dota 2 could tolerate it cheaply, and every machine with this kind of firmware would stop freezing:

    • Time spin-waits with clock_gettime(CLOCK_MONOTONIC) (vDSO) instead of raw RDTSC. Or, if RDTSC stays, use RDTSCP and restart the timer whenever TSC_AUX (the CPU number) changes between start and now.
    • Treat a negative elapsed time as "limit reached" (or restart the timer) rather than "keep spinning".
    • Check the kernel's verdict: when /sys/devices/system/clocksource/clocksource0/current_clocksource isn't tsc, the kernel has found the TSC unreliable on this machine.
    If you have the same freezes
    1. Run journalctl -k -b | grep "TSC warp". If it prints a line, convert the cycles to seconds (divide by the MHz in tsc: Detected … MHz, times 10⁶) and compare with your longest freezes in MangoHud. If they match, it's this.
    2. Check whether the kernel prefers the bad core: cat /sys/devices/system/cpu/amd_pstate/prefcore and grep . /sys/devices/system/cpu/cpu*/cpufreq/amd_pstate_prefcore_ranking. If prefcore is enabled and the out-of-sync core is ranked at the top, that is the combination described above.
    3. Workaround that fixed it here: boot with amd_prefcore=disable. To make it permanent, add it to GRUB_CMDLINE_LINUX_DEFAULT (e.g. in a file under /etc/default/grub.d/) and run update-grub. All cores stay in use. You only lose the scheduler's preference for the fastest-boosting cores.
    4. Stronger alternative: keep the game's threads off the bad core entirely. taskset doesn't help, because the game resets its own affinity. A cpuset does hold, for example sudo systemctl set-property --runtime user.slice AllowedCPUs=1-15 (lasts until reboot). This costs one logical CPU.
    Corrections to my earlier comments
    • "A fixed timeout of ~3.2 s" / "a condition set late or never": there is no fixed timeout. The cap is that boot's TSC gap, and it was 4.8 s on a later boot.
    • "Core 0 is just the scheduler's preferred core": core 0 is the core with the out-of-sync TSC.
    • "The ~130 ms shift in the cap comes from the proprietary kernel module": switching modules required a reboot, and the new boot had a different gap (3.341 → 3.209 s). The driver had nothing to do with it.
    Tools used in this investigation
    Tool What it contributed
    monitor (monitor all -f pid:…) GPU, per-process VRAM and disk every 500 ms, used to rule out the GPU, VRAM and disk
    monitor sys collector CPU, memory, swap, PSI, and every game thread's state, wchan, user/system time, last CPU and affinity. It found the single spinning thread on core 0, the A/B/C variants, and that taskset was ignored
    monitor -P + tools/perf-window.sh perf record call graphs, sliced per freeze window. They found ThreadSpin ← libanimationsystem in the original report
    monitor nouveau backend VRAM on nouveau + NVK, used for the Mesa/NVK session
    GameMode hook (local script) starts the monitor attached to the game's PID on every launch, so every session was recorded
    MangoHud per-frame log exact freeze lengths, which led to the hard cap and then to the TSC gap
    freeze-probe (probe/ in the monitor repository) bpftrace on the main thread: requested timeouts, ThreadMultiWait/eventfd waits, the FUTEX_WAKE on the same address, 99 Hz samples of the spinning thread
    tsc-per-cpu.c, tsc-vs-boottime.c, warp-per-boot.sh (attached) per-core TSC offsets, when each core started counting, and the gap and firmware time for every boot

    Attached: dota2-linux-freeze-3558-2026-10-05-root-cause.zip: the three TSC tools, the gap and firmware time for all 89 boots, the freeze-cap vs gap table, today's per-core measurements and the bpftrace probe log, with a README.txt.

    Thank you, Valve, for the native Linux client and for keeping this tracker open. This turned out not to be a bug in your code, but a small change in how the spin measures time would spare everyone with this firmware these freezes.

    — @rattones

    dota2-linux-freeze-3558-2026-10-05-root-cause.zip

  8. rattones commented on Oct 5, 2026

    @rattones
    Author

    The tools behind this investigation, and what each one contributed

    This issue went through several wrong hypotheses before reaching the TSC answer. Each step needed a measurement the previous tools couldn't take, so new tools were written along the way. This post lists them in the order they came in, what each measures, and what it ruled in or out. The general-purpose ones are in rattones/monitor (bash only, no Python). The TSC utilities are in the zip attached to the closing comment.

    1. monitor: GPU, VRAM and disk (repository)
    monitor all -f pid:$(pidof dota2)

    Samples every 500 ms into CSVs: GPU utilization, clocks, temperature and power, VRAM total and per process, and disk throughput and IOPS.

    • Role: the first hypothesis was VRAM exhaustion on a 4 GB card. The CSVs showed VRAM peaking at ~60% with over 1 GB free, and the GPU dropping to 0% during every freeze. That ruled out VRAM, disk and the GPU itself, and showed the stall happened before any work reached the GPU.
    • It also gave the first freeze detector, "GPU falls from ≥ 20% to ≤ 5% for ≥ 1 s", which I later checked against MangoHud.
    2. GameMode hook (local script, not published)

    gamemode-start.sh / gamemode-end.sh plus gamemode-monitor.sh, run by GameMode on every launch. The hook attaches monitor to the game's PID, with perf added when it is enabled, and stops it when the game exits. It also sets the power profile and pauses a background network speed test during play.

    • Role: every match was recorded without having to remember to start anything. Comparing many sessions was only possible because of this.
    3. monitor sys collector: CPU, memory and every thread

    Adds two CSVs. -sys.csv has total and per-core CPU, memory, swap, PSI (CPU, memory, I/O pressure), and the game's CPU, thread count, D-state threads and major faults. -threads.csv has every active game thread: state, wchan, CPU %, user/system split, last CPU and affinity.

    • Role: this is where the real signature appeared. During each freeze one thread (GlobPool/N, sometimes the main thread or VKRenderThread) ran at 100% user time on core 0, while the main thread slept in futex_do_wait or ep_poll, every other thread was idle, and the system sat at ~7% CPU with no pressure. That ruled out CPU contention, memory pressure and swap, and gave the A/B/C variants.
    • The last_cpu and affinity columns later showed that taskset and -disable_affinity_preferences were ignored (affinity stayed 0-15), and that the spinner was always on core 0.
    4. monitor -P + tools/perf-window.sh: where the thread spins

    -P runs perf record -g on the game's PIDs alongside the CSVs. tools/perf-window.sh <log> HH:MM:SS HH:MM:SS [thread] cuts the samples to a freeze window and breaks them down per thread, per library, and by the first frame outside the kernel.

    • Role: it located the spin in user space, in CThread::ThreadProc → libscenesystem → libclient → libanimationsystem → ThreadSpin (libtier0), with no driver library in the stack. That moved the investigation from "driver/system" to "the game's own waiting code".
    5. monitor nouveau backend: an independent graphics stack

    Reads VRAM through vulkaninfo (VK_EXT_memory_budget) when the machine runs nouveau + NVK, where nvidia-smi doesn't exist.

    • Role: it allowed a full session on Mesa/NVK, which shares no code with the NVIDIA driver. The same freeze, on the same core, ruled out the graphics driver. NVIDIA 595 and 610, with the open and proprietary modules, were tested the same way.
    6. MangoHud per-frame logs (MangoHud)

    A per-frame frametime log (log_interval=0), analyzed with small awk scripts: counts per hour, percentiles, and the list of frames ≥ 0.5 s with timestamps.

    • Role: 500 ms sampling can't measure a freeze's length precisely, and MangoHud can. It showed the hard cap: in each session the longest frames clustered within a few ms of each other (3240–3249 ms, later 3346–3359 ms). The cap moved between sessions, and that turned out to be the decisive clue.
    7. freeze-probe: what the main thread waits for (probe/)
    sudo ./probe/freeze-probe.sh --check   # validate on the running kernel
    sudo ./probe/freeze-probe.sh           # waits for dota2, exits with it

    A bpftrace program and a bash launcher, run under sudo and separate from the monitor. For every main-thread wait longer than a threshold it records:

    • the timeout the thread asked the kernel for, and the return value;

    • the user stack at the moment it went to sleep;

    • a FUTEX_WAKE on the same address from another game thread;

    • the epoll event that fired, mapped to its file descriptor through fdinfo;

    • 99 Hz stack samples of every game thread while the main thread is stopped.

    • Role: the main thread never sets a timeout (epoll_wait −1 in ThreadMultiWait, FUTEX_WAIT without timeout). So the cap was not the main thread's: it had to be in how the spinner measures time. The spinner sat at ThreadSpin+28 on core 0 in 397 of 430 samples.

    • Note: the first version kept its state in scalar bpftrace maps that other CPUs read stale, which produced false wake-ups and weighed on the game. Version 2 keys all state explicitly and resolves [unknown] frames into library+offset from a snapshot of /proc/PID/maps.

    8. The TSC utilities: the answer (attached to the closing comment)
    Tool What it does What it showed
    warp-per-boot.sh For every boot in the journal: the TSC gap the kernel measured (cycles and seconds), the clocksource it fell back to, and systemd's firmware/loader times The gap is on every one of 89 boots (2.0–20.7 s) and equals that boot's freeze cap. It follows the firmware time, not the bootloader
    tsc-per-cpu.c Pins to each CPU and reads RDTSCP between two reads of the global clock (CLOCK_MONOTONIC_RAW, HPET here), keeping the tightest of 200 pairs Only CPU 0 is off. CPUs 1–15 agree to under a millisecond
    tsc-vs-boottime.c Absolute TSC of each CPU compared with CLOCK_BOOTTIME CPU 0's counter starts with the firmware, and the others start seconds earlier, so the defect is in the firmware
    9. Kernel interfaces, no new code
    • /sys/devices/system/cpu/cpu*/cpufreq/amd_pstate_prefcore_ranking: the amd-pstate preferred-core ranking (kernel ≥ 6.9). It ranks core 0 at the top, so the scheduler favors the one core with the wrong TSC.
    • amd_prefcore=disable on the kernel command line, set through a file in /etc/default/grub.d/, turns the ranking off. Before: 78 freeze frames per hour. After: 0 frames ≥ 1 s in 30 minutes.
    How the pieces fit

    GPU at 0% (1) → one thread spinning on core 0 while the main thread waits (3) → the spin is ThreadSpin in the game's code (4) → not the driver, even on Mesa (5) → each session has its own hard cap (6) → the main thread never sets a timeout, so the cap comes from the spinner's clock (7) → the cap equals that boot's TSC gap, which only CPU 0 has (8) → kernel 7.0's preferred-core ranking sends threads to CPU 0, and disabling it removes the freezes (9).

    Everything except the GameMode hook is public. If you suspect the same problem on your machine, steps 6 and 8 are enough to confirm it: one MangoHud log and warp-per-boot.sh.

    — @rattones

  9. rattones commented on Oct 6, 2026

    @rattones
    Author

    The GameMode hooks are public too, and a correction about amd_prefcore=disable

    To make the setup behind this investigation easier to reproduce, I have also published the GameMode scripts I used: rattones/gamemode-hooks (MIT, README in English and Portuguese).

    They are what recorded every session in this issue. With gamemoderun %command% in the launch options, the hook starts monitor attached to the game's PID when it opens, and stops it when the game exits. No session had to be started by hand.

    On the same open/close events the hooks also apply, and then restore, a few common tweaks:

    • the platform power profile (ACPI platform_profile) set to performance;
    • NVIDIA PowerMizer set to "prefer maximum performance";
    • on X11 with more than one monitor, only the game's monitor left on;
    • user services you choose paused while the game runs;
    • a notification when free VRAM gets low.

    Each tweak checks for the feature it needs and is skipped where it is missing. The installer detects the hardware and asks about anything that isn't clear:

    git clone https://github.com/rattones/gamemode-hooks.git
    cd gamemode-hooks
    sudo ./install.sh --check   # show what was detected and what would change
    sudo ./install.sh           # install; it asks about anything unclear

    sudo is needed only to add your user to the gamemode group, which Ubuntu's polkit rule requires for GameMode to change the CPU governor. The files go to your own home, owned by you.

    To be clear: these hooks don't fix or cause the freezes. The root cause is CPU 0's TSC, as explained in the closing comment above. They are just the harness that made recording dozens of sessions effortless, and they may help anyone collecting comparable data on their own machine.

    Correction: amd_prefcore=disable reduces the freezes, it doesn't remove them

    In the closing comment I wrote that booting with amd_prefcore=disable "made the freezes disappear". That came from a single 30-minute session, and a longer one shows it was partly luck. To compare the same thing across the three sessions, the table counts the moments where GPU utilization fell to 0% for 1 s or more, from the monitor's 500 ms samples. The 2026-10-06 session has no MangoHud log.

    Session amd_prefcore TSC gap at boot GPU active Stops ≥ 1 s Stops ≥ 3 s
    2026-10-04 20:48 enabled (default) 3.209 s 37.2 min 36 (58/h) 12
    2026-10-05 14:33 disable 3.190 s 29.2 min 1, at game exit 0
    2026-10-06 08:16 disable 3.148 s 40.7 min 7 (10/h) 2 (3.5 and 3.0 s)

    Six of the seven stops on 2026-10-06 have the same signature as before: a thread spinning on core 0, either a GlobPool/N worker with the main thread waiting in futex_do_wait or ep_poll, or the main thread itself. In one of them the main thread moved from cpu1 to cpu0, spun at 100% and stopped spinning as soon as the scheduler moved it to cpu12. That is the TSC mechanism in a single trace. The seventh stop (1.0 s, a GlobPool worker on cpu1) is something else.

    So disabling preferred cores cuts the freezes by roughly 80–85%, because the scheduler stops packing work onto core 0. Threads still land on core 0 now and then (5.3% of busy game-thread samples in this session), and when one does in the middle of a spin, the freeze comes back with the same cap as that boot's TSC gap.

    The rest of the closing comment stands. The cause is still CPU 0's TSC, and amd_prefcore=disable is still the most effective workaround that keeps every core in use. Removing the freezes completely would take one of three things:

    • keeping the game off core 0 (a cpuset, which costs one logical CPU);
    • syncing CPU 0's TSC with the other cores at boot;
    • on Valve's side, timing the spin-wait with CLOCK_MONOTONIC instead of raw RDTSC, as suggested in the closing comment.

    — @rattones

  10. rattones commented on Oct 8, 2026

    @rattones
    Author

    Update: syncing CPU 0's TSC at boot removes the freezes here (tsc-sync)

    This is probably my last update. It is the best fix so far, and possibly the definitive one for this machine.

    To recap: the freezes come from CPU 0's TSC, which the firmware brings up a few seconds behind the other cores. The spin-wait in ThreadSpin is timed with RDTSC, so a thread that moves to core 0 in the middle of a wait spins for the whole gap. Booting with amd_prefcore=disable cut the freezes by about 85%, because the scheduler stopped favoring core 0. It didn't remove them, since threads still land on core 0 now and then.

    The remaining step was to remove the gap itself. This CPU has no TSC_ADJUST, so the kernel can't do it: it only marks the TSC unstable and switches to HPET. I wrote a small tool that does it at boot: rattones/tsc-sync (MIT).

    What it does
    • Measures each CPU's TSC against the majority group, directly in cycles. It reads the reference CPU, the target CPU and the reference again, each read bracketed by CLOCK_MONOTONIC_RAW, and interpolates. Its measurement of the gap matches the kernel's boot-time "TSC warp" figure to within a few dozen cycles.
    • Fixes only the CPUs outside the majority, by writing their TSC (MSR 0x10, through /dev/cpu/N/msr). It then measures again and refines until the gap is within 50 µs.
    • It runs from a systemd service early at boot, before any user program, and again on resume from suspend. It is installed disabled by default, and tsc-sync alone (no root) only measures.
    Results
    Boot CPU 0 behind by After the fix
    1 3.158645 s (kernel: 3.158 s) 6.0 µs, in one pass
    2 3.971967 s 4.5 µs, in one pass

    Five hours after the first boot, the TSCs were still in sync. With the fix active (and amd_prefcore=disable), a 71-minute session had no stop of 0.5 s or more. That count comes from the monitor's 500 ms GPU samples, since there was no MangoHud log in that session. For comparison, on the same measure:

    Setup Stops ≥ 1 s
    no workaround ~58 per hour
    amd_prefcore=disable alone ~8 per hour (15 of 17 on core 0)
    amd_prefcore=disable + tsc-sync 0 in 71 min

    An earlier 28-minute session with the fix had two stops, neither involving core 0: one while the match was loading and one as the game was closing.

    The boot log

    This is the journal of the second boot (journalctl -b -o short-monotonic -k plus -u tsc-sync.service), with the 14 "ok" lines for CPUs 2–15 omitted. tsc-sync prints in the system language, Portuguese here: "ATRASADA" means behind, and "sincronizada (resta …)" means in sync (… left).

    [    1.179238] kernel: Measured 12686465901 cycles TSC warp between CPUs, turning off TSC clock.
    [    1.179254] kernel: tsc: Marking TSC unstable due to check_tsc_sync_source failed
    [    1.205692] kernel: clocksource: Switched to clocksource hpet
    [    6.722998] systemd[1]: Starting tsc-sync.service - Sincroniza o TSC das CPUs que o firmware deixou fora de sincronia...
    [    7.073863] tsc-sync[557]: TSC a 3194.001 MHz; tolerancia 50 us; incerteza da medicao ~1.8 us
    [    7.073863] tsc-sync[557]: referencia: CPU 1 (grupo da maioria)
    [    7.073863] tsc-sync[557]:   CPU  0   -3.971967 s    ATRASADA
    [    7.073863] tsc-sync[557]:   CPU  1        +0.0 us   ok
    [    7.083022] kernel: msr: Write to unrecognized MSR 0x10 by tsc-sync (pid: 557), tainting CPU_OUT_OF_SPEC.
    [    7.091297] tsc-sync[557]: CPU 0: sincronizada (resta +4.512 us)
    [    7.091842] systemd[1]: Finished tsc-sync.service - Sincroniza o TSC das CPUs que o firmware deixou fora de sincronia.
    

    The kernel's 12,686,465,901 cycles at 3193.966 MHz are 3.972 s, the same gap tsc-sync measured on its own. The whole service takes 0.37 s and finishes 7.1 s after the kernel starts, before the desktop session. The first boot looked the same: the kernel reported 10,088,746,727 cycles (3.16 s), tsc-sync measured 3.158645 s, and one write left 6.0 µs.

    Two hours later, measured again (with TSC_SYNC_LANG=en for this post):

    $ TSC_SYNC_LANG=en tsc-sync
    TSC at 3194.004 MHz; tolerance 50 us; measurement uncertainty ~1.4 us
    reference: CPU 0 (majority group)
      CPU  0        -4.5 us   ok
      CPU  1        -0.0 us   ok
      CPU  2        -0.0 us   ok
      ...
      CPU 15        +0.0 us   ok
    result: in sync
    
    The tool

    rattones/tsc-sync is a small C program (libc only) plus two systemd units, with a README in English and Portuguese.

    git clone https://github.com/rattones/tsc-sync.git && cd tsc-sync
    make check                     # build, check the catalogs, measure, show the dry run (no root)
    tsc-sync                       # measure only, no root: which CPU is off, and by how much
    sudo tsc-sync sync --dry-run   # what it would write
    sudo tsc-sync sync             # write once, by hand, then run tsc-sync again
    sudo ./install.sh              # install the binary and the units, enabled: nothing
    sudo ./install.sh --enable     # run at boot and on resume from suspend
    sudo ./install.sh --disable    # stop running at boot (the current fix lasts until reboot)
    sudo ./install.sh --uninstall  # remove everything
    Exit code Meaning
    0 in sync, or synced
    1 error: not root, /dev/cpu/N/msr missing, write refused
    2 invalid usage
    3 out of sync (measure and --dry-run)
    4 wrote, but some CPU did not converge

    How it works, in more detail than above:

    • Measurement without the TSC frequency. Converting seconds to cycles would turn a few ppm of frequency error into tens of microseconds on a 3–4 s gap. So each comparison reads the reference CPU, the target CPU and the reference again, keeps the narrowest of 64 attempts for each read, and interpolates the two reference reads at the instant of the target's read. That gives the gap directly in cycles. 15 comparisons, median.
    • Reference = the majority. On this laptop CPUs 1–15 agree with each other to under 1 µs, so only CPU 0 gets written.
    • Write and verify. Pinned to the lagging CPU, it reads its own TSC and writes that value plus the gap plus the measured cost of the write. Then it measures again and refines, up to 6 passes, and only reports success within the tolerance.
    • Messages in English or Portuguese, chosen by TSC_SYNC_LANG, LC_ALL, LC_MESSAGES or LANG, with the same i18n pattern as monitor.
    Caveats
    • It is one machine. Resume from suspend has not been tested yet.
    • It writes a CPU register, which Linux itself avoids on AMD. The msr driver logs Write to unrecognized MSR 0x10 ... tainting CPU_OUT_OF_SPEC on every boot where it writes. It needs kernel lockdown off (Secure Boot usually turns it on).
    • It is meant for CPUs without TSC_ADJUST, like these Ryzen laptops. Where TSC_ADJUST exists (Intel), the kernel already keeps the TSCs in sync and would undo such a write.
    • Undoing it is disabling the service and rebooting.
    If you have the same freezes
    1. journalctl -k -b | grep "TSC warp": if the kernel reports a warp on your machine, compare it with your longest freezes.
    2. tsc-sync (no root) shows which CPU is off and by how much.
    3. amd_prefcore=disable is the low-risk first step. tsc-sync is the one that removed the freezes here.
    For Valve

    The real fix for everyone still belongs in the game. A user should not need to write CPU registers to play. Timing the spin-wait with CLOCK_MONOTONIC, or restarting the timer when RDTSCP reports a CPU change, would make Dota 2 immune to this firmware defect on every affected machine.

    Thank you to everyone who followed this thread.

    — @rattones

  11. dulcean commented on Oct 25, 2026

    @dulcean
  12. rattones commented on Oct 27, 2026

    @rattones
    Author

    19. https://github.com/dulcean/Dota2-TSC-Fix

    https://github.com/rattones/tsc-sync

    tsc-sync is a low-level utility designed to resolve Time Stamp Counter (TSC) drift on x86 multi-core CPUs. By directly targeting Core 0, it resets its hardware timestamp MSR to align seamlessly with all other cores. This eliminates micro-stutters, timing discrepancies, and performance losses caused by asynchronous core clocks.

    "This is my solution; it directly targets the Core 0 synchronization issue by resetting it so that all cores share the exact same timestamp."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions