linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: Check __clang__ to avoid performance influence with GCC in csum_tcpudp_nofold()
@ 2021-03-08 12:50 Tiezhu Yang
  2021-03-08 16:52 ` David Laight
  0 siblings, 1 reply; 3+ messages in thread
From: Tiezhu Yang @ 2021-03-08 12:50 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Xuefeng Li

The asm code in csum_tcpudp_nofold() is performance-critical, I am sorry
for the poorly considered implementation about the performance influence
with GCC in the commit 198688edbf77 ("MIPS: Fix inline asm input/output
type mismatch in checksum.h used with Clang").

With this patch, we can build successfully by both GCC and Clang,
at the same time, we can avoid the potential performance influence
with GCC.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/mips/include/asm/checksum.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/mips/include/asm/checksum.h b/arch/mips/include/asm/checksum.h
index 1e6c135..64d353e 100644
--- a/arch/mips/include/asm/checksum.h
+++ b/arch/mips/include/asm/checksum.h
@@ -130,7 +130,9 @@ static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
 					__u32 len, __u8 proto,
 					__wsum sum)
 {
+#ifdef __clang__
 	unsigned long tmp = (__force unsigned long)sum;
+#endif
 
 	__asm__(
 	"	.set	push		# csum_tcpudp_nofold\n"
@@ -159,7 +161,11 @@ static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
 	"	addu	%0, $1		\n"
 #endif
 	"	.set	pop"
+#ifdef __clang__
 	: "=r" (tmp)
+#else
+	: "=r" (sum)
+#endif
 	: "0" ((__force unsigned long)daddr),
 	  "r" ((__force unsigned long)saddr),
 #ifdef __MIPSEL__
@@ -169,7 +175,11 @@ static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
 #endif
 	  "r" ((__force unsigned long)sum));
 
+#ifdef __clang__
 	return (__force __wsum)tmp;
+#else
+	return sum;
+#endif
 }
 #define csum_tcpudp_nofold csum_tcpudp_nofold
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] MIPS: Check __clang__ to avoid performance influence with GCC in csum_tcpudp_nofold()
  2021-03-08 12:50 [PATCH] MIPS: Check __clang__ to avoid performance influence with GCC in csum_tcpudp_nofold() Tiezhu Yang
@ 2021-03-08 16:52 ` David Laight
  2021-03-09  2:22   ` Tiezhu Yang
  0 siblings, 1 reply; 3+ messages in thread
From: David Laight @ 2021-03-08 16:52 UTC (permalink / raw)
  To: 'Tiezhu Yang', Thomas Bogendoerfer
  Cc: linux-mips, linux-kernel, Xuefeng Li

From: Tiezhu Yang
> Sent: 08 March 2021 12:50
> 
> The asm code in csum_tcpudp_nofold() is performance-critical, I am sorry
> for the poorly considered implementation about the performance influence
> with GCC in the commit 198688edbf77 ("MIPS: Fix inline asm input/output
> type mismatch in checksum.h used with Clang").
> 
> With this patch, we can build successfully by both GCC and Clang,
> at the same time, we can avoid the potential performance influence
> with GCC.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  arch/mips/include/asm/checksum.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/mips/include/asm/checksum.h b/arch/mips/include/asm/checksum.h
> index 1e6c135..64d353e 100644
> --- a/arch/mips/include/asm/checksum.h
> +++ b/arch/mips/include/asm/checksum.h
> @@ -130,7 +130,9 @@ static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
>  					__u32 len, __u8 proto,
>  					__wsum sum)
>  {
> +#ifdef __clang__
>  	unsigned long tmp = (__force unsigned long)sum;
> +#endif

What happens if you make the above:
#ifdef __clang__
	unsigned long tmp = (__force unsigned long)sum;
#else
	__wsum tmp = sum;
#endif
	
and then leave the rest of the function the same for both compilers.
Maybe do s/sum/sum_in/,s/tmp/sum/ to reduce the changes.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS: Check __clang__ to avoid performance influence with GCC in csum_tcpudp_nofold()
  2021-03-08 16:52 ` David Laight
@ 2021-03-09  2:22   ` Tiezhu Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Tiezhu Yang @ 2021-03-09  2:22 UTC (permalink / raw)
  To: David Laight, Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Xuefeng Li

On 03/09/2021 12:52 AM, David Laight wrote:
> From: Tiezhu Yang
>> Sent: 08 March 2021 12:50
>>
>> The asm code in csum_tcpudp_nofold() is performance-critical, I am sorry
>> for the poorly considered implementation about the performance influence
>> with GCC in the commit 198688edbf77 ("MIPS: Fix inline asm input/output
>> type mismatch in checksum.h used with Clang").
>>
>> With this patch, we can build successfully by both GCC and Clang,
>> at the same time, we can avoid the potential performance influence
>> with GCC.
>>
>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>> ---
>>   arch/mips/include/asm/checksum.h | 10 ++++++++++
>>   1 file changed, 10 insertions(+)
>>
>> diff --git a/arch/mips/include/asm/checksum.h b/arch/mips/include/asm/checksum.h
>> index 1e6c135..64d353e 100644
>> --- a/arch/mips/include/asm/checksum.h
>> +++ b/arch/mips/include/asm/checksum.h
>> @@ -130,7 +130,9 @@ static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
>>   					__u32 len, __u8 proto,
>>   					__wsum sum)
>>   {
>> +#ifdef __clang__
>>   	unsigned long tmp = (__force unsigned long)sum;
>> +#endif
> What happens if you make the above:
> #ifdef __clang__
> 	unsigned long tmp = (__force unsigned long)sum;
> #else
> 	__wsum tmp = sum;
> #endif
> 	
> and then leave the rest of the function the same for both compilers.
> Maybe do s/sum/sum_in/,s/tmp/sum/ to reduce the changes.

Hi David,

Thank you very much.

As you suggested, the following changes looks much better,
I will test it and then send v2 later.

diff --git a/arch/mips/include/asm/checksum.h 
b/arch/mips/include/asm/checksum.h
index 1e6c135..80eddd4 100644
--- a/arch/mips/include/asm/checksum.h
+++ b/arch/mips/include/asm/checksum.h
@@ -128,9 +128,13 @@ static inline __sum16 ip_fast_csum(const void *iph, 
unsigned int ihl)

  static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
                                         __u32 len, __u8 proto,
-                                       __wsum sum)
+                                       __wsum sum_in)
  {
-       unsigned long tmp = (__force unsigned long)sum;
+#ifdef __clang__
+       unsigned long sum = (__force unsigned long)sum_in;
+#else
+       __wsum sum = sum_in;
+#endif

         __asm__(
         "       .set    push            # csum_tcpudp_nofold\n"
@@ -159,7 +163,7 @@ static inline __wsum csum_tcpudp_nofold(__be32 
saddr, __be32 daddr,
         "       addu    %0, $1          \n"
  #endif
         "       .set    pop"
-       : "=r" (tmp)
+       : "=r" (sum)
         : "0" ((__force unsigned long)daddr),
           "r" ((__force unsigned long)saddr),
  #ifdef __MIPSEL__
@@ -169,7 +173,7 @@ static inline __wsum csum_tcpudp_nofold(__be32 
saddr, __be32 daddr,
  #endif
           "r" ((__force unsigned long)sum));

-       return (__force __wsum)tmp;
+       return (__force __wsum)sum;
  }
  #define csum_tcpudp_nofold csum_tcpudp_nofold

Thanks,
Tiezhu

>
> 	David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-09  2:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 12:50 [PATCH] MIPS: Check __clang__ to avoid performance influence with GCC in csum_tcpudp_nofold() Tiezhu Yang
2021-03-08 16:52 ` David Laight
2021-03-09  2:22   ` Tiezhu Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).