Commit 7aef4136 authored by Christophe Leroy's avatar Christophe Leroy Committed by Scott Wood

powerpc32: rewrite csum_partial_copy_generic() based on copy_tofrom_user()

csum_partial_copy_generic() does the same as copy_tofrom_user and also
calculates the checksum during the copy. Unlike copy_tofrom_user(),
the existing version of csum_partial_copy_generic() doesn't take
benefit of the cache.

This patch is a rewrite of csum_partial_copy_generic() based on
copy_tofrom_user().
The previous version of csum_partial_copy_generic() was handling
errors. Now we have the checksum wrapper functions to handle the error
case like in powerpc64 so we can make the error case simple:
just return -EFAULT.
copy_tofrom_user() only has r12 available => we use it for the
checksum r7 and r8 which contains pointers to error feedback are used,
so we stack them.

On a TCP benchmark using socklib on the loopback interface on which
checksum offload and scatter/gather have been deactivated, we get
about 20% performance increase.
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: default avatarScott Wood <oss@buserror.net>
parent 37e08cad
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/sys.h> #include <linux/sys.h>
#include <asm/processor.h> #include <asm/processor.h>
#include <asm/cache.h>
#include <asm/errno.h> #include <asm/errno.h>
#include <asm/ppc_asm.h> #include <asm/ppc_asm.h>
...@@ -66,123 +67,220 @@ _GLOBAL(csum_partial) ...@@ -66,123 +67,220 @@ _GLOBAL(csum_partial)
* *
* csum_partial_copy_generic(src, dst, len, sum, src_err, dst_err) * csum_partial_copy_generic(src, dst, len, sum, src_err, dst_err)
*/ */
#define CSUM_COPY_16_BYTES_WITHEX(n) \
8 ## n ## 0: \
lwz r7,4(r4); \
8 ## n ## 1: \
lwz r8,8(r4); \
8 ## n ## 2: \
lwz r9,12(r4); \
8 ## n ## 3: \
lwzu r10,16(r4); \
8 ## n ## 4: \
stw r7,4(r6); \
adde r12,r12,r7; \
8 ## n ## 5: \
stw r8,8(r6); \
adde r12,r12,r8; \
8 ## n ## 6: \
stw r9,12(r6); \
adde r12,r12,r9; \
8 ## n ## 7: \
stwu r10,16(r6); \
adde r12,r12,r10
#define CSUM_COPY_16_BYTES_EXCODE(n) \
.section __ex_table,"a"; \
.align 2; \
.long 8 ## n ## 0b,src_error; \
.long 8 ## n ## 1b,src_error; \
.long 8 ## n ## 2b,src_error; \
.long 8 ## n ## 3b,src_error; \
.long 8 ## n ## 4b,dst_error; \
.long 8 ## n ## 5b,dst_error; \
.long 8 ## n ## 6b,dst_error; \
.long 8 ## n ## 7b,dst_error; \
.text
.text
.stabs "arch/powerpc/lib/",N_SO,0,0,0f
.stabs "checksum_32.S",N_SO,0,0,0f
0:
CACHELINE_BYTES = L1_CACHE_BYTES
LG_CACHELINE_BYTES = L1_CACHE_SHIFT
CACHELINE_MASK = (L1_CACHE_BYTES-1)
_GLOBAL(csum_partial_copy_generic) _GLOBAL(csum_partial_copy_generic)
addic r0,r6,0 stwu r1,-16(r1)
subi r3,r3,4 stw r7,12(r1)
subi r4,r4,4 stw r8,8(r1)
srwi. r6,r5,2
beq 3f /* if we're doing < 4 bytes */ andi. r0,r4,1 /* is destination address even ? */
andi. r9,r4,2 /* Align dst to longword boundary */ cmplwi cr7,r0,0
beq+ 1f addic r12,r6,0
81: lhz r6,4(r3) /* do 2 bytes to get aligned */ addi r6,r4,-4
addi r3,r3,2 neg r0,r4
subi r5,r5,2 addi r4,r3,-4
91: sth r6,4(r4) andi. r0,r0,CACHELINE_MASK /* # bytes to start of cache line */
addi r4,r4,2 beq 58f
addc r0,r0,r6
srwi. r6,r5,2 /* # words to do */ cmplw 0,r5,r0 /* is this more than total to do? */
beq 3f blt 63f /* if not much to do */
1: srwi. r6,r5,4 /* # groups of 4 words to do */ andi. r8,r0,3 /* get it word-aligned first */
beq 10f mtctr r8
mtctr r6 beq+ 61f
71: lwz r6,4(r3) li r3,0
72: lwz r9,8(r3) 70: lbz r9,4(r4) /* do some bytes */
73: lwz r10,12(r3) addi r4,r4,1
74: lwzu r11,16(r3) slwi r3,r3,8
adde r0,r0,r6 rlwimi r3,r9,0,24,31
75: stw r6,4(r4) 71: stb r9,4(r6)
adde r0,r0,r9 addi r6,r6,1
76: stw r9,8(r4) bdnz 70b
adde r0,r0,r10 adde r12,r12,r3
77: stw r10,12(r4) 61: subf r5,r0,r5
adde r0,r0,r11 srwi. r0,r0,2
78: stwu r11,16(r4) mtctr r0
bdnz 71b beq 58f
10: rlwinm. r6,r5,30,30,31 /* # words left to do */ 72: lwzu r9,4(r4) /* do some words */
beq 13f adde r12,r12,r9
mtctr r6 73: stwu r9,4(r6)
82: lwzu r9,4(r3) bdnz 72b
92: stwu r9,4(r4)
adde r0,r0,r9 58: srwi. r0,r5,LG_CACHELINE_BYTES /* # complete cachelines */
bdnz 82b clrlwi r5,r5,32-LG_CACHELINE_BYTES
13: andi. r5,r5,3 li r11,4
3: cmpwi 0,r5,2 beq 63f
blt+ 4f
83: lhz r6,4(r3) /* Here we decide how far ahead to prefetch the source */
addi r3,r3,2 li r3,4
subi r5,r5,2 cmpwi r0,1
93: sth r6,4(r4) li r7,0
ble 114f
li r7,1
#if MAX_COPY_PREFETCH > 1
/* Heuristically, for large transfers we prefetch
MAX_COPY_PREFETCH cachelines ahead. For small transfers
we prefetch 1 cacheline ahead. */
cmpwi r0,MAX_COPY_PREFETCH
ble 112f
li r7,MAX_COPY_PREFETCH
112: mtctr r7
111: dcbt r3,r4
addi r3,r3,CACHELINE_BYTES
bdnz 111b
#else
dcbt r3,r4
addi r3,r3,CACHELINE_BYTES
#endif /* MAX_COPY_PREFETCH > 1 */
114: subf r8,r7,r0
mr r0,r7
mtctr r8
53: dcbt r3,r4
54: dcbz r11,r6
/* the main body of the cacheline loop */
CSUM_COPY_16_BYTES_WITHEX(0)
#if L1_CACHE_BYTES >= 32
CSUM_COPY_16_BYTES_WITHEX(1)
#if L1_CACHE_BYTES >= 64
CSUM_COPY_16_BYTES_WITHEX(2)
CSUM_COPY_16_BYTES_WITHEX(3)
#if L1_CACHE_BYTES >= 128
CSUM_COPY_16_BYTES_WITHEX(4)
CSUM_COPY_16_BYTES_WITHEX(5)
CSUM_COPY_16_BYTES_WITHEX(6)
CSUM_COPY_16_BYTES_WITHEX(7)
#endif
#endif
#endif
bdnz 53b
cmpwi r0,0
li r3,4
li r7,0
bne 114b
63: srwi. r0,r5,2
mtctr r0
beq 64f
30: lwzu r0,4(r4)
adde r12,r12,r0
31: stwu r0,4(r6)
bdnz 30b
64: andi. r0,r5,2
beq+ 65f
40: lhz r0,4(r4)
addi r4,r4,2 addi r4,r4,2
adde r0,r0,r6 41: sth r0,4(r6)
4: cmpwi 0,r5,1 adde r12,r12,r0
bne+ 5f addi r6,r6,2
84: lbz r6,4(r3) 65: andi. r0,r5,1
94: stb r6,4(r4) beq+ 66f
slwi r6,r6,8 /* Upper byte of word */ 50: lbz r0,4(r4)
adde r0,r0,r6 51: stb r0,4(r6)
5: addze r3,r0 /* add in final carry */ slwi r0,r0,8
adde r12,r12,r0
66: addze r3,r12
addi r1,r1,16
beqlr+ cr7
rlwinm r3,r3,8,0,31 /* swap bytes for odd destination */
blr blr
/* These shouldn't go in the fixup section, since that would /* read fault */
cause the ex_table addresses to get out of order. */
src_error_4:
mfctr r6 /* update # bytes remaining from ctr */
rlwimi r5,r6,4,0,27
b 79f
src_error_1:
li r6,0
subi r5,r5,2
95: sth r6,4(r4)
addi r4,r4,2
79: srwi. r6,r5,2
beq 3f
mtctr r6
src_error_2:
li r6,0
96: stwu r6,4(r4)
bdnz 96b
3: andi. r5,r5,3
beq src_error
src_error_3:
li r6,0
mtctr r5
addi r4,r4,3
97: stbu r6,1(r4)
bdnz 97b
src_error: src_error:
cmpwi 0,r7,0 lwz r7,12(r1)
beq 1f addi r1,r1,16
li r6,-EFAULT cmpwi cr0,r7,0
stw r6,0(r7) beqlr
1: addze r3,r0 li r0,-EFAULT
stw r0,0(r7)
blr blr
/* write fault */
dst_error: dst_error:
cmpwi 0,r8,0 lwz r8,8(r1)
beq 1f addi r1,r1,16
li r6,-EFAULT cmpwi cr0,r8,0
stw r6,0(r8) beqlr
1: addze r3,r0 li r0,-EFAULT
stw r0,0(r8)
blr blr
.section __ex_table,"a" .section __ex_table,"a"
.long 81b,src_error_1 .align 2
.long 91b,dst_error .long 70b,src_error
.long 71b,src_error_4 .long 71b,dst_error
.long 72b,src_error_4 .long 72b,src_error
.long 73b,src_error_4 .long 73b,dst_error
.long 74b,src_error_4 .long 54b,dst_error
.long 75b,dst_error .text
.long 76b,dst_error
.long 77b,dst_error /*
.long 78b,dst_error * this stuff handles faults in the cacheline loop and branches to either
.long 82b,src_error_2 * src_error (if in read part) or dst_error (if in write part)
.long 92b,dst_error */
.long 83b,src_error_3 CSUM_COPY_16_BYTES_EXCODE(0)
.long 93b,dst_error #if L1_CACHE_BYTES >= 32
.long 84b,src_error_3 CSUM_COPY_16_BYTES_EXCODE(1)
.long 94b,dst_error #if L1_CACHE_BYTES >= 64
.long 95b,dst_error CSUM_COPY_16_BYTES_EXCODE(2)
.long 96b,dst_error CSUM_COPY_16_BYTES_EXCODE(3)
.long 97b,dst_error #if L1_CACHE_BYTES >= 128
CSUM_COPY_16_BYTES_EXCODE(4)
CSUM_COPY_16_BYTES_EXCODE(5)
CSUM_COPY_16_BYTES_EXCODE(6)
CSUM_COPY_16_BYTES_EXCODE(7)
#endif
#endif
#endif
.section __ex_table,"a"
.align 2
.long 30b,src_error
.long 31b,dst_error
.long 40b,src_error
.long 41b,dst_error
.long 50b,src_error
.long 51b,dst_error
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment