All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Peng Liu <liupeng17@lenovo.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Joel Fernandes <joel@joelfernandes.org>,
	Frederic Weisbecker <frederic@kernel.org>
Subject: [PATCH 02/16] tick/nohz: Remove duplicate between lowres and highres handlers
Date: Sun, 25 Feb 2024 23:54:54 +0100	[thread overview]
Message-ID: <20240225225508.11587-3-frederic@kernel.org> (raw)
In-Reply-To: <20240225225508.11587-1-frederic@kernel.org>

From: Peng Liu <liupeng17@lenovo.com>

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 <liupeng17@lenovo.com>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
---
 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());
-- 
2.43.0


  parent reply	other threads:[~2024-02-25 22:55 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-25 22:54 [PATCH 00/16 v3] timers/nohz cleanups and hotplug reorganization Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 01/16] tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer() Frederic Weisbecker
2024-02-26  8:14   ` Thomas Gleixner
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Peng Liu
2024-02-25 22:54 ` Frederic Weisbecker [this message]
2024-02-26  8:15   ` [PATCH 02/16] tick/nohz: Remove duplicate between lowres and highres handlers Thomas Gleixner
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Peng Liu
2024-02-25 22:54 ` [PATCH 03/16] tick: Remove useless oneshot ifdeffery Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] tick/sched: " tip-bot2 for Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 04/16] tick: Use IS_ENABLED() whenever possible Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 05/16] tick: s/tick_nohz_stop_sched_tick/tick_nohz_full_stop_tick Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] tick/sched: Rename tick_nohz_stop_sched_tick() to tick_nohz_full_stop_tick() tip-bot2 for Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 06/16] tick: No need to clear ts->next_tick again Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] tick/sched: Don't clear ts::next_tick again in can_stop_idle_tick() tip-bot2 for Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 07/16] tick: Start centralizing tick related CPU hotplug operations Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 08/16] tick: Move tick cancellation up to CPUHP_AP_TICK_DYING Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 09/16] tick: Move broadcast " Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 10/16] tick: Assume the tick can't be stopped in NOHZ_MODE_INACTIVE mode Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 11/16] tick: Move got_idle_tick away from common flags Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 12/16] tick: Move individual bit features to debuggable mask accesses Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 13/16] tick: Split nohz and highres features from nohz_mode Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 14/16] tick: Shut down low-res tick from dying CPU Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 15/16] tick: Assume timekeeping is correctly handed over upon last offline idle call Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 16/16] timers: Assert no next dyntick timer look-up while CPU is offline Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for 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=20240225225508.11587-3-frederic@kernel.org \
    --to=frederic@kernel.org \
    --cc=anna-maria@linutronix.de \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liupeng17@lenovo.com \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /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: link
Be 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.