mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 2/2] tick/nohz: Remove duplicate between tick_nohz_lowres_handler() and tick_nohz_highres_handler()
       [not found] <20231127083118.145704-1-pngliu@hotmail.com>
@ 2023-11-28  9:24 ` Peng Liu
  2023-11-28 21:39   ` Frederic Weisbecker
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Liu @ 2023-11-28  9:24 UTC (permalink / raw)
  Cc: frederic, tglx, mingo, linux-kernel, liupeng17

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 should reuse the latter.

Signed-off-by: Peng Liu <liupeng17@lenovo.com>
---
Changes in v2:
- Fix build warning: Function parameter or member 'mode' not described in 'tick_setup_sched_timer'
- Fix build error: use of undeclared identifier 'tick_nohz_highres_handler'
- Fix build error: use of undeclared identifier 'sched_skew_tick'
---
 kernel/time/tick-sched.c | 28 ++++++----------------------
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 96fcf5cb1b49..c2142b38c31d 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -1383,36 +1383,25 @@ void tick_nohz_idle_exit(void)
 	local_irq_enable();
 }
 
+static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer);
+
 /*
  * 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 meanwhile
- * for convenience with expiration calculation and forwarding.
+ * This low-resolution handler still reuse tick_nohz_highres_handler() since
+ * most of the work is independent of the clockevent level.
  */
 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_highres_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)
@@ -1481,10 +1470,7 @@ void tick_irq_enter(void)
 	tick_nohz_irq_enter();
 }
 
-/*
- * High resolution timer specific code
- */
-#ifdef CONFIG_HIGH_RES_TIMERS
+#if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
 /*
  * We rearm the timer until we get disabled by the idle code.
  * Called with interrupts disabled.
@@ -1519,9 +1505,7 @@ static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer)
 
 	return HRTIMER_RESTART;
 }
-#endif /* 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)
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 2/2] tick/nohz: Remove duplicate between tick_nohz_lowres_handler() and tick_nohz_highres_handler()
  2023-11-28  9:24 ` [PATCH v2 2/2] tick/nohz: Remove duplicate between tick_nohz_lowres_handler() and tick_nohz_highres_handler() Peng Liu
@ 2023-11-28 21:39   ` Frederic Weisbecker
  0 siblings, 0 replies; 2+ messages in thread
From: Frederic Weisbecker @ 2023-11-28 21:39 UTC (permalink / raw)
  To: Peng Liu; +Cc: tglx, mingo, linux-kernel, liupeng17

Le Tue, Nov 28, 2023 at 05:24:13PM +0800, Peng Liu a écrit :
> 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 should reuse the latter.
> 
> Signed-off-by: Peng Liu <liupeng17@lenovo.com>
> ---
> Changes in v2:
> - Fix build warning: Function parameter or member 'mode' not described in 'tick_setup_sched_timer'
> - Fix build error: use of undeclared identifier 'tick_nohz_highres_handler'
> - Fix build error: use of undeclared identifier 'sched_skew_tick'
> ---
>  kernel/time/tick-sched.c | 28 ++++++----------------------
>  1 file changed, 6 insertions(+), 22 deletions(-)
> 
> diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
> index 96fcf5cb1b49..c2142b38c31d 100644
> --- a/kernel/time/tick-sched.c
> +++ b/kernel/time/tick-sched.c
> @@ -1383,36 +1383,25 @@ void tick_nohz_idle_exit(void)
>  	local_irq_enable();
>  }
>  
> +static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer);

Then please move the entire function in this case. You'll need to move it to
a place where it is available both for CONFIG_NO_HZ_COMMON and
CONFIG_HIGH_RES_TIMERS. Below tick_sched_handle() for example.

Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-28 21:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20231127083118.145704-1-pngliu@hotmail.com>
2023-11-28  9:24 ` [PATCH v2 2/2] tick/nohz: Remove duplicate between tick_nohz_lowres_handler() and tick_nohz_highres_handler() Peng Liu
2023-11-28 21:39   ` Frederic Weisbecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®