Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2240607rdb; Wed, 21 Feb 2024 01:07:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUUSAteXgBpRVmTjbIbtouWirO79iJ6BI5BxaqoIzmga96OznefDjb0LgwOS6K6sgpz38OVQpE8ZGUhcV8UKSyatq6WANig07YUGv92nQ== X-Google-Smtp-Source: AGHT+IEBq6VS16odcm4OZ5b4RoOFzh4JGXibbUF8tU3Urd+/wUbddMcHtYnHOf86fTUC3Ph0NUYp X-Received: by 2002:a05:622a:1889:b0:42a:b8e6:aef8 with SMTP id v9-20020a05622a188900b0042ab8e6aef8mr21735217qtc.42.1708506447879; Wed, 21 Feb 2024 01:07:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708506447; cv=pass; d=google.com; s=arc-20160816; b=HoMIl2HXVsmQPYAN3926TG1g7LjElCcomsauS43jOvmhrhcBzEqEJq+Ooq8sB83Bkr mvRTn8ZJ15yMubgebvTSklKyS4oHXm5L2Cs7w/PJIQDpjD8MjueBuiv/fbzT6I82Lp77 J+RXwTi0ZW507sO8WBqgH2Qiy1ztv2ADStwrn58Jnbvm9cFfquXX2lj/1bf9/s3hAfha 8FiVAOYDsoJ3kjAJw+KwU5YXdCPMkwHw0r+FtdX4wN2USbJGi0n97zFB0TsQWWt2+PS4 Qvro4z9sB8MRZjW7O88DY2kqvtqrYbxH9oT3t+TX8qr26Udvk7qiAOlhfmC1uwZ8sQV4 +FWg== 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=QisrBEswo4w1Tqs9XJzYOTpU4VJaqEco1Cayy0t85z0=; fh=N5fTIFf2i7nvF8Om7kdprA8Zy2dleTNav/f0ArIISzo=; b=iYZJFCfztvMSePNYoTg5n4p/Qc9iGGrGcU5KYuMAo2xJibmc1abpc/GpzQ8yo7xmqq XW+UBK91TahUz0fNn0wPxAmsWiprcJIBJNzI3GJq0E+K8OTy2t4e6kpFgrtcQ2v4kgIb 1+sukiM8KvXRN2ZQGGGhEGHM4Y1ksvENpJTEUul1F7Ot1Gf/lCuWrwOfcmCPy34JO8L5 RcNB5UVKzBh6ZOOpfY4QFV8j/TrBQNRzE2kcPConwbn5+YrnJN7EKFjwjtCEIRYCYvXB MQ51x9AwUFq2733EvbMoWFa6QgBEkf29YhSL42Kd/D8SsMPZA5WA3KQJT1NTsqM0hV13 0sng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cxbjYNYY; 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-74351-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74351-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g17-20020ac85d51000000b0042c3306518esi10782383qtx.261.2024.02.21.01.07.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 01:07:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74351-linux.lists.archive=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=cxbjYNYY; 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-74351-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74351-linux.lists.archive=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 9F2A21C216B0 for ; Wed, 21 Feb 2024 09:07:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F03103E474; Wed, 21 Feb 2024 09:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cxbjYNYY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Sc1xvsMr" 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 D870E3D3A0 for ; Wed, 21 Feb 2024 09:06:17 +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=1708506379; cv=none; b=A3EJSyW5mC/USX1/Mv3EFRiJSFP61jjgLOSN8FsASmSCosgiB1FvuPSTcJ/JJYTnVslMlc8gCJ2UReF6lDX8i9wEaLo+Qtu35yob7Iy5rAKBMtyhNFciEHOtJ7+bwnjmrCRllPZU5kOR1kGUYHR+myO5AU5vIFqV6hKh5xkb5m4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506379; c=relaxed/simple; bh=fAB5xEIJhUT2xY7i5T7pqKYPBAt3GNmgTzm/jf5bOqc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nPloMWIQcl+0i6pcCp1uSmpLkoV+3m1wRxuK9rgkEQDlSBe0BQxPoArVQBJL0Cc4LHRypgsVEtRASp9kfLJFru9/NFEM22cxoj6f0Ajui/aL9UumljXwUsC4FrbE3bD1ky7XzfHq4YQvHs2MwnAFWgIiQf9xPgj4EJkK0kqqIcM= 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=cxbjYNYY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Sc1xvsMr; 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=1708506369; 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=QisrBEswo4w1Tqs9XJzYOTpU4VJaqEco1Cayy0t85z0=; b=cxbjYNYYvJE7nTIXnHt66nKWJdXP5gSGl1ZHzbW7WkQraHBGShczZFlaWC8cCHv0Nlal1u Fgamecy9zmNMhW2C0uGmgDvM69iP/PZMvYe2bvDUdZ08ArHoNyjsPaehvmFa/0QBvxF6iS xOUURNmNr2dh+yA2+0/MaUVZKJltKwceAY4+JdI1yCxjeo16RZRhbE9tH7KIV/PCW2YvZx sFQoYjOCGp/mMBCgUTlccfwSKqlvkWxIyO6PRn0Ic7SDK26DnHSkLJD2EXet6/LPX7QUZ7 riN0pjbWCiDzxPCOwMrkoQwFfaCn+onpcsvvD4zfpZdl997LzAQlqnAU5HHBXg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708506369; 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=QisrBEswo4w1Tqs9XJzYOTpU4VJaqEco1Cayy0t85z0=; b=Sc1xvsMrcCn5y3enYMmEDN21px5+dzmS0F3umaqNg/3PyQcflgyKmwhjWEo13yzGEfeU1K lFRuIkDk5XebubDQ== 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 05/20] timers: Introduce add_timer() variants which modify timer flags Date: Wed, 21 Feb 2024 10:05:33 +0100 Message-Id: <20240221090548.36600-6-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: 8bit A timer might be used as a pinned timer (using add_timer_on()) and later on as non-pinned timer using add_timer(). When the "NOHZ timer pull at expiry model" is in place, the TIMER_PINNED flag is required to be used whenever a timer needs to expire on a dedicated CPU. Otherwise the flag must not be set if expiration on a dedicated CPU is not required. add_timer_on()'s behavior will be changed during the preparation patches for the "NOHZ timer pull at expiry model" to unconditionally set TIMER_PINNED flag. To be able to clear/ set the flag when queueing a timer, two variants of add_timer() are introduced. This is a preparatory patch and has no functional change. Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker --- v10: Commit message reworded as suggested by bigeasy v9: Update documentation to match kernel-doc style (missing brackets after function names) New in v6 --- include/linux/timer.h | 2 ++ kernel/time/timer.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/linux/timer.h b/include/linux/timer.h index f18a2f1eb79e..2be8be6dd317 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -165,6 +165,8 @@ extern int timer_reduce(struct timer_list *timer, unsigned long expires); #define NEXT_TIMER_MAX_DELTA ((1UL << 30) - 1) extern void add_timer(struct timer_list *timer); +extern void add_timer_local(struct timer_list *timer); +extern void add_timer_global(struct timer_list *timer); extern int try_to_del_timer_sync(struct timer_list *timer); extern int timer_delete_sync(struct timer_list *timer); diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 2f69a485a070..3cf016d6fa59 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1245,6 +1245,40 @@ void add_timer(struct timer_list *timer) } EXPORT_SYMBOL(add_timer); +/** + * add_timer_local() - Start a timer on the local CPU + * @timer: The timer to be started + * + * Same as add_timer() except that the timer flag TIMER_PINNED is set. + * + * See add_timer() for further details. + */ +void add_timer_local(struct timer_list *timer) +{ + if (WARN_ON_ONCE(timer_pending(timer))) + return; + timer->flags |= TIMER_PINNED; + __mod_timer(timer, timer->expires, MOD_TIMER_NOTPENDING); +} +EXPORT_SYMBOL(add_timer_local); + +/** + * add_timer_global() - Start a timer without TIMER_PINNED flag set + * @timer: The timer to be started + * + * Same as add_timer() except that the timer flag TIMER_PINNED is unset. + * + * See add_timer() for further details. + */ +void add_timer_global(struct timer_list *timer) +{ + if (WARN_ON_ONCE(timer_pending(timer))) + return; + timer->flags &= ~TIMER_PINNED; + __mod_timer(timer, timer->expires, MOD_TIMER_NOTPENDING); +} +EXPORT_SYMBOL(add_timer_global); + /** * add_timer_on - Start a timer on a particular CPU * @timer: The timer to be started -- 2.39.2