From patchwork Thu Feb 22 17:12:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 204874 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp82582dyb; Thu, 22 Feb 2024 09:13:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVJz//PEeE+U7FXp36gga2WaGXviceybbSLDMlnBzl/b14E5z7rHzr4vnxbg8jh4siMtpCxFzBXTKVxhJKE4gGFwPsCGw== X-Google-Smtp-Source: AGHT+IHpdUmRszXckraxwfFNlZF9TAXhQ5tsHQOr+S0cahi3Qk0UR7VBrEb1gMjOWEsZiQ3CTVLB X-Received: by 2002:a17:902:a507:b0:1db:2ad9:9393 with SMTP id s7-20020a170902a50700b001db2ad99393mr18047732plq.48.1708622024083; Thu, 22 Feb 2024 09:13:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708622024; cv=pass; d=google.com; s=arc-20160816; b=r2qEXXB89bhqm3pEPFC/TNwhn+t480l/8WCOd9qvm20J7vnY3rg8nx72Q8eA2GxxPd FTAoEM3UQVp+Kn7qjt73KR6MOyhpGdSQFloLcEBuOXdLCJ7oazBDl6veEMs3gPhyjKiB dpUAE/LB+vFNi1ltHsesaFb8uXcwVDNBfDxxlKqs/muqZ+BDYowYHHXq8fvXQ2T7Uqwf qp8O/lvKC2meLBguUPCOEm05fookxwcSvqfo2vCuoCzEe4IVU3pcQ2hnz/E99uFaeMaL 43wDYVZ5QEJTEJkFaNolwEE8+P2aXGQ3spjaw78v2cxgtP6D6aFkaKHr1q5irFz996NN InXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=pLn33LD8Qj/C95HP7uinFUBZxJe0QSWpPvGr/HdBU/A=; fh=5HLJN1TJcWBAEXmgE4Q1wVLXykLWOFKyiYUuaJ2RJpM=; b=SaP2BEYGRL4N1pPx58HDqQ03G4+ezNF0hezm3tS7fHHxnVksrbK81x39fFq9BluZYt hs0UmDs5pO5xDl6CPPY/DQwJ7TB3ahx3fKOLRM0dkiDOiNtGEkkaCcBVJKwQNCdtwWoi 69MA4SVW+jOoI2lNrb4Jqgu1yhLNp3vFT985wbBHSEvArM/7iUgpZC9ffoLIo3EK06tK +Q+QS4iom6fo564mJhS7Wn8eSWvfipD+vcrNSO6GEDNA6e4tMcFYhuZU2qF0ZLMTX7Df EIphxZ2V2cZCzRB02xY0ZU+UYcZAO22udxzS1nYtWo5GqevVA60O3fXrULcGyJNDXbGZ OfDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zAI9ZvpB; 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-76938-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76938-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w4-20020a170902e88400b001dc0e6db066si6351050plg.394.2024.02.22.09.13.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 09:13:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76938-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zAI9ZvpB; 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-76938-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76938-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7B6BA28B5C2 for ; Thu, 22 Feb 2024 17:13:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7EBE1586F5; Thu, 22 Feb 2024 17:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zAI9ZvpB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jM6gd+8y" 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 4040C15531F; Thu, 22 Feb 2024 17:12:10 +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=1708621932; cv=none; b=ZvDl3I89EI1GuwTJ55S3GprbKZi4omSCRBfgYj7mP+2jA11EHizl4PZ0ZQq8vtE5r+NUmIP7can2zhlI5g09VTEeINxaiv7zLtA7KT2WMu2vBFm+tXmee0mVEJwSiQMLnEf8/lTalQHWjXRcpOPxl3zclGE2hlfN/qCimYIOV2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708621932; c=relaxed/simple; bh=iz/0atIqVTkjNZkdwKWQy3RNapr8HgTKcqdSsz0XKuU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=hA5as4gyyWlvilJNno/TZyVQOE8FGat7lrJgZeuf7lkVoVmWvvqUlOZqJ/rnTED/HFMwOkp2sDW3yXRXKmKn2IwIpWE9gB1tp1G2WAbqvMufhD/apxbnFtxR2TFiBotcMNArck9xvZ3I6nrOuk9kcb093JDhFaJfpn7g+V9rMvw= 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=zAI9ZvpB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jM6gd+8y; 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 Date: Thu, 22 Feb 2024 17:12:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708621929; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pLn33LD8Qj/C95HP7uinFUBZxJe0QSWpPvGr/HdBU/A=; b=zAI9ZvpBUdtZ062Degjl1ue8dKg2SOLUqiyk1j9o9wPcTGeScbD/E1FsDiXRbONNVtyYdd cfyXeT1EEZ0EVq7Wqkp2DjtlwH7h4WQSjqLRISVxvr2vuj0661ZRo4DXi8QA/I9LXt5ljX ghV/7g0ROGp4ub3juVvNtn7EqrExucTZAylT73UVKvoLoBNYHKwRyYer3dQiI5ekGdXxgA 6pXQr6KzAU0I3NULGlW1tuXo+0DXXsIKq5AHWvgs6j0f+K7FN+Gy0Di5dQ1ZAgXA0CnS+9 kUpTT+A8soRZdRAEFbqgZpUWkccyhUCMODec5HDYogDr0tLyT55V9il8DmiwHw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708621929; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pLn33LD8Qj/C95HP7uinFUBZxJe0QSWpPvGr/HdBU/A=; b=jM6gd+8y96z0tlHPuuzRSCvS8ybYFx2WNZaicqGxcg/9RpHEx39rXU6/l1bagc4Oc4FiI/ aaIg+zrV+c8e1DBw== From: "tip-bot2 for Richard Cochran (linutronix GmbH)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] timers: Restructure internal locking Cc: "Richard Cochran (linutronix GmbH)" , "Anna-Maria Behnsen" , Thomas Gleixner , Frederic Weisbecker , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240221090548.36600-15-anna-maria@linutronix.de> References: <20240221090548.36600-15-anna-maria@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170862192867.398.3423551157545120676.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791499098836356220 X-GMAIL-MSGID: 1791620047159710397 The following commit has been merged into the timers/core branch of tip: Commit-ID: 90f5df66c86c259d61aff84e16f519fe1424e1ef Gitweb: https://git.kernel.org/tip/90f5df66c86c259d61aff84e16f519fe1424e1ef Author: Richard Cochran (linutronix GmbH) AuthorDate: Wed, 21 Feb 2024 10:05:42 +01:00 Committer: Thomas Gleixner CommitterDate: Thu, 22 Feb 2024 17:52:31 +01:00 timers: Restructure internal locking Move the locking out from __run_timers() to the call sites, so the protected section can be extended at the call site. Preparatory work for changing the NOHZ timer placement to a pull at expiry time model. No functional change. Signed-off-by: Richard Cochran (linutronix GmbH) Signed-off-by: Anna-Maria Behnsen Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker Link: https://lore.kernel.org/r/20240221090548.36600-15-anna-maria@linutronix.de --- kernel/time/timer.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index bc074c0..51053af 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -2283,11 +2283,7 @@ static inline void __run_timers(struct timer_base *base) struct hlist_head heads[LVL_DEPTH]; int levels; - if (time_before(jiffies, base->next_expiry)) - return; - - timer_base_lock_expiry(base); - raw_spin_lock_irq(&base->lock); + lockdep_assert_held(&base->lock); while (time_after_eq(jiffies, base->clk) && time_after_eq(jiffies, base->next_expiry)) { @@ -2311,21 +2307,36 @@ static inline void __run_timers(struct timer_base *base) while (levels--) expire_timers(base, heads + levels); } +} + +static void __run_timer_base(struct timer_base *base) +{ + if (time_before(jiffies, base->next_expiry)) + return; + + timer_base_lock_expiry(base); + raw_spin_lock_irq(&base->lock); + __run_timers(base); raw_spin_unlock_irq(&base->lock); timer_base_unlock_expiry(base); } +static void run_timer_base(int index) +{ + struct timer_base *base = this_cpu_ptr(&timer_bases[index]); + + __run_timer_base(base); +} + /* * This function runs timers and the timer-tq in bottom half context. */ static __latent_entropy void run_timer_softirq(struct softirq_action *h) { - struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_LOCAL]); - - __run_timers(base); + run_timer_base(BASE_LOCAL); if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) { - __run_timers(this_cpu_ptr(&timer_bases[BASE_GLOBAL])); - __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF])); + run_timer_base(BASE_GLOBAL); + run_timer_base(BASE_DEF); } }