From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0074.outbound.protection.outlook.com [104.47.2.74]) by dpdk.org (Postfix) with ESMTP id 416F17EC7 for ; Thu, 25 Oct 2018 18:59:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oUYHMpnB0wCAND+9tL3h+iN5HDcyfk5AxwoT5ZJ6nwY=; b=bd8txb5nPme3gUE3g9SLoffKoR7+k4QY/SqNxAA0GW2LClSBcgVnKs47cEMzFDj4gZ4rLkEEgr+4QxrCRKUoj+eOn/zjg6ySJvhNPqJyo0HsHExb0nD0CYCPe7DYcauxfqL9H3lxAbTZNhAVTouTqBwR39yuUax9L0+OQ+HSHMw= Received: from DB6PR0801MB1864.eurprd08.prod.outlook.com (10.168.85.10) by DB6PR0801MB1637.eurprd08.prod.outlook.com (10.169.226.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1250.20; Thu, 25 Oct 2018 16:59:56 +0000 Received: from DB6PR0801MB1864.eurprd08.prod.outlook.com ([fe80::acb6:b973:48a9:792]) by DB6PR0801MB1864.eurprd08.prod.outlook.com ([fe80::acb6:b973:48a9:792%2]) with mapi id 15.20.1250.032; Thu, 25 Oct 2018 16:59:56 +0000 From: Malvika Gupta To: "Ananyev, Konstantin" CC: "dev@dpdk.org" , "Gavin Hu (Arm Technology China)" , Honnappa Nagarahalli , nd Thread-Topic: [PATCH] test/bpf: use hton instead of __builtin_bswap Thread-Index: AQHUPxBK9GM4qmAjxku+s3XgHfeEQqTgMAWAgAIP03CACssPIIA5wlCAgAmquSA= Date: Thu, 25 Oct 2018 16:59:55 +0000 Message-ID: References: <20180828204620.1862-1-Malvika.Gupta@arm.com> <2601191342CEEE43887BDE71AB977258EA9511E7@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772580102FE9DA4@IRSMSX106.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB9772580102FE9DA4@IRSMSX106.ger.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Malvika.Gupta@arm.com; x-originating-ip: [217.140.111.135] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0801MB1637; 6:0QGOarwow6xcmkeY7/JFiWsD4N86z8DdhiO4vKzF7KndfZo5670Ip9G6DjjeyWzpqtebUbD5Uw9xDDsPQcwPkYBwZn4B4DIja4zZaBwMKsUH6iDlkhFuhq2fVd6YG1L5xQ3+RO83npgABE16VpGj6GoVHNeR8k9PoT6uSWL/A6HVqj2K4Ai1LPY1SP10VMvYXjkfCF+6+LW9bb7kZt/zBP2Hs9z0d9vUuXKEbg1UNh7odKx8pKs0iOarUGgKo5KPB7XV/10glr0rT4uECzwmzSPt2MjeggD3BolDyyYX0hP/Uef1PbzgaNKFHwnJl0IV0NM+2vFQiYB0FmJlkBci7e0nuXCZQ7po3QZU44xEjh9VFNQLFSoBv4XhLb+nvhrILbv6QhfbK1VgKvrrhR44TqlI3wUdXZ9GenVoEoKBH6G/Qu5h9GK7HFHjQshdaLt6y+z9RZkKGvMz3RLu7wFHpw==; 5:4dax/cywRZNTcpM9PthvemiYZ9arJ5RARDlSu10MeKVYiyjZWHY9jRN16JI1uFFSfRcnB5qrylVRfxvSLyoNCM/WblWUpD1Wzmuy/Gk72HrYnbB0zK2Y0K+tj/I2GsLEQ9ErEktCcubn+5uMyqFlLvgAwM+iwj0/I8v7rjkBZIQ=; 7:81cstPAtrchRDNKQci3OUVNSoC1dDzNODQQCW/5dIxw6NtE84dbS2v0RR+7YFvhv46aRfrpVYgJNxNhtffpYIz4f+9DcbeLKeDMFCzgmAAjLKtebU4nL1FoqgLHKsGZd6V0YSbcCqLsdcWTH7FJ+qbaIJB5LSsnRc+RJLS4kXN6YILVLpgFn8Gq5nmCs9HagbONeiLLhc/iAnSYzyJHi+2g716gCUfS+9jg1CWtOKSVgVGz1qLBZGLX54s+duCnK x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-ms-office365-filtering-correlation-id: 063645a9-de3a-4460-e467-08d63a9b4a60 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DB6PR0801MB1637; x-ms-traffictypediagnostic: DB6PR0801MB1637: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(228905959029699)(180628864354917); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231355)(944501410)(52105095)(93006095)(93001095)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:DB6PR0801MB1637; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0801MB1637; x-forefront-prvs: 083691450C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(39860400002)(376002)(346002)(396003)(136003)(13464003)(199004)(189003)(81156014)(4326008)(3846002)(26005)(6916009)(305945005)(6116002)(8676002)(6506007)(478600001)(476003)(53546011)(99286004)(72206003)(86362001)(5660300001)(2906002)(229853002)(2900100001)(9686003)(7696005)(71200400001)(71190400001)(76176011)(186003)(102836004)(81166006)(256004)(6436002)(53936002)(55016002)(5250100002)(105586002)(8936002)(93886005)(11346002)(316002)(446003)(7736002)(106356001)(33656002)(66066001)(6246003)(486006)(97736004)(74316002)(54906003)(68736007)(25786009)(14454004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB1637; H:DB6PR0801MB1864.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 9hl449KxrAG8feytrWISQZJfnucZkO277TYaDDEtSqscplPMbt1nnzyj+n4ecqbsqzm1a3kIn7Ea8QTO7AHZF+4KsLwSR3G5xsLq6rD5xBVpKvTuhqoBBMzq+HWQUMGZ27UEPN8Yd8dK8ITLPlpZgEKQbJiYRc1zi3mTw8RprF0n6Sbeyoj7HbXJdLIkeQqBiTK4lNVZGp6XGYTcrgRTRWAJapUZ88hWLpy0CsD4dQVcIpc0B4fQUTw2sT7Z7TUy9dGtKS3QYAC84blR0lAuhkPFZFj8QIu6DhF/jNMXXW6B1WnJ/kKQ57VitlLT2thsHpLQcOWePNNTyMwW9tx2Fjoh0BIxIKm6e9z7mPZYqx0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 063645a9-de3a-4460-e467-08d63a9b4a60 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Oct 2018 16:59:56.0848 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1637 Subject: Re: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Oct 2018 16:59:58 -0000 Hi Konstantin, At time of upstreaming the patch, I had compiled it on Cortex-A72 and it ha= d worked with the -I parameter. But when tried building it on x86-64, I enc= ountered the error that you were facing. From my understanding of this prob= lem, this is a portability issue. As you pointed out, gcc and clang impleme= nt __builtin_constant_p in a different way on x86 but that may not be true = for ARM.=20 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, w= e 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 p= arameter to enable compilation on x86 and later decide if we want to write = a new patch with analogs for builtin hton() and ntoh(). =20 Best, Malvika=20 -----Original Message----- From: Ananyev, Konstantin =20 Sent: Friday, October 19, 2018 7:17 AM To: Malvika Gupta Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) ; Honna= ppa Nagarahalli ; nd Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap Hi Malvika, >=20 > Hi Konstantin, >=20 > I installed the clang version 4.0.1 to check for the issue you were=20 > facing with -O2 compilation. I was able to compile with -O2 and -O0 optim= ization without any errors. Please see the exact command I used and the fol= lowing output for your reference: >=20 > $ clang -O2 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c $=20 > clang -O0 -target bpf -I /usr/include/aarch64-linux-gnu/ -c t1.c $=20 > 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:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/6 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/7 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/8 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6=20 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7=20 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8=20 > 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 >=20 > 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__ >=3D 2 # define __bswap_16(x) \ (__extension__ = \ ({ unsigned short int __v, __x =3D (unsigned short int) (x); = \ if (__builtin_constant_p (__x)) = \ <------ evaluates to FALSE !!! __v =3D __bswap_constant_16 (__x); = \ else = \ __asm__ ("rorw $8, %w0" = \ : "=3Dr" (__v) = \ : "0" (__x) = \ : "cc"); = \ __v; })) # else /* This is better than nothing. */ # define __bswap_16(x) \ (__extension__ = \ ({ unsigned short int __x =3D (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=3D0; return__bswap_constant_16(x);} when compile= d 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.=20 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 >=20 >=20 > -----Original Message----- > From: Malvika Gupta > Sent: Wednesday, September 5, 2018 4:43 PM > To: Ananyev, Konstantin > Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) ;=20 > Honnappa Nagarahalli ; Brian Brooks=20 > ; nd > Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap >=20 > Hi Ananyev, >=20 > I used clang version 6.0.0. Please see the following output for your refe= rence. >=20 > $ 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:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/6 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/6.4.0 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/7 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/8 > Found candidate GCC installation:=20 > /usr/bin/../lib/gcc/aarch64-linux-gnu/8.0.1 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6=20 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.4.0 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7=20 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0 > Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8=20 > 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 >=20 > Also, the code compiles with both -O2 and -O0 for me. >=20 > I hope this was helpful > Best, > Malvika >=20 > -----Original Message----- > From: Ananyev, Konstantin > Sent: Tuesday, September 4, 2018 8:56 AM > To: Malvika Gupta > Cc: dev@dpdk.org; Gavin Hu (Arm Technology China) ;=20 > Honnappa Nagarahalli ; Brian Brooks=20 > ; nd > Subject: RE: [PATCH] test/bpf: use hton instead of __builtin_bswap >=20 > Hi, >=20 > > > > Convert host machine endianness to networking endianness for=20 > > comparison of incoming packets with BPF filter > > > > > > Signed-off-by: Malvika Gupta > > Reviewed-by: Gavin Hu > > Reviewed-by: Brian Brooks > > Suggested-by: Brian Brooks > > --- > > 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=20 > > 60f9434ab..7943fcf34 > > 100644 > > --- a/test/bpf/t1.c > > +++ b/test/bpf/t1.c > > @@ -28,24 +28,25 @@ > > #include > > #include > > #include > > +#include > > > > uint64_t > > entry(void *pkt) > > { > > struct ether_header *ether_header =3D (void *)pkt; > > > > - if (ether_header->ether_type !=3D __builtin_bswap16(0x0800)) > > + if (ether_header->ether_type !=3D htons(0x0800)) >=20 > 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 !=3D 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" >=20 > With '-O0' it compiles ok. >=20 > $ 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:=20 > /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 >=20 > Konstantin >=20 > > return 0; > > > > struct iphdr *iphdr =3D (void *)(ether_header + 1); > > if (iphdr->protocol !=3D 17 || (iphdr->frag_off & 0x1ffff) !=3D 0 || > > - iphdr->daddr !=3D __builtin_bswap32(0x1020304)) > > + iphdr->daddr !=3D htonl(0x1020304)) > > return 0; > > > > int hlen =3D iphdr->ihl * 4; > > struct udphdr *udphdr =3D (void *)iphdr + hlen; > > > > - if (udphdr->dest !=3D __builtin_bswap16(5000)) > > + if (udphdr->dest !=3D htons(5000)) > > return 0; > > > > return 1; > > diff --git a/test/bpf/t3.c b/test/bpf/t3.c index=20 > > 531b9cb8c..24298b7c7 > > 100644 > > --- a/test/bpf/t3.c > > +++ b/test/bpf/t3.c > > @@ -17,6 +17,7 @@ > > #include > > #include > > #include "mbuf.h" > > +#include > > > > extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *,=20 > > unsigned int); > > > > @@ -29,7 +30,7 @@ entry(const void *pkt) > > mb =3D pkt; > > eth =3D rte_pktmbuf_mtod(mb, const struct ether_header *); > > > > - if (eth->ether_type =3D=3D __builtin_bswap16(ETHERTYPE_ARP)) > > + if (eth->ether_type =3D=3D htons(ETHERTYPE_ARP)) > > rte_pktmbuf_dump(stdout, mb, 64); > > > > return 1; > > -- > > 2.17.1