From patchwork Tue Oct 1 06:29:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 174824 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp8126896ill; Mon, 30 Sep 2019 23:29:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyspJy7Q0kNXgNm8T3bccqgXtwql0tcaeYPIx7j8KIr9ch1RGmWDOvRANHGPo8qwVmq8eps X-Received: by 2002:a17:906:254d:: with SMTP id j13mr22625062ejb.30.1569911369696; Mon, 30 Sep 2019 23:29:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569911369; cv=none; d=google.com; s=arc-20160816; b=ncDoc4eomHD/qQBcS0/oRGRofn6H77CqFui+93OT9oVwAReh7MDCkyGGU7Pusg/Uar Ko5P1z+TktZxgPGv3iCHJZWocBmA67RBuiCPS0sOOZJdsIhXnKPi4QYTuighJx662p2f F0b3DfUTxISZKuKeWbo+OTDzQgUgbXJ6H7DOoNGAjGezchzTWl0uueYJYy9HK/c6tr0Y nF4nap7/QUzyWxZINPPqtmqATTslw1VmZK/fJRF5K/F2sYPBUWHbpCJRAEYlriDwzTvs TgTLknVuwYheSXu4bByj03lQze/Rs3MXj0NJZpnr9OFFU2pffquVcVO02H6cRzGVB8qs fDOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=YA8458dGu7H5Y2ayrWFU46ypOu1MMGzQ5tVOvKKAurA=; b=x+2GV0JITpoxc1BLuBFYnUYxPzn1LfEnAqHdTAIN3nIpC8B7L1F+Qx3F23ADWfm/5p fUujKhWoQzp0RvYw8eKw+Se0aK5qcmqZphk+SthIMpTJaa1EAZJMr22ioD95qDXcChgk ve4lTfVmjlVZPd/xVH1MB1cRrnftuqtX3WAYmd//mQq44vdwZk0z+tJ32iyk3lLq+KHQ 8g4QfzJsG8PMi33uIrlCuK1NQ08MrPFk4KW4/SuDVcmHUl1Ty0d2/F+Kqlgowr6H/qB7 vpXnP5v599K/C+7CuBhBhwpmk/5puPCmskMF8FtT82zGW0bQlXOQfmdRbOR/63XWhYjj UchQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id me9si8215968ejb.280.2019.09.30.23.29.29; Mon, 30 Sep 2019 23:29:29 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 71D884C8E; Tue, 1 Oct 2019 08:29:28 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 86D9D4C8D for ; Tue, 1 Oct 2019 08:29:26 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D8C951570; Mon, 30 Sep 2019 23:29:25 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 878663F7D7; Mon, 30 Sep 2019 23:32:03 -0700 (PDT) From: Honnappa Nagarahalli To: honnappa.nagarahalli@arm.com, konstantin.ananyev@intel.com, stephen@networkplumber.org, paulmck@linux.ibm.com Cc: yipeng1.wang@intel.com, vladimir.medvedkin@intel.com, ruifeng.wang@arm.com, dharmik.thakkar@arm.com, dev@dpdk.org, nd@arm.com Date: Tue, 1 Oct 2019 01:29:15 -0500 Message-Id: <20191001062917.35578-2-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191001062917.35578-1-honnappa.nagarahalli@arm.com> References: <20190906094534.36060-1-ruifeng.wang@arm.com> <20191001062917.35578-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v3 1/3] lib/ring: add peek API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Ruifeng Wang The peek API allows fetching the next available object in the ring without dequeuing it. This helps in scenarios where dequeuing of objects depend on their value. Signed-off-by: Dharmik Thakkar Signed-off-by: Ruifeng Wang Reviewed-by: Honnappa Nagarahalli Reviewed-by: Gavin Hu --- lib/librte_ring/rte_ring.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) -- 2.17.1 diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index 2a9f768a1..d3d0d5e18 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -953,6 +953,36 @@ rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table, r->cons.single, available); } +/** + * Peek one object from a ring. + * + * The peek API allows fetching the next available object in the ring + * without dequeuing it. This API is not multi-thread safe with respect + * to other consumer threads. + * + * @param r + * A pointer to the ring structure. + * @param obj_p + * A pointer to a void * pointer (object) that will be filled. + * @return + * - 0: Success, object available + * - -ENOENT: Not enough entries in the ring. + */ +__rte_experimental +static __rte_always_inline int +rte_ring_peek(struct rte_ring *r, void **obj_p) +{ + uint32_t prod_tail = r->prod.tail; + uint32_t cons_head = r->cons.head; + uint32_t count = (prod_tail - cons_head) & r->mask; + unsigned int n = 1; + if (count) { + DEQUEUE_PTRS(r, &r[1], cons_head, obj_p, n, void *); + return 0; + } + return -ENOENT; +} + #ifdef __cplusplus } #endif