Skip to content

Commit ff5fdaf

Browse files
Nicolas PitreRussell King
authored andcommitted
ARM: 8745/1: get rid of __memzero()
The __memzero assembly code is almost identical to memset's except for two orr instructions. The runtime performance of __memset(p, n) and memset(p, 0, n) is accordingly almost identical. However, the memset() macro used to guard against a zero length and to call __memzero at compile time when the fill value is a constant zero interferes with compiler optimizations. Arnd found tha the test against a zero length brings up some new warnings with gcc v8: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82103 And successively rremoving the test against a zero length and the call to __memzero optimization produces the following kernel sizes for defconfig with gcc 6: text data bss dec hex filename 12248142 6278960 413588 18940690 1210312 vmlinux.orig 12244474 6278960 413588 1893702 120f4be vmlinux.no_zero_test 12239160 6278960 413588 18931708 120dffc vmlinux.no_memzero So it is probably not worth keeping __memzero around given that the compiler can do a better job at inlining trivial memset(p,0,n) on its own. And the memset code already handles a zero length just fine. Suggested-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Nicolas Pitre <nico@linaro.org> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
1 parent ec80eb4 commit ff5fdaf

7 files changed

Lines changed: 5 additions & 161 deletions

File tree

‎arch/arm/boot/compressed/string.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,3 @@ void *memset(void *s, int c, size_t count)
130130
*xs++ = c;
131131
return s;
132132
}
133-
134-
void __memzero(void *s, size_t count)
135-
{
136-
memset(s, 0, count);
137-
}

‎arch/arm/include/asm/string.h‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,4 @@ static inline void *memset64(uint64_t *p, uint64_t v, __kernel_size_t n)
3939
return __memset64(p, v, n * 8, v >> 32);
4040
}
4141

42-
extern void __memzero(void *ptr, __kernel_size_t n);
43-
44-
#define memset(p,v,n) \
45-
({ \
46-
void *__p = (p); size_t __n = n; \
47-
if ((__n) != 0) { \
48-
if (__builtin_constant_p((v)) && (v) == 0) \
49-
__memzero((__p),(__n)); \
50-
else \
51-
memset((__p),(v),(__n)); \
52-
} \
53-
(__p); \
54-
})
55-
5642
#endif

‎arch/arm/kernel/armksyms.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ EXPORT_SYMBOL(__memset64);
9292
EXPORT_SYMBOL(memcpy);
9393
EXPORT_SYMBOL(memmove);
9494
EXPORT_SYMBOL(memchr);
95-
EXPORT_SYMBOL(__memzero);
9695

9796
EXPORT_SYMBOL(mmioset);
9897
EXPORT_SYMBOL(mmiocpy);

‎arch/arm/kernel/head-common.S‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ __mmap_switched:
105105
ARM( ldmia r4!, {r0, r1, sp} )
106106
THUMB( ldmia r4!, {r0, r1, r3} )
107107
THUMB( mov sp, r3 )
108-
sub r1, r1, r0
109-
bl __memzero @ clear .bss
108+
sub r2, r1, r0
109+
mov r1, #0
110+
bl memset @ clear .bss
110111

111112
ldmia r4, {r0, r1, r2, r3}
112113
str r9, [r0] @ Save processor ID

‎arch/arm/lib/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
lib-y := backtrace.o changebit.o csumipv6.o csumpartial.o \
99
csumpartialcopy.o csumpartialcopyuser.o clearbit.o \
1010
delay.o delay-loop.o findbit.o memchr.o memcpy.o \
11-
memmove.o memset.o memzero.o setbit.o \
11+
memmove.o memset.o setbit.o \
1212
strchr.o strrchr.o \
1313
testchangebit.o testclearbit.o testsetbit.o \
1414
ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \

‎arch/arm/lib/memzero.S‎

Lines changed: 0 additions & 137 deletions
This file was deleted.

‎drivers/dma/imx-dma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ static int imxdma_alloc_chan_resources(struct dma_chan *chan)
765765
desc = kzalloc(sizeof(*desc), GFP_KERNEL);
766766
if (!desc)
767767
break;
768-
__memzero(&desc->desc, sizeof(struct dma_async_tx_descriptor));
768+
memset(&desc->desc, 0, sizeof(struct dma_async_tx_descriptor));
769769
dma_async_tx_descriptor_init(&desc->desc, chan);
770770
desc->desc.tx_submit = imxdma_tx_submit;
771771
/* txd.flags will be overwritten in prep funcs */

0 commit comments

Comments
 (0)