lkml.org 
[lkml]   [2009]   [Jan]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] percpu: add optimized generic percpu accessors

    * Andrew Morton <akpm@linux-foundation.org> wrote:

    > On Thu, 15 Jan 2009 19:02:59 +0100 Ingo Molnar <mingo@elte.hu> wrote:
    >
    > >
    > > * Andrew Morton <akpm@linux-foundation.org> wrote:
    > >
    > > > On Thu, 15 Jan 2009 22:23:19 +0900 Tejun Heo <tj@kernel.org> wrote:
    > > >
    > > > > --- a/include/asm-generic/percpu.h
    > > > > +++ b/include/asm-generic/percpu.h
    > > > > @@ -80,4 +80,56 @@ extern void setup_per_cpu_areas(void);
    > > > > #define DECLARE_PER_CPU(type, name) extern PER_CPU_ATTRIBUTES \
    > > > > __typeof__(type) per_cpu_var(name)
    > > > >
    > > > > +/*
    > > > > + * Optional methods for optimized non-lvalue per-cpu variable access.
    > > > > + *
    > > > > + * @var can be a percpu variable or a field of it and its size should
    > > > > + * equal char, int or long. percpu_read() evaluates to a lvalue and
    > > > > + * all others to void.
    > > > > + *
    > > > > + * These operations are guaranteed to be atomic w.r.t. preemption.
    > > > > + * The generic versions use plain get/put_cpu_var(). Archs are
    > > > > + * encouraged to implement single-instruction alternatives which don't
    > > > > + * require preemption protection.
    > > > > + */
    > > > > +#ifndef percpu_read
    > > > > +# define percpu_read(var) \
    > > > > + ({ \
    > > > > + typeof(per_cpu_var(var)) __tmp_var__; \
    > > > > + __tmp_var__ = get_cpu_var(var); \
    > > > > + put_cpu_var(var); \
    > > > > + __tmp_var__; \
    > > > > + })
    > > > > +#endif
    > > >
    > > > I wonder if the preempt_disable()/preempt_enable() in here actually
    > > > does anything useful on any architecture.
    > >
    > > Provides "this is IRQ safe"
    >
    > ?
    >
    > > and "this is preempt safe" semantics.
    >
    > Of course. But do any architectures actually _need_ that for a single
    > read?

    not for a read i guess - but for the other ops like add/and/or/xor.

    > Maybe. And if so, they can interpose their arch-specific
    > implementation. But if the generic version is optimal for them, they
    > wouldn't need to..

    we cannot turn the generic ops into a single instruction so arch methods
    are preferable no matter how thick or thin the generic version is. But i
    agree that the optimization you suggest could be done.

    Ingo


    \
     
     \ /
      Last update: 2009-01-15 19:43    [W:2.503 / U:0.276 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site