From patchwork Tue Oct 25 13:58:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 10807 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1025888wru; Tue, 25 Oct 2022 07:04:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7UGAtlH2hPnbM7LUFL2/JToEWbjTe0bvtk9MRhs9ysG2dUJcGaFq2Y4QX0zig6TFW3jfLE X-Received: by 2002:a17:906:4fca:b0:78d:b042:eeca with SMTP id i10-20020a1709064fca00b0078db042eecamr31520484ejw.685.1666706684000; Tue, 25 Oct 2022 07:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666706683; cv=none; d=google.com; s=arc-20160816; b=lwdkNayjQytKWldCrz8yBSqPQ1h3UBsKFm3XVshV3pVZcnq8ra37pBqb8p1EPlt90E INKoMvkIPfyvJJGVnnUHO5AFQZg9sCtkEXFtP1bIwucmzS78ddjJgyzJi12CFcsoTmDo SXteEKyq8pCi6TTdsOQVCPW5j08VQeO1D37XJUVLNJG/mQ4JdmhqrB6qOg96OKctG12e HZqV572fm8ChvUFg3Fh2XFBMiYVNTT75V1+1uPGYHQmQB9NNZtTqpDdyhNY9RSM+O/UH ISRqX7W9qYOVTYVsawbQbIuYFgELtM3/eG/+C+p/2k0IZAjR/XKqD5My5V0fRx0Q6FW9 D7lw== 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=oP0fWluRaqq+tZG2dJILM23sro1m5U/XHwLQFeRCl3o=; b=bFzOUu9ELV0k0S3gvqrLwFoBHghoaLNNqLqvVzE6qTzRMzAsEuJjay3faqvGGinpeO /k/C04GqM6KI+zdFdGdB30WiZazlHaBiklTXo/k8FI1SzNerrZONqDF/NrsBbFT4hDNu pLFdjOQVFcokQPJ5WAfFY0dR4fkw7pvnn3+sz5ec8WAyynWR0NjOp/60TM3Dl6X31AwI Xy1hGOeBjYKRsQmP429B0wgWLuF86sDRcNY7bNw1hzlnuIhtSabG8A3AbWsn2V+85Ugk wbzaw5nLwZJW8sy/2GjobRb9dRBVd8LU7c9q9JzSwSlvd0win6syn+65Npctq3YLiEa4 uSNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0Eg6Zbxm; 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 js5-20020a17090797c500b0078d27c1c8f4si3411671ejc.696.2022.10.25.07.04.15; Tue, 25 Oct 2022 07:04:43 -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=0Eg6Zbxm; 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 S232721AbiJYOA4 (ORCPT + 99 others); Tue, 25 Oct 2022 10:00:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232161AbiJYN7h (ORCPT ); Tue, 25 Oct 2022 09:59:37 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6B5417AAB; Tue, 25 Oct 2022 06:59:31 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666706370; 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=oP0fWluRaqq+tZG2dJILM23sro1m5U/XHwLQFeRCl3o=; b=0Eg6ZbxmuMXbfIgn0sAXp3ULCCXFyqQQtHzl2xH5jlgUOd8RjrvMvZPngiSqQ/uBF1PlvC 9C0tbJW+sVdS+DAjMs9HDPuEHChU1u8mwIhVatnjiFurN8cB6b1ONTjDgf6PYEJ11KhDWm 0cPWMzqqFpUPBjMGMZW7dh5kVzEHrBNTua/xN61Djdnunb72Q5WJlBah36fwTd6QL5OrTZ uJlJWIj5makdOkBQ9ydWs+dfO5xprJa7l2oNflXamBNY66R8DL+fC5gAcKXpnjwgTiSLA+ jsfaS9bMQsglAe/04br6zM+/zkNYHqSoF7gKXy9x0hB1rgx+baiz5OH82C1jMg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666706370; 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=oP0fWluRaqq+tZG2dJILM23sro1m5U/XHwLQFeRCl3o=; b=8lpLCKUTS76ShpC/dXVU5vgSp553OSmhz+hNadGKfYlzIIqj55OD6ImpPLdzbexTWiCEpO 7i4ia9DdR8hIqNDQ== To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , John Stultz , Eric Dumazet , Thomas Gleixner , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, Arjan van de Ven , "Paul E. McKenney" , Frederic Weisbecker , Rik van Riel , Anna-Maria Behnsen , Richard Cochran Subject: [PATCH v3 17/17] timer: Always queue timers on the local CPU Date: Tue, 25 Oct 2022 15:58:50 +0200 Message-Id: <20221025135850.51044-18-anna-maria@linutronix.de> In-Reply-To: <20221025135850.51044-1-anna-maria@linutronix.de> References: <20221025135850.51044-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,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?1747668628155509194?= X-GMAIL-MSGID: =?utf-8?q?1747668628155509194?= The timer pull model is in place so we can remove the heuristics which try to guess the best target CPU at enqueue/modification time. All non pinned timers are queued on the local CPU in the seperate storage and eventually pulled at expiry time to a remote CPU. When a timer is added via add_timer_on(), TIMER_PINNED flag is required to ensure it expires on the specified CPU. Otherwise it will be enqueued in the global timer base which could be expired by a remote CPU. WARN_ONCE() is added to prevent misuse. Originally-by: Richard Cochran (linutronix GmbH) Signed-off-by: Anna-Maria Behnsen --- kernel/time/timer.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 67f9cc077ff7..f05e547e0c6c 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -947,17 +947,6 @@ static inline struct timer_base *get_timer_base(u32 tflags) return get_timer_cpu_base(tflags, tflags & TIMER_CPUMASK); } -static inline struct timer_base * -get_target_base(struct timer_base *base, unsigned tflags) -{ -#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) - if (static_branch_likely(&timers_migration_enabled) && - !(tflags & TIMER_PINNED)) - return get_timer_cpu_base(tflags, get_nohz_timer_target()); -#endif - return get_timer_this_cpu_base(tflags); -} - static inline void forward_timer_base(struct timer_base *base) { unsigned long jnow = READ_ONCE(jiffies); @@ -1093,7 +1082,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires, unsigned int option if (!ret && (options & MOD_TIMER_PENDING_ONLY)) goto out_unlock; - new_base = get_target_base(base, timer->flags); + new_base = get_timer_this_cpu_base(timer->flags); if (base != new_base) { /* @@ -1228,6 +1217,10 @@ void add_timer_on(struct timer_list *timer, int cpu) BUG_ON(timer_pending(timer) || !timer->function); + WARN_ONCE(!(timer->flags & TIMER_PINNED), "TIMER_PINNED flag for " + "add_timer_on() is missing: timer=%p function=%ps", + timer, timer->function); + new_base = get_timer_cpu_base(timer->flags, cpu); /*