DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
@ 2018-08-28 20:46 Malvika Gupta
  2018-08-28 20:58 ` Honnappa Nagarahalli
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Malvika Gupta @ 2018-08-28 20:46 UTC (permalink / raw)
  To: konstantin.ananyev
  Cc: dev, gavin.hu, honnappa.nagarahalli, brian.brooks, nd,
	Malvika Gupta, Malvika Gupta

Convert host machine endianness to networking endianness for
comparison of incoming packets with BPF filter


Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
Reviewed-by: Brian Brooks <brian.brooks@arm.com>
Suggested-by: Brian Brooks <brian.brooks@arm.com>
---
 test/bpf/t1.c | 7 ++++---
 test/bpf/t3.c | 3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/test/bpf/t1.c b/test/bpf/t1.c
index 60f9434ab..7943fcf34 100644
--- a/test/bpf/t1.c
+++ b/test/bpf/t1.c
@@ -28,24 +28,25 @@
 #include <net/ethernet.h>
 #include <netinet/ip.h>
 #include <netinet/udp.h>
+#include <arpa/inet.h>
 
 uint64_t
 entry(void *pkt)
 {
 	struct ether_header *ether_header = (void *)pkt;
 
-	if (ether_header->ether_type != __builtin_bswap16(0x0800))
+	if (ether_header->ether_type != htons(0x0800))
 		return 0;
 
 	struct iphdr *iphdr = (void *)(ether_header + 1);
 	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
-			iphdr->daddr != __builtin_bswap32(0x1020304))
+			iphdr->daddr != htonl(0x1020304))
 		return 0;
 
 	int hlen = iphdr->ihl * 4;
 	struct udphdr *udphdr = (void *)iphdr + hlen;
 
-	if (udphdr->dest !=  __builtin_bswap16(5000))
+	if (udphdr->dest != htons(5000))
 		return 0;
 
 	return 1;
diff --git a/test/bpf/t3.c b/test/bpf/t3.c
index 531b9cb8c..24298b7c7 100644
--- a/test/bpf/t3.c
+++ b/test/bpf/t3.c
@@ -17,6 +17,7 @@
 #include <net/ethernet.h>
 #include <rte_config.h>
 #include "mbuf.h"
+#include <arpa/inet.h>
 
 extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned int);
 
@@ -29,7 +30,7 @@ entry(const void *pkt)
 	mb = pkt;
 	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
 
-	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
+	if (eth->ether_type == htons(ETHERTYPE_ARP))
 		rte_pktmbuf_dump(stdout, mb, 64);
 
 	return 1;
-- 
2.17.1

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

* Re: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
  2018-08-28 20:46 [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap Malvika Gupta
@ 2018-08-28 20:58 ` Honnappa Nagarahalli
  2018-09-04 13:56 ` Ananyev, Konstantin
  2018-11-02 19:08 ` [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap Malvika Gupta
  2 siblings, 0 replies; 13+ messages in thread
From: Honnappa Nagarahalli @ 2018-08-28 20:58 UTC (permalink / raw)
  To: Malvika Gupta, konstantin.ananyev
  Cc: dev, Gavin Hu, Brian Brooks, nd, Malvika Gupta, Malvika Gupta



-----Original Message-----
From: Malvika Gupta <Malvika.Gupta@arm.com> 
Sent: Tuesday, August 28, 2018 3:46 PM
To: konstantin.ananyev@intel.com
Cc: dev@dpdk.org; Gavin Hu <Gavin.Hu@arm.com>; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Brian Brooks <Brian.Brooks@arm.com>; nd <nd@arm.com>; Malvika Gupta <Malvika.Gupta@arm.com>; Malvika Gupta <Malvika.Gupta@arm.com>
Subject: [PATCH] test/bpf: use hton instead of __builtin_bswap

Convert host machine endianness to networking endianness for comparison of incoming packets with BPF filter


Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
Reviewed-by: Brian Brooks <brian.brooks@arm.com>
Suggested-by: Brian Brooks <brian.brooks@arm.com>
---
 test/bpf/t1.c | 7 ++++---
 test/bpf/t3.c | 3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/test/bpf/t1.c b/test/bpf/t1.c index 60f9434ab..7943fcf34 100644
--- a/test/bpf/t1.c
+++ b/test/bpf/t1.c
@@ -28,24 +28,25 @@
 #include <net/ethernet.h>
 #include <netinet/ip.h>
 #include <netinet/udp.h>
+#include <arpa/inet.h>
 
 uint64_t
 entry(void *pkt)
 {
 	struct ether_header *ether_header = (void *)pkt;
 
-	if (ether_header->ether_type != __builtin_bswap16(0x0800))
+	if (ether_header->ether_type != htons(0x0800))
 		return 0;
 
 	struct iphdr *iphdr = (void *)(ether_header + 1);
 	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
-			iphdr->daddr != __builtin_bswap32(0x1020304))
+			iphdr->daddr != htonl(0x1020304))
 		return 0;
 
 	int hlen = iphdr->ihl * 4;
 	struct udphdr *udphdr = (void *)iphdr + hlen;
 
-	if (udphdr->dest !=  __builtin_bswap16(5000))
+	if (udphdr->dest != htons(5000))
 		return 0;
 
 	return 1;
diff --git a/test/bpf/t3.c b/test/bpf/t3.c index 531b9cb8c..24298b7c7 100644
--- a/test/bpf/t3.c
+++ b/test/bpf/t3.c
@@ -17,6 +17,7 @@
 #include <net/ethernet.h>
 #include <rte_config.h>
 #include "mbuf.h"
+#include <arpa/inet.h>
 
 extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned int);
 
@@ -29,7 +30,7 @@ entry(const void *pkt)
 	mb = pkt;
 	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
 
-	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
+	if (eth->ether_type == htons(ETHERTYPE_ARP))
 		rte_pktmbuf_dump(stdout, mb, 64);
 
 	return 1;
--
2.17.1

Compiled and tested.
Acked-by: Honnappa Nagarahalli <Honnappa.nagarahalli@arm.com>

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

* Re: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
  2018-08-28 20:46 [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap Malvika Gupta
  2018-08-28 20:58 ` Honnappa Nagarahalli
@ 2018-09-04 13:56 ` Ananyev, Konstantin
  2018-09-05 21:43   ` Malvika Gupta
  2018-11-02 19:08 ` [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap Malvika Gupta
  2 siblings, 1 reply; 13+ messages in thread
From: Ananyev, Konstantin @ 2018-09-04 13:56 UTC (permalink / raw)
  To: Malvika Gupta; +Cc: dev, gavin.hu, honnappa.nagarahalli, brian.brooks, nd

Hi,

> 
> Convert host machine endianness to networking endianness for
> comparison of incoming packets with BPF filter
> 
> 
> Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> Reviewed-by: Brian Brooks <brian.brooks@arm.com>
> Suggested-by: Brian Brooks <brian.brooks@arm.com>
> ---
>  test/bpf/t1.c | 7 ++++---
>  test/bpf/t3.c | 3 ++-
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/test/bpf/t1.c b/test/bpf/t1.c
> index 60f9434ab..7943fcf34 100644
> --- a/test/bpf/t1.c
> +++ b/test/bpf/t1.c
> @@ -28,24 +28,25 @@
>  #include <net/ethernet.h>
>  #include <netinet/ip.h>
>  #include <netinet/udp.h>
> +#include <arpa/inet.h>
> 
>  uint64_t
>  entry(void *pkt)
>  {
>  	struct ether_header *ether_header = (void *)pkt;
> 
> -	if (ether_header->ether_type != __builtin_bswap16(0x0800))
> +	if (ether_header->ether_type != htons(0x0800))

Which version of clang do you use?
With my one I get:
$ clang -O2 -target bpf -c t1.c
t1.c:37:34: error: couldn't allocate output register for constraint 'r'
        if (ether_header->ether_type != ntohs(0x0800))
                                        ^
/usr/include/netinet/in.h:402:21: note: expanded from macro 'ntohs'
#   define ntohs(x)     __bswap_16 (x)
                        ^
/usr/include/bits/byteswap-16.h:31:14: note: expanded from macro '__bswap_16'
           __asm__ ("rorw $8, %w0"  

With '-O0' it compiles ok.

$ clang -v
clang version 4.0.1 (tags/RELEASE_401/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

Konstantin

>  		return 0;
> 
>  	struct iphdr *iphdr = (void *)(ether_header + 1);
>  	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
> -			iphdr->daddr != __builtin_bswap32(0x1020304))
> +			iphdr->daddr != htonl(0x1020304))
>  		return 0;
> 
>  	int hlen = iphdr->ihl * 4;
>  	struct udphdr *udphdr = (void *)iphdr + hlen;
> 
> -	if (udphdr->dest !=  __builtin_bswap16(5000))
> +	if (udphdr->dest != htons(5000))
>  		return 0;
> 
>  	return 1;
> diff --git a/test/bpf/t3.c b/test/bpf/t3.c
> index 531b9cb8c..24298b7c7 100644
> --- a/test/bpf/t3.c
> +++ b/test/bpf/t3.c
> @@ -17,6 +17,7 @@
>  #include <net/ethernet.h>
>  #include <rte_config.h>
>  #include "mbuf.h"
> +#include <arpa/inet.h>
> 
>  extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned int);
> 
> @@ -29,7 +30,7 @@ entry(const void *pkt)
>  	mb = pkt;
>  	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
> 
> -	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
> +	if (eth->ether_type == htons(ETHERTYPE_ARP))
>  		rte_pktmbuf_dump(stdout, mb, 64);
> 
>  	return 1;
> --
> 2.17.1

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

* Re: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
  2018-09-04 13:56 ` Ananyev, Konstantin
@ 2018-09-05 21:43   ` Malvika Gupta
  2018-09-12 18:46     ` Malvika Gupta
  0 siblings, 1 reply; 13+ messages in thread
From: Malvika Gupta @ 2018-09-05 21:43 UTC (permalink / raw)
  To: Ananyev, Konstantin
  Cc: dev, Gavin Hu (Arm Technology China),
	Honnappa Nagarahalli, Brian Brooks, nd

Hi Ananyev,

I used clang version 6.0.0. Please see the following output for your reference. 

$ clang -v 
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8.0.1
Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

Also, the code compiles with both -O2 and -O0 for me. 

I hope this was helpful
Best,
Malvika

-----Original Message-----
From: Ananyev, Konstantin <konstantin.ananyev@intel.com> 
Sent: Tuesday, September 4, 2018 8:56 AM
To: Malvika Gupta <Malvika.Gupta@arm.com>
Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Brian Brooks <Brian.Brooks@arm.com>; nd <nd@arm.com>
Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap

Hi,

> 
> Convert host machine endianness to networking endianness for 
> comparison of incoming packets with BPF filter
> 
> 
> Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> Reviewed-by: Brian Brooks <brian.brooks@arm.com>
> Suggested-by: Brian Brooks <brian.brooks@arm.com>
> ---
>  test/bpf/t1.c | 7 ++++---
>  test/bpf/t3.c | 3 ++-
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/test/bpf/t1.c b/test/bpf/t1.c index 60f9434ab..7943fcf34 
> 100644
> --- a/test/bpf/t1.c
> +++ b/test/bpf/t1.c
> @@ -28,24 +28,25 @@
>  #include <net/ethernet.h>
>  #include <netinet/ip.h>
>  #include <netinet/udp.h>
> +#include <arpa/inet.h>
> 
>  uint64_t
>  entry(void *pkt)
>  {
>  	struct ether_header *ether_header = (void *)pkt;
> 
> -	if (ether_header->ether_type != __builtin_bswap16(0x0800))
> +	if (ether_header->ether_type != htons(0x0800))

Which version of clang do you use?
With my one I get:
$ clang -O2 -target bpf -c t1.c
t1.c:37:34: error: couldn't allocate output register for constraint 'r'
        if (ether_header->ether_type != ntohs(0x0800))
                                        ^
/usr/include/netinet/in.h:402:21: note: expanded from macro 'ntohs'
#   define ntohs(x)     __bswap_16 (x)
                        ^
/usr/include/bits/byteswap-16.h:31:14: note: expanded from macro '__bswap_16'
           __asm__ ("rorw $8, %w0"  

With '-O0' it compiles ok.

$ clang -v
clang version 4.0.1 (tags/RELEASE_401/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

Konstantin

>  		return 0;
> 
>  	struct iphdr *iphdr = (void *)(ether_header + 1);
>  	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
> -			iphdr->daddr != __builtin_bswap32(0x1020304))
> +			iphdr->daddr != htonl(0x1020304))
>  		return 0;
> 
>  	int hlen = iphdr->ihl * 4;
>  	struct udphdr *udphdr = (void *)iphdr + hlen;
> 
> -	if (udphdr->dest !=  __builtin_bswap16(5000))
> +	if (udphdr->dest != htons(5000))
>  		return 0;
> 
>  	return 1;
> diff --git a/test/bpf/t3.c b/test/bpf/t3.c index 531b9cb8c..24298b7c7 
> 100644
> --- a/test/bpf/t3.c
> +++ b/test/bpf/t3.c
> @@ -17,6 +17,7 @@
>  #include <net/ethernet.h>
>  #include <rte_config.h>
>  #include "mbuf.h"
> +#include <arpa/inet.h>
> 
>  extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, 
> unsigned int);
> 
> @@ -29,7 +30,7 @@ entry(const void *pkt)
>  	mb = pkt;
>  	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
> 
> -	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
> +	if (eth->ether_type == htons(ETHERTYPE_ARP))
>  		rte_pktmbuf_dump(stdout, mb, 64);
> 
>  	return 1;
> --
> 2.17.1

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

* Re: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
  2018-09-05 21:43   ` Malvika Gupta
@ 2018-09-12 18:46     ` Malvika Gupta
  2018-10-19 12:17       ` Ananyev, Konstantin
  0 siblings, 1 reply; 13+ messages in thread
From: Malvika Gupta @ 2018-09-12 18:46 UTC (permalink / raw)
  To: Ananyev, Konstantin
  Cc: dev, Gavin Hu (Arm Technology China), Honnappa Nagarahalli, nd

Hi Konstantin,

I installed the clang version 4.0.1 to check for the issue you were facing with -O2 compilation. I was able to compile with -O2 and -O0 optimization without any errors. Please see the exact command I used and the following output for your reference:

$ clang -O2 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c 
$ clang -O0 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c
$ clang -v
clang version 4.0.1-10 (tags/RELEASE_401/final)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8.0.1
Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

I hope this was helpful to you.
Best Regards,
Malvika Gupta


-----Original Message-----
From: Malvika Gupta 
Sent: Wednesday, September 5, 2018 4:43 PM
To: Ananyev, Konstantin <konstantin.ananyev@intel.com>
Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Brian Brooks <Brian.Brooks@arm.com>; nd <nd@arm.com>
Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap

Hi Ananyev,

I used clang version 6.0.0. Please see the following output for your reference. 

$ clang -v
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6 Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7 Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8 Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8.0.1
Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

Also, the code compiles with both -O2 and -O0 for me. 

I hope this was helpful
Best,
Malvika

-----Original Message-----
From: Ananyev, Konstantin <konstantin.ananyev@intel.com>
Sent: Tuesday, September 4, 2018 8:56 AM
To: Malvika Gupta <Malvika.Gupta@arm.com>
Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Brian Brooks <Brian.Brooks@arm.com>; nd <nd@arm.com>
Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap

Hi,

> 
> Convert host machine endianness to networking endianness for 
> comparison of incoming packets with BPF filter
> 
> 
> Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> Reviewed-by: Brian Brooks <brian.brooks@arm.com>
> Suggested-by: Brian Brooks <brian.brooks@arm.com>
> ---
>  test/bpf/t1.c | 7 ++++---
>  test/bpf/t3.c | 3 ++-
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/test/bpf/t1.c b/test/bpf/t1.c index 60f9434ab..7943fcf34
> 100644
> --- a/test/bpf/t1.c
> +++ b/test/bpf/t1.c
> @@ -28,24 +28,25 @@
>  #include <net/ethernet.h>
>  #include <netinet/ip.h>
>  #include <netinet/udp.h>
> +#include <arpa/inet.h>
> 
>  uint64_t
>  entry(void *pkt)
>  {
>  	struct ether_header *ether_header = (void *)pkt;
> 
> -	if (ether_header->ether_type != __builtin_bswap16(0x0800))
> +	if (ether_header->ether_type != htons(0x0800))

Which version of clang do you use?
With my one I get:
$ clang -O2 -target bpf -c t1.c
t1.c:37:34: error: couldn't allocate output register for constraint 'r'
        if (ether_header->ether_type != ntohs(0x0800))
                                        ^
/usr/include/netinet/in.h:402:21: note: expanded from macro 'ntohs'
#   define ntohs(x)     __bswap_16 (x)
                        ^
/usr/include/bits/byteswap-16.h:31:14: note: expanded from macro '__bswap_16'
           __asm__ ("rorw $8, %w0"  

With '-O0' it compiles ok.

$ clang -v
clang version 4.0.1 (tags/RELEASE_401/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

Konstantin

>  		return 0;
> 
>  	struct iphdr *iphdr = (void *)(ether_header + 1);
>  	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
> -			iphdr->daddr != __builtin_bswap32(0x1020304))
> +			iphdr->daddr != htonl(0x1020304))
>  		return 0;
> 
>  	int hlen = iphdr->ihl * 4;
>  	struct udphdr *udphdr = (void *)iphdr + hlen;
> 
> -	if (udphdr->dest !=  __builtin_bswap16(5000))
> +	if (udphdr->dest != htons(5000))
>  		return 0;
> 
>  	return 1;
> diff --git a/test/bpf/t3.c b/test/bpf/t3.c index 531b9cb8c..24298b7c7
> 100644
> --- a/test/bpf/t3.c
> +++ b/test/bpf/t3.c
> @@ -17,6 +17,7 @@
>  #include <net/ethernet.h>
>  #include <rte_config.h>
>  #include "mbuf.h"
> +#include <arpa/inet.h>
> 
>  extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, 
> unsigned int);
> 
> @@ -29,7 +30,7 @@ entry(const void *pkt)
>  	mb = pkt;
>  	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
> 
> -	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
> +	if (eth->ether_type == htons(ETHERTYPE_ARP))
>  		rte_pktmbuf_dump(stdout, mb, 64);
> 
>  	return 1;
> --
> 2.17.1

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

* Re: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
  2018-09-12 18:46     ` Malvika Gupta
@ 2018-10-19 12:17       ` Ananyev, Konstantin
  2018-10-25 16:59         ` Malvika Gupta
  0 siblings, 1 reply; 13+ messages in thread
From: Ananyev, Konstantin @ 2018-10-19 12:17 UTC (permalink / raw)
  To: Malvika Gupta
  Cc: dev, Gavin Hu (Arm Technology China), Honnappa Nagarahalli, nd


Hi Malvika,

> 
> Hi Konstantin,
> 
> I installed the clang version 4.0.1 to check for the issue you were facing with -O2 compilation. I was able to compile with -O2 and -O0
> optimization without any errors. Please see the exact command I used and the following output for your reference:
> 
> $ clang -O2 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c
> $ clang -O0 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c
> $ clang -v
> clang version 4.0.1-10 (tags/RELEASE_401/final)
> Target: aarch64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8.0.1
> Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> Candidate multilib: .;@m64
> Selected multilib: .;@m64
> 
> I hope this was helpful to you.

Sorry for delay.
I tried with clang 6.0, but still seeing same issue.
Digging a bit more, I think the culprit is here:

#ifdef __GNUC__
# if __GNUC__ >= 2
#  define __bswap_16(x) \
     (__extension__                                                           \
      ({ unsigned short int __v, __x = (unsigned short int) (x);              \
         if (__builtin_constant_p (__x))                                      \     <------ evaluates to FALSE !!!
           __v = __bswap_constant_16 (__x);                                   \
         else                                                                 \
           __asm__ ("rorw $8, %w0"                                            \
                    : "=r" (__v)                                              \
                    : "0" (__x)                                               \
                    : "cc");                                                  \
         __v; }))
# else
/* This is better than nothing.  */
#  define __bswap_16(x) \
     (__extension__                                                           \
      ({ unsigned short int __x = (unsigned short int) (x);                   \
         __bswap_constant_16 (__x); }))
# endif
#else
static __inline unsigned short int
__bswap_16 (unsigned short int __bsx)
{
  return __bswap_constant_16 (__bsx);
}
#endif

Seems that gcc and clang implements __builtin_constant_p in a different way.
Let say, the following function:
int bbb1(void) {uint16_t x=0; return__bswap_constant_16(x);}
when compiled with gcc would return 1, while when compiled with clang - 0.
Adding 'const' to definition of 'x' cures the problem for clang.
I don't know why there is no 'const' in original __bswap_16() macro. 
To overcome that problem, I used:
clang -O2 -U__GNUC__ -target bpf -c t1.c

Another possible option - define our own analogs for buitin hton*().
Konstantin


> Best Regards,
> Malvika Gupta
> 
> 
> -----Original Message-----
> From: Malvika Gupta
> Sent: Wednesday, September 5, 2018 4:43 PM
> To: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>;
> Brian Brooks <Brian.Brooks@arm.com>; nd <nd@arm.com>
> Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> 
> Hi Ananyev,
> 
> I used clang version 6.0.0. Please see the following output for your reference.
> 
> $ clang -v
> clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
> Target: aarch64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8
> Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6 Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7 Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8 Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8.0.1
> Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> Candidate multilib: .;@m64
> Selected multilib: .;@m64
> 
> Also, the code compiles with both -O2 and -O0 for me.
> 
> I hope this was helpful
> Best,
> Malvika
> 
> -----Original Message-----
> From: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Sent: Tuesday, September 4, 2018 8:56 AM
> To: Malvika Gupta <Malvika.Gupta@arm.com>
> Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>;
> Brian Brooks <Brian.Brooks@arm.com>; nd <nd@arm.com>
> Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> 
> Hi,
> 
> >
> > Convert host machine endianness to networking endianness for
> > comparison of incoming packets with BPF filter
> >
> >
> > Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> > Reviewed-by: Brian Brooks <brian.brooks@arm.com>
> > Suggested-by: Brian Brooks <brian.brooks@arm.com>
> > ---
> >  test/bpf/t1.c | 7 ++++---
> >  test/bpf/t3.c | 3 ++-
> >  2 files changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/test/bpf/t1.c b/test/bpf/t1.c index 60f9434ab..7943fcf34
> > 100644
> > --- a/test/bpf/t1.c
> > +++ b/test/bpf/t1.c
> > @@ -28,24 +28,25 @@
> >  #include <net/ethernet.h>
> >  #include <netinet/ip.h>
> >  #include <netinet/udp.h>
> > +#include <arpa/inet.h>
> >
> >  uint64_t
> >  entry(void *pkt)
> >  {
> >  	struct ether_header *ether_header = (void *)pkt;
> >
> > -	if (ether_header->ether_type != __builtin_bswap16(0x0800))
> > +	if (ether_header->ether_type != htons(0x0800))
> 
> Which version of clang do you use?
> With my one I get:
> $ clang -O2 -target bpf -c t1.c
> t1.c:37:34: error: couldn't allocate output register for constraint 'r'
>         if (ether_header->ether_type != ntohs(0x0800))
>                                         ^
> /usr/include/netinet/in.h:402:21: note: expanded from macro 'ntohs'
> #   define ntohs(x)     __bswap_16 (x)
>                         ^
> /usr/include/bits/byteswap-16.h:31:14: note: expanded from macro '__bswap_16'
>            __asm__ ("rorw $8, %w0"
> 
> With '-O0' it compiles ok.
> 
> $ clang -v
> clang version 4.0.1 (tags/RELEASE_401/final)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
> Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
> Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
> Candidate multilib: .;@m64
> Candidate multilib: 32;@m32
> Selected multilib: .;@m64
> 
> Konstantin
> 
> >  		return 0;
> >
> >  	struct iphdr *iphdr = (void *)(ether_header + 1);
> >  	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
> > -			iphdr->daddr != __builtin_bswap32(0x1020304))
> > +			iphdr->daddr != htonl(0x1020304))
> >  		return 0;
> >
> >  	int hlen = iphdr->ihl * 4;
> >  	struct udphdr *udphdr = (void *)iphdr + hlen;
> >
> > -	if (udphdr->dest !=  __builtin_bswap16(5000))
> > +	if (udphdr->dest != htons(5000))
> >  		return 0;
> >
> >  	return 1;
> > diff --git a/test/bpf/t3.c b/test/bpf/t3.c index 531b9cb8c..24298b7c7
> > 100644
> > --- a/test/bpf/t3.c
> > +++ b/test/bpf/t3.c
> > @@ -17,6 +17,7 @@
> >  #include <net/ethernet.h>
> >  #include <rte_config.h>
> >  #include "mbuf.h"
> > +#include <arpa/inet.h>
> >
> >  extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *,
> > unsigned int);
> >
> > @@ -29,7 +30,7 @@ entry(const void *pkt)
> >  	mb = pkt;
> >  	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
> >
> > -	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
> > +	if (eth->ether_type == htons(ETHERTYPE_ARP))
> >  		rte_pktmbuf_dump(stdout, mb, 64);
> >
> >  	return 1;
> > --
> > 2.17.1

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

* Re: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
  2018-10-19 12:17       ` Ananyev, Konstantin
@ 2018-10-25 16:59         ` Malvika Gupta
  2018-10-27 22:00           ` Ananyev, Konstantin
  0 siblings, 1 reply; 13+ messages in thread
From: Malvika Gupta @ 2018-10-25 16:59 UTC (permalink / raw)
  To: Ananyev, Konstantin
  Cc: dev, Gavin Hu (Arm Technology China), Honnappa Nagarahalli, nd

Hi Konstantin,

At time of upstreaming the patch, I had compiled it on Cortex-A72 and it had worked with the -I parameter. But when tried building it on x86-64, I encountered the error that you were facing. From my understanding of this problem, this is a portability issue. As you pointed out, gcc and clang implement __builtin_constant_p in a different way on x86 but that may not be true for ARM. 

In such a case, to enable compilation on x86, we may want to write specific hton and ntoh functions. But this would become a tedious task because, in future, to enable compilation on other architectures besides x86 and ARM, we may have to repeat this process of writing analogs for each architecture. I think the best solution in the current scenario would be to use the -U parameter to enable compilation on x86 and later decide if we want to write a new patch with analogs for builtin hton() and ntoh().   

Best,
Malvika 

-----Original Message-----
From: Ananyev, Konstantin <konstantin.ananyev@intel.com> 
Sent: Friday, October 19, 2018 7:17 AM
To: Malvika Gupta <Malvika.Gupta@arm.com>
Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; nd <nd@arm.com>
Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap


Hi Malvika,

> 
> Hi Konstantin,
> 
> I installed the clang version 4.0.1 to check for the issue you were 
> facing with -O2 compilation. I was able to compile with -O2 and -O0 optimization without any errors. Please see the exact command I used and the following output for your reference:
> 
> $ clang -O2 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c $ 
> clang -O0 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c $ 
> clang -v clang version 4.0.1-10 (tags/RELEASE_401/final)
> Target: aarch64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/6
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/7
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/8
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6 
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7 
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8 
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8.0.1
> Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> Candidate multilib: .;@m64
> Selected multilib: .;@m64
> 
> I hope this was helpful to you.

Sorry for delay.
I tried with clang 6.0, but still seeing same issue.
Digging a bit more, I think the culprit is here:

#ifdef __GNUC__
# if __GNUC__ >= 2
#  define __bswap_16(x) \
     (__extension__                                                           \
      ({ unsigned short int __v, __x = (unsigned short int) (x);              \
         if (__builtin_constant_p (__x))                                      \     <------ evaluates to FALSE !!!
           __v = __bswap_constant_16 (__x);                                   \
         else                                                                 \
           __asm__ ("rorw $8, %w0"                                            \
                    : "=r" (__v)                                              \
                    : "0" (__x)                                               \
                    : "cc");                                                  \
         __v; }))
# else
/* This is better than nothing.  */
#  define __bswap_16(x) \
     (__extension__                                                           \
      ({ unsigned short int __x = (unsigned short int) (x);                   \
         __bswap_constant_16 (__x); }))
# endif
#else
static __inline unsigned short int
__bswap_16 (unsigned short int __bsx)
{
  return __bswap_constant_16 (__bsx);
}
#endif

Seems that gcc and clang implements __builtin_constant_p in a different way.
Let say, the following function:
int bbb1(void) {uint16_t x=0; return__bswap_constant_16(x);} when compiled with gcc would return 1, while when compiled with clang - 0.
Adding 'const' to definition of 'x' cures the problem for clang.
I don't know why there is no 'const' in original __bswap_16() macro. 
To overcome that problem, I used:
clang -O2 -U__GNUC__ -target bpf -c t1.c

Another possible option - define our own analogs for buitin hton*().
Konstantin


> Best Regards,
> Malvika Gupta
> 
> 
> -----Original Message-----
> From: Malvika Gupta
> Sent: Wednesday, September 5, 2018 4:43 PM
> To: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; 
> Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Brian Brooks 
> <Brian.Brooks@arm.com>; nd <nd@arm.com>
> Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> 
> Hi Ananyev,
> 
> I used clang version 6.0.0. Please see the following output for your reference.
> 
> $ clang -v
> clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
> Target: aarch64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/6
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/7
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/8
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6 
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7 
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8 
> Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8.0.1
> Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> Candidate multilib: .;@m64
> Selected multilib: .;@m64
> 
> Also, the code compiles with both -O2 and -O0 for me.
> 
> I hope this was helpful
> Best,
> Malvika
> 
> -----Original Message-----
> From: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Sent: Tuesday, September 4, 2018 8:56 AM
> To: Malvika Gupta <Malvika.Gupta@arm.com>
> Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; 
> Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Brian Brooks 
> <Brian.Brooks@arm.com>; nd <nd@arm.com>
> Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> 
> Hi,
> 
> >
> > Convert host machine endianness to networking endianness for 
> > comparison of incoming packets with BPF filter
> >
> >
> > Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> > Reviewed-by: Brian Brooks <brian.brooks@arm.com>
> > Suggested-by: Brian Brooks <brian.brooks@arm.com>
> > ---
> >  test/bpf/t1.c | 7 ++++---
> >  test/bpf/t3.c | 3 ++-
> >  2 files changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/test/bpf/t1.c b/test/bpf/t1.c index 
> > 60f9434ab..7943fcf34
> > 100644
> > --- a/test/bpf/t1.c
> > +++ b/test/bpf/t1.c
> > @@ -28,24 +28,25 @@
> >  #include <net/ethernet.h>
> >  #include <netinet/ip.h>
> >  #include <netinet/udp.h>
> > +#include <arpa/inet.h>
> >
> >  uint64_t
> >  entry(void *pkt)
> >  {
> >  	struct ether_header *ether_header = (void *)pkt;
> >
> > -	if (ether_header->ether_type != __builtin_bswap16(0x0800))
> > +	if (ether_header->ether_type != htons(0x0800))
> 
> Which version of clang do you use?
> With my one I get:
> $ clang -O2 -target bpf -c t1.c
> t1.c:37:34: error: couldn't allocate output register for constraint 'r'
>         if (ether_header->ether_type != ntohs(0x0800))
>                                         ^
> /usr/include/netinet/in.h:402:21: note: expanded from macro 'ntohs'
> #   define ntohs(x)     __bswap_16 (x)
>                         ^
> /usr/include/bits/byteswap-16.h:31:14: note: expanded from macro '__bswap_16'
>            __asm__ ("rorw $8, %w0"
> 
> With '-O0' it compiles ok.
> 
> $ clang -v
> clang version 4.0.1 (tags/RELEASE_401/final)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> Found candidate GCC installation: 
> /usr/bin/../lib/gcc/x86_64-redhat-linux/7
> Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
> Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
> Candidate multilib: .;@m64
> Candidate multilib: 32;@m32
> Selected multilib: .;@m64
> 
> Konstantin
> 
> >  		return 0;
> >
> >  	struct iphdr *iphdr = (void *)(ether_header + 1);
> >  	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
> > -			iphdr->daddr != __builtin_bswap32(0x1020304))
> > +			iphdr->daddr != htonl(0x1020304))
> >  		return 0;
> >
> >  	int hlen = iphdr->ihl * 4;
> >  	struct udphdr *udphdr = (void *)iphdr + hlen;
> >
> > -	if (udphdr->dest !=  __builtin_bswap16(5000))
> > +	if (udphdr->dest != htons(5000))
> >  		return 0;
> >
> >  	return 1;
> > diff --git a/test/bpf/t3.c b/test/bpf/t3.c index 
> > 531b9cb8c..24298b7c7
> > 100644
> > --- a/test/bpf/t3.c
> > +++ b/test/bpf/t3.c
> > @@ -17,6 +17,7 @@
> >  #include <net/ethernet.h>
> >  #include <rte_config.h>
> >  #include "mbuf.h"
> > +#include <arpa/inet.h>
> >
> >  extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, 
> > unsigned int);
> >
> > @@ -29,7 +30,7 @@ entry(const void *pkt)
> >  	mb = pkt;
> >  	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
> >
> > -	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
> > +	if (eth->ether_type == htons(ETHERTYPE_ARP))
> >  		rte_pktmbuf_dump(stdout, mb, 64);
> >
> >  	return 1;
> > --
> > 2.17.1

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

* Re: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
  2018-10-25 16:59         ` Malvika Gupta
@ 2018-10-27 22:00           ` Ananyev, Konstantin
  2018-11-01 18:24             ` Malvika Gupta
  0 siblings, 1 reply; 13+ messages in thread
From: Ananyev, Konstantin @ 2018-10-27 22:00 UTC (permalink / raw)
  To: Malvika Gupta
  Cc: dev, Gavin Hu (Arm Technology China), Honnappa Nagarahalli, nd



> 
> Hi Konstantin,
> 
> At time of upstreaming the patch, I had compiled it on Cortex-A72 and it had worked with the -I parameter.

Just curious what is memory ordering on your box (BE/LE)?

> But when tried building it on
> x86-64, I encountered the error that you were facing. From my understanding of this problem, this is a portability issue. As you pointed out,
> gcc and clang implement __builtin_constant_p in a different way on x86 but that may not be true for ARM.
> 
> In such a case, to enable compilation on x86, we may want to write specific hton and ntoh functions. But this would become a tedious task
> because, in future, to enable compilation on other architectures besides x86 and ARM, we may have to repeat this process of writing
> analogs for each architecture.

Don't see why we need it done for each arch.
Obviously all is needed is BE and LE version.

> I think the best solution in the current scenario would be to use the -U parameter to enable compilation on
> x86 and later decide if we want to write a new patch with analogs for builtin hton() and ntoh().

I suppose -U__GNUC__ is ok.
If you decide to go that way, please update appropriate comments in *.c.

Konstantin

> 
> Best,
> Malvika
> 
> -----Original Message-----
> From: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Sent: Friday, October 19, 2018 7:17 AM
> To: Malvika Gupta <Malvika.Gupta@arm.com>
> Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>;
> nd <nd@arm.com>
> Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> 
> 
> Hi Malvika,
> 
> >
> > Hi Konstantin,
> >
> > I installed the clang version 4.0.1 to check for the issue you were
> > facing with -O2 compilation. I was able to compile with -O2 and -O0 optimization without any errors. Please see the exact command I
> used and the following output for your reference:
> >
> > $ clang -O2 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c $
> > clang -O0 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c $
> > clang -v clang version 4.0.1-10 (tags/RELEASE_401/final)
> > Target: aarch64-unknown-linux-gnu
> > Thread model: posix
> > InstalledDir: /usr/bin
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/6
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/7
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/8
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8.0.1
> > Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> > Candidate multilib: .;@m64
> > Selected multilib: .;@m64
> >
> > I hope this was helpful to you.
> 
> Sorry for delay.
> I tried with clang 6.0, but still seeing same issue.
> Digging a bit more, I think the culprit is here:
> 
> #ifdef __GNUC__
> # if __GNUC__ >= 2
> #  define __bswap_16(x) \
>      (__extension__                                                           \
>       ({ unsigned short int __v, __x = (unsigned short int) (x);              \
>          if (__builtin_constant_p (__x))                                      \     <------ evaluates to FALSE !!!
>            __v = __bswap_constant_16 (__x);                                   \
>          else                                                                 \
>            __asm__ ("rorw $8, %w0"                                            \
>                     : "=r" (__v)                                              \
>                     : "0" (__x)                                               \
>                     : "cc");                                                  \
>          __v; }))
> # else
> /* This is better than nothing.  */
> #  define __bswap_16(x) \
>      (__extension__                                                           \
>       ({ unsigned short int __x = (unsigned short int) (x);                   \
>          __bswap_constant_16 (__x); }))
> # endif
> #else
> static __inline unsigned short int
> __bswap_16 (unsigned short int __bsx)
> {
>   return __bswap_constant_16 (__bsx);
> }
> #endif
> 
> Seems that gcc and clang implements __builtin_constant_p in a different way.
> Let say, the following function:
> int bbb1(void) {uint16_t x=0; return__bswap_constant_16(x);} when compiled with gcc would return 1, while when compiled with clang - 0.
> Adding 'const' to definition of 'x' cures the problem for clang.
> I don't know why there is no 'const' in original __bswap_16() macro.
> To overcome that problem, I used:
> clang -O2 -U__GNUC__ -target bpf -c t1.c
> 
> Another possible option - define our own analogs for buitin hton*().
> Konstantin
> 
> 
> > Best Regards,
> > Malvika Gupta
> >
> >
> > -----Original Message-----
> > From: Malvika Gupta
> > Sent: Wednesday, September 5, 2018 4:43 PM
> > To: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> > Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>;
> > Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Brian Brooks
> > <Brian.Brooks@arm.com>; nd <nd@arm.com>
> > Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> >
> > Hi Ananyev,
> >
> > I used clang version 6.0.0. Please see the following output for your reference.
> >
> > $ clang -v
> > clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
> > Target: aarch64-unknown-linux-gnu
> > Thread model: posix
> > InstalledDir: /usr/bin
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/6
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/7
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/8
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8
> > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8.0.1
> > Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> > Candidate multilib: .;@m64
> > Selected multilib: .;@m64
> >
> > Also, the code compiles with both -O2 and -O0 for me.
> >
> > I hope this was helpful
> > Best,
> > Malvika
> >
> > -----Original Message-----
> > From: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> > Sent: Tuesday, September 4, 2018 8:56 AM
> > To: Malvika Gupta <Malvika.Gupta@arm.com>
> > Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>;
> > Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Brian Brooks
> > <Brian.Brooks@arm.com>; nd <nd@arm.com>
> > Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> >
> > Hi,
> >
> > >
> > > Convert host machine endianness to networking endianness for
> > > comparison of incoming packets with BPF filter
> > >
> > >
> > > Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> > > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> > > Reviewed-by: Brian Brooks <brian.brooks@arm.com>
> > > Suggested-by: Brian Brooks <brian.brooks@arm.com>
> > > ---
> > >  test/bpf/t1.c | 7 ++++---
> > >  test/bpf/t3.c | 3 ++-
> > >  2 files changed, 6 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/test/bpf/t1.c b/test/bpf/t1.c index
> > > 60f9434ab..7943fcf34
> > > 100644
> > > --- a/test/bpf/t1.c
> > > +++ b/test/bpf/t1.c
> > > @@ -28,24 +28,25 @@
> > >  #include <net/ethernet.h>
> > >  #include <netinet/ip.h>
> > >  #include <netinet/udp.h>
> > > +#include <arpa/inet.h>
> > >
> > >  uint64_t
> > >  entry(void *pkt)
> > >  {
> > >  	struct ether_header *ether_header = (void *)pkt;
> > >
> > > -	if (ether_header->ether_type != __builtin_bswap16(0x0800))
> > > +	if (ether_header->ether_type != htons(0x0800))
> >
> > Which version of clang do you use?
> > With my one I get:
> > $ clang -O2 -target bpf -c t1.c
> > t1.c:37:34: error: couldn't allocate output register for constraint 'r'
> >         if (ether_header->ether_type != ntohs(0x0800))
> >                                         ^
> > /usr/include/netinet/in.h:402:21: note: expanded from macro 'ntohs'
> > #   define ntohs(x)     __bswap_16 (x)
> >                         ^
> > /usr/include/bits/byteswap-16.h:31:14: note: expanded from macro '__bswap_16'
> >            __asm__ ("rorw $8, %w0"
> >
> > With '-O0' it compiles ok.
> >
> > $ clang -v
> > clang version 4.0.1 (tags/RELEASE_401/final)
> > Target: x86_64-unknown-linux-gnu
> > Thread model: posix
> > InstalledDir: /usr/bin
> > Found candidate GCC installation:
> > /usr/bin/../lib/gcc/x86_64-redhat-linux/7
> > Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
> > Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
> > Candidate multilib: .;@m64
> > Candidate multilib: 32;@m32
> > Selected multilib: .;@m64
> >
> > Konstantin
> >
> > >  		return 0;
> > >
> > >  	struct iphdr *iphdr = (void *)(ether_header + 1);
> > >  	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
> > > -			iphdr->daddr != __builtin_bswap32(0x1020304))
> > > +			iphdr->daddr != htonl(0x1020304))
> > >  		return 0;
> > >
> > >  	int hlen = iphdr->ihl * 4;
> > >  	struct udphdr *udphdr = (void *)iphdr + hlen;
> > >
> > > -	if (udphdr->dest !=  __builtin_bswap16(5000))
> > > +	if (udphdr->dest != htons(5000))
> > >  		return 0;
> > >
> > >  	return 1;
> > > diff --git a/test/bpf/t3.c b/test/bpf/t3.c index
> > > 531b9cb8c..24298b7c7
> > > 100644
> > > --- a/test/bpf/t3.c
> > > +++ b/test/bpf/t3.c
> > > @@ -17,6 +17,7 @@
> > >  #include <net/ethernet.h>
> > >  #include <rte_config.h>
> > >  #include "mbuf.h"
> > > +#include <arpa/inet.h>
> > >
> > >  extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *,
> > > unsigned int);
> > >
> > > @@ -29,7 +30,7 @@ entry(const void *pkt)
> > >  	mb = pkt;
> > >  	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
> > >
> > > -	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
> > > +	if (eth->ether_type == htons(ETHERTYPE_ARP))
> > >  		rte_pktmbuf_dump(stdout, mb, 64);
> > >
> > >  	return 1;
> > > --
> > > 2.17.1

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

* Re: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
  2018-10-27 22:00           ` Ananyev, Konstantin
@ 2018-11-01 18:24             ` Malvika Gupta
  0 siblings, 0 replies; 13+ messages in thread
From: Malvika Gupta @ 2018-11-01 18:24 UTC (permalink / raw)
  To: Ananyev, Konstantin
  Cc: dev, Gavin Hu (Arm Technology China), Honnappa Nagarahalli, nd

> > Hi Konstantin,
> >
> > At time of upstreaming the patch, I had compiled it on Cortex-A72 and it
> had worked with the -I parameter.
> 
> Just curious what is memory ordering on your box (BE/LE)?
 
The memory ordering on my machine was little endian

> > But when tried building it on
> > x86-64, I encountered the error that you were facing. From my
> > understanding of this problem, this is a portability issue. As you pointed
> out, gcc and clang implement __builtin_constant_p in a different way on x86
> but that may not be true for ARM.
> >
> > In such a case, to enable compilation on x86, we may want to write
> > specific hton and ntoh functions. But this would become a tedious task
> > because, in future, to enable compilation on other architectures besides
> x86 and ARM, we may have to repeat this process of writing analogs for each
> architecture.
> 
> Don't see why we need it done for each arch.
> Obviously all is needed is BE and LE version.
> 
> > I think the best solution in the current scenario would be to use the
> > -U parameter to enable compilation on
> > x86 and later decide if we want to write a new patch with analogs for
> builtin hton() and ntoh().
> 
> I suppose -U__GNUC__ is ok.
> If you decide to go that way, please update appropriate comments in *.c.

I will update the comments in the .c files and submit the patch again.

Thanks,
Malvika 
 
> Konstantin
> 
> >
> > Best,
> > Malvika
> >
> > -----Original Message-----
> > From: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> > Sent: Friday, October 19, 2018 7:17 AM
> > To: Malvika Gupta <Malvika.Gupta@arm.com>
> > Cc: dev@dpdk.org; Gavin Hu (Arm Technology China)
> <Gavin.Hu@arm.com>;
> > Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; nd
> <nd@arm.com>
> > Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> >
> >
> > Hi Malvika,
> >
> > >
> > > Hi Konstantin,
> > >
> > > I installed the clang version 4.0.1 to check for the issue you were
> > > facing with -O2 compilation. I was able to compile with -O2 and -O0
> > > optimization without any errors. Please see the exact command I
> > used and the following output for your reference:
> > >
> > > $ clang -O2 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c $
> > > clang -O0 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c $
> > > clang -v clang version 4.0.1-10 (tags/RELEASE_401/final)
> > > Target: aarch64-unknown-linux-gnu
> > > Thread model: posix
> > > InstalledDir: /usr/bin
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/6
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/7
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/8
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
> > > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6
> > > Found candidate GCC installation:
> > > /usr/lib/gcc/aarch64-linux-gnu/6.4.0
> > > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
> > > Found candidate GCC installation:
> > > /usr/lib/gcc/aarch64-linux-gnu/7.3.0
> > > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8
> > > Found candidate GCC installation:
> > > /usr/lib/gcc/aarch64-linux-gnu/8.0.1
> > > Selected GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> > > Candidate multilib: .;@m64
> > > Selected multilib: .;@m64
> > >
> > > I hope this was helpful to you.
> >
> > Sorry for delay.
> > I tried with clang 6.0, but still seeing same issue.
> > Digging a bit more, I think the culprit is here:
> >
> > #ifdef __GNUC__
> > # if __GNUC__ >= 2
> > #  define __bswap_16(x) \
> >      (__extension__                                                           \
> >       ({ unsigned short int __v, __x = (unsigned short int) (x);              \
> >          if (__builtin_constant_p (__x))                                      \     <------ evaluates
> to FALSE !!!
> >            __v = __bswap_constant_16 (__x);                                   \
> >          else                                                                 \
> >            __asm__ ("rorw $8, %w0"                                            \
> >                     : "=r" (__v)                                              \
> >                     : "0" (__x)                                               \
> >                     : "cc");                                                  \
> >          __v; }))
> > # else
> > /* This is better than nothing.  */
> > #  define __bswap_16(x) \
> >      (__extension__                                                           \
> >       ({ unsigned short int __x = (unsigned short int) (x);                   \
> >          __bswap_constant_16 (__x); })) # endif #else static __inline
> > unsigned short int
> > __bswap_16 (unsigned short int __bsx)
> > {
> >   return __bswap_constant_16 (__bsx);
> > }
> > #endif
> >
> > Seems that gcc and clang implements __builtin_constant_p in a different
> way.
> > Let say, the following function:
> > int bbb1(void) {uint16_t x=0; return__bswap_constant_16(x);} when
> compiled with gcc would return 1, while when compiled with clang - 0.
> > Adding 'const' to definition of 'x' cures the problem for clang.
> > I don't know why there is no 'const' in original __bswap_16() macro.
> > To overcome that problem, I used:
> > clang -O2 -U__GNUC__ -target bpf -c t1.c
> >
> > Another possible option - define our own analogs for buitin hton*().
> > Konstantin
> >
> >
> > > Best Regards,
> > > Malvika Gupta
> > >
> > >
> > > -----Original Message-----
> > > From: Malvika Gupta
> > > Sent: Wednesday, September 5, 2018 4:43 PM
> > > To: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> > > Cc: dev@dpdk.org; Gavin Hu (Arm Technology China)
> > > <Gavin.Hu@arm.com>; Honnappa Nagarahalli
> > > <Honnappa.Nagarahalli@arm.com>; Brian Brooks
> <Brian.Brooks@arm.com>;
> > > nd <nd@arm.com>
> > > Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> > >
> > > Hi Ananyev,
> > >
> > > I used clang version 6.0.0. Please see the following output for your
> reference.
> > >
> > > $ clang -v
> > > clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
> > > Target: aarch64-unknown-linux-gnu
> > > Thread model: posix
> > > InstalledDir: /usr/bin
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/6
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/7
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/8
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1
> > > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6
> > > Found candidate GCC installation:
> > > /usr/lib/gcc/aarch64-linux-gnu/6.4.0
> > > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
> > > Found candidate GCC installation:
> > > /usr/lib/gcc/aarch64-linux-gnu/7.3.0
> > > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8
> > > Found candidate GCC installation:
> > > /usr/lib/gcc/aarch64-linux-gnu/8.0.1
> > > Selected GCC installation:
> > > /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
> > > Candidate multilib: .;@m64
> > > Selected multilib: .;@m64
> > >
> > > Also, the code compiles with both -O2 and -O0 for me.
> > >
> > > I hope this was helpful
> > > Best,
> > > Malvika
> > >
> > > -----Original Message-----
> > > From: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> > > Sent: Tuesday, September 4, 2018 8:56 AM
> > > To: Malvika Gupta <Malvika.Gupta@arm.com>
> > > Cc: dev@dpdk.org; Gavin Hu (Arm Technology China)
> > > <Gavin.Hu@arm.com>; Honnappa Nagarahalli
> > > <Honnappa.Nagarahalli@arm.com>; Brian Brooks
> <Brian.Brooks@arm.com>;
> > > nd <nd@arm.com>
> > > Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap
> > >
> > > Hi,
> > >
> > > >
> > > > Convert host machine endianness to networking endianness for
> > > > comparison of incoming packets with BPF filter
> > > >
> > > >
> > > > Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> > > > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> > > > Reviewed-by: Brian Brooks <brian.brooks@arm.com>
> > > > Suggested-by: Brian Brooks <brian.brooks@arm.com>
> > > > ---
> > > >  test/bpf/t1.c | 7 ++++---
> > > >  test/bpf/t3.c | 3 ++-
> > > >  2 files changed, 6 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/test/bpf/t1.c b/test/bpf/t1.c index
> > > > 60f9434ab..7943fcf34
> > > > 100644
> > > > --- a/test/bpf/t1.c
> > > > +++ b/test/bpf/t1.c
> > > > @@ -28,24 +28,25 @@
> > > >  #include <net/ethernet.h>
> > > >  #include <netinet/ip.h>
> > > >  #include <netinet/udp.h>
> > > > +#include <arpa/inet.h>
> > > >
> > > >  uint64_t
> > > >  entry(void *pkt)
> > > >  {
> > > >  	struct ether_header *ether_header = (void *)pkt;
> > > >
> > > > -	if (ether_header->ether_type != __builtin_bswap16(0x0800))
> > > > +	if (ether_header->ether_type != htons(0x0800))
> > >
> > > Which version of clang do you use?
> > > With my one I get:
> > > $ clang -O2 -target bpf -c t1.c
> > > t1.c:37:34: error: couldn't allocate output register for constraint 'r'
> > >         if (ether_header->ether_type != ntohs(0x0800))
> > >                                         ^
> > > /usr/include/netinet/in.h:402:21: note: expanded from macro 'ntohs'
> > > #   define ntohs(x)     __bswap_16 (x)
> > >                         ^
> > > /usr/include/bits/byteswap-16.h:31:14: note: expanded from macro
> '__bswap_16'
> > >            __asm__ ("rorw $8, %w0"
> > >
> > > With '-O0' it compiles ok.
> > >
> > > $ clang -v
> > > clang version 4.0.1 (tags/RELEASE_401/final)
> > > Target: x86_64-unknown-linux-gnu
> > > Thread model: posix
> > > InstalledDir: /usr/bin
> > > Found candidate GCC installation:
> > > /usr/bin/../lib/gcc/x86_64-redhat-linux/7
> > > Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
> > > Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7
> > > Candidate multilib: .;@m64
> > > Candidate multilib: 32;@m32
> > > Selected multilib: .;@m64
> > >
> > > Konstantin
> > >
> > > >  		return 0;
> > > >
> > > >  	struct iphdr *iphdr = (void *)(ether_header + 1);
> > > >  	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
> > > > -			iphdr->daddr != __builtin_bswap32(0x1020304))
> > > > +			iphdr->daddr != htonl(0x1020304))
> > > >  		return 0;
> > > >
> > > >  	int hlen = iphdr->ihl * 4;
> > > >  	struct udphdr *udphdr = (void *)iphdr + hlen;
> > > >
> > > > -	if (udphdr->dest !=  __builtin_bswap16(5000))
> > > > +	if (udphdr->dest != htons(5000))
> > > >  		return 0;
> > > >
> > > >  	return 1;
> > > > diff --git a/test/bpf/t3.c b/test/bpf/t3.c index
> > > > 531b9cb8c..24298b7c7
> > > > 100644
> > > > --- a/test/bpf/t3.c
> > > > +++ b/test/bpf/t3.c
> > > > @@ -17,6 +17,7 @@
> > > >  #include <net/ethernet.h>
> > > >  #include <rte_config.h>
> > > >  #include "mbuf.h"
> > > > +#include <arpa/inet.h>
> > > >
> > > >  extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *,
> > > > unsigned int);
> > > >
> > > > @@ -29,7 +30,7 @@ entry(const void *pkt)
> > > >  	mb = pkt;
> > > >  	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
> > > >
> > > > -	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
> > > > +	if (eth->ether_type == htons(ETHERTYPE_ARP))
> > > >  		rte_pktmbuf_dump(stdout, mb, 64);
> > > >
> > > >  	return 1;
> > > > --
> > > > 2.17.1

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

* [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap
  2018-08-28 20:46 [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap Malvika Gupta
  2018-08-28 20:58 ` Honnappa Nagarahalli
  2018-09-04 13:56 ` Ananyev, Konstantin
@ 2018-11-02 19:08 ` Malvika Gupta
  2018-11-06  1:52   ` Thomas Monjalon
  2018-11-06 10:17   ` Ananyev, Konstantin
  2 siblings, 2 replies; 13+ messages in thread
From: Malvika Gupta @ 2018-11-02 19:08 UTC (permalink / raw)
  To: konstantin.ananyev
  Cc: dev, gavin.hu, honnappa.nagarahalli, nd, Malvika Gupta, Malvika Gupta

From: Malvika Gupta <Malvika.Gupta@arm.com>

Convert host machine endianness to networking endianness for
comparison of incoming packets with BPF filter

Suggested-by: Brian Brooks <brian.brooks@arm.com>
Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
Reviewed-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Acked-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
---
v2:
* Correct compilation command in the comments for x86.
* Added compilation command for ARM.

---
 test/bpf/t1.c | 14 +++++++++-----
 test/bpf/t3.c | 13 ++++++++++---
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/test/bpf/t1.c b/test/bpf/t1.c
index 60f9434ab..3364b4f1e 100644
--- a/test/bpf/t1.c
+++ b/test/bpf/t1.c
@@ -20,32 +20,36 @@
  * (011) ret      #1
  * (012) ret      #0
  *
- * To compile:
- * clang -O2 -target bpf -c t1.c
+ * To compile on x86:
+ * clang -O2 -U __GNUC__ -target bpf -c t1.c
+ *
+ * To compile on ARM:
+ * clang -O2 -I/usr/include/aarch64-linux-gnu/ -target bpf -c t1.c
  */
 
 #include <stdint.h>
 #include <net/ethernet.h>
 #include <netinet/ip.h>
 #include <netinet/udp.h>
+#include <arpa/inet.h>
 
 uint64_t
 entry(void *pkt)
 {
 	struct ether_header *ether_header = (void *)pkt;
 
-	if (ether_header->ether_type != __builtin_bswap16(0x0800))
+	if (ether_header->ether_type != htons(0x0800))
 		return 0;
 
 	struct iphdr *iphdr = (void *)(ether_header + 1);
 	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
-			iphdr->daddr != __builtin_bswap32(0x1020304))
+			iphdr->daddr != htonl(0x1020304))
 		return 0;
 
 	int hlen = iphdr->ihl * 4;
 	struct udphdr *udphdr = (void *)iphdr + hlen;
 
-	if (udphdr->dest !=  __builtin_bswap16(5000))
+	if (udphdr->dest != htons(5000))
 		return 0;
 
 	return 1;
diff --git a/test/bpf/t3.c b/test/bpf/t3.c
index 531b9cb8c..9ba34638a 100644
--- a/test/bpf/t3.c
+++ b/test/bpf/t3.c
@@ -6,9 +6,15 @@
  * eBPF program sample.
  * Accepts pointer to struct rte_mbuf as an input parameter.
  * Dump the mbuf into stdout if it is an ARP packet (aka tcpdump 'arp').
- * To compile:
- * clang -O2 -I${RTE_SDK}/${RTE_TARGET}/include \
+ *
+ * To compile on x86:
+ * clang -O2 -U __GNUC__ -I${RTE_SDK}/${RTE_TARGET}/include \
  * -target bpf -Wno-int-to-void-pointer-cast -c t3.c
+ *
+ * To compile on ARM:
+ * clang -O2 -I/usr/include/aarch64-linux-gnu \
+ * -I${RTE_SDK}/${RTE_TARGET}/include -target bpf \
+ * -Wno-int-to-void-pointer-cast -c t3.c
  */
 
 #include <stdint.h>
@@ -17,6 +23,7 @@
 #include <net/ethernet.h>
 #include <rte_config.h>
 #include "mbuf.h"
+#include <arpa/inet.h>
 
 extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned int);
 
@@ -29,7 +36,7 @@ entry(const void *pkt)
 	mb = pkt;
 	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
 
-	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
+	if (eth->ether_type == htons(ETHERTYPE_ARP))
 		rte_pktmbuf_dump(stdout, mb, 64);
 
 	return 1;
-- 
2.17.1

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

* Re: [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap
  2018-11-02 19:08 ` [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap Malvika Gupta
@ 2018-11-06  1:52   ` Thomas Monjalon
  2018-11-06 10:17   ` Ananyev, Konstantin
  1 sibling, 0 replies; 13+ messages in thread
From: Thomas Monjalon @ 2018-11-06  1:52 UTC (permalink / raw)
  To: konstantin.ananyev
  Cc: dev, Malvika Gupta, gavin.hu, honnappa.nagarahalli, nd, Malvika Gupta

02/11/2018 20:08, Malvika Gupta:
> From: Malvika Gupta <Malvika.Gupta@arm.com>
> 
> Convert host machine endianness to networking endianness for
> comparison of incoming packets with BPF filter
> 
> Suggested-by: Brian Brooks <brian.brooks@arm.com>
> Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> Reviewed-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
> Acked-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>

Not sure Konstantin really reviewed this version.
Please confirm it is OK.

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

* Re: [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap
  2018-11-02 19:08 ` [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap Malvika Gupta
  2018-11-06  1:52   ` Thomas Monjalon
@ 2018-11-06 10:17   ` Ananyev, Konstantin
  2018-11-13 22:33     ` Thomas Monjalon
  1 sibling, 1 reply; 13+ messages in thread
From: Ananyev, Konstantin @ 2018-11-06 10:17 UTC (permalink / raw)
  To: Malvika Gupta; +Cc: dev, gavin.hu, honnappa.nagarahalli, nd


Hi Malvika,

> -----Original Message-----
> From: Malvika Gupta [mailto:malvika.gupta@arm.com]
> Sent: Friday, November 2, 2018 7:08 PM
> To: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Cc: dev@dpdk.org; gavin.hu@arm.com; honnappa.nagarahalli@arm.com; nd@arm.com; Malvika Gupta <Malvika.Gupta@arm.com>;
> Malvika Gupta <malvika.gupta@arm.com>
> Subject: [PATCH v2] test/bpf: use hton instead of _builtin_bswap
> 
> From: Malvika Gupta <Malvika.Gupta@arm.com>
> 
> Convert host machine endianness to networking endianness for
> comparison of incoming packets with BPF filter
> 
> Suggested-by: Brian Brooks <brian.brooks@arm.com>
> Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> Reviewed-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

I don't remember I acked it before actually, but I am ok to do it now for v2.
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

> Acked-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> ---
> v2:
> * Correct compilation command in the comments for x86.
> * Added compilation command for ARM.
> 
> ---
>  test/bpf/t1.c | 14 +++++++++-----
>  test/bpf/t3.c | 13 ++++++++++---
>  2 files changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/test/bpf/t1.c b/test/bpf/t1.c
> index 60f9434ab..3364b4f1e 100644
> --- a/test/bpf/t1.c
> +++ b/test/bpf/t1.c
> @@ -20,32 +20,36 @@
>   * (011) ret      #1
>   * (012) ret      #0
>   *
> - * To compile:
> - * clang -O2 -target bpf -c t1.c
> + * To compile on x86:
> + * clang -O2 -U __GNUC__ -target bpf -c t1.c
> + *
> + * To compile on ARM:
> + * clang -O2 -I/usr/include/aarch64-linux-gnu/ -target bpf -c t1.c
>   */
> 
>  #include <stdint.h>
>  #include <net/ethernet.h>
>  #include <netinet/ip.h>
>  #include <netinet/udp.h>
> +#include <arpa/inet.h>
> 
>  uint64_t
>  entry(void *pkt)
>  {
>  	struct ether_header *ether_header = (void *)pkt;
> 
> -	if (ether_header->ether_type != __builtin_bswap16(0x0800))
> +	if (ether_header->ether_type != htons(0x0800))
>  		return 0;
> 
>  	struct iphdr *iphdr = (void *)(ether_header + 1);
>  	if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
> -			iphdr->daddr != __builtin_bswap32(0x1020304))
> +			iphdr->daddr != htonl(0x1020304))
>  		return 0;
> 
>  	int hlen = iphdr->ihl * 4;
>  	struct udphdr *udphdr = (void *)iphdr + hlen;
> 
> -	if (udphdr->dest !=  __builtin_bswap16(5000))
> +	if (udphdr->dest != htons(5000))
>  		return 0;
> 
>  	return 1;
> diff --git a/test/bpf/t3.c b/test/bpf/t3.c
> index 531b9cb8c..9ba34638a 100644
> --- a/test/bpf/t3.c
> +++ b/test/bpf/t3.c
> @@ -6,9 +6,15 @@
>   * eBPF program sample.
>   * Accepts pointer to struct rte_mbuf as an input parameter.
>   * Dump the mbuf into stdout if it is an ARP packet (aka tcpdump 'arp').
> - * To compile:
> - * clang -O2 -I${RTE_SDK}/${RTE_TARGET}/include \
> + *
> + * To compile on x86:
> + * clang -O2 -U __GNUC__ -I${RTE_SDK}/${RTE_TARGET}/include \
>   * -target bpf -Wno-int-to-void-pointer-cast -c t3.c
> + *
> + * To compile on ARM:
> + * clang -O2 -I/usr/include/aarch64-linux-gnu \
> + * -I${RTE_SDK}/${RTE_TARGET}/include -target bpf \
> + * -Wno-int-to-void-pointer-cast -c t3.c
>   */
> 
>  #include <stdint.h>
> @@ -17,6 +23,7 @@
>  #include <net/ethernet.h>
>  #include <rte_config.h>
>  #include "mbuf.h"
> +#include <arpa/inet.h>
> 
>  extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned int);
> 
> @@ -29,7 +36,7 @@ entry(const void *pkt)
>  	mb = pkt;
>  	eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
> 
> -	if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
> +	if (eth->ether_type == htons(ETHERTYPE_ARP))
>  		rte_pktmbuf_dump(stdout, mb, 64);
> 
>  	return 1;
> --
> 2.17.1

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

* Re: [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap
  2018-11-06 10:17   ` Ananyev, Konstantin
@ 2018-11-13 22:33     ` Thomas Monjalon
  0 siblings, 0 replies; 13+ messages in thread
From: Thomas Monjalon @ 2018-11-13 22:33 UTC (permalink / raw)
  To: Malvika Gupta
  Cc: dev, Ananyev, Konstantin, gavin.hu, honnappa.nagarahalli, nd

06/11/2018 11:17, Ananyev, Konstantin:
> 
> Hi Malvika,
> 
> > From: Malvika Gupta <Malvika.Gupta@arm.com>
> > 
> > Convert host machine endianness to networking endianness for
> > comparison of incoming packets with BPF filter
> > 
> > Suggested-by: Brian Brooks <brian.brooks@arm.com>
> > Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> > Reviewed-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
> 
> I don't remember I acked it before actually, but I am ok to do it now for v2.
> Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
> 
> > Acked-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>

Applied, thanks

I don't add Cc:stable@dpdk.org because only x86 BPF is supported for now.

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

end of thread, other threads:[~2018-11-13 22:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-28 20:46 [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap Malvika Gupta
2018-08-28 20:58 ` Honnappa Nagarahalli
2018-09-04 13:56 ` Ananyev, Konstantin
2018-09-05 21:43   ` Malvika Gupta
2018-09-12 18:46     ` Malvika Gupta
2018-10-19 12:17       ` Ananyev, Konstantin
2018-10-25 16:59         ` Malvika Gupta
2018-10-27 22:00           ` Ananyev, Konstantin
2018-11-01 18:24             ` Malvika Gupta
2018-11-02 19:08 ` [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap Malvika Gupta
2018-11-06  1:52   ` Thomas Monjalon
2018-11-06 10:17   ` Ananyev, Konstantin
2018-11-13 22:33     ` Thomas Monjalon

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).