From patchwork Wed Feb 21 09:05:42 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: 204038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp919849dyc; Wed, 21 Feb 2024 01:11:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWw8orz72PqxeQQuE5TpoLjj/LGoHTPga+CCFav8rf0fvCRTuInm2+dVrNkoflrauIxBgbaxYA55BGPuVsfCEm46uOcCQ== X-Google-Smtp-Source: AGHT+IEzpxfZbEmsWpNb1niy76CiPbBDYF1nk9dzz5osVHnc9Z+EpEURihuDuso7vvNExoCSNRs2 X-Received: by 2002:a05:6808:bc6:b0:3c1:652a:93d3 with SMTP id o6-20020a0568080bc600b003c1652a93d3mr5525148oik.29.1708506678317; Wed, 21 Feb 2024 01:11:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708506678; cv=pass; d=google.com; s=arc-20160816; b=AcfQU9ISSuNjWmzsXIzj+wqug2ZUPPv9Ez70lJAZKYdV+jJgsDi0cDiYtD6iR9dnx3 6ebDKJI50ISbzFRgPIIJ3AvH9rBydKvjjaR7VR3uzK8Bv4LLsfOLD2FLI6zkoEcyx8Wt sf+jsebLyR9f19AMY7hEgDYKa3NNrPEPXAh9DM8Xb6OYAD851aRaK+OxEaW+KO5D9P3G H3VYVALZDWve4OWstgCONuPLPk1Oy6erQ9cWAZceRwxz8wHc1Ine0ZtAX25ZOI5ZZjjN F0ci/Y4D+FuiXu5lnPf0ZVWw4xJEpbWHVVDvUyticTjZ6vVRNgM4+NkW6OtNTBtG90Cf bbIQ== 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=8Rk56jS4ox3LCyUSnYHvNlLdqZIvRSv1jWR0mBi/KNM=; fh=kuIFmsLavJbIiXGfj+OQqzrKlGRdum47/II5WvdxEO4=; b=Vw99UK17GOWMVjslUKFq8a5E3Bm38rl5hB3cpLER7lOv5saaSXyINQWcup0uhc1bWX ijoH9y8dts6xnBaXBXqZCkOR5kBj+kNgXOtKk6WPU7E+QTLaX+qnyiOn2Q9NzoyFeClT zd9MF8+DcatIaDOqomU7LwZsvu1Q6ShnUq99M6dDBbjCKaBP5bEgtqJI30sxFh1YOIk2 c3DU9DtwSRBFKKA0JY78fTlnlyhN22XreuULe4XfTnjDl8X6i+GuzKPPSrk0ZpST8vbw mL7BCRA411n3N8rhpBsAVD/JyG37y77tGlJgBVbc/Q00s55mdjFKtY2xnVuqeJt+HVpU ZrNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tvSifHza; 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-74357-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74357-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 u71-20020a63794a000000b005dc8762dce5si7904089pgc.51.2024.02.21.01.11.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 01:11:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74357-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=tvSifHza; 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-74357-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74357-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 2A4032851AE for ; Wed, 21 Feb 2024 09:10:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6EC1B45BE6; 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="tvSifHza"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wtOujEsX" 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 B83323D965 for ; Wed, 21 Feb 2024 09:06:19 +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=1708506381; cv=none; b=ns+ZXF1IyDH01ChP2U1t5bdBIQroyvxcKIrPs+AGXeIhtUM1ge5sEa8V6BHDKyIFJzRxSqu9jzDIXFhgbfN6MdpRA0EhrgdWsMUqXfmrzFMjWD/0HPwKE0V/S0cW4tZH9hbczuHaq9jz3JLBSEwI2+xvw/fDzMeN3vB3aO9tvCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506381; c=relaxed/simple; bh=Y2acepoGiFBus/o+gYKEuBFXzXXX1WvysSEaYzKXOYg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G5BZGaSMCKY2MFUqrZ4xK116RqM3+KzZRmmNqp3872MaPx4GVjCj4npfIWhrga/o8x72RigndSnd3yGKVPL7No+EOb7M/gaSc621wJ4OjFAwxMH8RqsD4KKHYMSVMmrU4Ouyt2zm7xgqUo5D8BysRObIePEaEQz9z791vcAZGOY= 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=tvSifHza; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wtOujEsX; 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=1708506375; 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=8Rk56jS4ox3LCyUSnYHvNlLdqZIvRSv1jWR0mBi/KNM=; b=tvSifHza9FJpYdPGN14ZKC6V3XR8MQF6d1u8sRX1M3nXQkeBVoGTK3ed45Tp+Wn6Pxl34P 6IeT7hO5vshrkdsYEa11CvDY2TV2OumynAdBsHrz+zGnGhKt5939Qqixkem4dRqkNsoTPI YijYecLSRUiZQ/jzOkiN2Y7VXUeNBznGVaQYdGRZzLjCRSkyMvzFXo1YZTF+Sy+89QbpAf ghnWE/HFPgZJN+LMRiSk7WFx/ajpy7z3E4F4L3QiApGCdFBmTmQ2n/qD8Get8icU8Hgkg8 cgOk0xiWQf1V2On6T0jm+96lB03fPKwNMt8JjwbzQW1sSlWDG8drZ4x0dqlDnA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708506375; 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=8Rk56jS4ox3LCyUSnYHvNlLdqZIvRSv1jWR0mBi/KNM=; b=wtOujEsXq56FVsf4pAgUz4UY2mcmXcLUCrvFSKEik1is8Jtqy3EJq05R0YiQNLzYwXRU1a TUIrAQ29Ip7CV2BA== 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 , "Richard Cochran (linutronix GmbH)" , Anna-Maria Behnsen Subject: [PATCH v11 14/20] timers: Restructure internal locking Date: Wed, 21 Feb 2024 10:05:42 +0100 Message-Id: <20240221090548.36600-15-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: 1791499098836356220 X-GMAIL-MSGID: 1791499098836356220 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 88160b3461e0..52af50d00ae6 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -2238,11 +2238,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)) { @@ -2266,21 +2262,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); } }