Skip to contentSkip to conversation

e1000e: Fix tx/rx counters

PATCH In review [email protected] 4 participants 6 messages Apr 10, 2023 – May 11, 2023

lore
Share & tools
lore
#0 lore raw

cover e1000e: Fix tx/rx counters

This commit fixes a bug in the stats registers of the e1000* devices reporting higher bandwidth usage.

I'm adding a bit of context for affected Googlers:

The e1000e is the default NIC used by libvirt for Windows VMs. This bug creates huge slowdowns on BITS transfers (used for Windows Update for example).
The task manager shows high usage of bandwidth (>2Gbps inbound), and thus the BITS client throttles the speed (<1kbps).

A temporary fix is to switch to the rtl8139 device.

Timothée Cocault (1):
  e1000e: Fix tx/rx counters

 hw/net/e1000.c         | 5 ++---
 hw/net/e1000e_core.c   | 5 ++---
 hw/net/e1000x_common.c | 5 ++---
 hw/net/igb_core.c      | 5 ++---

 4 files changed, 8 insertions(+), 12 deletions(-)
#1 lore raw

PATCH 1/1 e1000e: Fix tx/rx counters

The bytes and packets counter registers are cleared on read.

Copying the "total counter" registers to the "good counter" registers has side effects.
If the "total" register is never read by the OS, it only gets incremented. This leads to exponential growth of the "good" register.

This commit increments the counters individually to avoid this.

---
 hw/net/e1000.c         | 5 ++---
 hw/net/e1000e_core.c   | 5 ++---
 hw/net/e1000x_common.c | 5 ++---
 hw/net/igb_core.c      | 5 ++---
 4 files changed, 8 insertions(+), 12 deletions(-)
hw/net/e1000.c +2 -3
index 23d660619f..59bacb5d3b 100644
@@ -637,9 +637,8 @@ xmit_seg(E1000State *s)
 
     e1000x_inc_reg_if_not_full(s->mac_reg, TPT);
     e1000x_grow_8reg_if_not_full(s->mac_reg, TOTL, s->tx.size + 4);
-    s->mac_reg[GPTC] = s->mac_reg[TPT];
-    s->mac_reg[GOTCL] = s->mac_reg[TOTL];
-    s->mac_reg[GOTCH] = s->mac_reg[TOTH];
+    e1000x_inc_reg_if_not_full(s->mac_reg, GPTC);
+    e1000x_grow_8reg_if_not_full(s->mac_reg, GOTCL, s->tx.size + 4);
 }
 
 static void
hw/net/e1000e_core.c +2 -3
index c0c09b6965..cfa3f55e96 100644
@@ -711,9 +711,8 @@ e1000e_on_tx_done_update_stats(E1000ECore *core, struct NetTxPkt *tx_pkt)
         g_assert_not_reached();
     }
 
-    core->mac[GPTC] = core->mac[TPT];
-    core->mac[GOTCL] = core->mac[TOTL];
-    core->mac[GOTCH] = core->mac[TOTH];
+    e1000x_inc_reg_if_not_full(core->mac, GPTC);
+    e1000x_grow_8reg_if_not_full(core->mac, GOTCL, tot_len);
 }
 
 static void
hw/net/e1000x_common.c +2 -3
index b844af590a..4c8e7dcf70 100644
@@ -220,15 +220,14 @@ e1000x_update_rx_total_stats(uint32_t *mac,
 
     e1000x_increase_size_stats(mac, PRCregs, data_fcs_size);
     e1000x_inc_reg_if_not_full(mac, TPR);
-    mac[GPRC] = mac[TPR];
+    e1000x_inc_reg_if_not_full(mac, GPRC);
     /* TOR - Total Octets Received:
     * This register includes bytes received in a packet from the <Destination
     * Address> field through the <CRC> field, inclusively.
     * Always include FCS length (4) in size.
     */
     e1000x_grow_8reg_if_not_full(mac, TORL, data_size + 4);
-    mac[GORCL] = mac[TORL];
-    mac[GORCH] = mac[TORH];
+    e1000x_grow_8reg_if_not_full(mac, GORCL, data_size + 4);
 }
 
 void
hw/net/igb_core.c +2 -3
index d733fed6cf..826e7a6cf1 100644
@@ -538,9 +538,8 @@ igb_on_tx_done_update_stats(IGBCore *core, struct NetTxPkt *tx_pkt, int qn)
         g_assert_not_reached();
     }
 
-    core->mac[GPTC] = core->mac[TPT];
-    core->mac[GOTCL] = core->mac[TOTL];
-    core->mac[GOTCH] = core->mac[TOTH];
+    e1000x_inc_reg_if_not_full(core->mac, GPTC);
+    e1000x_grow_8reg_if_not_full(core->mac, GOTCL, tot_len);
 
     if (core->mac[MRQC] & 1) {
         uint16_t pool = qn % IGB_NUM_VM_POOLS;
Signature · 1 line
2.40.0
Reviewed-by on v1 1/1
#2 lore raw
Quoted 10 lines · On 2023/04/11 0:27, [email protected] wrote:

The bytes and packets counter registers are cleared on read.

Copying the "total counter" registers to the "good counter" registers has side effects.
If the "total" register is never read by the OS, it only gets incremented. This leads to exponential growth of the "good" register.

This commit increments the counters individually to avoid this.

Quoted 77 lines
---
  hw/net/e1000.c         | 5 ++---
  hw/net/e1000e_core.c   | 5 ++---
  hw/net/e1000x_common.c | 5 ++---
  hw/net/igb_core.c      | 5 ++---
  4 files changed, 8 insertions(+), 12 deletions(-)
hw/net/e1000.c +2 -3
index 23d660619f..59bacb5d3b 100644
@@ -637,9 +637,8 @@ xmit_seg(E1000State *s)
 
      e1000x_inc_reg_if_not_full(s->mac_reg, TPT);
      e1000x_grow_8reg_if_not_full(s->mac_reg, TOTL, s->tx.size + 4);
-    s->mac_reg[GPTC] = s->mac_reg[TPT];
-    s->mac_reg[GOTCL] = s->mac_reg[TOTL];
-    s->mac_reg[GOTCH] = s->mac_reg[TOTH];
+    e1000x_inc_reg_if_not_full(s->mac_reg, GPTC);
+    e1000x_grow_8reg_if_not_full(s->mac_reg, GOTCL, s->tx.size + 4);
  }
 
  static void
hw/net/e1000e_core.c +2 -3
index c0c09b6965..cfa3f55e96 100644
@@ -711,9 +711,8 @@ e1000e_on_tx_done_update_stats(E1000ECore *core, struct NetTxPkt *tx_pkt)
          g_assert_not_reached();
      }
 
-    core->mac[GPTC] = core->mac[TPT];
-    core->mac[GOTCL] = core->mac[TOTL];
-    core->mac[GOTCH] = core->mac[TOTH];
+    e1000x_inc_reg_if_not_full(core->mac, GPTC);
+    e1000x_grow_8reg_if_not_full(core->mac, GOTCL, tot_len);
  }
 
  static void
hw/net/e1000x_common.c +2 -3
index b844af590a..4c8e7dcf70 100644
@@ -220,15 +220,14 @@ e1000x_update_rx_total_stats(uint32_t *mac,
 
      e1000x_increase_size_stats(mac, PRCregs, data_fcs_size);
      e1000x_inc_reg_if_not_full(mac, TPR);
-    mac[GPRC] = mac[TPR];
+    e1000x_inc_reg_if_not_full(mac, GPRC);
      /* TOR - Total Octets Received:
      * This register includes bytes received in a packet from the <Destination
      * Address> field through the <CRC> field, inclusively.
      * Always include FCS length (4) in size.
      */
      e1000x_grow_8reg_if_not_full(mac, TORL, data_size + 4);
-    mac[GORCL] = mac[TORL];
-    mac[GORCH] = mac[TORH];
+    e1000x_grow_8reg_if_not_full(mac, GORCL, data_size + 4);
  }
 
  void
hw/net/igb_core.c +2 -3
index d733fed6cf..826e7a6cf1 100644
@@ -538,9 +538,8 @@ igb_on_tx_done_update_stats(IGBCore *core, struct NetTxPkt *tx_pkt, int qn)
          g_assert_not_reached();
      }
 
-    core->mac[GPTC] = core->mac[TPT];
-    core->mac[GOTCL] = core->mac[TOTL];
-    core->mac[GOTCH] = core->mac[TOTH];
+    e1000x_inc_reg_if_not_full(core->mac, GPTC);
+    e1000x_grow_8reg_if_not_full(core->mac, GOTCL, tot_len);
 
      if (core->mac[MRQC] & 1) {
          uint16_t pool = qn % IGB_NUM_VM_POOLS;
#3 lore raw
Quoted 8 lines · Akihiko Odaki
Quoted 7 lines · On 2023/04/11 0:27, [email protected] wrote:

The bytes and packets counter registers are cleared on read.

Copying the "total counter" registers to the "good counter" registers has side effects.
If the "total" register is never read by the OS, it only gets incremented. This leads to exponential growth of the "good" register.

Quoted 5 lines
Quoted 3 lines

This commit increments the counters individually to avoid this.

Queued.

Thanks

Quoted 73 lines
Quoted 72 lines

---
  hw/net/e1000.c         | 5 ++---
  hw/net/e1000e_core.c   | 5 ++---
  hw/net/e1000x_common.c | 5 ++---
  hw/net/igb_core.c      | 5 ++---

  4 files changed, 8 insertions(+), 12 deletions(-)
hw/net/e1000.c +2 -3
index 23d660619f..59bacb5d3b 100644
@@ -637,9 +637,8 @@ xmit_seg(E1000State *s)
         e1000x_inc_reg_if_not_full(s->mac_reg, TPT);
       e1000x_grow_8reg_if_not_full(s->mac_reg, TOTL, s->tx.size + 4);
-    s->mac_reg[GPTC] = s->mac_reg[TPT];
-    s->mac_reg[GOTCL] = s->mac_reg[TOTL];
-    s->mac_reg[GOTCH] = s->mac_reg[TOTH];
+    e1000x_inc_reg_if_not_full(s->mac_reg, GPTC);
+    e1000x_grow_8reg_if_not_full(s->mac_reg, GOTCL, s->tx.size + 4);
   }

    static void

hw/net/e1000e_core.c +2 -2
index c0c09b6965..cfa3f55e96 100644
@@ -711,9 +711,8 @@ e1000e_on_tx_done_update_stats(E1000ECore *core, 
 struct NetTxPkt *tx_pkt)
           g_assert_not_reached();
       }
   -    core->mac[GPTC] = core->mac[TPT];
-    core->mac[GOTCL] = core->mac[TOTL];
-    core->mac[GOTCH] = core->mac[TOTH];
+    e1000x_inc_reg_if_not_full(core->mac, GPTC);
+    e1000x_grow_8reg_if_not_full(core->mac, GOTCL, tot_len);
   }

    static void

hw/net/e1000x_common.c +2 -3
index b844af590a..4c8e7dcf70 100644
@@ -220,15 +220,14 @@ e1000x_update_rx_total_stats(uint32_t *mac,
         e1000x_increase_size_stats(mac, PRCregs, data_fcs_size);
       e1000x_inc_reg_if_not_full(mac, TPR);
-    mac[GPRC] = mac[TPR];
+    e1000x_inc_reg_if_not_full(mac, GPRC);
       /* TOR - Total Octets Received:
       * This register includes bytes received in a packet from the <Destination
       * Address> field through the <CRC> field, inclusively.
       * Always include FCS length (4) in size.
       */
       e1000x_grow_8reg_if_not_full(mac, TORL, data_size + 4);
-    mac[GORCL] = mac[TORL];
-    mac[GORCH] = mac[TORH];
+    e1000x_grow_8reg_if_not_full(mac, GORCL, data_size + 4);
   }

    void

hw/net/igb_core.c +2 -2
index d733fed6cf..826e7a6cf1 100644
@@ -538,9 +538,8 @@ igb_on_tx_done_update_stats(IGBCore *core, struct 
 NetTxPkt *tx_pkt, int qn)
           g_assert_not_reached();
       }
   -    core->mac[GPTC] = core->mac[TPT];
-    core->mac[GOTCL] = core->mac[TOTL];
-    core->mac[GOTCH] = core->mac[TOTH];
+    e1000x_inc_reg_if_not_full(core->mac, GPTC);
+    e1000x_grow_8reg_if_not_full(core->mac, GOTCL, tot_len);
         if (core->mac[MRQC] & 1) {
           uint16_t pool = qn % IGB_NUM_VM_POOLS;
#4 lore raw
In reply to [email protected]
Quoted 8 lines · 10.04.2023 18:27, [email protected] wrote:

The bytes and packets counter registers are cleared on read.

Copying the "total counter" registers to the "good counter" registers has side effects.
If the "total" register is never read by the OS, it only gets incremented. This leads to exponential growth of the "good" register.

This commit increments the counters individually to avoid this.

Smells like a -stable material, is it not?

Thanks,

/mjt

#5 lore raw
Quoted 4 lines · Michael Tokarev
Quoted 2 lines · 10.04.2023 18:27, [email protected] wrote:

The bytes and packets counter registers are cleared on read.

Quoted 8 lines
Quoted 6 lines

Copying the "total counter" registers to the "good counter" registers has side effects.
If the "total" register is never read by the OS, it only gets incremented. This leads to exponential growth of the "good" register.

This commit increments the counters individually to avoid this.

Smells like a -stable material, is it not?

Yes, tagged for stable.

Thanks

Quoted 5 lines

Thanks,

/mjt