Re: [PATCH] timers: Make the lower-level timer function first call than higher-level

From: Muchun Song
Date: Mon Nov 19 2018 - 21:08:27 EST


Hi John,

Thanks for your review.

John Stultz <john.stultz@xxxxxxxxxx> ä2018å11æ20æåä äå2:16åéï
>
> On Mon, Nov 19, 2018 at 6:10 AM, Muchun Song <smuchun@xxxxxxxxx> 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.