* [PATCH v2 TSC and clocksource-watchdog updates for v6.12 1/5] clocksource: Improve comments for watchdog skew bounds
2024-08-02 15:45 ` [PATCH v2 clocksource 0/5] TSC and clocksource-watchdog updates for v6.12 Paul E. McKenney
@ 2024-08-02 15:46 ` Paul E. McKenney
2024-08-02 16:43 ` [tip: timers/clocksource] " tip-bot2 for Borislav Petkov
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 2/5] clocksource: Fix brown-bag boolean thinko in cs_watchdog_read() Paul E. McKenney
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Paul E. McKenney @ 2024-08-02 15:46 UTC (permalink / raw)
To: Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: H. Peter Anvin, John Stultz, Stephen Boyd, Peter Zijlstra,
Feng Tang, Waiman Long, Neeraj Upadhyay, x86, kernel-team,
linux-kernel, Paul E . McKenney, Thomas Gleixner
From: Borislav Petkov <bp@alien8.de>
Add more detail on the rationale for bounding the clocksource
->uncertainty_margin below at about 500ppm.
Signed-off-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: John Stultz <jstultz@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Feng Tang <feng.tang@intel.com>
---
kernel/time/clocksource.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index d25ba49e313cc..9ca4e8d2a70f8 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -125,6 +125,13 @@ static u64 suspend_start;
*
* The default of 500 parts per million is based on NTP's limits.
* If a clocksource is good enough for NTP, it is good enough for us!
+ *
+ * In other words, by default, even if a clocksource is extremely
+ * precise (for example, with a sub-nanosecond period), the maximum
+ * permissible skew between the clocksource watchdog and the clocksource
+ * under test is not permitted to go below the 500ppm minimum defined
+ * by MAX_SKEW_USEC. This 500ppm minimum may be overridden using the
+ * CLOCKSOURCE_WATCHDOG_MAX_SKEW_US Kconfig option.
*/
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US
#define MAX_SKEW_USEC CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US
@@ -1146,14 +1153,19 @@ void __clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq
}
/*
- * If the uncertainty margin is not specified, calculate it.
- * If both scale and freq are non-zero, calculate the clock
- * period, but bound below at 2*WATCHDOG_MAX_SKEW. However,
- * if either of scale or freq is zero, be very conservative and
- * take the tens-of-milliseconds WATCHDOG_THRESHOLD value for the
- * uncertainty margin. Allow stupidly small uncertainty margins
- * to be specified by the caller for testing purposes, but warn
- * to discourage production use of this capability.
+ * If the uncertainty margin is not specified, calculate it. If
+ * both scale and freq are non-zero, calculate the clock period, but
+ * bound below at 2*WATCHDOG_MAX_SKEW, that is, 500ppm by default.
+ * However, if either of scale or freq is zero, be very conservative
+ * and take the tens-of-milliseconds WATCHDOG_THRESHOLD value
+ * for the uncertainty margin. Allow stupidly small uncertainty
+ * margins to be specified by the caller for testing purposes,
+ * but warn to discourage production use of this capability.
+ *
+ * Bottom line: The sum of the uncertainty margins of the
+ * watchdog clocksource and the clocksource under test will be at
+ * least 500ppm by default. For more information, please see the
+ * comment preceding CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US above.
*/
if (scale && freq && !cs->uncertainty_margin) {
cs->uncertainty_margin = NSEC_PER_SEC / (scale * freq);
--
2.40.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [tip: timers/clocksource] clocksource: Improve comments for watchdog skew bounds
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 1/5] clocksource: Improve comments for watchdog skew bounds Paul E. McKenney
@ 2024-08-02 16:43 ` tip-bot2 for Borislav Petkov
0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Borislav Petkov @ 2024-08-02 16:43 UTC (permalink / raw)
To: linux-tip-commits
Cc: Borislav Petkov, Paul E. McKenney, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/clocksource branch of tip:
Commit-ID: 17915131ae4660658aa779f89e9f444319861561
Gitweb: https://git.kernel.org/tip/17915131ae4660658aa779f89e9f444319861561
Author: Borislav Petkov <bp@alien8.de>
AuthorDate: Fri, 02 Aug 2024 08:46:14 -07:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 02 Aug 2024 18:37:13 +02:00
clocksource: Improve comments for watchdog skew bounds
Add more detail on the rationale for bounding the clocksource
->uncertainty_margin below at about 500ppm.
Signed-off-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20240802154618.4149953-1-paulmck@kernel.org
---
kernel/time/clocksource.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index d0538a7..581cdbb 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -125,6 +125,13 @@ static u64 suspend_start;
*
* The default of 500 parts per million is based on NTP's limits.
* If a clocksource is good enough for NTP, it is good enough for us!
+ *
+ * In other words, by default, even if a clocksource is extremely
+ * precise (for example, with a sub-nanosecond period), the maximum
+ * permissible skew between the clocksource watchdog and the clocksource
+ * under test is not permitted to go below the 500ppm minimum defined
+ * by MAX_SKEW_USEC. This 500ppm minimum may be overridden using the
+ * CLOCKSOURCE_WATCHDOG_MAX_SKEW_US Kconfig option.
*/
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US
#define MAX_SKEW_USEC CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US
@@ -1146,14 +1153,19 @@ void __clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq
}
/*
- * If the uncertainty margin is not specified, calculate it.
- * If both scale and freq are non-zero, calculate the clock
- * period, but bound below at 2*WATCHDOG_MAX_SKEW. However,
- * if either of scale or freq is zero, be very conservative and
- * take the tens-of-milliseconds WATCHDOG_THRESHOLD value for the
- * uncertainty margin. Allow stupidly small uncertainty margins
- * to be specified by the caller for testing purposes, but warn
- * to discourage production use of this capability.
+ * If the uncertainty margin is not specified, calculate it. If
+ * both scale and freq are non-zero, calculate the clock period, but
+ * bound below at 2*WATCHDOG_MAX_SKEW, that is, 500ppm by default.
+ * However, if either of scale or freq is zero, be very conservative
+ * and take the tens-of-milliseconds WATCHDOG_THRESHOLD value
+ * for the uncertainty margin. Allow stupidly small uncertainty
+ * margins to be specified by the caller for testing purposes,
+ * but warn to discourage production use of this capability.
+ *
+ * Bottom line: The sum of the uncertainty margins of the
+ * watchdog clocksource and the clocksource under test will be at
+ * least 500ppm by default. For more information, please see the
+ * comment preceding CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US above.
*/
if (scale && freq && !cs->uncertainty_margin) {
cs->uncertainty_margin = NSEC_PER_SEC / (scale * freq);
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 TSC and clocksource-watchdog updates for v6.12 2/5] clocksource: Fix brown-bag boolean thinko in cs_watchdog_read()
2024-08-02 15:45 ` [PATCH v2 clocksource 0/5] TSC and clocksource-watchdog updates for v6.12 Paul E. McKenney
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 1/5] clocksource: Improve comments for watchdog skew bounds Paul E. McKenney
@ 2024-08-02 15:46 ` Paul E. McKenney
2024-08-02 16:34 ` [tip: timers/urgent] " tip-bot2 for Paul E. McKenney
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 3/5] clocksource: Fix comments on WATCHDOG_THRESHOLD & WATCHDOG_MAX_SKEW Paul E. McKenney
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Paul E. McKenney @ 2024-08-02 15:46 UTC (permalink / raw)
To: Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: H. Peter Anvin, John Stultz, Stephen Boyd, Peter Zijlstra,
Feng Tang, Waiman Long, Neeraj Upadhyay, x86, kernel-team,
linux-kernel, Paul E. McKenney
The current "nretries > 1 || nretries >= max_retries" check in
cs_watchdog_read() will always evaluate to true, and thus pr_warn(), if
nretries is greater than 1. The intent is instead to never warn on the
first try, but otherwise warn if the successful retry was the last retry.
Therefore, change that "||" to "&&".
Reported-by: Borislav Petkov <bp@alien8.de>
Fixes: db3a34e17433 ("clocksource: Retry clock read if long delays detected")
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/time/clocksource.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 9ca4e8d2a70f8..581cdbb538448 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -253,7 +253,7 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
wd_delay = cycles_to_nsec_safe(watchdog, *wdnow, wd_end);
if (wd_delay <= WATCHDOG_MAX_SKEW) {
- if (nretries > 1 || nretries >= max_retries) {
+ if (nretries > 1 && nretries >= max_retries) {
pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before success\n",
smp_processor_id(), watchdog->name, nretries);
}
--
2.40.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [tip: timers/urgent] clocksource: Fix brown-bag boolean thinko in cs_watchdog_read()
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 2/5] clocksource: Fix brown-bag boolean thinko in cs_watchdog_read() Paul E. McKenney
@ 2024-08-02 16:34 ` tip-bot2 for Paul E. McKenney
0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Paul E. McKenney @ 2024-08-02 16:34 UTC (permalink / raw)
To: linux-tip-commits
Cc: Borislav Petkov, Paul E. McKenney, Thomas Gleixner, stable, x86,
linux-kernel
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: f2655ac2c06a15558e51ed6529de280e1553c86e
Gitweb: https://git.kernel.org/tip/f2655ac2c06a15558e51ed6529de280e1553c86e
Author: Paul E. McKenney <paulmck@kernel.org>
AuthorDate: Fri, 02 Aug 2024 08:46:15 -07:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 02 Aug 2024 18:29:28 +02:00
clocksource: Fix brown-bag boolean thinko in cs_watchdog_read()
The current "nretries > 1 || nretries >= max_retries" check in
cs_watchdog_read() will always evaluate to true, and thus pr_warn(), if
nretries is greater than 1. The intent is instead to never warn on the
first try, but otherwise warn if the successful retry was the last retry.
Therefore, change that "||" to "&&".
Fixes: db3a34e17433 ("clocksource: Retry clock read if long delays detected")
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20240802154618.4149953-2-paulmck@kernel.org
---
kernel/time/clocksource.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index d25ba49..d0538a7 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -246,7 +246,7 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
wd_delay = cycles_to_nsec_safe(watchdog, *wdnow, wd_end);
if (wd_delay <= WATCHDOG_MAX_SKEW) {
- if (nretries > 1 || nretries >= max_retries) {
+ if (nretries > 1 && nretries >= max_retries) {
pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before success\n",
smp_processor_id(), watchdog->name, nretries);
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 TSC and clocksource-watchdog updates for v6.12 3/5] clocksource: Fix comments on WATCHDOG_THRESHOLD & WATCHDOG_MAX_SKEW
2024-08-02 15:45 ` [PATCH v2 clocksource 0/5] TSC and clocksource-watchdog updates for v6.12 Paul E. McKenney
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 1/5] clocksource: Improve comments for watchdog skew bounds Paul E. McKenney
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 2/5] clocksource: Fix brown-bag boolean thinko in cs_watchdog_read() Paul E. McKenney
@ 2024-08-02 15:46 ` Paul E. McKenney
2024-08-02 16:43 ` [tip: timers/clocksource] " tip-bot2 for Paul E. McKenney
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 4/5] clocksource: Set cs_watchdog_read() checks based on .uncertainty_margin Paul E. McKenney
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 5/5] tsc: Check for sockets instead of CPUs to make code match comment Paul E. McKenney
4 siblings, 1 reply; 11+ messages in thread
From: Paul E. McKenney @ 2024-08-02 15:46 UTC (permalink / raw)
To: Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: H. Peter Anvin, John Stultz, Stephen Boyd, Peter Zijlstra,
Feng Tang, Waiman Long, Neeraj Upadhyay, x86, kernel-team,
linux-kernel, Paul E. McKenney
The WATCHDOG_THRESHOLD macro is no longer used to supply a default value
for ->uncertainty_margin, but WATCHDOG_MAX_SKEW now is. Therefore,
update the comments to reflect this change.
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Acked-by: Borislav Petkov (AMD) <bp@alien8.de>
---
kernel/time/clocksource.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 581cdbb538448..ee0ad5e4d5170 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -113,7 +113,6 @@ static u64 suspend_start;
/*
* Threshold: 0.0312s, when doubled: 0.0625s.
- * Also a default for cs->uncertainty_margin when registering clocks.
*/
#define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 5)
@@ -139,6 +138,13 @@ static u64 suspend_start;
#define MAX_SKEW_USEC (125 * WATCHDOG_INTERVAL / HZ)
#endif
+/*
+ * Default for maximum permissible skew when cs->uncertainty_margin is
+ * not specified, and the lower bound even when cs->uncertainty_margin
+ * is specified. This is also the default that is used when registering
+ * clocks with unspecifed cs->uncertainty_margin, so this macro is used
+ * even in CONFIG_CLOCKSOURCE_WATCHDOG=n kernels.
+ */
#define WATCHDOG_MAX_SKEW (MAX_SKEW_USEC * NSEC_PER_USEC)
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG
--
2.40.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [tip: timers/clocksource] clocksource: Fix comments on WATCHDOG_THRESHOLD & WATCHDOG_MAX_SKEW
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 3/5] clocksource: Fix comments on WATCHDOG_THRESHOLD & WATCHDOG_MAX_SKEW Paul E. McKenney
@ 2024-08-02 16:43 ` tip-bot2 for Paul E. McKenney
0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Paul E. McKenney @ 2024-08-02 16:43 UTC (permalink / raw)
To: linux-tip-commits
Cc: Borislav Petkov, Paul E. McKenney, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/clocksource branch of tip:
Commit-ID: f33a5d4bd9c2e545857b2cf7481eb721bcab867c
Gitweb: https://git.kernel.org/tip/f33a5d4bd9c2e545857b2cf7481eb721bcab867c
Author: Paul E. McKenney <paulmck@kernel.org>
AuthorDate: Fri, 02 Aug 2024 08:46:16 -07:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 02 Aug 2024 18:37:13 +02:00
clocksource: Fix comments on WATCHDOG_THRESHOLD & WATCHDOG_MAX_SKEW
The WATCHDOG_THRESHOLD macro is no longer used to supply a default value
for ->uncertainty_margin, but WATCHDOG_MAX_SKEW now is.
Therefore, update the comments to reflect this change.
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/all/20240802154618.4149953-3-paulmck@kernel.org
---
kernel/time/clocksource.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 581cdbb..ee0ad5e 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -113,7 +113,6 @@ static u64 suspend_start;
/*
* Threshold: 0.0312s, when doubled: 0.0625s.
- * Also a default for cs->uncertainty_margin when registering clocks.
*/
#define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 5)
@@ -139,6 +138,13 @@ static u64 suspend_start;
#define MAX_SKEW_USEC (125 * WATCHDOG_INTERVAL / HZ)
#endif
+/*
+ * Default for maximum permissible skew when cs->uncertainty_margin is
+ * not specified, and the lower bound even when cs->uncertainty_margin
+ * is specified. This is also the default that is used when registering
+ * clocks with unspecifed cs->uncertainty_margin, so this macro is used
+ * even in CONFIG_CLOCKSOURCE_WATCHDOG=n kernels.
+ */
#define WATCHDOG_MAX_SKEW (MAX_SKEW_USEC * NSEC_PER_USEC)
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 TSC and clocksource-watchdog updates for v6.12 4/5] clocksource: Set cs_watchdog_read() checks based on .uncertainty_margin
2024-08-02 15:45 ` [PATCH v2 clocksource 0/5] TSC and clocksource-watchdog updates for v6.12 Paul E. McKenney
` (2 preceding siblings ...)
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 3/5] clocksource: Fix comments on WATCHDOG_THRESHOLD & WATCHDOG_MAX_SKEW Paul E. McKenney
@ 2024-08-02 15:46 ` Paul E. McKenney
2024-08-02 16:43 ` [tip: timers/clocksource] " tip-bot2 for Paul E. McKenney
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 5/5] tsc: Check for sockets instead of CPUs to make code match comment Paul E. McKenney
4 siblings, 1 reply; 11+ messages in thread
From: Paul E. McKenney @ 2024-08-02 15:46 UTC (permalink / raw)
To: Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: H. Peter Anvin, John Stultz, Stephen Boyd, Peter Zijlstra,
Feng Tang, Waiman Long, Neeraj Upadhyay, x86, kernel-team,
linux-kernel, Paul E. McKenney, Thomas Gleixner
Right now, cs_watchdog_read() does clocksource sanity checks based
on WATCHDOG_MAX_SKEW, which sets a floor on any clocksource's
.uncertainty_margin. These sanity checks can therefore act
inappropriately for clocksources with large uncertainty margins.
One reason for a clocksource to have a large .uncertainty_margin is when
that clocksource has long read-out latency, given that it does not make
sense for the .uncertainty_margin to be smaller than the read-out latency.
With the current checks, cs_watchdog_read() could reject all normal
reads from a clocksource with long read-out latencies, such as those
from legacy clocksources that are no longer implemented in hardware.
Therefore, recast the cs_watchdog_read() checks in terms of the
.uncertainty_margin values of the clocksources involved in the timespan
in question. The first covers two watchdog reads and one cs read,
so use twice the watchdog .uncertainty_margin plus that of the cs.
The second covers only a pair of watchdog reads, so use twice the
watchdog .uncertainty_margin.
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: John Stultz <jstultz@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Feng Tang <feng.tang@intel.com>
Cc: Waiman Long <longman@redhat.com>
Cc: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
Cc: <x86@kernel.org>
---
kernel/time/clocksource.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index ee0ad5e4d5170..23336eecb4f43 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -244,6 +244,7 @@ enum wd_read_status {
static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
{
+ int64_t md = 2 * watchdog->uncertainty_margin;
unsigned int nretries, max_retries;
int64_t wd_delay, wd_seq_delay;
u64 wd_end, wd_end2;
@@ -258,7 +259,7 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
local_irq_enable();
wd_delay = cycles_to_nsec_safe(watchdog, *wdnow, wd_end);
- if (wd_delay <= WATCHDOG_MAX_SKEW) {
+ if (wd_delay <= md + cs->uncertainty_margin) {
if (nretries > 1 && nretries >= max_retries) {
pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before success\n",
smp_processor_id(), watchdog->name, nretries);
@@ -271,12 +272,12 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
* there is too much external interferences that cause
* significant delay in reading both clocksource and watchdog.
*
- * If consecutive WD read-back delay > WATCHDOG_MAX_SKEW/2,
- * report system busy, reinit the watchdog and skip the current
+ * If consecutive WD read-back delay > md, report
+ * system busy, reinit the watchdog and skip the current
* watchdog test.
*/
wd_seq_delay = cycles_to_nsec_safe(watchdog, wd_end, wd_end2);
- if (wd_seq_delay > WATCHDOG_MAX_SKEW/2)
+ if (wd_seq_delay > md)
goto skip_test;
}
--
2.40.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [tip: timers/clocksource] clocksource: Set cs_watchdog_read() checks based on .uncertainty_margin
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 4/5] clocksource: Set cs_watchdog_read() checks based on .uncertainty_margin Paul E. McKenney
@ 2024-08-02 16:43 ` tip-bot2 for Paul E. McKenney
0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Paul E. McKenney @ 2024-08-02 16:43 UTC (permalink / raw)
To: linux-tip-commits
Cc: Borislav Petkov, Paul E. McKenney, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/clocksource branch of tip:
Commit-ID: 4ac1dd3245b9067f929ab30141bb0475e9e32fc5
Gitweb: https://git.kernel.org/tip/4ac1dd3245b9067f929ab30141bb0475e9e32fc5
Author: Paul E. McKenney <paulmck@kernel.org>
AuthorDate: Fri, 02 Aug 2024 08:46:17 -07:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 02 Aug 2024 18:37:13 +02:00
clocksource: Set cs_watchdog_read() checks based on .uncertainty_margin
Right now, cs_watchdog_read() does clocksource sanity checks based
on WATCHDOG_MAX_SKEW, which sets a floor on any clocksource's
.uncertainty_margin. These sanity checks can therefore act
inappropriately for clocksources with large uncertainty margins.
One reason for a clocksource to have a large .uncertainty_margin is when
that clocksource has long read-out latency, given that it does not make
sense for the .uncertainty_margin to be smaller than the read-out latency.
With the current checks, cs_watchdog_read() could reject all normal
reads from a clocksource with long read-out latencies, such as those
from legacy clocksources that are no longer implemented in hardware.
Therefore, recast the cs_watchdog_read() checks in terms of the
.uncertainty_margin values of the clocksources involved in the timespan in
question. The first covers two watchdog reads and one cs read, so use
twice the watchdog .uncertainty_margin plus that of the cs. The second
covers only a pair of watchdog reads, so use twice the watchdog
.uncertainty_margin.
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20240802154618.4149953-4-paulmck@kernel.org
---
kernel/time/clocksource.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index ee0ad5e..23336ee 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -244,6 +244,7 @@ enum wd_read_status {
static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
{
+ int64_t md = 2 * watchdog->uncertainty_margin;
unsigned int nretries, max_retries;
int64_t wd_delay, wd_seq_delay;
u64 wd_end, wd_end2;
@@ -258,7 +259,7 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
local_irq_enable();
wd_delay = cycles_to_nsec_safe(watchdog, *wdnow, wd_end);
- if (wd_delay <= WATCHDOG_MAX_SKEW) {
+ if (wd_delay <= md + cs->uncertainty_margin) {
if (nretries > 1 && nretries >= max_retries) {
pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before success\n",
smp_processor_id(), watchdog->name, nretries);
@@ -271,12 +272,12 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
* there is too much external interferences that cause
* significant delay in reading both clocksource and watchdog.
*
- * If consecutive WD read-back delay > WATCHDOG_MAX_SKEW/2,
- * report system busy, reinit the watchdog and skip the current
+ * If consecutive WD read-back delay > md, report
+ * system busy, reinit the watchdog and skip the current
* watchdog test.
*/
wd_seq_delay = cycles_to_nsec_safe(watchdog, wd_end, wd_end2);
- if (wd_seq_delay > WATCHDOG_MAX_SKEW/2)
+ if (wd_seq_delay > md)
goto skip_test;
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 TSC and clocksource-watchdog updates for v6.12 5/5] tsc: Check for sockets instead of CPUs to make code match comment
2024-08-02 15:45 ` [PATCH v2 clocksource 0/5] TSC and clocksource-watchdog updates for v6.12 Paul E. McKenney
` (3 preceding siblings ...)
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 4/5] clocksource: Set cs_watchdog_read() checks based on .uncertainty_margin Paul E. McKenney
@ 2024-08-02 15:46 ` Paul E. McKenney
2024-08-02 16:43 ` [tip: x86/timers] x86/tsc: " tip-bot2 for Paul E. McKenney
4 siblings, 1 reply; 11+ messages in thread
From: Paul E. McKenney @ 2024-08-02 15:46 UTC (permalink / raw)
To: Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: H. Peter Anvin, John Stultz, Stephen Boyd, Peter Zijlstra,
Feng Tang, Waiman Long, Neeraj Upadhyay, x86, kernel-team,
linux-kernel, Paul E. McKenney, Zhengxu Chen,
Danielle Costantino, Thomas Gleixner
The unsynchronized_tsc() eventually checks num_possible_cpus(), and
if the system is non-Intel and the number of possible CPUs is greater
than one, assumes that TSCs are unsynchronized. This despite the
comment saying "assume multi socket systems are not synchronized",
that is, socket rather than CPU. This behavior was preserved by
commit 8fbbc4b45ce3 ("x86: merge tsc_init and clocksource code") and
by the previous relevant commit 7e69f2b1ead2 ("clocksource: Remove the
update callback").
The clocksource drivers were added by commit 5d0cf410e94b ("Time: i386
Clocksource Drivers") back in 2006, and the comment still said "socket"
rather than "CPU".
Therefore, bravely (and perhaps foolishly) make the code match the
comment.
Note that it is possible to bypass both code and comment by booting
with tsc=reliable, but this also disables the clocksource watchdog,
which is undesirable when trust in the TSC is strictly limited.
[ paulmck: Switch from nr_online_nodes to topology_max_packages() per Feng Tang feedback. ]
Reported-by: Zhengxu Chen <zhxchen17@meta.com>
Reported-by: Danielle Costantino <dcostantino@meta.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Feng Tang <feng.tang@intel.com>
Cc: Waiman Long <longman@redhat.com>
Cc: John Stultz <jstultz@google.com>
Cc: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
Cc: <x86@kernel.org>
---
arch/x86/kernel/tsc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index d4462fb262996..b7b050ca8baa1 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -1290,7 +1290,7 @@ int unsynchronized_tsc(void)
*/
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
/* assume multi socket systems are not synchronized: */
- if (num_possible_cpus() > 1)
+ if (topology_max_packages() > 1)
return 1;
}
--
2.40.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [tip: x86/timers] x86/tsc: Check for sockets instead of CPUs to make code match comment
2024-08-02 15:46 ` [PATCH v2 TSC and clocksource-watchdog updates for v6.12 5/5] tsc: Check for sockets instead of CPUs to make code match comment Paul E. McKenney
@ 2024-08-02 16:43 ` tip-bot2 for Paul E. McKenney
0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Paul E. McKenney @ 2024-08-02 16:43 UTC (permalink / raw)
To: linux-tip-commits
Cc: Zhengxu Chen, Danielle Costantino, Paul E. McKenney,
Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the x86/timers branch of tip:
Commit-ID: e7ff4ebffe3bedf55560ef861d80f6500ff0d76f
Gitweb: https://git.kernel.org/tip/e7ff4ebffe3bedf55560ef861d80f6500ff0d76f
Author: Paul E. McKenney <paulmck@kernel.org>
AuthorDate: Fri, 02 Aug 2024 08:46:18 -07:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 02 Aug 2024 18:38:07 +02:00
x86/tsc: Check for sockets instead of CPUs to make code match comment
The unsynchronized_tsc() eventually checks num_possible_cpus(), and if the
system is non-Intel and the number of possible CPUs is greater than one,
assumes that TSCs are unsynchronized. This despite the comment saying
"assume multi socket systems are not synchronized", that is, socket rather
than CPU. This behavior was preserved by commit 8fbbc4b45ce3 ("x86: merge
tsc_init and clocksource code") and by the previous relevant commit
7e69f2b1ead2 ("clocksource: Remove the update callback").
The clocksource drivers were added by commit 5d0cf410e94b ("Time: i386
Clocksource Drivers") back in 2006, and the comment still said "socket"
rather than "CPU".
Therefore, bravely (and perhaps foolishly) make the code match the
comment.
Note that it is possible to bypass both code and comment by booting
with tsc=reliable, but this also disables the clocksource watchdog,
which is undesirable when trust in the TSC is strictly limited.
Reported-by: Zhengxu Chen <zhxchen17@meta.com>
Reported-by: Danielle Costantino <dcostantino@meta.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20240802154618.4149953-5-paulmck@kernel.org
---
arch/x86/kernel/tsc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 0ced187..dfe6847 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -1288,7 +1288,7 @@ int unsynchronized_tsc(void)
*/
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
/* assume multi socket systems are not synchronized: */
- if (num_possible_cpus() > 1)
+ if (topology_max_packages() > 1)
return 1;
}
^ permalink raw reply [flat|nested] 11+ messages in thread