Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1248796rdb; Wed, 24 Jan 2024 09:05:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEal8ILfNr8Jd7UFd0kZqy3nfVxijyinmthCx0AoV/fjWnrTNVGK66WhjU4DW9x7bdAp6pH X-Received: by 2002:a17:906:6a07:b0:a28:b183:fccc with SMTP id qw7-20020a1709066a0700b00a28b183fcccmr1164122ejc.122.1706115944411; Wed, 24 Jan 2024 09:05:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706115944; cv=pass; d=google.com; s=arc-20160816; b=wjda7+J27gehM0mxbPivpWfkHVqA/dVMcTfbyE7F+SLl7TfUZ+cZeafvlmQXxPB6ZS pBm/Nn0DWIsL+dFTUiMgYJ2SMEf2Sb7zRQDrnZjCraqZyEjkvozkHYBy3geaGIDDW35y jURhl64OmeBsIeRdcZzWlXpFW9OmupbIqodk8i5VXPktWQZ7NjhYLGTZVUt1s4tTHkWc vGX/Z4HRCdzz7iiaDF1YkD9CmW0ybBxeU9dPWGi/C+KWPG2g82axbetB+kdjNdlbUhhd i0AR5Wauf0oPxiP4wLxI6Y4yYnB0zxHcB8iMoMSqoM1EX3H5PCxbIadwsSiIcRYatLv3 YjTQ== 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=JJ1SgK/gl45ZvPSddGsJDu7EvaMBUYysGPZGRNkaLCo=; fh=4P8gqRLFmANjcHHSJu0T2ajtncG7F3hkmyD1v1G3zYE=; b=CB/xQN1wMp+BLsXBqidMsSawMkIqcJHrtGrcGL3tAPZSptsglhCokOtvWenqN1ox6U YTx4uBgYq2se8uLt1npNTbfC6kuPxAdfS4a85nMrOHJFUA/GNGNXXcx/ZOyP8mcDUGrV 0mcxq5jq4eUWAoiBV/OnkpjEeLGJjqwWsPfS45BwbfhF/v14vwP2LtukK8deEIw7GI/t IifH/z7oBG3YVQSXxNoqrhWTFKvXhpKOpVeHbU5S1qkg3UfLkJAAAUbihBAeOAnEZo3x 1mTgEFnlOsIBPgmSmLPPKWkfr08utiAwsfcGTnuyOkwPtELk+nvje6dTh9/jI+w5S0St CxVQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TQfsInHm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-37380-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37380-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e20-20020a170906249400b00a2de3fac739si69969ejb.699.2024.01.24.09.05.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:05:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37380-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TQfsInHm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-37380-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37380-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2AA0B1F22FB4 for ; Wed, 24 Jan 2024 17:05:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 594547E798; Wed, 24 Jan 2024 17:05:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TQfsInHm" 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 7714F80058 for ; Wed, 24 Jan 2024 17:05:12 +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=1706115912; cv=none; b=sq6GvXmd6rj8zwJn142eYKOJr05cM3XxCdkoISQT2COC0kad5TS/jEylTsHFcDLvNzuKzNQIzmKQAJO5Z1ZRr8mF9oy3yQH2ycSmsqPDQ59IYl6ekAvtZ/YyfsUnBYxmlycek0j/4eqqcZ3l8l5wKzcws1neUloj1HGjr/NNThM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706115912; c=relaxed/simple; bh=yHPR6j3OL36RltRUGFvaGlb/MMYM5ilnHWsVaQEKuT4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NcYvRfNQJirxiwr1aQKCCNn6zfHo78+kZ+BpuMORA6CYAKyemi3dxvrjJJ3JiQ7dtrk2mhT8PUlHPMKut3a/S22lxtFs/2KNZPwDafzKS9GDI0rAqmltLCWEpHsoxVkwES0xGXLaePujzwKjLutTrwFVVRw90Bz8ZzAfBaFLhcc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TQfsInHm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6EABC433F1; Wed, 24 Jan 2024 17:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706115912; bh=yHPR6j3OL36RltRUGFvaGlb/MMYM5ilnHWsVaQEKuT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TQfsInHmRq9DSrjfNMLhsPDqw+p77hD7gmMndejyr2j4ovFyXStTsUR4BY+7zGZNW 6TjJ3foqNPdU+BM3L4D3ZjbXEmn3i02koEdCeCtpGjj9cGDNPvlBMaKtnoeju5/eIp 8OtrIh2aLovc5ot5goCSePo/QKJWwRwepBPwoZNQV6NH1MqsPIo96hy7Hr+S2S3Uet G83GVehCyNDctDdTNBjm2XxQjRYwCLUtwThdxRjjgM4gldwz8t2JVNxW3IPnWS9gbk oQvjMkqxUetd/8h6SZ4U7jd3wT0DXCTeSag24Nxustpi7eStWk3HdWSCuiLS2dR4pZ znaL1S3Gth1hQ== From: Frederic Weisbecker To: LKML Cc: Peng Liu , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Joel Fernandes , Frederic Weisbecker Subject: [PATCH 01/15] tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer() Date: Wed, 24 Jan 2024 18:04:45 +0100 Message-ID: <20240124170459.24850-2-frederic@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124170459.24850-1-frederic@kernel.org> References: <20240124170459.24850-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 | 38 +++++++++++++++++--------------------- kernel/time/tick-sched.h | 2 +- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 760793998cdd..355b5a957f7f 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -746,7 +746,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 d2501673028d..e90dbb7ae70a 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1433,9 +1433,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; @@ -1444,16 +1441,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) @@ -1532,7 +1522,9 @@ static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer) return HRTIMER_RESTART; } +#endif /* 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) @@ -1545,15 +1537,18 @@ 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; +#ifdef CONFIG_HIGH_RES_TIMERS + if (mode == NOHZ_MODE_HIGHRES) + ts->sched_timer.function = tick_nohz_highres_handler; +#endif /* Get the next period (per-CPU) */ hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); @@ -1566,13 +1561,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 (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); @@ -1589,7 +1585,7 @@ void tick_cancel_sched_timer(int cpu) ts->idle_sleeptime = idle_sleeptime; ts->iowait_sleeptime = iowait_sleeptime; } -#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