Skip to content

Commit 58a6d5f

Browse files
chleroygregkh
authored andcommitted
net: Force inlining of checksum functions in net/checksum.h
commit 5486f5b upstream. All functions defined as static inline in net/checksum.h are meant to be inlined for performance reason. But since commit ac7c3e4 ("compiler: enable CONFIG_OPTIMIZE_INLINING forcibly") the compiler is allowed to uninline functions when it wants. Fair enough in the general case, but for tiny performance critical checksum helpers that's counter-productive. The problem mainly arises when selecting CONFIG_CC_OPTIMISE_FOR_SIZE, Those helpers being 'static inline' in header files you suddenly find them duplicated many times in the resulting vmlinux. Here is a typical exemple when building powerpc pmac32_defconfig with CONFIG_CC_OPTIMISE_FOR_SIZE. csum_sub() appears 4 times: c04a23cc <csum_sub>: c04a23cc: 7c 84 20 f8 not r4,r4 c04a23d0: 7c 63 20 14 addc r3,r3,r4 c04a23d4: 7c 63 01 94 addze r3,r3 c04a23d8: 4e 80 00 20 blr ... c04a2ce8: 4b ff f6 e5 bl c04a23cc <csum_sub> ... c04a2d2c: 4b ff f6 a1 bl c04a23cc <csum_sub> ... c04a2d5: 4b ff f6 79 bl c04a23cc <csum_sub> ... c04a754c <csum_sub>: c04a754c: 7c 84 20 f8 not r4,r4 c04a7550: 7c 63 20 14 addc r3,r3,r4 c04a7554: 7c 63 01 94 addze r3,r3 c04a7558: 4e 80 00 20 blr ... c04ac930: 4b ff ac 1d bl c04a754c <csum_sub> ... c04ad264: 4b ff a2 e9 bl c04a754c <csum_sub> ... c04e3b08 <csum_sub>: c04e3b08: 7c 84 20 f8 not r4,r4 c04e3b0c: 7c 63 20 14 addc r3,r3,r4 c04e3b10: 7c 63 01 94 addze r3,r3 c04e3b14: 4e 80 00 20 blr ... c04e5788: 4b ff e3 81 bl c04e3b08 <csum_sub> ... c04e65c8: 4b ff d5 41 bl c04e3b08 <csum_sub> ... c0512d34 <csum_sub>: c0512d34: 7c 84 20 f8 not r4,r4 c0512d38: 7c 63 20 14 addc r3,r3,r4 c0512d3c: 7c 63 01 94 addze r3,r3 c0512d40: 4e 80 00 20 blr ... c0512dfc: 4b ff ff 39 bl c0512d34 <csum_sub> ... c05138bc: 4b ff f4 79 bl c0512d34 <csum_sub> ... Restore the expected behaviour by using __always_inline for all functions defined in net/checksum.h vmlinux size is even reduced by 256 bytes with this patch: text data bss dec hex filename 6980022 2515362 194384 9689768 93daa8 vmlinux.before 6979862 2515266 194384 9689512 93d9a8 vmlinux.now Fixes: ac7c3e4 ("compiler: enable CONFIG_OPTIMIZE_INLINING forcibly") Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 550d98a commit 58a6d5f

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

‎include/net/checksum.h‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <asm/checksum.h>
2323

2424
#ifndef _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
25-
static inline
25+
static __always_inline
2626
__wsum csum_and_copy_from_user (const void __user *src, void *dst,
2727
int len)
2828
{
@@ -33,7 +33,7 @@ __wsum csum_and_copy_from_user (const void __user *src, void *dst,
3333
#endif
3434

3535
#ifndef HAVE_CSUM_COPY_USER
36-
static __inline__ __wsum csum_and_copy_to_user
36+
static __always_inline __wsum csum_and_copy_to_user
3737
(const void *src, void __user *dst, int len)
3838
{
3939
__wsum sum = csum_partial(src, len, ~0U);
@@ -45,7 +45,7 @@ static __inline__ __wsum csum_and_copy_to_user
4545
#endif
4646

4747
#ifndef _HAVE_ARCH_CSUM_AND_COPY
48-
static inline __wsum
48+
static __always_inline __wsum
4949
csum_partial_copy_nocheck(const void *src, void *dst, int len)
5050
{
5151
memcpy(dst, src, len);
@@ -54,33 +54,33 @@ csum_partial_copy_nocheck(const void *src, void *dst, int len)
5454
#endif
5555

5656
#ifndef HAVE_ARCH_CSUM_ADD
57-
static inline __wsum csum_add(__wsum csum, __wsum addend)
57+
static __always_inline __wsum csum_add(__wsum csum, __wsum addend)
5858
{
5959
u32 res = (__force u32)csum;
6060
res += (__force u32)addend;
6161
return (__force __wsum)(res + (res < (__force u32)addend));
6262
}
6363
#endif
6464

65-
static inline __wsum csum_sub(__wsum csum, __wsum addend)
65+
static __always_inline __wsum csum_sub(__wsum csum, __wsum addend)
6666
{
6767
return csum_add(csum, ~addend);
6868
}
6969

70-
static inline __sum16 csum16_add(__sum16 csum, __be16 addend)
70+
static __always_inline __sum16 csum16_add(__sum16 csum, __be16 addend)
7171
{
7272
u16 res = (__force u16)csum;
7373

7474
res += (__force u16)addend;
7575
return (__force __sum16)(res + (res < (__force u16)addend));
7676
}
7777

78-
static inline __sum16 csum16_sub(__sum16 csum, __be16 addend)
78+
static __always_inline __sum16 csum16_sub(__sum16 csum, __be16 addend)
7979
{
8080
return csum16_add(csum, ~addend);
8181
}
8282

83-
static inline __wsum
83+
static __always_inline __wsum
8484
csum_block_add(__wsum csum, __wsum csum2, int offset)
8585
{
8686
u32 sum = (__force u32)csum2;
@@ -92,36 +92,37 @@ csum_block_add(__wsum csum, __wsum csum2, int offset)
9292
return csum_add(csum, (__force __wsum)sum);
9393
}
9494

95-
static inline __wsum
95+
static __always_inline __wsum
9696
csum_block_add_ext(__wsum csum, __wsum csum2, int offset, int len)
9797
{
9898
return csum_block_add(csum, csum2, offset);
9999
}
100100

101-
static inline __wsum
101+
static __always_inline __wsum
102102
csum_block_sub(__wsum csum, __wsum csum2, int offset)
103103
{
104104
return csum_block_add(csum, ~csum2, offset);
105105
}
106106

107-
static inline __wsum csum_unfold(__sum16 n)
107+
static __always_inline __wsum csum_unfold(__sum16 n)
108108
{
109109
return (__force __wsum)n;
110110
}
111111

112-
static inline __wsum csum_partial_ext(const void *buff, int len, __wsum sum)
112+
static __always_inline
113+
__wsum csum_partial_ext(const void *buff, int len, __wsum sum)
113114
{
114115
return csum_partial(buff, len, sum);
115116
}
116117

117118
#define CSUM_MANGLED_0 ((__force __sum16)0xffff)
118119

119-
static inline void csum_replace_by_diff(__sum16 *sum, __wsum diff)
120+
static __always_inline void csum_replace_by_diff(__sum16 *sum, __wsum diff)
120121
{
121122
*sum = csum_fold(csum_add(diff, ~csum_unfold(*sum)));
122123
}
123124

124-
static inline void csum_replace4(__sum16 *sum, __be32 from, __be32 to)
125+
static __always_inline void csum_replace4(__sum16 *sum, __be32 from, __be32 to)
125126
{
126127
__wsum tmp = csum_sub(~csum_unfold(*sum), (__force __wsum)from);
127128

@@ -134,7 +135,7 @@ static inline void csum_replace4(__sum16 *sum, __be32 from, __be32 to)
134135
* m : old value of a 16bit field
135136
* m' : new value of a 16bit field
136137
*/
137-
static inline void csum_replace2(__sum16 *sum, __be16 old, __be16 new)
138+
static __always_inline void csum_replace2(__sum16 *sum, __be16 old, __be16 new)
138139
{
139140
*sum = ~csum16_add(csum16_sub(~(*sum), old), new);
140141
}
@@ -153,16 +154,16 @@ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
153154
void inet_proto_csum_replace_by_diff(__sum16 *sum, struct sk_buff *skb,
154155
__wsum diff, bool pseudohdr);
155156

156-
static inline void inet_proto_csum_replace2(__sum16 *sum, struct sk_buff *skb,
157-
__be16 from, __be16 to,
158-
bool pseudohdr)
157+
static __always_inline
158+
void inet_proto_csum_replace2(__sum16 *sum, struct sk_buff *skb,
159+
__be16 from, __be16 to, bool pseudohdr)
159160
{
160161
inet_proto_csum_replace4(sum, skb, (__force __be32)from,
161162
(__force __be32)to, pseudohdr);
162163
}
163164

164-
static inline __wsum remcsum_adjust(void *ptr, __wsum csum,
165-
int start, int offset)
165+
static __always_inline __wsum remcsum_adjust(void *ptr, __wsum csum,
166+
int start, int offset)
166167
{
167168
__sum16 *psum = (__sum16 *)(ptr + offset);
168169
__wsum delta;
@@ -178,7 +179,7 @@ static inline __wsum remcsum_adjust(void *ptr, __wsum csum,
178179
return delta;
179180
}
180181

181-
static inline void remcsum_unadjust(__sum16 *psum, __wsum delta)
182+
static __always_inline void remcsum_unadjust(__sum16 *psum, __wsum delta)
182183
{
183184
*psum = csum_fold(csum_sub(delta, (__force __wsum)*psum));
184185
}

0 commit comments

Comments
 (0)