From nobody Tue Dec 16 02:24:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D81DBCA0ECA for ; Tue, 12 Sep 2023 10:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234311AbjILKpC (ORCPT ); Tue, 12 Sep 2023 06:45:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234213AbjILKos (ORCPT ); Tue, 12 Sep 2023 06:44:48 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 813E31719 for ; Tue, 12 Sep 2023 03:44:17 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3BD4C433C9; Tue, 12 Sep 2023 10:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694515457; bh=DfGb/oQJpcnc2u0v4QarnLBwZAczc4rgBDguNVZFTUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KXoO/Z54oTmdIbTn/COSHP50p6mFZ74ZsOEqTt/SgXMpYrv3qZJ+G2IcSoTrR9coG mbmlKCu2Lzzlj/V4fPzzEHS9iYkvDULa0ns+igEzbqmMdjj5klRN073QGxcvOwHWOh I0vcGz3UPmCm0UUXthSuJbWp+cXNm8vMFnspmBTUPCl6GQHy41pDiyICuy3x8vrPEr b7l/WsrfaqHoSq27xeAcCEFiqmqV1tKDUFyZLuGFr/NbAdjcucEXwFzU5+82kBLkpW Cb5b8iENoRh5G5BGFiC1MbN9Luc2fH0P55qGAF4y4BN4LspvGC+Fnln1xAdUii8dcv VG2c5HucFP7lw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Joel Fernandes , Thomas Gleixner , vineethrp@gmail.com Subject: [PATCH 1/5] tick/nohz: Rename the tick handlers to more self-explanatory names Date: Tue, 12 Sep 2023 12:44:02 +0200 Message-Id: <20230912104406.312185-2-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912104406.312185-1-frederic@kernel.org> References: <20230912104406.312185-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The current name of the tick handlers don't tell much about what differ between them. Use names that better reflect their role and resolution. Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 87015e9deacc..b66dd0ff1153 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1366,7 +1366,7 @@ void tick_nohz_idle_exit(void) /* * The nohz low res interrupt handler */ -static void tick_nohz_handler(struct clock_event_device *dev) +static void tick_nohz_lowres_handler(struct clock_event_device *dev) { struct tick_sched *ts =3D this_cpu_ptr(&tick_cpu_sched); struct pt_regs *regs =3D get_irq_regs(); @@ -1412,7 +1412,7 @@ static void tick_nohz_switch_to_nohz(void) if (!tick_nohz_enabled) return; =20 - if (tick_switch_to_oneshot(tick_nohz_handler)) + if (tick_switch_to_oneshot(tick_nohz_lowres_handler)) return; =20 /* @@ -1475,7 +1475,7 @@ void tick_irq_enter(void) * We rearm the timer until we get disabled by the idle code. * Called with interrupts disabled. */ -static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer) +static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *time= r) { struct tick_sched *ts =3D container_of(timer, struct tick_sched, sched_timer); @@ -1524,7 +1524,7 @@ void tick_setup_sched_timer(void) * Emulate tick processing via per-CPU hrtimers: */ hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); - ts->sched_timer.function =3D tick_sched_timer; + ts->sched_timer.function =3D tick_nohz_highres_handler; =20 /* Get the next period (per-CPU) */ hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); --=20 2.34.1 From nobody Tue Dec 16 02:24:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6B44CA0EC3 for ; Tue, 12 Sep 2023 10:45:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234221AbjILKpX (ORCPT ); Tue, 12 Sep 2023 06:45:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234412AbjILKov (ORCPT ); Tue, 12 Sep 2023 06:44:51 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3621E1723 for ; Tue, 12 Sep 2023 03:44:19 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B6DDC433C7; Tue, 12 Sep 2023 10:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694515458; bh=VCFbnQWF4lBKNsyVMLqdG0QZaSmJF0XJv43q7YI+WJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ij0CYZgaVcSp8NNMGm/8zBEDL0iwV2PKmBd1Nm5k3o6P+Qp2yBJ98gBJSnUMfe9nb IflZHmMYS+fwdXrzegZVbXuI6GQrB2I4JL5Xmdx+wOlS7AR5HJCWHAuWM4bCbrrWqi 02ZQa72WsGXDf9LUvHsU8c+M/1+1WryFlODfmXHVHCOkJ+RXj5v3EH1FRDgJvkliYq q8ZLvYU+gbFuaVnioZnoiLTBklfsQdkbENaNEs5cEw5Bci7FoM58SXmigmJjR5LRgI tMDPLfpiTdWgqPWqvuGih3IHvGRHV4civS8KaQ3ooUdCegwF6guIvM+5X45PvJWRzZ HumGu/L4k3BRA== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Joel Fernandes , Thomas Gleixner , vineethrp@gmail.com Subject: [PATCH 2/5] tick/nohz: Update obsolete comments Date: Tue, 12 Sep 2023 12:44:03 +0200 Message-Id: <20230912104406.312185-3-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912104406.312185-1-frederic@kernel.org> References: <20230912104406.312185-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some comments are obsolete enough to assume that IRQ exit restarts the tick in idle or RCU is turned on at the same time as the tick, among other details. Update them and add more. Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 46 +++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index b66dd0ff1153..95a8d1d118a2 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1175,12 +1175,23 @@ void tick_nohz_idle_enter(void) } =20 /** - * tick_nohz_irq_exit - update next tick event from interrupt exit + * tick_nohz_irq_exit - Notify the tick about IRQ exit * - * When an interrupt fires while we are idle and it doesn't cause - * a reschedule, it may still add, modify or delete a timer, enqueue - * an RCU callback, etc... - * So we need to re-calculate and reprogram the next tick event. + * A timer may have been added/modified/deleted either by the current IRQ, + * or by another place using this IRQ as a notification. This IRQ may have + * also updated the RCU callback list. These events may require a + * re-evaluation of the next tick. Depending on the context: + * + * 1) If the CPU is idle and no resched is pending, just proceed with idle + * time accounting. The next tick will be re-evaluated on the next idle + * loop iteration. + * + * 2) If the CPU is nohz_full: + * + * 2.1) If there is any tick dependency, restart the tick if stopped. + * + * 2.2) If there is no tick dependency, (re-)evaluate the next tick and + * stop/update it accordingly. */ void tick_nohz_irq_exit(void) { @@ -1330,11 +1341,20 @@ static void tick_nohz_idle_update_tick(struct tick_= sched *ts, ktime_t now) } =20 /** - * tick_nohz_idle_exit - restart the idle tick from the idle task + * tick_nohz_idle_exit - Update the tick upon idle task exit + * + * When the idle task exits, update the tick depending on the + * following situations: + * + * 1) If the CPU is not in nohz_full mode (most cases), then + * restart the tick. + * + * 2) If the CPU is in nohz_full mode (corner case): + * 2.1) If the tick can be kept stopped (no tick dependencies) + * then re-eavaluate the next tick and try to keep it stopped + * as long as possible. + * 2.2) If the tick has dependencies, restart the tick. * - * Restart the idle tick when the CPU is woken up from idle - * This also exit the RCU extended quiescent state. The CPU - * can use RCU again after this function is called. */ void tick_nohz_idle_exit(void) { @@ -1364,7 +1384,13 @@ void tick_nohz_idle_exit(void) } =20 /* - * The nohz low res interrupt handler + * In low-resolution mode, the tick handler must be implemented directly + * 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 meanwh= ile + * for commodity with expiration calculation and forwarding. */ static void tick_nohz_lowres_handler(struct clock_event_device *dev) { --=20 2.34.1 From nobody Tue Dec 16 02:24:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94511CA0ECF for ; Tue, 12 Sep 2023 10:45:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231560AbjILKpd (ORCPT ); Tue, 12 Sep 2023 06:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234453AbjILKov (ORCPT ); Tue, 12 Sep 2023 06:44:51 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CCC4172E for ; Tue, 12 Sep 2023 03:44:21 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52499C433C8; Tue, 12 Sep 2023 10:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694515460; bh=8IMEGNQxJUVrw2F/l3GmN1Ldd+1Byg1w8yqybgZALh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tEbvCx9uyF/x3U3frcNYdc0orFnxJFUZf6M65+NQ6QlTsM0zyiPtq33dJaI5zvgYq 3cA/hKUI7sBb8mYwLRFR2XMCSZ7+msxco0rRRkt9b8A2/xU1sr13E23dZC4zrut+xK HO0U+BjZqCW6XqlrCfWeLWcIWM0M1tsVMSpX/ziQumN3H7OGFjs++AR3BZLop5vWHG wI9Z/EeoOlPuw8p2fY95zQR0K0MATtZL3ca6JP9GqZ1+9RSR6lfpoSeUdeZD0PowRe vjbZz3TzGJZIPgeGezEFrQc9an1xqTqUf35Q5mhoz84fTZqWm07At91+Ksyh/JdwQf Il+4zUKLz0v1w== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Joel Fernandes , Thomas Gleixner , vineethrp@gmail.com, Nicholas Piggin Subject: [PATCH 3/5] tick/nohz: Don't shutdown the lowres tick from itself Date: Tue, 12 Sep 2023 12:44:04 +0200 Message-Id: <20230912104406.312185-4-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912104406.312185-1-frederic@kernel.org> References: <20230912104406.312185-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In lowres dynticks mode, just like in highres dynticks mode, when there is no tick to program in the future, the tick eventually gets deactivated either: * From the idle loop if in idle mode. * From the IRQ exit if in full dynticks mode. Therefore there is no need to deactivate it from the tick itself. This just just brings more overhead in the idle tick path for no reason. Fixes: 62c1256d5447 ("timers/nohz: Switch to ONESHOT_STOPPED in the low-res= handler when the tick is stopped") Signed-off-by: Frederic Weisbecker Reviewed-by: Joel Fernandes (Google) --- kernel/time/tick-sched.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 95a8d1d118a2..8e9a9dcf60d5 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1403,18 +1403,16 @@ static void tick_nohz_lowres_handler(struct clock_e= vent_device *dev) tick_sched_do_timer(ts, now); tick_sched_handle(ts, regs); =20 - if (unlikely(ts->tick_stopped)) { - /* - * The clockevent device is not reprogrammed, so change the - * clock event device to ONESHOT_STOPPED to avoid spurious - * interrupts on devices which might not be truly one shot. - */ - tick_program_event(KTIME_MAX, 1); - return; + /* + * 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); + tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); } =20 - hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); - tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); } =20 static inline void tick_nohz_activate(struct tick_sched *ts, int mode) @@ -1519,7 +1517,11 @@ static enum hrtimer_restart tick_nohz_highres_handle= r(struct hrtimer *timer) else ts->next_tick =3D 0; =20 - /* No need to reprogram if we are in idle or full dynticks mode */ + /* + * 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; =20 --=20 2.34.1 From nobody Tue Dec 16 02:24:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDEC3CA0ECA for ; Tue, 12 Sep 2023 10:45:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234449AbjILKpr (ORCPT ); Tue, 12 Sep 2023 06:45:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234478AbjILKox (ORCPT ); Tue, 12 Sep 2023 06:44:53 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 520A11982 for ; Tue, 12 Sep 2023 03:44:23 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36007C433C7; Tue, 12 Sep 2023 10:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694515462; bh=wNRp0lSuxwMF/JBQ5Mv5SUmlz7jkA1SazJ3u0SEnyQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mRiMFQ3TZg0b5e2/UXpeqpL962IQg/Dw5AKU6Z6/L9QPyYyo5R/qFsbM+dIFQKsCT ctbs2cJujr/63bxzP1T1GNjK0rVUGAkCoWGd00x1CzZK2R+YISC8hZXIBqlh7AIRMm voH1VupgLpwxumQEJPwbP9D0FMv9hOLHM4E9o70nPc4T8sbucC6iyRV8ERv+Uus/tJ 8jNVqm1tm/q52P/qzjGJMi8+US5jZ+7Pseb0ol1SmDb3qEb/j3GaBJOfJQu913qb/0 2j4m74AB9JhG3BGCXZ/wbs88J4wdIgVx2H9UlBNYD5mqTpEF43sjB2ow3cOFbSjR1q JCY7cTnrD5Pwg== From: Frederic Weisbecker To: LKML Cc: Xueshi Hu , Frederic Weisbecker , Joel Fernandes , Thomas Gleixner , vineethrp@gmail.com Subject: [PATCH 4/5] tick/nohz: remove unused tick_nohz_idle_stop_tick_protected() Date: Tue, 12 Sep 2023 12:44:05 +0200 Message-Id: <20230912104406.312185-5-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912104406.312185-1-frederic@kernel.org> References: <20230912104406.312185-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xueshi Hu All the caller has been removed since commit 336f560a8917 ("x86/xen: don't let xen_pv_play_dead() return") Signed-off-by: Xueshi Hu Signed-off-by: Frederic Weisbecker --- include/linux/tick.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/include/linux/tick.h b/include/linux/tick.h index 9459fef5b857..716d17f31c45 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -140,14 +140,6 @@ extern unsigned long tick_nohz_get_idle_calls(void); extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu); extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); - -static inline void tick_nohz_idle_stop_tick_protected(void) -{ - local_irq_disable(); - tick_nohz_idle_stop_tick(); - local_irq_enable(); -} - #else /* !CONFIG_NO_HZ_COMMON */ #define tick_nohz_enabled (0) static inline int tick_nohz_tick_stopped(void) { return 0; } @@ -170,8 +162,6 @@ static inline ktime_t tick_nohz_get_sleep_length(ktime_= t *delta_next) } static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1= ; } - -static inline void tick_nohz_idle_stop_tick_protected(void) { } #endif /* !CONFIG_NO_HZ_COMMON */ =20 #ifdef CONFIG_NO_HZ_FULL --=20 2.34.1 From nobody Tue Dec 16 02:24:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 139D7CA0ECA for ; Tue, 12 Sep 2023 10:45:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234478AbjILKp4 (ORCPT ); Tue, 12 Sep 2023 06:45:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234493AbjILKoy (ORCPT ); Tue, 12 Sep 2023 06:44:54 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8DC51987 for ; Tue, 12 Sep 2023 03:44:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19AB6C433C8; Tue, 12 Sep 2023 10:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694515464; bh=1xq6Mgf32EY2JQOJHQcEgJ3L7Kjn6lb+CzCCKEAz46M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HVplCqOXjJormHSlR2bAyrpRlkyfPFfJEe2vJuJn5mL6+u6rPaN61klmUFrLzRuSe 5Sa1L92QTSATpU1dj8EkdTWjGsnj/WWzmhP8KOGqMIUfVIkFeEKWjk8b2tG0zjp/b9 xqtgWfjjpOwTfTEbUOLbrKRWtRUcX4PIqv58T7E96oZUUX8ILH8QB9nm8VGAt+Rdkp 6IWYMbPSlcWUa/MQkDUqeFHp0NISKywyiGYeDJfCXZnVJzCE82s8FW3NxJre0QFigG rpIRrVXQIh+eEOB++P+ea8VLh8U/vXk81EPR4mlUeCvn5KRm114kdG83D0MpdSGNOL ok5tAtzcqTA7g== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Joel Fernandes , Thomas Gleixner , vineethrp@gmail.com Subject: [PATCH 5/5] timers: Tag (hr)timer softirq as hotplug safe Date: Tue, 12 Sep 2023 12:44:06 +0200 Message-Id: <20230912104406.312185-6-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912104406.312185-1-frederic@kernel.org> References: <20230912104406.312185-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Specific stress involving frequent CPU-hotplug operations, such as running rcutorture for example, may trigger the following message: "NOHZ tick-stop error: local softirq work is pending, handler #02!!!" This happens in the CPU-down hotplug process, after CPUHP_AP_SMPBOOT_THREADS whose teardown callback parks ksoftirqd, and before the target CPU shuts down through CPUHP_AP_IDLE_DEAD. In this fragile intermediate state, softirqs waiting for threaded handling may be forever ignored and eventually reported by the idle task as in the above example. However some vectors are known to be safe as long as the corresponding subsystems have teardown callbacks handling the migration of their events. The above error message reports pending timers softirq although this vector can be considered as hotplug safe because the CPUHP_TIMERS_PREPARE teardown callback performs the necessary migration of timers after the death of the CPU. Hrtimers also have a similar hotplug handling. Therefore this error message, as far as (hr-)timers are concerned, can be considered spurious and the relevant softirq vectors can be marked as hotplug safe. Signed-off-by: Frederic Weisbecker Reviewed-by: Joel Fernandes (Google) --- include/linux/interrupt.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index a92bce40b04b..4a1dc88ddbff 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -569,8 +569,12 @@ enum * 2) rcu_report_dead() reports the final quiescent states. * * _ IRQ_POLL: irq_poll_cpu_dead() migrates the queue + * + * _ (HR)TIMER_SOFTIRQ: (hr)timers_dead_cpu() migrates the queue */ -#define SOFTIRQ_HOTPLUG_SAFE_MASK (BIT(RCU_SOFTIRQ) | BIT(IRQ_POLL_SOFTIRQ= )) +#define SOFTIRQ_HOTPLUG_SAFE_MASK (BIT(TIMER_SOFTIRQ) | BIT(IRQ_POLL_SOFTI= RQ) |\ + BIT(HRTIMER_SOFTIRQ) | BIT(RCU_SOFTIRQ)) + =20 /* map softirq index to softirq name. update 'softirq_to_name' in * kernel/softirq.c when adding a new softirq. --=20 2.34.1