From patchwork Wed Mar 1 14:17:38 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: 62920 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3658716wrd; Wed, 1 Mar 2023 06:23:14 -0800 (PST) X-Google-Smtp-Source: AK7set8hjZh/H/7UnqKBzWM4kTsQ6DEu4iLPQk9eqOUaDEneH2y3wdGVHdRauuD914UKk50Yxuoc X-Received: by 2002:a17:906:3b82:b0:889:d998:1576 with SMTP id u2-20020a1709063b8200b00889d9981576mr6605672ejf.66.1677680594442; Wed, 01 Mar 2023 06:23:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677680594; cv=none; d=google.com; s=arc-20160816; b=x/QKrUBTnPqiZvexaNVRFDUFVv9vp2J4c37LM1WXhEKv0S5ivCfyjXv1Y4c4AIWIpA RDv7zDrLeQmDfvsHs97+Ii+S+k7IhEqf2HkbpgGk77USaDHVMF7dP1cFNwbNielJl7yD Jr4UMc6CSaQVGfiG1KnF4OItkRIy32b0ebSHW4RPIxSWcV30ktb34vgp1kH4kntu6XEN Z6m4fYFpdIxlIl+Brlq8bCm2loYYTySyL6tQk3VmKPh/8PDTNDrJ+P67Rc43GDwbT8KM 1wwvCyeMzUE9zYApI10OSC49uYtR3Szh0geURvxojxbdRoSGQ3xeRbclpEiVHuJgsFV7 BdcA== 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=VpDSCQnNc4s0GTZc/8uTJZlimFSIHsKz1UPfERjKnI8=; b=PjxgDtjcUZoktNY8NUNzl1JISg+IlU1U9km/gWso0j8eeQSvsJ1Lf/6NVIx9WoVGkH M88Zqfu17/69rGZ605mVMvwXGQe6UoJ4p+74fcX7vT6ELx1NwnlXB4goVh84qcl/MU06 M9RzMd8ygd5bQ5mz4g5Bl0Ax5m2woefsoGCQ+m23kvRG/RVG37+uWWl7ucPJfGRU1epQ kODuopHzMBb8trPXnSnqczM3YHMcaiVfBn9+WtR+fw5dfyq80JAPMhaa47Ho4pIQRdGL ymVujQCnC/Nf8mTK+UwQMCbwrZv85bJLhASMNkhNO5hIJuCpHLP8pnqi3CDintoE2ki6 KUcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Uyg0dL6E; 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 rp8-20020a170906d96800b008bd8270048dsi15164517ejb.371.2023.03.01.06.22.51; Wed, 01 Mar 2023 06:23:14 -0800 (PST) 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=Uyg0dL6E; 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 S230044AbjCAOTE (ORCPT + 99 others); Wed, 1 Mar 2023 09:19:04 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759175606693726209?= X-GMAIL-MSGID: =?utf-8?q?1759175606693726209?= 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.