linux-stable/include/asm-generic
Christoph Lameter 7340a0b152 this_cpu: Introduce this_cpu_ptr() and generic this_cpu_* operations
This patch introduces two things: First this_cpu_ptr and then per cpu
atomic operations.

this_cpu_ptr
------------

A common operation when dealing with cpu data is to get the instance of the
cpu data associated with the currently executing processor. This can be
optimized by

this_cpu_ptr(xx) = per_cpu_ptr(xx, smp_processor_id).

The problem with per_cpu_ptr(x, smp_processor_id) is that it requires
an array lookup to find the offset for the cpu. Processors typically
have the offset for the current cpu area in some kind of (arch dependent)
efficiently accessible register or memory location.

We can use that instead of doing the array lookup to speed up the
determination of the address of the percpu variable. This is particularly
significant because these lookups occur in performance critical paths
of the core kernel. this_cpu_ptr() can avoid memory accesses and

this_cpu_ptr comes in two flavors. The preemption context matters since we
are referring the the currently executing processor. In many cases we must
insure that the processor does not change while a code segment is executed.

__this_cpu_ptr 	-> Do not check for preemption context
this_cpu_ptr	-> Check preemption context

The parameter to these operations is a per cpu pointer. This can be the
address of a statically defined per cpu variable (&per_cpu_var(xxx)) or
the address of a per cpu variable allocated with the per cpu allocator.

per cpu atomic operations: this_cpu_*(var, val)
-----------------------------------------------
this_cpu_* operations (like this_cpu_add(struct->y, value) operate on
abitrary scalars that are members of structures allocated with the new
per cpu allocator. They can also operate on static per_cpu variables
if they are passed to per_cpu_var() (See patch to use this_cpu_*
operations for vm statistics).

These operations are guaranteed to be atomic vs preemption when modifying
the scalar. The calculation of the per cpu offset is also guaranteed to
be atomic at the same time. This means that a this_cpu_* operation can be
safely used to modify a per cpu variable in a context where interrupts are
enabled and preemption is allowed. Many architectures can perform such
a per cpu atomic operation with a single instruction.

Note that the atomicity here is different from regular atomic operations.
Atomicity is only guaranteed for data accessed from the currently executing
processor. Modifications from other processors are still possible. There
must be other guarantees that the per cpu data is not modified from another
processor when using these instruction. The per cpu atomicity is created
by the fact that the processor either executes and instruction or not.
Embedded in the instruction is the relocation of the per cpu address to
the are reserved for the current processor and the RMW action. Therefore
interrupts or preemption cannot occur in the mids of this processing.

Generic fallback functions are used if an arch does not define optimized
this_cpu operations. The functions come also come in the two flavors used
for this_cpu_ptr().

The firstparameter is a scalar that is a member of a structure allocated
through allocpercpu or a per cpu variable (use per_cpu_var(xxx)). The
operations are similar to what percpu_add() and friends do.

this_cpu_read(scalar)
this_cpu_write(scalar, value)
this_cpu_add(scale, value)
this_cpu_sub(scalar, value)
this_cpu_inc(scalar)
this_cpu_dec(scalar)
this_cpu_and(scalar, value)
this_cpu_or(scalar, value)
this_cpu_xor(scalar, value)

Arch code can override the generic functions and provide optimized atomic
per cpu operations. These atomic operations must provide both the relocation
(x86 does it through a segment override) and the operation on the data in a
single instruction. Otherwise preempt needs to be disabled and there is no
gain from providing arch implementations.

A third variant is provided prefixed by irqsafe_. These variants are safe
against hardware interrupts on the *same* processor (all per cpu atomic
primitives are *always* *only* providing safety for code running on the
*same* processor!). The increment needs to be implemented by the hardware
in such a way that it is a single RMW instruction that is either processed
before or after an interrupt.

cc: David Howells <dhowells@redhat.com>
cc: Ingo Molnar <mingo@elte.hu>
cc: Rusty Russell <rusty@rustcorp.com.au>
cc: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
2009-10-03 19:48:22 +09:00
..
bitops asm-generic: rename atomic.h to atomic-long.h 2009-06-11 21:02:17 +02:00
4level-fixup.h mm: Pass virtual address to [__]p{te,ud,md}_free_tlb() 2009-07-27 12:10:38 -07:00
Kbuild asm-generic: add a generic unistd.h 2009-06-11 21:02:16 +02:00
Kbuild.asm KVM: export kvm_para.h 2009-09-10 10:46:47 +03:00
atomic-long.h asm-generic: merge branch 'master' of torvalds/linux-2.6 2009-06-12 11:32:58 +02:00
atomic.h asm-generic: add generic atomic.h and io.h 2009-06-11 21:02:49 +02:00
atomic64.h lib: Provide generic atomic64_t implementation 2009-06-15 13:27:38 +10:00
audit_change_attr.h [PATCH] fix missing ifdefs in syscall classes hookup for generic targets 2006-09-22 17:48:56 -07:00
audit_dir_write.h [PATCH] fix missing ifdefs in syscall classes hookup for generic targets 2006-09-22 17:48:56 -07:00
audit_read.h [PATCH] audit: more syscall classes added 2006-09-11 13:32:27 -04:00
audit_signal.h [PATCH] add SIGNAL syscall class (v3) 2007-05-11 05:38:25 -04:00
audit_write.h [PATCH] asm/generic: fix bug - kernel fails to build when enable some common audit code on Blackfin 2008-12-09 02:27:39 -05:00
auxvec.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
bitops.h asm-generic: make bitops.h usable 2009-06-11 21:02:31 +02:00
bitsperlong.h asm-generic: introduce asm/bitsperlong.h 2009-06-11 21:02:14 +02:00
bug.h Eliminate thousands of warnings with gcc 3.2 build 2009-05-06 16:36:09 -07:00
bugs.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
cache.h asm-generic: add generic NOMMU versions of some headers 2009-06-11 21:02:50 +02:00
cacheflush.h asm-generic: add generic NOMMU versions of some headers 2009-06-11 21:02:50 +02:00
checksum.h add generic lib/checksum.c 2009-06-11 21:02:51 +02:00
cmpxchg-local.h Add cmpxchg_local to asm-generic for per cpu atomic operations 2008-02-07 08:42:30 -08:00
cmpxchg.h Add cmpxchg_local to asm-generic for per cpu atomic operations 2008-02-07 08:42:30 -08:00
cputime.h cputime: Optimize jiffies_to_cputime(1) 2009-08-03 14:48:36 +02:00
current.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
delay.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
device.h Driver Core: Add platform device arch data V3 2009-07-22 00:28:38 +02:00
div64.h rename div64_64 to div64_u64 2008-05-01 08:03:58 -07:00
dma-coherent.h generic: per-device coherent dma allocator 2008-06-30 12:51:05 +02:00
dma-mapping-broken.h dma-mapping: add the device argument to dma_mapping_error() 2008-07-26 12:00:03 -07:00
dma-mapping-common.h dma-ops: Remove flush_write_buffers() in dma-mapping-common.h 2009-08-10 09:34:57 +02:00
dma.h asm-generic: add legacy I/O header files 2009-06-11 21:02:42 +02:00
emergency-restart.h
errno-base.h
errno.h cfg80211: add rfkill support 2009-06-03 14:06:14 -04:00
fb.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
fcntl.h fcntl: add F_[SG]ETOWN_EX 2009-09-24 07:21:01 -07:00
futex.h remove __KERNEL__ tests of unexported headers under asm-generic/ 2008-04-30 08:29:54 -07:00
getorder.h asm-generic: rename page.h and uaccess.h 2009-06-11 21:02:17 +02:00
gpio.h asm-generic/gpio.h: pull in linux/kernel.h for might_sleep() 2009-10-01 16:11:11 -07:00
hardirq.h asm-generic: drop HARDIRQ_BITS definition from hardirq.h 2009-06-19 14:58:09 +02:00
hw_irq.h asm-generic: add legacy I/O header files 2009-06-11 21:02:42 +02:00
ide_iops.h
int-l64.h asm-generic: introduce asm/bitsperlong.h 2009-06-11 21:02:14 +02:00
int-ll64.h asm-generic: introduce asm/bitsperlong.h 2009-06-11 21:02:14 +02:00
io.h asm-generic: add generic atomic.h and io.h 2009-06-11 21:02:49 +02:00
ioctl.h Make ioctl.h compatible with userland 2008-08-12 16:07:31 -07:00
ioctls.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
iomap.h generic: add ioremap_wc() interface wrapper 2008-04-24 23:40:47 +02:00
ipcbuf.h asm-generic: add generic sysv ipc headers 2009-06-11 21:02:15 +02:00
irq.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
irq_regs.h IRQ: Maintain regs pointer globally rather than passing to IRQ handlers 2006-10-05 15:10:12 +01:00
irqflags.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
kdebug.h asm-generic: define DIE_OOPS in asm-generic 2008-10-27 11:39:03 +01:00
kmap_types.h kmap_types.h: rename D macro 2009-09-23 07:39:30 -07:00
libata-portmap.h libata-portmap: Remove unused definitions 2007-10-12 14:55:37 -04:00
linkage.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
local.h asm-generic: fix local_add_unless macro 2009-05-18 08:34:08 -07:00
memory_model.h mm: remove CONFIG_OUT_OF_LINE_PFN_TO_PAGE 2009-01-06 15:59:10 -08:00
mm_hooks.h [PATCH] x86: PARAVIRT: add hooks to intercept mm creation and destruction 2007-05-02 19:27:14 +02:00
mman-common.h Merge branch 'hwpoison' of git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-mce-2.6 2009-09-24 07:53:22 -07:00
mman.h mm: add MAP_HUGETLB for mmaping pseudo-anonymous huge page regions 2009-09-22 07:17:41 -07:00
mmu.h asm-generic: add generic NOMMU versions of some headers 2009-06-11 21:02:50 +02:00
mmu_context.h asm-generic: add generic NOMMU versions of some headers 2009-06-11 21:02:50 +02:00
module.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
msgbuf.h asm-generic: add generic sysv ipc headers 2009-06-11 21:02:15 +02:00
mutex-dec.h mutex: speed up generic mutex implementations 2008-10-23 09:18:20 -07:00
mutex-null.h fix file specification in comments 2006-10-03 23:01:26 +02:00
mutex-xchg.h mutex: speed up generic mutex implementations 2008-10-23 09:18:20 -07:00
mutex.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
page.h asm-generic: add generic NOMMU versions of some headers 2009-06-11 21:02:50 +02:00
param.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
parport.h asm-generic: add legacy I/O header files 2009-06-11 21:02:42 +02:00
pci-dma-compat.h dma-mapping: add the device argument to dma_mapping_error() 2008-07-26 12:00:03 -07:00
pci.h PCI: remove pcibios_scan_all_fns() 2009-09-09 13:29:18 -07:00
percpu.h this_cpu: Introduce this_cpu_ptr() and generic this_cpu_* operations 2009-10-03 19:48:22 +09:00
pgalloc.h asm-generic: add generic NOMMU versions of some headers 2009-06-11 21:02:50 +02:00
pgtable-nopmd.h mm: Pass virtual address to [__]p{te,ud,md}_free_tlb() 2009-07-27 12:10:38 -07:00
pgtable-nopud.h mm: Pass virtual address to [__]p{te,ud,md}_free_tlb() 2009-07-27 12:10:38 -07:00
pgtable.h asm-generic: add dummy pgprot_noncached() 2009-06-23 14:34:30 +02:00
poll.h Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
posix_types.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
resource.h sched: SCHED_FIFO/SCHED_RR watchdog timer 2008-01-25 21:08:27 +01:00
rtc.h asm-generic: make get_rtc_time overridable 2009-06-11 21:02:18 +02:00
scatterlist.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
sections.h asm/sections: add text/data checking functions for arches to override 2009-09-23 07:39:30 -07:00
segment.h asm-generic: add generic NOMMU versions of some headers 2009-06-11 21:02:50 +02:00
sembuf.h asm-generic: add generic sysv ipc headers 2009-06-11 21:02:15 +02:00
serial.h asm-generic: add legacy I/O header files 2009-06-11 21:02:42 +02:00
setup.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
shmbuf.h asm-generic: add generic sysv ipc headers 2009-06-11 21:02:15 +02:00
shmparam.h asm-generic: add generic sysv ipc headers 2009-06-11 21:02:15 +02:00
siginfo.h HWPOISON: Add new SIGBUS error codes for hardware poison signals 2009-09-16 11:50:06 +02:00
signal-defs.h asm-generic: rename termios.h, signal.h and mman.h 2009-06-11 21:01:52 +02:00
signal.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
socket.h net: implement a SO_DOMAIN getsockoption 2009-08-05 13:02:57 -07:00
sockios.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
spinlock.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
stat.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
statfs.h remove __KERNEL_STRICT_NAMES 2009-03-26 18:14:21 +01:00
string.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
swab.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
syscall.h asm-generic: syscall_get_nr returns int 2009-09-22 19:56:50 -07:00
syscalls.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
system.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
termbits.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
termios-base.h asm-generic: rename termios.h, signal.h and mman.h 2009-06-11 21:01:52 +02:00
termios.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
timex.h asm-generic: add legacy I/O header files 2009-06-11 21:02:42 +02:00
tlb.h mm: Pass virtual address to [__]p{te,ud,md}_free_tlb() 2009-07-27 12:10:38 -07:00
tlbflush.h asm-generic: add generic NOMMU versions of some headers 2009-06-11 21:02:50 +02:00
topology.h cpumask: remove obsolete node_to_cpumask now everyone uses cpumask_of_node 2009-09-24 09:34:34 +09:30
types.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
uaccess-unaligned.h asm-generic: rename page.h and uaccess.h 2009-06-11 21:02:17 +02:00
uaccess.h asm-generic: uaccess: fix up local access_ok() usage 2009-06-19 14:58:08 +02:00
ucontext.h asm-generic: add generic ABI headers 2009-06-11 21:02:15 +02:00
unaligned.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
unistd.h perf: Do the big rename: Performance Counters -> Performance Events 2009-09-21 14:28:04 +02:00
user.h asm-generic: add generic versions of common headers 2009-06-11 21:02:37 +02:00
vga.h asm-generic: add legacy I/O header files 2009-06-11 21:02:42 +02:00
vmlinux.lds.h Optimize the ordering of sections in RW_DATA_SECTION. 2009-09-24 17:16:21 -07:00
xor.h