Commit d48730f
Cranelift: robustify timing infrastructure against mis-use and/or system clock bugs. (#13273)
* Cranelift: robustify timing infrastructure against mis-use and/or system clock bugs.
In #12692, it was observed that the computation of time spent in
nested timing spans, minus child time, was underflowing.
Correct operation of the handling of nested spans depends on the
invariant that the accumulated time for child spans is less than or
equal to a parent span once timing is completed. This property should
hold as long as the system clock is monotonic, and as long as timing
tokens are dropped in-order, so that the elapsed time of a parent
truly is computed after the elapsed time of a child ends.
The timing state may also temporarily violate this invariant whenever
a token is pending (still on stack and timing): the child time of any
completed child spans will be counted, but the parent has not yet
been. Hence, taking a snapshot of the state and computing "parent
minus children" on that snapshot may observe cases that yield
underflow.
This PR makes the infrastructure more robust along a few different
dimensions:
- It hardens the clock source we use to have a locally-ensured
guarantee of monotonicity, since we rely on this for logical
correctness. In particular, for each thread (since timing spans never
move between threads), we track the last `Instant` that was used by
the timing infrastructure, and use that value (zero time passed) if
the system clock moves backward.
- It hardens the assert about pass-timing token drop order from a
`debug_assert` to an `assert`. If this invariant is being violated,
we want to know about it noisily, rather than observing a
subtraction underflow or other inconsistency later.
- It adds an assert in `take_current()` to ensure that a snapshot is
never taken when any pass timing is in progress.
This should address any theoretically possible sources of #12692, as
far as I can tell.
(cherry picked from commit 2f8644f)
* Update releases.md
* Fix timing information in cranelift
A typo in #12709 accidentally led to all passes clocking in at 0ns. Swap
the order of arguments to get true timing information.
(cherry picked from commit 8b664c3)
* Fix releases update
---------
Co-authored-by: Chris Fallin <chris@cfallin.org>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>1 parent 332e8ad commit d48730f
2 files changed
Lines changed: 46 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
1 | 13 | | |
2 | 14 | | |
3 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
223 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
224 | 233 | | |
225 | 234 | | |
226 | 235 | | |
227 | 236 | | |
228 | 237 | | |
229 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
230 | 260 | | |
231 | 261 | | |
232 | 262 | | |
233 | 263 | | |
234 | 264 | | |
235 | 265 | | |
236 | 266 | | |
237 | | - | |
| 267 | + | |
238 | 268 | | |
239 | 269 | | |
240 | 270 | | |
| |||
260 | 290 | | |
261 | 291 | | |
262 | 292 | | |
263 | | - | |
| 293 | + | |
| 294 | + | |
264 | 295 | | |
265 | 296 | | |
266 | | - | |
| 297 | + | |
267 | 298 | | |
268 | 299 | | |
269 | 300 | | |
| |||
0 commit comments