History

clocksource: Make negative motion detection more robust

Guenter reported boot stalls on a emulated ARM 32-bit platform, which has a 24-bit wide clocksource. It turns out that the calculated maximal idle time, which limits idle sleeps to prevent clocksource wrap arounds, is close to the point where the negative motion detection triggers. max_idle_ns: 597268854 ns negative motion tripping point: 671088640 ns If the idle wakeup is delayed beyond that point, the clocksource advances far enough to trigger the negative motion detection. This prevents the clock to advance and in the worst case the system stalls completely if the consecutive sleeps based on the stale clock are delayed as well. Cure this by calculating a more robust cut-off value for negative motion, which covers 87.5% of the actual clocksource counter width. Compare the delta against this value to catch negative motion. This is specifically for clock sources with a small counter width as their wrap around time is close to the half counter width. For clock sources with wide counters this is not a problem because the maximum idle time is far from the half counter width due to the math overflow protection constraints. For the case at hand this results in a tripping point of 1174405120ns. Note, that this cannot prevent issues when the delay exceeds the 87.5% margin, but that's not different from the previous unchecked version which allowed arbitrary time jumps. Systems with small counter width are prone to invalid results, but this problem is unlikely to be seen on real hardware. If such a system completely stalls for more than half a second, then there are other more urgent problems than the counter wrapping around.

Thomas Gleixner committed 1 year ago

Commit 76031d91 parent e70140b4 files · +20 −7Browse files

Showing the changes to include/linux (1 of 4 files). Show all

Unified · Split

include/linux/clocksource.h+2−0
@@ -49,6 +49,7 @@ struct module; · 48 unmodified lines
4949 * @archdata: Optional arch-specific data
5050 * @max_cycles: Maximum safe cycle value which won't overflow on
5151 * multiplication
52+ * @max_raw_delta: Maximum safe delta value for negative motion detection
5253 * @name: Pointer to clocksource name
5354 * @list: List head for registration (internal)
5455 * @freq_khz: Clocksource frequency in khz.
@@ -109,6 +110,7 @@ struct clocksource { · 54 unmodified lines
109110 struct arch_clocksource_data archdata;
110111 #endif
111112 u64 max_cycles;
113+ u64 max_raw_delta;
112114 const char *name;
113115 struct list_head list;
114116 u32 freq_khz;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t