@@ -113,7 +113,6 @@ static u64 suspend_start;
113
113
114
114
/*
115
115
* Threshold: 0.0312s, when doubled: 0.0625s.
116
- * Also a default for cs->uncertainty_margin when registering clocks.
117
116
*/
118
117
#define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 5)
119
118
@@ -125,13 +124,27 @@ static u64 suspend_start;
125
124
*
126
125
* The default of 500 parts per million is based on NTP's limits.
127
126
* If a clocksource is good enough for NTP, it is good enough for us!
127
+ *
128
+ * In other words, by default, even if a clocksource is extremely
129
+ * precise (for example, with a sub-nanosecond period), the maximum
130
+ * permissible skew between the clocksource watchdog and the clocksource
131
+ * under test is not permitted to go below the 500ppm minimum defined
132
+ * by MAX_SKEW_USEC. This 500ppm minimum may be overridden using the
133
+ * CLOCKSOURCE_WATCHDOG_MAX_SKEW_US Kconfig option.
128
134
*/
129
135
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US
130
136
#define MAX_SKEW_USEC CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US
131
137
#else
132
138
#define MAX_SKEW_USEC (125 * WATCHDOG_INTERVAL / HZ)
133
139
#endif
134
140
141
+ /*
142
+ * Default for maximum permissible skew when cs->uncertainty_margin is
143
+ * not specified, and the lower bound even when cs->uncertainty_margin
144
+ * is specified. This is also the default that is used when registering
145
+ * clocks with unspecifed cs->uncertainty_margin, so this macro is used
146
+ * even in CONFIG_CLOCKSOURCE_WATCHDOG=n kernels.
147
+ */
135
148
#define WATCHDOG_MAX_SKEW (MAX_SKEW_USEC * NSEC_PER_USEC)
136
149
137
150
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG
@@ -231,6 +244,7 @@ enum wd_read_status {
231
244
232
245
static enum wd_read_status cs_watchdog_read (struct clocksource * cs , u64 * csnow , u64 * wdnow )
233
246
{
247
+ int64_t md = 2 * watchdog -> uncertainty_margin ;
234
248
unsigned int nretries , max_retries ;
235
249
int64_t wd_delay , wd_seq_delay ;
236
250
u64 wd_end , wd_end2 ;
@@ -245,7 +259,7 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
245
259
local_irq_enable ();
246
260
247
261
wd_delay = cycles_to_nsec_safe (watchdog , * wdnow , wd_end );
248
- if (wd_delay <= WATCHDOG_MAX_SKEW ) {
262
+ if (wd_delay <= md + cs -> uncertainty_margin ) {
249
263
if (nretries > 1 && nretries >= max_retries ) {
250
264
pr_warn ("timekeeping watchdog on CPU%d: %s retried %d times before success\n" ,
251
265
smp_processor_id (), watchdog -> name , nretries );
@@ -258,12 +272,12 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
258
272
* there is too much external interferences that cause
259
273
* significant delay in reading both clocksource and watchdog.
260
274
*
261
- * If consecutive WD read-back delay > WATCHDOG_MAX_SKEW/2,
262
- * report system busy, reinit the watchdog and skip the current
275
+ * If consecutive WD read-back delay > md, report
276
+ * system busy, reinit the watchdog and skip the current
263
277
* watchdog test.
264
278
*/
265
279
wd_seq_delay = cycles_to_nsec_safe (watchdog , wd_end , wd_end2 );
266
- if (wd_seq_delay > WATCHDOG_MAX_SKEW / 2 )
280
+ if (wd_seq_delay > md )
267
281
goto skip_test ;
268
282
}
269
283
@@ -1146,14 +1160,19 @@ void __clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq
1146
1160
}
1147
1161
1148
1162
/*
1149
- * If the uncertainty margin is not specified, calculate it.
1150
- * If both scale and freq are non-zero, calculate the clock
1151
- * period, but bound below at 2*WATCHDOG_MAX_SKEW. However,
1152
- * if either of scale or freq is zero, be very conservative and
1153
- * take the tens-of-milliseconds WATCHDOG_THRESHOLD value for the
1154
- * uncertainty margin. Allow stupidly small uncertainty margins
1155
- * to be specified by the caller for testing purposes, but warn
1156
- * to discourage production use of this capability.
1163
+ * If the uncertainty margin is not specified, calculate it. If
1164
+ * both scale and freq are non-zero, calculate the clock period, but
1165
+ * bound below at 2*WATCHDOG_MAX_SKEW, that is, 500ppm by default.
1166
+ * However, if either of scale or freq is zero, be very conservative
1167
+ * and take the tens-of-milliseconds WATCHDOG_THRESHOLD value
1168
+ * for the uncertainty margin. Allow stupidly small uncertainty
1169
+ * margins to be specified by the caller for testing purposes,
1170
+ * but warn to discourage production use of this capability.
1171
+ *
1172
+ * Bottom line: The sum of the uncertainty margins of the
1173
+ * watchdog clocksource and the clocksource under test will be at
1174
+ * least 500ppm by default. For more information, please see the
1175
+ * comment preceding CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US above.
1157
1176
*/
1158
1177
if (scale && freq && !cs -> uncertainty_margin ) {
1159
1178
cs -> uncertainty_margin = NSEC_PER_SEC / (scale * freq );
0 commit comments