From: Nicholas Piggin <npiggin@gmail.com> To: Thomas Gleixner <tglx@linutronix.de> Cc: "Nicholas Piggin" <npiggin@gmail.com>, "Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>, "Zhouyi Zhou" <zhouzhouyi@gmail.com>, "Frederic Weisbecker" <fweisbec@gmail.com>, "Ingo Molnar" <mingo@kernel.org>, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "Viresh Kumar" <viresh.kumar@linaro.org>, "Paul E . McKenney" <paulmck@kernel.org>, "Michael Ellerman" <mpe@ellerman.id.au>, "Michal Suchánek" <msuchanek@suse.de> Subject: [PATCH] timers/nohz: Low-res tick handler switch to ONESHOT_STOPPED if tick stops Date: Sat, 23 Apr 2022 00:14:46 +1000 [thread overview] Message-ID: <20220422141446.915024-1-npiggin@gmail.com> (raw) When tick_nohz_stop_tick() stops the tick, the the clock event device is not put into ONESHOT_STOPPED mode. This can lead to spurious timer interrupts with some clock event device drivers that don't shut down entirely after firing. Eliminate these by putting the device into ONESHOT_STOPPED mode at points where it is not being reprogrammed. When there are no timers active, then tick_program_event() with KTIME_MAX can be used to stop the device. When there is a timer active, the device can be stopped at the next tick (any new timer added by timers will reprogram the tick). Signed-off-by: Nicholas Piggin <npiggin@gmail.com> --- kernel/time/tick-sched.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index d257721c68b8..da1a7efa45a4 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -928,6 +928,8 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) if (unlikely(expires == KTIME_MAX)) { if (ts->nohz_mode == NOHZ_MODE_HIGHRES) hrtimer_cancel(&ts->sched_timer); + else + tick_program_event(KTIME_MAX, 1); return; } @@ -1364,9 +1366,14 @@ static void tick_nohz_handler(struct clock_event_device *dev) tick_sched_do_timer(ts, now); tick_sched_handle(ts, regs); - /* No need to reprogram if we are running tickless */ - if (unlikely(ts->tick_stopped)) + if (unlikely(ts->tick_stopped)) { + /* + * If we are tickless, no need to reprogram, so change the + * clock event device to ONESHOT_STOPPED. + */ + tick_program_event(KTIME_MAX, 1); return; + } hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); -- 2.35.1
WARNING: multiple messages have this Message-ID (diff)
From: Nicholas Piggin <npiggin@gmail.com> To: Thomas Gleixner <tglx@linutronix.de> Cc: "Paul E . McKenney" <paulmck@kernel.org>, "Frederic Weisbecker" <fweisbec@gmail.com>, linux-kernel@vger.kernel.org, "Nicholas Piggin" <npiggin@gmail.com>, "Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>, "Viresh Kumar" <viresh.kumar@linaro.org>, "Zhouyi Zhou" <zhouzhouyi@gmail.com>, "Michal Suchánek" <msuchanek@suse.de>, linuxppc-dev@lists.ozlabs.org, "Ingo Molnar" <mingo@kernel.org> Subject: [PATCH] timers/nohz: Low-res tick handler switch to ONESHOT_STOPPED if tick stops Date: Sat, 23 Apr 2022 00:14:46 +1000 [thread overview] Message-ID: <20220422141446.915024-1-npiggin@gmail.com> (raw) When tick_nohz_stop_tick() stops the tick, the the clock event device is not put into ONESHOT_STOPPED mode. This can lead to spurious timer interrupts with some clock event device drivers that don't shut down entirely after firing. Eliminate these by putting the device into ONESHOT_STOPPED mode at points where it is not being reprogrammed. When there are no timers active, then tick_program_event() with KTIME_MAX can be used to stop the device. When there is a timer active, the device can be stopped at the next tick (any new timer added by timers will reprogram the tick). Signed-off-by: Nicholas Piggin <npiggin@gmail.com> --- kernel/time/tick-sched.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index d257721c68b8..da1a7efa45a4 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -928,6 +928,8 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) if (unlikely(expires == KTIME_MAX)) { if (ts->nohz_mode == NOHZ_MODE_HIGHRES) hrtimer_cancel(&ts->sched_timer); + else + tick_program_event(KTIME_MAX, 1); return; } @@ -1364,9 +1366,14 @@ static void tick_nohz_handler(struct clock_event_device *dev) tick_sched_do_timer(ts, now); tick_sched_handle(ts, regs); - /* No need to reprogram if we are running tickless */ - if (unlikely(ts->tick_stopped)) + if (unlikely(ts->tick_stopped)) { + /* + * If we are tickless, no need to reprogram, so change the + * clock event device to ONESHOT_STOPPED. + */ + tick_program_event(KTIME_MAX, 1); return; + } hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); -- 2.35.1
next reply other threads:[~2022-04-22 14:15 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-22 14:14 Nicholas Piggin [this message] 2022-04-22 14:14 ` [PATCH] timers/nohz: Low-res tick handler switch to ONESHOT_STOPPED if tick stops Nicholas Piggin 2022-04-25 12:50 ` [tip: timers/core] timers/nohz: Switch to ONESHOT_STOPPED in the low-res handler when the tick is stopped tip-bot2 for Nicholas Piggin 2023-05-03 16:36 ` Frederic Weisbecker
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220422141446.915024-1-npiggin@gmail.com \ --to=npiggin@gmail.com \ --cc=fweisbec@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linuxppc-dev@lists.ozlabs.org \ --cc=miguel.ojeda.sandonis@gmail.com \ --cc=mingo@kernel.org \ --cc=mpe@ellerman.id.au \ --cc=msuchanek@suse.de \ --cc=paulmck@kernel.org \ --cc=tglx@linutronix.de \ --cc=viresh.kumar@linaro.org \ --cc=zhouzhouyi@gmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.