linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] timers: Make the lower-level timer function first call than higher-level
@ 2018-11-19 14:10 Muchun Song
  2018-11-19 18:16 ` John Stultz
  0 siblings, 1 reply; 6+ messages in thread
From: Muchun Song @ 2018-11-19 14:10 UTC (permalink / raw)
  To: john.stultz, tglx, sboyd; +Cc: linux-kernel

The elements of the heads array are a linked list of timer events that
expire at the current time. And it can contain up to LVL_DEPTH levels
and the lower the level represents the smaller the time granularity.

Now the result is that the function, which will be called when the timer
expires, in the higher-level is called first than the lower-level function.
I think it might be better to call the lower-level timer function first
than the higher-level function. Because the lower-level has the smaller
granularity and delay has less impact on higher-level. So fix it.

Signed-off-by: Muchun Song <smuchun@gmail.com>
---
 kernel/time/timer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index fa49cd753dea..7c757b27aa58 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1674,12 +1674,13 @@ static inline void __run_timers(struct timer_base *base)
 	base->must_forward_clk = false;
 
 	while (time_after_eq(jiffies, base->clk)) {
+		int i;
 
 		levels = collect_expired_timers(base, heads);
 		base->clk++;
 
-		while (levels--)
-			expire_timers(base, heads + levels);
+		for (i = 0; i < levels; i++)
+			expire_timers(base, heads + i);
 	}
 	base->running_timer = NULL;
 	raw_spin_unlock_irq(&base->lock);
-- 
2.17.1


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

* Re: [PATCH] timers: Make the lower-level timer function first call than higher-level
  2018-11-19 14:10 [PATCH] timers: Make the lower-level timer function first call than higher-level Muchun Song
@ 2018-11-19 18:16 ` John Stultz
  2018-11-20  2:08   ` Muchun Song
  0 siblings, 1 reply; 6+ messages in thread
From: John Stultz @ 2018-11-19 18:16 UTC (permalink / raw)
  To: Muchun Song; +Cc: Thomas Gleixner, Stephen Boyd, lkml

On Mon, Nov 19, 2018 at 6:10 AM, Muchun Song <smuchun@gmail.com> wrote:
> The elements of the heads array are a linked list of timer events that
> expire at the current time. And it can contain up to LVL_DEPTH levels
> and the lower the level represents the smaller the time granularity.
>
> Now the result is that the function, which will be called when the timer
> expires, in the higher-level is called first than the lower-level function.
> I think it might be better to call the lower-level timer function first
> than the higher-level function. Because the lower-level has the smaller
> granularity and delay has less impact on higher-level. So fix it.

Interesting.

Do you have any specific examples of where this was helpful?  Maybe
data on how much this helped the case your concerned about?

thanks
-john

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

* Re: [PATCH] timers: Make the lower-level timer function first call than higher-level
  2018-11-19 18:16 ` John Stultz
@ 2018-11-20  2:08   ` Muchun Song
  2018-11-21 20:44     ` Thomas Gleixner
  0 siblings, 1 reply; 6+ messages in thread
From: Muchun Song @ 2018-11-20  2:08 UTC (permalink / raw)
  To: John Stultz; +Cc: tglx, sboyd, linux-kernel

Hi John,

Thanks for your review.

John Stultz <john.stultz@linaro.org> 于2018年11月20日周二 上午2:16写道:
>
> On Mon, Nov 19, 2018 at 6:10 AM, Muchun Song <smuchun@gmail.com> wrote:
> > The elements of the heads array are a linked list of timer events that
> > expire at the current time. And it can contain up to LVL_DEPTH levels
> > and the lower the level represents the smaller the time granularity.
> >
> > Now the result is that the function, which will be called when the timer
> > expires, in the higher-level is called first than the lower-level function.
> > I think it might be better to call the lower-level timer function first
> > than the higher-level function. Because the lower-level has the smaller
> > granularity and delay has less impact on higher-level. So fix it.
>
> Interesting.
>
> Do you have any specific examples of where this was helpful?  Maybe
> data on how much this helped the case your concerned about?
>

                     heads(with HZ > 100)
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |
+--+--+--+--+--+--+-----+-----+-----+-----+-----+-----+
   |     |     |
   |     |     |
   |     |     +--->timer4--->timer5
   |     +--->timer1--->timer2--->timer3
   +--->timer0

If we have 6 timers that expire at the current time. And the heads array
layout as shown above. The collect_expired_timers() will return 3. If timer0
belong to the first wheel level(level 0), timer1-3 belong to level 2 and
timer4-5 belong to level 5.

Follow the current code logic, the timer0 function is called until the
function call of timer1-5 is completed. So the delay of timer0 is the time
spent by other timer function calls. If we can call the timer function in
the following order, this should be more friendly to lower-level timers.

        timer0->timer1->->timer2->->timer3->->timer4->->timer5

Although not friendly to higher-level timers, higher-level has larger
granularity. Therefore the delay has less impact on higher-level.

Is it right?

Thanks.

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

* Re: [PATCH] timers: Make the lower-level timer function first call than higher-level
  2018-11-20  2:08   ` Muchun Song
@ 2018-11-21 20:44     ` Thomas Gleixner
  2018-11-28 15:15       ` Thomas Gleixner
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2018-11-21 20:44 UTC (permalink / raw)
  To: Muchun Song; +Cc: John Stultz, sboyd, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2276 bytes --]

Song,

On Tue, 20 Nov 2018, Muchun Song wrote:
> John Stultz <john.stultz@linaro.org> 于2018年11月20日周二 上午2:16写道:
> >
> > On Mon, Nov 19, 2018 at 6:10 AM, Muchun Song <smuchun@gmail.com> wrote:
> > > The elements of the heads array are a linked list of timer events that
> > > expire at the current time. And it can contain up to LVL_DEPTH levels
> > > and the lower the level represents the smaller the time granularity.
> > >
> > > Now the result is that the function, which will be called when the timer
> > > expires, in the higher-level is called first than the lower-level function.
> > > I think it might be better to call the lower-level timer function first
> > > than the higher-level function. Because the lower-level has the smaller
> > > granularity and delay has less impact on higher-level. So fix it.
> >
> > Interesting.
> >
> > Do you have any specific examples of where this was helpful?  Maybe
> > data on how much this helped the case your concerned about?
> >
> 
>                      heads(with HZ > 100)
> +-----+-----+-----+-----+-----+-----+-----+-----+-----+
> |  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |
> +--+--+--+--+--+--+-----+-----+-----+-----+-----+-----+
>    |     |     |
>    |     |     |
>    |     |     +--->timer4--->timer5
>    |     +--->timer1--->timer2--->timer3
>    +--->timer0
> 
> If we have 6 timers that expire at the current time. And the heads array
> layout as shown above. The collect_expired_timers() will return 3. If timer0
> belong to the first wheel level(level 0), timer1-3 belong to level 2 and
> timer4-5 belong to level 5.
> 
> Follow the current code logic, the timer0 function is called until the
> function call of timer1-5 is completed. So the delay of timer0 is the time
> spent by other timer function calls. If we can call the timer function in
> the following order, this should be more friendly to lower-level timers.
> 
>         timer0->timer1->->timer2->->timer3->->timer4->->timer5
> 
> Although not friendly to higher-level timers, higher-level has larger
> granularity. Therefore the delay has less impact on higher-level.

Well yes, that's clear. But is it a problem in practice and if so, what is
the measurable benefit.

Thanks,

	tglx

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

* Re: [PATCH] timers: Make the lower-level timer function first call than higher-level
  2018-11-21 20:44     ` Thomas Gleixner
@ 2018-11-28 15:15       ` Thomas Gleixner
  2018-11-28 16:51         ` Muchun Song
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2018-11-28 15:15 UTC (permalink / raw)
  To: Muchun Song; +Cc: John Stultz, sboyd, linux-kernel

Song,

On Wed, 21 Nov 2018, Thomas Gleixner wrote:
> On Tue, 20 Nov 2018, Muchun Song wrote:
> > Follow the current code logic, the timer0 function is called until the
> > function call of timer1-5 is completed. So the delay of timer0 is the time
> > spent by other timer function calls. If we can call the timer function in
> > the following order, this should be more friendly to lower-level timers.
> > 
> >         timer0->timer1->->timer2->->timer3->->timer4->->timer5
> > 
> > Although not friendly to higher-level timers, higher-level has larger
> > granularity. Therefore the delay has less impact on higher-level.
> 
> Well yes, that's clear. But is it a problem in practice and if so, what is
> the measurable benefit.

Polite reminder. Can you please describe what the practical relevance is of
that and what real world problem you are solving? Ideally with numbers
backing it up.

Thanks,

	tglx

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

* Re: [PATCH] timers: Make the lower-level timer function first call than higher-level
  2018-11-28 15:15       ` Thomas Gleixner
@ 2018-11-28 16:51         ` Muchun Song
  0 siblings, 0 replies; 6+ messages in thread
From: Muchun Song @ 2018-11-28 16:51 UTC (permalink / raw)
  To: tglx; +Cc: John Stultz, sboyd, linux-kernel

Hi tglx,

I'm sorry. Thanks for your reminder.

Thomas Gleixner <tglx@linutronix.de> 于2018年11月28日周三 下午11:15写道:
>
> Song,
>
> On Wed, 21 Nov 2018, Thomas Gleixner wrote:
> > On Tue, 20 Nov 2018, Muchun Song wrote:
> > > Follow the current code logic, the timer0 function is called until the
> > > function call of timer1-5 is completed. So the delay of timer0 is the time
> > > spent by other timer function calls. If we can call the timer function in
> > > the following order, this should be more friendly to lower-level timers.
> > >
> > >         timer0->timer1->->timer2->->timer3->->timer4->->timer5
> > >
> > > Although not friendly to higher-level timers, higher-level has larger
> > > granularity. Therefore the delay has less impact on higher-level.
> >
> > Well yes, that's clear. But is it a problem in practice and if so, what is
> > the measurable benefit.
>
> Polite reminder. Can you please describe what the practical relevance is of
> that and what real world problem you are solving? Ideally with numbers
> backing it up.
>

I just think that this change might be better for me when I read the code.
Maybe what I think is not a problem. So if there is something wrong,
please ignore the patch. Sorry.

Thanks.

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

end of thread, other threads:[~2018-11-28 16:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-19 14:10 [PATCH] timers: Make the lower-level timer function first call than higher-level Muchun Song
2018-11-19 18:16 ` John Stultz
2018-11-20  2:08   ` Muchun Song
2018-11-21 20:44     ` Thomas Gleixner
2018-11-28 15:15       ` Thomas Gleixner
2018-11-28 16:51         ` Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).