Move watchdog_hld.c to kernel/, and rename arm_pmu_irq_is_nmi()
to arch_pmu_irq_is_nmi() for cross-arch reusability.
Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
---
arch/arm64/kernel/Makefile | 1 -
drivers/perf/arm_pmu.c | 2 +-
include/linux/nmi.h | 1 +
include/linux/perf/arm_pmu.h | 2 --
kernel/Makefile | 2 +-
{arch/arm64/kernel => kernel}/watchdog_hld.c | 8 ++++++--
6 files changed, 9 insertions(+), 7 deletions(-)
rename {arch/arm64/kernel => kernel}/watchdog_hld.c (97%)
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 76f32e424065e..12d77f373fea4 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -44,7 +44,6 @@ obj-$(CONFIG_KUSER_HELPERS) += kuser32.o
obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o
obj-$(CONFIG_MODULES) += module.o module-plts.o
obj-$(CONFIG_PERF_EVENTS) += perf_regs.o perf_callchain.o
-obj-$(CONFIG_HARDLOCKUP_DETECTOR_PERF) += watchdog_hld.o
obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
obj-$(CONFIG_CPU_PM) += sleep.o suspend.o
obj-$(CONFIG_KGDB) += kgdb.o
diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
index 5c310e803dd78..4fd7f88d44543 100644
--- a/drivers/perf/arm_pmu.c
+++ b/drivers/perf/arm_pmu.c
@@ -696,7 +696,7 @@ static int armpmu_get_cpu_irq(struct arm_pmu *pmu, int cpu)
return per_cpu(hw_events->irq, cpu);
}
-bool arm_pmu_irq_is_nmi(void)
+bool arch_pmu_irq_is_nmi(void)
{
return has_nmi;
}
diff --git a/include/linux/nmi.h b/include/linux/nmi.h
index cf3c6ab408aac..c34bdc4f43f6d 100644
--- a/include/linux/nmi.h
+++ b/include/linux/nmi.h
@@ -207,6 +207,7 @@ static inline bool trigger_single_cpu_backtrace(int cpu)
#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
u64 hw_nmi_get_sample_period(int watchdog_thresh);
bool arch_perf_nmi_is_available(void);
+bool arch_pmu_irq_is_nmi(void);
#endif
#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
index 93c9a26492fcf..6b53fb453fd63 100644
--- a/include/linux/perf/arm_pmu.h
+++ b/include/linux/perf/arm_pmu.h
@@ -184,8 +184,6 @@ void kvm_host_pmu_init(struct arm_pmu *pmu);
#define kvm_host_pmu_init(x) do { } while(0)
#endif
-bool arm_pmu_irq_is_nmi(void);
-
/* Internal functions only for core arm_pmu code */
struct arm_pmu *armpmu_alloc(void);
void armpmu_free(struct arm_pmu *pmu);
diff --git a/kernel/Makefile b/kernel/Makefile
index c60623448235f..4ec7702b00aa1 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -101,7 +101,7 @@ obj-$(CONFIG_KGDB) += debug/
obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o
obj-$(CONFIG_HARDLOCKUP_DETECTOR_BUDDY) += watchdog_buddy.o
-obj-$(CONFIG_HARDLOCKUP_DETECTOR_PERF) += watchdog_perf.o
+obj-$(CONFIG_HARDLOCKUP_DETECTOR_PERF) += watchdog_perf.o watchdog_hld.o
obj-$(CONFIG_SECCOMP) += seccomp.o
obj-$(CONFIG_RELAY) += relay.o
obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
diff --git a/arch/arm64/kernel/watchdog_hld.c b/kernel/watchdog_hld.c
similarity index 97%
rename from arch/arm64/kernel/watchdog_hld.c
rename to kernel/watchdog_hld.c
index 3093037dcb7be..f3864e604a6b5 100644
--- a/arch/arm64/kernel/watchdog_hld.c
+++ b/kernel/watchdog_hld.c
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/nmi.h>
#include <linux/cpufreq.h>
-#include <linux/perf/arm_pmu.h>
/*
* Safe maximum CPU frequency in case a particular platform doesn't implement
@@ -25,6 +24,11 @@ u64 hw_nmi_get_sample_period(int watchdog_thresh)
return (u64)max_cpu_freq * watchdog_thresh;
}
+__weak bool arch_pmu_irq_is_nmi(void)
+{
+ return false;
+}
+
bool __init arch_perf_nmi_is_available(void)
{
/*
@@ -32,7 +36,7 @@ bool __init arch_perf_nmi_is_available(void)
* however, the pmu interrupts will act like a normal interrupt instead of
* NMI and the hardlockup detector would be broken.
*/
- return arm_pmu_irq_is_nmi();
+ return arch_pmu_irq_is_nmi();
}
static int watchdog_perf_update_period(void *data)
--
2.39.5
Hi, On Wed, Aug 27, 2025 at 3:10 AM Yunhui Cui <cuiyunhui@bytedance.com> wrote: > > Move watchdog_hld.c to kernel/, and rename arm_pmu_irq_is_nmi() > to arch_pmu_irq_is_nmi() for cross-arch reusability. > > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com> > --- > arch/arm64/kernel/Makefile | 1 - > drivers/perf/arm_pmu.c | 2 +- > include/linux/nmi.h | 1 + > include/linux/perf/arm_pmu.h | 2 -- > kernel/Makefile | 2 +- > {arch/arm64/kernel => kernel}/watchdog_hld.c | 8 ++++++-- > 6 files changed, 9 insertions(+), 7 deletions(-) > rename {arch/arm64/kernel => kernel}/watchdog_hld.c (97%) I'm not a huge fan of the perf hardlockup detector and IMO we should maybe just delete it. Thus spreading it to support a new architecture isn't my favorite thing to do. Can't you use the buddy hardlockup detector? That being said, I did a quick look at your patch. I'm pretty sure you can't just move the arm64 "watchdog_hld.c" to be generic. Won't hw_nmi_get_sample_period() conflict with everyone else's (x86 and powerpc)? -Doug
Hi Doug, On Sat, Aug 30, 2025 at 5:34 AM Doug Anderson <dianders@chromium.org> wrote: > > Hi, > > On Wed, Aug 27, 2025 at 3:10 AM Yunhui Cui <cuiyunhui@bytedance.com> wrote: > > > > Move watchdog_hld.c to kernel/, and rename arm_pmu_irq_is_nmi() > > to arch_pmu_irq_is_nmi() for cross-arch reusability. > > > > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com> > > --- > > arch/arm64/kernel/Makefile | 1 - > > drivers/perf/arm_pmu.c | 2 +- > > include/linux/nmi.h | 1 + > > include/linux/perf/arm_pmu.h | 2 -- > > kernel/Makefile | 2 +- > > {arch/arm64/kernel => kernel}/watchdog_hld.c | 8 ++++++-- > > 6 files changed, 9 insertions(+), 7 deletions(-) > > rename {arch/arm64/kernel => kernel}/watchdog_hld.c (97%) > > I'm not a huge fan of the perf hardlockup detector and IMO we should > maybe just delete it. Thus spreading it to support a new architecture > isn't my favorite thing to do. Can't you use the buddy hardlockup > detector? > > That being said, I did a quick look at your patch. I'm pretty sure you > can't just move the arm64 "watchdog_hld.c" to be generic. Won't > hw_nmi_get_sample_period() conflict with everyone else's (x86 and > powerpc)? After discussing whether to remove watchdog perf, it still seems necessary to keep advancing with it. For the code, we just need to decorate hw_nmi_get_sample_period() with __weak, right? > > -Doug > Thanks, Yunhui
Hi, On Tue, Sep 23, 2025 at 7:41 PM yunhui cui <cuiyunhui@bytedance.com> wrote: > > Hi Doug, > > On Sat, Aug 30, 2025 at 5:34 AM Doug Anderson <dianders@chromium.org> wrote: > > > > Hi, > > > > On Wed, Aug 27, 2025 at 3:10 AM Yunhui Cui <cuiyunhui@bytedance.com> wrote: > > > > > > Move watchdog_hld.c to kernel/, and rename arm_pmu_irq_is_nmi() > > > to arch_pmu_irq_is_nmi() for cross-arch reusability. > > > > > > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com> > > > --- > > > arch/arm64/kernel/Makefile | 1 - > > > drivers/perf/arm_pmu.c | 2 +- > > > include/linux/nmi.h | 1 + > > > include/linux/perf/arm_pmu.h | 2 -- > > > kernel/Makefile | 2 +- > > > {arch/arm64/kernel => kernel}/watchdog_hld.c | 8 ++++++-- > > > 6 files changed, 9 insertions(+), 7 deletions(-) > > > rename {arch/arm64/kernel => kernel}/watchdog_hld.c (97%) > > > > I'm not a huge fan of the perf hardlockup detector and IMO we should > > maybe just delete it. Thus spreading it to support a new architecture > > isn't my favorite thing to do. Can't you use the buddy hardlockup > > detector? > > > > That being said, I did a quick look at your patch. I'm pretty sure you > > can't just move the arm64 "watchdog_hld.c" to be generic. Won't > > hw_nmi_get_sample_period() conflict with everyone else's (x86 and > > powerpc)? > > After discussing whether to remove watchdog perf, it still seems > necessary to keep advancing with it. For the code, we just need to > decorate hw_nmi_get_sample_period() with __weak, right? That would probably work, but IMO you should make sure you can figure out how to at least compile the x86/powerpc kernels to confirm. -Doug
Hi Doug, On Sat, Aug 30, 2025 at 5:34 AM Doug Anderson <dianders@chromium.org> wrote: > > Hi, > > On Wed, Aug 27, 2025 at 3:10 AM Yunhui Cui <cuiyunhui@bytedance.com> wrote: > > > > Move watchdog_hld.c to kernel/, and rename arm_pmu_irq_is_nmi() > > to arch_pmu_irq_is_nmi() for cross-arch reusability. > > > > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com> > > --- > > arch/arm64/kernel/Makefile | 1 - > > drivers/perf/arm_pmu.c | 2 +- > > include/linux/nmi.h | 1 + > > include/linux/perf/arm_pmu.h | 2 -- > > kernel/Makefile | 2 +- > > {arch/arm64/kernel => kernel}/watchdog_hld.c | 8 ++++++-- > > 6 files changed, 9 insertions(+), 7 deletions(-) > > rename {arch/arm64/kernel => kernel}/watchdog_hld.c (97%) > > I'm not a huge fan of the perf hardlockup detector and IMO we should > maybe just delete it. Thus spreading it to support a new architecture > isn't my favorite thing to do. Can't you use the buddy hardlockup > detector? Why is there a plan to remove CONFIG_HARDLOCKUP_DETECTOR_PERF? Could you explain the specific reasons? Is the community's future plan to favor CONFIG_HARDLOCKUP_DETECTOR_BUDDY? > > That being said, I did a quick look at your patch. I'm pretty sure you > can't just move the arm64 "watchdog_hld.c" to be generic. Won't > hw_nmi_get_sample_period() conflict with everyone else's (x86 and > powerpc)? > > -Doug > Thanks, Yunhui
Hi, On Sun, Aug 31, 2025 at 10:57 PM yunhui cui <cuiyunhui@bytedance.com> wrote: > > Hi Doug, > > On Sat, Aug 30, 2025 at 5:34 AM Doug Anderson <dianders@chromium.org> wrote: > > > > Hi, > > > > On Wed, Aug 27, 2025 at 3:10 AM Yunhui Cui <cuiyunhui@bytedance.com> wrote: > > > > > > Move watchdog_hld.c to kernel/, and rename arm_pmu_irq_is_nmi() > > > to arch_pmu_irq_is_nmi() for cross-arch reusability. > > > > > > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com> > > > --- > > > arch/arm64/kernel/Makefile | 1 - > > > drivers/perf/arm_pmu.c | 2 +- > > > include/linux/nmi.h | 1 + > > > include/linux/perf/arm_pmu.h | 2 -- > > > kernel/Makefile | 2 +- > > > {arch/arm64/kernel => kernel}/watchdog_hld.c | 8 ++++++-- > > > 6 files changed, 9 insertions(+), 7 deletions(-) > > > rename {arch/arm64/kernel => kernel}/watchdog_hld.c (97%) > > > > I'm not a huge fan of the perf hardlockup detector and IMO we should > > maybe just delete it. Thus spreading it to support a new architecture > > isn't my favorite thing to do. Can't you use the buddy hardlockup > > detector? > > Why is there a plan to remove CONFIG_HARDLOCKUP_DETECTOR_PERF? Could > you explain the specific reasons? Is the community's future plan to > favor CONFIG_HARDLOCKUP_DETECTOR_BUDDY? I don't think there are any concrete plans, but there was some discussion here: https://lore.kernel.org/all/CAD=FV=WWUiCi6bZCs_gseFpDDWNkuJMoL6XCftEo6W7q6jRCkg@mail.gmail.com/ -Doug
Hi Doug, On Wed, Sep 3, 2025 at 1:04 AM Doug Anderson <dianders@chromium.org> wrote: > > Hi, > > On Sun, Aug 31, 2025 at 10:57 PM yunhui cui <cuiyunhui@bytedance.com> wrote: > > > > Hi Doug, > > > > On Sat, Aug 30, 2025 at 5:34 AM Doug Anderson <dianders@chromium.org> wrote: > > > > > > Hi, > > > > > > On Wed, Aug 27, 2025 at 3:10 AM Yunhui Cui <cuiyunhui@bytedance.com> wrote: > > > > > > > > Move watchdog_hld.c to kernel/, and rename arm_pmu_irq_is_nmi() > > > > to arch_pmu_irq_is_nmi() for cross-arch reusability. > > > > > > > > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com> > > > > --- > > > > arch/arm64/kernel/Makefile | 1 - > > > > drivers/perf/arm_pmu.c | 2 +- > > > > include/linux/nmi.h | 1 + > > > > include/linux/perf/arm_pmu.h | 2 -- > > > > kernel/Makefile | 2 +- > > > > {arch/arm64/kernel => kernel}/watchdog_hld.c | 8 ++++++-- > > > > 6 files changed, 9 insertions(+), 7 deletions(-) > > > > rename {arch/arm64/kernel => kernel}/watchdog_hld.c (97%) > > > > > > I'm not a huge fan of the perf hardlockup detector and IMO we should > > > maybe just delete it. Thus spreading it to support a new architecture > > > isn't my favorite thing to do. Can't you use the buddy hardlockup > > > detector? > > > > Why is there a plan to remove CONFIG_HARDLOCKUP_DETECTOR_PERF? Could > > you explain the specific reasons? Is the community's future plan to > > favor CONFIG_HARDLOCKUP_DETECTOR_BUDDY? > > I don't think there are any concrete plans, but there was some discussion here: > > https://lore.kernel.org/all/CAD=FV=WWUiCi6bZCs_gseFpDDWNkuJMoL6XCftEo6W7q6jRCkg@mail.gmail.com/ > > -Doug > I’ve read your linked content, which details the pros and cons of perf watchdog and buddy watchdog. I think everyone will agree on choosing one as the default. It seems there’s no kernel/watchdog entry in MAINTAINERS—what’s next for these two approaches? Thanks, Yunhui
Hi, On Wed, Sep 3, 2025 at 4:56 AM yunhui cui <cuiyunhui@bytedance.com> wrote: > > Hi Doug, > > On Wed, Sep 3, 2025 at 1:04 AM Doug Anderson <dianders@chromium.org> wrote: > > > > Hi, > > > > On Sun, Aug 31, 2025 at 10:57 PM yunhui cui <cuiyunhui@bytedance.com> wrote: > > > > > > Hi Doug, > > > > > > On Sat, Aug 30, 2025 at 5:34 AM Doug Anderson <dianders@chromium.org> wrote: > > > > > > > > Hi, > > > > > > > > On Wed, Aug 27, 2025 at 3:10 AM Yunhui Cui <cuiyunhui@bytedance.com> wrote: > > > > > > > > > > Move watchdog_hld.c to kernel/, and rename arm_pmu_irq_is_nmi() > > > > > to arch_pmu_irq_is_nmi() for cross-arch reusability. > > > > > > > > > > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com> > > > > > --- > > > > > arch/arm64/kernel/Makefile | 1 - > > > > > drivers/perf/arm_pmu.c | 2 +- > > > > > include/linux/nmi.h | 1 + > > > > > include/linux/perf/arm_pmu.h | 2 -- > > > > > kernel/Makefile | 2 +- > > > > > {arch/arm64/kernel => kernel}/watchdog_hld.c | 8 ++++++-- > > > > > 6 files changed, 9 insertions(+), 7 deletions(-) > > > > > rename {arch/arm64/kernel => kernel}/watchdog_hld.c (97%) > > > > > > > > I'm not a huge fan of the perf hardlockup detector and IMO we should > > > > maybe just delete it. Thus spreading it to support a new architecture > > > > isn't my favorite thing to do. Can't you use the buddy hardlockup > > > > detector? > > > > > > Why is there a plan to remove CONFIG_HARDLOCKUP_DETECTOR_PERF? Could > > > you explain the specific reasons? Is the community's future plan to > > > favor CONFIG_HARDLOCKUP_DETECTOR_BUDDY? > > > > I don't think there are any concrete plans, but there was some discussion here: > > > > https://lore.kernel.org/all/CAD=FV=WWUiCi6bZCs_gseFpDDWNkuJMoL6XCftEo6W7q6jRCkg@mail.gmail.com/ > > > > -Doug > > > > I’ve read your linked content, which details the pros and cons of perf > watchdog and buddy watchdog. > I think everyone will agree on choosing one as the default. > It seems there’s no kernel/watchdog entry in MAINTAINERS—what’s next > for these two approaches? I guess to start, someone (you?) should send some patches to the list. Maybe one patch to make buddy the default and one to change the description of the "perf" lockup detector say that its usage is discouraged, that it might be removed, that people should use the "buddy" detector instead, and that if there's a reason someone needs the "perf" detector instead of the buddy one then they should make some loud noises. You'd want to CC folks who were involved in recent watchdog changes and make sure to CC Andrew (akpm). If folks react positive and Andrew agrees then he'll likely land the the patches and we'll have made forward progress. :-) -Doug
On Fri, Sep 5, 2025 at 4:57 PM Doug Anderson <dianders@chromium.org> wrote: > > Hi, > > On Wed, Sep 3, 2025 at 4:56 AM yunhui cui <cuiyunhui@bytedance.com> wrote: > > I’ve read your linked content, which details the pros and cons of perf > > watchdog and buddy watchdog. > > I think everyone will agree on choosing one as the default. > > It seems there’s no kernel/watchdog entry in MAINTAINERS—what’s next > > for these two approaches? > > I guess to start, someone (you?) should send some patches to the list. > Maybe one patch to make buddy the default and one to change the > description of the "perf" lockup detector say that its usage is > discouraged, that it might be removed, that people should use the > "buddy" detector instead, and that if there's a reason someone needs > the "perf" detector instead of the buddy one then they should make > some loud noises. > > You'd want to CC folks who were involved in recent watchdog changes > and make sure to CC Andrew (akpm). If folks react positive and Andrew > agrees then he'll likely land the the patches and we'll have made > forward progress. :-) +1 There are also things like /proc/sys/kernel/nmi_watchdog being used to enable/disable the hard lookup detector. If we could move that to a unique file so that perf is less confused in places like: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/util.c#n70 ie. perf shouldn't warn about the NMI watchdog being enabled and taking a perf event when it doesn't. Thanks, Ian
Hi, On Mon, Sep 8, 2025 at 7:15 AM Ian Rogers <irogers@google.com> wrote: > > On Fri, Sep 5, 2025 at 4:57 PM Doug Anderson <dianders@chromium.org> wrote: > > > > Hi, > > > > On Wed, Sep 3, 2025 at 4:56 AM yunhui cui <cuiyunhui@bytedance.com> wrote: > > > I’ve read your linked content, which details the pros and cons of perf > > > watchdog and buddy watchdog. > > > I think everyone will agree on choosing one as the default. > > > It seems there’s no kernel/watchdog entry in MAINTAINERS—what’s next > > > for these two approaches? > > > > I guess to start, someone (you?) should send some patches to the list. > > Maybe one patch to make buddy the default and one to change the > > description of the "perf" lockup detector say that its usage is > > discouraged, that it might be removed, that people should use the > > "buddy" detector instead, and that if there's a reason someone needs > > the "perf" detector instead of the buddy one then they should make > > some loud noises. > > > > You'd want to CC folks who were involved in recent watchdog changes > > and make sure to CC Andrew (akpm). If folks react positive and Andrew > > agrees then he'll likely land the the patches and we'll have made > > forward progress. :-) > > +1 Okay, I intend to directly send a patch that removes HARDLOCKUP_DETECTOR_PERF, and then we can discuss on that patch. > > There are also things like /proc/sys/kernel/nmi_watchdog being used to > enable/disable the hard lookup detector. If we could move that to a > unique file so that perf is less confused in places like: > https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/util.c#n70 > ie. perf shouldn't warn about the NMI watchdog being enabled and > taking a perf event when it doesn't. Okay, let's first take a look at the status of the discussion on the patch for removing HARDLOCKUP_DETECTOR_PERF, and then we'll modify this part. > > Thanks, > Ian Thanks, Yunhui
© 2016 - 2025 Red Hat, Inc.