From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 84891DE0 for ; Tue, 26 Nov 2013 17:50:22 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 26 Nov 2013 08:50:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.93,775,1378882800"; d="scan'208,217";a="440355873" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by fmsmga002.fm.intel.com with ESMTP; 26 Nov 2013 08:50:22 -0800 Received: from irsmsx103.ger.corp.intel.com ([169.254.3.66]) by IRSMSX102.ger.corp.intel.com ([169.254.2.114]) with mapi id 14.03.0123.003; Tue, 26 Nov 2013 16:49:47 +0000 From: "Richardson, Bruce" To: "dev@dpdk.org" Thread-Topic: [PATCH] pmd_pcap: fixed incorrect mbuf allocation Thread-Index: Ac7qx14yf1wg5jsbTTGkp8Fp2ZRJ6Q== Date: Tue, 26 Nov 2013 16:49:46 +0000 Message-ID: <59AF69C657FD0841A61C55336867B5B01A977BA3@IRSMSX103.ger.corp.intel.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [dpdk-dev] [PATCH] pmd_pcap: fixed incorrect 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: Tue, 26 Nov 2013 16:50:23 -0000 The mbufs returned by the pcap pmd RX function were constantly reused, instead of being allocated on demand. This has been fixed. Signed-off-by: Bruce Richardson --- lib/librte_pmd_pcap/rte_eth_pcap.c | 37 +++++++++++++++++++++++++--------= -- 1 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_e= th_pcap.c index 19d19b3..8a98471 100644 --- a/lib/librte_pmd_pcap/rte_eth_pcap.c +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c @@ -118,32 +118,47 @@ eth_pcap_rx(void *queue, struct pcap_pkthdr header; const u_char *packet; struct rte_mbuf *mbuf; - static struct rte_mbuf *mbufs[RTE_ETH_PCAP_MBUFS] =3D { 0 }; struct pcap_rx_queue *pcap_q =3D queue; + struct rte_pktmbuf_pool_private *mbp_priv; uint16_t num_rx =3D 0; + uint16_t buf_size; if (unlikely(pcap_q->pcap =3D=3D NULL || nb_pkts =3D=3D 0)) return 0; - if(unlikely(!mbufs[0])) - for (i =3D 0; i < RTE_ETH_PCAP_MBUFS; i++) - mbufs[i] =3D rte_pktmbuf_alloc(pcap_q->mb_pool); - /* Reads the given number of packets from the pcap file one by one * and copies the packet data into a newly allocated mbuf to return= . */ for (i =3D 0; i < nb_pkts; i++) { - mbuf =3D mbufs[i % RTE_ETH_PCAP_MBUFS]; + /* Get the next PCAP packet */ packet =3D pcap_next(pcap_q->pcap, &header); if (unlikely(packet =3D=3D NULL)) break; + else + mbuf =3D rte_pktmbuf_alloc(pcap_q->mb_pool); if (unlikely(mbuf =3D=3D NULL)) break; - rte_memcpy(mbuf->pkt.data, packet, header.len); - mbuf->pkt.data_len =3D (uint16_t)header.len; - mbuf->pkt.pkt_len =3D mbuf->pkt.data_len; - bufs[i] =3D mbuf; - num_rx++; + + /* Now get the space available for data in the mbuf */ + mbp_priv =3D (struct rte_pktmbuf_pool_private *) + ((char *)pcap_q->mb_pool + sizeof(struct rt= e_mempool)); + buf_size =3D (uint16_t) (mbp_priv->mbuf_data_room_size - + RTE_PKTMBUF_HEADROOM); + + if (header.len <=3D buf_size) { + /* pcap packet will fit in the mbuf, go ahead and c= opy */ + rte_memcpy(mbuf->pkt.data, packet, header.len); + mbuf->pkt.data_len =3D (uint16_t)header.len; + mbuf->pkt.pkt_len =3D mbuf->pkt.data_len; + bufs[i] =3D mbuf; + num_rx++; + } else { + /* pcap packet will not fit in the mbuf, so drop pa= cket */ + RTE_LOG(ERR, PMD, + "PCAP packet %d bytes will not fit = in mbuf (%d bytes)\n", + header.len, buf_size); + rte_pktmbuf_free(mbuf); + } } pcap_q->rx_pkts +=3D num_rx; return num_rx; -- 1.7.7.6