linux/arch/arm/lib
Nicolas Pitre 7549423000 [ARM] 2947/1: copy template with new memcpy/memmove
Patch from Nicolas Pitre

This patch provides a new implementation for optimized memory copy
functions on ARM.  It is made of two levels: a template that consists of
the core copy code and separate files that define macros to be used with
the core code depending on the type of copy needed. This allows for best
performances while sharing the same core for implementing memcpy(),
copy_from_user() and copy_to_user() for instance.

Two reasons for this work:

1) the current copy_to_user/copy_from_user implementation assumes no
   task switch will ever occur in the middle of each copied page making
   it completely unsafe with CONFIG_PREEMPT=y.

2) current copy implementations are measurably suboptimal and optimizing
   different implementations separately is a pain and more opportunities
   for bugs.

The reason for (1) is the fact that copy inside user pages are performed
with the ldm instruction which has no mean for testing user protections
and could possibly race with process preemption bypassing the COW mechanism
for example.  This is a longstanding issue that we said ought to be fixed
for about two years now.  The solution is to substitute those ldm insns
with a series of ldrt or strt insns to enforce user memory protection.
At least on StrongARM and XScale cores the ldm is not faster than the
equivalent ldr/str insns with a warm i-cache so there is no measurable
performance degradation with that change. The fact that the copy code is
a template makes it pretty easy to reuse the same core code as for memcpy
and benefit from the same performance optimizations.

Now (2) is best demonstrated with actual throughput measurements.
First, here is a summary of memcopy tests performed on a StrongARM core:

	PTR alignment	buffer size	kernel version	this version
	------------------------------------------------------------
	  aligned	     32		 59.73		107.43
	unaligned	     32		 61.31		 74.72
	  aligned	    100		132.47		136.15
	unaligned	    100	    	103.84		123.76
	  aligned	   4096		130.67		130.80
	unaligned	   4096	    	130.68		130.64
	  aligned	1048576		 68.03		68.18
	unaligned	1048576		 68.03		68.18

The buffer size is in bytes and the measured speed in MB/s.  The copy
was performed repeatedly with given buffer and throughput averaged over
3 seconds.

Here we can see that the current kernel version has a higher entry cost
that shows up with small buffers.  As buffer size grows both implementation
converge to the same throughput.

Now here's the exact same test performed on an XScale core (PXA255):

	PTR alignment	buffer size	kernel version	this version
	------------------------------------------------------------
	  aligned	     32		 46.99		 77.58
	unaligned	     32		 53.61		 59.59
	  aligned	    100		107.19		136.59
	unaligned	    100		 83.61		 97.58
	  aligned	   4096		129.13		129.98
	unaligned	   4096		128.36		128.53
	  aligned	1048576		 53.76		 59.41
	unaligned	1048576		 33.67		 56.96

Again we can see the entry setup cost being higher for the current kernel
before getting to the main copy loop.  Then throughput results converge
as long as the buffer remains in the cache. Then the 1MB case shows more
differences probably due to better pld placement and/or less instruction
interlocks in this proposed implementation.

Disclaimer: The PXA system was running with slower clocks than the
StrongARM system so trying to infer any conclusion by comparing those
separate sets of results side by side would be completely inappropriate.

So...  What this patch does is to replace both memcpy and memmove with
an implementation based on the provided copy code template.  The memmove
code is kept separate since it is used only if the memory areas involved
do overlap in which case the code is a transposition of the template but
with the copy occurring in the opposite direction (trying to fit that
mode into the template turned it into a mess not worth it for memmove
alone).  And obviously both memcpy and memmove were tested with all kinds
of pointer alignments and buffer sizes to exercise all code paths for
correctness.

The next patch will provide the now trivial replacement implementation
copy_to_user and copy_from_user.

Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2005-11-01 19:52:23 +00:00
..
ashldi3.S [ARM] 3049/1: More optimized libgcc functions 2005-10-30 23:08:03 +00:00
ashrdi3.S [ARM] 3049/1: More optimized libgcc functions 2005-10-30 23:08:03 +00:00
backtrace.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
bitops.h [ARM SMP] Only enable V6K instructions on V6 MP core CPUs 2005-08-10 14:41:45 +01:00
changebit.S [PATCH] ARM: bitops 2005-04-17 15:51:02 +01:00
clear_user.S [ARM] 2946/2: split --arch_clear_user() out of lib/uaccess.S 2005-11-01 19:52:22 +00:00
clearbit.S [PATCH] ARM: bitops 2005-04-17 15:51:02 +01:00
copy_page.S kbuild: arm - use generic asm-offsets.h support 2005-09-09 21:08:59 +02:00
copy_template.S [ARM] 2947/1: copy template with new memcpy/memmove 2005-11-01 19:52:23 +00:00
csumipv6.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
csumpartial.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
csumpartialcopy.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
csumpartialcopygeneric.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
csumpartialcopyuser.S kbuild: arm - use generic asm-offsets.h support 2005-09-09 21:08:59 +02:00
delay.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
div64.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
ecard.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
findbit.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
floppydma.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
getuser.S kbuild: arm - use generic asm-offsets.h support 2005-09-09 21:08:59 +02:00
io-acorn.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
io-readsb.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
io-readsl.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
io-readsw-armv3.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
io-readsw-armv4.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
io-shark.c [PATCH] ARM: 2815/1: Shark: new defconfig, fixes with __io and serial ports 2005-07-16 17:17:18 +01:00
io-writesb.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
io-writesl.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
io-writesw-armv3.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
io-writesw-armv4.S [PATCH] ARM: 2705/1: fix writesw for misaligned source pointer 2005-06-08 19:00:16 +01:00
lib1funcs.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
lshrdi3.S [ARM] 3049/1: More optimized libgcc functions 2005-10-30 23:08:03 +00:00
Makefile [ARM] 2947/1: copy template with new memcpy/memmove 2005-11-01 19:52:23 +00:00
memchr.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
memcpy.S [ARM] 2947/1: copy template with new memcpy/memmove 2005-11-01 19:52:23 +00:00
memmove.S [ARM] 2947/1: copy template with new memcpy/memmove 2005-11-01 19:52:23 +00:00
memset.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
memzero.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
muldi3.S [ARM] 3049/1: More optimized libgcc functions 2005-10-30 23:08:03 +00:00
putuser.S kbuild: arm - use generic asm-offsets.h support 2005-09-09 21:08:59 +02:00
setbit.S [PATCH] ARM: bitops 2005-04-17 15:51:02 +01:00
sha1.S [ARM] 2930/1: optimized sha1 implementation for ARM 2005-10-28 15:26:40 +01:00
strchr.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
strncpy_from_user.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
strnlen_user.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
strrchr.S Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
testchangebit.S [PATCH] ARM: bitops 2005-04-17 15:51:02 +01:00
testclearbit.S [PATCH] ARM: bitops 2005-04-17 15:51:02 +01:00
testsetbit.S [PATCH] ARM: bitops 2005-04-17 15:51:02 +01:00
uaccess.S [ARM] 2946/2: split --arch_clear_user() out of lib/uaccess.S 2005-11-01 19:52:22 +00:00
ucmpdi2.S [ARM] 3049/1: More optimized libgcc functions 2005-10-30 23:08:03 +00:00