From patchwork Wed Feb 21 09:05:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 204033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp919368dyc; Wed, 21 Feb 2024 01:10:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVlE6ry17A33H3d1Cvogz4vUX6sosZ4mlpvI3IxNc4tY+TxdfZeXNxjO4oMujNQodY40D/dF5GKiwkgy9pJIRX+fl3o8w== X-Google-Smtp-Source: AGHT+IFNbOekbbtztlFoCpJBmWzzSIxgqNpI9RDCe4yfzm94Hf9/ChnbdQIk8X9KJyPQiypn/Mtb X-Received: by 2002:a05:622a:1747:b0:42d:a88f:1cf6 with SMTP id l7-20020a05622a174700b0042da88f1cf6mr21388514qtk.5.1708506603182; Wed, 21 Feb 2024 01:10:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708506603; cv=pass; d=google.com; s=arc-20160816; b=E1uA7sD8pkwNdFMIFSjv67Iu3jysW+zWGeiVgsr9Azd42uKdXKSkpFboaUHLBsTQG3 PkjjgfpHTbuz7h9/cLfs1I5Mut5Y6q23VcJeaw2JAmleOe5jGZPPTxxVQn/VqKfGXwaH 53+goMscO4rlWs7Rvtm7L07esYOcjkkh41TAM7EAxXosx2+Jjhsvpkb+O6UsLt5NUy/H 8nz8UXVexFrXvWEWLFxCY/3xFdDbnd5yyiYHqkdzm0gHhWCWvPB8B44WG5zKALO6+1hv RrlEfj0V1YVcVmB8pfHpl5sGxtezs6DqaMefCKV+0TKNtLWhYHuVQ3kA67jKTeFwAAP/ 9pbA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=tVCrlgF3mrMVRn6VCmTujRoLZ7e8Pe7/0fX1s066Dis=; fh=N5fTIFf2i7nvF8Om7kdprA8Zy2dleTNav/f0ArIISzo=; b=wQcBS+HRZVarbstobtG91B99+/4sir4gwfVD4vnpnD2ulVHbDnH1y3zrwCmg7wd68n kvIcul/6LrTDSrqCdDRg2SYWLSNu3brepOBz1JrYZ0CSpBPcMLGqKlbPc9E3VPfou0PA 6viOtxK3h54O4yWlwN1T4McXQq1Fwq0aDBmS3A4vC3yvQ3MqnPTKNhj5ZS2drRvSdZoE slwDzFcxkvjevAbVlC9r05RGNeSlBzdQP5+F12/VVR/tHB6i6p8KP7fyKyMdOUmTidAF j2VYjNCtYiUKO6TaRpHIBVfz0R8HXzRPzrKMjSNE+pMa5e1kJ0M8iqWLZRB8yaJBpWBA v3jg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UauhkFtN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-74354-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74354-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j13-20020ac85f8d000000b0042e3fe7ff8dsi59211qta.203.2024.02.21.01.10.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 01:10:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74354-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UauhkFtN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-74354-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74354-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E43181C22F0C for ; Wed, 21 Feb 2024 09:10:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08E0745014; Wed, 21 Feb 2024 09:06:26 +0000 (UTC) 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" 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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791499019927847242 X-GMAIL-MSGID: 1791499019927847242 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 expires) return DIV_ROUND_UP_ULL(nextevt, TICK_NSEC) * TICK_NSEC; } +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 = basej + NEXT_TIMER_MAX_DELTA; + + return base->next_expiry; +} + static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, bool *idle) { struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); - unsigned long nextevt = basej + NEXT_TIMER_MAX_DELTA; u64 expires = KTIME_MAX; + unsigned long nextevt; /* * Pretend that there is no timer pending if the cpu is offline. @@ -1969,24 +1986,13 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, } raw_spin_lock(&base->lock); - if (base->next_expiry_recalc) - next_expiry_recalc(base); + nextevt = next_timer_interrupt(base, basej); if (base->timers_pending) { - nextevt = base->next_expiry; - /* If we missed a tick already, force 0 delta */ if (time_before(nextevt, basej)) nextevt = basej; expires = 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 = nextevt; } /*