From patchwork Wed May 24 07:06:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 98330 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2650215vqo; Wed, 24 May 2023 00:09:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47OVVvYAk499e2uGP0MmMSaYMa9/FowZYD0Z5jHbBT3VyQjfWNJxTL/F2x/huVlHdli2qO X-Received: by 2002:a05:6a20:3d1a:b0:101:96b0:be40 with SMTP id y26-20020a056a203d1a00b0010196b0be40mr19907222pzi.26.1684912155495; Wed, 24 May 2023 00:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684912155; cv=none; d=google.com; s=arc-20160816; b=OmfZfzqYIgLQloF47+WlNc1Hk6qZLzdgib3K/PmCU/YiEHNlDAlAxG78n6W+6HUwft OD54zF84QG54j0hvhivNNp8WQFWo+YcXDiWU2FfC6WSLCUtMzZXpNxNQrc1fXLbw0o1b vhw2KgqxBH6ZbokOD0wQgpOpHSsm/CDdm4c+hd/GLsinV6PkLP4HdHa2l8skY8EIuuHh Yli7N2mjGvoMPIxqjcLBEBBYWuehlYqYAdOiao1fukThs+L5lVRYC3GKpWtrckUEB/42 HLCYM37Yh8uQljQBoiYJW+uhYE5PlvZ5pTVQpQKJy50UH9L6LkgHPp0nuEnudgx074j9 VETg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=V5ghRq1p1UzQMeOe2kb9B0X1weJSuecItqx6Ppb2A0s=; b=qOeq/tyvfgXq6SuFdDC7stlFb/VYLhGkEjUzHo+e40DhDaorDHwmYPlb0MZU4ykxKC pW2YnSnPyC5cwI2atVm3sl43OcDQaEFRva0VoNFplEwKPjV43NDkd/THJzh4rn2QptuU CCsHCOG4/EyZEMEfcW4SUr8Vg+NtK3p2Qq/JrZ6+7kUtOzHFRwfFJog+M/T53Y/PlMms qm9YHXXkN/ASnK+Ji68bSUscdXrRawIXsD25qeagaSj1V6Ua3+wsHXZqBFcapAORpuSS Qw8Jxt8bi8Hlx7vXWHwys+afV2ehKdkiNzkqMmZbTeUFLyWrwfgu2E6EsnjgLyK2pwCW MnVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2WjbYAAV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a63b648000000b00534769ac7acsi7711413pgt.879.2023.05.24.00.09.00; Wed, 24 May 2023 00:09:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2WjbYAAV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239891AbjEXHH3 (ORCPT + 99 others); Wed, 24 May 2023 03:07:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239804AbjEXHHE (ORCPT ); Wed, 24 May 2023 03:07:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A503DFC for ; Wed, 24 May 2023 00:07:00 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1684912019; 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=V5ghRq1p1UzQMeOe2kb9B0X1weJSuecItqx6Ppb2A0s=; b=2WjbYAAV6lbiLJ7V0U3sea1cyaYFl/TwuQaIWaGpI+OU2Z7fWTKSIC80eyHe7aLx1fL9kD jPpHpVJMr6UJIt15OB9iEZJIFXv1ZTS+jnkaoFk8YgGjh4B8CKX7N+BOvvMt7N6LtZcOyM kZ11fSAH3zJY1NuCS7d3Ms4jjw17WweDB8lWYUQMcJIQA+wLrQ36SehwsuiY96QAb00ROR c2RGtT7WJG4T7ODze3SjqrVV8ez5psTj/LHMHDChPJrWJnl5SliMnrQI8qcnLBQuxLlXos wzxFw2x2z02YRz1x9W+6OxvSARzVl1LzXL332lDXqMBuwW2fvZ/XVN1CtN9LZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1684912019; 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=V5ghRq1p1UzQMeOe2kb9B0X1weJSuecItqx6Ppb2A0s=; b=JVr0tIqLMcWr2kJTnV1Dpt+Euh05MXC73CvKJbxWlZr9gT7yeSneT2L6w6+7X1drsNAr7U b1hvvIv2dm5FiUDA== 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" , Anna-Maria Behnsen Subject: [PATCH v7 07/21] timers: Introduce add_timer() variants which modify timer flags Date: Wed, 24 May 2023 09:06:15 +0200 Message-Id: <20230524070629.6377-8-anna-maria@linutronix.de> In-Reply-To: <20230524070629.6377-1-anna-maria@linutronix.de> References: <20230524070629.6377-1-anna-maria@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766758448093627781?= X-GMAIL-MSGID: =?utf-8?q?1766758448093627781?= Timer might be used as pinned timer (using add_timer_on()) and later on as non pinned timers using add_timer(). When the NOHZ timer pull at expiry model is in place, TIMER_PINNED flag is required to be used whenever a timer needs to expire on a dedicated CPU. Flag must no 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 reset/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 --- 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 9162f275819a..6f96661480dd 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -180,6 +180,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 1522fb81887e..ab9a8bb11a8a 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1242,6 +1242,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