From patchwork Mon Feb 26 22:24:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 206968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2368011dyb; Mon, 26 Feb 2024 14:32:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV44GdRGPlhA3akC8YypQajWTQVawBWwZdoZMLivHUwFsRvXKQvXRIQnfphO3YHnexcaY3mFAwDv4kEz8GlzgbVLKp15w== X-Google-Smtp-Source: AGHT+IEMrnu9Gan35r+nhj0HWAZYoqLkNmijOfnYJ0IwKLn4HtxOvAvEBXXVcQvjeurZQG8ZQU27 X-Received: by 2002:a17:90a:d80e:b0:29a:67fa:7bbf with SMTP id a14-20020a17090ad80e00b0029a67fa7bbfmr5986758pjv.43.1708986720683; Mon, 26 Feb 2024 14:32:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708986720; cv=pass; d=google.com; s=arc-20160816; b=0LUBhY//9jxCklBWgLVRvzaMJElR4UdAE6A4M8zLWMlvHDwzO2rMvhzC7a6zKzj36+ Wt0vOKayPRSISAyTV43nieIBRmLJjavNvhJy2tXBK6i2JM7TOzWjotqOZCFpAQ/RpuHL umS6K5HJPqYJ6zQLtEPtq4FcfJiNV3BaH6QFSO9jtcBoGrgG8ujt/pQMEmXFqA8UqNo0 w8SV3iUHSUiwqebCcbxNojc1eiTt/LfhO3+MwMigfzvHrbV4qGPYQvdAIFHtMdsofGs3 YuYX+6LxeRGJFfKbq9zCmHHvUsPqO46ueoKUbCfEgjD5yXHlmkWCBAsZkhhVgjdJg3bz Rtig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=o/G6C9/G4u/CPD+cxAg48KLQaWTYbj1ouXiri7BRgv4=; fh=winNYrYSfZsXalU9A6nfOtDYnmCiVdGCfAmJYAycaaQ=; b=kMd02pRtd6YG1yilgeyL/XvnzehG6WAPmyp//Jt1oK/bMXBvOM+93Rd+ETRbmShkOH Ynd48fDkcclxYeoph6n9NIRJnKQhQz+VjnwKTEblVZFvYW7sTTwZb3A9fiC/tg54DlLu 5VtquGZL7cW6HL6W5QGoRcDDV4/FfVpm7gTdEkyfDG0fVrxOusexYVXRtKWKE6Niztuy h+ouJLR1mNnfzxQ7luJRtzy/HHxvz7KJLtd72Qj//0nBvK2rY/VIv+HDUAfL53EvfDOF u4G5mnSrnLVADxiuGYxRk8+8g8M32GUA/KBd0Q4F+NmxaVVN1+LDvK2HpLkYS5bwJmki wrnw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2QfzqHKq; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-82401-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82401-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id pg8-20020a17090b1e0800b0029aa7be81b1si3806189pjb.78.2024.02.26.14.32.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 14:32:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82401-ouuuleilei=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=@linutronix.de header.s=2020 header.b=2QfzqHKq; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-82401-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82401-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 C8912B242BA for ; Mon, 26 Feb 2024 22:27:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A96A01369B2; Mon, 26 Feb 2024 22:24:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2QfzqHKq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="p18jR+ua" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 A98F4135A76; Mon, 26 Feb 2024 22:24:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708986285; cv=none; b=TIOXP6KdKcS4e7gy4wrArhywSPLH3e80wHjkSJx0W6i3QlRmGI9eM5q2mKZXiXz040hj8y8yJj2hLVo/SMwiy+2x7ZbGfqmIcZLoFR1XTEcUegA5D8EPYsI4zuoXnY4/8NDLJqeszREN9lAkKjbuuEcDAU3gPmRkcSjkDpgjzS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708986285; c=relaxed/simple; bh=R0TQ3GEIDkbr8qCquKhdE15Qhnwdxh9Mav1l1xT353M=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=TLEjzeo8mTBA0a0JYZErPiNnF+XU4PijHvklpQNN+zgx+hQRFJFEGGXLFgvej0Km8lRXeZDF+DYh5dKlyvm81/35icxwnsbr3IClP2UuKo/Y6aCrTrGksYxKwCuaePihcxTCBdOQQ7CbBkSzKDH/qBwEKBi8XCQ9+More7qlkSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2QfzqHKq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=p18jR+ua; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Mon, 26 Feb 2024 22:24:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708986281; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o/G6C9/G4u/CPD+cxAg48KLQaWTYbj1ouXiri7BRgv4=; b=2QfzqHKqYSaXW65aLO8FSPCLdqpWzj2OVwakaXJ2F8t9ky8Bq/u5smXuf0UZrpMThT1VL/ FTx8dtKFbFGHkmTBCZVXV4pmWm+TpGnPcZZdylFqV2VfInesj5jhPPcA/NWI1IDU74p2TT pZnLvynlaRyTUmitFHiEaetxNZK03vntveiTeWi3K4PNYWUX5ztYjm86z9fPaYjCK1OYHh 2YbqKVbOLqXs1XK9DXTGfe8WqNS76tY4SFqgIXzHFO2cxsXUaEYpPSt/xLPV0ooc/En684 ocdIdiKIHTucafhAvjHwSH+n3hfKH3ECQMdRJQ6VXakxuvc32rJsLku73+FuOg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708986281; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o/G6C9/G4u/CPD+cxAg48KLQaWTYbj1ouXiri7BRgv4=; b=p18jR+uadXzAlmubJCbuVk5VEvGHDz0vxZBlrbU/GXsvTR9XBuuhHk/yDBZqnfR+7pk0By d86Q5pQVIh9YSjAQ== From: "tip-bot2 for Peng Liu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer() Cc: Peng Liu , Frederic Weisbecker , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240225225508.11587-2-frederic@kernel.org> References: <20240225225508.11587-2-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170898628107.398.13083154575515487608.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913357372679050 X-GMAIL-MSGID: 1792002459670214312 The following commit has been merged into the timers/core branch of tip: Commit-ID: ffb7e01c4e654d5c8bf2ce2a4830b826fa1f149e Gitweb: https://git.kernel.org/tip/ffb7e01c4e654d5c8bf2ce2a4830b826fa1f149e Author: Peng Liu AuthorDate: Sun, 25 Feb 2024 23:54:53 +01:00 Committer: Thomas Gleixner CommitterDate: Mon, 26 Feb 2024 11:37:31 +01:00 tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer() 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 the low resolution mode sched_timer benefit from the tick skew boot option. Signed-off-by: Peng Liu Signed-off-by: Frederic Weisbecker Signed-off-by: Thomas Gleixner Reviewed-by: Thomas Gleixner Link: https://lore.kernel.org/r/20240225225508.11587-2-frederic@kernel.org --- 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 1fd106a..95f1f35 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 417bb7f..d490165 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 5ed5a9d..35808bb 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