From patchwork Sun Feb 25 22:54:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770217dyb; Sun, 25 Feb 2024 14:55:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWRM8khuiQavKWrizwlbGQLzZSAbqn3tbQRxPUlYjm+/zDQe+KXCwzCGQo09XfQEmdFdK4Tn9MyN+2Vi3M6J4PBj1u44Q== X-Google-Smtp-Source: AGHT+IF8agI9MhVA9BWM6F7V46aIzoqh9QDLLr1IMifs4IXJzIrl/+iu9oZjSKP+VgPE9nAHu/Om X-Received: by 2002:a05:6512:3087:b0:512:e1c3:5ab with SMTP id z7-20020a056512308700b00512e1c305abmr3605894lfd.45.1708901746057; Sun, 25 Feb 2024 14:55:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901746; cv=pass; d=google.com; s=arc-20160816; b=SEwfnzjbyNoj/1qLjtNDSiB2uC/lje75BOTyT3Zf7p0YFrMpaGwdgR34NgGgoFaeuj jZjErtozNSoT3tESpq6WNT76pL/WRuyulHrwY/nFtHfkx8eG8OZLekeSx72WWwmUbty8 3eW0FbDAVMprC8kqnp2JACmW5yE375sBRaklNZnHZ9v20wDFCMsWPp7CMsETPocKww7E BBjhnbkOLrers/+29a1PQQ0J1los6R93NXny3aBWhjElw5YAi+ZU1H6zXsDvrfCVOPb/ YLmupjBVLjBa2F9DrCmZzVG9xWv3QOJw3q1InyhtK5IgzMA+BH+hReBC/IHQL3WryVpG PSNw== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80328-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v25-20020a17090606d900b00a43109ef737si1022858ejb.272.2024.02.25.14.55.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:55:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80328-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80328-ouuuleilei=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 7E7201F21C77 for ; Sun, 25 Feb 2024 22:55:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 840161C295; Sun, 25 Feb 2024 22:55:19 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913357372679050 X-GMAIL-MSGID: 1791913357372679050 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 Reviewed-by: Thomas Gleixner --- 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 From patchwork Sun Feb 25 22:54:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770252dyb; Sun, 25 Feb 2024 14:55:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUIblt0SPEJklu8fPlhCl9pnkN6u+2Tnr+314ReYtRqiVzxf18WzP/SN9UjdJvN+anxFX2byXWtHVbr1SaaCIHw49QjOw== X-Google-Smtp-Source: AGHT+IG4Msgzczo0yskZTlBGAETvxqnpBeeYlahoMaEzuYRgeAZJKT53fY9BzZICWDX7t1u4HZm+ X-Received: by 2002:a17:90a:e2c7:b0:299:35ea:cfb5 with SMTP id fr7-20020a17090ae2c700b0029935eacfb5mr3058885pjb.2.1708901754843; Sun, 25 Feb 2024 14:55:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901754; cv=pass; d=google.com; s=arc-20160816; b=Obl3yWYPfiTZGZ0BDZejFLq3wxoa/0zY33XD/O5XCdOxG/W5NbrmU1oArG8JN1SBjo 8F3CX8kgBMlSQY2jPLyIjrw9eXX2wWYQiQVe7zPQk4gmvjNFx7+TPMtK6/rp14GeuaHb XHZGKQPebX0B5lAaVc28jNV62k1YHrRv90s2Wa9mwZ4KMke81i1CjvigRkAl+9akIM6K r1zOoD7ZGai7fkDWFUIx/jnBVRjfWasISpHXriOE7JtkDkDtofJfo5RWl2QB9dCnOb6F LE5ekMfrS0zUNG9iO1P8Bt9mJ9iqGfCn1o5O2lJYX73rKFnOzF6ovPEL8UfADHPkxdFM +eSw== 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=F2HMzsbSBya5PazJzoP4ezhwGTyyYr23HIP8ixzYQu0=; fh=4P8gqRLFmANjcHHSJu0T2ajtncG7F3hkmyD1v1G3zYE=; b=zUcQrkQ9oK36qAM6ctG8FWxL3XcOiP+RDjbwALcPANaWCdxvkC6ugFXxoDuAPghD+h tQmq+Xux+6TgsNUnKS/is8te9pINY1zjgbGTTqFVzSEE/gDQGoQ4waKx2cR1o4sg3xeO hLiV3xPSu+lmDNshBvSjxe7vW92+wU2Gd3I18qRJmd2Ra0IjlNL3QlijO+r9NZsGfq9p zQR6n2CxeiIOh+1YQw9N5XzNVEM2vnyS/eouK9Qxp3Qv0d+ZScd+4Itt65WNf9h6Nl0z o9IaoQH+at0pA/lbUjAV4HegmtoXRkhPmiEOalSozMvnUOU+9mmuBiw+3pe8wCU0gAMq n08g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dEq6qFQu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80329-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80329-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o4-20020a17090ac70400b0029a5eba078asi4541691pjt.142.2024.02.25.14.55.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:55:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80329-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dEq6qFQu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80329-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80329-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A798E282065 for ; Sun, 25 Feb 2024 22:55:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6303F1C6AF; Sun, 25 Feb 2024 22:55:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dEq6qFQu" 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 8DFDC1BF32 for ; Sun, 25 Feb 2024 22:55:18 +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=1708901718; cv=none; b=g5GtRgW2QFBktW0/j3prbb8sYBVukfy1LjaERT5ACxHhW/Rcq4AeigaoDd3tGIrJpawowFLY+Cr5wKGZ0T8ShjW+kuRmRR3JSyaH/cUKDRFzjS9LEEzOkopdmPaNIXgXSYqJj+vxYyFYOzlJM2hxc41A+Gqm+Q+5BVJsJwW7BXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901718; c=relaxed/simple; bh=+VkDJHjdvXPixo+AoZLYaSFfxZZUAYxpQOjC47SAJvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YhjspfS4luiDyP7OYQNBJ9fpTdG1OnueLBdlzqjg9/W6GP3gwfQOXxSovdzPyis+BFKgboQJnfA7yY1nowJBoRaa3yJCXXt3/auPhNrUl1/gEKv/okPj+SmJifSj0wp4bQYu2CncnLCq/l2+Zg0GPx5PkYVM8s0Dy5UnX7g3lCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dEq6qFQu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93B78C433C7; Sun, 25 Feb 2024 22:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901718; bh=+VkDJHjdvXPixo+AoZLYaSFfxZZUAYxpQOjC47SAJvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dEq6qFQu6pU6EZ3Ejzac3rNBls6OXzOOCQ+HwqB3QGi+X0lUQFwqGVF9DrN9zlrUY DQDlNOHff0D4hFajnvSo3Zq92dTzGGeMc7mgKVAga5AXLxpDLWqs3p7Ilm1ucNMsq7 uSxkWQHyJMajQ1qROJqXky/AF+LhPEe4iPZXSm6VXYRk8vaI7JSxfmwxJDA1aAtBUV Lmbt8gnIle5ppJt9mryOoI3o0c/mMAPwQjxCmnmZB6K6EkVTBgJBxH5EsHFxe0znkh n8GvsM2LFoSNdxWasYTBxMBOn5BxAXjja6M3rTI/76AeEhzMi/fHpC5MNvC0+0xT5i QD2O6tsI2JhHQ== From: Frederic Weisbecker To: LKML Cc: Peng Liu , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Joel Fernandes , Frederic Weisbecker Subject: [PATCH 02/16] tick/nohz: Remove duplicate between lowres and highres handlers Date: Sun, 25 Feb 2024 23:54:54 +0100 Message-ID: <20240225225508.11587-3-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913366158391970 X-GMAIL-MSGID: 1791913366158391970 From: Peng Liu tick_nohz_lowres_handler() does the same work as tick_nohz_highres_handler() plus the clockevent device reprogramming, so make the former reuse the latter and rename it accordingly. Signed-off-by: Peng Liu Signed-off-by: Frederic Weisbecker Reviewed-by: Thomas Gleixner --- kernel/time/tick-sched.c | 96 +++++++++++++++------------------------- 1 file changed, 36 insertions(+), 60 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index d4901654148d..88c992f48126 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -255,6 +255,40 @@ static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs) update_process_times(user_mode(regs)); profile_tick(CPU_PROFILING); } + +/* + * We rearm the timer until we get disabled by the idle code. + * Called with interrupts disabled. + */ +static enum hrtimer_restart tick_nohz_handler(struct hrtimer *timer) +{ + struct tick_sched *ts = container_of(timer, struct tick_sched, sched_timer); + struct pt_regs *regs = get_irq_regs(); + ktime_t now = ktime_get(); + + tick_sched_do_timer(ts, now); + + /* + * Do not call when we are not in IRQ context and have + * no valid 'regs' pointer + */ + if (regs) + tick_sched_handle(ts, regs); + else + ts->next_tick = 0; + + /* + * In dynticks mode, tick reprogram is deferred: + * - to the idle task if in dynticks-idle + * - to IRQ exit if in full-dynticks. + */ + if (unlikely(ts->tick_stopped)) + return HRTIMER_NORESTART; + + hrtimer_forward(timer, now, TICK_NSEC); + + return HRTIMER_RESTART; +} #endif #ifdef CONFIG_NO_HZ_FULL @@ -1429,31 +1463,15 @@ void tick_nohz_idle_exit(void) * at the clockevent level. hrtimer can't be used instead, because its * infrastructure actually relies on the tick itself as a backend in * low-resolution mode (see hrtimer_run_queues()). - * - * This low-resolution handler still makes use of some hrtimer APIs meanwhile - * for convenience with expiration calculation and forwarding. */ static void tick_nohz_lowres_handler(struct clock_event_device *dev) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - struct pt_regs *regs = get_irq_regs(); - ktime_t now = ktime_get(); dev->next_event = KTIME_MAX; - tick_sched_do_timer(ts, now); - tick_sched_handle(ts, regs); - - /* - * In dynticks mode, tick reprogram is deferred: - * - to the idle task if in dynticks-idle - * - to IRQ exit if in full-dynticks. - */ - if (likely(!ts->tick_stopped)) { - hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); + if (likely(tick_nohz_handler(&ts->sched_timer) == HRTIMER_RESTART)) tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); - } - } static inline void tick_nohz_activate(struct tick_sched *ts, int mode) @@ -1522,48 +1540,6 @@ void tick_irq_enter(void) tick_nohz_irq_enter(); } -/* - * High resolution timer specific code - */ -#ifdef CONFIG_HIGH_RES_TIMERS -/* - * We rearm the timer until we get disabled by the idle code. - * Called with interrupts disabled. - */ -static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer) -{ - struct tick_sched *ts = - container_of(timer, struct tick_sched, sched_timer); - struct pt_regs *regs = get_irq_regs(); - ktime_t now = ktime_get(); - - tick_sched_do_timer(ts, now); - - /* - * Do not call when we are not in IRQ context and have - * no valid 'regs' pointer - */ - if (regs) - tick_sched_handle(ts, regs); - else - ts->next_tick = 0; - - /* - * In dynticks mode, tick reprogram is deferred: - * - to the idle task if in dynticks-idle - * - to IRQ exit if in full-dynticks. - */ - if (unlikely(ts->tick_stopped)) - return HRTIMER_NORESTART; - - hrtimer_forward(timer, now, TICK_NSEC); - - 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; @@ -1587,7 +1563,7 @@ void tick_setup_sched_timer(int mode) hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && mode == NOHZ_MODE_HIGHRES) - ts->sched_timer.function = tick_nohz_highres_handler; + ts->sched_timer.function = tick_nohz_handler; /* Get the next period (per-CPU) */ hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); From patchwork Sun Feb 25 22:54:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770296dyb; Sun, 25 Feb 2024 14:56:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUtbnH7x2iDoWKem7fL0LCMBnI8jpJT6qYsLwjkAkHY1psRDDYQZfkX2mafp9YVuGOTyvH2TZ284jiceUVLTrOv0rHpIQ== X-Google-Smtp-Source: AGHT+IGhHN7KWdxh54R3AdTWluW2yDptx3ClfL/UE48slZWXTof/D4PHKIm79bny9PJguefpyUB1 X-Received: by 2002:aa7:868d:0:b0:6de:1b57:ca8c with SMTP id d13-20020aa7868d000000b006de1b57ca8cmr4882505pfo.23.1708901767943; Sun, 25 Feb 2024 14:56:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901767; cv=pass; d=google.com; s=arc-20160816; b=tcRJ/ZHSIL/2Dwo2ESIxLAr15Ig96SZTZaOZmKogQDUbhUS6CCzDRwNNJKDKhknyV0 sMZdy9kdohkArygKZMXA8kbs+lPyGK9iBJRqNKs2fmbVaLtTQsqVxioS4/CRgC6GTBdG FYm6CCSP7RE5qa/LNn6N11md9F23i0yme6tDEfj7OQ7B9WFf49J7pJsHCm54TcOHKOpZ O0uiZvzPUdFonlb5yD0E2fpcVe2jEtPL7j8hUnMvEkGVzgRnXLY64Y73ohCmAzX2gxxa uaMxSbVwXTj8mmJ7GhL1yXUY5bPCGLd6bzCe7CmrrFx1IsOTnLJqXDBQ9dujQlqhwNHH 3QMw== 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=vcR1WnYz0wmQlhW4q7UfXNCFmCQ/ghhN/ytUtcHmT24=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=NRAg5wrjJR84t1iqB9DPom5dLHrinwWdIAbX0agOC8l0bhH8YiNYyrijw9MKshUmL/ P/SHKPOhviebGW4uvW0feC8VnkZscXMH+hAy/HgjSJSEKCswNBsuodKJs6Fz23qpcY1l vB93faEr7MKD+fMN4vKyoZdEGMbqSVb8P5b5YJy/hPx51LCo+NpadE6UCDJ+MBmXkF3W CRV7Pr0WrVYIaGQ373Jw4bBqGDUqC1F88jppvSwKurp4HQNCTPzL4XyqdIxSfL2EaOMa CtwxyZNcgfPg9IZMGsXd78AqRgP6urvlJt3vk7llObZaTAqu4sxVp41fq97tQd40Zbst kYTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rCDSSL8H; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80330-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80330-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 9-20020a630009000000b005dc98dad591si2692251pga.707.2024.02.25.14.56.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:56:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80330-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rCDSSL8H; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80330-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80330-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BEB91281FE7 for ; Sun, 25 Feb 2024 22:56:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0E381CA8C; Sun, 25 Feb 2024 22:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rCDSSL8H" 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 13F9A1C6A1 for ; Sun, 25 Feb 2024 22:55:20 +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=1708901721; cv=none; b=YvjkluOdOV8ozjyKobbStZtlg6/hw5jbkEPIg9x9dmOru6f/yU8Li6A+Hr5pqXdzFx8d9c4QP2sY6B3YPHKwDZRHKh1bM+X50jcpDDPQGi/dTnM27+KDB5HFrB9fXB8XP1YiWHc6G1ReDkDOxqKGVTNG/yKZCnmGIBa4bUPp+Mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901721; c=relaxed/simple; bh=IqLfgv0CY7qkTUyv21aAmqS1ETFIUjP/QLPaIXsEnIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Klc2vouo29CNsSOrSB6HhBEK9u6wZPgxy6b6zmf6kLkw/QykVkLPjBsaDb2iJIxE6NyYML1OMrg7NJ9tBcI07/B5/4VgaEd2FCO8iS6eDBkTGvsslNzwWEfz3K/9ccq9w52jvcjs+imW05I5wpFrvV7k+dYfDSWRNmi3vj02RtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rCDSSL8H; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0C70C433C7; Sun, 25 Feb 2024 22:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901720; bh=IqLfgv0CY7qkTUyv21aAmqS1ETFIUjP/QLPaIXsEnIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rCDSSL8HBySNRgVYrhvPX4oxo3P4sPwhiqjEW45X11zBnm+q17QNkPMPZc5Rkz9lO VM/0rZ8DjQeeWWKftNpl2Y5H3ZAA7OmasnfeKtvVcnifnodP3zWAhY3kq424is3Dt+ sXsHRXsjctSNIqLrr3vgfg0x2UafV3412HgMW30EieC6EfjNOs15mp28dEjTSxXl12 yPRouNzq89x5vIc2AlH3SeCS+DHgFuPsEXtgHxEoPnsLginZd9LpaPhreuubkyULbF FnUvxM3SoxQtkw8AtbjN/5LLLvK8FVew7XHwA6wbruExJm8TajJGJxqXTJ6okKkXFH iw3VAyoR49JqQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 03/16] tick: Remove useless oneshot ifdeffery Date: Sun, 25 Feb 2024 23:54:55 +0100 Message-ID: <20240225225508.11587-4-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913380163748122 X-GMAIL-MSGID: 1791913380163748122 tick-sched.c is only built when CONFIG_TICK_ONESHOT=y, which is selected only if CONFIG_NO_HZ_COMMON=y or CONFIG_HIGH_RES_TIMERS=y. Therefore the related ifdeferry in this file is needless and can be removed. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 88c992f48126..27aaecb2e50c 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -43,7 +43,6 @@ struct tick_sched *tick_get_tick_sched(int cpu) return &per_cpu(tick_cpu_sched, cpu); } -#if defined(CONFIG_NO_HZ_COMMON) || defined(CONFIG_HIGH_RES_TIMERS) /* * The time when the last jiffy update happened. Write access must hold * jiffies_lock and jiffies_seq. tick_nohz_next_event() needs to get a @@ -289,7 +288,6 @@ static enum hrtimer_restart tick_nohz_handler(struct hrtimer *timer) return HRTIMER_RESTART; } -#endif #ifdef CONFIG_NO_HZ_FULL cpumask_var_t tick_nohz_full_mask; @@ -635,7 +633,7 @@ void __init tick_nohz_init(void) pr_info("NO_HZ: Full dynticks CPUs: %*pbl.\n", cpumask_pr_args(tick_nohz_full_mask)); } -#endif +#endif /* #ifdef CONFIG_NO_HZ_FULL */ /* * NOHZ - aka dynamic tick functionality @@ -1540,7 +1538,6 @@ void tick_irq_enter(void) tick_nohz_irq_enter(); } -#if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS static int sched_skew_tick; static int __init skew_tick(char *str) @@ -1605,7 +1602,6 @@ void tick_cancel_sched_timer(int cpu) ts->idle_calls = idle_calls; ts->idle_sleeps = idle_sleeps; } -#endif /* CONFIG_NO_HZ_COMMON || CONFIG_HIGH_RES_TIMERS */ /* * Async notification about clocksource changes From patchwork Sun Feb 25 22:54:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206132 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770333dyb; Sun, 25 Feb 2024 14:56:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUFypO8G75Zgd0fcn01oF1RFrcrjS8QpwL1Ca66tV0pKu0v3qp8K6Qx+oVQ95/POGAsAoJNUgbljPtdJhxyQoA7WWNIoQ== X-Google-Smtp-Source: AGHT+IEJN/cA5LjkTM5JkZ8Kl/mGwgcLdx77vWZI0zhmH3DgY14dNg9DKX64vAzGxocvI2HerbLd X-Received: by 2002:a0c:f2cd:0:b0:68f:634d:443b with SMTP id c13-20020a0cf2cd000000b0068f634d443bmr7804379qvm.2.1708901780894; Sun, 25 Feb 2024 14:56:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901780; cv=pass; d=google.com; s=arc-20160816; b=xvM91qmecZ7wPZ9sM6O8IFc7oPeZLU4RpRTcWyqHdm6dp/tLzripO7hcfTmXDvGv7L NS/Oppfgas3aZNCcqOAcnBRU/bPmQqHuo+tS3JX2HVgo6r5ObvJfG6NUXuC18Pn54aOR rsEL8cbJ6vfA8r9aMKD5/VKAtXFNlH+pY0HoMS4jfZt2BtlnoCUlPnVfpDRwsSgKSxVO yzy38ezjdP7xPJ4JAMKdMITns3cX/9qjCZDfhIngC4LxC0wCF+Q4VGyCcqcmC25ZFFY1 vZAu1ZhTLK6303zDFOoIp0raLMPhJiPth3/Dqz3qEZkkbFg14RK8g7AEzSHyuYRH/F76 MF+w== 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=KP57oNgiiWc8bUQWDLBfL9MmrbUo4nKOqFci7pn/N6E=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=iK0VaQNTwGol+F4OeDCd+FQnLueHb6/GTayJNzBEmKqaYZx35l+19sta8mz0ElNIl3 PaYVMzwHoMYkn28AJ6SPfZBi19n7RUYqNNgf4fopOAwBwuEHBmGXlVSwhQqx4r94sx2I 3/HGgRib1alX6oXj1CdPNV+bABYLwJB1HJEnF7AoERPGuVs4EX79KEnRswM0KctmT/dK ctn+Zp380cbabpoKPww3HvhKFQHgCu5hetxUhc1pxvS964e3CGUwonTw82q7qzxMUwTa E7Sh573Fug08IF1EjL+JrAV8XZzpw7RhDClkZE1QuZuIqoVJC5poO0nf69fbva0bBjzw +ckQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aJiqOwTa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80331-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80331-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r13-20020ad4576d000000b00690085cd8eesi1176863qvx.568.2024.02.25.14.56.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:56:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80331-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aJiqOwTa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80331-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80331-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id ADF191C210D3 for ; Sun, 25 Feb 2024 22:56:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B60611DDD1; Sun, 25 Feb 2024 22:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aJiqOwTa" 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 133D41C6BC for ; Sun, 25 Feb 2024 22:55:22 +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=1708901723; cv=none; b=lJFCny5mlXn27ZBYuzshyZrZlr1gfLZ4l/UiA/akgJA1QXiNQLqgdYNbXvQGtBh6GWVt6bkTzMKk0Zf7rhiB0lQ+86xlSesxBo+UAAmhfES5Cy+pyrlrWwPhds32fDeMNRg45Loy6Ylu2rO1m0Szk27KfjDduDR2HiaJJMoTARU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901723; c=relaxed/simple; bh=Uf94OwcRiSANlW0Oxi4zepCxsB0vE767pi+Mh6tUbYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n7P7IT1VN6kitmSr63ZlX7HC0lxRFm+fjzCa7NuPm+oNeWEYUsKmebP/M0Q1Uz6LIzP6En/cTcpPlNpXm2NULgoyJgxYs3iKOfBLgeIpiO3ktOgEbB7ZTH5pAvapCkE8wi33cCBx9h9IM8TJ4lx5Wwy7se43s25ijqQJZsOH17M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aJiqOwTa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B472C433A6; Sun, 25 Feb 2024 22:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901722; bh=Uf94OwcRiSANlW0Oxi4zepCxsB0vE767pi+Mh6tUbYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aJiqOwTaNKs7nT10lRqYCUxxCsw5cqZ7uUhn3K1lUaPPznGvnTAGwOlIUPDQKGOO7 3Lj6mO7SyUuCzZaY+mNUO/wFcZefZAVaXOlqGFZ3EefthIm7999koKBPdyuwGls+sd f9Iyk600QRuw8EGYW5ltYs6015SsgJbGq3cnRqC88BBNgliUNVbt4pOa47KZjMbm+W u1wA6R/ipUJIm8r5yspWO3h64j93F2h4U0+348IdeBeEfGpoSwDLroO/ViiscWGOHN pN/bIIywPRE2IKqlcQpNGpBshwU7kjss/0vDItHoPZPjH7mkphwaKFU6AstZOopE5m Wwt62ZVpnUxGA== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 04/16] tick: Use IS_ENABLED() whenever possible Date: Sun, 25 Feb 2024 23:54:56 +0100 Message-ID: <20240225225508.11587-5-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913393536375129 X-GMAIL-MSGID: 1791913393536375129 Avoid ifdeferry if it can be converted to IS_ENABLED() whenever possible Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/tick-common.c | 4 +--- kernel/time/tick-sched.c | 14 +++++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index e9138cd7a0f5..0084e1ae2583 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -111,15 +111,13 @@ void tick_handle_periodic(struct clock_event_device *dev) tick_periodic(cpu); -#if defined(CONFIG_HIGH_RES_TIMERS) || defined(CONFIG_NO_HZ_COMMON) /* * The cpu might have transitioned to HIGHRES or NOHZ mode via * update_process_times() -> run_local_timers() -> * hrtimer_run_queues(). */ - if (dev->event_handler != tick_handle_periodic) + if (IS_ENABLED(CONFIG_TICK_ONESHOT) && dev->event_handler != tick_handle_periodic) return; -#endif if (!clockevent_state_oneshot(dev)) return; diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 27aaecb2e50c..4e34967edc0d 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -186,7 +186,6 @@ static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now) { int cpu = smp_processor_id(); -#ifdef CONFIG_NO_HZ_COMMON /* * Check if the do_timer duty was dropped. We don't care about * concurrency: This happens only when the CPU in charge went @@ -197,13 +196,13 @@ static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now) * If nohz_full is enabled, this should not happen because the * 'tick_do_timer_cpu' CPU never relinquishes. */ - if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE)) { + if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && + unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE)) { #ifdef CONFIG_NO_HZ_FULL WARN_ON_ONCE(tick_nohz_full_running); #endif tick_do_timer_cpu = cpu; } -#endif /* Check if jiffies need an update */ if (tick_do_timer_cpu == cpu) @@ -230,7 +229,6 @@ static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now) static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs) { -#ifdef CONFIG_NO_HZ_COMMON /* * When we are idle and the tick is stopped, we have to touch * the watchdog as we might not schedule for a really long @@ -239,7 +237,7 @@ static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs) * idle" jiffy stamp so the idle accounting adjustment we do * when we go busy again does not account too many ticks. */ - if (ts->tick_stopped) { + if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && ts->tick_stopped) { touch_softlockup_watchdog_sched(); if (is_idle_task(current)) ts->idle_jiffies++; @@ -250,7 +248,7 @@ static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs) */ ts->next_tick = 0; } -#endif + update_process_times(user_mode(regs)); profile_tick(CPU_PROFILING); } @@ -1587,10 +1585,8 @@ void tick_cancel_sched_timer(int cpu) ktime_t idle_sleeptime, iowait_sleeptime; unsigned long idle_calls, idle_sleeps; -# ifdef CONFIG_HIGH_RES_TIMERS - if (ts->sched_timer.base) + if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && ts->sched_timer.base) hrtimer_cancel(&ts->sched_timer); -# endif idle_sleeptime = ts->idle_sleeptime; iowait_sleeptime = ts->iowait_sleeptime; From patchwork Sun Feb 25 22:54:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770374dyb; Sun, 25 Feb 2024 14:56:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXlFxSDN2IwZk/y4q5W4zeQFltSFib1xD/LpY/+2nNxvWFp4ZhzBEwBlJ5tfYBz7ZberDna9E6tIHrs5YfwCLeCd+lUoA== X-Google-Smtp-Source: AGHT+IHFjDd/Ifk9uOFiVKK3b5AApADjJGtX3f0kLqBoelfjpJPv80zwe+nqSsmOiosy4LxrIhxS X-Received: by 2002:a17:902:d4cb:b0:1dc:8b82:7f56 with SMTP id o11-20020a170902d4cb00b001dc8b827f56mr5606828plg.20.1708901793396; Sun, 25 Feb 2024 14:56:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901793; cv=pass; d=google.com; s=arc-20160816; b=s5Fl9EjpK7n9F6VLmVBFVDICb7iAIjNsUy5E5lXX16/4Tnr8Hhv75DlbrEdlSMsfnz dY0X0vnhjvfJtv4z/6TX5JpkKluD01zxaDePfvrLI9phEK1ipd9XsKp41v/jdoBfJzMy LSdcwYv1IpczZahS0YjioN5IRgd502ponJabnZjhPGoQwuBiReYtnKQhzftTC6y3QDjX PyTL6Ffh7374xM8HV+1Hk9AMHG+0mdRir4f9/5pq1t9NfMWH2TSQV9kq1daiAzrdivPG SUD+6GX52NccdCE4hzvPl6DWT80gmVfMUK/wcoErSpnLGyefSX7AHo9QetMBa/De086k xmEg== 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=s026lBjpy8GRvcAWeAlp3WMFQiXWmm2HHylqzxIoa1A=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=zGzN5MtWQwoq3hHjs7PbSC1sUq1UQ4IhDtEY018DlJG9I70AkLtpeSMxnltvvNVHAM XW/zsmR5JBYEpZiIpdRbrgKAXrUzrvH+YYyGnneA7bee4N5JzCos7bpeksSsN+VjYZFt eMbJ/hKbqPhCFsRtx3aXbjLskjFaWQmW177rSe8Sd8S1gMTv81RbgQJRCA1dZKs5kVUb VeFGmW+wi/DQ2/JTlSmkJadsMQy5RBn4cIHmY+qWZ9AqSS3zWpz/zILBhGiL7+2VDUsj efpRHPL3cv17Y0tXaWhjvyFBIWFwlF3Cno7BNcFF9xIwKkMCip4kimMoCVz4ITXnlPB0 VpPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Rr7isJqi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80332-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80332-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j18-20020a170903025200b001d8a9162f22si2672645plh.60.2024.02.25.14.56.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:56:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80332-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Rr7isJqi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80332-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80332-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 39609281F65 for ; Sun, 25 Feb 2024 22:56:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AADB71F94C; Sun, 25 Feb 2024 22:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Rr7isJqi" 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 16DA21CD1A for ; Sun, 25 Feb 2024 22:55:24 +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=1708901725; cv=none; b=VxEPXX6wNl46Neidqc2E0cwufMNgex61j7gLdBTBUEWXGBe7EyPUPrPTczGLAnkDz7mnViKDXogzl09cLXsbb8ybVlu1+OZ1QaXd1RuFYA8kyx2yUuTC7boMox4rvGQWdjF0V8xiJX6kFullJTVLDp3xiWKKBQfMxQRMJxPUocg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901725; c=relaxed/simple; bh=IamgszwyZ3IggU9+C9+L0AHD8yJxSmoVUB5dySoZ5Bg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p4M2D3xpw0j5V+aiE1AMsLBbqdMxGaoHwVgeTjW0ICkl1KxI3tn4Hc6fJSpIiYZsAtKV37D+0pJITbO6hglQOrdpkWdltkPD2nKxlRaWDSAPV9l5yss7J9MZNCCnlLDRT+Yf1U69+j6LvGSOVBS1g7AV+Id+56AhWP6LKNUCLgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rr7isJqi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24A0AC433F1; Sun, 25 Feb 2024 22:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901724; bh=IamgszwyZ3IggU9+C9+L0AHD8yJxSmoVUB5dySoZ5Bg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rr7isJqiDhIDuwueOypOg8KMlIwexB8lFBwW6JDcheReDFJIAwiF9oMKhwR3hn5m4 6kjrKILkI8H8+slfeeQgWj3RXKnXHBMup23qMYJ/v7et58hB+WXGPnvGyXVgO3lAfg iVz6jjvFdasMsVUL4YTGL50zhFjP7auQKSNSkg3ny+BirlxSZyWg7iUFANKU+QTGco fPypIq2Cr6Lsiu59j1PXby4azbkRFhQR5QhDACyprCPu6bW98bun6Jbmpty5DBukLv 8fPUUr0qfcTQRUj1GjpgAvTfeOvWPHArfoRtiuDKYhxJGmVdzVJaAcpLiH/lz1Kfbt XnMVKHhbjo+qg== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 05/16] tick: s/tick_nohz_stop_sched_tick/tick_nohz_full_stop_tick Date: Sun, 25 Feb 2024 23:54:57 +0100 Message-ID: <20240225225508.11587-6-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913406917978685 X-GMAIL-MSGID: 1791913406917978685 tick_nohz_stop_sched_tick() is only about nohz_full and not about dynticks-idle. Reflect that in the function name to avoid confusion. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 4e34967edc0d..9f75f5621965 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1040,7 +1040,7 @@ static void tick_nohz_retain_tick(struct tick_sched *ts) } #ifdef CONFIG_NO_HZ_FULL -static void tick_nohz_stop_sched_tick(struct tick_sched *ts, int cpu) +static void tick_nohz_full_stop_tick(struct tick_sched *ts, int cpu) { if (tick_nohz_next_event(ts, cpu)) tick_nohz_stop_tick(ts, cpu); @@ -1075,7 +1075,7 @@ static void __tick_nohz_full_update_tick(struct tick_sched *ts, int cpu = smp_processor_id(); if (can_stop_full_tick(cpu, ts)) - tick_nohz_stop_sched_tick(ts, cpu); + tick_nohz_full_stop_tick(ts, cpu); else if (ts->tick_stopped) tick_nohz_restart_sched_tick(ts, now); #endif From patchwork Sun Feb 25 22:54:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206147 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1778796dyb; Sun, 25 Feb 2024 15:21:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXSxl2jkmD0vjT8GprxnPDG7TEf6tKKAejD/Nib1J5DyXFDKZLe7MitJKh4prCXjKXgrKBOPPqjyuQfwkliaz9T9Cc+Bg== X-Google-Smtp-Source: AGHT+IHLq9cbTboF9QrOyTIGm6lzIG2U/hPVwaYNTNE31wj2iyXobGG1rJd6Hpq9955eFYxAGPj1 X-Received: by 2002:a05:6402:b14:b0:565:2b6:6a7 with SMTP id bm20-20020a0564020b1400b0056502b606a7mr3916033edb.34.1708903292782; Sun, 25 Feb 2024 15:21:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708903292; cv=pass; d=google.com; s=arc-20160816; b=V6kARBB7q4qI9HEuM6AHzNN8QV7v6yDcJwml2gbPD757se07dsH1jvshep8dAk3ISr krXcmYG2YzrDQjc//MvWHxoUGeQk04Gz6TGEHCh8x25i1laqGzFXQYdo4lSqwQeRx7kN /d2vyf6tey/gUPddrwSv5YgHhsvLXlCTeNr28i3nlAeT3ocF1CIM6OD0bBx+rwqX/FI6 sBq1rTRy03C9IwAz6flZCfbK5ep45l4QgH+pWN99gqoxGMji3rwpmVDr/IPAWrt/dAxH lQzAVt1tAFiQhhorXF8w/wAduGpAZQ+n3BgtEVdX17lDha/ty58J4/pVJcBRAG0/PkyZ aMWg== 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=JqHHLOQqUv5xfwT+lJsi/MnTliEWNbGbU+FDZ5U1DJ4=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=OIOz0Im2zofINHm9Vjn/tdWZPbKINrpWFZZLvevk/pRBjihhj3Stv52D7REA/3VI1T uTCSPfcsWxjXYXvpPY+vGKsI+6uLjX8MVfLCuPWVsfDKTJHVd0lxELeA82QqdqqQl3eA piORSbf7+XWZQNRz7QIN4IU+qHAb3hUwiKFZbR7VQahz5GQwFZzE+RDNEuX/jbNXwpJ5 xRq7wlJ+5k3wcQ+Omi2vT8hJWudhlnEf6f/wYmP4CMDKdbqpJY3mmp1FP/kg+NjT0gOw I0SkxIhZI9PTtuHyIQfHzodjHD0FhmkqHHTPtWipXI/a6tfKW/VEcRQaatoD5ppCKtcA iytw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oDxXy8zs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80333-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80333-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e13-20020a056402148d00b0056420f51921si1491978edv.264.2024.02.25.15.21.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 15:21:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80333-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oDxXy8zs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80333-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80333-ouuuleilei=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 B98391F22C89 for ; Sun, 25 Feb 2024 22:56:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FA83208B6; Sun, 25 Feb 2024 22:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oDxXy8zs" 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 E7ADC1F608 for ; Sun, 25 Feb 2024 22:55:26 +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=1708901727; cv=none; b=VyfMoNwM05CLJRd/qE4Z1nTUM3RIaTtENO8I/Q3izXRthztrzbLkwvynad7iTV99RNmQJtACxHgdOzsU9ZB9YviuNAH5L7rAhSyBbfgp6WLY94oIsMI5bDq3M3ihum1SeCazJT+4aL6gzFS26qRuO87wy5s5phRIY1sBXBmXiWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901727; c=relaxed/simple; bh=elCK0+UoX/y8indul9dlqt/x3/BB/vOLFTEHdirzUYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=owVZCcIXh4uUoX/AVS9qizvkH0wesUzxPc0VtChgKFLUUK+9nhFcU2ivmT4iZv0bsv/Ab+MPuw5e/rg5zP9eHtb2HP+H6Lmc1zIxRS5m1xQshl47WIsRvC1mq/gYv4QpHYfIT8K38nbDS5AmQu3WsDuRKgmNl3sg023e+oHRb5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oDxXy8zs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35B06C433C7; Sun, 25 Feb 2024 22:55:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901726; bh=elCK0+UoX/y8indul9dlqt/x3/BB/vOLFTEHdirzUYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oDxXy8zs+PD/0lFXaeh+O7GkIW/2o2BmLXGid5juParGagr6D/1nuC1RpV/4D/KRV Jv7qk9e13MvoUXQUvt4gnxtdZx0xh2/gt59C+ZxP71ylsVMpSTThjcIT/jTic64+jO S21gfq2BPBG1Yj3HWuHVKqM8rGgZZ32yssOa9BfVRDrQrytFI9oXNIfsno5DHxceUD sVv6Sp9TWvIctBEeZMuaZXpDn4INZE0tDFVuK023M43zPseubxNB6w3uwWk4LjmUaT HxNa9xd+WRRmJDx263Ie4UN4ajiGbplFKA3GTzyqsLlXmzKpK5JA+QQ1Okb2aBJOtO JXEMQmz38YtFg== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 06/16] tick: No need to clear ts->next_tick again Date: Sun, 25 Feb 2024 23:54:58 +0100 Message-ID: <20240225225508.11587-7-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791914978934713805 X-GMAIL-MSGID: 1791914978934713805 The tick sched structure is already cleared from tick_cancel_sched_timer(), so there is no need to clear that field again. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 9f75f5621965..b17895de26b9 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1143,11 +1143,6 @@ static bool can_stop_idle_tick(int cpu, struct tick_sched *ts) if (unlikely(!cpu_online(cpu))) { if (cpu == tick_do_timer_cpu) tick_do_timer_cpu = TICK_DO_TIMER_NONE; - /* - * Make sure the CPU doesn't get fooled by obsolete tick - * deadline if it comes back online later. - */ - ts->next_tick = 0; return false; } From patchwork Sun Feb 25 22:54:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770457dyb; Sun, 25 Feb 2024 14:57:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXGl45mOtZ1wcLFszMqgs2gq7TvabjxmSwwCres2LdrmhhOJr4JsQ/tJO8gECPg5pA9W7Rd51F0yKkmWzVXQAJKjSUEVw== X-Google-Smtp-Source: AGHT+IGyeMIAlzYcJ5UEz+krmv9uQD6xEXg2jZvMW+8NV1uNjNXTb/Fccy4txiKb0fs4zFXOVaT0 X-Received: by 2002:a05:6214:29e3:b0:68f:c56a:c823 with SMTP id jv3-20020a05621429e300b0068fc56ac823mr8089920qvb.47.1708901820537; Sun, 25 Feb 2024 14:57:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901820; cv=pass; d=google.com; s=arc-20160816; b=kEKp4QRcpN2Hs8nQCDSsNWH0qIf+s9ZJMB/5TO+rcypkI4FDzi/L/GQ876xx0ihSCB w2FXa8Kyl8vAxgidSS+3943VvtUAzphRLNVu5JcfU167fF963s1qFrWMBxWrxAD34khk iYBxcMaEgGSv4M0I9twTKKLbM9/BJ5vSCpCC+oKf2vlwmL68qNIkRDpKGMPSCzVPXlDB oIC60owAJTXXIqgmM5b7YhxO7GNDYZRVheqiI97QAmCpdK/q/gzHiDbx4eTPLs20sZK/ HydSqwJA/PA7dkd0xsc3suCQjIRojZSSfusi4JppaBTfM1SkSIxNhdVyQAV2huQS6NiS sA6A== 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=2xQ0fNH0kAKVvyTSOAOxW0s2WNeYJ8wtWIaQJhecEZo=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=CUpfKz6QDPFv52meRAIuV4zxmN+wbCX953SWWQcBbAThJTqvIt1uQ1gItvClvSkI7m +DJfjfFthzDjdixgE2KSC4KkjwdOAuvETBJLVUUJcPiMha9rZE25D9H6NcuBDcSJY3TG oQqRHa/kxocWask7QeXsTIzRxFdfviD70waP9OnsSKHsiHhX02N+FQjZXTCnkln5r/A3 hWJabyQ+p5Ue+jRlPjnkg3lzkSmMdIn6uTPD64m9NCwguliF/FaMgjKmF1M+BwUYHwMV tvrRRh6B1KNpuDTqFp/Rwm1UrDAgw2qsA4nyt9OuJpqoIOumV35VipwUbm+RDQcAxtTR 8d6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oK1XDXQt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80334-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80334-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q3-20020ad45ca3000000b0068fef8d0341si3550127qvh.20.2024.02.25.14.57.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:57:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80334-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oK1XDXQt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80334-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80334-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 47A7B1C203B2 for ; Sun, 25 Feb 2024 22:57:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C016241E2; Sun, 25 Feb 2024 22:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oK1XDXQt" 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 84E24208B0 for ; Sun, 25 Feb 2024 22:55:29 +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=1708901729; cv=none; b=KAuA0W8wYM/OHEekqlxuewbHcXJ3iz2ejfI03Qy34DT3eHteSc0/O/L/FdNeesh00Fzsj9geryENoAdop5/iTispTwpyZyJjdzqYHEn2ew5IF05cJpBI5hjiMk3DpDDQHh8+lIRkUzYx9jfmsXiVDprwYWQaG5AuMpoPYAFprgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901729; c=relaxed/simple; bh=rhrRAJBoPCE4HwgmAN52WPXfTKv2Ml+3lJBb9gSFYtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NBKKBP36fdw1n1irQ5A2wDKKV7bUG9zgnpaOiwwPklxgzGng3ebWkhBOuTwyLiI46bRiVV6kbn2ykq6petnmIcADjNAehBRaUKWsmlGd0oRFKpYipNq3eNePxJq0hDmcMXNEZEcMfsb2B+wLa0QM358vgni3+TBrqNfV/rB/0G4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oK1XDXQt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62CE2C433F1; Sun, 25 Feb 2024 22:55:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901729; bh=rhrRAJBoPCE4HwgmAN52WPXfTKv2Ml+3lJBb9gSFYtI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oK1XDXQtIvK+SNEy+hobHIp59LVxXqGNE6bPN5lZOY1n02+8DHq2SHlbfELwqswBL 9UsQemTbGQpo1Xt4XYGzsz0JIfmgpqwFAQP34OKKCzeWO2/5BzwiU0lkJMU1hpLUaX zlQL3tedoqCIR19GOmkhvbdTct/rUR+RyFYk8pkrPp8aUQFuZMyJqMZ8yKwfyGTzmr nmaWkMvXNq/L0VR/jDgaceEUnVOsEwlEWEL1lHTZAAWar3OdL1jC8PReXm4JO5LppD HzVj0QAORyxCnrHIrRd4j1OqmoD8qxFwygrWDQtaJZaMFqxfnI1pqKC6NsG/z2Wucn CruSoshxNb9Aw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 07/16] tick: Start centralizing tick related CPU hotplug operations Date: Sun, 25 Feb 2024 23:54:59 +0100 Message-ID: <20240225225508.11587-8-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913435414659149 X-GMAIL-MSGID: 1791913435414659149 During the CPU offlining process, the various timer tick features are shut down from scattered places, sometimes from teardown callbacks on stop machine, sometimes through explicit calls, sometimes from the control CPU after the CPU died. The reason why these shutdown operations are spread around is not always clear and it makes the tick lifecycle hard to follow. The tick should be shut down in order from highest to lowest level: On stop machine from the dying CPU (high-level): 1) Hand-over the timekeeping duty (tick_handover_do_timer()) 2) Cancel the tick implementation called by the clockevent callback (tick_cancel_sched_timer()) 3) Shutdown broadcasting (tick_offline_cpu() / tick_broadcast_offline()) On stop machine from the dying CPU (low-level): 4) Shutdown clockevents drivers (CPUHP_AP_*_TIMER_STARTING states) From the control CPU after the CPU died (low-level): 5) Shutdown/unregister/cleanup clockevents for the dead CPU (tick_cleanup_dead_cpu()) Instead the current order is 2, 4 (both from CPU hotplug states), then 1 and 3 through direct calls. This layout and order don't make much sense. The operations 1, 2, 3 should be gathered together and in order. Sort this situation with creating a new TICK shut-down CPU hotplug state and start with introducing the timekeeping duty hand-over there. The state must precede hrtimers migration because the tick hrtimer will be stopped from it in a further patch. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- include/linux/cpuhotplug.h | 1 + include/linux/tick.h | 8 ++++++-- kernel/cpu.c | 8 +++++--- kernel/time/tick-common.c | 17 +++++++++++------ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 7651904c6db5..35e78ddb2b37 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -184,6 +184,7 @@ enum cpuhp_state { CPUHP_AP_ARM64_ISNDEP_STARTING, CPUHP_AP_SMPCFD_DYING, CPUHP_AP_HRTIMERS_DYING, + CPUHP_AP_TICK_DYING, CPUHP_AP_X86_TBOOT_DYING, CPUHP_AP_ARM_CACHE_B15_RAC_DYING, CPUHP_AP_ONLINE, diff --git a/include/linux/tick.h b/include/linux/tick.h index 716d17f31c45..afff4c207bd8 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -19,16 +19,20 @@ extern void __init tick_init(void); extern void tick_suspend_local(void); /* Should be core only, but XEN resume magic and ARM BL switcher require it */ extern void tick_resume_local(void); -extern void tick_handover_do_timer(void); extern void tick_cleanup_dead_cpu(int cpu); #else /* CONFIG_GENERIC_CLOCKEVENTS */ static inline void tick_init(void) { } static inline void tick_suspend_local(void) { } static inline void tick_resume_local(void) { } -static inline void tick_handover_do_timer(void) { } static inline void tick_cleanup_dead_cpu(int cpu) { } #endif /* !CONFIG_GENERIC_CLOCKEVENTS */ +#if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_HOTPLUG_CPU) +extern int tick_cpu_dying(unsigned int cpu); +#else +#define tick_cpu_dying NULL +#endif + #if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_SUSPEND) extern void tick_freeze(void); extern void tick_unfreeze(void); diff --git a/kernel/cpu.c b/kernel/cpu.c index e6ec3ba4950b..263508073da8 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1324,8 +1324,6 @@ static int take_cpu_down(void *_param) */ cpuhp_invoke_callback_range_nofail(false, cpu, st, target); - /* Give up timekeeping duties */ - tick_handover_do_timer(); /* Remove CPU from timer broadcasting */ tick_offline_cpu(cpu); /* Park the stopper thread */ @@ -2205,7 +2203,11 @@ static struct cpuhp_step cpuhp_hp_states[] = { .startup.single = NULL, .teardown.single = hrtimers_cpu_dying, }, - + [CPUHP_AP_TICK_DYING] = { + .name = "tick:dying", + .startup.single = NULL, + .teardown.single = tick_cpu_dying, + }, /* Entry state on starting. Interrupts enabled from here on. Transient * state for synchronsization */ [CPUHP_AP_ONLINE] = { diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 0084e1ae2583..a89ef450fda7 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -397,15 +397,20 @@ EXPORT_SYMBOL_GPL(tick_broadcast_oneshot_control); #ifdef CONFIG_HOTPLUG_CPU /* - * Transfer the do_timer job away from a dying cpu. - * - * Called with interrupts disabled. No locking required. If - * tick_do_timer_cpu is owned by this cpu, nothing can change it. + * Stop the tick and transfer the timekeeping job away from a dying cpu. */ -void tick_handover_do_timer(void) +int tick_cpu_dying(unsigned int dying_cpu) { - if (tick_do_timer_cpu == smp_processor_id()) + /* + * If the current CPU is the timekeeper, it's the only one that + * can safely hand over its duty. Also all online CPUs are in + * stop machine, guaranteed not to be idle, therefore it's safe + * to pick any online successor. + */ + if (tick_do_timer_cpu == dying_cpu) tick_do_timer_cpu = cpumask_first(cpu_online_mask); + + return 0; } /* From patchwork Sun Feb 25 22:55:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770539dyb; Sun, 25 Feb 2024 14:57:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUjpIljNZG4GR+eomFaU4vnF07yGbGkWBkeQiDiyeiXMAYy0dd33FZut1jzpwdJx8glaGayPVONLJzYMQxDiCMqQU0oZw== X-Google-Smtp-Source: AGHT+IEUE1r3fr3bKbvUpgr65qnFyVD5JVmMCZdvg3qhUpOjYF5caaFWYujhuDXo7HjqPsLvlwOe X-Received: by 2002:a05:6830:1557:b0:6e4:640d:797f with SMTP id l23-20020a056830155700b006e4640d797fmr5503984otp.35.1708901840228; Sun, 25 Feb 2024 14:57:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901840; cv=pass; d=google.com; s=arc-20160816; b=HAu6QE4PvIQOLy1pTTLX8jeuAc/JpUpGGeCbKCTIn9Oo0wshXWN0jjOhb7a7tSNgpx jqXKksmCTChW9yWMQNWVQpu9jfLwtwucjrPiceMkfuQBjrBJPralk9klY7g7H6+UbRDq VT/I+20e6MadMstyzebyMcgr8pKheluWgN9EXOyrZSel9tLu6TVwXr2GyjYYI+YBsWH/ V2i5SV8vFqgkj4uop77yGla2+iNLwgPlJAYLfZ9BVBxPtPCvrdvSSeze1zXxVSQ9+qMT d/mh02KqN4sIa2C412ZH+p95NCDB2RHUqJEgkZTEwOLJL4H5mIkjCMuZS7oK3fUZp1Fj StUA== 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=iQwhWWYAFaSrwDSx2oDuA41/x09GHcZ9wjNxXH7L1IU=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=a1HLkoIKDYzIjoILBhz6ww3jIcGXMmEp6likyNTgMP40sEfTXVyaP57FUipF1SvKaq WK4RqAv8dIRsawDFBPWA3HnYcGGlsfsbC9BwFlEnd9M02luQQ7HxD1aABLweKXBzMTbI lCBkzvOza00LZQKAB299tAoJgVxydUaOIqV/jXA3jct/c88lwqlWNHIM7qe+c4F9nUBK DZdl+WPp6rlOqrUbVQnhXXxz5pc1arLXW6JcMVpuip+ht0pQ7OJS0MJdNYFaPdKT5Uqf jsIW3iT91VOAiHo9xAlEWTGzOZOgK0C9ib8Jxtw1vOLqhhS9Bt9p1uhCD4ZztYrtRdhj SkkA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="lFu+0/g8"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80335-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80335-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h22-20020a633856000000b005dc0b3095b3si2665998pgn.283.2024.02.25.14.57.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:57:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80335-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=@kernel.org header.s=k20201202 header.b="lFu+0/g8"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80335-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80335-ouuuleilei=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 EBEBAB20F29 for ; Sun, 25 Feb 2024 22:57:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0438F2576D; Sun, 25 Feb 2024 22:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lFu+0/g8" 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 5B4C522337 for ; Sun, 25 Feb 2024 22:55:31 +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=1708901731; cv=none; b=LCXtasIleyZCiPd/jEdE2iiV2RJKn335wI74zRWvgTKmuGZGxfbq7jZd442QRMuQuQdRDHiONtWC1ekt6myDMAqO2rgb1+eeGRNi+ux9w1hDuHTPAFjZ7DlupNxCQn1Ejy5MV3iQsbRd103jvD149A6XUKByvjSTreItIT8dMUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901731; c=relaxed/simple; bh=1t2Igcp3/2acM8Dgm/Zgl3S5NWNsliShc0fKBxG7fGM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hnA4CvcvmkTCskZGgoVvtFPFiblu2LgyeArXieIQHG2KeTj8ka4/1WvqzXJrnHSaSFwgtHjciEAHwk4nO63TrNyYSfjeRUElEG5q6WhE4LdX2OXEPT8/RT/UX6NPPNKxKHXccE0aN4n87mkaLOxEYYiF/hf7rYGq9VUs13ZoiwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lFu+0/g8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 835A4C43399; Sun, 25 Feb 2024 22:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901731; bh=1t2Igcp3/2acM8Dgm/Zgl3S5NWNsliShc0fKBxG7fGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lFu+0/g8aFgFX5z8neujR4W+AFrCcIfkYFBKFcQh607ouLhXix5pCMNLTGSFAm8L/ 2/CvF98St2mtPrEEJebheFT8xJl8ibt7MWlx40OCaOf8x3vh6Fgmb5ahis6kVsJiZ5 LeyeSdQVWUUNX9+bFfUezZGK7k8xB+9xXQQ2x+9w+rqq3THSTxKte9BzlJPxiZ8kgo C2Jw6ZSEugfUO8Q3+4TxSlgDy6cARbz8K8rFfjBt/2PBfajZzsUf2Hg3aX9dBZFLpw pQvdKOEpjKS/o/jgnDE4PxmvBXXj7d5tYBs3Wa6dVz2tgyLr8uoJNXDF+vYLOr81wF 4YyOxFiuFAdAw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 08/16] tick: Move tick cancellation up to CPUHP_AP_TICK_DYING Date: Sun, 25 Feb 2024 23:55:00 +0100 Message-ID: <20240225225508.11587-9-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913455674164919 X-GMAIL-MSGID: 1791913455674164919 The tick hrtimer is cancelled right before hrtimers are migrated. This is done from the hrtimer subsystem even though it shouldn't know about its actual users. Move instead the tick hrtimer cancellation to the relevant CPU hotplug state that aims at centralizing high level tick shutdown operations so that the related flow is easy to follow. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/hrtimer.c | 2 -- kernel/time/tick-common.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 95f1f351dcd9..3e95474199ac 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -2229,8 +2229,6 @@ int hrtimers_cpu_dying(unsigned int dying_cpu) int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping_cpumask(HK_TYPE_TIMER)); struct hrtimer_cpu_base *old_base, *new_base; - tick_cancel_sched_timer(dying_cpu); - old_base = this_cpu_ptr(&hrtimer_bases); new_base = &per_cpu(hrtimer_bases, ncpu); diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index a89ef450fda7..b4af8c743b73 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -410,6 +410,8 @@ int tick_cpu_dying(unsigned int dying_cpu) if (tick_do_timer_cpu == dying_cpu) tick_do_timer_cpu = cpumask_first(cpu_online_mask); + tick_cancel_sched_timer(dying_cpu); + return 0; } From patchwork Sun Feb 25 22:55:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770584dyb; Sun, 25 Feb 2024 14:57:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWJjPfHqeiLQo5+J2bQt2UWxVlkNwbmpl8pxbUFoDLmP1WaygZma+mmnOZ2PAfLI0cJSm5g/IrXh5lB/89ZD+Lt0szkVw== X-Google-Smtp-Source: AGHT+IH2bVOK4+yYlRH5WRt02Yv/xIoCte48vHxc/E/6PCCp1XREa/+NqUk8w4stUQsFp/SF+6aA X-Received: by 2002:a17:902:ca0d:b0:1dc:11f:d941 with SMTP id w13-20020a170902ca0d00b001dc011fd941mr4802314pld.26.1708901853972; Sun, 25 Feb 2024 14:57:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901853; cv=pass; d=google.com; s=arc-20160816; b=yc8TritZxOE/BZ1jvAl1r8eZ3aFaNJ4aOlMUYpuiLoywowGFhu6uCCdPqhN2tt8lXf EgXm7u/ztIADfyNzvbY5jxDpHbaTir3bPO4n9VkaiF/dOnOUuuDqXibasUtdCqBZ7dUl 24GTaqp1XrsXIBuiDq+fq75ABQBPUfxgc6C+eAu660fXhglaoIr2Aq85gLtLcohxJdYy tmlzjuUGelB03PvHkSfDNsbkN2V1iJDrnJ2CqCqYnpSvNtlyxoKUapiuRLkS/5Mpuclz BF2EjF0KZKFu3EBVVJtHpO5EruDLv0jqCCenfkZpZwCRXLl4Eg8G3eh2IXjLvD22eTwB wtig== 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=GPfbRWLuTmFZ67iA/iDHMD64V4SaiQWw1cwLFRmCh+k=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=n2pfxPQewSFWfYp/3pxL6/Wx7RQ/v9UAQ1ukT39qR0BGJgzyH9NfViRqDCaCp0pshj 9xQ7SrtFAz3xpcGKYYemDif7vwubQMkaYBgbsInIUcZkZFMqIIIOL+yc8sktxJRoV1Tf tNHlXFo8RanuWDUMcHOyuxGOLP2zIloOEEQ3KQN5yFoXyaKhFQzSE4tFKpbicGocDQF/ 6GQArCQLaNK+67o9PZxrJp+t9JkhtYBR9jiQ404o3W3SX0hXjg1vlto4qi+20qIGJzhK clOKPQWh6nRUYENwo+zB48Hz0J9RdkmuAl1mOPK6d7J6Mbx6G6XqsAlMQ7PJZ5M3MCCA EmSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=e7oYwvG4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80336-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80336-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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.57.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:57:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80336-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=@kernel.org header.s=k20201202 header.b=e7oYwvG4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80336-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80336-ouuuleilei=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 875FEB21053 for ; Sun, 25 Feb 2024 22:57:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 966083D3B9; Sun, 25 Feb 2024 22:55:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e7oYwvG4" 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 E5B672576B for ; Sun, 25 Feb 2024 22:55:33 +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=1708901734; cv=none; b=Iet1CLtRTQEGgtBXcbpUaVEsyXfBh79xDQoBluFqHdHh9HzmGA+gJ+4+TCYP+xvYpYbyH5Oax1u2+3h7oPnhF9PXw5/kFQ0UO85dHyb3e/DLzQGoknBp0YqORngSsB9m0y+YDxQyt03XIhg9AEqlF8iEHdKBbQli+gf2rmuJT+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901734; c=relaxed/simple; bh=a2TLuKZ1NcjYXwjYQRiKiZcFGSpIbLE6pKtHI2QYajQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sZicznxWB6rmEWq29uTFg8zs2RHH7I+aLC4zL78Cd5Aadf6Qs74shE68K84WZQxziKA42MDLexGEDk3DREDJZj+j7d55YynKvRDkyIB17bRd8E6mgD6qDxzhKABEyCIeTtVAAMFbnF9QV3P2Brfy1YCMMqE9T54UBWSz9ZPPOq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e7oYwvG4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5F1DC43330; Sun, 25 Feb 2024 22:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901733; bh=a2TLuKZ1NcjYXwjYQRiKiZcFGSpIbLE6pKtHI2QYajQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e7oYwvG4n1Y7nG60vnmZjcVkm5N0H1Z4Xn/LhEoBOrMY7z4uX9D9hOMYtj6hC2Bjo 7Ftd8HoYbh8PsFjzgUweXRX/AkY4PENBhAzsxOK5aIOPIqbCBScse3s2aDIE6xD9Mq oUYEgUFr/Tal9YFs1UjrC2mqn5nEJMJFAMVKNFi20Hq5oZVcvJEx4RsdTv+D1ZvnAy lEX7mTUIYOGepiZrqrWGe1jsljnXvlle5FVGyacpkbtLsM4Eio9/N/UvzXiNCiZbNE itZdcMLiGD9k2WKnfDOCasexBUJ2CP4yYhZAR1m1OrRGDB4mN5nIIdFlUR9cPg0JcB jCI+dyxCZeTnw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 09/16] tick: Move broadcast cancellation up to CPUHP_AP_TICK_DYING Date: Sun, 25 Feb 2024 23:55:01 +0100 Message-ID: <20240225225508.11587-10-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913470617872397 X-GMAIL-MSGID: 1791913470617872397 The broadcast shutdown code is executed through a random explicit call within stop machine from the outgoing CPU. However the tick broadcast is a midware between the tick callback and the clocksource, therefore it makes more sense to shut it down after the tick callback and before the clocksource drivers. Move it instead to the common tick shutdown CPU hotplug state where related operations can be ordered from highest to lowest level. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- include/linux/tick.h | 6 ------ kernel/cpu.c | 2 -- kernel/time/tick-common.c | 3 +++ kernel/time/tick-internal.h | 2 ++ 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/linux/tick.h b/include/linux/tick.h index afff4c207bd8..c7840ae8ebaf 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -73,12 +73,6 @@ extern void tick_broadcast_control(enum tick_broadcast_mode mode); static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { } #endif /* BROADCAST */ -#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_HOTPLUG_CPU) -extern void tick_offline_cpu(unsigned int cpu); -#else -static inline void tick_offline_cpu(unsigned int cpu) { } -#endif - #ifdef CONFIG_GENERIC_CLOCKEVENTS extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state); #else diff --git a/kernel/cpu.c b/kernel/cpu.c index 263508073da8..5a8ad4f5ccf3 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1324,8 +1324,6 @@ static int take_cpu_down(void *_param) */ cpuhp_invoke_callback_range_nofail(false, cpu, st, target); - /* Remove CPU from timer broadcasting */ - tick_offline_cpu(cpu); /* Park the stopper thread */ stop_machine_park(cpu); return 0; diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index b4af8c743b73..522414089c0d 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -412,6 +412,9 @@ int tick_cpu_dying(unsigned int dying_cpu) tick_cancel_sched_timer(dying_cpu); + /* Remove CPU from timer broadcasting */ + tick_offline_cpu(dying_cpu); + return 0; } diff --git a/kernel/time/tick-internal.h b/kernel/time/tick-internal.h index a3243c4ac45f..5f2105e637bd 100644 --- a/kernel/time/tick-internal.h +++ b/kernel/time/tick-internal.h @@ -142,8 +142,10 @@ static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_ #endif /* !(BROADCAST && ONESHOT) */ #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_HOTPLUG_CPU) +extern void tick_offline_cpu(unsigned int cpu); extern void tick_broadcast_offline(unsigned int cpu); #else +static inline void tick_offline_cpu(unsigned int cpu) { } static inline void tick_broadcast_offline(unsigned int cpu) { } #endif From patchwork Sun Feb 25 22:55:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770597dyb; Sun, 25 Feb 2024 14:57:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUvImdYQE23ng8LilTEmjadOq0sVOFWeoe+KwRpWi9woFq+gGYPWVGqEYmva+ljb9eg6xGC2l5G9MfId+lb9UDpENiUTg== X-Google-Smtp-Source: AGHT+IFjQTxx9mPhqv+hoPRXgs6+SFyBJ3gbHVuckZ230e+gFP4LmDVWqMYwnckwrB+rJ0fvHVV+ X-Received: by 2002:a17:903:41c4:b0:1dc:6b99:a547 with SMTP id u4-20020a17090341c400b001dc6b99a547mr6979197ple.47.1708901856304; Sun, 25 Feb 2024 14:57:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901856; cv=pass; d=google.com; s=arc-20160816; b=WhoR4eJP2JGumXuRD+I012sPz8Cjor4fDzaAKWeUfec+PdUuvhubYDJFEIxNRVdQJV ekGwUUoUcRiccjeP1v4lZd8yN5UWGhnhp9B4BTv9WjZ7yXkOz0XvbfL4Y6Zx5E8lFVmB nHNK1UAyU3HI14vmEmZHEGFpIdIDWru14aD7mGZGwfK9ilwhz8eAGLqFyIt7FJHHMELD AEYAl5i5QdmwyFq9vSyy1xk2gQLJXVVY1PtlvGojRPsyw8J3iQpPHapZh81dfbh+uH4n tpGFkFLc3xK7ebr8g/R94XqCnzLt4w04qEeHANA6HOj9J/kHhMdBljSTkiDzBHDJEJOy sZaQ== 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=sKI71+HnDvWAqSjKAPIgifJ6hRULcxs2a0NSNaclWUg=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=QV14KCTBKIIgABSfKDtI6XBkO6bkpIc5uOhNYIaNM0Ubyfwob7+gThOLYqe2yJi5aV V4RCcczTXIlPlMmqWwb9dqSU+nL9BA5330pQmSOlIlih6FMa5b38F7v23tSoRS+SU7NH qx5/GTuoBCIjtKbaM0hNTcdOisKkW6e8XW8uomZs+9mgRprx+r76eA37g4dTWfZ8U55u 9s5Pk6bxyg3jeQ2B7KqVdXq93TukxUhx23+JyTWOTXJ1l7j4U2XgljKG423FebvYnNQV mxOc9v9WAtlhuRGbcquCkcptxWyO8F/i/iGn9Ql6Mr3/8JRWCcLrcUBsU0lP9EnFS+ah FfxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LCeDELy1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80337-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80337-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2-20020a170902cec200b001dca6272e21si315024plg.36.2024.02.25.14.57.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:57:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80337-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LCeDELy1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80337-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80337-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 23B0F2820BA for ; Sun, 25 Feb 2024 22:57:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D4F8A47F58; Sun, 25 Feb 2024 22:55:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LCeDELy1" 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 1862D39FFA for ; Sun, 25 Feb 2024 22:55:35 +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=1708901736; cv=none; b=CIbQPkNTGSN6TWbMzkQ97KaibnvOFWYPsTfV6fYa4W8RLz8otuP5cHqPIC252jRMfebBPYVj/pLt4UVqJNDC1nnvB7ZIpYDz57W3AZ6qi6ccbDUoSS+ZqVlPSWF0u7X1duj9tn7hZElXL9Mrgp0q84geVpQVExamU0HfyOvlh2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901736; c=relaxed/simple; bh=PZKcGOqePrNpkgM5JGTpq6/R9MYj7zTGFX6r8zvTk9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQ7a8yDIXtyXTE7FByWJUNYQiLL/wSHUlaX/zu4oEJROE1neCo2cNpvm/y9ODxIocBd80ORXG+Ub0fgx88uiC9WBkzSYmeSG6WwKVHYCjCTcTj/Dybx1z8xd+KYe2fjsHl7nzrgVy2S/mcRCg8kuXGvDWcgvI76WMT0yahkadew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LCeDELy1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6E7AC43399; Sun, 25 Feb 2024 22:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901735; bh=PZKcGOqePrNpkgM5JGTpq6/R9MYj7zTGFX6r8zvTk9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LCeDELy1YQOown/uvX4TDYiQfujwPApQ0Wh3b2vs/w9bDEbnAwmF8CV0su5cRWPNW xHpVULLwGP5eS72gUd7meM32Szn6p7y0YLXYrSihMmTkSRQ2pY7u8BOy+Nwp2LQQAK JKzc1ZEfKhlWh0s58SjncruAT2eWHpJSwxPKRbyY8PI+yvfn4zY0lWu78QXMeeYKPL pRJS43rBVzBNkR0CJ2sKY3Eec/OrRqjz0GlP2AA9viAVqRaPGDEiQu5HOn8R21p38y HXUoiHarxDYXzOFqXRssm2dy+L33O+4Q6PQbO6PfGhkuCtU9MlFNCRpLqUJUcEBjYi DIXih21NlPdTQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 10/16] tick: Assume the tick can't be stopped in NOHZ_MODE_INACTIVE mode Date: Sun, 25 Feb 2024 23:55:02 +0100 Message-ID: <20240225225508.11587-11-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913473037167437 X-GMAIL-MSGID: 1791913473037167437 The full-nohz update function checks if the nohz mode is active before proceeding. It considers one exception though: if the tick is already stopped even though the nohz mode is inactive, it still moves on in order to update/restart the tick if needed. However in order for the tick to be stopped, the nohz_mode has to be either NOHZ_MODE_LOWRES or NOHZ_MODE_HIGHRES. Therefore it doesn't make sense to test if the tick is stopped before verifying NOHZ_MODE_INACTIVE mode. Remove the needless related condition. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index b17895de26b9..b79f5403433b 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1086,7 +1086,7 @@ static void tick_nohz_full_update_tick(struct tick_sched *ts) if (!tick_nohz_full_cpu(smp_processor_id())) return; - if (!ts->tick_stopped && ts->nohz_mode == NOHZ_MODE_INACTIVE) + if (ts->nohz_mode == NOHZ_MODE_INACTIVE) return; __tick_nohz_full_update_tick(ts, ktime_get()); From patchwork Sun Feb 25 22:55:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206138 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770633dyb; Sun, 25 Feb 2024 14:57:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXohFYTr07N0qC9cVrdjbwwJfwcPwRx4ERIlfv4rAlVcYtbVPxwq7KiSFABCA2dbRe/C+GIrEQYST7shUJ74TK6m/bxnw== X-Google-Smtp-Source: AGHT+IFX1gAvp997kwzRuJf0ZYNemzzqiyoWPL5ltzMW6Eg2EIZPOaD6Jol+HdShf70CN9c3Z6qg X-Received: by 2002:a05:6214:e8e:b0:68f:4a88:fa14 with SMTP id hf14-20020a0562140e8e00b0068f4a88fa14mr8045147qvb.32.1708901866600; Sun, 25 Feb 2024 14:57:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901866; cv=pass; d=google.com; s=arc-20160816; b=tfVEU0UqpQ3/ppBqrRcd/sQZzSG3Fv3AiNqVnwQj7nSVtCo4aObwvcBYedD7GQGg8B iqqHdiWKW81o7iSluifuccD2gblkLjEfqvwIAKADJSaJMG2VbrXQZNggXPq3RQtSkIFv 8C0DhBufn0VMlIe4YNN90Wcc+jti+fxbe08Ac4pz5NOGzvTNbwD+W/7lYOw+InhFj6V+ uf5k3G8urGn/ncE6WB/1/blSl+C0FvADCoIP/K7VNCIg5nCGDfraZsG4P+HKbq4iCmli 8q6aBrINFPxkf6F/FGLVaaYInTzR2So9yfYDdClKQFFVOzE8oYp9mMkCpA8X6a9/aTm0 gnJQ== 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=32PBNjbxtnXDVrDZlxu6pNH0KE8j3mQZCqSzuvfBD2Q=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=euLY9q4VW995qzgJ5KlQ0FqKDycice2IgaWb5dB/pPxJMD+2+sBcUTvFtHGrrCFPHS ukjrZ+QdUAL6od+86L1sbZLbBMXFP0kZ/fBX6waRYsCFW0xrdPgW2FqzrpPsqz+nLiq1 ylZYK8v15X+2E8SjK6fSaPT95cSI37qpvDywkSyRShVZR5Zm+VhyD2ntLV1emUNPOj33 yzcURMg5mepT9kiUrzP7MXXnM5x9lG7YXjzFxshIYFeplQo41DtoMDccWUpefrdxqpeX 8MOMi7+bhaIh1Ux1zZDTonGY+lr/KS4kEEukywTXL7QmbBdh+JkNobyy63tIbudMS7gG ysBg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FjV4lzBy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80338-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80338-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kd1-20020a056214400100b0068f13165047si3906376qvb.0.2024.02.25.14.57.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:57:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80338-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FjV4lzBy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80338-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80338-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 654361C210D3 for ; Sun, 25 Feb 2024 22:57:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B335E1BDCF; Sun, 25 Feb 2024 22:55:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FjV4lzBy" 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 006C03F9D4 for ; Sun, 25 Feb 2024 22:55:37 +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=1708901738; cv=none; b=TCgh7xR+igrK7ibkNdiUR3ttmYxImWq3W6dAJkUC0alqxh7cXFmP6pfRGiN6v2vRHLfVVJdWgi+juu89cbg4JizNf4nnoeMh0ichRtUtfzgiCVnDS4aJYvtvl7c6IlzYS3wtUbOJQeBbUqOiCiIlKiUeXiNg9xJkUIVGgbtust0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901738; c=relaxed/simple; bh=ENJnGfyd2+EEzXokoqGcyz6LV1lezsDunVEKa8lSN3M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PKn/cXKTG+g6+NH4PSdn0Kd7JI2xwWOe3DW/DXYBLiZ9izuzgdCwLX3wUURyrbz5B4bMFSHdjqkwnRJ3rGL+GREKHkyR44E7pJHX8Kya9qQ8iV/hnKnbN22osdfCYApFTPZk9+7XWSxYxxNvuSMNWlZzcuYtVAyZ9mdOKmB+9iM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FjV4lzBy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A8B7C433C7; Sun, 25 Feb 2024 22:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901737; bh=ENJnGfyd2+EEzXokoqGcyz6LV1lezsDunVEKa8lSN3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FjV4lzBy+48yVJ6MtN08wD5bGhgv4/sVSxjayzSEscmTLWMCAtNbmZGo4tj3+eeDn /rYrbsD1m1OkVKe1DKtywblm8kGzLWXyntzuo8iACq7Pw1/JJKaCfw5XY9r8jimH34 sKxEcyC18kmKMe0pjf3dXNiHklF3An4HXXPBx50+tA9v4jJn7BoIBtFuAp2VFSZe42 di97SQZPDeW9OjlIHgeyEVGwgNiQpn32IjkaAO6XS1BOxDguoLGTT1GU5XDEReGwTl 0NF3HpA96e56ii9CwwxARG7S35TlGwWy+yGUQK18dmb/NRdm+ni9KojQZkluy4Aq/Q dHAL9rpt2Jf2Q== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 11/16] tick: Move got_idle_tick away from common flags Date: Sun, 25 Feb 2024 23:55:03 +0100 Message-ID: <20240225225508.11587-12-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913483579797503 X-GMAIL-MSGID: 1791913483579797503 tick_nohz_idle_got_tick() is called by cpuidle_reflect() within the idle loop with interrupts enabled. This function modifies the struct tick_sched's bitfield "got_idle_tick". However this bitfield is stored within the same mask as other bitfields that can be modified from interrupts. Fortunately so far it looks like the only race that can happen is while writing ->got_idle_tick to 0, an interrupt fires and writes the ->idle_active field to 0. It's then possible that the interrupted write to ->got_idle_tick writes back the old value of ->idle_active back to 1. However if that happens, the worst possible outcome is that the time spent between that interrupt and the upcoming call to tick_nohz_idle_exit() is accounted as idle, which is negligible quantity. Still all the bitfield writes within this struct tick_sched's shadow mask should be IRQ-safe. Therefore move this bitfield out to its own storage to avoid further suprises. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/tick-sched.h b/kernel/time/tick-sched.h index 35808bbb8a47..3b555e0fa937 100644 --- a/kernel/time/tick-sched.h +++ b/kernel/time/tick-sched.h @@ -61,7 +61,6 @@ struct tick_sched { unsigned int tick_stopped : 1; unsigned int idle_active : 1; unsigned int do_timer_last : 1; - unsigned int got_idle_tick : 1; /* Tick handling: jiffies stall check */ unsigned int stalled_jiffies; @@ -73,6 +72,7 @@ struct tick_sched { ktime_t next_tick; unsigned long idle_jiffies; ktime_t idle_waketime; + unsigned int got_idle_tick; /* Idle entry */ seqcount_t idle_sleeptime_seq; From patchwork Sun Feb 25 22:55:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206146 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1777407dyb; Sun, 25 Feb 2024 15:16:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX0EG56a0XqFoA6cZEHqc22MPgACSYgFSRxgjgn2cHGa22tfG4+wGd2iiyzuCeq0AffG88HyJ6afGxKlay3fv9MYF2KCQ== X-Google-Smtp-Source: AGHT+IEydYxcu/EdgPZLAJwYJhoysKbrHLdmZEtzTon1NY0C8ARcqbL30Ek5fjwCUTVo4hL8vMVT X-Received: by 2002:a17:906:f117:b0:a3f:69a6:8216 with SMTP id gv23-20020a170906f11700b00a3f69a68216mr2884883ejb.41.1708902996981; Sun, 25 Feb 2024 15:16:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708902996; cv=pass; d=google.com; s=arc-20160816; b=SIku9bUkU6DUvPGepnLua1SDu9ryqbCdwCRYKmq+DpQAJF99gvHCK1xdW5ul4UqmsH Ji/dOc0mCzDWGWhF0gUY43Ls56zzuIFmHTBWH8n82yffsBu/YdznMRw55ja9yPRP+7Rs DJlInDHUbG+CJWMZR02OIPAG1Fjn544n1qJY/AN+lTK5Lo3p8eBLW3BgZch1LHrg4zTj 1MMvlyBQkhM6rd+bnTnA9Ru41i3nFD2y4wyQe8ipmIUIe0d50FB302XBs86/42vN6FVA rHVmIwqDCGhZTE6kpB7lgU2rIJRBO9595dP4ydPQy1pjv1v2O8YVGkS1KOHhIl5YNLQI gNGw== 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=Kq81pAI/4hedae3tdgLgFGpbOqOnnDBh+1dmc02ZZyU=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=oJYLZyNqQ1kJFxZzRKF2s6JcrI/naNMM11J0vV4I9mnLBSIYk3h9HinIU5nR5yoyv3 SMpmlGqZ37Pl+J2MGAq0EeLhsmO1ML6cBeDGDRkcimf9yQB4F3MOz0UdmgCcixE6+1/a xj0pOlZ8hAlqbrUUKSLT1mbimHoc1XZKc+iShrVN8btBrOZn9lAEuX6+gpxq4FwY6R/T yesmbKpzl8BKnbqEieq8tSKQMi01HrpInBE+QBteQTu8k9fjCy6xmQnjwymwki1ATbBY d/jLSSQn//9P0mW6v+mi1hQajH73TTsdDHMFiqpU1K40a85ZkZAgXHtGLfaIFpHFU8UA Yqjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s6krpi+u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80339-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80339-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qk42-20020a1709077faa00b00a43277c0624si758183ejc.74.2024.02.25.15.16.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 15:16:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80339-ouuuleilei=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=s6krpi+u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80339-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80339-ouuuleilei=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 9118F1F23B97 for ; Sun, 25 Feb 2024 22:58:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD3061BF58; Sun, 25 Feb 2024 22:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s6krpi+u" 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 36C711BC56 for ; Sun, 25 Feb 2024 22:55:39 +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=1708901740; cv=none; b=YJVGOhGi6xKq8xSqHo0ijVHQshI2housgARkpfsPPhf7LD55Awj5tkNw9rYkHab250oF2U5jTcjdlLnudRSK1+diQ529q0YkFKLqeu9RrnK51lq6ygknywJQ1pfpwX0dTxKT18WtaVXJhTIhQ71tvTUnnLODR2k4YOwXTkCksYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901740; c=relaxed/simple; bh=nvq+0+c2VgwiAV9LLQoQtr7r3jeFHn9GHHJ6M6acVz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S6TlCy9suLfSO848apWqmaiQcaYUnPWNAhnPIvdt23MJUZlzDuGOyRD4uNjXoiFcx20qMN5EBy7bAsrhwRQalwuP1Pdu9vpFvnCF0tyHKio2tbihKgi94zOPicS5nhVrSNvO6rJ2a+Kj6P4DxMb5sdQfECg9uncnF1QlWEUxqvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s6krpi+u; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 034E8C433F1; Sun, 25 Feb 2024 22:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901739; bh=nvq+0+c2VgwiAV9LLQoQtr7r3jeFHn9GHHJ6M6acVz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s6krpi+uTj30i1AM6Rhbq+0CRl7L0VL/A7HfIV6qZMm2zKgnIsJZIZwWX8sBxdFDe /SchY+1KCq3xwPRU+MdxtC29L4XU2ixQ6CmNqm/3FvlgM2ahlin5TdfgKY5Vu7ijCO 0p96bXCwmFcKNwohle9F1RJumyTXA5/nO5ii7/lUrAI2fT/fPr85cUk0OPCLELQP/j uulL0wGCgBQcNZ6guTrpQ7G6Xs5Mo8k3A6W4UUy6f+XvSm/bImrAxU1FeDTPlcciGJ U7h0XbtvzphlbHMP+WHOljIFpUwnYkU1wr1Akl+78T0BXuAu5IJE+BNy1fLlaTsBOx SXti2G3vnDyFQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 12/16] tick: Move individual bit features to debuggable mask accesses Date: Sun, 25 Feb 2024 23:55:04 +0100 Message-ID: <20240225225508.11587-13-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791914668685211553 X-GMAIL-MSGID: 1791914668685211553 The individual bitfields of struct tick_sched must be modified from IRQs disabled places, otherwise local modifications can race due to them sharing the same memory storage. The recent move of the "got_idle_tick" bitfield to its own storage shows that the use of these bitfields, as pretty as they look, can be as much error prone. In order to avoid future issues of the like and make sure that those bitfields are safely accessed, move those flags to an explicit mask along with a mutator function performing the basic IRQs disabled sanity check. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 88 +++++++++++++++++++++++++--------------- kernel/time/tick-sched.h | 23 +++++++---- kernel/time/timer_list.c | 5 ++- 3 files changed, 73 insertions(+), 43 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index b79f5403433b..4aa7ce04a72c 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -180,6 +180,26 @@ static ktime_t tick_init_jiffy_update(void) return period; } +static inline int tick_sched_flag_test(struct tick_sched *ts, + unsigned long flag) +{ + return !!(ts->flags & flag); +} + +static inline void tick_sched_flag_set(struct tick_sched *ts, + unsigned long flag) +{ + lockdep_assert_irqs_disabled(); + ts->flags |= flag; +} + +static inline void tick_sched_flag_clear(struct tick_sched *ts, + unsigned long flag) +{ + lockdep_assert_irqs_disabled(); + ts->flags &= ~flag; +} + #define MAX_STALLED_JIFFIES 5 static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now) @@ -223,7 +243,7 @@ static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now) } } - if (ts->inidle) + if (tick_sched_flag_test(ts, TS_FLAG_INIDLE)) ts->got_idle_tick = 1; } @@ -237,7 +257,8 @@ static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs) * idle" jiffy stamp so the idle accounting adjustment we do * when we go busy again does not account too many ticks. */ - if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && ts->tick_stopped) { + if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && + tick_sched_flag_test(ts, TS_FLAG_STOPPED)) { touch_softlockup_watchdog_sched(); if (is_idle_task(current)) ts->idle_jiffies++; @@ -279,7 +300,7 @@ static enum hrtimer_restart tick_nohz_handler(struct hrtimer *timer) * - to the idle task if in dynticks-idle * - to IRQ exit if in full-dynticks. */ - if (unlikely(ts->tick_stopped)) + if (unlikely(tick_sched_flag_test(ts, TS_FLAG_STOPPED))) return HRTIMER_NORESTART; hrtimer_forward(timer, now, TICK_NSEC); @@ -559,7 +580,7 @@ void __tick_nohz_task_switch(void) ts = this_cpu_ptr(&tick_cpu_sched); - if (ts->tick_stopped) { + if (tick_sched_flag_test(ts, TS_FLAG_STOPPED)) { if (atomic_read(¤t->tick_dep_mask) || atomic_read(¤t->signal->tick_dep_mask)) tick_nohz_full_kick(); @@ -656,14 +677,14 @@ bool tick_nohz_tick_stopped(void) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - return ts->tick_stopped; + return tick_sched_flag_test(ts, TS_FLAG_STOPPED); } bool tick_nohz_tick_stopped_cpu(int cpu) { struct tick_sched *ts = per_cpu_ptr(&tick_cpu_sched, cpu); - return ts->tick_stopped; + return tick_sched_flag_test(ts, TS_FLAG_STOPPED); } /** @@ -693,7 +714,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) { ktime_t delta; - if (WARN_ON_ONCE(!ts->idle_active)) + if (WARN_ON_ONCE(!tick_sched_flag_test(ts, TS_FLAG_IDLE_ACTIVE))) return; delta = ktime_sub(now, ts->idle_entrytime); @@ -705,7 +726,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); ts->idle_entrytime = now; - ts->idle_active = 0; + tick_sched_flag_clear(ts, TS_FLAG_IDLE_ACTIVE); write_seqcount_end(&ts->idle_sleeptime_seq); sched_clock_idle_wakeup_event(); @@ -715,7 +736,7 @@ static void tick_nohz_start_idle(struct tick_sched *ts) { write_seqcount_begin(&ts->idle_sleeptime_seq); ts->idle_entrytime = ktime_get(); - ts->idle_active = 1; + tick_sched_flag_set(ts, TS_FLAG_IDLE_ACTIVE); write_seqcount_end(&ts->idle_sleeptime_seq); sched_clock_idle_sleep_event(); @@ -737,7 +758,7 @@ static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime, do { seq = read_seqcount_begin(&ts->idle_sleeptime_seq); - if (ts->idle_active && compute_delta) { + if (tick_sched_flag_test(ts, TS_FLAG_IDLE_ACTIVE) && compute_delta) { ktime_t delta = ktime_sub(now, ts->idle_entrytime); idle = ktime_add(*sleeptime, delta); @@ -905,7 +926,7 @@ static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu) * We've not stopped the tick yet, and there's a timer in the * next period, so no point in stopping it either, bail. */ - if (!ts->tick_stopped) { + if (!tick_sched_flag_test(ts, TS_FLAG_STOPPED)) { ts->timer_expires = 0; goto out; } @@ -918,7 +939,8 @@ static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu) */ delta = timekeeping_max_deferment(); if (cpu != tick_do_timer_cpu && - (tick_do_timer_cpu != TICK_DO_TIMER_NONE || !ts->do_timer_last)) + (tick_do_timer_cpu != TICK_DO_TIMER_NONE || + !tick_sched_flag_test(ts, TS_FLAG_DO_TIMER_LAST))) delta = KTIME_MAX; /* Calculate the next expiry time */ @@ -938,7 +960,7 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); unsigned long basejiff = ts->last_jiffies; u64 basemono = ts->timer_expires_base; - bool timer_idle = ts->tick_stopped; + bool timer_idle = tick_sched_flag_test(ts, TS_FLAG_STOPPED); u64 expires; /* Make sure we won't be trying to stop it twice in a row. */ @@ -978,13 +1000,13 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) */ if (cpu == tick_do_timer_cpu) { tick_do_timer_cpu = TICK_DO_TIMER_NONE; - ts->do_timer_last = 1; + tick_sched_flag_set(ts, TS_FLAG_DO_TIMER_LAST); } else if (tick_do_timer_cpu != TICK_DO_TIMER_NONE) { - ts->do_timer_last = 0; + tick_sched_flag_clear(ts, TS_FLAG_DO_TIMER_LAST); } /* Skip reprogram of event if it's not changed */ - if (ts->tick_stopped && (expires == ts->next_tick)) { + if (tick_sched_flag_test(ts, TS_FLAG_STOPPED) && (expires == ts->next_tick)) { /* Sanity check: make sure clockevent is actually programmed */ if (expires == KTIME_MAX || ts->next_tick == hrtimer_get_expires(&ts->sched_timer)) return; @@ -1002,12 +1024,12 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) * call we save the current tick time, so we can restart the * scheduler tick in tick_nohz_restart_sched_tick(). */ - if (!ts->tick_stopped) { + if (!tick_sched_flag_test(ts, TS_FLAG_STOPPED)) { calc_load_nohz_start(); quiet_vmstat(); ts->last_tick = hrtimer_get_expires(&ts->sched_timer); - ts->tick_stopped = 1; + tick_sched_flag_set(ts, TS_FLAG_STOPPED); trace_tick_stop(1, TICK_DEP_MASK_NONE); } @@ -1064,7 +1086,7 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now) touch_softlockup_watchdog_sched(); /* Cancel the scheduled timer and restore the tick: */ - ts->tick_stopped = 0; + tick_sched_flag_clear(ts, TS_FLAG_STOPPED); tick_nohz_restart(ts, now); } @@ -1076,7 +1098,7 @@ static void __tick_nohz_full_update_tick(struct tick_sched *ts, if (can_stop_full_tick(cpu, ts)) tick_nohz_full_stop_tick(ts, cpu); - else if (ts->tick_stopped) + else if (tick_sched_flag_test(ts, TS_FLAG_STOPPED)) tick_nohz_restart_sched_tick(ts, now); #endif } @@ -1196,14 +1218,14 @@ void tick_nohz_idle_stop_tick(void) ts->idle_calls++; if (expires > 0LL) { - int was_stopped = ts->tick_stopped; + int was_stopped = tick_sched_flag_test(ts, TS_FLAG_STOPPED); tick_nohz_stop_tick(ts, cpu); ts->idle_sleeps++; ts->idle_expires = expires; - if (!was_stopped && ts->tick_stopped) { + if (!was_stopped && tick_sched_flag_test(ts, TS_FLAG_STOPPED)) { ts->idle_jiffies = ts->last_jiffies; nohz_balance_enter_idle(cpu); } @@ -1234,7 +1256,7 @@ void tick_nohz_idle_enter(void) WARN_ON_ONCE(ts->timer_expires_base); - ts->inidle = 1; + tick_sched_flag_set(ts, TS_FLAG_INIDLE); tick_nohz_start_idle(ts); local_irq_enable(); @@ -1263,7 +1285,7 @@ void tick_nohz_irq_exit(void) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - if (ts->inidle) + if (tick_sched_flag_test(ts, TS_FLAG_INIDLE)) tick_nohz_start_idle(ts); else tick_nohz_full_update_tick(ts); @@ -1317,7 +1339,7 @@ ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next) ktime_t now = ts->idle_entrytime; ktime_t next_event; - WARN_ON_ONCE(!ts->inidle); + WARN_ON_ONCE(!tick_sched_flag_test(ts, TS_FLAG_INIDLE)); *delta_next = ktime_sub(dev->next_event, now); @@ -1389,7 +1411,7 @@ void tick_nohz_idle_restart_tick(void) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - if (ts->tick_stopped) { + if (tick_sched_flag_test(ts, TS_FLAG_STOPPED)) { ktime_t now = ktime_get(); tick_nohz_restart_sched_tick(ts, now); tick_nohz_account_idle_time(ts, now); @@ -1430,12 +1452,12 @@ void tick_nohz_idle_exit(void) local_irq_disable(); - WARN_ON_ONCE(!ts->inidle); + WARN_ON_ONCE(!tick_sched_flag_test(ts, TS_FLAG_INIDLE)); WARN_ON_ONCE(ts->timer_expires_base); - ts->inidle = 0; - idle_active = ts->idle_active; - tick_stopped = ts->tick_stopped; + tick_sched_flag_clear(ts, TS_FLAG_INIDLE); + idle_active = tick_sched_flag_test(ts, TS_FLAG_IDLE_ACTIVE); + tick_stopped = tick_sched_flag_test(ts, TS_FLAG_STOPPED); if (idle_active || tick_stopped) now = ktime_get(); @@ -1498,10 +1520,10 @@ static inline void tick_nohz_irq_enter(void) struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); ktime_t now; - if (!ts->idle_active && !ts->tick_stopped) + if (!tick_sched_flag_test(ts, TS_FLAG_STOPPED | TS_FLAG_IDLE_ACTIVE)) return; now = ktime_get(); - if (ts->idle_active) + if (tick_sched_flag_test(ts, TS_FLAG_IDLE_ACTIVE)) tick_nohz_stop_idle(ts, now); /* * If all CPUs are idle we may need to update a stale jiffies value. @@ -1510,7 +1532,7 @@ static inline void tick_nohz_irq_enter(void) * rare case (typically stop machine). So we must make sure we have a * last resort. */ - if (ts->tick_stopped) + if (tick_sched_flag_test(ts, TS_FLAG_STOPPED)) tick_nohz_update_jiffies(now); } diff --git a/kernel/time/tick-sched.h b/kernel/time/tick-sched.h index 3b555e0fa937..07a4c0144c47 100644 --- a/kernel/time/tick-sched.h +++ b/kernel/time/tick-sched.h @@ -20,14 +20,22 @@ enum tick_nohz_mode { NOHZ_MODE_HIGHRES, }; +/* The CPU is in the tick idle mode */ +#define TS_FLAG_INIDLE BIT(0) +/* The idle tick has been stopped */ +#define TS_FLAG_STOPPED BIT(1) +/* + * Indicator that the CPU is actively in the tick idle mode; + * it is reset during irq handling phases. + */ +#define TS_FLAG_IDLE_ACTIVE BIT(2) +/* CPU was the last one doing do_timer before going idle */ +#define TS_FLAG_DO_TIMER_LAST BIT(3) + /** * struct tick_sched - sched tick emulation and no idle tick control/stats * - * @inidle: Indicator that the CPU is in the tick idle mode - * @tick_stopped: Indicator that the idle tick has been stopped - * @idle_active: Indicator that the CPU is actively in the tick idle mode; - * it is reset during irq handling phases. - * @do_timer_last: CPU was the last one doing do_timer before going idle + * @flags: State flags gathering the TS_FLAG_* features * @got_idle_tick: Tick timer function has run with @inidle set * @stalled_jiffies: Number of stalled jiffies detected across ticks * @last_tick_jiffies: Value of jiffies seen on last tick @@ -57,10 +65,7 @@ enum tick_nohz_mode { */ struct tick_sched { /* Common flags */ - unsigned int inidle : 1; - unsigned int tick_stopped : 1; - unsigned int idle_active : 1; - unsigned int do_timer_last : 1; + unsigned long flags; /* Tick handling: jiffies stall check */ unsigned int stalled_jiffies; diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c index ed7d6ad694fb..38f81d836fc5 100644 --- a/kernel/time/timer_list.c +++ b/kernel/time/timer_list.c @@ -147,11 +147,14 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now) # define P_ns(x) \ SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \ (unsigned long long)(ktime_to_ns(ts->x))) +# define P_flag(x, f) \ + SEQ_printf(m, " .%-15s: %d\n", #x, !!(ts->flags & (f))) + { struct tick_sched *ts = tick_get_tick_sched(cpu); P(nohz_mode); P_ns(last_tick); - P(tick_stopped); + P_flag(tick_stopped, TS_FLAG_STOPPED); P(idle_jiffies); P(idle_calls); P(idle_sleeps); From patchwork Sun Feb 25 22:55:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770760dyb; Sun, 25 Feb 2024 14:58:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXYVT94OR3XFAUXG/fWo/Mh8YrU4loTChfOz+PToy6jJ4timlgI6g5MfHbEEfUEtcgQi4+1HXn9ABhKb+nM1CR7Ys2DCA== X-Google-Smtp-Source: AGHT+IGvArx8oSfN9q6TYKdU1oZJppuLlPnMxgq2KVdHM20CYaEfN7dC5AzVuD3b68yPe02N+FQ4 X-Received: by 2002:a17:902:aa81:b0:1d9:3843:3f07 with SMTP id d1-20020a170902aa8100b001d938433f07mr4965319plr.61.1708901904294; Sun, 25 Feb 2024 14:58:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901904; cv=pass; d=google.com; s=arc-20160816; b=b014AvUVsQbTTbyAjLgthcSdzRl3B5mnivKhIWdJUjpfNkhdVWk76QQGTsU9uVEM+J 3rprqsYevzzS7uxpmv/V97clHZp/99G0OfiEHHUn7jEPQXAF72jZjdVXvcDcmYie+t4u bPVjtSwyGDg1n1H6sI3gz7YYtN19o754vZChGe0GK3fpKQthe9+0v61sYRUfEvglvhGH HiH3uiztlSw/GomoMq1mN+TwQ9WanLFh2Q3mvtDQmFRG+tIpDNRae0REakuN8jie/ZrW XJ4LkJ7H/rt1uJ4Xe5Y8c9mOYgQDBX6HKIVofCzIRovE4Oghys2aZhWHFYWrYQVEPF1S k8qg== 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=pcQ6ht6lD24L1fjr8aXIUSYtb47a4rQ3awG9yaIYfUs=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=hnkfRTMkJrtWq8sSzbZlve/qXogJMOoPfuRxleqIBkdwDFvCdms6kaTXXUGSwqFHDM NDTVsNzznCvwIym/JDN5WsuWHokQTcFo9PysJsL/cWQOkvztPo0UVEwyRCOe+1jHFwdM pi4WUNzeNUmtodZWmCHk1Gu5Qd6/0P1LiXKs76+qneBZAVTqemnzeyQgBHNIZpx0uWlY RvkPnqqcevNjcIRrv3ShXs7bkSQ+2VbyrAWUZ6RL42g7G+ExCrUDdVrc8xwD6KhgymOd ccsxcWZ6Y7Psk/V6X1hxa2qEWgKQ/OtGgMxIH9Nfk7vM67q55jKcejxqJdp4e/Udkf1F OdUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VVwZkeMs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80340-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80340-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h13-20020a170902680d00b001dc5e90b4f5si2668098plk.592.2024.02.25.14.58.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:58:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80340-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=@kernel.org header.s=k20201202 header.b=VVwZkeMs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80340-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80340-ouuuleilei=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 884A0B20FD2 for ; Sun, 25 Feb 2024 22:58:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4131C1BF47; Sun, 25 Feb 2024 22:55:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VVwZkeMs" 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 797761BF35 for ; Sun, 25 Feb 2024 22:55:42 +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=1708901742; cv=none; b=gtgw/R6fbm3nGA8djoahxscpc1IvwcGf2H140vVdR9dTP3lhw1F6NDkkLEqykZbrcDUXikgMgyDgbsQeSZSF0EQpsStq8Y/ccSCc4RD/HwmcQCFkLe7oQVdhBCu3A+EvIhLqk/vSjk+SGxU7PGqOfph/8LxydQkT0Wn6YDReODo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901742; c=relaxed/simple; bh=9i+6LrQeoWXgQOQr/7C+jReFscj2yOzZY2cAKOTq+14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EmJvVCh8C8QQgpvJ9Hkp4wHkTQBi8Dv8N4Ghsvca+u3MWxzRtf0/xZeoHBDrnER2Qm1zNa5Rww1k2swBQqkTWf2bp7kXTQKFI3ZzYoNw/bzgVrPSZA9vRHupMsLt/LQwOQ1SsCgB9x53GerMMsx1MH5PvsGFxKfT44BOrTiB83s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VVwZkeMs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E1BEC433C7; Sun, 25 Feb 2024 22:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901742; bh=9i+6LrQeoWXgQOQr/7C+jReFscj2yOzZY2cAKOTq+14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VVwZkeMsb7A/3ki85CSFzmoP7osV+sScdBpSFfRw6LhcJL4CF8gwEijrOOygciyQh XI/heK/npidAx6ccy5RZ9oM11kiQr7V+RjhDaTPsm3G+cYhmcaCfLma8bcTDa/e8ZQ Wdsl2UvcklxV0bGVEL6yfGHCVJmDZPWcdUbZAo4sRCCzzledLJFCiUepVfOKsI4Jr5 04PLo5XgcTDi5z4/dU29SMQqGEU6gUt1iVO54ywQhchWXDsa4PYETT0G91gjkAE2+X dhYDrW6qmoC+9K+7l1wcX4+1AnOIUP5TQnr//s0J+UiR1Rjr5KJdEKJN0YkN2yvdn7 BX2yLRgiccZ5g== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 13/16] tick: Split nohz and highres features from nohz_mode Date: Sun, 25 Feb 2024 23:55:05 +0100 Message-ID: <20240225225508.11587-14-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913522972083405 X-GMAIL-MSGID: 1791913522972083405 The nohz mode field tells about low resolution nohz mode or high resolution nohz mode but it doesn't tell about high resolution non-nohz mode. In order to retrieve the latter state, tick_cancel_sched_timer() must fiddle with struct hrtimer's internals to guess if the tick has been initialized in high resolution. Move instead the nohz mode field information into the tick flags and provide two new bits: one to know if the tick is in nohz mode and another one to know if the tick is in high resolution. The combination of those two flags provides all the needed informations to determine which of the three tick modes is running. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/hrtimer.c | 2 +- kernel/time/tick-sched.c | 32 +++++++++++++++++--------------- kernel/time/tick-sched.h | 13 +++++-------- kernel/time/timer_list.c | 5 +++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 3e95474199ac..70625dff62ce 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(NOHZ_MODE_HIGHRES); + tick_setup_sched_timer(true); /* "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 4aa7ce04a72c..dcb9f0394182 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -831,7 +831,7 @@ static void tick_nohz_restart(struct tick_sched *ts, ktime_t now) /* Forward the time to expire in the future */ hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); - if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { + if (tick_sched_flag_test(ts, TS_FLAG_HIGHRES)) { hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED_HARD); } else { @@ -1040,14 +1040,14 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) * the tick timer. */ if (unlikely(expires == KTIME_MAX)) { - if (ts->nohz_mode == NOHZ_MODE_HIGHRES) + if (tick_sched_flag_test(ts, TS_FLAG_HIGHRES)) hrtimer_cancel(&ts->sched_timer); else tick_program_event(KTIME_MAX, 1); return; } - if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { + if (tick_sched_flag_test(ts, TS_FLAG_HIGHRES)) { hrtimer_start(&ts->sched_timer, expires, HRTIMER_MODE_ABS_PINNED_HARD); } else { @@ -1108,7 +1108,7 @@ static void tick_nohz_full_update_tick(struct tick_sched *ts) if (!tick_nohz_full_cpu(smp_processor_id())) return; - if (ts->nohz_mode == NOHZ_MODE_INACTIVE) + if (!tick_sched_flag_test(ts, TS_FLAG_NOHZ)) return; __tick_nohz_full_update_tick(ts, ktime_get()); @@ -1168,7 +1168,7 @@ static bool can_stop_idle_tick(int cpu, struct tick_sched *ts) return false; } - if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE)) + if (unlikely(!tick_sched_flag_test(ts, TS_FLAG_NOHZ))) return false; if (need_resched()) @@ -1487,11 +1487,11 @@ static void tick_nohz_lowres_handler(struct clock_event_device *dev) tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); } -static inline void tick_nohz_activate(struct tick_sched *ts, int mode) +static inline void tick_nohz_activate(struct tick_sched *ts) { if (!tick_nohz_enabled) return; - ts->nohz_mode = mode; + tick_sched_flag_set(ts, TS_FLAG_NOHZ); /* One update is enough */ if (!test_and_set_bit(0, &tick_nohz_active)) timers_update_nohz(); @@ -1512,7 +1512,7 @@ static void tick_nohz_switch_to_nohz(void) * Recycle the hrtimer in 'ts', so we can share the * highres code. */ - tick_setup_sched_timer(NOHZ_MODE_LOWRES); + tick_setup_sched_timer(false); } static inline void tick_nohz_irq_enter(void) @@ -1540,7 +1540,7 @@ static inline void tick_nohz_irq_enter(void) static inline void tick_nohz_switch_to_nohz(void) { } static inline void tick_nohz_irq_enter(void) { } -static inline void tick_nohz_activate(struct tick_sched *ts, int mode) { } +static inline void tick_nohz_activate(struct tick_sched *ts) { } #endif /* CONFIG_NO_HZ_COMMON */ @@ -1567,15 +1567,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(int mode) +void tick_setup_sched_timer(bool hrtimer) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); /* Emulate tick processing via per-CPU hrtimers: */ hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); - if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && mode == NOHZ_MODE_HIGHRES) + if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && hrtimer) { + tick_sched_flag_set(ts, TS_FLAG_HIGHRES); ts->sched_timer.function = tick_nohz_handler; + } /* Get the next period (per-CPU) */ hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); @@ -1589,11 +1591,11 @@ void tick_setup_sched_timer(int mode) } hrtimer_forward_now(&ts->sched_timer, TICK_NSEC); - if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && mode == NOHZ_MODE_HIGHRES) + if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && hrtimer) 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); + tick_nohz_activate(ts); } void tick_cancel_sched_timer(int cpu) @@ -1602,7 +1604,7 @@ void tick_cancel_sched_timer(int cpu) ktime_t idle_sleeptime, iowait_sleeptime; unsigned long idle_calls, idle_sleeps; - if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && ts->sched_timer.base) + if (tick_sched_flag_test(ts, TS_FLAG_HIGHRES)) hrtimer_cancel(&ts->sched_timer); idle_sleeptime = ts->idle_sleeptime; @@ -1652,7 +1654,7 @@ int tick_check_oneshot_change(int allow_nohz) if (!test_and_clear_bit(0, &ts->check_clocks)) return 0; - if (ts->nohz_mode != NOHZ_MODE_INACTIVE) + if (tick_sched_flag_test(ts, TS_FLAG_NOHZ)) return 0; if (!timekeeping_valid_for_hres() || !tick_is_oneshot_available()) diff --git a/kernel/time/tick-sched.h b/kernel/time/tick-sched.h index 07a4c0144c47..bbe72a078985 100644 --- a/kernel/time/tick-sched.h +++ b/kernel/time/tick-sched.h @@ -14,12 +14,6 @@ struct tick_device { enum tick_device_mode mode; }; -enum tick_nohz_mode { - NOHZ_MODE_INACTIVE, - NOHZ_MODE_LOWRES, - NOHZ_MODE_HIGHRES, -}; - /* The CPU is in the tick idle mode */ #define TS_FLAG_INIDLE BIT(0) /* The idle tick has been stopped */ @@ -31,6 +25,10 @@ enum tick_nohz_mode { #define TS_FLAG_IDLE_ACTIVE BIT(2) /* CPU was the last one doing do_timer before going idle */ #define TS_FLAG_DO_TIMER_LAST BIT(3) +/* NO_HZ is enabled */ +#define TS_FLAG_NOHZ BIT(4) +/* High resolution tick mode */ +#define TS_FLAG_HIGHRES BIT(5) /** * struct tick_sched - sched tick emulation and no idle tick control/stats @@ -84,7 +82,6 @@ struct tick_sched { ktime_t idle_entrytime; /* Tick stop */ - enum tick_nohz_mode nohz_mode; unsigned long last_jiffies; u64 timer_expires_base; u64 timer_expires; @@ -107,7 +104,7 @@ struct tick_sched { extern struct tick_sched *tick_get_tick_sched(int cpu); -extern void tick_setup_sched_timer(int mode); +extern void tick_setup_sched_timer(bool hrtimer); #if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS extern void tick_cancel_sched_timer(int cpu); #else diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c index 38f81d836fc5..1c311c46da50 100644 --- a/kernel/time/timer_list.c +++ b/kernel/time/timer_list.c @@ -152,7 +152,8 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now) { struct tick_sched *ts = tick_get_tick_sched(cpu); - P(nohz_mode); + P_flag(nohz, TS_FLAG_NOHZ); + P_flag(highres, TS_FLAG_HIGHRES); P_ns(last_tick); P_flag(tick_stopped, TS_FLAG_STOPPED); P(idle_jiffies); @@ -259,7 +260,7 @@ static void timer_list_show_tickdevices_header(struct seq_file *m) static inline void timer_list_header(struct seq_file *m, u64 now) { - SEQ_printf(m, "Timer List Version: v0.9\n"); + SEQ_printf(m, "Timer List Version: v0.10\n"); SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES); SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now); SEQ_printf(m, "\n"); From patchwork Sun Feb 25 22:55:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770775dyb; Sun, 25 Feb 2024 14:58:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUQuSvl/OE40yGjTKSv/PscrfqCNwUGwYhEPKaDAkF0D0yqUMArqgN1GpJwHFnBzvbCreaO42m7yVBWViWRFIyLFL/8Tw== X-Google-Smtp-Source: AGHT+IGG8gYvZlyTXShJGo7aSoddudAOOnP4hUqFnpabF458WiO3IHBOSrPC/UlAtV3uceizSTeF X-Received: by 2002:a05:6a00:3c86:b0:6e1:3cdb:76f1 with SMTP id lm6-20020a056a003c8600b006e13cdb76f1mr7591439pfb.20.1708901907920; Sun, 25 Feb 2024 14:58:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901907; cv=pass; d=google.com; s=arc-20160816; b=VCw2/FAntYbfFqKL5ajvLUuH0fejBj+LCIsqMz4bv3OTrorbqQ1JkOZqGD11KoS4+B nIU+jdKNFc9KfqJnwbacQL1riLSLdBJw1RNSZ79W4N05IpVmRvPPbt4ANi059tkFDMYD 95Vx8Z2Ggvo/BCqhoJ1tfPftkkp7G8eHDU/XB67SG0BfN1XIz9kcRGFSJbQMJiwEtPHo qMDqtDTaz4f8bAwNQZffTqmeKFGxOrZIklmNW6hW5qhxWlt7BIF1tXP1nIJ6KIRA03gz GfOb9XN+h3ie2MfqCFeJ6Ow/0nrkTjzg1QTiXyB0jPW8WZdov0cMsww16mTuSPp1bQFE qQaQ== 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=gkjEggIG3lBu+eJ5SGBTI4x2QEXEWQe/wIhEww89mOM=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=l0IYBsW2vjE5xdu7zgAFp8eh/X/XV8Dl1Slk3+yrg/861te2M93/onFpvqAxUu0F54 oQPncyJOdGsay6284Sr/wJrndr02uQ4zwaZMdis6rF0JN/IDd7hEdSTL2Vy2V8xA+xJ5 TSZaX6mSk4Heax8qoWk007lhFIwaaaS8EdHvSsU3t7+/lPcQ168QcvoGuO6q7I8T4T5i iQXs9fyLh0vzytq5o48fWLI2Q1xYrQxE0Ri1aFBJa4dmUXS3M132/abPRNvhMDUWecVs ZkabNk8m5zh0oSXSR7m5+Izs+YDG5ZWbTbaEZfPu92GuCe/cBLHZ9QXHBla1kivxmhQk ykeQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k+KU80Pj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80341-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80341-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k14-20020a6568ce000000b005d3adb65694si2657011pgt.757.2024.02.25.14.58.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:58:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80341-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k+KU80Pj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80341-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80341-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B34AB281FC0 for ; Sun, 25 Feb 2024 22:58:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9A3F4CE17; Sun, 25 Feb 2024 22:55:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k+KU80Pj" 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 995A0249F9 for ; Sun, 25 Feb 2024 22:55:44 +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=1708901744; cv=none; b=ul4W0SUN294oP+3KZNSdXBJZ3YdzXYwVCmGqk+/ekAeX9jG6r8SUASHB2zZYYABFgL9H36nwGLHImnrsalppJzBtvpGesrZMywDeJv2rgCxkZfTvtAQAYRHSkqfuKD9uNUE2mC4VChpf9RNIw8Sdb5EJBIQITklffo5hELI5bmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901744; c=relaxed/simple; bh=zps/wj0u7k34+pF6RPIaYiiRwL0ICoQgkvZ4JnirR2I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dhyWdq5WNwUvvK1TxR0wHfP3GQqaih2f+zn6nSfAZL/ZD99Pr4l0Jni5GuQsT/C5C/vRIcCE3mhFaI+/pihB/pwnvWdBrf6CVnmIqdhjCU2Zxjzg6fXW+FbXy8z9JTlAmJpB4kjKeHwHxa5DJuRlKIBXxS6f0zueTfqOR7TSRcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k+KU80Pj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BF83C43390; Sun, 25 Feb 2024 22:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901744; bh=zps/wj0u7k34+pF6RPIaYiiRwL0ICoQgkvZ4JnirR2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k+KU80PjgKyzoDFi6jUw+0IVXg8H68HmxJoiPKcqB2LJDCHKH2TAmAs4DTADUtu3F hv+1p+5Ff8Y4kYRpX4UaqHW696zpPzE8TrnoB/YOfy61wWHyhH3iVQUqoko0fZyfyk LQfksH/gUJd42KKz/SCKSGSPGulSvSA54X85a1m84ftUqzADL2oLscETgmz2YHwQGx ridkT3lXZ3TVAX3lYsX3ABBNHPnXdA0qruE/mUswu07n0rafuWvMNqKWKTLVW4PzVO /HbRY+kSssRnXlCd4JEufeZPyE/lxLYja/baQc+FMpiE9zv+btyTE4pVYobhWrvDZ7 EYcMLtKd7OhqQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 14/16] tick: Shut down low-res tick from dying CPU Date: Sun, 25 Feb 2024 23:55:06 +0100 Message-ID: <20240225225508.11587-15-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913526835409113 X-GMAIL-MSGID: 1791913526835409113 The timekeeping duty is handed over from the outgoing CPU within stop machine. This works well if CONFIG_NO_HZ_COMMON=n or the tick is in high-res mode. However in low-res dynticks mode, the tick isn't cancelled until the clockevent is shut down, which can happen later. The tick may therefore fire again once IRQs are re-enabled on stop machine and until IRQs are disabled for good upon the last call to idle. That's so many opportunities for a timekeeper to go idle and the outgoing CPU to take over that duty. This is why tick_nohz_idle_stop_tick() is called one last time on idle if the CPU is seen offline: so that the timekeeping duty is handed over again in case the CPU has re-taken the duty. This means there are two timekeeping handovers on CPU down hotplug with different undocumented constraints and purposes: 1) A handover on stop machine for !dynticks || highres. All online CPUs are guaranteed to be non-idle and the timekeeping duty can be safely handed-over. The hrtimer tick is cancelled so it is guaranteed that in dynticks mode the outgoing CPU won't take again the duty. 2) A handover on last idle call for dynticks && lowres. Setting the duty to TICK_DO_TIMER_NONE makes sure that a CPU will take over the timekeeping. Prepare for consolidating the handover to a single place (the first one) with shutting down the low-res tick as well from tick_cancel_sched_timer() as well. This will simplify the handover and unify the tick cancellation between high-res and low-res. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- kernel/time/tick-common.c | 3 ++- kernel/time/tick-sched.c | 32 +++++++++++++++++++++++++------- kernel/time/tick-sched.h | 4 ++-- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 522414089c0d..9cd09eea06d6 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -410,7 +410,8 @@ int tick_cpu_dying(unsigned int dying_cpu) if (tick_do_timer_cpu == dying_cpu) tick_do_timer_cpu = cpumask_first(cpu_online_mask); - tick_cancel_sched_timer(dying_cpu); + /* Make sure the CPU won't try to retake the timekeeping duty */ + tick_sched_timer_dying(dying_cpu); /* Remove CPU from timer broadcasting */ tick_offline_cpu(dying_cpu); diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index dcb9f0394182..89d16b8ea2c4 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -308,6 +308,14 @@ static enum hrtimer_restart tick_nohz_handler(struct hrtimer *timer) return HRTIMER_RESTART; } +static void tick_sched_timer_cancel(struct tick_sched *ts) +{ + if (tick_sched_flag_test(ts, TS_FLAG_HIGHRES)) + hrtimer_cancel(&ts->sched_timer); + else if (tick_sched_flag_test(ts, TS_FLAG_NOHZ)) + tick_program_event(KTIME_MAX, 1); +} + #ifdef CONFIG_NO_HZ_FULL cpumask_var_t tick_nohz_full_mask; EXPORT_SYMBOL_GPL(tick_nohz_full_mask); @@ -1040,10 +1048,7 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) * the tick timer. */ if (unlikely(expires == KTIME_MAX)) { - if (tick_sched_flag_test(ts, TS_FLAG_HIGHRES)) - hrtimer_cancel(&ts->sched_timer); - else - tick_program_event(KTIME_MAX, 1); + tick_sched_timer_cancel(ts); return; } @@ -1598,14 +1603,27 @@ void tick_setup_sched_timer(bool hrtimer) tick_nohz_activate(ts); } -void tick_cancel_sched_timer(int cpu) +/* + * Shut down the tick and make sure the CPU won't try to retake the timekeeping + * duty before disabling IRQs in idle for the last time. + */ +void tick_sched_timer_dying(int cpu) { + struct tick_device *td = &per_cpu(tick_cpu_device, cpu); struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); + struct clock_event_device *dev = td->evtdev; ktime_t idle_sleeptime, iowait_sleeptime; unsigned long idle_calls, idle_sleeps; - if (tick_sched_flag_test(ts, TS_FLAG_HIGHRES)) - hrtimer_cancel(&ts->sched_timer); + /* This must happen before hrtimers are migrated! */ + tick_sched_timer_cancel(ts); + + /* + * If the clockevents doesn't support CLOCK_EVT_STATE_ONESHOT_STOPPED, + * make sure not to call low-res tick handler. + */ + if (tick_sched_flag_test(ts, TS_FLAG_NOHZ)) + dev->event_handler = clockevents_handle_noop; idle_sleeptime = ts->idle_sleeptime; iowait_sleeptime = ts->iowait_sleeptime; diff --git a/kernel/time/tick-sched.h b/kernel/time/tick-sched.h index bbe72a078985..58d8d1c49dd3 100644 --- a/kernel/time/tick-sched.h +++ b/kernel/time/tick-sched.h @@ -106,9 +106,9 @@ extern struct tick_sched *tick_get_tick_sched(int cpu); extern void tick_setup_sched_timer(bool hrtimer); #if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS -extern void tick_cancel_sched_timer(int cpu); +extern void tick_sched_timer_dying(int cpu); #else -static inline void tick_cancel_sched_timer(int cpu) { } +static inline void tick_sched_timer_dying(int cpu) { } #endif #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST From patchwork Sun Feb 25 22:55:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770798dyb; Sun, 25 Feb 2024 14:58:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVlojcxCtntKL3mw97gEOr1AG38bpr29pI0AmFSUc6DCPDdJSQQQITDnpMGu/fQZ4jix6vNZdA67YK5/r0sLSFhEjnI+g== X-Google-Smtp-Source: AGHT+IE5va2rS+5TCwTrFmj9v2IdD0wUfIu891/todh2TBX/j03V38C3GXoSUdWOx4Q/70hWViiE X-Received: by 2002:a0d:db89:0:b0:607:786c:c3c2 with SMTP id d131-20020a0ddb89000000b00607786cc3c2mr4561733ywe.19.1708901921148; Sun, 25 Feb 2024 14:58:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901921; cv=pass; d=google.com; s=arc-20160816; b=UL4yW6DE8TNf2bg+yoNMY1VsDNkH7coPUpUDVZSqEO8RVa4l/w/DFzrLKFRYe2icYW d/Z174BXhk3ATV1ruO927q7Y9hcYYqrnYKpKhz6yVrkVU2PXPTliQH4zeM1A5iFGoi85 dbe40wTJuctaI5ficY9zaozGAcba0zEZNyriVF38RM/vaj4AY0UxPr2AIdUjNOrskGPD vJGjSPWGciup2GvxTLYdfi/qyQ9VbXyFnq4YLty/7kOdUHiKlixTyNiOVumTY76A3PX3 NEMpl6ll3EmE0uxfK8qUKB5Wr9cE01orbyJgqnJJCCyaAtVkYmEVAKNc6zvWDI5V3Xwp Uxmw== 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=6aA6ap2Bc/CxP8BQVCp0cbvq3HSgnpT9mVKK1+jOpv0=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=qNwAR04VqdYo1l2Hs0hrFhOfd6kBnB/EajGUOxaRI5KE60BbpV6Pnhgo9DiW7TNc1Q qOYcVcnip7ROgfZ6s3MAGzDeOEPOpjjJ/k5cn4WGRgLN5hyYDb5tbi29E/ltNVxajXOR wleduvwD+S3UER8Y0+H6KhEdotOh4wcxNu+tvUVlchS3ZCvrbQGLl6527nVz52gWbkNs 8e0VCM91v5iGfkiT9dMAhujqeqrChTtazlTvBJS314OvHVxX3wSyKNgvDwM/Zzo2M+DE 4qErrntmKFVQNOMmvZ5w8TaptmP6/EwzXT7K5VsCC3vxKAQnDld5trqwPaGRr85tupKb 3q8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="r6JDPu/X"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80342-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80342-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x3-20020a05620a448300b00787c6efd700si3561012qkp.340.2024.02.25.14.58.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:58:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80342-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="r6JDPu/X"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80342-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80342-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EC0831C21372 for ; Sun, 25 Feb 2024 22:58:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C2D24D9F4; Sun, 25 Feb 2024 22:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r6JDPu/X" 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 C607D4C627 for ; Sun, 25 Feb 2024 22:55:46 +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=1708901746; cv=none; b=AmA6Ez22GH64LjLyRPXiqyl/9cuRgGugYfZCszmIKO7XPNzjyhi1n4DX426kq+ViuhI8QGReeZM9qS6ApHD2mjKwlolx8tPeYdBqSRG4Aa1xUNgqJOSTq/KbipUMZyUZfm5OS3hbK+fZHtSERCCwDgDbget/5f2PdOiura+dBiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901746; c=relaxed/simple; bh=NDOPh+Q83W9rQkR/7bH7TINzHCRIhsUWJciY2roq4us=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V7j8PFdGvxEL32IEKSx1v+v5de4ANDpPTbObtImn6qqP42bELWC6eh+klnS8eVTzBoUBgSqdCC6/ucj7pzlSqE3XzxxJVD7iwNQWjI20R8x07ZhBcfDcepQKOc5WCR40zgs63f4nkxUZkZY4ZbofjB/QlU2mNnNCPr1/aatbOQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r6JDPu/X; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 924FDC433B2; Sun, 25 Feb 2024 22:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901746; bh=NDOPh+Q83W9rQkR/7bH7TINzHCRIhsUWJciY2roq4us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r6JDPu/XJ7FFFTaV4YxUjZJWuRjoXkN59ouw+A/DsHXduiMDbELbhcJpmTRCl47hM cXmpmy7U2euFnsO+tCU9r5fdBo10bo+SJ6gkxlNi5y5MP2JMMj8Zgyyu2tOFW0Qy2G xLZoB6KOulA7nuAXFlsqtM3kLGmVTfTHNp3RpCLUEIEKzARzlAiNgnHYfV3JS34UxW 5Fv2fuz3O8HBfqhWLPjOWQSfnrAgD/dOBFvNfY+p7Z6rQxhcmogB4yUib8JY7dMv35 +0aflVTwxaKd8i6bcKjDwV/OehiTR2g8QBYzJldJcBrKjNwyi5Ddt0kCrxrPTveGLn 2bBDI/g2AvuOg== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 15/16] tick: Assume timekeeping is correctly handed over upon last offline idle call Date: Sun, 25 Feb 2024 23:55:07 +0100 Message-ID: <20240225225508.11587-16-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913540699483640 X-GMAIL-MSGID: 1791913540699483640 The timekeeping duty is handed over from the outgoing CPU on stop machine, then the oneshot tick is stopped right after. Therefore it's guaranteed that the current CPU isn't the timekeeper upon its last call to idle. Besides, calling tick_nohz_idle_stop_tick() while the dying CPU goes into idle suggests that the tick is going to be stopped while it is actually stopped already from the appropriate CPU hotplug state. Remove the confusing call and the obsolete case handling and convert it to a sanity check that verifies the above assumption. Reviewed-by: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- include/linux/tick.h | 2 ++ kernel/cpu.c | 1 + kernel/sched/idle.c | 1 - kernel/time/tick-common.c | 4 ++++ kernel/time/tick-sched.c | 13 +------------ 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/include/linux/tick.h b/include/linux/tick.h index c7840ae8ebaf..44fddfa93e18 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -29,8 +29,10 @@ static inline void tick_cleanup_dead_cpu(int cpu) { } #if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_HOTPLUG_CPU) extern int tick_cpu_dying(unsigned int cpu); +extern void tick_assert_timekeeping_handover(void); #else #define tick_cpu_dying NULL +static inline void tick_assert_timekeeping_handover(void) { } #endif #if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_SUSPEND) diff --git a/kernel/cpu.c b/kernel/cpu.c index 5a8ad4f5ccf3..7e84a7b0675e 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1399,6 +1399,7 @@ void cpuhp_report_idle_dead(void) struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state); BUG_ON(st->state != CPUHP_AP_OFFLINE); + tick_assert_timekeeping_handover(); rcutree_report_cpu_dead(); st->state = CPUHP_AP_IDLE_DEAD; /* diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 31231925f1ec..b15d40cad7ea 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -291,7 +291,6 @@ static void do_idle(void) local_irq_disable(); if (cpu_is_offline(cpu)) { - tick_nohz_idle_stop_tick(); cpuhp_report_idle_dead(); arch_cpu_idle_dead(); } diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 9cd09eea06d6..fb0fdec8719a 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -396,6 +396,10 @@ int tick_broadcast_oneshot_control(enum tick_broadcast_state state) EXPORT_SYMBOL_GPL(tick_broadcast_oneshot_control); #ifdef CONFIG_HOTPLUG_CPU +void tick_assert_timekeeping_handover(void) +{ + WARN_ON_ONCE(tick_do_timer_cpu == smp_processor_id()); +} /* * Stop the tick and transfer the timekeeping job away from a dying cpu. */ diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 89d16b8ea2c4..269e21590df5 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1160,18 +1160,7 @@ static bool report_idle_softirq(void) static bool can_stop_idle_tick(int cpu, struct tick_sched *ts) { - /* - * If this CPU is offline and it is the one which updates - * jiffies, then give up the assignment and let it be taken by - * the CPU which runs the tick timer next. If we don't drop - * this here, the jiffies might be stale and do_timer() never - * gets invoked. - */ - if (unlikely(!cpu_online(cpu))) { - if (cpu == tick_do_timer_cpu) - tick_do_timer_cpu = TICK_DO_TIMER_NONE; - return false; - } + WARN_ON_ONCE(cpu_is_offline(cpu)); if (unlikely(!tick_sched_flag_test(ts, TS_FLAG_NOHZ))) return false; From patchwork Sun Feb 25 22:55:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770846dyb; Sun, 25 Feb 2024 14:58:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUKAYTfk6Ao73wDrMF0O64D8kG2ya3q5ok5vZTuwJL2RGLoLUOzrGJmHUEeCnM2plwaSSmhYlGfysTJrmjPjHYlzqhCKw== X-Google-Smtp-Source: AGHT+IGZlG8015jbhblPJ4knz4zVwGbosS9nzh6TsHLkm/ScI3HxjEmg/0K/6OJLOeHIzzauXiP2 X-Received: by 2002:a17:903:2595:b0:1d9:b8bc:fd7 with SMTP id jb21-20020a170903259500b001d9b8bc0fd7mr4717183plb.68.1708901933219; Sun, 25 Feb 2024 14:58:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901933; cv=pass; d=google.com; s=arc-20160816; b=jJM3Blf0XRGmouas+HrRHUd5jUa8JfmGVmBik+AG+3Bb0MyuJy+wsdlqFYE8zo/fRz vKl/JlPVaPRZ/gbH/T4D4boSN/GtBab+XuZyVWNN3V7guTjuecCcpGZlIljkScvgTNKq gXRf/cEG8jK6UBriUMawh2HO4o1duPl7EX8n3tziCZ1AW/O4JG88KyqEq0/0/LI0s726 RONE7scwMyMfJRz2HeX8sAXoEz0uF7FNTROYcZwqGYdSTosSCeqzac9UEJ68qJksNl6C otCwWFghSx/MNg8OZvqBrxtH+6FZvZumC/S0mLp0YcIGaSuxJ4SOlg6RUvId9CE+p9DD pmDw== 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=BIcnpcaN/mY8ENBlVtcNMfqugFzFKDu5N+5HdWJLzRA=; fh=9AYDxpIF3ws21qQDvjghHSFUuXpDdpq2Zh/SbnasVRo=; b=OahdV4YW3hQnyPrhuOA75XjoGPf/t8wrkzFz0M80eIg6NySduNK8FV3vDehbGMS8og ZZBteon2YcaOPfwxwcZN5eMTg4bRNAlnf+D3c2HVkfZn7/CxMwfWE7VAZzEE+6qJKYya v97xLAzZhqFGnz1mW1c/UzJYgC4fx5DxZ9/LXnvHTEcj0bpDhmYDuZX+e4LgLkKQXkgd s3CqRpo+9ItX6KBMEq56G6DpyJzDlHQTLT4Y9GvuNWifvrh5EZCdsqMtL0tS37b2MI8v XxU/cyfrJclqy9TRkIuIcLzKK+zscdrew/uwFXtGGMhroaQs/eML5JSgZ1/gvcDY3X8n mOcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cw9SWUL6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80343-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80343-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h13-20020a170902680d00b001dc5e90b4f5si2668098plk.592.2024.02.25.14.58.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:58:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80343-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=@kernel.org header.s=k20201202 header.b=cw9SWUL6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80343-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80343-ouuuleilei=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 2D45BB20F2D for ; Sun, 25 Feb 2024 22:58:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33C244E1C4; Sun, 25 Feb 2024 22:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cw9SWUL6" 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 734774D5A0 for ; Sun, 25 Feb 2024 22:55:48 +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=1708901748; cv=none; b=iDkVeZ9+7wOXfn5htAQJ0FyqVPpDI3cxVWre7TTFp6OSBJxTaG859K5dLFIoG5NK3aiFT+p10n+2icgd0rif4pk5MyNovtQzCpy6PcjrQ3HnGNpZ92b6deyNBghrgU59hW+gdNhBED4vDpAAMfWH/S4vky6UNcUlhlOGBQb1Ry0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901748; c=relaxed/simple; bh=0ATute8e6VvAt1imtugny66nHYVAoAroOYlbqbrp6NU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VxScetmMguGjvpK9X/qYoyZAKdnf1tGgqfWz18luJRpTLcmr9BC87ehPtH4JaQii4KOwcSO65XhyHwhI6jNW9sw0+DU69RQXhx+lCsD9zVSBaEiF3qV5JE81RXB1O1BjWlYlpOLld+iWrv3MkmjwgQHu8Rq5c4iz8wc6QRux9Bc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cw9SWUL6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3464C433C7; Sun, 25 Feb 2024 22:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901748; bh=0ATute8e6VvAt1imtugny66nHYVAoAroOYlbqbrp6NU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cw9SWUL6v04yVpISlBEFC9hi2sYD4jXHK2xhyoCpkpTQRnH6PeLXCklz1EHkjIWnF A4ponYwyRyvgHO6QC6mNhM8Q9dYaG7Y5IIy8S/ONqx1ZRfMTgZ/lsY20XuwtxwmEJ2 APKhijkKfHuKi9v5wdx2UEJJ0pcQPVrM6wI7vAWpWUodHhEhqd7hwJeZhX43lS8Nvw kjAUkPsPo6pv1gu/4oX+YEBudLrQXxjAJAg5SIpVJErUW7Cgq3kVHSsqi0wmgmlw8c f3HAbhIhyxsN2KhsHhPQvv+BTGqn7GOaNK38kLt8IUJG9k6O8HLU5Ko9GGMctZBSwE XJw7x/bECQ5tQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 16/16] timers: Assert no next dyntick timer look-up while CPU is offline Date: Sun, 25 Feb 2024 23:55:08 +0100 Message-ID: <20240225225508.11587-17-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913553784527599 X-GMAIL-MSGID: 1791913553784527599 The next timer (re-)evaluation, with the purpose of entering/updating the dyntick mode, can happen from 3 sites and none of them are relevant while the CPU is offline: 1) The idle loop: a) From the quick check helping the cpuidle governor to heuristically predict the best C-state. b) While stopping the tick. But if the CPU is offline, the tick has been cancelled and there is consequently no need to further stop the tick. 2) Remote expiry: when a CPU remotely expires global timers on behalf of another CPU, the latter target's next timer is re-evaluated afterwards. However remote expĂ®ry doesn't happen on offline CPUs. 3) IRQ exit: on nohz_full mode, the tick is (re-)evaluated on IRQ exit. But full dynticks is disabled on offline CPUs. Therefore it is safe to assume that no next dyntick timer lookup can be performed on offline CPUs. Assert this expectation to report any surprise. Signed-off-by: Frederic Weisbecker --- kernel/time/timer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 4f4930da6448..e69e75d3858c 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -2233,10 +2233,10 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, bool idle_is_possible; /* - * Pretend that there is no timer pending if the cpu is offline. - * Possible pending timers will be migrated later to an active cpu. + * When the CPU is offline, the tick is cancelled and nothing is supposed + * to try to stop it. */ - if (cpu_is_offline(smp_processor_id())) { + if (WARN_ON_ONCE(cpu_is_offline(smp_processor_id()))) { if (idle) *idle = true; return tevt.local;