On Fri, 5 Aug 2005 11:39 am, Con Kolivas wrote: > On Fri, 5 Aug 2005 10:53 am, Nick Piggin wrote: > > All else being equal, it is much better if you unlock in the > > same function that takes the lock. For readability. > > > > It looks like you should be able to leave all the flow control > > and locking the same, and use update_monotonic_base() to > > do the actual update? > > Good advice, thanks. Will respin.
Like this I assume you meant? Cheers, Con ---
Index: linux-2.6.13-rc5-ck2/arch/i386/kernel/timers/timer_tsc.c =================================================================== --- linux-2.6.13-rc5-ck2.orig/arch/i386/kernel/timers/timer_tsc.c 2005-08-03 11:29:29.000000000 +1000 +++ linux-2.6.13-rc5-ck2/arch/i386/kernel/timers/timer_tsc.c 2005-08-05 13:15:23.000000000 +1000 @@ -167,10 +167,19 @@ static void delay_tsc(unsigned long loop } while ((now-bclock) < loops); } +/* update the monotonic base value */ +static inline void update_monotonic_base(unsigned long long last_offset) +{ + unsigned long long this_offset; + + this_offset = ((unsigned long long)last_tsc_high << 32) | last_tsc_low; + monotonic_base += cycles_2_ns(this_offset - last_offset); +} + #ifdef CONFIG_HPET_TIMER static void mark_offset_tsc_hpet(void) { - unsigned long long this_offset, last_offset; + unsigned long long last_offset; unsigned long offset, temp, hpet_current; write_seqlock(&monotonic_lock); @@ -198,9 +207,7 @@ static void mark_offset_tsc_hpet(void) } hpet_last = hpet_current; - /* update the monotonic base value */ - this_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low; - monotonic_base += cycles_2_ns(this_offset - last_offset); + update_monotonic_base(last_offset); write_sequnlock(&monotonic_lock); /* calculate delay_at_last_interrupt */ @@ -347,7 +354,7 @@ static void mark_offset_tsc(void) int count; int countmp; static int count1 = 0; - unsigned long long this_offset, last_offset; + unsigned long long last_offset; static int lost_count = 0; write_seqlock(&monotonic_lock); @@ -368,8 +375,11 @@ static void mark_offset_tsc(void) rdtsc(last_tsc_low, last_tsc_high); - if (dyn_tick_enabled()) - goto monotonic_base; + if (dyn_tick_enabled()) { + update_monotonic_base(last_offset); + write_sequnlock(&monotonic_lock); + return; + } spin_lock(&i8253_lock); outb_p(0x00, PIT_MODE); /* latch the count ASAP */ @@ -439,16 +449,9 @@ static void mark_offset_tsc(void) } else lost_count = 0; - monotonic_base: - - /* update the monotonic base value */ - this_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low; - monotonic_base += cycles_2_ns(this_offset - last_offset); + update_monotonic_base(last_offset); write_sequnlock(&monotonic_lock); - if (dyn_tick_enabled()) - return; - /* calculate delay_at_last_interrupt */ count = ((LATCH-1) - count) * TICK_SIZE; delay_at_last_interrupt = (count + LATCH/2) / LATCH;