From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 3A2F52BB2 for ; Fri, 18 Mar 2016 11:35:16 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP; 18 Mar 2016 03:35:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,354,1455004800"; d="scan'208";a="936706679" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.221.44]) by orsmga002.jf.intel.com with SMTP; 18 Mar 2016 03:35:13 -0700 Received: by (sSMTP sendmail emulation); Fri, 18 Mar 2016 10:35:12 +0025 Date: Fri, 18 Mar 2016 10:35:12 +0000 From: Bruce Richardson To: Olivier Matz Cc: Mauricio =?iso-8859-1?Q?V=E1squez?= , Lazaros Koromilas , dev@dpdk.org Message-ID: <20160318103512.GE4848@bricha3-MOBL3> References: <1458229783-15547-1-git-send-email-l@nofutznetworks.com> <20160318101823.GC4848@bricha3-MOBL3> <56EBD806.8010707@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56EBD806.8010707@6wind.com> 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: Fri, 18 Mar 2016 10:35:16 -0000 On Fri, Mar 18, 2016 at 11:27:18AM +0100, Olivier Matz wrote: > Hi, > > On 03/18/2016 11:18 AM, Bruce Richardson wrote: > >>> diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h > >>> index 943c97c..eb45e41 100644 > >>> --- a/lib/librte_ring/rte_ring.h > >>> +++ b/lib/librte_ring/rte_ring.h > >>> @@ -431,6 +431,11 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * > >>> const *obj_table, > >>> uint32_t mask = r->prod.mask; > >>> int ret; > >>> > >>> + /* 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. > Hi Olivier, it might be worse if the user makes a lot of calls with n == 0. It almost certainly would depend upon the compiler. Overall, I'd rather see us err on the side of not putting in the calls unless there is a proven case to do so. I don't think the documentation benefit is huge here either, it's just standard parameter checking at the start of the function. /Bruce