Skip to contentSkip to conversation

Clocksource:Avoid misjudgment of clocksource

PATCH New yanghui 1 participant 1 message Oct 9, 2021 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore

yanghui

author
#0 lore raw

PATCH v2 1/1 Clocksource:Avoid misjudgment of clocksource

Function clocksource_watchdog() is executed every WATCHDOG_INTERVAL(0.5s) by Timer. But sometimes system is very busy and the Timer cannot be executed in 0.5sec. For example,if clocksource_watchdog be executed after 10sec, the calculated value of abs(cs_nsec - wd_nsec) will be magnified. Then the current clocksource will be misjudged as unstable. So we add conditions to prevent the clocksource from being misjudged.

---
Change in v2:
Remove the check on cs_nsec.

 kernel/time/clocksource.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/time/clocksource.c +4 -1
index b8a14d2fb5ba..c35bb708e030 100644
@@ -136,8 +136,10 @@ static void __clocksource_change_rating(struct clocksource *cs, int rating);
 
 /*
  * Interval: 0.5sec.
+ * MaxInterval: 1s.
  */
 #define WATCHDOG_INTERVAL (HZ >> 1)
+#define WATCHDOG_MAX_INTERVAL_NS (NSEC_PER_SEC)
 
 static void clocksource_watchdog_work(struct work_struct *work)
 {
@@ -404,7 +406,8 @@ static void clocksource_watchdog(struct timer_list *unused)
 
 		/* Check the deviation from the watchdog clocksource. */
 		md = cs->uncertainty_margin + watchdog->uncertainty_margin;
-		if (abs(cs_nsec - wd_nsec) > md) {
+		if ((abs(cs_nsec - wd_nsec) > md) &&
+		    wd_nsec < WATCHDOG_MAX_INTERVAL_NS) {
 			pr_warn("timekeeping watchdog on CPU%d: Marking clocksource '%s' as unstable because the skew is too large:\n",
 				smp_processor_id(), cs->name);
 			pr_warn("                      '%s' wd_nsec: %lld wd_now: %llx wd_last: %llx mask: %llx\n",
Signature · 1 line
2.20.1