DPDK patches and discussions
 help / color / mirror / Atom feed
From: Malvika Gupta <Malvika.Gupta@arm.com>
To: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>
Cc: "dev@dpdk.org" <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: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap
Date: Wed, 5 Sep 2018 21:43:28 +0000	[thread overview]
Message-ID: <AM5PR0801MB18595543877A92AE78D67C23E7020@AM5PR0801MB1859.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <2601191342CEEE43887BDE71AB977258EA9511E7@irsmsx105.ger.corp.intel.com>

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

  reply	other threads:[~2018-09-05 21:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 20:46 Malvika Gupta
2018-08-28 20:58 ` Honnappa Nagarahalli
2018-09-04 13:56 ` Ananyev, Konstantin
2018-09-05 21:43   ` Malvika Gupta [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM5PR0801MB18595543877A92AE78D67C23E7020@AM5PR0801MB1859.eurprd08.prod.outlook.com \
    --to=malvika.gupta@arm.com \
    --cc=Brian.Brooks@arm.com \
    --cc=Gavin.Hu@arm.com \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@intel.com \
    --cc=nd@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).