Skip to contentSkip to conversation

clocksource: Improve cs_watchdog_read()

PATCH In review Heiner Kallweit 2 participants 4 messages Nov 9, 2021 – Nov 10, 2021 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource: Improve cs_watchdog_read()

If max_cswd_read_retries is set to 0 or 1 then the current warning behavior doesn't seem to make too much sense to me.
If set to 0, then we'd warn with each watchdog run.
If set to 1, then we'd warn at the first retry, even though the commit description of db3a34e17433 states that one retry is expected behavior. If printing a message at all in this case, then it should be debug level.

Whilst being at it, move declaration of wd_end and wd_delta into the loop and remove not needed braces.

---
 kernel/time/clocksource.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/time/clocksource.c +3 -3
index f29d1a524..8c0be9c02 100644
@@ -208,10 +208,11 @@ module_param(verify_n_cpus, int, 0644);
 static bool cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
 {
 	unsigned int nretries;
-	u64 wd_end, wd_delta;
 	int64_t wd_delay;
 
 	for (nretries = 0; nretries <= max_cswd_read_retries; nretries++) {
+		u64 wd_end, wd_delta;
+
 		local_irq_disable();
 		*wdnow = watchdog->read(watchdog);
 		*csnow = cs->read(cs);
@@ -222,10 +223,9 @@ static bool cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
 		wd_delay = clocksource_cyc2ns(wd_delta, watchdog->mult,
 					      watchdog->shift);
 		if (wd_delay <= WATCHDOG_MAX_SKEW) {
-			if (nretries > 1 || nretries >= max_cswd_read_retries) {
+			if (nretries > 1)
 				pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before success\n",
 					smp_processor_id(), watchdog->name, nretries);
-			}
 			return true;
 		}
 	}
Signature · 1 line
2.33.1
#1 lore raw
Quoted 7 lines · Heiner Kallweit

If max_cswd_read_retries is set to 0 or 1 then the current warning behavior doesn't seem to make too much sense to me.
If set to 0, then we'd warn with each watchdog run.
If set to 1, then we'd warn at the first retry, even though the commit description of db3a34e17433 states that one retry is expected behavior. If printing a message at all in this case, then it should be debug level.

The behavior for max_cswd_read_retries==1 is exactly what you want when you are checking to see whether or not your system would retry at all for the duration of a given run.

The behavior for max_cswd_read_retries==0 is exactly what you want when you are testing the ability to print that message on a system that will not do a retry in a reasonable period of time.

Or am I missing something here?

Quoted 2 lines

Whilst being at it, move declaration of wd_end and wd_delta into the loop and remove not needed braces.

I am OK with moving those two variables into the "for" loop.

I am personally OK removing the braces, but if I remember correctly, my upstream maintainer asked that I add them due to the statement being split across two lines.

Thanx, Paul

Quoted 37 lines
---
 kernel/time/clocksource.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/time/clocksource.c +3 -3
index f29d1a524..8c0be9c02 100644
@@ -208,10 +208,11 @@ module_param(verify_n_cpus, int, 0644);
 static bool cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
 {
 	unsigned int nretries;
-	u64 wd_end, wd_delta;
 	int64_t wd_delay;
 
 	for (nretries = 0; nretries <= max_cswd_read_retries; nretries++) {
+		u64 wd_end, wd_delta;
+
 		local_irq_disable();
 		*wdnow = watchdog->read(watchdog);
 		*csnow = cs->read(cs);
@@ -222,10 +223,9 @@ static bool cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
 		wd_delay = clocksource_cyc2ns(wd_delta, watchdog->mult,
 					      watchdog->shift);
 		if (wd_delay <= WATCHDOG_MAX_SKEW) {
-			if (nretries > 1 || nretries >= max_cswd_read_retries) {
+			if (nretries > 1)
 				pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before success\n",
 					smp_processor_id(), watchdog->name, nretries);
-			}
 			return true;
 		}
 	}
Signature · 1 line
2.33.1
#2 lore raw
Quoted 13 lines · Paul E. McKenney
Quoted 7 lines · Heiner Kallweit

If max_cswd_read_retries is set to 0 or 1 then the current warning behavior doesn't seem to make too much sense to me.
If set to 0, then we'd warn with each watchdog run.
If set to 1, then we'd warn at the first retry, even though the commit description of db3a34e17433 states that one retry is expected behavior. If printing a message at all in this case, then it should be debug level.

The behavior for max_cswd_read_retries==1 is exactly what you want when you are checking to see whether or not your system would retry at all for the duration of a given run.

Quoted 6 lines

The behavior for max_cswd_read_retries==0 is exactly what you want when you are testing the ability to print that message on a system that will not do a retry in a reasonable period of time.

Or am I missing something here?

For me this mixes production warning and debug features. To support your debug use cases, maybe use something like this?

if (nretries > 1)

	pr_warn()
else if (nretries >= max_cswd_read_retries)
	pr_debug()
Quoted 48 lines
Quoted 2 lines

Whilst being at it, move declaration of wd_end and wd_delta into the loop and remove not needed braces.

I am OK with moving those two variables into the "for" loop.

I am personally OK removing the braces, but if I remember correctly, my upstream maintainer asked that I add them due to the statement being split across two lines.

Thanx, Paul

Quoted 37 lines
---
 kernel/time/clocksource.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/time/clocksource.c +3 -3
index f29d1a524..8c0be9c02 100644
@@ -208,10 +208,11 @@ module_param(verify_n_cpus, int, 0644);
 static bool cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
 {
 	unsigned int nretries;
-	u64 wd_end, wd_delta;
 	int64_t wd_delay;
 
 	for (nretries = 0; nretries <= max_cswd_read_retries; nretries++) {
+		u64 wd_end, wd_delta;
+
 		local_irq_disable();
 		*wdnow = watchdog->read(watchdog);
 		*csnow = cs->read(cs);
@@ -222,10 +223,9 @@ static bool cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
 		wd_delay = clocksource_cyc2ns(wd_delta, watchdog->mult,
 					      watchdog->shift);
 		if (wd_delay <= WATCHDOG_MAX_SKEW) {
-			if (nretries > 1 || nretries >= max_cswd_read_retries) {
+			if (nretries > 1)
 				pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before success\n",
 					smp_processor_id(), watchdog->name, nretries);
-			}
 			return true;
 		}
 	}
Signature · 1 line
2.33.1
#3 lore raw
Quoted 14 lines · Heiner Kallweit
Quoted 13 lines · Paul E. McKenney
Quoted 7 lines · Heiner Kallweit

If max_cswd_read_retries is set to 0 or 1 then the current warning behavior doesn't seem to make too much sense to me.
If set to 0, then we'd warn with each watchdog run.
If set to 1, then we'd warn at the first retry, even though the commit description of db3a34e17433 states that one retry is expected behavior. If printing a message at all in this case, then it should be debug level.

The behavior for max_cswd_read_retries==1 is exactly what you want when you are checking to see whether or not your system would retry at all for the duration of a given run.

Quoted 7 lines
Quoted 6 lines

The behavior for max_cswd_read_retries==0 is exactly what you want when you are testing the ability to print that message on a system that will not do a retry in a reasonable period of time.

Or am I missing something here?

For me this mixes production warning and debug features.

I know of no law saying that a given module parameter cannot be used for both debugging and production features. In fact, there are any number of parameters that take ranges of values, some of which should not be used in production. In addition, Linux supports such a wide range of environments and workloads that people supporting different production environments will have very different ideas about the advisability of setting a given value for a given module parameter.

So if your production environments don't like setting the value of clocksource.max_cswd_read_retries to less than two, why not just prohibit such settings in your production environments?

Quoted 6 lines

To support your debug use cases, maybe use something like this?

if (nretries > 1)

	pr_warn()
else if (nretries >= max_cswd_read_retries)
	pr_debug()

I am sorry, but I am not seeing the benefit of this change. How does this help you?

Thanx, Paul

Quoted 49 lines
Quoted 48 lines
Quoted 2 lines

Whilst being at it, move declaration of wd_end and wd_delta into the loop and remove not needed braces.

I am OK with moving those two variables into the "for" loop.

I am personally OK removing the braces, but if I remember correctly, my upstream maintainer asked that I add them due to the statement being split across two lines.

Thanx, Paul

Quoted 37 lines
---
 kernel/time/clocksource.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/time/clocksource.c +3 -3
index f29d1a524..8c0be9c02 100644
@@ -208,10 +208,11 @@ module_param(verify_n_cpus, int, 0644);
 static bool cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
 {
 	unsigned int nretries;
-	u64 wd_end, wd_delta;
 	int64_t wd_delay;
 
 	for (nretries = 0; nretries <= max_cswd_read_retries; nretries++) {
+		u64 wd_end, wd_delta;
+
 		local_irq_disable();
 		*wdnow = watchdog->read(watchdog);
 		*csnow = cs->read(cs);
@@ -222,10 +223,9 @@ static bool cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
 		wd_delay = clocksource_cyc2ns(wd_delta, watchdog->mult,
 					      watchdog->shift);
 		if (wd_delay <= WATCHDOG_MAX_SKEW) {
-			if (nretries > 1 || nretries >= max_cswd_read_retries) {
+			if (nretries > 1)
 				pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before success\n",
 					smp_processor_id(), watchdog->name, nretries);
-			}
 			return true;
 		}
 	}
Signature · 1 line
2.33.1