| @@ -285,12 +285,13 @@ Release builds; best of 7 runs, interleaved with `main` (f2b02b7) on the same ma |
| 285 | 285 | - **A possible small regression:** the virtual-time timer benchmark is 2–5% slower on 8 and 22 threads, in three separate runs. Its cause is not established. One guess: the control lock serialised timer pushes, which also spaced out the actors' other shared accesses (the actor table, the run queues). |
| 286 | 286 | |
| 287 | 287 | ### ThreadSanitizer |
| 288 | | −- **`scripts/tsan.sh`** runs ThreadSanitizer on the runtime's unit tests, then on native programs: every `tests/run` program on 4 threads, and the stress test, the message ring and the timer benchmark on 8. It fails on any report, a wrong exit status or a leak. CI runs it with `TILC_CI_TSAN=1`; it is opt-in because it needs a nightly toolchain with `rust-src`. It takes about a minute, plus a few minutes the first time, to build the instrumented standard library. |
| 288 | +- **`scripts/tsan.sh`** runs ThreadSanitizer on the runtime's unit tests, then on native programs: every `tests/run` program on 4 threads (but one, see below), and the stress test, the message ring and the timer benchmark on 8. It fails on any report, a wrong exit status or a leak. CI runs it with `TILC_CI_TSAN=1`; it is opt-in because it needs a nightly toolchain with `rust-src`. It takes about a minute, plus a few minutes the first time, to build the instrumented standard library. |
| 289 | 289 | - **What it needs:** |
| 290 | 290 | - the runtime and Rust's standard library instrumented: nightly `-Zsanitizer=thread -Zbuild-std`; |
| 291 | 291 | - the runtime built without mimalloc, whose C code is not instrumented; |
| 292 | 292 | - fiber switches announced to TSan (`--cfg tilrt_tsan`, ADR 0011 note); |
| 293 | 293 | - generated C built with `-fsanitize=thread` but without TSan's function entry/exit hooks (`-mllvm -tsan-instrument-func-entry-exit=0`). The hooks do not pair up across `musttail` calls, so an endless tail-recursive loop (`tests/run/process.til`'s `spin`) overflowed TSan's shadow call stack. Memory accesses are still checked; reports show fewer C frames. |
| 294 | +- **A limit: TSan's shadow call stack holds 64Ki frames per fiber, without a bounds check.** Recursion deeper than that through instrumented runtime frames silently corrupts TSan's own memory. It showed as CHECK failures in TSan's allocator, thousands of bogus use-after-free reports, or a hang, at random, in `tests/run/generators.til`: there, `x + resume(())` nests 20,000 handler resumptions, about 80,000 runtime frames. The script skips that program, with the reason; ASan and the differential tests still run it. Turning off the hooks for the runtime too would remove the limit, but reports would lose their stack traces. |
| 294 | 295 | - **Findings:** no race in the runtime or in generated code. One report is suppressed (`scripts/tsan.supp`, with its reason): crossbeam-deque's stealer reads a slot speculatively and discards the value when its compare-and-swap fails, which is the deque's design. |
| 295 | 296 | - **Checked:** a deliberate data race in a runtime unit test is reported, so a clean run means something. |
| 296 | 297 | - **Cost under TSan:** programs run about 25–40× slower than release builds (the runtime is a debug build there). The 100k-actor stress test takes about 10 s on 8 threads. |