From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B78C3A63EB for ; Tue, 24 Feb 2026 16:37:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771951027; cv=none; b=JBvb4L/49qZWSuj8sOJE11s4CRoUBnYwIF22ntkEwtuMdif5kk2YWSjdCejIvwYu9cG1aD1LtJPzAFSdvLhLMcr/jYzBBwtw/79BJEnb0JiydpS2Fzi8fmqTXa4KaIicIaEnZszU8F2By4zRW9W3rUaJ7D4lL+r2ZuWacbbc6ls= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771951027; c=relaxed/simple; bh=TziM9q0N7YYDBX5sc27kUykYVPLf7kEjYe5jWDOaQ9A=; h=Date:Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=X2wMQ8624TL9MNJTBY+6zIPSw35JNPQTosCNv4U+NoB3J+OVR7DNkakpiM/Pc+D6yL5D8thAszEMsZqT0iE6+tKiFu+I04MoXmdUFrOy1x09VXoSaQzH+CFoccGSJ5FdQrjcVpiXsoINgOxuKriUYqZteBE7R5601caaTEt+8RA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wc3HhJ1E; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wc3HhJ1E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6198C19422; Tue, 24 Feb 2026 16:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771951027; bh=TziM9q0N7YYDBX5sc27kUykYVPLf7kEjYe5jWDOaQ9A=; h=Date:From:To:Cc:Subject:References:From; b=Wc3HhJ1E1t7WifNMksPtbd8QenzP0iXvxN8wuQF3vslaBRCBplcu5j9Gy+lXSRD1N c1A45I8f/O85o3pI7MFBzg7lCtlHgmPH2EMy9eSIoLRjYRLXK2FLdy4CVL6C8flBOX 42UrRUdpxPo1kvsG1SgFskdcO5ZfpIf5dD+UIv3cRBY/QEwS31DLo86eDKbsNgSfrZ jRDcpzFGyIka9TUKn0JSp+Y+QaJyQ0Dk2uDpQzl8DWCk2QYZunMFznydafjIbvb7i0 fp+qefQwEOgjoUNJbYSd/I55Pfql0Zb4PANKgZCJhlD1Nf3n0uasyCcVcj1QVoHxu1 SkxkME9tmksWA== Date: Tue, 24 Feb 2026 17:37:04 +0100 Message-ID: <20260224163430.275551488@kernel.org> User-Agent: quilt/0.68 From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , John Stultz , Stephen Boyd , Daniel Lezcano , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , x86@kernel.org, Peter Zijlstra , Frederic Weisbecker , Eric Dumazet Subject: [patch 23/48] hrtimer: Use guards where appropriate References: <20260224163022.795809588@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Simplify and tidy up the code where possible. Signed-off-by: Thomas Gleixner --- kernel/time/hrtimer.c | 48 +++++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 33 deletions(-) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -838,13 +838,12 @@ static void retrigger_next_event(void *a * In periodic low resolution mode, the next softirq expiration * must also be updated. */ - raw_spin_lock(&base->lock); + guard(raw_spinlock)(&base->lock); hrtimer_update_base(base); if (hrtimer_hres_active(base)) hrtimer_force_reprogram(base, 0); else hrtimer_update_next_event(base); - raw_spin_unlock(&base->lock); } /* @@ -994,7 +993,6 @@ static bool update_needs_ipi(struct hrti void clock_was_set(unsigned int bases) { cpumask_var_t mask; - int cpu; if (!hrtimer_highres_enabled() && !tick_nohz_is_active()) goto out_timerfd; @@ -1005,24 +1003,19 @@ void clock_was_set(unsigned int bases) } /* Avoid interrupting CPUs if possible */ - cpus_read_lock(); - for_each_online_cpu(cpu) { - struct hrtimer_cpu_base *cpu_base; - unsigned long flags; + scoped_guard(cpus_read_lock) { + int cpu; - cpu_base = &per_cpu(hrtimer_bases, cpu); - raw_spin_lock_irqsave(&cpu_base->lock, flags); + for_each_online_cpu(cpu) { + struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu); - if (update_needs_ipi(cpu_base, bases)) - cpumask_set_cpu(cpu, mask); - - raw_spin_unlock_irqrestore(&cpu_base->lock, flags); + guard(raw_spinlock_irqsave)(&cpu_base->lock); + if (update_needs_ipi(cpu_base, bases)) + cpumask_set_cpu(cpu, mask); + } + scoped_guard(preempt) + smp_call_function_many(mask, retrigger_next_event, NULL, 1); } - - preempt_disable(); - smp_call_function_many(mask, retrigger_next_event, NULL, 1); - preempt_enable(); - cpus_read_unlock(); free_cpumask_var(mask); out_timerfd: @@ -1600,15 +1593,11 @@ u64 hrtimer_get_next_event(void) { struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases); u64 expires = KTIME_MAX; - unsigned long flags; - - raw_spin_lock_irqsave(&cpu_base->lock, flags); + guard(raw_spinlock_irqsave)(&cpu_base->lock); if (!hrtimer_hres_active(cpu_base)) expires = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_ALL); - raw_spin_unlock_irqrestore(&cpu_base->lock, flags); - return expires; } @@ -1623,25 +1612,18 @@ u64 hrtimer_next_event_without(const str { struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases); u64 expires = KTIME_MAX; - unsigned long flags; - - raw_spin_lock_irqsave(&cpu_base->lock, flags); + guard(raw_spinlock_irqsave)(&cpu_base->lock); if (hrtimer_hres_active(cpu_base)) { unsigned int active; if (!cpu_base->softirq_activated) { active = cpu_base->active_bases & HRTIMER_ACTIVE_SOFT; - expires = __hrtimer_next_event_base(cpu_base, exclude, - active, KTIME_MAX); + expires = __hrtimer_next_event_base(cpu_base, exclude, active, KTIME_MAX); } active = cpu_base->active_bases & HRTIMER_ACTIVE_HARD; - expires = __hrtimer_next_event_base(cpu_base, exclude, active, - expires); + expires = __hrtimer_next_event_base(cpu_base, exclude, active, expires); } - - raw_spin_unlock_irqrestore(&cpu_base->lock, flags); - return expires; } #endif