From patchwork Mon Jan 15 14:37: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: 188190 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1744384dyc; Mon, 15 Jan 2024 06:41:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnjCMGgiOzu6tHYxdyOCLcHVgPx6O1Z2LofeRUkir1FXbmmIJnEZa0Ma7Eh+fuiwmF9Iaz X-Received: by 2002:a05:6a21:1692:b0:19b:250a:57f9 with SMTP id np18-20020a056a21169200b0019b250a57f9mr291934pzb.26.1705329712120; Mon, 15 Jan 2024 06:41:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705329712; cv=none; d=google.com; s=arc-20160816; b=CwM+ETU/9AMKGjGcsqTOmFAuy5nbNq9Kdn7s8pVDSbLzLIdMSW4qlKhHXAA4CVlVdY XCBBVaBhPdOzv4DEqpVNaKwPg3OSLQbMgMzLt0CCFL+0r1nujFIcUCvQon2PXg8iqzKH e8ygm/m8R037EXsvK3CLxiZIkGLbTSGC5lsQdnZCGu9I4T9YmRx2N0911PoSdyBd9PMi 2qFjzbIbriUuKWsKji5RKmskjM3933jtgP6+DJZtupgCeWuanovjOUN5PiH/fxvnrxOF I7SoodhU44bvbzFu/+TufPUPfVXwj7LLsiAsMxwlvMiiFlPwyRWuMSUFk26XH4mjk71i X+SA== ARC-Message-Signature: i=1; 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=Nb48Ec9P9wN/ba+vLQTCWoxnTPCDbsQyo2JqCHOzxss=; fh=H6hHKnScvHhKAB7z8Wb75LBNJxB0aNyPhv3ZCgyEYhY=; b=oBS0IfqiLuga1fQt/UsWzd/Puai72mBtholtsHXAjD1Jikpih2lYQ9gfDBeJ8vePxH z0Cv3ZM5lXuDUEIizmY43ihC79u05EBplTR58odWJLgqb770ev2sQyuw0FThihKz5IHc dmKu97CyUL/q41Id1UAC+5UfG39BcbBCnloBf/QYymUqTtkwy8TfUM/X88o+eIE0zcBX KuvWvPmWFegueFgs16zMMiWwrXBz1/6qtJqDNm6D+p4nooOeHyhD5TGamGsyQhTKNB3w st2rl3ZSQos3BgcK6KtCMQQlaBCUypAtccgihlevYnVw2RgdzPM1aJPky6b56TlwQDF9 YEDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RpM+MlQ9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-26110-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26110-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 q11-20020a17090a9f4b00b0028ded0d5690si8789063pjv.95.2024.01.15.06.41.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:41:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26110-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=RpM+MlQ9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-26110-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26110-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 E0C402820BD for ; Mon, 15 Jan 2024 14:41:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C70C7199B3; Mon, 15 Jan 2024 14:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RpM+MlQ9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ktZOmXHD" 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 64EEC18632 for ; Mon, 15 Jan 2024 14:38:12 +0000 (UTC) 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=1705329490; 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=Nb48Ec9P9wN/ba+vLQTCWoxnTPCDbsQyo2JqCHOzxss=; b=RpM+MlQ98engTxxgTZb3m1VEMYSW7zPbVdt9EtlYVA92ZO5VCBuGDLe2A6/9XL672oLhz8 hXSYjXGyXyvVjkbJn77lqdYHPrwJpatsb0XPTubsfT3bbsF+gBeLyYExxM9kiBcT09cRPe VfykTG5s77jURoIqGMsIiZpqAOkXGlARCipzI2ye5tp7GtgtkVj65uQ2RjEzym4Ewf64wB zywAwo3/qBIHBCyruCWmsDcEJC20gf1zfxK6h2ay031x717BwY+VWkhuy5d5FP8cMGnoIv jebL2aKqB99ATJBOMsN49nuHlggiEt9QxCdISlAHCOg1E8i/hTWq+FwR1Zyn2g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1705329490; 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=Nb48Ec9P9wN/ba+vLQTCWoxnTPCDbsQyo2JqCHOzxss=; b=ktZOmXHD5e+0jPN1zjCs1yytQQtNHNYadVzQ83G1DCIneFUyqWPZpmcomr3cjqK/SuTg0n iPzH1Z1ilW5vU1AQ== 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 , "Richard Cochran (linutronix GmbH)" , Anna-Maria Behnsen Subject: [PATCH v10 14/20] timers: Restructure internal locking Date: Mon, 15 Jan 2024 15:37:37 +0100 Message-Id: <20240115143743.27827-15-anna-maria@linutronix.de> In-Reply-To: <20240115143743.27827-1-anna-maria@linutronix.de> References: <20240115143743.27827-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: 1788167808075560150 X-GMAIL-MSGID: 1788167808075560150 From: "Richard Cochran (linutronix GmbH)" Move the locking out from __run_timers() to the call sites, so the protected section can be extended at the call site. Preparatory patch 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 Reviewed-by: Frederic Weisbecker --- 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 3e2adfc15f3a..ccb2a5c03b87 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -2223,11 +2223,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)) { @@ -2251,21 +2247,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); } }