* [dpdk-dev] Do we need the refcnt set to zero again?
@ 2015-02-28 18:08 Wiles, Keith
2015-03-02 10:16 ` Bruce Richardson
0 siblings, 1 reply; 2+ messages in thread
From: Wiles, Keith @ 2015-02-28 18:08 UTC (permalink / raw)
To: dev
Looking that the code below does the rte_mbuf_refcnt_set(m,0) need to be present?
static inline struct rte_mbuf* __attribute__((always_inline))
__rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
{
__rte_mbuf_sanity_check(m, 0);
if (likely (rte_mbuf_refcnt_read(m) == 1) ||
likely (rte_mbuf_refcnt_update(m, -1) == 0)) {
rte_mbuf_refcnt_set(m, 0);
/* if this is an indirect mbuf, then
* - detach mbuf
* - free attached mbuf segment
*/
if (RTE_MBUF_INDIRECT(m)) {
struct rte_mbuf *md = RTE_MBUF_FROM_BADDR(m->buf_addr);
rte_pktmbuf_detach(m);
if (rte_mbuf_refcnt_update(md, -1) == 0)
__rte_mbuf_raw_free(md);
}
return(m);
}
return (NULL);
}
It seems like the code could be this or did I miss a race-condition?
static inline struct rte_mbuf* __attribute__((always_inline))
__rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
{
__rte_mbuf_sanity_check(m, 0);
/* The sanity check above should have checked for refcnt being zero */
if ( likely (rte_mbuf_refcnt_update(m, -1) == 0 ) {
/* if this is an indirect mbuf, then
* - detach mbuf
* - free attached mbuf segment
*/
if (RTE_MBUF_INDIRECT(m)) {
struct rte_mbuf *md = RTE_MBUF_FROM_BADDR(m->buf_addr);
rte_pktmbuf_detach(m);
if (rte_mbuf_refcnt_update(md, -1) == 0)
__rte_mbuf_raw_free(md);
}
return(m);
}
return (NULL);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [dpdk-dev] Do we need the refcnt set to zero again?
2015-02-28 18:08 [dpdk-dev] Do we need the refcnt set to zero again? Wiles, Keith
@ 2015-03-02 10:16 ` Bruce Richardson
0 siblings, 0 replies; 2+ messages in thread
From: Bruce Richardson @ 2015-03-02 10:16 UTC (permalink / raw)
To: Wiles, Keith; +Cc: dev
On Sat, Feb 28, 2015 at 06:08:16PM +0000, Wiles, Keith wrote:
> Looking that the code below does the rte_mbuf_refcnt_set(m,0) need to be present?
>
> static inline struct rte_mbuf* __attribute__((always_inline))
> __rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
> {
> __rte_mbuf_sanity_check(m, 0);
>
> if (likely (rte_mbuf_refcnt_read(m) == 1) ||
> likely (rte_mbuf_refcnt_update(m, -1) == 0)) {
>
> rte_mbuf_refcnt_set(m, 0);
>
> /* if this is an indirect mbuf, then
> * - detach mbuf
> * - free attached mbuf segment
> */
> if (RTE_MBUF_INDIRECT(m)) {
> struct rte_mbuf *md = RTE_MBUF_FROM_BADDR(m->buf_addr);
> rte_pktmbuf_detach(m);
> if (rte_mbuf_refcnt_update(md, -1) == 0)
> __rte_mbuf_raw_free(md);
> }
> return(m);
> }
> return (NULL);
> }
>
> It seems like the code could be this or did I miss a race-condition?
What you are really missing is the initial check for refcnt == 1. In the case
of the atomic refcnt, this allows us to skip the atomic decrement operation,
which is very expensive, and instead just do a regular assignment of the refcnt
to zero, in the refcnt_set call.
/Bruce
>
> static inline struct rte_mbuf* __attribute__((always_inline))
> __rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
> {
> __rte_mbuf_sanity_check(m, 0);
>
> /* The sanity check above should have checked for refcnt being zero */
> if ( likely (rte_mbuf_refcnt_update(m, -1) == 0 ) {
>
> /* if this is an indirect mbuf, then
> * - detach mbuf
> * - free attached mbuf segment
> */
> if (RTE_MBUF_INDIRECT(m)) {
> struct rte_mbuf *md = RTE_MBUF_FROM_BADDR(m->buf_addr);
> rte_pktmbuf_detach(m);
> if (rte_mbuf_refcnt_update(md, -1) == 0)
> __rte_mbuf_raw_free(md);
> }
> return(m);
> }
> return (NULL);
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-02 10:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-28 18:08 [dpdk-dev] Do we need the refcnt set to zero again? Wiles, Keith
2015-03-02 10:16 ` Bruce Richardson
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).