Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp1007106rwl; Fri, 4 Nov 2022 08:45:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ATTFa4iMOLMpdcJt2pTy9mE8csGknaNV2O4jzJOSB6V+WLYHjbaLmIu45h2pCIY0rqSUn X-Received: by 2002:a63:1cb:0:b0:46f:a202:fa36 with SMTP id 194-20020a6301cb000000b0046fa202fa36mr26546007pgb.276.1667576740491; Fri, 04 Nov 2022 08:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667576740; cv=none; d=google.com; s=arc-20160816; b=say1CE5jIidG4yeqbGjVTrlzE4uEUJL6qymyECWLSerV21n3vE1XZ/1rX5xqweWguC dc7HURxpHwkwrjkwJxraXE1NfK8DC1fRB0aqwho9WW0HknfqVxrq3ABPt+smagWDBPBN oPZttAeU2/yGLZNROCMqWz8yjkvWHEimPupAes9IutmoJgVQmPnB16QykPJQd/s5SNgX LRQGtVj+v8d+2n8ncR5sBaAw7GZidfVGmVkLKpYZc3SQtj41H1KCNDh0vxbIzXtbne0v B9pqhRhhOqtB8n5X0sGVbpkWQiJyaOhGGpKgsq44NAYV8n12rdbnlYFRX6shThIATNYF 2meQ== 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=FdVcoBx7/tuIOiTEjcb989uDKzmjA/NfDt6Q7fyRUUU=; b=VzefIm/6QG5TPf622cVc/OCXJyi1fboIQxhjidHf9XPt0NTTdwzsd4D1KY5jmuKl9g EVxX29JtxYdiuXQxG5Ph89lGV8HnoFm0SL/ScQl1mtc4wubTZEQRFCy1yYihngGSR953 /v+/XDlQ1ldqFxDflbQ17Dl7lKAQgiqiYIPaEMLZfiJaWuGzzSKprc/lMQPGMuwCyKt9 eoktjTZeQffTpQLVvsISyWZ3TF4qsEyfazTKI9AaqZ8EoBqndKCp0u3ipLuIQfEYWsh7 l0bAE5OEyegKOSbdJovWOjx6KpXF0LIMfhHUaZIxKizbm+kRiND1qKHqyT+Q84fh7qpp bpZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0g22eLEg; dkim=neutral (no key) header.i=@linutronix.de header.b=dAIjc2Y3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u66-20020a627945000000b00567719e34aesi4581768pfc.49.2022.11.04.08.45.27; Fri, 04 Nov 2022 08:45:40 -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=0g22eLEg; dkim=neutral (no key) header.i=@linutronix.de header.b=dAIjc2Y3; 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 S232385AbiKDO7W (ORCPT + 96 others); Fri, 4 Nov 2022 10:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232305AbiKDO6M (ORCPT ); Fri, 4 Nov 2022 10:58:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F5E131ED0 for ; Fri, 4 Nov 2022 07:58:03 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667573881; 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=FdVcoBx7/tuIOiTEjcb989uDKzmjA/NfDt6Q7fyRUUU=; b=0g22eLEgtf+duujb8mx91XeZxs3w2lmo2ok9sJqTz2qndFHIDwU3ND4lBw/yvb4ozJPAjZ lHmijG/mdXeNls5aMN5YUTPHyTNdxGmwASeDPF+pzPK6km2aTNX1tVRoVQGUZoGiSFO6Xk K5XDGgrsd1V2J64kvfH7tp1o8gcLzGJ0wJQR+xX5+xE9IPUQ4/bRGjJ8ipdrO6ulCdtXC0 O6eUfTWLlz+1G5nmHJlCc5Zd1kjgrbNJAj18Ta/qLQFRnDBF6im1WC56JFrAPvsmgwEIoV BUGJ69P/+9dM9YQ0AtHniaxG+brnxPJ+G7CYXVh1VQ6nL77/rjyKI5jXZDWKgQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667573881; 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=FdVcoBx7/tuIOiTEjcb989uDKzmjA/NfDt6Q7fyRUUU=; b=dAIjc2Y3hCQFk7g+gXz6kF/aSMr0MpEjlw+MrN+F/R5HuISKPvp2SarBBoTcpf2vPR5FyX s/m7EwNWsIDwwIDw== 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 , Anna-Maria Behnsen , Richard Cochran Subject: [PATCH v4 16/16] timer: Always queue timers on the local CPU Date: Fri, 4 Nov 2022 15:57:37 +0100 Message-Id: <20221104145737.71236-17-anna-maria@linutronix.de> In-Reply-To: <20221104145737.71236-1-anna-maria@linutronix.de> References: <20221104145737.71236-1-anna-maria@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 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 --- v4: Update comment about TIMER_PINNED flag (heristic is removed) --- include/linux/timer.h | 5 ++--- kernel/time/timer.c | 17 +++++------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/include/linux/timer.h b/include/linux/timer.h index 648f00105f58..181a3d3fa45a 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -50,9 +50,8 @@ struct timer_list { * workqueue locking issues. It's not meant for executing random crap * with interrupts disabled. Abuse is monitored! * - * @TIMER_PINNED: A pinned timer will not be affected by any timer - * placement heuristics (like, NOHZ) and will always expire on the CPU - * on which the timer was enqueued. + * @TIMER_PINNED: A pinned timer will always expire on the CPU on which + * the timer was enqueued. * * Note: Because enqueuing of timers can migrate the timer from one * CPU to another, pinned timers are not guaranteed to stay on the diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 214397d84747..bdff4be066e4 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); /* -- 2.30.2