[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20070109220616.GA30535@Krystal>
Date: Tue, 9 Jan 2007 17:06:16 -0500
From: Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca>
To: Andrew Morton <akpm@...l.org>
Cc: Pavel Machek <pavel@...e.cz>, linux-kernel@...r.kernel.org,
Ingo Molnar <mingo@...hat.com>,
Greg Kroah-Hartman <gregkh@...e.de>,
Christoph Hellwig <hch@...radead.org>, ltt-dev@...fik.org,
systemtap@...rces.redhat.com,
Douglas Niehaus <niehaus@...s.ku.edu>,
"Martin J. Bligh" <mbligh@...igh.org>,
Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH] local_t : Documentation
* Andrew Morton (akpm@...l.org) wrote:
> On Mon, 8 Jan 2007 22:14:46 -0500
> Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca> wrote:
>
> > +* How to use local atomic operations
> > +
> > +#include <linux/percpu.h>
> > +#include <asm/local.h>
> > +
> > +static DEFINE_PER_CPU(local_t, counters) = LOCAL_INIT(0);
> > +
> > +
> > +* Counting
> > +
> > +In preemptible context, use get_cpu_var() and put_cpu_var() around local atomic
> > +operations : it makes sure that preemption is disabled around write access to
> > +the per cpu variable. For instance :
> > +
> > + local_inc(&get_cpu_var(counters));
> > + put_cpu_var(counters);
>
> Confused. The whole point behind local_t is that we can do
> atomic-wrt-interrupts inc and dec on them.
>
> Consequently, as atomic-wrt-interrupts means atomic-wrt-preemption, there
> is no need to do a preempt_disable() around local_inc() and local_dec().
>
Hi Andrew,
Not exactly : the increment operation is atomic, but not the selection of the
local variable. local_inc(&__get_cpu_var()) implies the following sequence
of operations :
1 - Get the variable copy corresponding to the currently running CPU.
2 - atomically increment the variable.
It would be wrong to be scheduled on another CPU between 1 and 2, because the
atomic increment should only be done by the CPU "owner" of the local variable,
as the local atomic increment is not atomic wrt other CPUs.
Mathieu
--
OpenPGP public key: http://krystal.dyndns.org:8080/key/compudj.gpg
Key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists