From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f179.google.com (mail-wr0-f179.google.com [209.85.128.179]) by dpdk.org (Postfix) with ESMTP id 269B5108A for ; Wed, 8 Mar 2017 11:49:14 +0100 (CET) Received: by mail-wr0-f179.google.com with SMTP id g10so20435945wrg.2 for ; Wed, 08 Mar 2017 02:49:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:date:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jiaOUb9DtksGWcnx1yXk/lnFQvhrgRt6/a1iem16EIk=; b=HSkESbohAU2hfN7bYrguwHoETWKqWksulT8B2/1jCVx1uUKhvDYwkhWSY+K0vmwy3M pxRitfOTRtpFpUsCBsl3bSSQCVAb4n08QwQz1RvTiC8MjDPsnnxOSqe1O1dC+YwDstY9 IoGu51ROWFHxvMN6pe3D91xT3cYL8pWplbQKx8ZBS352lDSAJHhPj2LjD68iJfu/ou6f e45C5bnt84J39wg/PhxHH4STPp3L3j1TG4LMtejj9vAayxVkO7iVvTefbjW/mURdfjM3 dOtv9Z68tEdcfDsUFnJUGDKb1VFxipw97cl08yDikaf2dIbc1mw5cFbFyTIlZqBh1EEZ SAtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jiaOUb9DtksGWcnx1yXk/lnFQvhrgRt6/a1iem16EIk=; b=oMQ7D0Gr9QK/bjRuk1mGa+nBvAH9M0AOB5rY9VkXiHZrH9d0af/2KBBwJm3hTwYI36 mAZWzeCThOx0zJNDsSB/UXDzjmFhJaEGGvIiFq/ZAeLOomGfMSBUbGJWd2CGku4cORSI vrcPKfgt+CYJgsNkkFAPj2EfWowwRv8iESIktIOuhl/ViPbCEwqCyREo6ROBklnRhs3v nQFzaBTeRhXqt3peAIgqIu+bWdH+ZMdu5BEryfl9jStwh4OjRUS9KfhpRSnaxpil3taQ fqV9M+wcU5oMDepqus7wtdchi9EJc6VqDD4bQoSmGI0l52cH/ns8kMu3o1uw0oAiZlLz t7YA== X-Gm-Message-State: AMke39mlpfM8/GaEED+YBv8zvqujytbj2nZj7ss//NCHeB2AycrUqUllOEmEl5yV9ONg/MYK X-Received: by 10.223.167.66 with SMTP id e2mr4563161wrd.48.1488970154644; Wed, 08 Mar 2017 02:49:14 -0800 (PST) Received: from glumotte.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id 17sm3655648wru.16.2017.03.08.02.49.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Mar 2017 02:49:14 -0800 (PST) From: Olivier MATZ X-Google-Original-From: Olivier MATZ Date: Wed, 8 Mar 2017 11:49:06 +0100 To: Bruce Richardson Cc: olivier.matz@6wind.com, dev@dpdk.org Message-ID: <20170308114906.6101f90b@glumotte.dev.6wind.com> In-Reply-To: <20170223172407.27664-13-bruce.richardson@intel.com> References: <20170223172407.27664-1-bruce.richardson@intel.com> <20170223172407.27664-13-bruce.richardson@intel.com> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v1 12/14] ring: separate out head index manipulation for enq/deq 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: , X-List-Received-Date: Wed, 08 Mar 2017 10:49:15 -0000 On Thu, 23 Feb 2017 17:24:05 +0000, Bruce Richardson wrote: > We can write a single common function for head manipulation for enq > and a common one for deq, allowing us to have a single worker function > for enq and deq, rather than two of each. Update all other inline > functions to use the new functions. > > Signed-off-by: Bruce Richardson > --- > lib/librte_ring/rte_ring.c | 4 +- > lib/librte_ring/rte_ring.h | 328 ++++++++++++++++++++------------------------- > 2 files changed, 149 insertions(+), 183 deletions(-) > [...] > +static inline __attribute__((always_inline)) unsigned int > +__rte_ring_do_enqueue(struct rte_ring *r, void * const *obj_table, > + unsigned int n, enum rte_ring_queue_behavior behavior, > + int is_sp, unsigned int *free_space) > { > - uint32_t prod_head, cons_tail; > - uint32_t prod_next, free_entries; > - uint32_t mask = r->mask; > - > - prod_head = r->prod.head; > - cons_tail = r->cons.tail; > - /* The subtraction is done between two unsigned 32bits value > - * (the result is always modulo 32 bits even if we have > - * prod_head > cons_tail). So 'free_entries' is always between 0 > - * and size(ring)-1. */ > - free_entries = mask + cons_tail - prod_head; > - > - /* check that we have enough room in ring */ > - if (unlikely(n > free_entries)) > - n = (behavior == RTE_RING_QUEUE_FIXED) ? 0 : free_entries; > + uint32_t prod_head, prod_next; > + uint32_t free_entries; > > + n = __rte_ring_move_prod_head(r, is_sp, n, behavior, > + &prod_head, &prod_next, &free_entries); > if (n == 0) > goto end; > > - > - prod_next = prod_head + n; > - r->prod.head = prod_next; > - > - /* write entries in ring */ > ENQUEUE_PTRS(); > rte_smp_wmb(); > > + /* > + * If there are other enqueues in progress that preceded us, > + * we need to wait for them to complete > + */ > + while (unlikely(r->prod.tail != prod_head)) > + rte_pause(); > + I'd say this part should not be done in case is_sp == 1. Since it is sometimes a constant arg in an inline func, it may be better to add the if (is_sp == 0). [...] > +static inline __attribute__((always_inline)) unsigned int > +__rte_ring_do_dequeue(struct rte_ring *r, void **obj_table, > unsigned int n, enum rte_ring_queue_behavior behavior, > - unsigned int *available) > + int is_mp, unsigned int *available) > { > - uint32_t cons_head, prod_tail; > - uint32_t cons_next, entries; > - uint32_t mask = r->mask; > - > - cons_head = r->cons.head; > - prod_tail = r->prod.tail; > - /* The subtraction is done between two unsigned 32bits value > - * (the result is always modulo 32 bits even if we have > - * cons_head > prod_tail). So 'entries' is always between 0 > - * and size(ring)-1. */ > - entries = prod_tail - cons_head; > - > - if (n > entries) > - n = (behavior == RTE_RING_QUEUE_FIXED) ? 0 : entries; > - > - if (unlikely(entries == 0)) > - goto end; > + uint32_t cons_head, cons_next; > + uint32_t entries; > > - cons_next = cons_head + n; > - r->cons.head = cons_next; > + n = __rte_ring_move_cons_head(r, is_mp, n, behavior, > + &cons_head, &cons_next, &entries); > + if (n == 0) > + goto end; > > - /* copy in table */ > DEQUEUE_PTRS(); > rte_smp_rmb(); > > + /* > + * If there are other enqueues in progress that preceded us, > + * we need to wait for them to complete > + */ > + while (unlikely(r->cons.tail != cons_head)) > + rte_pause(); > + > r->cons.tail = cons_next; Same here.