From patchwork Wed May 10 07:28:03 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: 91917 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3430068vqo; Wed, 10 May 2023 00:31:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4wlgQEyLe8v69iombZ+FyXBE1MTeA/eGhRnuMy8yxpzggWOaKJVHwRPV2a8pmvS0arfZjY X-Received: by 2002:a17:90b:3a8c:b0:247:40f1:79d7 with SMTP id om12-20020a17090b3a8c00b0024740f179d7mr16511536pjb.34.1683703907573; Wed, 10 May 2023 00:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683703907; cv=none; d=google.com; s=arc-20160816; b=nk2jOy+qJpIzMg57SNVooxjobwpInRcihvQ7Gfd8Uedv4LVCLLceZFHybL+EGB3dj4 4EQO6q308X6tBNvmfY2G74W5wDYmlzTrB9tuITqjkpHclFBGxuflYKwKzwcp3KPBNliO F1qe9xh/trjeDeQqhToNlPdYYsocovtCsICi34Zm5lHNYd/Zb6WGjgNH2nEAesB1YFKH IXrGNO0OeW5LHzmejj6w05FbmQqMD+hsCGXWb8C1tfCjhHxSJ1fuGKYjyOL36xCznAOf MuVyotJy6YcRQg7dAVQPseZ09nHXW6mf2ayN/fJOtMQOqsy0OUbymYfBMejibyUNETCD treg== 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=0atNCNaZP9lxXjEQpSGlLcPEiC7DV00EhZ8ok767lpPv2vI41AyrOgdfjleg2BPr5b ymMQexVIpXxxdlF2E2vLNiSTm4m47yJ9iVcgf6Y2S3NxHALO5Mi9CAQZi+s3T+O1nFX0 s1fjioNnPazir6LDPuq8ZUSXv33bjHnqvda3eH7tSnHG3IlwwIHGWs7Uajtt0Rjjrk4v eE9z9qnsdN9En2/4T0Z5SKfz7S2p2M1/IM7sy40Imzc5IqWTAZSdcBDzaQCqSn3gDdWd S3J0oosvLY0hkP3U0fWcigJzEQtZ+GvuYssToIEUybP5jEMDnr6tCG3lUhQzPhFbSX3t m8OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=eR8XMjga; dkim=neutral (no key) header.i=@linutronix.de; 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 b1-20020a17090aa58100b0024ddf3f8a0bsi17094191pjq.82.2023.05.10.00.31.32; Wed, 10 May 2023 00:31:47 -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=eR8XMjga; dkim=neutral (no key) header.i=@linutronix.de; 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 S236172AbjEJH3p (ORCPT + 99 others); Wed, 10 May 2023 03:29:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236034AbjEJH3V (ORCPT ); Wed, 10 May 2023 03:29:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 645CC76BA for ; Wed, 10 May 2023 00:28:53 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1683703719; 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=eR8XMjgaG2N6MMMlyqB0RosEEgNQTP41nxZctDSCa+a2I2Rb/93TL6uxFQzBL4b16cVIun awsYgQa4paT1gzIq8iX7nrtkvC0PaG/L+gkIj/P3BMS6I7FOQSmlui8o+EMK1z7RdniuQH Mh3bGNU+wOhBCSJu8GNBRLgpu5RQBjNqxx5cb71s0C46PRXKsa6JZDGiArPqwkvAB6bMDJ pWKbPVOWksBL1WGjxWS6ydeTZ9EWhCVfOR8zvUC0+otc9Lw+36g9IT20Pi+BixwEASpJ6/ ulZ+TTF6+hs/0LLKkSov2d0PUTWZz0LsejtsZmUZWU0CjUlEeLR6jHZ5sBQsjQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1683703719; 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=HDCdnjAayuDo88P3EQdNiFilSUamlMyH+6wzCAQRTuUuX1qOT305Qo0myxegEHG1L4LPyp f8f3lD06Lr7m0dCg== 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 v6 07/21] timers: Introduce add_timer() variants which modify timer flags Date: Wed, 10 May 2023 09:28:03 +0200 Message-Id: <20230510072817.116056-8-anna-maria@linutronix.de> In-Reply-To: <20230510072817.116056-1-anna-maria@linutronix.de> References: <20230510072817.116056-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,URIBL_BLOCKED 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?1765491508438659281?= X-GMAIL-MSGID: =?utf-8?q?1765491508438659281?= 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