i40e/i40evf: Moves skb from i40e_rx_buffer to i40e_ring
authorScott Peterson <scott.d.peterson@intel.com>
Fri, 10 Feb 2017 07:40:25 +0000 (23:40 -0800)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Sun, 12 Feb 2017 04:39:01 +0000 (20:39 -0800)
This patch reduces the size of struct i40e_rx_buffer by one pointer,
and makes the i40e driver a little more consistent with the igb driver
in terms of packets that span buffers.

We do this by moving the skb field from struct i40e_rx_buffer to
struct i40e_ring. We pass the skb we already have (or NULL if we
don't) to i40e_fetch_rx_buffer(), which skips the skb allocation if we
already have one for this packet.

Change-ID: I4ad48a531844494ba0c5d8e1a62209a057f661b0
Signed-off-by: Scott Peterson <scott.d.peterson@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/i40e/i40e_txrx.c
drivers/net/ethernet/intel/i40e/i40e_txrx.h
drivers/net/ethernet/intel/i40evf/i40e_txrx.c
drivers/net/ethernet/intel/i40evf/i40e_txrx.h

index 4852445122d97b871646955ff8d12cf43dac8ef0..aa9755b55d48127b1ecd0b5ca430eaba48b01c9e 100644 (file)
@@ -1013,14 +1013,15 @@ void i40e_clean_rx_ring(struct i40e_ring *rx_ring)
        if (!rx_ring->rx_bi)
                return;
 
+       if (rx_ring->skb) {
+               dev_kfree_skb(rx_ring->skb);
+               rx_ring->skb = NULL;
+       }
+
        /* Free all the Rx ring sk_buffs */
        for (i = 0; i < rx_ring->count; i++) {
                struct i40e_rx_buffer *rx_bi = &rx_ring->rx_bi[i];
 
-               if (rx_bi->skb) {
-                       dev_kfree_skb(rx_bi->skb);
-                       rx_bi->skb = NULL;
-               }
                if (!rx_bi->page)
                        continue;
 
@@ -1608,7 +1609,8 @@ static bool i40e_add_rx_frag(struct i40e_ring *rx_ring,
  */
 static inline
 struct sk_buff *i40e_fetch_rx_buffer(struct i40e_ring *rx_ring,
-                                    union i40e_rx_desc *rx_desc)
+                                    union i40e_rx_desc *rx_desc,
+                                    struct sk_buff *skb)
 {
        u64 local_status_error_len =
                le64_to_cpu(rx_desc->wb.qword1.status_error_len);
@@ -1616,15 +1618,12 @@ struct sk_buff *i40e_fetch_rx_buffer(struct i40e_ring *rx_ring,
                (local_status_error_len & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
                I40E_RXD_QW1_LENGTH_PBUF_SHIFT;
        struct i40e_rx_buffer *rx_buffer;
-       struct sk_buff *skb;
        struct page *page;
 
        rx_buffer = &rx_ring->rx_bi[rx_ring->next_to_clean];
        page = rx_buffer->page;
        prefetchw(page);
 
-       skb = rx_buffer->skb;
-
        if (likely(!skb)) {
                void *page_addr = page_address(page) + rx_buffer->page_offset;
 
@@ -1648,8 +1647,6 @@ struct sk_buff *i40e_fetch_rx_buffer(struct i40e_ring *rx_ring,
                 * it now to avoid a possible cache miss
                 */
                prefetchw(skb->data);
-       } else {
-               rx_buffer->skb = NULL;
        }
 
        /* we are reusing so sync this buffer for CPU use */
@@ -1702,7 +1699,6 @@ static bool i40e_is_non_eop(struct i40e_ring *rx_ring,
 #define staterrlen rx_desc->wb.qword1.status_error_len
        if (unlikely(i40e_rx_is_programming_status(le64_to_cpu(staterrlen)))) {
                i40e_clean_programming_status(rx_ring, rx_desc);
-               rx_ring->rx_bi[ntc].skb = skb;
                return true;
        }
        /* if we are the last buffer then there is nothing else to do */
@@ -1710,8 +1706,6 @@ static bool i40e_is_non_eop(struct i40e_ring *rx_ring,
        if (likely(i40e_test_staterr(rx_desc, I40E_RXD_EOF)))
                return false;
 
-       /* place skb in next buffer to be received */
-       rx_ring->rx_bi[ntc].skb = skb;
        rx_ring->rx_stats.non_eop_descs++;
 
        return true;
@@ -1732,12 +1726,12 @@ static bool i40e_is_non_eop(struct i40e_ring *rx_ring,
 static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget)
 {
        unsigned int total_rx_bytes = 0, total_rx_packets = 0;
+       struct sk_buff *skb = rx_ring->skb;
        u16 cleaned_count = I40E_DESC_UNUSED(rx_ring);
        bool failure = false;
 
        while (likely(total_rx_packets < budget)) {
                union i40e_rx_desc *rx_desc;
-               struct sk_buff *skb;
                u16 vlan_tag;
                u8 rx_ptype;
                u64 qword;
@@ -1766,7 +1760,7 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget)
                 */
                dma_rmb();
 
-               skb = i40e_fetch_rx_buffer(rx_ring, rx_desc);
+               skb = i40e_fetch_rx_buffer(rx_ring, rx_desc, skb);
                if (!skb)
                        break;
 
@@ -1785,8 +1779,10 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget)
                        continue;
                }
 
-               if (i40e_cleanup_headers(rx_ring, skb))
+               if (i40e_cleanup_headers(rx_ring, skb)) {
+                       skb = NULL;
                        continue;
+               }
 
                /* probably a little skewed due to removing CRC */
                total_rx_bytes += skb->len;
@@ -1811,11 +1807,14 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget)
                           le16_to_cpu(rx_desc->wb.qword0.lo_dword.l2tag1) : 0;
 
                i40e_receive_skb(rx_ring, skb, vlan_tag);
+               skb = NULL;
 
                /* update budget accounting */
                total_rx_packets++;
        }
 
+       rx_ring->skb = skb;
+
        u64_stats_update_begin(&rx_ring->syncp);
        rx_ring->stats.packets += total_rx_packets;
        rx_ring->stats.bytes += total_rx_bytes;
index 1ea820e9debe5abfb439cbbe06c0f34a9b86e9a9..f80979025c0131a07e7b956826f17877b8b7081a 100644 (file)
@@ -253,7 +253,6 @@ struct i40e_tx_buffer {
 };
 
 struct i40e_rx_buffer {
-       struct sk_buff *skb;
        dma_addr_t dma;
        struct page *page;
        unsigned int page_offset;
@@ -354,6 +353,14 @@ struct i40e_ring {
 
        struct rcu_head rcu;            /* to avoid race on free */
        u16 next_to_alloc;
+       struct sk_buff *skb;            /* When i40e_clean_rx_ring_irq() must
+                                        * return before it sees the EOP for
+                                        * the current packet, we save that skb
+                                        * here and resume receiving this
+                                        * packet the next time
+                                        * i40e_clean_rx_ring_irq() is called
+                                        * for this ring.
+                                        */
 } ____cacheline_internodealigned_in_smp;
 
 enum i40e_latency_range {
index 4264d9133366def053138eaf1edb0a7aa92ddf11..7e9c425fc14934b96ea821f5db9fff21dc9ff7cf 100644 (file)
@@ -501,14 +501,15 @@ void i40evf_clean_rx_ring(struct i40e_ring *rx_ring)
        if (!rx_ring->rx_bi)
                return;
 
+       if (rx_ring->skb) {
+               dev_kfree_skb(rx_ring->skb);
+               rx_ring->skb = NULL;
+       }
+
        /* Free all the Rx ring sk_buffs */
        for (i = 0; i < rx_ring->count; i++) {
                struct i40e_rx_buffer *rx_bi = &rx_ring->rx_bi[i];
 
-               if (rx_bi->skb) {
-                       dev_kfree_skb(rx_bi->skb);
-                       rx_bi->skb = NULL;
-               }
                if (!rx_bi->page)
                        continue;
 
@@ -1086,7 +1087,8 @@ static bool i40e_add_rx_frag(struct i40e_ring *rx_ring,
  */
 static inline
 struct sk_buff *i40evf_fetch_rx_buffer(struct i40e_ring *rx_ring,
-                                      union i40e_rx_desc *rx_desc)
+                                      union i40e_rx_desc *rx_desc,
+                                      struct sk_buff *skb)
 {
        u64 local_status_error_len =
                le64_to_cpu(rx_desc->wb.qword1.status_error_len);
@@ -1094,15 +1096,12 @@ struct sk_buff *i40evf_fetch_rx_buffer(struct i40e_ring *rx_ring,
                (local_status_error_len & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
                I40E_RXD_QW1_LENGTH_PBUF_SHIFT;
        struct i40e_rx_buffer *rx_buffer;
-       struct sk_buff *skb;
        struct page *page;
 
        rx_buffer = &rx_ring->rx_bi[rx_ring->next_to_clean];
        page = rx_buffer->page;
        prefetchw(page);
 
-       skb = rx_buffer->skb;
-
        if (likely(!skb)) {
                void *page_addr = page_address(page) + rx_buffer->page_offset;
 
@@ -1126,8 +1125,6 @@ struct sk_buff *i40evf_fetch_rx_buffer(struct i40e_ring *rx_ring,
                 * it now to avoid a possible cache miss
                 */
                prefetchw(skb->data);
-       } else {
-               rx_buffer->skb = NULL;
        }
 
        /* we are reusing so sync this buffer for CPU use */
@@ -1182,8 +1179,6 @@ static bool i40e_is_non_eop(struct i40e_ring *rx_ring,
        if (likely(i40e_test_staterr(rx_desc, I40E_RXD_EOF)))
                return false;
 
-       /* place skb in next buffer to be received */
-       rx_ring->rx_bi[ntc].skb = skb;
        rx_ring->rx_stats.non_eop_descs++;
 
        return true;
@@ -1204,12 +1199,12 @@ static bool i40e_is_non_eop(struct i40e_ring *rx_ring,
 static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget)
 {
        unsigned int total_rx_bytes = 0, total_rx_packets = 0;
+       struct sk_buff *skb = rx_ring->skb;
        u16 cleaned_count = I40E_DESC_UNUSED(rx_ring);
        bool failure = false;
 
        while (likely(total_rx_packets < budget)) {
                union i40e_rx_desc *rx_desc;
-               struct sk_buff *skb;
                u16 vlan_tag;
                u8 rx_ptype;
                u64 qword;
@@ -1238,7 +1233,7 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget)
                 */
                dma_rmb();
 
-               skb = i40evf_fetch_rx_buffer(rx_ring, rx_desc);
+               skb = i40evf_fetch_rx_buffer(rx_ring, rx_desc, skb);
                if (!skb)
                        break;
 
@@ -1257,8 +1252,10 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget)
                        continue;
                }
 
-               if (i40e_cleanup_headers(rx_ring, skb))
+               if (i40e_cleanup_headers(rx_ring, skb)) {
+                       skb = NULL;
                        continue;
+               }
 
                /* probably a little skewed due to removing CRC */
                total_rx_bytes += skb->len;
@@ -1275,11 +1272,14 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget)
                           le16_to_cpu(rx_desc->wb.qword0.lo_dword.l2tag1) : 0;
 
                i40e_receive_skb(rx_ring, skb, vlan_tag);
+               skb = NULL;
 
                /* update budget accounting */
                total_rx_packets++;
        }
 
+       rx_ring->skb = skb;
+
        u64_stats_update_begin(&rx_ring->syncp);
        rx_ring->stats.packets += total_rx_packets;
        rx_ring->stats.bytes += total_rx_bytes;
index a5fc789f78eba64c26a2ec322a94914ad339d41a..8274ba68bd32a6583538f7af6fd80417dc25e6ec 100644 (file)
@@ -239,7 +239,6 @@ struct i40e_tx_buffer {
 };
 
 struct i40e_rx_buffer {
-       struct sk_buff *skb;
        dma_addr_t dma;
        struct page *page;
        unsigned int page_offset;
@@ -340,6 +339,14 @@ struct i40e_ring {
 
        struct rcu_head rcu;            /* to avoid race on free */
        u16 next_to_alloc;
+       struct sk_buff *skb;            /* When i40evf_clean_rx_ring_irq() must
+                                        * return before it sees the EOP for
+                                        * the current packet, we save that skb
+                                        * here and resume receiving this
+                                        * packet the next time
+                                        * i40evf_clean_rx_ring_irq() is called
+                                        * for this ring.
+                                        */
 } ____cacheline_internodealigned_in_smp;
 
 enum i40e_latency_range {