From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
David Miller <davem@davemloft.net>,
Paul Mackerras <paulus@samba.org>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Christoph Lameter <christoph@lameter.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Martin Bligh <mbligh@google.com>
Subject: Re: local_add_return
Date: Tue, 16 Dec 2008 11:25:32 -0500 [thread overview]
Message-ID: <20081216162532.GA7575@Krystal> (raw)
In-Reply-To: <200812161703.00697.rusty@rustcorp.com.au>
* Rusty Russell (rusty@rustcorp.com.au) wrote:
> On Tuesday 16 December 2008 00:17:35 Steven Rostedt wrote:
> > Shouldn't local_add_return be a way for archs that can increment a memory
> > location atomically against interrupts to use that infrastructure? It can
> > simply fall back to atomic_add_return for those archs that do not have
> > a lesser equivalent of atomic_add_return.
>
> local_t was originally introduced (but actually never used for) the
> SNMP counters. They use two counters to avoid atomics, but as the ancient
> comment says:
>
> /*
> * FIXME: On x86 and some other CPUs the split into user and softirq parts
> * is not needed because addl $1,memory is atomic against interrupts (but
> * atomic_inc would be overkill because of the lock cycles). Wants new
> * nonlocked_atomic_inc() primitives -AK
> */
> #define DEFINE_SNMP_STAT(type, name) \
> __typeof__(type) *name[2]
>
> Then last year Mathieu sent (and Andrew accepted) a "rich set of atomic
> operations", including excellent documentation "local_ops.txt". Except
> he thought they were atomics, so treated them accordingly. Also, there
> were no users (you're now the only one).
>
> But if these new operations are to become the norm, it changes how archs
> should implement local_t. eg. trivalue becomes less attractive, atomic_long
> more. x86 has its own implementation so doesn't have these issues.
>
> Now, I posted a benchmark patch before for archs to test. I'm interested
> in Sparc64. Does any arch win from using multiple counters? PowerPC has
> soft interrupt disable, so that solution wins over atomic_long_t for them.
>
Hi Rusty,
I'd like to comment on your test case found at
http://groups.google.com/group/linux.kernel/msg/98c512fceda26351
Specifically on this comment :
+/* There are three obvious ways to implement local_t on an arch which
+ * can't do single-instruction inc/dec etc.
+ * 1) atomic_long
+ * 2) irq_save/irq_restore
+ * 3) multiple counters.
+ *
+ * This does a very rough benchmark on each one.
+ */
Option 3) is not workable for tracers, because it's not safe against
some exceptions (e.g. some hardware errors) nor NMIs. Also, local_t
operations must have preemption disabled before playing on per-cpu data,
which I don't see in your test. This has to be taken into account in the
runtime cost. The "multiple counters" options should also disable
preemption, because a thread being moved to another CPU could corrupt
some other thread's data when being rescheduled.
Only two alternatives does not have this preempt_disable() requirement :
atomic_long_t and the CPU_OPS work done by Christoph Lameter which use
segments to address the per-cpu data, which effectively removes the need
for disabling preemption around local_t operations because the CPU ID
becomes encoded in a cpu register.
Otherwise, you can be moved to a different CPU between the moment you
read the CPU ID and the moment you access the local data, which can lead
to corruption with local_t and multiple counters options.
Cheers,
Mathieu
> Cheers,
> Rusty.
--
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
next prev parent reply other threads:[~2008-12-16 16:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-15 13:47 local_add_return Steven Rostedt
2008-12-16 6:33 ` local_add_return Rusty Russell
2008-12-16 6:57 ` local_add_return David Miller
2008-12-16 7:13 ` local_add_return David Miller
2008-12-16 22:38 ` local_add_return Rusty Russell
2008-12-16 23:25 ` local_add_return Luck, Tony
2008-12-16 23:43 ` local_add_return Heiko Carstens
2008-12-16 23:59 ` local_add_return Eric Dumazet
2008-12-17 0:01 ` local_add_return Mathieu Desnoyers
2008-12-18 22:52 ` local_add_return Rusty Russell
2008-12-19 3:35 ` local_add_return Mathieu Desnoyers
2008-12-19 5:54 ` local_add_return Rusty Russell
2008-12-19 17:06 ` local_add_return Mathieu Desnoyers
2008-12-20 1:33 ` local_add_return Rusty Russell
2008-12-22 18:43 ` local_add_return Mathieu Desnoyers
2008-12-24 11:42 ` local_add_return Rusty Russell
2008-12-24 18:53 ` local_add_return Mathieu Desnoyers
2008-12-16 16:25 ` Mathieu Desnoyers [this message]
2008-12-17 11:23 ` local_add_return Rusty Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081216162532.GA7575@Krystal \
--to=mathieu.desnoyers@polymtl.ca \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=christoph@lameter.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mbligh@google.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=paulus@samba.org \
--cc=rostedt@goodmis.org \
--cc=rusty@rustcorp.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox