Skip to content

Commit cf8fb55

Browse files
antonblanchardozbenh
authored andcommitted
powerpc: Optimise the 64bit optimised __clear_user
I blame Mikey for this. He elevated my slightly dubious testcase: to benchmark status. And naturally we need to be number 1 at creating zeros. So lets improve __clear_user some more. As Paul suggests we can use dcbz for large lengths. This patch gets the destination cacheline aligned then uses dcbz on whole cachelines. Before: 10485760000 bytes (10 GB) copied, 0.414744 s, 25.3 GB/s After: 10485760000 bytes (10 GB) copied, 0.268597 s, 39.0 GB/s 39 GB/s, a new record. Signed-off-by: Anton Blanchard <anton@samba.org> Tested-by: Olof Johansson <olof@lixom.net> Acked-by: Olof Johansson <olof@lixom.net> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent b4c3a87 commit cf8fb55

1 file changed

Lines changed: 62 additions & 1 deletion

File tree

‎arch/powerpc/lib/string_64.S‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
*/
2020

2121
#include <asm/ppc_asm.h>
22+
#include <asm/asm-offsets.h>
23+
24+
.section ".toc","aw"
25+
PPC64_CACHES:
26+
.tc ppc64_caches[TC],ppc64_caches
27+
.section ".text"
2228

2329
/**
2430
* __clear_user: - Zero a block of memory in user space, with less checking.
@@ -94,9 +100,14 @@ err1; stw r0,0(r3)
94100
addi r3,r3,4
95101

96102
3: sub r4,r4,r6
97-
srdi r6,r4,5
103+
98104
cmpdi r4,32
105+
cmpdi cr1,r4,512
99106
blt .Lshort_clear
107+
bgt cr1,.Llong_clear
108+
109+
.Lmedium_clear:
110+
srdi r6,r4,5
100111
mtctr r6
101112

102113
/* Do 32 byte chunks */
@@ -139,3 +150,53 @@ err1; stb r0,0(r3)
139150

140151
10: li r3,0
141152
blr
153+
154+
.Llong_clear:
155+
ld r5,PPC64_CACHES@toc(r2)
156+
157+
bf cr7*4+0,11f
158+
err2; std r0,0(r3)
159+
addi r3,r3,8
160+
addi r4,r4,-8
161+
162+
/* Destination is 16 byte aligned, need to get it cacheline aligned */
163+
11: lwz r7,DCACHEL1LOGLINESIZE(r5)
164+
lwz r9,DCACHEL1LINESIZE(r5)
165+
166+
/*
167+
* With worst case alignment the long clear loop takes a minimum
168+
* of 1 byte less than 2 cachelines.
169+
*/
170+
sldi r10,r9,2
171+
cmpd r4,r10
172+
blt .Lmedium_clear
173+
174+
neg r6,r3
175+
addi r10,r9,-1
176+
and. r5,r6,r10
177+
beq 13f
178+
179+
srdi r6,r5,4
180+
mtctr r6
181+
mr r8,r3
182+
12:
183+
err1; std r0,0(r3)
184+
err1; std r0,8(r3)
185+
addi r3,r3,16
186+
bdnz 12b
187+
188+
sub r4,r4,r5
189+
190+
13: srd r6,r4,r7
191+
mtctr r6
192+
mr r8,r3
193+
14:
194+
err1; dcbz r0,r3
195+
add r3,r3,r9
196+
bdnz 14b
197+
198+
and r4,r4,r10
199+
200+
cmpdi r4,32
201+
blt .Lshort_clear
202+
b .Lmedium_clear

0 commit comments

Comments
 (0)