From mboxrd@z Thu Jan 1 00:00:00 1970 From: Or Gerlitz Subject: Re: [PATCH net-next V2 3/3] net: Add GRO support for vxlan traffic Date: Wed, 8 Jan 2014 11:45:34 +0200 Message-ID: <52CD1E3E.3090806@mellanox.com> References: <1389108594-665-1-git-send-email-ogerlitz@mellanox.com> <1389108594-665-4-git-send-email-ogerlitz@mellanox.com> <1389124947.26646.54.camel@edumazet-glaptop2.roam.corp.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit Cc: Eric Dumazet , Jerry Chu , "Eric Dumazet" , Herbert Xu , Linux Netdev List , Yan Burman , Shlomo Pongratz To: Tom Herbert Return-path: Received: from eu1sys200aog102.obsmtp.com ([207.126.144.113]:52520 "EHLO eu1sys200aog102.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755152AbaAHJq7 (ORCPT ); Wed, 8 Jan 2014 04:46:59 -0500 In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: On 07/01/2014 23:09, Tom Herbert wrote: > On Tue, Jan 7, 2014 at 12:12 PM, Or Gerlitz wrote: >> On Tue, Jan 7, 2014 at 10:02 PM, Eric Dumazet wrote: >>> On Tue, 2014-01-07 at 21:43 +0200, Or Gerlitz wrote: >>>> On Tue, Jan 7, 2014 at 8:08 PM, Tom Herbert wrote: >>>>> Why ^ instead of != ? >>>> The XOR approach is very popular in the GRO stack, e.g see the IPv4 chain >>>> of inet_gro_receive() && tcp_gro_receive(), I guess this might relates >>>> to more efficient assembly code for ^ vs. != and/or the fast/elegant >>>> transitive nature of that operator >>> This trick is only needed/used when many compares are folded into a >>> single conditional : >>> >>> if (a->f1 != b->f1 || a->f2 != b->f2) >>> >>> -> >>> >>> if (((a->f1 ^ b->f1) | (a->f2 ^ b->f2)) != 0) >>> >>> Please do not use XOR for a single compare. >> OK, but just out of curiosity -- what's the reasoning? clarity or >> efficiency or both? > Both. Compiling a simple program and comparing alternatives: gcc > produced the identical code for the single conditional (^ vs !=) > using the cmp instruction. Testing the two conditional case like Eric > provided; the second method (using ^) resulted in 4 more instructions, > but only one branch as opposed to two in the first method (!=). Method > #1 has the advantage of short circuiting when the first condition is > true, so organizing the conditionals to maximize the probability of > short circuit could be beneficial. OK, I will follow that. Or.