Skip to contentSkip to conversation

powerpc/lib: Optimisation of memcmp() and __clear_user() for PPC32

PATCH In review Christophe Leroy 2 participants 4 messages May 30, 2018 – Jun 4, 2018 PowerPC

lore
Share & tools
lore
#0 lore raw

v6 cover powerpc/lib: Optimisation of memcmp() and __clear_user() for PPC32

This serie intends to optimise memcmp() and __clear_user() for PPC32 in the same spirit as already done on PPC64.

The first patch rewrites __clear_user() by using dcbz intruction The second patch rewrites memcmp() to compare 32 bits words instead of comparing byte per byte.

As shown in each individual commit log, second and third patches provide significant improvment.

Changes in v6:
- Dropped first patch of the serie which was just moving memcmp() and __clear_user() into new string_32.S file
- As suggested by Mathieu, to be consistant with PPC64:
- __clear_user() is moved into new file string_32.S
- memcmp() is moved into new file memcmp_32.S
- Removed unneccessary included header files.

Changes in v5:
- Removed the handling of Little Endian, as PPC32 kernel only support Big Endian at the time being, and because unaligned accesses should be handled differently in LE.

Changes in v4:
- In memcmp(), dropped the special handling for when length is 0. Handling it through the small length path.

Changes in v3:
- Fixed the sign of the result returned by memcmp() by using a logical comparison of u32 words and returning -1, 0 or 1 instead of doing a substract.
- In first patch, replaced PPC_LCMPI by cmpwi
- Fixed licence in string_32.S
- Removed the two last patches from the serie. They will be handled later as they require further tests and analysis to properly identify their real benefit in all possible cases.

Changes in v2:
- Moved out the patch removing the hot loop alignment on PPC32
- Squashed the changes related to NUL size verification in a single patch
- Reordered the patches in a more logical order
- Modified the inlining patch to avoid warning about impossibility to version symbols.

Christophe Leroy (2):
powerpc/lib: optimise 32 bits __clear_user()
powerpc/lib: optimise PPC32 memcmp

 arch/powerpc/lib/Makefile    |  5 ++-
 arch/powerpc/lib/memcmp_32.S | 45 ++++++++++++++++++++++
 arch/powerpc/lib/string.S    | 63 -------------------------------
 arch/powerpc/lib/string_32.S | 90 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 138 insertions(+), 65 deletions(-)
 create mode 100644 arch/powerpc/lib/memcmp_32.S
 create mode 100644 arch/powerpc/lib/string_32.S
Signature · 1 line
2.13.3
#1 lore raw

PATCH v6 1/2 powerpc/lib: optimise 32 bits __clear_user()

Rewrite clear_user() on the same principle as memset(0), making use of dcbz to clear complete cache lines.

This code is a copy/paste of memset(), with some modifications in order to retrieve remaining number of bytes to be cleared, as it needs to be returned in case of error.

On the same way as done on PPC64 in commit 17968fbbd19f1 ("powerpc: 64bit optimised __clear_user"), the patch moves __clear_user() into a dedicated file string_32.S

On a MPC885, throughput is almost doubled:

Before:
~# dd if=/dev/zero of=/dev/null bs=1M count=1000 1048576000 bytes (1000.0MB) copied, 18.990779 seconds, 52.7MB/s

After:
~# dd if=/dev/zero of=/dev/null bs=1M count=1000 1048576000 bytes (1000.0MB) copied, 9.611468 seconds, 104.0MB/s

On a MPC8321, throughput is multiplied by 2.12:

Before:

root@vgoippro:~# dd if=/dev/zero of=/dev/null bs=1M count=1000
1048576000 bytes (1000.0MB) copied, 6.844352 seconds, 146.1MB/s

After:

root@vgoippro:~# dd if=/dev/zero of=/dev/null bs=1M count=1000
1048576000 bytes (1000.0MB) copied, 3.218854 seconds, 310.7MB/s
---
 arch/powerpc/lib/Makefile    |  5 ++-
 arch/powerpc/lib/string.S    | 46 ----------------------
 arch/powerpc/lib/string_32.S | 90 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 48 deletions(-)
 create mode 100644 arch/powerpc/lib/string_32.S
arch/powerpc/lib/Makefile +3 -2
index 653901042ad7..2c9b8c0adf22 100644
@@ -26,13 +26,14 @@ obj-$(CONFIG_PPC_BOOK3S_64) += copyuser_power7.o copypage_power7.o \
 			       memcpy_power7.o
 
 obj64-y	+= copypage_64.o copyuser_64.o mem_64.o hweight_64.o \
-	   string_64.o memcpy_64.o memcmp_64.o pmem.o
+	   memcpy_64.o memcmp_64.o pmem.o
 
 obj64-$(CONFIG_SMP)	+= locks.o
 obj64-$(CONFIG_ALTIVEC)	+= vmx-helper.o
 obj64-$(CONFIG_KPROBES_SANITY_TEST) += test_emulate_step.o
 
-obj-y			+= checksum_$(BITS).o checksum_wrappers.o
+obj-y			+= checksum_$(BITS).o checksum_wrappers.o \
+			   string_$(BITS).o
 
 obj-y			+= sstep.o ldstfp.o quad.o
 obj64-y			+= quad.o
arch/powerpc/lib/string.S +0 -46

55 lines not on this page · raw message

arch/powerpc/lib/string_32.S new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
2.13.3
#2 lore raw

Re: [v6,1/2] powerpc/lib: optimise 32 bits __clear_user()

Quoted 24 lines · Christophe Leroy

Rewrite clear_user() on the same principle as memset(0), making use of dcbz to clear complete cache lines.

This code is a copy/paste of memset(), with some modifications in order to retrieve remaining number of bytes to be cleared, as it needs to be returned in case of error.

On the same way as done on PPC64 in commit 17968fbbd19f1 ("powerpc: 64bit optimised __clear_user"), the patch moves __clear_user() into a dedicated file string_32.S

On a MPC885, throughput is almost doubled:

Before:
~# dd if=/dev/zero of=/dev/null bs=1M count=1000 1048576000 bytes (1000.0MB) copied, 18.990779 seconds, 52.7MB/s

After:
~# dd if=/dev/zero of=/dev/null bs=1M count=1000 1048576000 bytes (1000.0MB) copied, 9.611468 seconds, 104.0MB/s

On a MPC8321, throughput is multiplied by 2.12:

Before:

Quoted 8 lines
root@vgoippro:~# dd if=/dev/zero of=/dev/null bs=1M count=1000
1048576000 bytes (1000.0MB) copied, 6.844352 seconds, 146.1MB/s

After:

root@vgoippro:~# dd if=/dev/zero of=/dev/null bs=1M count=1000
1048576000 bytes (1000.0MB) copied, 3.218854 seconds, 310.7MB/s

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f36bbf21e8b911b3c629fd36d4d217

cheers

#3 lore raw

PATCH v6 2/2 powerpc/lib: optimise PPC32 memcmp

In reply to Christophe Leroy

At the time being, memcmp() compares two chunks of memory byte per byte.

This patch optimises the comparison by comparing word by word.

On the same way as commit 15c2d45d17418 ("powerpc: Add 64bit optimised memcmp"), this patch moves memcmp() into a dedicated file named memcmp_32.S

A small benchmark performed on an 8xx comparing two chuncks of 512 bytes performed 100000 times gives:

Before : 5852274 TB ticks
After:   1488638 TB ticks

This is almost 4 times faster

---
 arch/powerpc/lib/Makefile    |  4 ++--
 arch/powerpc/lib/memcmp_32.S | 45 ++++++++++++++++++++++++++++++++++++++++++++
 arch/powerpc/lib/string.S    | 17 -----------------
 3 files changed, 47 insertions(+), 19 deletions(-)
 create mode 100644 arch/powerpc/lib/memcmp_32.S
arch/powerpc/lib/Makefile +2 -2
index 2c9b8c0adf22..d0ca13ad8231 100644
@@ -26,14 +26,14 @@ obj-$(CONFIG_PPC_BOOK3S_64) += copyuser_power7.o copypage_power7.o \
 			       memcpy_power7.o
 
 obj64-y	+= copypage_64.o copyuser_64.o mem_64.o hweight_64.o \
-	   memcpy_64.o memcmp_64.o pmem.o
+	   memcpy_64.o pmem.o
 
 obj64-$(CONFIG_SMP)	+= locks.o
 obj64-$(CONFIG_ALTIVEC)	+= vmx-helper.o
 obj64-$(CONFIG_KPROBES_SANITY_TEST) += test_emulate_step.o
 
 obj-y			+= checksum_$(BITS).o checksum_wrappers.o \
-			   string_$(BITS).o
+			   string_$(BITS).o memcmp_$(BITS).o
 
 obj-y			+= sstep.o ldstfp.o quad.o
 obj64-y			+= quad.o
arch/powerpc/lib/memcmp_32.S new file +45 -0

45 lines not on this page · raw message

arch/powerpc/lib/string.S +0 -17
index 5343a88e619e..4b41970e9ed8 100644
@@ -54,23 +54,6 @@ _GLOBAL(strncmp)
 	blr
 EXPORT_SYMBOL(strncmp)
 
-#ifdef CONFIG_PPC32
-_GLOBAL(memcmp)
-	PPC_LCMPI 0,r5,0
-	beq-	2f
-	mtctr	r5
-	addi	r6,r3,-1
-	addi	r4,r4,-1
-1:	lbzu	r3,1(r6)
-	lbzu	r0,1(r4)
-	subf.	r3,r0,r3
-	bdnzt	2,1b
-	blr
-2:	li	r3,0
-	blr
-EXPORT_SYMBOL(memcmp)
-#endif
-
 _GLOBAL(memchr)
 	PPC_LCMPI 0,r5,0
 	beq-	2f
Signature · 1 line
2.13.3