alistair23-linux/arch/powerpc/include/asm
Anton Blanchard a66086b819 powerpc: POWER7 optimised copy_to_user/copy_from_user using VMX
Implement a POWER7 optimised copy_to_user/copy_from_user using VMX.
For large aligned copies this new loop is over 10% faster, and for
large unaligned copies it is over 200% faster.

If we take a fault we fall back to the old version, this keeps
things relatively simple and easy to verify.

On POWER7 unaligned stores rarely slow down - they only flush when
a store crosses a 4KB page boundary. Furthermore this flush is
handled completely in hardware and should be 20-30 cycles.

Unaligned loads on the other hand flush much more often - whenever
crossing a 128 byte cache line, or a 32 byte sector if either sector
is an L1 miss.

Considering this information we really want to get the loads aligned
and not worry about the alignment of the stores. Microbenchmarks
confirm that this approach is much faster than the current unaligned
copy loop that uses shifts and rotates to ensure both loads and
stores are aligned.

We also want to try and do the stores in cacheline aligned, cacheline
sized chunks. If the store queue is unable to merge an entire
cacheline of stores then the L2 cache will have to do a
read/modify/write. Even worse, we will serialise this with the stores
in the next iteration of the copy loop since both iterations hit
the same cacheline.

Based on this, the new loop does the following things:

1 - 127 bytes
Get the source 8 byte aligned and use 8 byte loads and stores. Pretty
boring and similar to how the current loop works.

128 - 4095 bytes
Get the source 8 byte aligned and use 8 byte loads and stores,
1 cacheline at a time. We aren't doing the stores in cacheline
aligned chunks so we will potentially serialise once per cacheline.
Even so it is much better than the loop we have today.

4096 - bytes
If both source and destination have the same alignment get them both
16 byte aligned, then get the destination cacheline aligned. Do
cacheline sized loads and stores using VMX.

If source and destination do not have the same alignment, we get the
destination cacheline aligned, and use permute to do aligned loads.

In both cases the VMX loop should be optimal - we always do aligned
loads and stores and are always doing stores in cacheline aligned,
cacheline sized chunks.

To be able to use VMX we must be careful about interrupts and
sleeping. We don't use the VMX loop when in an interrupt (which should
be rare anyway) and we wrap the VMX loop in disable/enable_pagefault
and fall back to the existing copy_tofrom_user loop if we do need to
sleep.

The VMX breakpoint of 4096 bytes was chosen using this microbenchmark:

http://ozlabs.org/~anton/junkcode/copy_to_user.c

Since we are using VMX and there is a cost to saving and restoring
the user VMX state there are two broad cases we need to benchmark:

- Best case - userspace never uses VMX

- Worst case - userspace always uses VMX

In reality a userspace process will sit somewhere between these two
extremes. Since we need to test both aligned and unaligned copies we
end up with 4 combinations. The point at which the VMX loop begins to
win is:

0% VMX
aligned		2048 bytes
unaligned	2048 bytes

100% VMX
aligned		16384 bytes
unaligned	8192 bytes

Considering this is a microbenchmark, the data is hot in cache and
the VMX loop has better store queue merging properties we set the
breakpoint to 4096 bytes, a little below the unaligned breakpoints.

Some future optimisations we can look at:

- Looking at the perf data, a significant part of the cost when a
  task is always using VMX is the extra exception we take to restore
  the VMX state. As such we should do something similar to the x86
  optimisation that restores FPU state for heavy users. ie:

        /*
         * If the task has used fpu the last 5 timeslices, just do a full
         * restore of the math state immediately to avoid the trap; the
         * chances of needing FPU soon are obviously high now
         */
        preload_fpu = tsk_used_math(next_p) && next_p->fpu_counter > 5;

  and

        /*
         * fpu_counter contains the number of consecutive context switches
         * that the FPU is used. If this is over a threshold, the lazy fpu
         * saving becomes unlazy to save the trap. This is an unsigned char
         * so that after 256 times the counter wraps and the behavior turns
         * lazy again; this to deal with bursty apps that only use FPU for
         * a short time
         */

- We could create a paca bit to mirror the VMX enabled MSR bit and check
  that first, avoiding multiple calls to calling enable_kernel_altivec.
  That should help with iovec based system calls like readv.

- We could have two VMX breakpoints, one for when we know the user VMX
  state is loaded into the registers and one when it isn't. This could
  be a second bit in the paca so we can calculate the break points quickly.

- One suggestion from Ben was to save and restore the VSX registers
  we use inline instead of using enable_kernel_altivec.

[BenH: Fixed a problem with preempt and fixed build without CONFIG_ALTIVEC]

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2011-12-19 14:40:40 +11:00
..
iseries
8xx_immap.h powerpc: Fix multicast problem in fs_enet driver 2011-04-21 16:59:30 -07:00
abs_addr.h
agp.h
asm-compat.h
asm-offsets.h
async_tx.h
atomic.h powerpc: Fix atomic_xxx_return barrier semantics 2011-11-17 16:26:07 +11:00
auxvec.h
backlight.h
bitops.h powerpc: Fix atomic_xxx_return barrier semantics 2011-11-17 16:26:07 +11:00
bitsperlong.h
bootx.h
btext.h
bug.h
bugs.h
byteorder.h
cache.h
cacheflush.h
cell-pmu.h
cell-regs.h
checksum.h powerpc: Add 64bit csum_and_copy_to_user 2010-09-02 14:07:30 +10:00
clk_interface.h
code-patching.h
compat.h compat: sync compat_stats with statfs. 2011-10-28 14:58:53 +02:00
cpm.h Fix common misspellings 2011-03-31 11:26:23 -03:00
cpm1.h Fix common misspellings 2011-03-31 11:26:23 -03:00
cpm2.h
cputable.h powerpc: POWER7 optimised copy_to_user/copy_from_user using VMX 2011-12-19 14:40:40 +11:00
cputhreads.h powerpc: Convert old cpumask API into new one 2011-05-04 15:22:59 +10:00
cputime.h taskstats: use real microsecond granularity for CPU times 2010-10-27 18:03:17 -07:00
current.h
dbdma.h
dbell.h powerpc: Fix doorbell type shift 2011-06-20 11:21:48 +10:00
dcr-generic.h
dcr-mmio.h
dcr-native.h
dcr-regs.h
dcr.h
delay.h
device.h powerpc: Use the newly added get_required_mask dma_map_ops hook 2011-09-20 09:19:35 +10:00
disassemble.h
div64.h
dma-mapping.h powerpc: Use the newly added get_required_mask dma_map_ops hook 2011-09-20 09:19:35 +10:00
dma.h
edac.h
eeh.h
eeh_event.h
ehv_pic.h powerpc: introduce the ePAPR embedded hypervisor vmpic driver 2011-06-27 08:30:26 -05:00
elf.h treewide: fix potentially dangerous trailing ';' in #defined values/expressions 2011-07-21 14:10:00 +02:00
emergency-restart.h
emulated_ops.h atomic: use <linux/atomic.h> 2011-07-26 16:49:47 -07:00
epapr_hcalls.h powerpc: introduce ePAPR embedded hypervisor hcall interface 2011-06-27 08:30:19 -05:00
errno.h
exception-64e.h powerpc/book3e-64: use a separate TLB handler when linear map is bolted 2011-06-29 17:47:48 +10:00
exception-64s.h KVM: PPC: book3s_hv: Add support for PPC970-family processors 2011-07-12 13:16:59 +03:00
fb.h
fcntl.h
feature-fixups.h powerpc: Use new CPU feature bit to select 2.06 tlbie 2011-05-04 15:19:26 +10:00
firmware.h powerpc/powernv: Basic support for OPAL 2011-09-20 16:09:50 +10:00
fixmap.h
floppy.h powerpc/irq: Remove IRQF_DISABLED 2011-11-08 14:51:46 +11:00
fs_pd.h
fsl_85xx_cache_sram.h powerpc/85xx: add cache-sram support 2010-10-14 00:54:38 -05:00
fsl_gtm.h
fsl_guts.h powerpc: rename immap_86xx.h to fsl_guts.h, and add 85xx support 2010-08-12 14:00:15 +01:00
fsl_hcalls.h powerpc: introduce ePAPR embedded hypervisor hcall interface 2011-06-27 08:30:19 -05:00
fsl_lbc.h powerpc/85xx: Add lbc suspend support for PM 2011-11-24 02:01:40 -06:00
ftrace.h powerpc/ftrace: Implement raw syscall tracepoints on PowerPC 2011-05-26 13:38:57 +10:00
futex.h powerpc: Fix atomic_xxx_return barrier semantics 2011-11-17 16:26:07 +11:00
gpio.h
grackle.h
hardirq.h
heathrow.h
highmem.h mm: stack based kmap_atomic() 2010-10-26 16:52:08 -07:00
hugetlb.h powerpc: Define/use HUGETLB_NEED_PRELOAD insead of complicated #if 2011-12-07 16:26:24 +11:00
hvcall.h KVM: PPC: Handle some PAPR hcalls in the kernel 2011-07-12 13:16:55 +03:00
hvconsole.h
hvcserver.h
hvsi.h powerpc/hvsi: Fix conflict with old HVSI driver 2011-07-01 13:10:21 +10:00
hw_breakpoint.h perf, powerpc: Fix build borkage 2011-07-01 16:20:04 +02:00
hw_irq.h powerpc: Use ARCH_IRQ_INIT_FLAGS 2011-03-02 16:50:24 +11:00
hydra.h Update broken web addresses in arch directory. 2010-10-18 11:03:21 +02:00
i8259.h
ibmebus.h
ide.h
immap_cpm2.h
immap_qe.h powerpc: fix warning when compiling immap_qe.h 2011-01-12 18:02:46 -06:00
io-defs.h
io-workarounds.h powerpc/pci: Make IO workarounds init implicit when first bus is registered 2011-04-27 14:18:31 +10:00
io.h powerpc: Remove ioremap_flags 2011-05-19 14:30:43 +10:00
io_event_irq.h powerpc/pseries: Add support for IO event interrupts 2011-05-06 13:19:01 +10:00
ioctl.h
ioctls.h tty: add TIOCVHANGUP to allow clean tty shutdown of all ttys 2011-02-17 14:16:30 -08:00
iommu.h
ipcbuf.h
ipic.h
irq.h atomic: use <linux/atomic.h> 2011-07-26 16:49:47 -07:00
irq_regs.h
irqflags.h powerpc/ppc64/tracing: Add stack frame to calls of trace_hardirqs_on/off 2011-01-21 14:08:33 +11:00
jump_label.h powerpc: Jump label misalignment causes oops at boot 2011-08-05 14:47:55 +10:00
Kbuild powerpc: Use rwsem.h from generic location 2011-12-16 14:39:48 +11:00
kdebug.h
kdump.h powerpc: Move kdump default base address to half RMO size on 64bit 2011-08-05 14:47:56 +10:00
kexec.h powerpc: Cleanup crash/kexec code 2011-12-08 14:02:23 +11:00
keylargo.h
kgdb.h kgdb,ppc: Individual register get/set for ppc 2010-10-29 13:14:42 -05:00
kmap_types.h
kprobes.h Fix common misspellings 2011-03-31 11:26:23 -03:00
kvm.h Revert "KVM: PPC: Add support for explicit HIOR setting" 2011-11-17 16:30:25 +02:00
kvm_44x.h KVM: PPC: booke: add sregs support 2011-05-22 08:47:53 -04:00
kvm_asm.h KVM: PPC: Add support for Book3S processors in hypervisor mode 2011-07-12 13:16:54 +03:00
kvm_book3s.h Revert "KVM: PPC: Add support for explicit HIOR setting" 2011-11-17 16:30:25 +02:00
kvm_book3s_32.h
kvm_book3s_64.h KVM: PPC: Accelerate H_PUT_TCE by implementing it in real mode 2011-07-12 13:16:56 +03:00
kvm_book3s_asm.h KVM: PPC: Implement H_CEDE hcall for book3s_hv in real-mode code 2011-09-25 19:52:30 +03:00
kvm_booke.h KVM: PPC: Add support for Book3S processors in hypervisor mode 2011-07-12 13:16:54 +03:00
kvm_e500.h KVM: PPC: e500: Add shadow PID support 2011-07-12 13:16:39 +03:00
kvm_fpu.h powerpc: Remove fpscr use from [kvm_]cvt_{fd,df} 2010-09-02 14:07:32 +10:00
kvm_host.h KVM: PPC: Implement H_CEDE hcall for book3s_hv in real-mode code 2011-09-25 19:52:30 +03:00
kvm_para.h KVM: PPC: Move of include to __KERNEL__ section 2010-10-24 10:52:23 +02:00
kvm_ppc.h KVM: PPC: Add sanity checking to vcpu_run 2011-09-25 19:52:27 +03:00
libata-portmap.h
linkage.h
local.h atomic: use <linux/atomic.h> 2011-07-26 16:49:47 -07:00
local64.h
lppaca.h powerpc: Ensure dtl buffers do not cross 4k boundary 2011-05-19 14:30:41 +10:00
lv1call.h powerpc/ps3: Fix hcall lv1_read_repository_node 2011-12-08 14:05:55 +11:00
machdep.h powerpc/pci: Add a platform hook after probe and before resource survey 2011-11-25 14:32:53 +11:00
macio.h treewide: Convert uses of struct resource to resource_size(ptr) 2011-06-10 14:55:36 +02:00
mc146818rtc.h
mediabay.h
memblock.h
mman.h
mmu-8xx.h
mmu-40x.h
mmu-44x.h
mmu-book3e.h powerpc: Define/use HUGETLB_NEED_PRELOAD insead of complicated #if 2011-12-07 16:26:24 +11:00
mmu-hash32.h
mmu-hash64.h powerpc: Hugetlb for BookE 2011-09-20 09:19:40 +10:00
mmu.h powerpc: Hugetlb for BookE 2011-09-20 09:19:40 +10:00
mmu_context.h powerpc: Add Initiate Coprocessor Store Word (icswx) support 2011-05-04 15:19:26 +10:00
mmzone.h Fix node_start/end_pfn() definition for mm/page_cgroup.c 2011-06-27 14:13:09 -07:00
module.h
mpc5xxx.h
mpc6xx.h
mpc8xx.h
mpc52xx.h powerpc/5200: add mpc5200_psc_ac97_gpio_reset 2010-08-06 20:49:18 -06:00
mpc52xx_psc.h powerpc/5200: add mpc5200_psc_ac97_gpio_reset 2010-08-06 20:49:18 -06:00
mpc5121.h
mpc8260.h
mpic.h powerpc/mpic: Cache the device-tree node in "struct mpic" 2011-12-07 13:43:08 +11:00
msgbuf.h
msi_bitmap.h
mutex.h
nvram.h powerpc/nvram: Generalize code for OS partitions in NVRAM 2011-03-04 18:19:04 +11:00
ohare.h
opal.h powerpc/powernv: Update OPAL interfaces 2011-12-07 18:02:02 +11:00
oprofile_impl.h
paca.h powerpc: Provide a way for KVM to indicate that NV GPR values are lost 2011-12-08 14:22:53 +11:00
page.h powerpc: Implement CONFIG_STRICT_DEVMEM 2011-11-28 11:42:08 +11:00
page_32.h dma-mapping: rename ARCH_KMALLOC_MINALIGN to ARCH_DMA_MINALIGN 2010-08-11 08:59:21 -07:00
page_64.h powerpc: Only define HAVE_ARCH_HUGETLB_UNMAPPED_AREA if PPC_MM_SLICES 2011-12-07 16:26:21 +11:00
param.h
parport.h
pasemi_dma.h Fix common misspellings 2011-03-31 11:26:23 -03:00
pci-bridge.h powerpc/powernv: PCI support for p7IOC under OPAL v2 2011-11-25 14:53:15 +11:00
pci.h powerpc/pci: Make pci_read_irq_line() static 2011-12-07 18:04:58 +11:00
percpu.h
perf_event.h
perf_event_fsl_emb.h
perf_event_server.h
pgalloc-32.h
pgalloc-64.h
pgalloc.h mm, powerpc: move the RCU page-table freeing into generic code 2011-05-25 08:39:16 -07:00
pgtable-ppc32.h mm: remove pte_*map_nested() 2010-10-26 16:52:08 -07:00
pgtable-ppc64-4k.h
pgtable-ppc64-64k.h
pgtable-ppc64.h powerpc: Whitespace fix to include/asm/pgtable-ppc64.h 2011-06-29 17:48:16 +10:00
pgtable.h powerpc: Add pgprot_cached_noncoherent() 2011-11-25 14:32:52 +11:00
phyp_dump.h
pmac_feature.h Fix common misspellings 2011-03-31 11:26:23 -03:00
pmac_low_i2c.h
pmac_pfunc.h
pmc.h
pmi.h
poll.h
posix_types.h
ppc-opcode.h net: filter: BPF 'JIT' compiler for PPC64 2011-07-21 12:38:32 -07:00
ppc-pci.h powerpc/pci: Fix return type of BUID_{HI,LO} macros 2010-10-13 16:19:20 +11:00
ppc4xx.h
ppc_asm.h powerpc/e500: SPE register saving: take arbitrary struct offset 2011-07-12 13:16:31 +03:00
processor.h powerpc/cpuidle: Handle power_save=off 2011-12-08 13:57:34 +11:00
prom.h atomic: use <linux/atomic.h> 2011-07-26 16:49:47 -07:00
ps3.h
ps3av.h
ps3fb.h
ps3gpu.h
ps3stor.h
pSeries_reconfig.h powerpc/pseries: Introduce pSeries_reconfig_notify() 2011-06-29 17:48:22 +10:00
pte-8xx.h
pte-40x.h
pte-44x.h
pte-book3e.h powerpc: Hugetlb for BookE 2011-09-20 09:19:40 +10:00
pte-common.h powerpc: Don't write protect kernel text with CONFIG_DYNAMIC_FTRACE enabled 2011-04-18 13:08:21 +10:00
pte-fsl-booke.h
pte-hash32.h
pte-hash64-4k.h
pte-hash64-64k.h treewide: fix a few typos in comments 2011-05-10 10:16:21 +02:00
pte-hash64.h
ptrace.h powerpc/ptrace: Remove BUG_ON when full register set not available 2011-03-21 11:18:14 +11:00
qe.h doc: fix broken references 2011-09-27 18:08:04 +02:00
qe_ic.h powerpc: qe_ic: Rename get_irq_desc_data and get_irq_desc_chip 2011-03-30 15:38:02 +02:00
reg.h powerpc/476fpe: Add 476fpe SoC code 2011-12-09 07:51:02 -05:00
reg_8xx.h
reg_a2.h powerpc: Add early debug for WSP platforms 2011-05-06 13:32:41 +10:00
reg_booke.h powerpc/book3e: Add ICSWX/ACOP support to Book3e cores like A2 2011-11-25 14:11:28 +11:00
reg_fsl_emb.h
resource.h
rheap.h
rio.h powerpc/fsl_rio: Fix compile error when CONFIG_FSL_RIO not set 2011-06-02 15:29:08 -05:00
rtas.h powerpc: Punch a hole in /dev/mem for librtas 2011-12-08 14:22:52 +11:00
rtc.h
scatterlist.h remove needless ISA_DMA_THRESHOLD 2010-08-07 18:15:50 +02:00
scom.h powerpc: Add SCOM infrastructure 2011-04-20 17:01:19 +10:00
seccomp.h
sections.h powerpc: Copy down exception vectors after feature fixups 2011-11-16 14:47:54 +11:00
sembuf.h
serial.h
setjmp.h
setup.h powerpc: Fix build problem with default ppc_md.progress commit 2011-07-01 13:00:21 +10:00
sfp-machine.h
shmbuf.h
shmparam.h
sigcontext.h
siginfo.h
signal.h
smp.h powerpc/smp: More generic support for "soft hotplug" 2011-09-20 15:53:24 +10:00
smu.h treewide: fix potentially dangerous trailing ';' in #defined values/expressions 2011-07-21 14:10:00 +02:00
socket.h
sockios.h
sparsemem.h powerpc: Fix oops when echoing bad values to /sys/devices/system/memory/probe 2011-09-20 15:53:23 +10:00
spinlock.h
spinlock_types.h
spu.h powerpc: fix implicit use of mutex.h by include/asm/spu.h 2011-10-31 19:30:42 -04:00
spu_csa.h
spu_info.h
spu_priv1.h Fix common misspellings 2011-03-31 11:26:23 -03:00
sstep.h
stat.h
statfs.h
string.h
swab.h
swiotlb.h
synch.h powerpc: Fix atomic_xxx_return barrier semantics 2011-11-17 16:26:07 +11:00
syscall.h powerpc/ftrace: Implement raw syscall tracepoints on PowerPC 2011-05-26 13:38:57 +10:00
syscalls.h
systbl.h Cross Memory Attach 2011-10-31 17:30:44 -07:00
system.h Merge branch 'kexec' into next 2011-12-16 11:09:21 +11:00
tce.h powerpc/powernv: Add TCE SW invalidation support 2011-11-25 14:32:57 +11:00
termbits.h tty: Add EXTPROC support for LINEMODE 2010-08-10 13:47:39 -07:00
termios.h
thread_info.h powerpc/ftrace: Implement raw syscall tracepoints on PowerPC 2011-05-26 13:38:57 +10:00
time.h powerpc/time: Optimise decrementer_check_overflow 2011-11-25 14:11:26 +11:00
timex.h
tlb.h mm, powerpc: move the RCU page-table freeing into generic code 2011-05-25 08:39:16 -07:00
tlbflush.h powerpc/mm: Standardise on MMU_NO_CONTEXT 2011-04-20 16:59:20 +10:00
topology.h powerpc/numa: Remove duplicate RECLAIM_DISTANCE definition 2011-09-20 15:53:22 +10:00
trace.h
tsi108.h
tsi108_irq.h
tsi108_pci.h
types.h remove dma64_addr_t 2011-03-23 19:47:18 -07:00
uaccess.h
ucc.h
ucc_fast.h
ucc_slow.h
ucontext.h
udbg.h Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc 2011-11-06 17:12:03 -08:00
uic.h
unaligned.h
uninorth.h Revert wrong fixes for common misspellings 2011-04-26 23:31:11 -07:00
unistd.h Cross Memory Attach 2011-10-31 17:30:44 -07:00
user.h
vdso.h
vdso_datapage.h Fix common misspellings 2011-03-31 11:26:23 -03:00
vga.h
vio.h
wsp.h powerpc: Add WSP platform 2011-05-06 13:32:35 +10:00
xics.h powerpc/irq: Remove IRQF_DISABLED 2011-11-08 14:51:46 +11:00
xilinx_intc.h
xilinx_pci.h
xmon.h
xor.h