Re: [RFC] [PATCH 1/1] hrtimers: Cache next hrtimer

From: Ashwin Chaugule
Date: Sun Aug 30 2009 - 02:08:25 EST


Thomas Gleixner wrote:

Hmm. I'd really like to know why that's behaving different.

Usually there are only timers in the CLOCK_MONOTONIC base during
boot. CLOCK_REALTIME base should be empty most of the time. If my
theory is correct then the number of reprogram events is correct as
well because base[MONOTONIC]->first is always the one which armed the
timer.


Okay, I think I figured this out :)

I added some debug to find out how many timers are going to expire_next.

hrtimer_reprogram()

if (expires.tv64 == expires_next->tv64)

if (timer != next_hrtimer)

timer->realtime++; (lazily reusing realtime here, coz we know its always zero otherwise ;) )

Now timer->realtime is very much non-zero :)

So, now base->first has already changed (leftmost node in the rb tree) and is pointing to this new timer node which is also going to expire_next, but hasn't
changed the value of expire_next (we just returned 0).

Therefore, in remove_hrtimer()

+ if (base->first == &timer->node) {
+ base->first = rb_next(&timer->node);
+ /* Reprogram the clock event device. if enabled */
+ if (reprogram && hrtimer_hres_active()) {
+ expires = ktime_sub(hrtimer_get_expires(timer),
+ base->offset);


timer->node is going to point to the latest timer enqueued which is going to expire_next.

With your latest patch, we will force reprogram, but the next node to arm
the timer will be needless, because, its expiry is equal to expires_next.

So, by having a pointer like next_hrtimer, helps to represent all the timers
that are going to expire next, and thats why timer->cache_hits was always less
than timer->total_count.IOW, we avoided re-programming the device, if the next timer was going to expire at the same time as the one we just removed.

Thoughts ?

Cheers,

Ashwin

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/