From mboxrd@z Thu Jan 1 00:00:00 1970 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 C4F3DC6FA9D for ; Wed, 1 Mar 2023 14:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229674AbjCAOTF (ORCPT ); Wed, 1 Mar 2023 09:19:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbjCAOSL (ORCPT ); Wed, 1 Mar 2023 09:18:11 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B93CF6A73 for ; Wed, 1 Mar 2023 06:18:09 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1677680287; 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=VpDSCQnNc4s0GTZc/8uTJZlimFSIHsKz1UPfERjKnI8=; b=Uyg0dL6EYzTTDFMRiXND4aJPhbj6wTr14qABVK5tmOYitP7LgAv07U++eCmTbuxqYHmyg9 j9CjS6S9GfdKKdxcYIyHsq1BloFWheXZL1oDQf09ID8xaREyDPQFyBjZlpvg4TwAmrjqB3 y9xZKVtW6sOtHv6GO8Lk4kyR5lfU/a1Pd99FNCoF7jjhg+4AsEkYJ/GLKfjfJkBxyxpVAX d/3erg8cPNNspyM6wlzrM26g7rk/KT+vqP/f35r3lRp/DmDinEgY5NFo1chvZrlM8+ChPM ka7TzBrv5Ovt3en+dPs7y6bQK2GHl1JLODh5TH9w/gPILAE3VdUR2UNO2zw+BQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1677680287; 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=VpDSCQnNc4s0GTZc/8uTJZlimFSIHsKz1UPfERjKnI8=; b=3E8OfASZGSVsrorgzwXmLFf6+2XmRclKO9aBdiDYIBDMpk8QjDtF4bGkfJVKr+T7TQjYaD 87fweegl1rxd9aDA== 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 Subject: [PATCH v5 12/18] timer: Add get next timer interrupt functionality for remote CPUs Date: Wed, 1 Mar 2023 15:17:38 +0100 Message-Id: <20230301141744.16063-13-anna-maria@linutronix.de> In-Reply-To: <20230301141744.16063-1-anna-maria@linutronix.de> References: <20230301141744.16063-1-anna-maria@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To prepare for the conversion of the NOHZ timer placement to a pull at expiry time model it's required to have functionality available getting the next timer interrupt on a remote CPU. Signed-off-by: Anna-Maria Behnsen --- kernel/time/tick-internal.h | 8 +++++++ kernel/time/timer.c | 46 +++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/kernel/time/tick-internal.h b/kernel/time/tick-internal.h index 649f2b48e8f0..28471c8f8c9c 100644 --- a/kernel/time/tick-internal.h +++ b/kernel/time/tick-internal.h @@ -8,6 +8,11 @@ #include "timekeeping.h" #include "tick-sched.h" +struct timer_events { + u64 local; + u64 global; +}; + #ifdef CONFIG_GENERIC_CLOCKEVENTS # define TICK_DO_TIMER_NONE -1 @@ -164,6 +169,9 @@ static inline void timers_update_nohz(void) { } DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases); extern u64 get_next_timer_interrupt(unsigned long basej, u64 basem); +extern void fetch_next_timer_interrupt_remote(unsigned long basej, u64 basem, + struct timer_events *tevt, + unsigned int cpu); void timer_clear_idle(void); #define CLOCK_SET_WALL \ diff --git a/kernel/time/timer.c b/kernel/time/timer.c index dfc744545159..9daaef5d2f6f 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -221,11 +221,6 @@ struct timer_base { static DEFINE_PER_CPU(struct timer_base, timer_bases[NR_BASES]); -struct timer_events { - u64 local; - u64 global; -}; - #ifdef CONFIG_NO_HZ_COMMON static DEFINE_STATIC_KEY_FALSE(timers_nohz_active); @@ -1984,6 +1979,47 @@ static unsigned long fetch_next_timer_interrupt(struct timer_base *base_local, return local_first ? nextevt_local : nextevt_global; } +/** + * fetch_next_timer_interrupt_remote + * @basej: base time jiffies + * @basem: base time clock monotonic + * @tevt: Pointer to the storage for the expiry values + * @cpu: Remote CPU + * + * Stores the next pending local and global timer expiry values in the + * struct pointed to by @tevt. If a queue is empty the corresponding + * field is set to KTIME_MAX. If local event expires before global + * event, global event is set to KTIME_MAX as well. + */ +void fetch_next_timer_interrupt_remote(unsigned long basej, u64 basem, + struct timer_events *tevt, + unsigned int cpu) +{ + struct timer_base *base_local, *base_global; + unsigned long flags; + + /* Preset local / global events */ + tevt->local = tevt->global = KTIME_MAX; + + /* + * Pretend that there is no timer pending if the cpu is offline. + * Possible pending timers will be migrated later to an active cpu. + */ + if (cpu_is_offline(cpu)) + return; + + base_local = per_cpu_ptr(&timer_bases[BASE_LOCAL], cpu); + base_global = per_cpu_ptr(&timer_bases[BASE_GLOBAL], cpu); + + raw_spin_lock_irqsave(&base_local->lock, flags); + raw_spin_lock_nested(&base_global->lock, SINGLE_DEPTH_NESTING); + + fetch_next_timer_interrupt(base_local, base_global, basej, basem, tevt); + + raw_spin_unlock(&base_global->lock); + raw_spin_unlock_irqrestore(&base_local->lock, flags); +} + /* * Forward base clock is done only when @basej is past base->clk, otherwise * base-clk might be rewind. -- 2.30.2