Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] thermal: Fix CPU mask truncation in power limit trace event
@ 2026-10-23  6:07 Hungyu Lin
  2026-10-26 19:22 ` Rafael J. Wysocki (Intel)
  0 siblings, 1 reply; 2+ messages in thread
From: Hungyu Lin @ 2026-10-23  6:07 UTC (permalink / raw)
  To: rafael, daniel.lezcano
  Cc: rui.zhang, lukasz.luba, javi.merino, rostedt, edubezval, linux-pm,
	linux-kernel, Hungyu Lin

num_possible_cpus() counts CPUs, but CPU IDs need not be contiguous.
Using it to size the thermal_power_cpu_limit bitmap can omit CPUs with
higher IDs. For example, possible CPUs 0 and 64 produce an eight-byte
bitmap on a 64-bit system, dropping CPU 64.

Use nr_cpumask_bits for both sizing and copying the bitmap.

Fixes: 6828a4711f99 ("thermal: add trace events to the power allocator governor")
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
 drivers/thermal/thermal_trace.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_trace.h b/drivers/thermal/thermal_trace.h
index df8f4edd6068..2f953fd8289d 100644
--- a/drivers/thermal/thermal_trace.h
+++ b/drivers/thermal/thermal_trace.h
@@ -119,7 +119,7 @@ TRACE_EVENT(thermal_power_cpu_limit,
 	TP_ARGS(cpus, freq, cdev_state, power),
 
 	TP_STRUCT__entry(
-		__bitmask(cpumask, num_possible_cpus())
+		__bitmask(cpumask, nr_cpumask_bits)
 		__field(unsigned int,  freq      )
 		__field(unsigned long, cdev_state)
 		__field(u32,           power     )
@@ -127,7 +127,7 @@ TRACE_EVENT(thermal_power_cpu_limit,
 
 	TP_fast_assign(
 		__assign_bitmask(cpumask, cpumask_bits(cpus),
-				num_possible_cpus());
+				nr_cpumask_bits);
 		__entry->freq = freq;
 		__entry->cdev_state = cdev_state;
 		__entry->power = power;

base-commit: 503bb6e70bbf6304b8113373d09dfffcc4aa9183
-- 
2.43.0


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

* Re: [PATCH] thermal: Fix CPU mask truncation in power limit trace event
  2026-10-23  6:07 [PATCH] thermal: Fix CPU mask truncation in power limit trace event Hungyu Lin
@ 2026-10-26 19:22 ` Rafael J. Wysocki (Intel)
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-10-26 19:22 UTC (permalink / raw)
  To: Hungyu Lin
  Cc: rafael, daniel.lezcano, rui.zhang, lukasz.luba, javi.merino,
	rostedt, edubezval, linux-pm, linux-kernel

On Fri, Oct 23, 2026 at 8:08 AM Hungyu Lin <dennylin0707@gmail.com> wrote:
>
> num_possible_cpus() counts CPUs, but CPU IDs need not be contiguous.
> Using it to size the thermal_power_cpu_limit bitmap can omit CPUs with
> higher IDs. For example, possible CPUs 0 and 64 produce an eight-byte
> bitmap on a 64-bit system, dropping CPU 64.
>
> Use nr_cpumask_bits for both sizing and copying the bitmap.
>
> Fixes: 6828a4711f99 ("thermal: add trace events to the power allocator governor")
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
>  drivers/thermal/thermal_trace.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/thermal_trace.h b/drivers/thermal/thermal_trace.h
> index df8f4edd6068..2f953fd8289d 100644
> --- a/drivers/thermal/thermal_trace.h
> +++ b/drivers/thermal/thermal_trace.h
> @@ -119,7 +119,7 @@ TRACE_EVENT(thermal_power_cpu_limit,
>         TP_ARGS(cpus, freq, cdev_state, power),
>
>         TP_STRUCT__entry(
> -               __bitmask(cpumask, num_possible_cpus())
> +               __bitmask(cpumask, nr_cpumask_bits)
>                 __field(unsigned int,  freq      )
>                 __field(unsigned long, cdev_state)
>                 __field(u32,           power     )
> @@ -127,7 +127,7 @@ TRACE_EVENT(thermal_power_cpu_limit,
>
>         TP_fast_assign(
>                 __assign_bitmask(cpumask, cpumask_bits(cpus),
> -                               num_possible_cpus());
> +                               nr_cpumask_bits);
>                 __entry->freq = freq;
>                 __entry->cdev_state = cdev_state;
>                 __entry->power = power;
>
> base-commit: 503bb6e70bbf6304b8113373d09dfffcc4aa9183
> --

Applied as 7.4-rc material, thanks!

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

end of thread, other threads:[~2026-10-26 19:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23  6:07 [PATCH] thermal: Fix CPU mask truncation in power limit trace event Hungyu Lin
2026-10-26 19:22 ` Rafael J. Wysocki (Intel)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox