From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id E16E22C1A for ; Tue, 22 Mar 2016 11:13:11 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 22 Mar 2016 03:13:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,376,1455004800"; d="scan'208";a="70992617" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.220.103]) by fmsmga004.fm.intel.com with SMTP; 22 Mar 2016 03:13:08 -0700 Received: by (sSMTP sendmail emulation); Tue, 22 Mar 2016 10:13:08 +0025 Date: Tue, 22 Mar 2016 10:13:08 +0000 From: Bruce Richardson To: "Xie, Huawei" Cc: Mauricio =?iso-8859-1?Q?V=E1squez?= , Thomas Monjalon , "dev@dpdk.org" , Olivier Matz , Lazaros Koromilas Message-ID: <20160322101307.GA19268@bricha3-MOBL3> References: <1458229783-15547-1-git-send-email-l@nofutznetworks.com> <20160318101823.GC4848@bricha3-MOBL3> <56EBD806.8010707@6wind.com> <17186869.jQBbCLbaVI@xps13> <20160318141632.GC12932@bricha3-MOBL3> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: Intel Shannon Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [dpdk-dev] [PATCH v2] ring: check for zero objects mc dequeue / mp enqueue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Mar 2016 10:13:12 -0000 On Mon, Mar 21, 2016 at 05:47:44PM +0000, Xie, Huawei wrote: > On 3/18/2016 10:17 PM, Bruce Richardson wrote: > > On Fri, Mar 18, 2016 at 01:47:29PM +0100, Mauricio Vásquez wrote: > >> Hi, > >> > >> > >> On Fri, Mar 18, 2016 at 11:35 AM, Thomas Monjalon >>> wrote: > >>> 2016-03-18 11:27, Olivier Matz: > >>>> On 03/18/2016 11:18 AM, Bruce Richardson wrote: > >>>>>>> + /* Avoid the unnecessary cmpset operation below, which is > >>> also > >>>>>>> + * potentially harmful when n equals 0. */ > >>>>>>> + if (n == 0) > >>>>>>> > >>>>>> What about using unlikely here? > >>>>>> > >>>>> Unless there is a measurable performance increase by adding in > >>> likely/unlikely > >>>>> I'd suggest avoiding it's use. In general, likely/unlikely should only > >>> be used > >>>>> for things like catestrophic errors because the penalty for taking the > >>> unlikely > >>>>> leg of the code can be quite severe. For normal stuff, where the code > >>> nearly > >>>>> always goes one way in the branch but occasionally goes the other, the > >>> hardware > >>>>> branch predictors generally do a good enough job. > >>>> Do you mean using likely/unlikely could be worst than not using it > >>>> in this case? > >>>> > >>>> To me, using unlikely here is not a bad idea: it shows to the compiler > >>>> and to the reader of the code that is case is not the usual case. > >>> It would be nice to have a guideline section about likely/unlikely in > >>> doc/guides/contributing/design.rst > >>> > >>> Bruce gave a talk at Dublin about this kind of things. > >>> I'm sure he could contribute more design guidelines ;) > >>> > >> There is a small explanation in the section "Branch Prediction" of > >> doc/guides/contributing/coding_style.rst, but I do not know if that is > >> enough to understand when to use them. > >> > >> I've made a fast check and there are many PMDs that use them to check if > >> number of packets is zero in the transmission function. > > Yeah, and I wonder how many of those are actually necessary too :-) > > > > It's not a big deal either way, I just think the patch is fine as-is without > > the extra macros. > > IMO we use likely/unlikely in two cases, catastrophic errors and the > code nearly always goes one way, i.e, preferred/favored fast path. > Likely/unlikely helps not only for branch predication but also for cache For branch prediction, anything after the first time through the code path the prediction will be based on what happened before rather than any static hints in the code. > usage. The code generated for the likely path will directly follow the > branch instruction. To me, it is reasonable enough to add unlikely for n > == 0, which we don't expect to happen. > I remember with/without likely, compiler could generate three kind of > instructions. Didn't deep dive into it. > > > > > /Bruce > > >