linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] watchdog: Don't need a definition of the perf fallback-attr
@ 2025-07-27  3:25 Qing Wong
  2025-08-09  4:07 ` Qing Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Qing Wong @ 2025-07-27  3:25 UTC (permalink / raw)
  To: peterz, linux-kernel; +Cc: mingo, akpm, song, Qing Wang

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] watchdog: Don't need a definition of the perf fallback-attr
  2025-07-27  3:25 [PATCH] watchdog: Don't need a definition of the perf fallback-attr Qing Wong
@ 2025-08-09  4:07 ` Qing Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Qing Wang @ 2025-08-09  4:07 UTC (permalink / raw)
  To: peterz, linux-kernel; +Cc: mingo, akpm, song

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);
>   	}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-09  4:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-27  3:25 [PATCH] watchdog: Don't need a definition of the perf fallback-attr Qing Wong
2025-08-09  4:07 ` Qing Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).