From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp03.srv.cs.cmu.edu (SMTP03.SRV.CS.CMU.EDU [128.2.217.198]) by dpdk.org (Postfix) with ESMTP id 25DA34AAA for ; Mon, 6 May 2013 15:28:36 +0200 (CEST) Received: from mail-pb0-f44.google.com (mail-pb0-f44.google.com [209.85.160.44]) (authenticated bits=0) by smtp03.srv.cs.cmu.edu (8.13.6/8.13.6) with ESMTP id r46DSY5w017488 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=FAIL) for ; Mon, 6 May 2013 09:28:35 -0400 (EDT) Received: by mail-pb0-f44.google.com with SMTP id wz17so2001018pbc.17 for ; Mon, 06 May 2013 06:28:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=FtsTMfw6gRcvCuoz4X5PePFMPSLdDP+IDptq+FqDiDE=; b=U5fMfxrwmMft1qdtGeUQO3f9HMqgEiJxefiwYoqzBuoM+qt2i4JzxejxKQ4CCpJ9/I wklvun1sppXh+fTwfVNMhayNxUAB6OH6t7oUItv12sTEoZOkj0FeJjHa7H79kLTnZNFh DH5PLsOCSh0RlU37YEyKuAWjHHBeKK21LIMWOCKG+Os5wqE5iBbIVkE6+8fKUvEgSaDD oLBPzwm4WUgOYQ1ZsIww5z9I4TLg6dK5UVOXLeJkfUr1+9Yp0KVXHqqgqfQuP5MNlhY8 ANbnaSAZrS+cwtMdLoh4uOH1S5+QO50+qqI7eoF2U03t3tkhejk1LpYFrBcD0JdRX6hM Ld4g== MIME-Version: 1.0 X-Received: by 10.66.249.195 with SMTP id yw3mr26509187pac.12.1367846914062; Mon, 06 May 2013 06:28:34 -0700 (PDT) Received: by 10.66.148.199 with HTTP; Mon, 6 May 2013 06:28:33 -0700 (PDT) Received: by 10.66.148.199 with HTTP; Mon, 6 May 2013 06:28:33 -0700 (PDT) In-Reply-To: <1367844470-15346-1-git-send-email-thomas.monjalon@6wind.com> References: <1367844470-15346-1-git-send-email-thomas.monjalon@6wind.com> Date: Mon, 6 May 2013 09:28:33 -0400 Message-ID: From: "Han, Dongsu" To: Thomas Monjalon Content-Type: multipart/alternative; boundary=047d7b10d1a16b805204dc0cadb8 X-Scanned-By: mimedefang-cmuscs on 128.2.217.198 Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH] app: fix refcnt in mbuf allocation 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: Mon, 06 May 2013 13:28:36 -0000 --047d7b10d1a16b805204dc0cadb8 Content-Type: text/plain; charset=ISO-8859-1 Sounds good. With the two bug fixes I submitted txonly now runs perfectly. Thanks! -Dongsu On May 6, 2013 8:47 AM, "Thomas Monjalon" wrote: > Hi Dongsu Han, > > I think your fix is right. > I've just removed tx_mbuf_alloc() and directly called rte_pktmbuf_alloc() > instead. > Is it OK for you ? > Could you also review this (modified) description ? > > Thank you > > --- > > From: Dongsu Han > > test-pmd txonly leaks mbuf from the pool. > The function tx_mbuf_alloc() does not change the refcnt > and the refcnt is 0 when it is first allocated. > However, rte_pktmbuf_free_seg called by the driver's xmit code decrements > reference count to -1. So mbuf never goes back to the pool. > As a result, txonly can't send packets after it exhausts the mempool. > > The function tx_mbuf_alloc() was getting mbuf directly from mempool and so > was bypassing mbuf API. > By using the right API, refcnt is correctly handled among other > initializations. > > Signed-off-by: Dongsu Han > Signed-off-by: Thomas Monjalon > --- > app/test-pmd/txonly.c | 17 ++--------------- > 1 file changed, 2 insertions(+), 15 deletions(-) > > diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c > index d7c8c31..53f7138 100644 > --- a/app/test-pmd/txonly.c > +++ b/app/test-pmd/txonly.c > @@ -89,19 +89,6 @@ > static struct ipv4_hdr pkt_ip_hdr; /**< IP header of transmitted > packets. */ > static struct udp_hdr pkt_udp_hdr; /**< UDP header of transmitted > packets. */ > > -static inline struct rte_mbuf * > -tx_mbuf_alloc(struct rte_mempool *mp) > -{ > - struct rte_mbuf *m; > - void *mb; > - > - if (rte_mempool_get(mp, &mb) < 0) > - return NULL; > - m = (struct rte_mbuf *)mb; > - __rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 1); > - return m; > -} > - > static void > copy_buf_to_pkt_segs(void* buf, unsigned len, struct rte_mbuf *pkt, > unsigned offset) > @@ -223,7 +210,7 @@ pkt_burst_transmit(struct fwd_stream *fs) > vlan_tci = ports[fs->tx_port].tx_vlan_id; > ol_flags = ports[fs->tx_port].tx_ol_flags; > for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) { > - pkt = tx_mbuf_alloc(mbp); > + pkt = rte_pktmbuf_alloc(mbp); > if (pkt == NULL) { > nomore_mbuf: > if (nb_pkt == 0) > @@ -233,7 +220,7 @@ pkt_burst_transmit(struct fwd_stream *fs) > pkt->pkt.data_len = tx_pkt_seg_lengths[0]; > pkt_seg = pkt; > for (i = 1; i < tx_pkt_nb_segs; i++) { > - pkt_seg->pkt.next = tx_mbuf_alloc(mbp); > + pkt_seg->pkt.next = rte_pktmbuf_alloc(mbp); > if (pkt_seg->pkt.next == NULL) { > pkt->pkt.nb_segs = i; > rte_pktmbuf_free(pkt); > -- > 1.7.10.4 > > _______________________________________________ > dev mailing list > dev@dpdk.org > http://dpdk.org/ml/listinfo/dev > --047d7b10d1a16b805204dc0cadb8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Sounds good. With the two bug fixes I submitted txonly now r= uns perfectly.
Thanks!
-Dongsu

On May 6, 2013 8:47 AM, "Thomas Monjalon&qu= ot; <thomas.monjalon@6wind.= com> wrote:
Hi Dongsu Han,

I think your fix is right.
I've just removed tx_mbuf_alloc() and directly called rte_pktmbuf_alloc= () instead.
Is it OK for you ?
Could you also review this (modified) description ?

Thank you

---

From: Dongsu Han <dongsuh at cs.cmu.edu>

test-pmd txonly leaks mbuf from the pool.
The function tx_mbuf_alloc() does not change the refcnt
and the refcnt is 0 when it is first allocated.
However, rte_pktmbuf_free_seg called by the driver's xmit code decremen= ts
reference count to -1. So mbuf never goes back to the pool.
As a result, txonly can't send packets after it exhausts the mempool.
The function tx_mbuf_alloc() was getting mbuf directly from mempool and so<= br> was bypassing mbuf API.
By using the right API, refcnt is correctly handled among other
initializations.

Signed-off-by: Dongsu Han <dongsuh= @cs.cmu.edu>
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
=A0app/test-pmd/txonly.c | =A0 17 ++---------------
=A01 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index d7c8c31..53f7138 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -89,19 +89,6 @@
=A0static struct ipv4_hdr =A0pkt_ip_hdr; =A0/**< IP header of transmitte= d packets. */
=A0static struct udp_hdr pkt_udp_hdr; /**< UDP header of transmitted pac= kets. */

-static inline struct rte_mbuf *
-tx_mbuf_alloc(struct rte_mempool *mp)
-{
- =A0 =A0 =A0 struct rte_mbuf *m;
- =A0 =A0 =A0 void *mb;
-
- =A0 =A0 =A0 if (rte_mempool_get(mp, &mb) < 0)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
- =A0 =A0 =A0 m =3D (struct rte_mbuf *)mb;
- =A0 =A0 =A0 __rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 1);
- =A0 =A0 =A0 return m;
-}
-
=A0static void
=A0copy_buf_to_pkt_segs(void* buf, unsigned len, struct rte_mbuf *pkt,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unsigned offset)
@@ -223,7 +210,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
=A0 =A0 =A0 =A0 vlan_tci =3D ports[fs->tx_port].tx_vlan_id;
=A0 =A0 =A0 =A0 ol_flags =3D ports[fs->tx_port].tx_ol_flags;
=A0 =A0 =A0 =A0 for (nb_pkt =3D 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) = {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 pkt =3D tx_mbuf_alloc(mbp);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 pkt =3D rte_pktmbuf_alloc(mbp);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (pkt =3D=3D NULL) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 nomore_mbuf:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (nb_pkt =3D=3D 0)
@@ -233,7 +220,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pkt->pkt.data_len =3D tx_pkt_seg_lengths= [0];
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pkt_seg =3D pkt;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 for (i =3D 1; i < tx_pkt_nb_segs; i++) {=
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pkt_seg->pkt.next =3D tx_m= buf_alloc(mbp);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pkt_seg->pkt.next =3D rte_= pktmbuf_alloc(mbp);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (pkt_seg->pkt.next = =3D=3D NULL) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pkt->pkt= .nb_segs =3D i;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rte_pktmbuf= _free(pkt);
--
1.7.10.4

_______________________________________________
dev mailing list
dev@dpdk.org
http://dpdk.o= rg/ml/listinfo/dev
--047d7b10d1a16b805204dc0cadb8--