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: 13019289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8C7BFA3740 for ; Tue, 25 Oct 2022 13:59:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232179AbiJYN7p (ORCPT ); Tue, 25 Oct 2022 09:59:45 -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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 --- 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); /*