[RESEND PATCH v13 4/9] timers: Use scoped_guard when setting/clearing the tmigr available flag

Gabriele Monaco
2025-10-20T11:28:24Z

Cleanup tmigr_clear_cpu_available() and tmigr_set_cpu_available() to
prepare for easier checks on the available flag.

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
kernel/time/timer_migration.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c
index 865071ab5062..0a3a26e766d0 100644
--- a/kernel/time/timer_migration.c
+++ b/kernel/time/timer_migration.c
@@ -1450,17 +1450,17 @@ static int tmigr_clear_cpu_available(unsigned int cpu)
u64 firstexp;

cpumask_clear_cpu(cpu, tmigr_available_cpumask);
- raw_spin_lock_irq(&tmc->lock);
- tmc->available = false;
- WRITE_ONCE(tmc->wakeup, KTIME_MAX);
+ scoped_guard(raw_spinlock_irq, &tmc->lock) {
+ tmc->available = false;
+ WRITE_ONCE(tmc->wakeup, KTIME_MAX);

- /*
- * CPU has to handle the local events on his own, when on the way to
- * offline; Therefore nextevt value is set to KTIME_MAX
- */
- firstexp = __tmigr_cpu_deactivate(tmc, KTIME_MAX);
- trace_tmigr_cpu_unavailable(tmc);
- raw_spin_unlock_irq(&tmc->lock);
+ /*
+ * CPU has to handle the local events on his own, when on the way to
+ * offline; Therefore nextevt value is set to KTIME_MAX
+ */
+ firstexp = __tmigr_cpu_deactivate(tmc, KTIME_MAX);
+ trace_tmigr_cpu_unavailable(tmc);
+ }

if (firstexp != KTIME_MAX) {
migrator = cpumask_any(tmigr_available_cpumask);
@@ -1479,13 +1479,13 @@ static int tmigr_set_cpu_available(unsigned int cpu)
return -EINVAL;

cpumask_set_cpu(cpu, tmigr_available_cpumask);
- raw_spin_lock_irq(&tmc->lock);
- trace_tmigr_cpu_available(tmc);
- tmc->idle = timer_base_is_idle();
- if (!tmc->idle)
- __tmigr_cpu_activate(tmc);
- tmc->available = true;
- raw_spin_unlock_irq(&tmc->lock);
+ scoped_guard(raw_spinlock_irq, &tmc->lock) {
+ trace_tmigr_cpu_available(tmc);
+ tmc->idle = timer_base_is_idle();
+ if (!tmc->idle)
+ __tmigr_cpu_activate(tmc);
+ tmc->available = true;
+ }
return 0;
}

--
2.51.0