All of lore.kernel.org
 help / color / mirror / Atom feed
From: srivatsa.bhat@linux.vnet.ibm.com (Srivatsa S. Bhat)
To: kernelnewbies@lists.kernelnewbies.org
Subject: PER-CPU data
Date: Fri, 30 Mar 2012 12:24:15 +0530	[thread overview]
Message-ID: <4F755897.8070200@linux.vnet.ibm.com> (raw)
In-Reply-To: <CABi1daFRLahrwOXYvMwL5JwPYOP=5aZnaG4+Rdv6KUN4C=LTwg@mail.gmail.com>

On 03/30/2012 12:05 PM, Dave Hylands wrote:

> Hi Rajasekhar,
> 
> On Thu, Mar 29, 2012 at 11:00 PM, Rajasekhar Pulluru
> <pullururajasekhar@gmail.com> wrote:
>> Hi,
>>
>> I would like to know how per-cpu data are stored internally?
>> And how are they protected from other cores?
> 


To put it in very simplistic terms, per-cpu data is nothing but having
NR_CPUS copies of the data, like an array, something like:

int data[NR_CPUS];

And accessing this per-cpu data will essentially boil down to finding
out the id of the processor you are running on, and indexing this array
using that, something like:

int val, cpu;

cpu = smp_processor_id();
val = data[cpu];

So you automatically read/write the copy that belongs to your processor.
That's it. However, this is an over-simplified view of per-cpu data,
but you get the general idea...

> I believe that they're just kmalloc'd like other kernel data. At the
> kernel level there is no protection, just like all the rest of the
> memory accessible to the kernel.
> http://lxr.linux.no/#linux+v3.3/include/asm-generic/percpu.h#L8
> http://lxr.linux.no/#linux+v3.3/mm/percpu.c
> 
> When you declare a per-cpu variable, it goes into a special section,
> and what you're really doing is figuring out the offset within a
> per_cpu region of memory.
> 

 
Regards,
Srivatsa S. Bhat

  reply	other threads:[~2012-03-30  6:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-30  6:00 PER-CPU data Rajasekhar Pulluru
2012-03-30  6:35 ` Dave Hylands
2012-03-30  6:54   ` Srivatsa S. Bhat [this message]
2012-04-04  5:10     ` Rajasekhar Pulluru
2012-03-30  6:54   ` Srivatsa S. Bhat
  -- strict thread matches above, loose matches on Subject: below --
2002-07-12  6:01 per-cpu data Rusty Russell
2002-07-12  8:21 ` Richard Henderson
2002-07-24 12:31 ` Jamie Lokier
2002-07-25  0:28   ` 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=4F755897.8070200@linux.vnet.ibm.com \
    --to=srivatsa.bhat@linux.vnet.ibm.com \
    --cc=kernelnewbies@lists.kernelnewbies.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.