From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olivier Matz Subject: Re: [PATCH v2] ring: check for zero objects mc dequeue / mp enqueue Date: Fri, 18 Mar 2016 11:27:18 +0100 Message-ID: <56EBD806.8010707@6wind.com> References: <1458229783-15547-1-git-send-email-l@nofutznetworks.com> <20160318101823.GC4848@bricha3-MOBL3> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: Lazaros Koromilas , dev@dpdk.org To: Bruce Richardson , =?UTF-8?Q?Mauricio_V=c3=a1squez?= Return-path: Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by dpdk.org (Postfix) with ESMTP id 771FA5947 for ; Fri, 18 Mar 2016 11:27:21 +0100 (CET) Received: by mail-wm0-f51.google.com with SMTP id p65so30381554wmp.0 for ; Fri, 18 Mar 2016 03:27:21 -0700 (PDT) In-Reply-To: <20160318101823.GC4848@bricha3-MOBL3> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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. Olivier