Skip to contentSkip to conversation

watchdog: Don't need a definition of the perf fallback-attr

PATCH In review Qing Wong 1 participant 2 messages Jul 27, 2025 – Aug 9, 2025

lore
Share & tools
lore

Qing Wong

author
#0 lore raw

PATCH 1/1 watchdog: Don't need a definition of the perf fallback-attr

From: Qing Wang <[email protected]>

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.

---
 kernel/watchdog_perf.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
kernel/watchdog_perf.c +7 -10
index 75af12ff774e..08b9acbd2aa4 100644
@@ -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);
 	}
Signature · 1 line
2.43.0
author
#1 lore raw

Hello,

PING.

Thanks,
Qing.

Quoted 54 lines · Qing Wong

From: Qing Wang <[email protected]>

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.

---
  kernel/watchdog_perf.c | 17 +++++++----------
  1 file changed, 7 insertions(+), 10 deletions(-)
kernel/watchdog_perf.c +7 -10
index 75af12ff774e..08b9acbd2aa4 100644
@@ -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);
  	}