From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from compass.polito.it (compass.polito.it [130.192.55.110]) by dpdk.org (Postfix) with ESMTP id A9D0D56A0 for ; Thu, 17 Mar 2016 17:09:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by compass.polito.it (Postfix) with ESMTP id 534B110013C for ; Thu, 17 Mar 2016 17:09:10 +0100 (CET) Authentication-Results: compass.polito.it (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=studenti.polito.it DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= studenti.polito.it; h=content-type:content-type:cc:to:from:from :subject:subject:message-id:date:date:references:in-reply-to :received:mime-version:received:received:received; s=y2k10; t= 1458230949; bh=eON1wAmyxYzYcDUmN3+weWmcAeazEp18sfKGPTmTY/c=; b=k kA1oTsGJtuehxtu6kgvBn6LAEhQZIrnHwFXEWZHQJYpqJptwkZNJHg1BQod4xx2i hhF/GP2m4RK06Smn1l+S2Lpgvx78AYePpIWncmwuwP87kNIEaUW6Ivfc0ESfhVTG fiJmQWVj1XzftcaLOszeoWfBQ2iMtw9lxDu+dViYkk= X-Virus-Scanned: amavisd-new at studenti.polito.it X-Spam-Flag: NO X-Spam-Score: -5.847 X-Spam-Level: X-Spam-Status: No, score=-5.847 tagged_above=-100 required=3.5 tests=[ALL_TRUSTED=-5, AWL=0.652, BAYES_00=-1.5, HTML_MESSAGE=0.001] autolearn=ham Received: from compass.polito.it ([127.0.0.1]) by localhost (compass.polito.it [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jeAm9YB_VHId for ; Thu, 17 Mar 2016 17:09:09 +0100 (CET) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: s203403@studenti.polito.it) by compass.polito.it (Postfix) with ESMTPSA id 11C51100141 for ; Thu, 17 Mar 2016 17:09:09 +0100 (CET) Received: by mail-lf0-f53.google.com with SMTP id l83so46398783lfd.3 for ; Thu, 17 Mar 2016 09:09:08 -0700 (PDT) X-Gm-Message-State: AD7BkJKRjoiVMySWO1C9C/l5aevcoVYPAqgMFKLoEip6LuUj+xr3OOqhipJNp7ANTRsHhjKY4Etw7tNdQgjSGg== MIME-Version: 1.0 X-Received: by 10.25.79.14 with SMTP id d14mr3936525lfb.98.1458230948625; Thu, 17 Mar 2016 09:09:08 -0700 (PDT) Received: by 10.25.23.166 with HTTP; Thu, 17 Mar 2016 09:09:08 -0700 (PDT) In-Reply-To: <1458229783-15547-1-git-send-email-l@nofutznetworks.com> References: <1458229783-15547-1-git-send-email-l@nofutznetworks.com> Date: Thu, 17 Mar 2016 17:09:08 +0100 X-Gmail-Original-Message-ID: Message-ID: From: =?UTF-8?Q?Mauricio_V=C3=A1squez?= To: Lazaros Koromilas Cc: dev@dpdk.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 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: Thu, 17 Mar 2016 16:09:10 -0000 Hi Lazaros, On Thu, Mar 17, 2016 at 4:49 PM, Lazaros Koromilas wrote: > Issuing a zero objects dequeue with a single consumer has no effect. > Doing so with multiple consumers, can get more than one thread to succeed > the compare-and-set operation and observe starvation or even deadlock in > the while loop that checks for preceding dequeues. The problematic piece > of code when n = 0: > > cons_next = cons_head + n; > success = rte_atomic32_cmpset(&r->cons.head, cons_head, cons_next); > > The same is possible on the enqueue path. > > Signed-off-by: Lazaros Koromilas > --- > lib/librte_ring/rte_ring.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > 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? > + return 0; > + > /* move prod.head atomically */ > do { > /* Reset n to the initial burst count */ > @@ -618,6 +623,11 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void > **obj_table, > unsigned i, rep = 0; > uint32_t mask = r->prod.mask; > > + /* Avoid the unnecessary cmpset operation below, which is also > + * potentially harmful when n equals 0. */ > + if (n == 0) > Also here. > + return 0; > + > /* move cons.head atomically */ > do { > /* Restore n as it may change every loop */ > -- > 1.9.1 > >