Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1977060rdb; Wed, 31 Jan 2024 15:32:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGR6Ka9PCoQ6E9fFT4q1ZXNOZIrP0HA3T+KHTYKcS8cIwrVTT2rluChfpFIYFS+vftAwXu/ X-Received: by 2002:a17:906:e0cd:b0:a35:3bed:6cb4 with SMTP id gl13-20020a170906e0cd00b00a353bed6cb4mr2023212ejb.66.1706743927661; Wed, 31 Jan 2024 15:32:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706743927; cv=pass; d=google.com; s=arc-20160816; b=cnzMMf4OagAXbSH/Rj3oa7ms1QlfKKtXixq0jMj24vJc0WeDYZmKnYq7CMZStEWphW njrAodzpwgiWOjGCpBtyM3d283GCASa3rUV9drW3r9GRwIIeK5M9/tH6yt7vcRN7f1Uv S20+UnOMd7fAud9jKHBjjldDZsoRqGcrha4m5C68sCV1iwso6BdEYmZ5iI4m3b2ojzdB il5C3vZDx9m+BouGGyWSztCkuRg961R87x1HW4OvlkYIUlXdDrMCUBbOfotgPtdqByXD heOtUV9/mBbIlKxnokAw8rZrh/GPY39DUX9TbkATRzU0SoSRwaXyXZYnbdBzjIse4Q/m wmzA== 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=nxSR2BczxCCa3uv0qTI3Je1VkKszE9x/yANuRI8FHgw=; fh=6phQehKiSXmY3tEqefTX8thTFYT6l6EKyU3I6Iy3yVI=; b=QpvT1r/E8aQskyeoDXoBQ8mSMMmuhygtc8TEyp5+5RxiKmBnsOLpauboRr/qy+owt/ eJ9tNagHsk0HuxIMvAXirAw3dakB4GQJwEHcL4zbGZcWqJhtK2BH+ADQjinRMXGSBh+t mH3RqghNLA8ZH+1poAuPvKr+iINNKlnzfbSkBEzCcVMMA6Pv9J/kYY5bJKOpllmi/cSw NTX7kQxpUBV0OGneCHeVad146Ny2FMjZ4PfxDp4spUzuC+APtwEabe5m3WPlL8MO6v29 pFzZc1+5s1De5PKkiOxDvzZdJ0x72IclFV1vJ1peWqjqXf+Un75W9qvNfOGFZBoAgztF 19EQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fBTfiSUM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47359-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47359-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWDP8RMiOY14QPOGgbwHQdtMu1WRUm9TRq7u792Mw0J/L93TcA09FEp0EAJurNB3t6iaTtnczTrgGi1+7Da3/cX1qGBtwt9o3mwWO4faw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id oq27-20020a170906cc9b00b00a30fe086fc1si5658713ejb.1029.2024.01.31.15.32.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 15:32:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47359-linux.lists.archive=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=fBTfiSUM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47359-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47359-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F1DA31F27289 for ; Wed, 31 Jan 2024 23:31:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9072F13AA4F; Wed, 31 Jan 2024 23:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fBTfiSUM" 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 B2C7813A25F for ; Wed, 31 Jan 2024 23:12:00 +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=1706742720; cv=none; b=dOyAFKmDHTTQP4d7idGOZHesCfPbC6WHWS9Whle1KOJki9Y7DNCz8DAFuNl+TuosqdXn+aqiA+IjOnVXPvL7/FVTR9NpGCh8WvkcU+af4hvVxARzeKQo8Qf9bEktJFSctlC1Gt6GuQErzJxj6ud45BfNRwCBCG+cfula19cDe/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706742720; c=relaxed/simple; bh=u2P1r5FEYqsMg24uO7pS2JZU0ctu1FvUTqkt+nPckno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h10O9MJ5Wzr7T+yIIapIIviC5zJRxo32EZ1hx5y1Ih1Zmm1sGWAzuJY2UMeHFRWpR4FAnN7lLgW9EbQiqbez6jVVZ8CG0mzaBFx+FK+JsWN7ASfuXhpeU2F4e+PLG3yTez/qT+zUtdKbRiEdtrl/V8uPrkLW40iDcO+rF7Tqii4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fBTfiSUM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C88DAC433A6; Wed, 31 Jan 2024 23:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706742720; bh=u2P1r5FEYqsMg24uO7pS2JZU0ctu1FvUTqkt+nPckno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fBTfiSUMVYOYZ/98kxN4SU48/pwvj2neLluIuuDRY7aLiJ2KIiovzLWi6+aJ5bhJc 95KL2r+0LZw8e914CEY7qxy9oXioveIxzbRlVGMX5Npq0yaQJ3DjKUJrnAxaIGq2M1 bmUkzXdxcRG1aFHUWvTwl1BJlBN160jRIJfqyPCyVVMAsOLmJsYKqbIAW98K7vLxnO zoj8micYhI9ER/BeI4IqxO3mPADK0yP8XYXsoCp7ncMmtvXLMfisdi23KLewQpi85g Lzs/+JkfrJBoKqhr6yg5GniHWyupM5aI0Fb5zdzGoNBV7+eztPu8GVuY8WfGd9CLR6 MSbEsjA1ahb0w== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Peng Liu , Joel Fernandes Subject: [PATCH 15/15] tick: Assume timekeeping is correctly handed over upon last offline idle call Date: Thu, 1 Feb 2024 00:11:20 +0100 Message-ID: <20240131231120.12006-16-frederic@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131231120.12006-1-frederic@kernel.org> References: <20240131231120.12006-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 cb8e4a171288..0dcd1c0e0a4e 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1117,18 +1117,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; -- 2.43.0