Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1005903rbb; Sun, 25 Feb 2024 14:55:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVVLaQWtXyDOhfQw9HAcZxbdosqKQsZNupKVtZuAXH8UkPD9pjbjF+3IOo6Ntfq4qMHej4G0NAqrtiS+3Npi/+jfMCh2klgV0u1n4NMqA== X-Google-Smtp-Source: AGHT+IGyy9hT27kYQOFFEOpEIQ+u5Pp86En0dyJEsRukImKtzNAHzMLQFWhPwwZAvA7aHWg7fqqh X-Received: by 2002:a05:6a21:3403:b0:1a0:db5c:9762 with SMTP id yn3-20020a056a21340300b001a0db5c9762mr3955454pzb.19.1708901744962; Sun, 25 Feb 2024 14:55:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901744; cv=pass; d=google.com; s=arc-20160816; b=ostRImkwdnM2bEy/TQG3FbqoqdvtzkZ73fmdloK8fmX+hlCC5qEsefn65ihrVfx+6X DE33xgHY++mnkPOEhWbMWJxwHjK2tMvytJ6k1cFeGdr+/BnLQOa2Ell4OkXhq1/IgRl8 qkDO8l8krfGNPXeNowpYQgdUnsya5qfJWWssIgjKXzKd6Uk1rS2FzyVeTeQuqOiT9dJX 6FNWPHCzOAhXn+iT39lG+EgUoQQ6EFTF/IwMXr0O1hajTst8ElcOYPegms4t0p4G2k3+ w7eUiB/bFIXq+e2H74JHJlhLCs2QzUyC0EgLv7PMPSeoETgQv44IZnnITW0Y3gIoTYkA KQTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Kw8NgGwuAYbYx/asULPrYx74vBsDFyafcKiajtFiGHk=; fh=4P8gqRLFmANjcHHSJu0T2ajtncG7F3hkmyD1v1G3zYE=; b=OMnuI7FdwOovlHTsfOqacG25X7aC4t5NmvLimKrgue678FM+wFcR8URYvMaG96pejS 5rKfnPQNvE1s4GoE8EJAWhio41z685Gj3YbrxVUj4ftUXCMvaOk5KJwBk0BPqLAxsu/s 4VF5S/toqiyqQoBEoDbbAzHUJQMBLt8pAF+r1A0wzMAT/DPNTkyfjFYIXWOTWzQ6LrgU gCxpNXU5+HQ85iweAZVotT/w9+H7Nz/E9TMMHwmb4nPXRhlyOJwcOSxiaLG8SAIbEPfh izKRKsg89te9KbKWmKPzVZhKR8bS9C0lrb+/xbFgzvtV+JvcdCkWZ5CWJv5pWTfbjefM KRZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b3Ta1KdR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80328-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80328-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id az10-20020a170902a58a00b001dbc1a37d5asi2575589plb.143.2024.02.25.14.55.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:55:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80328-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b3Ta1KdR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80328-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80328-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id CF100B20F40 for ; Sun, 25 Feb 2024 22:55:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 828F31BDEB; Sun, 25 Feb 2024 22:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b3Ta1KdR" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97A591BC58 for ; Sun, 25 Feb 2024 22:55:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901716; cv=none; b=Xr5sWrLPBGljNs3y1lXlWMd4vA646OMcLDBVib8BG7F/Kp1JAgRCZVosQidSsh6+S73PifteZrifSxm0hGiLF2in4ygjur3OCFZRFIv0ljjqvYO9TVzAzyqifzcf1RsEgmO5j35n8eE9SHzwvIFOqXTjWeeRSnmu7d2NjTuevaY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901716; c=relaxed/simple; bh=H+m7K3DvE8H8qAY81UzJsAiUzQ/BG/aITwfdWYcyNlI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K1TiKxgB3gXb+oLX3wdd2etrPX9RvXpT1cZWK/k9tND307bPb8rfsh55UYLHIE0SUpRL8SrQ+YtS8aEpYGAMnMMgpNzRzazSB+FzPqh1kS2um9m+Iqdowv555IzPi9Qq1Xkd33WHvcL45WPmXXKjqmyukq5gUWpRpQflEL7uc8g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b3Ta1KdR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 587D0C43390; Sun, 25 Feb 2024 22:55:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901716; bh=H+m7K3DvE8H8qAY81UzJsAiUzQ/BG/aITwfdWYcyNlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b3Ta1KdRq+BzARX7r3IMOpNa2VC1E+14lwcEqeml5kuSsdrhwwS8Wmmu0NyIZi8BV UrXDuswmBCOxSH9CEbuGVhYcPPodauBdW5SDg/IsE6rrNjOZZqJQfRwvkyG8Ogtk+j vkRI3LqLfo2DVCWmBZIw4IxW6cqT0W/hAGUyAQWq8DNfW0yg9PFRDXKumpfAW0v5br MSg+WdeV5SVtHh7/KvXf+daU3CyWReFy733UeJ4a7oouVDbbr7WbHPqTVTtCwhlKjd zxSYTvuLzuJaBMbEuATN8KzdyspOo3SpbdxstMQJlXuk/Ob0MMClhffY4d5G/S+1zR pUeADexAc3o4w== From: Frederic Weisbecker To: LKML Cc: Peng Liu , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Joel Fernandes , Frederic Weisbecker Subject: [PATCH 01/16] tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer() Date: Sun, 25 Feb 2024 23:54:53 +0100 Message-ID: <20240225225508.11587-2-frederic@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240225225508.11587-1-frederic@kernel.org> References: <20240225225508.11587-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Peng Liu The ts->sched_timer initialization work of tick_nohz_switch_to_nohz() is almost the same as that of tick_setup_sched_timer(), so adjust the latter to get it reused by tick_nohz_switch_to_nohz(). This also makes low-res mode sched_timer benefit from the tick skew boot option. Signed-off-by: Peng Liu Signed-off-by: Frederic Weisbecker --- kernel/time/hrtimer.c | 2 +- kernel/time/tick-sched.c | 39 ++++++++++++++++++--------------------- kernel/time/tick-sched.h | 2 +- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 1fd106af747d..95f1f351dcd9 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -747,7 +747,7 @@ static void hrtimer_switch_to_hres(void) base->hres_active = 1; hrtimer_resolution = HIGH_RES_NSEC; - tick_setup_sched_timer(); + tick_setup_sched_timer(NOHZ_MODE_HIGHRES); /* "Retrigger" the interrupt to get things going */ retrigger_next_event(NULL); } diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 417bb7f880ca..d4901654148d 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1471,9 +1471,6 @@ static inline void tick_nohz_activate(struct tick_sched *ts, int mode) */ static void tick_nohz_switch_to_nohz(void) { - struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - ktime_t next; - if (!tick_nohz_enabled) return; @@ -1482,16 +1479,9 @@ static void tick_nohz_switch_to_nohz(void) /* * Recycle the hrtimer in 'ts', so we can share the - * hrtimer_forward_now() function with the highres code. + * highres code. */ - hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); - /* Get the next period */ - next = tick_init_jiffy_update(); - - hrtimer_set_expires(&ts->sched_timer, next); - hrtimer_forward_now(&ts->sched_timer, TICK_NSEC); - tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); - tick_nohz_activate(ts, NOHZ_MODE_LOWRES); + tick_setup_sched_timer(NOHZ_MODE_LOWRES); } static inline void tick_nohz_irq_enter(void) @@ -1570,7 +1560,11 @@ static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer) return HRTIMER_RESTART; } +#else +#define tick_nohz_highres_handler NULL +#endif /* CONFIG_HIGH_RES_TIMERS */ +#if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS static int sched_skew_tick; static int __init skew_tick(char *str) @@ -1583,15 +1577,17 @@ early_param("skew_tick", skew_tick); /** * tick_setup_sched_timer - setup the tick emulation timer + * @mode: tick_nohz_mode to setup for */ -void tick_setup_sched_timer(void) +void tick_setup_sched_timer(int mode) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - ktime_t now = ktime_get(); /* Emulate tick processing via per-CPU hrtimers: */ hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); - ts->sched_timer.function = tick_nohz_highres_handler; + + if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && mode == NOHZ_MODE_HIGHRES) + ts->sched_timer.function = tick_nohz_highres_handler; /* Get the next period (per-CPU) */ hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); @@ -1604,13 +1600,14 @@ void tick_setup_sched_timer(void) hrtimer_add_expires_ns(&ts->sched_timer, offset); } - hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); - hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED_HARD); - tick_nohz_activate(ts, NOHZ_MODE_HIGHRES); + hrtimer_forward_now(&ts->sched_timer, TICK_NSEC); + if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && mode == NOHZ_MODE_HIGHRES) + hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED_HARD); + else + tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); + tick_nohz_activate(ts, mode); } -#endif /* HIGH_RES_TIMERS */ -#if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS void tick_cancel_sched_timer(int cpu) { struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); @@ -1632,7 +1629,7 @@ void tick_cancel_sched_timer(int cpu) ts->idle_calls = idle_calls; ts->idle_sleeps = idle_sleeps; } -#endif +#endif /* CONFIG_NO_HZ_COMMON || CONFIG_HIGH_RES_TIMERS */ /* * Async notification about clocksource changes diff --git a/kernel/time/tick-sched.h b/kernel/time/tick-sched.h index 5ed5a9d41d5a..35808bbb8a47 100644 --- a/kernel/time/tick-sched.h +++ b/kernel/time/tick-sched.h @@ -102,7 +102,7 @@ struct tick_sched { extern struct tick_sched *tick_get_tick_sched(int cpu); -extern void tick_setup_sched_timer(void); +extern void tick_setup_sched_timer(int mode); #if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS extern void tick_cancel_sched_timer(int cpu); #else -- 2.43.0