Skip to content

Commit 42f930d

Browse files
dzickusrhKAGA-KOKO
authored andcommitted
watchdog/hardlockup/perf: Use atomics to track in-use cpu counter
Guenter reported: There is still a problem. When running echo 6 > /proc/sys/kernel/watchdog_thresh echo 5 > /proc/sys/kernel/watchdog_thresh repeatedly, the message NMI watchdog: Enabled. Permanently consumes one hw-PMU counter. stops after a while (after ~10-30 iterations, with fluctuations). Maybe watchdog_cpus needs to be atomic ? That's correct as this again is affected by the asynchronous nature of the smpboot thread unpark mechanism. CPU 0 CPU1 CPU2 write(watchdog_thresh, 6) stop() park() update() start() unpark() thread->unpark() cnt++; write(watchdog_thresh, 5) thread->unpark() stop() park() thread->park() cnt--; cnt++; update() start() unpark() That's not a functional problem, it just affects the informational message. Convert watchdog_cpus to atomic_t to prevent the problem Reported-and-tested-by: Guenter Roeck <[email protected]> Signed-off-by: Don Zickus <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 9c388a5 commit 42f930d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

kernel/watchdog_hld.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define pr_fmt(fmt) "NMI watchdog: " fmt
1313

1414
#include <linux/nmi.h>
15+
#include <linux/atomic.h>
1516
#include <linux/module.h>
1617
#include <linux/sched/debug.h>
1718

@@ -25,7 +26,7 @@ static DEFINE_PER_CPU(struct perf_event *, dead_event);
2526
static struct cpumask dead_events_mask;
2627

2728
static unsigned long hardlockup_allcpu_dumped;
28-
static unsigned int watchdog_cpus;
29+
static atomic_t watchdog_cpus = ATOMIC_INIT(0);
2930

3031
void arch_touch_nmi_watchdog(void)
3132
{
@@ -189,7 +190,8 @@ void hardlockup_detector_perf_enable(void)
189190
if (hardlockup_detector_event_create())
190191
return;
191192

192-
if (!watchdog_cpus++)
193+
/* use original value for check */
194+
if (!atomic_fetch_inc(&watchdog_cpus))
193195
pr_info("Enabled. Permanently consumes one hw-PMU counter.\n");
194196

195197
perf_event_enable(this_cpu_read(watchdog_ev));
@@ -207,7 +209,7 @@ void hardlockup_detector_perf_disable(void)
207209
this_cpu_write(watchdog_ev, NULL);
208210
this_cpu_write(dead_event, event);
209211
cpumask_set_cpu(smp_processor_id(), &dead_events_mask);
210-
watchdog_cpus--;
212+
atomic_dec(&watchdog_cpus);
211213
}
212214
}
213215

0 commit comments

Comments
 (0)