Skip to contentSkip to conversation

clocksource: Use better cpumask API where appropriate

PATCH RESEND Applied Yury Norov 3 participants 6 messages Jun 14, 2025 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore

Yury Norov

author
#0 lore raw

cover clocksource: Use better cpumask API where appropriate

From: Yury Norov [NVIDIA] <[email protected]>

The dedicated API works better and improves on readability

Resend: drop 'fix opencoded...' wording (Tomas)
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Yury Norov [NVIDIA] (2):
clocksource: Use cpumask_any_but() in clocksource_verify_choose_cpus()
clocksource: Use cpumask_next_wrap() in clocksource_watchdog()

 kernel/time/clocksource.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 clocksource: Use cpumask_any_but() in clocksource_verify_choose_cpus()

From: "Yury Norov [NVIDIA]" <[email protected]>

cpumask_any_but() is more verbose than cpumask_first() followed by cpumask_next(). Use it in clocksource_verify_choose_cpus().

---
 kernel/time/clocksource.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/time/clocksource.c +1 -3
index 6a8bc7da9062..a2f2e9f4d37b 100644
@@ -323,9 +323,7 @@ static void clocksource_verify_choose_cpus(void)
 		return;
 
 	/* Make sure to select at least one CPU other than the current CPU. */
-	cpu = cpumask_first(cpu_online_mask);
-	if (cpu == smp_processor_id())
-		cpu = cpumask_next(cpu, cpu_online_mask);
+	cpu = cpumask_any_but(cpu_online_mask, smp_processor_id());
 	if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
 		return;
 	cpumask_set_cpu(cpu, &cpus_chosen);
Signature · 1 line
2.43.0
#2 lore raw

[tip: timers/core] clocksource: Use cpumask_any_but() in clocksource_verify_choose_cpus()

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     4fa7d61d5a02ad57a05c69365db293afddf678fc
Gitweb:        https://git.kernel.org/tip/4fa7d61d5a02ad57a05c69365db293afddf678fc
Author:        Yury Norov [NVIDIA] <[email protected]>
AuthorDate:    Sat, 14 Jun 2025 11:50:29 -04:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sat, 14 Jun 2025 20:09:44 +02:00

clocksource: Use cpumask_any_but() in clocksource_verify_choose_cpus()

cpumask_any_but() is more verbose than cpumask_first() followed by cpumask_next(). Use it in clocksource_verify_choose_cpus().

---
 kernel/time/clocksource.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/time/clocksource.c +1 -3
index 6a8bc7d..a2f2e9f 100644
@@ -323,9 +323,7 @@ static void clocksource_verify_choose_cpus(void)
 		return;
 
 	/* Make sure to select at least one CPU other than the current CPU. */
-	cpu = cpumask_first(cpu_online_mask);
-	if (cpu == smp_processor_id())
-		cpu = cpumask_next(cpu, cpu_online_mask);
+	cpu = cpumask_any_but(cpu_online_mask, smp_processor_id());
 	if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
 		return;
 	cpumask_set_cpu(cpu, &cpus_chosen);
author
#3 lore raw

PATCH 2/2 clocksource: Use cpumask_next_wrap() in clocksource_watchdog()

In reply to Yury Norov

From: "Yury Norov [NVIDIA]" <[email protected]>

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

---
 kernel/time/clocksource.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/time/clocksource.c +1 -3
index a2f2e9f4d37b..e400fe150f9d 100644
@@ -587,9 +587,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
Signature · 1 line
2.43.0
#4 lore raw

[tip: timers/core] clocksource: Use cpumask_next_wrap() in clocksource_watchdog()

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     bfa788dc2ddaea7d7930f63a5c7c8f3668a3f2c5
Gitweb:        https://git.kernel.org/tip/bfa788dc2ddaea7d7930f63a5c7c8f3668a3f2c5
Author:        Yury Norov [NVIDIA] <[email protected]>
AuthorDate:    Sat, 14 Jun 2025 11:50:30 -04:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sat, 14 Jun 2025 20:09:44 +02:00

clocksource: Use cpumask_next_wrap() in clocksource_watchdog()

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

---
 kernel/time/clocksource.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/time/clocksource.c +1 -3
index a2f2e9f..e400fe1 100644
@@ -587,9 +587,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
#5 lore raw
In reply to Yury Norov
Quoted 5 lines · Yury Norov

From: Yury Norov [NVIDIA] <[email protected]>

The dedicated API works better and improves on readability

Resend: drop 'fix opencoded...' wording (Tomas)

This is not a resend as you changed the change log, so it's V3.

Resend is only for unmodified versions where you got no feedback and did not change anything.

And in the RESEND case you have to keep the version number so stuff can be identified as resend of a particular version.

People have scripts which depend on submitters following the rules. Chasing stuff by hand is just waste of time.

Thanks,

tglx