From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by dpdk.org (Postfix) with ESMTP id D56C0C33C for ; Tue, 4 Aug 2015 14:57:26 +0200 (CEST) Received: by wibud3 with SMTP id ud3so22638015wib.0 for ; Tue, 04 Aug 2015 05:57:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=2XwdXX/OnFR/XT5VIr9nfIjimHtFoDZzQQk8SV8/wug=; b=R0XESOzoedbpRzEzSQlLgStv97RHu/1pAjwKuuLoOq3XJLRQWQci4vOXoZdpeqlZ5o py9baSoE59yxPPq/sWpDpLhpDLeU01n352QIYYa2HgQQdAbm6b7ynr8+wqUUF5fM3h01 uWX6o/98nGBlN8c4KdDMcY2BtpdDuEQOqIsP9d+RBRqWWeP6EEUIr7kBDAxVhNE4pOVi 8NpNv03w5pfiwqjiBmKKG8vlsgnxHPTTraYkcXlOGuXPn7lJP4UrDVtvWJjD8fH7d413 VDd8fORIAf4GMksHL+w9N1+SoIhn4keQjd4IU6uiORGY+LCFEoFUulSfLaoXHdF3nTOv 7pJw== X-Gm-Message-State: ALoCoQl1O9zhs/Gv1c07ACVYhtYevIHVuF1PspZo2X3oa+nS44lN35h1oRoB25bEWfZ/aUHPr2/l X-Received: by 10.194.77.5 with SMTP id o5mr8626925wjw.102.1438693046720; Tue, 04 Aug 2015 05:57:26 -0700 (PDT) Received: from [10.16.0.195] (6wind.net2.nerim.net. [213.41.151.210]) by smtp.gmail.com with ESMTPSA id 4sm1705570wjt.46.2015.08.04.05.57.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Aug 2015 05:57:25 -0700 (PDT) Message-ID: <55C0B6AC.2080001@6wind.com> Date: Tue, 04 Aug 2015 14:57:16 +0200 From: Olivier MATZ User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: "Yan, Liming (Nokia - CN/Hangzhou)" , "dev@dpdk.org" References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] Could DPDK ring provide peek interface or any comments for this function? 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: Tue, 04 Aug 2015 12:57:27 -0000 Hi, On 08/04/2015 04:20 AM, Yan, Liming (Nokia - CN/Hangzhou) wrote: > Hi, > As we see, DPDK ring has mainly the enqueue/dequeue APIs for SINGLE/MULTI producer/consumer. I have a requirement in work to take a peek on the top object in the ring. I don't want to consume it, just check the reference of the object. How could this be supported? Or any alternative solution for my requirement? Thanks. > I wrote my own simple peek interface but it's not MC-safe. I think it's better if DPDK can support it officially. I think it's a good idea. I think we could avoid a test by using the same naming convention than other functions applying to single consumer rings. I'm not sure the function is safe on mc rings: the pointer returned via peek() should not be accessed while another core dequeues the object and modify/free it. A simplified version would be something like that: /** * Peek one object from a single-consumer ring * * The returned object is not dequeued. This function does not work * on a multi-consumers ring. * * @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; objects dequeued. * - -ENOENT: Not enough entries in the ring to peek */ static inline int rte_ring_sc_peek(struct rte_ring *r, void **obj_p) { if (unlikely(rte_ring_empty(r))) return -ENOENT; *obj_p = r->ring[r->cons.head & r->prod.mask]; return 0; } Regards, Olivier > > > /** > + * Just take a peek on the top object from a ring but not consume it. > + * Note: This interface is MC and multi-thread not safe. > + * It can only be used for ring with RING_F_SC_DEQ attribute. > + * > + * @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 is peeked. > + * - -ENOENT: Not entries in the ring. > + * - - EPERM: Operation not permitted/supported > + */ > +static inline int __attribute__((always_inline)) > +rte_ring_peek(const struct rte_ring *r, void **obj_p) > +{ > + uint32_t cons_head, prod_tail; > + > + if (r->cons.sc_dequeue) { > + cons_head = r->cons.head; > + prod_tail = r->prod.tail; > + > + if (prod_tail - cons_head == 0) { > + return -ENOENT; > + } > + *obj_p = r->ring[cons_head & r->prod.mask]; > + } else { > + return -EPERM; > + } > + return 0; > +} > + > +/** > > > --------^_^-------- > Best Regards > Yan Limin > >