Re: [RFC] time: xtime_lock is held too long

Eric Dumazet
2011-05-06T01:41:51Z

Le jeudi 05 mai 2011 à 23:01 +0200, Andi Kleen a écrit :
> > > Another idea would be to prime cache lines to be dirtied in cpu cache
> > > before taking locks, and better pack variables to reduce number of cache
> > > lines.
> >
> > Most variables are packed already in struct timekeeper, which should
> > be pretty cache hot anyway, so I don't know whether we gain much.
>
> There's actually some potential here. I got a moderate speedup in a
> database benchmark with this patch recently. The biggest win
> was in the timer interrupt.
>
> All those variables are on separate cache lines.
>
> (needs some cleanups, just for illustration)
>
> -Andi
>
> From: Andi Kleen <ak@linux.intel.com>
> Subject: [PATCH] do prefetches for timer state in timer interrupt
>
> diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
> index 76b96d7..2704267 100644
> --- a/arch/x86/kernel/apic/apic.c
> +++ b/arch/x86/kernel/apic/apic.c
> @@ -856,6 +856,17 @@ void __irq_entry smp_apic_timer_interrupt(struct pt_regs *regs)
> {
> struct pt_regs *old_regs = set_irq_regs(regs);
>
> + extern struct timespec xtime;
> + extern struct timespec wall_to_monotonic;
> +
> +
> + /* Prefetch here to make the ktime_get later faster.
> + * XXX move them all on the same cache line.
> + */
> + prefetch(&xtime_lock);
> + prefetch(&xtime);
> + prefetch(&wall_to_monotonic);
> +
> /*
> * NOTE! We'd better ACK the irq immediately,
> * because timer handling can be slow.
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index d27c756..0002e9e 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -157,8 +157,8 @@ __cacheline_aligned_in_smp DEFINE_SEQLOCK(xtime_lock);
> * - wall_to_monotonic is no longer the boot time, getboottime must be
> * used instead.
> */
> -static struct timespec xtime __attribute__ ((aligned (16)));
> -static struct timespec wall_to_monotonic __attribute__ ((aligned (16)));
> +struct timespec xtime __attribute__ ((aligned (16)));
> +struct timespec wall_to_monotonic __attribute__ ((aligned (16)));
> static struct timespec total_sleep_time;
>
> /*
>

Did you tried prefetchw() by any chance ?