From: Olivier MATZ <olivier.matz@6wind.com>
To: "Yan, Liming (Nokia - CN/Hangzhou)" <liming.yan@nokia.com>,
"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: Could DPDK ring provide peek interface or any comments for this function?
Date: Tue, 04 Aug 2015 14:57:16 +0200 [thread overview]
Message-ID: <55C0B6AC.2080001@6wind.com> (raw)
In-Reply-To: <D102FDD76C087B41BDC117FCC87D056F3E7E84CA@SGSIMBX007.nsn-intra.net>
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
>
>
next prev parent reply other threads:[~2015-08-04 12:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-03 21:39 I want to post my patch about examples/kni EaseTheWorld Mr.
2015-08-03 22:10 ` Thomas Monjalon
2015-08-04 2:08 ` Could DPDK ring provide peek interface or any comments for this function? Yan, Liming (Nokia - CN/Hangzhou)
2015-08-04 2:20 ` Yan, Liming (Nokia - CN/Hangzhou)
2015-08-04 12:57 ` Olivier MATZ [this message]
2015-08-04 16:14 ` Stephen Hemminger
2015-08-05 3:08 ` Yan, Liming (Nokia - CN/Hangzhou)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55C0B6AC.2080001@6wind.com \
--to=olivier.matz@6wind.com \
--cc=dev@dpdk.org \
--cc=liming.yan@nokia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.