Commit fff7036
committed
Fix cumulative drift in periodic timers
Currently, periodic timers allow errors to accumulate because the next
deadline is calculated relative to the current system tick (now +
period). Any latency in the tick handler execution—whether due to
interrupt jitter or system load—permanently shifts the phase of all
future expirations.
Fix the drift by anchoring the timer schedule to an absolute baseline.
A new field, last_expected_fire_tick, is introduced to track the
theoretical expiration time.
When the timer fires, the next deadline is now computed by advancing
this expected time by the period, rather than relying on the actual
execution time. This ensures the timer maintains its long-term
frequency accuracy regardless of short-term scheduling delays.1 parent b4c2d10 commit fff7036
2 files changed
+10
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| |||
305 | 307 | | |
306 | 308 | | |
307 | 309 | | |
| 310 | + | |
308 | 311 | | |
309 | 312 | | |
310 | 313 | | |
| |||
387 | 390 | | |
388 | 391 | | |
389 | 392 | | |
390 | | - | |
| 393 | + | |
| 394 | + | |
391 | 395 | | |
392 | 396 | | |
393 | 397 | | |
| |||
0 commit comments