[PATCH 2/2] clocksource: fix opencoded cpumask_next_wrap()

Yury Norov posted 2 patches 6 months, 2 weeks ago
[PATCH 2/2] clocksource: fix opencoded cpumask_next_wrap()
Posted by Yury Norov 6 months, 2 weeks ago
From: Yury Norov [NVIDIA] <yury.norov@gmail.com>

cpumask_next_wrap() is more verbose and efficient comparing to
cpumask_next() followed by cpumask_first().

Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
---
 kernel/time/clocksource.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 2e24ce884272..0aef0e349e49 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -584,9 +584,7 @@ static void clocksource_watchdog(struct timer_list *unused)
 	 * Cycle through CPUs to check if the CPUs stay synchronized
 	 * to each other.
 	 */
-	next_cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask);
-	if (next_cpu >= nr_cpu_ids)
-		next_cpu = cpumask_first(cpu_online_mask);
+	next_cpu = cpumask_next_wrap(raw_smp_processor_id(), cpu_online_mask);
 
 	/*
 	 * Arm timer if not already pending: could race with concurrent
-- 
2.43.0
Re: [PATCH 2/2] clocksource: fix opencoded cpumask_next_wrap()
Posted by John Stultz 6 months, 2 weeks ago
On Wed, Jun 4, 2025 at 4:25 PM Yury Norov <yury.norov@gmail.com> wrote:
>
> From: Yury Norov [NVIDIA] <yury.norov@gmail.com>
>
> cpumask_next_wrap() is more verbose and efficient comparing to
> cpumask_next() followed by cpumask_first().
>
> Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
> ---
>  kernel/time/clocksource.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
> index 2e24ce884272..0aef0e349e49 100644
> --- a/kernel/time/clocksource.c
> +++ b/kernel/time/clocksource.c
> @@ -584,9 +584,7 @@ static void clocksource_watchdog(struct timer_list *unused)
>          * Cycle through CPUs to check if the CPUs stay synchronized
>          * to each other.
>          */
> -       next_cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask);
> -       if (next_cpu >= nr_cpu_ids)
> -               next_cpu = cpumask_first(cpu_online_mask);
> +       next_cpu = cpumask_next_wrap(raw_smp_processor_id(), cpu_online_mask);
>

This looks ok to me. The only nit is that often folks like to see the
$Subject line look like:
  $topic: Capitalized description.

So for this one:
  clocksource: Fix opencoded cpumask_next_wrap()

Acked-by: John Stultz <jstultz@google.com>
thanks
-john