Re: PER-CPU data
Hi Srivatsa, Thanks for the response. I have used per-CPU vars and I know about how to creating/using per-CPU vars: DECLARE_PER_CPU(type, name) for creating per-cpu at compile time and use alloc_percpu(type) for creating them dynamically. I intended to ask how they are stored internally (.percpu section) and its protection mechanism if it has any. Thanks & Regards, Rajasekhar On Fri, Mar 30, 2012 at 12:24 PM, Srivatsa S. Bhat wrote: > On 03/30/2012 12:05 PM, Dave Hylands wrote: > >> Hi Rajasekhar, >> >> On Thu, Mar 29, 2012 at 11:00 PM, Rajasekhar Pulluru >> 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 > ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: PER-CPU data
On 03/30/2012 12:05 PM, Dave Hylands wrote: > Hi Rajasekhar, > > On Thu, Mar 29, 2012 at 11:00 PM, Rajasekhar Pulluru > 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 ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: PER-CPU data
On 03/30/2012 12:05 PM, Dave Hylands wrote: > Hi Rajasekhar, > > On Thu, Mar 29, 2012 at 11:00 PM, Rajasekhar Pulluru > 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 ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: PER-CPU data
Hi Rajasekhar, On Thu, Mar 29, 2012 at 11:00 PM, Rajasekhar Pulluru wrote: > Hi, > > I would like to know how per-cpu data are stored internally? > And how are they protected from other cores? 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. -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
PER-CPU data
Hi, I would like to know how per-cpu data are stored internally? And how are they protected from other cores? Thanks & Regards, Rajasekhar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies