From nobody Tue Dec 16 13:54:12 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 B23503D556 for ; Wed, 21 Feb 2024 09:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506380; cv=none; b=Zo3NATDVZPtJdv8mo6cY4e05W0dZ31wj0JqNGo4R/PKES/Uboa9qsxcS7kYgd1UGm3ANpRYQlVMOR2l3rk4TdsIb0mO+NizE0dmWbtzN2IVPO6TZQ/fbYvPVy5+UQX8o3lCRaNCmj8Jxlgc+wEMBY6q/i3sZCACMDKh6GD8acqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506380; c=relaxed/simple; bh=qUk4S9h8Q0/zI9/a+pkUeXQEJ/CkK2JDvQly8qMxVXw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qqfC7OusqtyObnBKZLGpQ1snxXqK0SjrF1m8VntcNagCf4sqfIBv+nk8NWMIzjmWcEyYb/+H6t7EFrCCiIGNw+UOhkGN5Tc3i1uW+V5MPjTi+cR+zC2KYvdZnqow21niI+Y0Eq+tXSxy5PrQDzWQd7lQyZC+PwTVpZ6U5uS1TZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UauhkFtN; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Xw6B4fp4; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UauhkFtN"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Xw6B4fp4" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708506372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tVCrlgF3mrMVRn6VCmTujRoLZ7e8Pe7/0fX1s066Dis=; b=UauhkFtNugJUVAcU2XBXqHgJpEFFzmmYJbalN9Bx5r6lqOQF5mi+ok6kGZQRczwcuMp45o TdYGS2AuQqd+26Yqo7OEgLOgB32vjtdHAK9XmFr8x8yFFuRfkq2IVI84ZuwF3gBZGmuo6Y jkEXZIqwsEHiU5NaQjndBffrWrOcTglHHVvXCGP0VRR+eOPFd3tvDyW8TVo6VOIaieqUrt KNBAyPpuaUtkdwoTd5ClwibvvsxmGq7pgYcF1HJ+oM6CForFA9X5u9gZywu+ykjpXXECis dgIfI6+l1BZ3DJjISCpOseksYX68Vfij+nZlSl/FbIm68tBkQey57PcXddhWwg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708506372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tVCrlgF3mrMVRn6VCmTujRoLZ7e8Pe7/0fX1s066Dis=; b=Xw6B4fp4kN3Srl3jj/CMgV47Uasf86D4P80s5n23HE3qzLv2k0wZP+p/jaKVkkGBIuH1Dn itPtcKAGxKRghNCA== To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , John Stultz , Thomas Gleixner , Eric Dumazet , "Rafael J . Wysocki" , Arjan van de Ven , "Paul E . McKenney" , Frederic Weisbecker , Rik van Riel , Steven Rostedt , Sebastian Siewior , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak , Christian Loehle , Anna-Maria Behnsen Subject: [PATCH v11 09/20] timers: Split next timer interrupt logic Date: Wed, 21 Feb 2024 10:05:37 +0100 Message-Id: <20240221090548.36600-10-anna-maria@linutronix.de> In-Reply-To: <20240221090548.36600-1-anna-maria@linutronix.de> References: <20240221090548.36600-1-anna-maria@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Split the logic for getting next timer interrupt (no matter of recalculated or already stored in base->next_expiry) into a separate function named next_timer_interrupt(). Make it available to local call sites only. No functional change. Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker --- v10: Reword commit message v9: Adapt to the fix for empty timer bases. --- kernel/time/timer.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 793848167852..4d6cf49a2fd1 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1951,12 +1951,29 @@ static u64 cmp_next_hrtimer_event(u64 basem, u64 ex= pires) return DIV_ROUND_UP_ULL(nextevt, TICK_NSEC) * TICK_NSEC; } =20 +static unsigned long next_timer_interrupt(struct timer_base *base, + unsigned long basej) +{ + if (base->next_expiry_recalc) + next_expiry_recalc(base); + + /* + * Move next_expiry for the empty base into the future to prevent an + * unnecessary raise of the timer softirq when the next_expiry value + * will be reached even if there is no timer pending. + */ + if (!base->timers_pending) + base->next_expiry =3D basej + NEXT_TIMER_MAX_DELTA; + + return base->next_expiry; +} + static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 base= m, bool *idle) { struct timer_base *base =3D this_cpu_ptr(&timer_bases[BASE_STD]); - unsigned long nextevt =3D basej + NEXT_TIMER_MAX_DELTA; u64 expires =3D KTIME_MAX; + unsigned long nextevt; =20 /* * Pretend that there is no timer pending if the cpu is offline. @@ -1969,24 +1986,13 @@ static inline u64 __get_next_timer_interrupt(unsign= ed long basej, u64 basem, } =20 raw_spin_lock(&base->lock); - if (base->next_expiry_recalc) - next_expiry_recalc(base); + nextevt =3D next_timer_interrupt(base, basej); =20 if (base->timers_pending) { - nextevt =3D base->next_expiry; - /* If we missed a tick already, force 0 delta */ if (time_before(nextevt, basej)) nextevt =3D basej; expires =3D basem + (u64)(nextevt - basej) * TICK_NSEC; - } else { - /* - * Move next_expiry for the empty base into the future to - * prevent a unnecessary raise of the timer softirq when the - * next_expiry value will be reached even if there is no timer - * pending. - */ - base->next_expiry =3D nextevt; } =20 /* --=20 2.39.2