From: Eric Dumazet <dada1@cosmosbay.com>
To: "Julio M. Merino Vidal" <jmerino@ac.upc.edu>
Cc: Andi Kleen <andi@firstfloor.org>, linux-kernel@vger.kernel.org
Subject: Re: Per-CPU data as a structure
Date: Fri, 4 May 2007 10:55:26 +0200 [thread overview]
Message-ID: <20070504105526.e5ea950b.dada1@cosmosbay.com> (raw)
In-Reply-To: <463AF095.30406@ac.upc.edu>
On Fri, 04 May 2007 10:36:37 +0200
"Julio M. Merino Vidal" <jmerino@ac.upc.edu> wrote:
>
> Anyway, what do you think about adding the above text to the code (percpu.h
> maybe) as documentation? See the patch below. (Dunno if the Signed-off-by
> line is appropriate as most of the text is yours.)
>
> Signed-off-by: Julio M. Merino Vidal <jmerino@ac.upc.edu>
>
> diff --git a/include/linux/percpu.h b/include/linux/percpu.h
> index 600e3d3..b8e8b8c 100644
> --- a/include/linux/percpu.h
> +++ b/include/linux/percpu.h
> @@ -1,6 +1,21 @@
> #ifndef __LINUX_PERCPU_H
> #define __LINUX_PERCPU_H
>
> +/*
> + * percpu provides a mechanism to define variables that are specific to
> each
> + * CPU in the system.
> + *
> + * Each variable is defined as an independent array of NR_CPUS elements.
> + * This approach is used instead of a per-CPU structure because it has the
> + * following advantages:
> + * - Independent maintenance: a source file can define new per-CPU
> + * variables without distorting others.
> + * - Fast access and relatively compact code.
> + * - Avoids false sharing by keeping cache lines of different CPUs
> separate.
> + * - Doesn't waste a lot of memory in padding like NR_CPUs arrays usually
> + * need to to avoid the previous point.
> + */
> +
> #include <linux/spinlock.h> /* For preempt_disable() */
> #include <linux/slab.h> /* For kmalloc() */
> #include <linux/smp.h>
Documentation is good, and percpu probably misses one, but please add it in a Documentation/percpu.txt file, because it's the right place.
You then can really have an extensive documentation, and you wont slow down kernel compiles...
I suggest you document all variants (get_cpu_var(), __get_cpu_var(), ...) with examples of use
Also, please note that per cpu data is not allocated * NR_CPUS, but depends on possible cpus. So if you boot an SMP kernel on a one CPU desktop, kernel allocates only the needed space.
So per_cpu data has also a space saving argument against structures declared with [NR_CPUS] arrays.
Thank you
next prev parent reply other threads:[~2007-05-04 8:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-03 15:16 Per-CPU data as a structure Julio M. Merino Vidal
2007-05-03 17:19 ` Andi Kleen
2007-05-04 8:36 ` Julio M. Merino Vidal
2007-05-04 8:55 ` Eric Dumazet [this message]
2007-05-04 14:07 ` Andi Kleen
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=20070504105526.e5ea950b.dada1@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=andi@firstfloor.org \
--cc=jmerino@ac.upc.edu \
--cc=linux-kernel@vger.kernel.org \
/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