[PATCH v7 3/7] timers: Use scoped_guard when setting/clearing the tmigr available flag
From: Gabriele Monaco
Date: Thu Jun 26 2025 - 07:52:38 EST
Cleanup tmigr_clear_cpu_available() and tmigr_set_cpu_available() to
prepare for easier checks on the available flag.
Signed-off-by: Gabriele Monaco <gmonaco@xxxxxxxxxx>
---
kernel/time/timer_migration.c | 38 +++++++++++++++++------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c
index 2ec003c2bbbea..a51af4acc5e3c 100644
--- a/kernel/time/timer_migration.c
+++ b/kernel/time/timer_migration.c
@@ -1449,18 +1449,18 @@ static int tmigr_clear_cpu_available(unsigned int cpu)
int migrator;
u64 firstexp;
- raw_spin_lock_irq(&tmc->lock);
- tmc->available = false;
- WRITE_ONCE(tmc->wakeup, KTIME_MAX);
- cpumask_clear_cpu(cpu, tmigr_available_cpumask);
+ scoped_guard(raw_spinlock_irq, &tmc->lock) {
+ tmc->available = false;
+ WRITE_ONCE(tmc->wakeup, KTIME_MAX);
+ cpumask_clear_cpu(cpu, tmigr_available_cpumask);
- /*
- * 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);
@@ -1478,14 +1478,14 @@ static int tmigr_set_cpu_available(unsigned int cpu)
if (WARN_ON_ONCE(!tmc->tmgroup))
return -EINVAL;
- 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;
- cpumask_set_cpu(cpu, tmigr_available_cpumask);
- 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;
+ cpumask_set_cpu(cpu, tmigr_available_cpumask);
+ }
return 0;
}
--
2.49.0