From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id 8045EFFA for ; Thu, 17 Mar 2016 16:49:46 +0100 (CET) Received: by mail-wm0-f42.google.com with SMTP id l124so90196075wmf.1 for ; Thu, 17 Mar 2016 08:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nofutznetworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=bgLF1rW/uzRUBxP/jYB5xDWWhABqir66rv1cYrE3F5I=; b=nOPFEhcQ2NL//5YYbq8201mC4gcJ3hKoq7//ueQPCVMvdCtiU0OiUveLiYU6kjwr4C 7kO1Aogljmi2yHUExnqoiFXXWjnm/j2Qxg07byFPJfo2BNAdebpNjcHbZsSLAUCKXnDT DN7/PfhTl1pWWIX0U2J6lxaSyZ6L7mBfQ6A/cG7RCsfylOxgV2Z992oorh1TP4ZyQjHC mR8Z5fYQ8S7lxDx/TmIa4Zs0CG1WLlZCDjIpZXfYtWeeDSpiyyrbVCofjj8loMt6eT53 xr3gvCnbWmSTjeg7XVCZKJrl/kf9iHUD6eCQALTtmOJOIgdHc0z8Qqknfugn/Zjabg9Q ciuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=bgLF1rW/uzRUBxP/jYB5xDWWhABqir66rv1cYrE3F5I=; b=JOj/tOFEf9m2rYUak3FQsHZs/LHaoq6LEzJzrLUj6eTE08Rbstg5mu7G0JAxkNTCJr R1Dt82FnzgcuV4gexuIHRp4qzj408NoclLa4Twy6WrveXfZnNQH3MPqwzyBQ0VateeTy kEPGzCv73rM9DwJXn7QaLxkPB0pcaYjd76w/a64cbcjxLWYT9A6bk5W/h64XWXBWcg9B 56fPAgauiOMcfT8DhlCFU4kbYF1gYYaGPcPvd0c7aA3psyvQQrMZbmE8xnjGoKJv61K5 p0cMp4ZAuA9UiG8AWtnGsCDKBPwgh07aXCO83nVUJEvDs9AZ1ZQI3NWSHYnnS9YgQ2SO YgVA== X-Gm-Message-State: AD7BkJJcnOUvol0xUVWcNacwVsW7t3Fd7bksf9fotMT1Snv78euvZZulgEbJ1CvU54RZPQ== X-Received: by 10.28.46.5 with SMTP id u5mr11948566wmu.75.1458229786344; Thu, 17 Mar 2016 08:49:46 -0700 (PDT) Received: from lap-3.nofutz.com (ppp089210158019.access.hol.gr. [89.210.158.19]) by smtp.gmail.com with ESMTPSA id v82sm8693109wmv.6.2016.03.17.08.49.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Mar 2016 08:49:45 -0700 (PDT) From: Lazaros Koromilas To: dev@dpdk.org Date: Thu, 17 Mar 2016 17:49:43 +0200 Message-Id: <1458229783-15547-1-git-send-email-l@nofutznetworks.com> X-Mailer: git-send-email 1.9.1 Subject: [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 15:49:46 -0000 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) + 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) + return 0; + /* move cons.head atomically */ do { /* Restore n as it may change every loop */ -- 1.9.1