From patchwork Mon Jan 15 14:37:28 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: 188184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1743464dyc; Mon, 15 Jan 2024 06:40:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDaLD4AmBp2WgurIqN9E7iKQEOXGaAvSjnm2BVos5DCj5WhtIkrcidlxF/WVqOpGoHK7Cn X-Received: by 2002:a17:90a:cf85:b0:28c:c616:3dc8 with SMTP id i5-20020a17090acf8500b0028cc6163dc8mr3047521pju.79.1705329602965; Mon, 15 Jan 2024 06:40:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705329602; cv=none; d=google.com; s=arc-20160816; b=ntVFbQfpQ1ITlJ9fQv/88o+/geBya9qbetr3dXXZbfkqSsu8vuk3v4K6RilujaV6lt sn6oYH0EnwblxWruANQB9MZdVCW15QnyosouGVAZ3HEGp6xnmJxtoSRBS3A12eZQE3SM FROHGLup0eMo0ei64kstX4vHtigeA90pnoWjzoBviTLBeMbKx7cWfAbnc+3oNJr+C+pV dsYJ2ONAROUk+JIAIIF3E9wIHrJFS0sYwsFCB49pSlPGhMMu3xgISbxg7fXiw5Q0ypwi SLKDkfrj6S9T56SvPs47rY2luz0Ior18aiMjVijoqCwVG0O3nThbA4Kru6990UEL5mRq gC9g== 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=dd7ZSY9uCCvXsEjv5hsri8WxYcwJShixETTpt1BLsE4=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=U++ranzWhPC4rr7LbxzSMl+LTX9Nn0geegxsmM8O7vmmB/rRTywMGqHhf54qVDjnZW xMXXdRfsbXaaQ1YE18j9SuUlJkoPpGPIyWaQteAhCkHuUc5NTFjBxH56lF8RyrUguD+U 1RO6ceOyuNmFQFY01UIyx3Nt++tLQ4T/x4cbY1w5kcQnuMUYDz6hrOxZwybtbZDu6chA b8aKQoiDApKWx+luWrhu92lXOWOJ0RbhWPEJ1YbcjAvy5KFMi9HS73wk0ZrQvKGM+Kab 9aQFDqnKZw4Sg332EGhSHi3ZehUyp5nhvPSObyQR6s7x9eGkFHRWU6oDAh0/XOc7rkiH g/ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="f57/0sSB"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-26102-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26102-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 x21-20020a17090aca1500b0028d29091591si12140301pjt.144.2024.01.15.06.40.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:40:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26102-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="f57/0sSB"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-26102-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26102-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 B8DCD2828EB for ; Mon, 15 Jan 2024 14:40:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F5A018643; Mon, 15 Jan 2024 14:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="f57/0sSB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WqiDL90+" 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 0776F17999 for ; Mon, 15 Jan 2024 14:38:07 +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=1705329485; 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=dd7ZSY9uCCvXsEjv5hsri8WxYcwJShixETTpt1BLsE4=; b=f57/0sSBXZ1JRAX3RVEVr5HFQv6Lqb5w3CD5uk8FY+PR9dgPCaun9CyEOq7cdBwCYK3TwZ QV4OykKeDthyz2Q5gL0/pysVAVrZy/qsIrc4ePzSvIqEJRO3QTh+3TB4JIbsuPoKgb4SaI 98gmtJ/nGofxAzq1BWJ1HpmbxTdutIV7/1oo3Yis2h0Ht3WkFR8EVxHEyaXi7cfzn4hbyz dPubmZNV6uAofAmMhnWHw+CP8T7VzwJGSEh9KGL6SGLwpR5gNKzzLdiQYNhcEDRrZw+efJ pUBOOZ+rHMo0345vx2R+yOthEkzdKNUNqtr74EEpTZDQsNVy7ZcMvCVgxdCG9g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1705329485; 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=dd7ZSY9uCCvXsEjv5hsri8WxYcwJShixETTpt1BLsE4=; b=WqiDL90+9AC1nMXbkvsV88JCQ77hfxzaVccWYpl01ws4yhT+L5Gkum9jw4wwsNZ9ofshe6 ukC2UFG/zu2l6KAA== 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 , Anna-Maria Behnsen Subject: [PATCH v10 05/20] timers: Introduce add_timer() variants which modify timer flags Date: Mon, 15 Jan 2024 15:37:28 +0100 Message-Id: <20240115143743.27827-6-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: 1788167693346337186 X-GMAIL-MSGID: 1788167693346337186 timer flags 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 26a545bb0153..404bb31a95c7 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -179,6 +179,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