Re: [patch 04/41] cpu ops: Core piece for generic atomic per cpu operations

Christoph Lameter
2008-06-10T17:42:35Z

On Mon, 2 Jun 2008, Rusty Russell wrote:

> > Believe me I have tried to use local_t repeatedly for vm statistics etc.
> > It always fails on that issue.
>
> Frankly, I am finding it increasingly easy to believe that you failed. But
> you are blaming the wrong thing.
>
> There are three implementations of local_t which are obvious. The best is for
> architectures which can locate and increment a per-cpu var in one instruction
> (eg. x86). Otherwise, using atomic_t/atomic64_t for local_t provides a
> general solution. The other general solution would involve
> local_irq_disable()/increment/local_irq_enable().
>
> My (fading) hope is that this idiocy is an abberation,

1. The x86 implementation does not exist because the segment register has
so far not been available on x86_64. So you could not do the solution.
You need the zero basing. Then you can use per_xxx_add in cpu_inc.

2. The general solution created overhead that is often not needed. If we
would have done vm event counters with local_t then we would have
atomic overhead for each increment on f.e. IA64. That was not
acceptable. cpu_alloc never falls back to atomic operations.

3. local_t is based on the atomic logic. But percpu handling is
fundamentally different in that accesses without the special macros
are okay provided you are in a non preemptible or irq context!
A local_t declaration makes such accesses impossible.

4. The modeling of local_t on atomic_t limits it to 32bit! There is no
way to use this with pointers or 64 bit entities. Adding that would
duplicate the API for each type added.