DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Olivier Matz <olivier.matz@6wind.com>
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] mbuf: optimize first reference increment in rte_pktmbuf_attach
Date: Wed, 3 Jun 2015 11:59:49 +0100	[thread overview]
Message-ID: <20150603105948.GC12832@bricha3-MOBL3> (raw)
In-Reply-To: <1433151145-8176-1-git-send-email-olivier.matz@6wind.com>

On Mon, Jun 01, 2015 at 11:32:25AM +0200, Olivier Matz wrote:
> As it's done in __rte_pktmbuf_prefree_seg(), we can avoid using an
> atomic increment in rte_pktmbuf_attach() by checking if we are the
> only owner of the mbuf first.
> 
> Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
> ---
>  lib/librte_mbuf/rte_mbuf.h | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
> index ab6de67..cea35b7 100644
> --- a/lib/librte_mbuf/rte_mbuf.h
> +++ b/lib/librte_mbuf/rte_mbuf.h
> @@ -838,7 +838,11 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m)
>  	else
>  		md = rte_mbuf_from_indirect(m);
>  
> -	rte_mbuf_refcnt_update(md, 1);
> +	/* optimize the case where we are the only owner */
> +	if (likely(rte_mbuf_refcnt_read(md) == 1))
> +		rte_mbuf_refcnt_set(md, 2);
> +	else
> +		rte_mbuf_refcnt_update(md, 1);
>  	mi->priv_size = m->priv_size;
>  	mi->buf_physaddr = m->buf_physaddr;
>  	mi->buf_addr = m->buf_addr;
> -- 
> 2.1.4
> 
Why not make the change inside rte_mbuf_refcnt_update itself? If it is ever
called with a current refcnt of 1, it should always be safe to do the update
without a cmpset.

/Bruce

  reply	other threads:[~2015-06-03 10:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01  9:32 Olivier Matz
2015-06-03 10:59 ` Bruce Richardson [this message]
2015-06-05  9:07   ` Olivier MATZ
2015-06-08 14:57 ` [dpdk-dev] [PATCH v2] mbuf: optimize rte_mbuf_refcnt_update Olivier Matz
2015-06-09 12:57   ` Bruce Richardson
2015-06-12 14:10     ` Thomas Monjalon

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=20150603105948.GC12832@bricha3-MOBL3 \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=olivier.matz@6wind.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).