kernel/watchdog_perf.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
From: Qing Wang <wangqing7171@gmail.com>
The 'hardlockup_config_perf_event()' only overwrites the type and
config of the perf attr. It's wasteful that redefining a big static
variable to fallback. It’s just a matter of simply fallback these
two variables.
Signed-off-by: Qing Wang <wangqing7171@gmail.com>
---
kernel/watchdog_perf.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/kernel/watchdog_perf.c b/kernel/watchdog_perf.c
index 75af12ff774e..08b9acbd2aa4 100644
--- a/kernel/watchdog_perf.c
+++ b/kernel/watchdog_perf.c
@@ -92,14 +92,6 @@ static struct perf_event_attr wd_hw_attr = {
.disabled = 1,
};
-static struct perf_event_attr fallback_wd_hw_attr = {
- .type = PERF_TYPE_HARDWARE,
- .config = PERF_COUNT_HW_CPU_CYCLES,
- .size = sizeof(struct perf_event_attr),
- .pinned = 1,
- .disabled = 1,
-};
-
/* Callback function for perf event subsystem */
static void watchdog_overflow_callback(struct perf_event *event,
struct perf_sample_data *data,
@@ -114,6 +106,12 @@ static void watchdog_overflow_callback(struct perf_event *event,
watchdog_hardlockup_check(smp_processor_id(), regs);
}
+static void fallback_wd_hw_attr(void)
+{
+ wd_hw_attr.type = PERF_TYPE_HARDWARE;
+ wd_hw_attr.config = PERF_COUNT_HW_CPU_CYCLES;
+}
+
static int hardlockup_detector_event_create(void)
{
unsigned int cpu;
@@ -133,8 +131,7 @@ static int hardlockup_detector_event_create(void)
evt = perf_event_create_kernel_counter(wd_attr, cpu, NULL,
watchdog_overflow_callback, NULL);
if (IS_ERR(evt)) {
- wd_attr = &fallback_wd_hw_attr;
- wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh);
+ fallback_wd_hw_attr();
evt = perf_event_create_kernel_counter(wd_attr, cpu, NULL,
watchdog_overflow_callback, NULL);
}
--
2.43.0
Hello, PING. Thanks, Qing. On 7/27/2025 11:25 AM, Qing Wong wrote: > From: Qing Wang <wangqing7171@gmail.com> > > The 'hardlockup_config_perf_event()' only overwrites the type and > config of the perf attr. It's wasteful that redefining a big static > variable to fallback. It’s just a matter of simply fallback these > two variables. > > Signed-off-by: Qing Wang <wangqing7171@gmail.com> > --- > kernel/watchdog_perf.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/kernel/watchdog_perf.c b/kernel/watchdog_perf.c > index 75af12ff774e..08b9acbd2aa4 100644 > --- a/kernel/watchdog_perf.c > +++ b/kernel/watchdog_perf.c > @@ -92,14 +92,6 @@ static struct perf_event_attr wd_hw_attr = { > .disabled = 1, > }; > > -static struct perf_event_attr fallback_wd_hw_attr = { > - .type = PERF_TYPE_HARDWARE, > - .config = PERF_COUNT_HW_CPU_CYCLES, > - .size = sizeof(struct perf_event_attr), > - .pinned = 1, > - .disabled = 1, > -}; > - > /* Callback function for perf event subsystem */ > static void watchdog_overflow_callback(struct perf_event *event, > struct perf_sample_data *data, > @@ -114,6 +106,12 @@ static void watchdog_overflow_callback(struct perf_event *event, > watchdog_hardlockup_check(smp_processor_id(), regs); > } > > +static void fallback_wd_hw_attr(void) > +{ > + wd_hw_attr.type = PERF_TYPE_HARDWARE; > + wd_hw_attr.config = PERF_COUNT_HW_CPU_CYCLES; > +} > + > static int hardlockup_detector_event_create(void) > { > unsigned int cpu; > @@ -133,8 +131,7 @@ static int hardlockup_detector_event_create(void) > evt = perf_event_create_kernel_counter(wd_attr, cpu, NULL, > watchdog_overflow_callback, NULL); > if (IS_ERR(evt)) { > - wd_attr = &fallback_wd_hw_attr; > - wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh); > + fallback_wd_hw_attr(); > evt = perf_event_create_kernel_counter(wd_attr, cpu, NULL, > watchdog_overflow_callback, NULL); > }
© 2016 - 2025 Red Hat, Inc.