From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) by dpdk.org (Postfix) with ESMTP id 5FECA5AA1 for ; Thu, 26 Mar 2015 17:00:03 +0100 (CET) Received: by wgs2 with SMTP id 2so69640160wgs.1 for ; Thu, 26 Mar 2015 09:00:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VfEHE+Zwzp9cHu1AQsROasGqcNJQs+BUZw94FqTB4Wg=; b=Bs23Uwt1rMnGzc3BubJbgTuO5Z+h8IFmjSQhbtYJYNmTy87sFECd/gitf7VuXpjwB5 7ipo/3sZi6SDokGUZBf3imNgDYWlPbcx6pTuPxo0K+8spdxpwoukimuKSCrFGQpvQQ2o w5Tuio55596WtecMbESRcC0lCOR1mhowMq69izPhtdAvrvIlvcSZUjkaznPO30w02LiO 1kuZZrQRYWBENAEuKNcNqxP5bv4o5oCMTlvpeCnKXacJfhyE++LWnoRTUsBFxYcTzlpI 6yOhisTbqDV+FQWeEa+8+4Zs8fKLiGuurid8t9l78/0VR4HnjADlve8DKH1JUnk8Wn48 104g== X-Gm-Message-State: ALoCoQlZ3oQOnXeTaivWRpTfR4dqDjtKICTHcboNreLxN/X8r0mrmss7X9R7uo9pOJri8sycUb7z X-Received: by 10.180.104.33 with SMTP id gb1mr48298519wib.33.1427385603114; Thu, 26 Mar 2015 09:00:03 -0700 (PDT) Received: from glumotte.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id i3sm2797619wiy.23.2015.03.26.09.00.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Mar 2015 09:00:02 -0700 (PDT) From: Olivier Matz To: dev@dpdk.org Date: Thu, 26 Mar 2015 16:59:52 +0100 Message-Id: <1427385595-15011-3-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1427385595-15011-1-git-send-email-olivier.matz@6wind.com> References: <1427302838-8285-1-git-send-email-olivier.matz@6wind.com> <1427385595-15011-1-git-send-email-olivier.matz@6wind.com> Cc: zoltan.kiss@linaro.org Subject: [dpdk-dev] [PATCH v2 2/5] mbuf: allow to clone an indirect mbuf 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: Thu, 26 Mar 2015 16:00:03 -0000 Remove one limitation of rte_pktmbuf_attach(): "mbuf we're attaching to must be direct". Now, when we attach to an indirect mbuf: - copy the all relevant fields (addr, len, offload, ...) as before - get the pointer to the mbuf that embeds the data buffer (direct mbuf), and increase the reference counter of this one. When detaching the mbuf, we can retrieve this direct mbuf as the pointer is determined from the buffer address. Signed-off-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf.h | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 45ac948..be635f0 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -715,44 +715,50 @@ static inline struct rte_mbuf *rte_pktmbuf_alloc(struct rte_mempool *mp) * After attachment we refer the mbuf we attached as 'indirect', * while mbuf we attached to as 'direct'. * Right now, not supported: - * - attachment to indirect mbuf (e.g. - md has to be direct). * - attachment for already indirect mbuf (e.g. - mi has to be direct). * - mbuf we trying to attach (mi) is used by someone else * e.g. it's reference counter is greater then 1. * * @param mi * The indirect packet mbuf. - * @param md - * The direct packet mbuf. + * @param m + * The packet mbuf we're attaching to. */ -static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *md) +static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m) { - RTE_MBUF_ASSERT(RTE_MBUF_DIRECT(md) && - RTE_MBUF_DIRECT(mi) && + struct rte_mbuf *md; + + RTE_MBUF_ASSERT(RTE_MBUF_DIRECT(mi) && rte_mbuf_refcnt_read(mi) == 1); + /* if m is not direct, get the mbuf that embeds the data */ + if (RTE_MBUF_DIRECT(m)) + md = m; + else + md = rte_mbuf_from_indirect(m); + rte_mbuf_refcnt_update(md, 1); - mi->buf_physaddr = md->buf_physaddr; - mi->buf_addr = md->buf_addr; - mi->buf_len = md->buf_len; - - mi->next = md->next; - mi->data_off = md->data_off; - mi->data_len = md->data_len; - mi->port = md->port; - mi->vlan_tci = md->vlan_tci; - mi->tx_offload = md->tx_offload; - mi->hash = md->hash; + mi->buf_physaddr = m->buf_physaddr; + mi->buf_addr = m->buf_addr; + mi->buf_len = m->buf_len; + + mi->next = m->next; + mi->data_off = m->data_off; + mi->data_len = m->data_len; + mi->port = m->port; + mi->vlan_tci = m->vlan_tci; + mi->tx_offload = m->tx_offload; + mi->hash = m->hash; mi->next = NULL; mi->pkt_len = mi->data_len; mi->nb_segs = 1; - mi->ol_flags = md->ol_flags | IND_ATTACHED_MBUF; - mi->packet_type = md->packet_type; + mi->ol_flags = m->ol_flags | IND_ATTACHED_MBUF; + mi->packet_type = m->packet_type; __rte_mbuf_sanity_check(mi, 1); - __rte_mbuf_sanity_check(md, 0); + __rte_mbuf_sanity_check(m, 0); } /** -- 2.1.4