DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Richardson, Bruce" <bruce.richardson@intel.com>
To: "dev@dpdk.org" <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH] pmd_pcap: fixed incorrect mbuf allocation
Date: Tue, 26 Nov 2013 16:49:46 +0000	[thread overview]
Message-ID: <59AF69C657FD0841A61C55336867B5B01A977BA3@IRSMSX103.ger.corp.intel.com> (raw)

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 <bruce.richardson@intel.com>
---
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_eth_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] = { 0 };
        struct pcap_rx_queue *pcap_q = queue;
+       struct rte_pktmbuf_pool_private *mbp_priv;
        uint16_t num_rx = 0;
+       uint16_t buf_size;

        if (unlikely(pcap_q->pcap == NULL || nb_pkts == 0))
                return 0;

-       if(unlikely(!mbufs[0]))
-               for (i = 0; i < RTE_ETH_PCAP_MBUFS; i++)
-                       mbufs[i] = 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 = 0; i < nb_pkts; i++) {
-               mbuf = mbufs[i % RTE_ETH_PCAP_MBUFS];
+               /* Get the next PCAP packet */
                packet = pcap_next(pcap_q->pcap, &header);
                if (unlikely(packet == NULL))
                        break;
+               else
+                       mbuf = rte_pktmbuf_alloc(pcap_q->mb_pool);
                if (unlikely(mbuf == NULL))
                        break;
-               rte_memcpy(mbuf->pkt.data, packet, header.len);
-               mbuf->pkt.data_len = (uint16_t)header.len;
-               mbuf->pkt.pkt_len = mbuf->pkt.data_len;
-               bufs[i] = mbuf;
-               num_rx++;
+
+               /* Now get the space available for data in the mbuf */
+               mbp_priv = (struct rte_pktmbuf_pool_private *)
+                               ((char *)pcap_q->mb_pool + sizeof(struct rte_mempool));
+               buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
+                               RTE_PKTMBUF_HEADROOM);
+
+               if (header.len <= buf_size) {
+                       /* pcap packet will fit in the mbuf, go ahead and copy */
+                       rte_memcpy(mbuf->pkt.data, packet, header.len);
+                       mbuf->pkt.data_len = (uint16_t)header.len;
+                       mbuf->pkt.pkt_len = mbuf->pkt.data_len;
+                       bufs[i] = mbuf;
+                       num_rx++;
+               } else {
+                       /* pcap packet will not fit in the mbuf, so drop packet */
+                       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 += num_rx;
        return num_rx;
--
1.7.7.6

             reply	other threads:[~2013-11-26 16:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-26 16:49 Richardson, Bruce [this message]
2013-12-10  9:38 ` 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=59AF69C657FD0841A61C55336867B5B01A977BA3@IRSMSX103.ger.corp.intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /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).