netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Christoph Lameter <cl@linux-foundation.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>, Tejun Heo <tj@kernel.org>,
	Ingo Molnar <mingo@elte.hu>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	akpm@linux-foundation.org, hpa@zytor.com, brgerst@gmail.com,
	ebiederm@xmission.com, travis@sgi.com,
	linux-kernel@vger.kernel.org, steiner@sgi.com, hugh@veritas.com,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org
Subject: Re: [PATCH] percpu: add optimized generic percpu accessors
Date: Wed, 28 Jan 2009 13:07:57 -0500	[thread overview]
Message-ID: <20090128180757.GA9908@Krystal> (raw)
In-Reply-To: <alpine.DEB.1.10.0901281148540.13825@qirst.com>

* Christoph Lameter (cl@linux-foundation.org) wrote:
> On Wed, 28 Jan 2009, Rusty Russell wrote:
> 
> > AFAICT we'll need a hybrid: HAVE_NMISAFE_CPUOPS, and if not, use atomic_t
> > in ftrace (which isn't NMI safe on parisc or sparc/32 anyway, but I don't think we care).
> 
> Right.
> 

Ideally this should be done transparently so we don't have to #ifdef
code around HAVE_NMISAFE_CPUOPS everywhere in the tracer. We might
consider declaring an intermediate type with this kind of #ifdef in the
tracer code if we are the only one user though.

> 
> > Other than the shouting, I liked Christoph's system:
> > - CPU_INC = always safe (eg. local_irq_save/per_cpu(i)++/local_irq_restore)
> > - _CPU_INC = not safe against interrupts (eg. get_cpu/per_cpu(i)++/put_cpu)
> > - __CPU_INC = not safe against anything (eg. per_cpu(i)++)
> >
> > I prefer the name 'local' to the name 'cpu', but I'm not hugely fussed.
> 
> The term cpu is meaning multiple things at this point. So yes it may be
> better to go with glibc naming of thread local space.
> 

However using "local" for "per-cpu" could be confusing with the glibc
naming of thread local space, because "per-thread" and "per-cpu"
variables are different from a synchronization POV and we can end up
needing both (e.g. a thread local variable can never be accessed by
another thread, but a cpu local variable could be accessed by a
different CPU due to scheduling).

I'm currently thinking about implementing user-space per-cpu tracing buffers,
and the last thing I'd like is to have a "local" semantic clash between
the kernel and glibc. Ideally, we could have something like :

Atomic safe primitives (emulated with irq disable if the architecture
does not have atomic primitives) :
- atomic_thread_inc()
  * current mainline local_t local_inc().
- atomic_cpu_inc()
  * Your proposed CPU_INC.

Non-safe against interrupts, but safe against preemption :
- thread_inc()
  * no preempt_disable involved, because this deals with per-thread
    variables :
    * Simple var++
- cpu_inc()
  * disables preemption, per_cpu(i)++, enables preemption

Not safe against preemption nor interrupts :
- _thread_inc()
  * maps to thread_inc()
- _cpu_inc()
  * simple per_cpu(i)++

So maybe we don't really need thread_inc(), _thread_inc() and _cpu_inc,
because they map to standard C operations, but we may find that in some
architectures that the atomic_cpu_inc() is faster than the per_cpu(i)++,
and in those cases it would make sense to map e.g. _cpu_inc() to
atomic_cpu_inc().

Also note that don't think adding _ and __ prefixes to the operations
makes it clear for the programmer and reviewer what is safe against
what. OMHO, it will just make the code more obscure. One level of
underscore is about the limit I think people can "know" what this
"unsafe" version of the primitive does.

Mathieu

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

  reply	other threads:[~2009-01-28 18:07 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090115183942.GA6325@elte.hu>
     [not found] ` <20090116001200.GA9137@gondor.apana.org.au>
     [not found]   ` <20090116001544.GA11073@elte.hu>
2009-01-16  0:18     ` [PATCH] percpu: add optimized generic percpu accessors Herbert Xu
     [not found]       ` <200901170827.33729.rusty@rustcorp.com.au>
2009-01-16 22:08         ` Ingo Molnar
     [not found]           ` <200901201328.24605.rusty@rustcorp.com.au>
2009-01-20  6:25             ` Tejun Heo
2009-01-20 10:36               ` Ingo Molnar
     [not found]               ` <200901271213.18605.rusty@rustcorp.com.au>
2009-01-27  2:24                 ` Tejun Heo
2009-01-27 13:13                   ` Ingo Molnar
2009-01-27 23:07                     ` Tejun Heo
2009-01-28  3:36                       ` Tejun Heo
2009-01-28  8:12                         ` Tejun Heo
2009-01-27 20:08                   ` Christoph Lameter
2009-01-27 21:47                     ` David Miller
2009-01-27 22:47                       ` Rick Jones
2009-01-28  0:17                         ` Luck, Tony
2009-01-28 16:48                           ` Christoph Lameter
2009-01-28 17:15                             ` Luck, Tony
2009-01-28 16:45                       ` Christoph Lameter
2009-01-28 20:47                         ` David Miller
2009-01-28 10:38                   ` Rusty Russell
2009-01-28 10:56                     ` Tejun Heo
2009-01-29  2:06                       ` Rusty Russell
2009-01-31  6:11                         ` Tejun Heo
2009-01-28 16:50                     ` Christoph Lameter
2009-01-28 18:07                       ` Mathieu Desnoyers [this message]
2009-01-29 18:33                         ` Christoph Lameter
2009-01-29 18:48                           ` H. Peter Anvin
2009-01-20 10:40             ` Ingo Molnar
2009-01-21  5:52               ` Tejun Heo
2009-01-21 10:05                 ` Ingo Molnar
2009-01-21 11:21                 ` Eric W. Biederman
2009-01-21 12:45                   ` Stephen Hemminger
2009-01-21 14:13                     ` Eric W. Biederman
2009-01-21 20:34                     ` David Miller

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=20090128180757.GA9908@Krystal \
    --to=mathieu.desnoyers@polymtl.ca \
    --cc=akpm@linux-foundation.org \
    --cc=brgerst@gmail.com \
    --cc=cl@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=ebiederm@xmission.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=hugh@veritas.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=netdev@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=steiner@sgi.com \
    --cc=tj@kernel.org \
    --cc=travis@sgi.com \
    /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;
as well as URLs for NNTP newsgroup(s).