Skip to contentSkip to conversation

igb: Implement Transmit Rate Limiting (TRL)

PATCH Superseded Josh Hilke 3 participants 16 messages Jun 22 – Jun 23

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Josh Hilke

author
#0 lore raw

v7 cover igb: Implement Transmit Rate Limiting (TRL)

This is v7 of a patch series implementing the Transmit Rate Limiter (TRL) feature for the Intel 82576 (igb) network device emulation in QEMU.

v6: https://lists.gnu.org/archive/html/qemu-devel/2026-06/msg04562.html

Changelog:

v7:
- Inline igb_trl_disable() since it's only needed in one location,

    igb_core_set_link_status().

- Fix indentation in QTest.
- Don't set PCI_MSIX_ENTRY_CTRL_MASKBIT when clearing pending interrupts in Qtest.
- Fold calculations igb_trl_calculate_delay() to simplify logic.

---
Josh Hilke (7):
igb: Define TRL registers and core state
igb: Add VMState support for TRL state
igb: Implement TRL register write and configuration
igb: Refactor TX path to return processed byte count
igb: Implement TRL throttling and timer resumption
igb: Add QTest for Transmit Rate Limiter register multiplexing
igb: Add QTest for Transmit Rate Limiter traffic throttling

 hw/net/igb.c           |  43 +++++++++++
 hw/net/igb_common.h    |   1 +
 hw/net/igb_core.c      | 142 ++++++++++++++++++++++++++++++++--
 hw/net/igb_core.h      |  12 +++
 hw/net/igb_regs.h      |   5 ++
 tests/qtest/igb-test.c | 206 +++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 404 insertions(+), 5 deletions(-)

---
base-commit: 98b060da3a4f92b2a994ead5b16a87e783baf77c
change-id: 20260608-igb-trl-19be198da6f2

Best regards,

Signature · 1 line
Josh Hilke <[email protected]>
author
#1 lore raw

PATCH v7 1/7 igb: Define TRL registers and core state

Introduce register offsets and bitmask constants for the Transmit Rate Limiter (TRL). Add the IGBTrlQueue structure and corresponding fields to IGBCore to track TRL state (timers, throttling status, and target rates) per queue. Initialize and free these timers during the device realize/uninit lifecycle, and reset them on device reset.

---
 hw/net/igb_common.h |  1 +
 hw/net/igb_core.c   | 41 +++++++++++++++++++++++++++++++++++++++++
 hw/net/igb_core.h   | 12 ++++++++++++
 hw/net/igb_regs.h   |  5 +++++
 4 files changed, 59 insertions(+)
hw/net/igb_common.h +1 -0
index b316a5b..8c0a0cf 100644
@@ -148,6 +148,7 @@ enum {
     defreg(MTA_A),
 
     defreg(VTIVAR), defreg(VTIVAR_MISC),
+    defreg(TRLDQSEL), defreg(TRLRC),
 };
 
 uint64_t igb_mmio_read(void *opaque, hwaddr addr, unsigned size);
hw/net/igb_core.c +41 -0

71 lines not on this page · raw message

hw/net/igb_core.h +12 -0
index d70b54e..922d8cd 100644
@@ -63,6 +63,13 @@ typedef struct IGBIntrDelayTimer_st {
     IGBCore *core;
 } IGBIntrDelayTimer;
 
+typedef struct IGBTrlQueue_st {
+    QEMUTimer *timer;
+    IGBCore *core;
+    uint32_t qidx;
+    uint32_t trlrc;
+} IGBTrlQueue;
+
 struct IGBCore {
     uint32_t mac[E1000E_MAC_SIZE];
     uint16_t phy[MAX_PHY_REG_ADDRESS + 1];
@@ -99,6 +106,9 @@ struct IGBCore {
     void (*owner_start_recv)(PCIDevice *d);
 
     int64_t timadj;
+
+    /* Transmit Rate Limiting */
+    IGBTrlQueue trl[IGB_NUM_QUEUES];
 };
 
 void
@@ -143,4 +153,6 @@ igb_receive_iov(IGBCore *core, const struct iovec *iov, int iovcnt);
 void
 igb_start_recv(IGBCore *core);
 
+bool igb_trl_enabled(const IGBTrlQueue *q);
+
 #endif
hw/net/igb_regs.h +5 -0
index 4dc4c31..4c31e4b 100644
@@ -718,4 +718,9 @@ static inline uint8_t igb_ivar_entry_tx(uint8_t i)
     return i < 8 ? i * 4 + 1 : (i - 8) * 4 + 3;
 }
 
+/* Transmit Rate Limiting */
+#define E1000_TRLDQSEL 0x03604
+#define E1000_TRLRC 0x036B0
+#define E1000_TRLRC_RS_ENA BIT(31)
+
 #endif
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
Reviewed-by on v7 1/7
#2 lore raw

Re: [PATCH v7 1/7] igb: Define TRL registers and core state

Quoted 20 lines · Josh Hilke

Introduce register offsets and bitmask constants for the Transmit Rate Limiter (TRL). Add the IGBTrlQueue structure and corresponding fields to IGBCore to track TRL state (timers, throttling status, and target rates) per queue. Initialize and free these timers during the device realize/uninit lifecycle, and reset them on device reset.

---
  hw/net/igb_common.h |  1 +
  hw/net/igb_core.c   | 41 +++++++++++++++++++++++++++++++++++++++++
  hw/net/igb_core.h   | 12 ++++++++++++
  hw/net/igb_regs.h   |  5 +++++
  4 files changed, 59 insertions(+)
hw/net/igb_regs.h +0 -0
index 4dc4c31..4c31e4b 100644

hw/net/igb_regs.h static inline uint8_t igb_ivar_entry_tx(uint8_t i) · line 724

Quoted 7 lines
hw/net/igb_regs.h +4 -0
@@ -718,4 +718,9 @@ static inline uint8_t igb_ivar_entry_tx(uint8_t i)
      return i < 8 ? i * 4 + 1 : (i - 8) * 4 + 3;
  }
 
+/* Transmit Rate Limiting */
+#define E1000_TRLDQSEL 0x03604
+#define E1000_TRLRC 0x036B0
+#define E1000_TRLRC_RS_ENA BIT(31)

I haven't checked the datasheet for these values, but for the rest of modelling:

author
#3 lore raw

PATCH v7 2/7 igb: Add VMState support for TRL state

In reply to Josh Hilke

Add VMState representation for the Transmit Rate Limiter (TRL) state to support migration. This includes the TRL timers and target rates per queue.

---
 hw/net/igb.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
hw/net/igb.c +43 -0
index c076807..773da26 100644
@@ -563,6 +563,45 @@ static const VMStateDescription igb_vmstate_intr_timer = {
     VMSTATE_STRUCT_ARRAY(_f, _s, _num, 0,                           \
                          igb_vmstate_intr_timer, IGBIntrDelayTimer)
 
+static bool igb_trl_needed(void *opaque)
+{
+    IGBState *s = opaque;
+
+    for (int i = 0; i < IGB_NUM_QUEUES; i++) {
+        if (s->core.trl[i].trlrc) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
+static const VMStateDescription igb_vmstate_trl_queue = {
+    .name = "igb-trl-queue",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (const VMStateField[]) {
+        VMSTATE_TIMER_PTR(timer, IGBTrlQueue),
+        VMSTATE_UINT32(trlrc, IGBTrlQueue),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+#define VMSTATE_IGB_TRL_QUEUE_ARRAY(_f, _s, _num)                    \
+    VMSTATE_STRUCT_ARRAY(_f, _s, _num, 0,                            \
+                         igb_vmstate_trl_queue, IGBTrlQueue)
+
+static const VMStateDescription igb_vmstate_trl_state = {
+    .name = "igb/trl_state",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = igb_trl_needed,
+    .fields = (const VMStateField[]) {
+        VMSTATE_IGB_TRL_QUEUE_ARRAY(core.trl, IGBState, IGB_NUM_QUEUES),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static const VMStateDescription igb_vmstate = {
     .name = "igb",
     .version_id = 1,
@@ -591,6 +630,10 @@ static const VMStateDescription igb_vmstate = {
         VMSTATE_INT64(core.timadj, IGBState),
 
         VMSTATE_END_OF_LIST()
+    },
+    .subsections = (const VMStateDescription * const []) {
+        &igb_vmstate_trl_state,
+        NULL
     }
 };
 
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
Reviewed-by on v7 2/7
#4 lore raw

Re: [PATCH v7 2/7] igb: Add VMState support for TRL state

Quoted 8 lines · Josh Hilke

Add VMState representation for the Transmit Rate Limiter (TRL) state to support migration. This includes the TRL timers and target rates per queue.

---
  hw/net/igb.c | 43 +++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 43 insertions(+)
author
#5 lore raw

PATCH v7 3/7 igb: Implement TRL register write and configuration

In reply to Josh Hilke

Implement write handlers for TLDQSEL and TRLRC registers to allow the guest to configure Transmit Rate Limiting. Translate the register Rate Factor into a physical target rate (bytes/sec) per queue. Disable TRL and clear timers when the link status changes or when TRL is disabled by the guest.

---
 hw/net/igb_core.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
hw/net/igb_core.c +28 -1
index 44e8e58..ca427d7 100644
@@ -2150,6 +2150,11 @@ void igb_core_set_link_status(IGBCore *core)
     NetClientState *nc = qemu_get_queue(core->owner_nic);
     uint32_t old_status = core->mac[STATUS];
 
+    /* Disable TRL for all queues (section 4.5.12.1) */
+    for (int i = 0; i < IGB_NUM_QUEUES; i++) {
+        core->trl[i].trlrc &= ~E1000_TRLRC_RS_ENA;
+    }
+
     trace_e1000e_link_status_changed(nc->link_down ? false : true);
 
     if (nc->link_down) {
@@ -2632,6 +2637,25 @@ static void igb_set_vtivar(IGBCore *core, int index, uint32_t val)
      */
 }
 
+static uint32_t igb_get_trlrc(IGBCore *core, int index)
+{
+    const uint32_t qidx = core->mac[TRLDQSEL];
+
+    return core->trl[qidx].trlrc;
+}
+
+static void igb_set_trldqsel(IGBCore *core, int index, uint32_t val)
+{
+    core->mac[index] = extract32(val, 0, 4);
+}
+
+static void igb_set_trlrc(IGBCore *core, int index, uint32_t val)
+{
+    const uint32_t qidx = core->mac[TRLDQSEL];
+
+    core->trl[qidx].trlrc = val;
+}
+
 static inline void
 igb_autoneg_timer(void *opaque)
 {
@@ -3687,6 +3711,7 @@ static const readops igb_macreg_readops[] = {
     [RQDPC15] = igb_mac_read_clr4,
     [VTIVAR ... VTIVAR + 7] = igb_mac_readreg,
     [VTIVAR_MISC ... VTIVAR_MISC + 7] = igb_mac_readreg,
+    [TRLRC] = igb_get_trlrc,
 };
 enum { IGB_NREADOPS = ARRAY_SIZE(igb_macreg_readops) };
 
@@ -4135,7 +4160,9 @@ static const writeops igb_macreg_writeops[] = {
     [PVTEICR6] = igb_set_vteicr,
     [PVTEICR7] = igb_set_vteicr,
     [VTIVAR ... VTIVAR + 7] = igb_set_vtivar,
-    [VTIVAR_MISC ... VTIVAR_MISC + 7] = igb_mac_writereg
+    [VTIVAR_MISC ... VTIVAR_MISC + 7] = igb_mac_writereg,
+    [TRLDQSEL] = igb_set_trldqsel,
+    [TRLRC]    = igb_set_trlrc,
 };
 enum { IGB_NWRITEOPS = ARRAY_SIZE(igb_macreg_writeops) };
 
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
author
#6 lore raw

PATCH v7 4/7 igb: Refactor TX path to return processed byte count

In reply to Josh Hilke

Modify igb_process_tx_desc to return the total size of the transmitted packet (in bytes) when processing the End of Packet (EOP) descriptor, and 0 otherwise. This allows the transmission loop to track how many bytes are being sent for rate-limiting calculations.

---
 hw/net/igb_core.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
hw/net/igb_core.c +7 -3
index ca427d7..9a8ef15 100644
@@ -599,7 +599,7 @@ igb_on_tx_done_update_stats(IGBCore *core, struct NetTxPkt *tx_pkt, int qn)
     }
 }
 
-static void
+static size_t
 igb_process_tx_desc(IGBCore *core,
                     PCIDevice *dev,
                     struct igb_tx *tx,
@@ -632,10 +632,10 @@ igb_process_tx_desc(IGBCore *core,
             tx->ctx[idx].seqnum_seed = le32_to_cpu(tx_ctx_desc->seqnum_seed);
             tx->ctx[idx].type_tucmd_mlhl = le32_to_cpu(tx_ctx_desc->type_tucmd_mlhl);
             tx->ctx[idx].mss_l4len_idx = le32_to_cpu(tx_ctx_desc->mss_l4len_idx);
-            return;
+            return 0;
         } else {
             /* unknown descriptor type */
-            return;
+            return 0;
         }
     } else {
         /* legacy descriptor */
@@ -654,11 +654,13 @@ igb_process_tx_desc(IGBCore *core,
     }
 
     if (cmd_type_len & E1000_TXD_CMD_EOP) {
+        size_t total_len = 0;
         if (!tx->skip_cp && net_tx_pkt_parse(tx->tx_pkt)) {
             idx = (tx->first_olinfo_status >> 4) & 1;
             igb_tx_insert_vlan(core, queue_index, tx,
                 tx->ctx[idx].vlan_macip_lens >> IGB_TX_FLAGS_VLAN_SHIFT,
                 !!(tx->first_cmd_type_len & E1000_TXD_CMD_VLE));
+            total_len = net_tx_pkt_get_total_len(tx->tx_pkt);
 
             if ((tx->first_cmd_type_len & E1000_ADVTXD_MAC_TSTAMP) &&
                 (core->mac[TSYNCTXCTL] & E1000_TSYNCTXCTL_ENABLED) &&
@@ -675,7 +677,9 @@ igb_process_tx_desc(IGBCore *core,
         tx->first = true;
         tx->skip_cp = false;
         net_tx_pkt_reset(tx->tx_pkt, net_tx_pkt_unmap_frag_pci, dev);
+        return total_len;
     }
+    return 0;
 }
 
 static uint32_t igb_tx_wb_eic(IGBCore *core, int queue_idx)
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
Reviewed-by on v7 4/7
#7 lore raw

Re: [PATCH v7 4/7] igb: Refactor TX path to return processed byte count

Quoted 9 lines · Josh Hilke

Modify igb_process_tx_desc to return the total size of the transmitted packet (in bytes) when processing the End of Packet (EOP) descriptor, and 0 otherwise. This allows the transmission loop to track how many bytes are being sent for rate-limiting calculations.

---
  hw/net/igb_core.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
author
#8 lore raw

PATCH v7 5/7 igb: Implement TRL throttling and timer resumption

In reply to Josh Hilke

Integrate throttling logic into the transmission path. In igb_start_xmit, check if the queue is currently throttled. Accumulate bytes sent, calculate the transmission delay based on the configured target rate, and if a throttle is triggered, set the virtual timer, mark the queue as throttled, and defer remaining packets. Implement the timer callback to clear the throttled state and resume transmission when the timer expires.

---
 hw/net/igb_core.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 63 insertions(+), 3 deletions(-)
hw/net/igb_core.c +63 -3
index 9a8ef15..e158837 100644
@@ -97,6 +97,7 @@ igb_receive_internal(IGBCore *core, const struct iovec *iov, int iovcnt,
 static void igb_raise_interrupts(IGBCore *core, size_t index, uint32_t causes);
 static void igb_reset(IGBCore *core, bool sw);
 
+
 static inline void
 igb_raise_legacy_irq(IGBCore *core)
 {
@@ -875,6 +876,48 @@ igb_tx_enabled(IGBCore *core, const E1000ERingInfo *txi)
         (core->mac[TXDCTL0 + (qn * 16)] & E1000_TXDCTL_QUEUE_ENABLE);
 }
 
+static uint64_t igb_trl_calculate_delay(const IGBTrlQueue *q, size_t bytes_sent)
+{
+    uint32_t divisor;
+    uint32_t rf;
+
+    if (!igb_trl_enabled(q)) {
+        return 0;
+    }
+
+    /*
+     * 7.8 Transmit Rate Limiting (TRL)
+     *
+     * > RF = 1Gb/s / Target-Rate (Rate Factor) is the ratio between the
+     * > nominal link rate and the target maximum rate to achieve for
+     * > that rate controlled queue. It is a decimal number ranging from
+     * > 1 to 1,000 (1 Mb/s minimum target rate) at least 10-bits before
+     * > the hexadecimal point and 14-bits after, as required for the
+     * > maximum PL by which it is multiplied.
+     *
+     * The TRLRC register stores the RF in 10.14 fixed-point format:
+     * - Bits 13:0: Fractional part
+     * - Bits 23:14: Integer part
+     *
+     * Combined, the lower 24 bits of the register (23:0) represent the
+     * RF directly.
+     */
+    rf = MAX(extract32(q->trlrc, 0, 24), 1 << 14);
+
+    /*
+     * Delay = PL (Packet Length) / Target-Rate
+     *       = PL / (1Gb/s / RF)
+     *       = PL * RF / 1Gb/s
+     *       = PL * RF / (1G / b/B / ns/s) B/ns
+     *       = (bytes_sent * (RF_scaled / 2^14) / (1G / b/B / ns/s)) ns
+     *       = (bytes_sent * RF_scaled / (1G / b/B * 2^14 / ns/s)) ns
+     */
+    divisor = ((1000000000ULL / BITS_PER_BYTE) << 14) /
+              NANOSECONDS_PER_SECOND;
+
+    return (uint64_t)bytes_sent * rf / divisor;
+}
+
 static void
 igb_start_xmit(IGBCore *core, const IGB_TxRing *txr)
 {
@@ -883,12 +926,19 @@ igb_start_xmit(IGBCore *core, const IGB_TxRing *txr)
     union e1000_adv_tx_desc desc;
     const E1000ERingInfo *txi = txr->i;
     uint32_t eic = 0;
+    size_t bytes_sent = 0;
+    uint64_t delay_ns;
 
     if (!igb_tx_enabled(core, txi)) {
         trace_e1000e_tx_disabled();
         return;
     }
 
+    if (igb_trl_enabled(&core->trl[txi->idx]) &&
+        timer_pending(core->trl[txi->idx].timer)) {
+        return;
+    }
+
     d = pcie_sriov_get_vf_at_index(core->owner, txi->idx % 8);
     if (!d) {
         d = core->owner;
@@ -902,9 +952,16 @@ igb_start_xmit(IGBCore *core, const IGB_TxRing *txr)
         trace_e1000e_tx_descr((void *)(intptr_t)desc.read.buffer_addr,
                               desc.read.cmd_type_len, desc.wb.status);
 
-        igb_process_tx_desc(core, d, txr->tx, &desc, txi->idx);
+        bytes_sent += igb_process_tx_desc(core, d, txr->tx, &desc, txi->idx);
         igb_ring_advance(core, txi, 1);
         eic |= igb_txdesc_writeback(core, base, &desc, txi);
+
+        delay_ns = igb_trl_calculate_delay(&core->trl[txi->idx], bytes_sent);
+        if (delay_ns > 0) {
+            timer_mod(core->trl[txi->idx].timer,
+                      qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + delay_ns);
+            break;
+        }
     }
 
     if (eic) {
@@ -4321,7 +4378,6 @@ igb_autoneg_resume(IGBCore *core)
                   qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500);
     }
 }
-
 bool igb_trl_enabled(const IGBTrlQueue *q)
 {
     return q->trlrc & E1000_TRLRC_RS_ENA;
@@ -4329,7 +4385,11 @@ bool igb_trl_enabled(const IGBTrlQueue *q)
 
 static void igb_trl_timer_cb(void *opaque)
 {
-    /* Stub */
+    IGBTrlQueue *trl = opaque;
+    IGB_TxRing txr;
+
+    igb_tx_ring_init(trl->core, &txr, trl->qidx);
+    igb_start_xmit(trl->core, &txr);
 }
 
 static void igb_trl_init(IGBCore *core)
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
Reviewed-by on v7 5/7
#9 lore raw

Re: [PATCH v7 5/7] igb: Implement TRL throttling and timer resumption

Quoted 18 lines · Josh Hilke

Integrate throttling logic into the transmission path. In igb_start_xmit, check if the queue is currently throttled. Accumulate bytes sent, calculate the transmission delay based on the configured target rate, and if a throttle is triggered, set the virtual timer, mark the queue as throttled, and defer remaining packets. Implement the timer callback to clear the throttled state and resume transmission when the timer expires.

---
  hw/net/igb_core.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
  1 file changed, 63 insertions(+), 3 deletions(-)
hw/net/igb_core.c +0 -0
index 9a8ef15..e158837 100644

hw/net/igb_core.c igb_receive_internal(IGBCore *core, const struct iovec *iov, int iovcnt, · line 100

Quoted 4 lines
hw/net/igb_core.c +1 -0
@@ -97,6 +97,7 @@ igb_receive_internal(IGBCore *core, const struct iovec *iov, int iovcnt,
  static void igb_raise_interrupts(IGBCore *core, size_t index, uint32_t causes);
  static void igb_reset(IGBCore *core, bool sw);
 
+

Hmm?

Quoted 37 lines
hw/net/igb_core.c +30 -0
  static inline void
  igb_raise_legacy_irq(IGBCore *core)
  {
@@ -875,6 +876,48 @@ igb_tx_enabled(IGBCore *core, const E1000ERingInfo *txi)
          (core->mac[TXDCTL0 + (qn * 16)] & E1000_TXDCTL_QUEUE_ENABLE);
  }
 
+static uint64_t igb_trl_calculate_delay(const IGBTrlQueue *q, size_t bytes_sent)
+{
+    uint32_t divisor;
+    uint32_t rf;
+
+    if (!igb_trl_enabled(q)) {
+        return 0;
+    }
+
+    /*
+     * 7.8 Transmit Rate Limiting (TRL)
+     *
+     * > RF = 1Gb/s / Target-Rate (Rate Factor) is the ratio between the
+     * > nominal link rate and the target maximum rate to achieve for
+     * > that rate controlled queue. It is a decimal number ranging from
+     * > 1 to 1,000 (1 Mb/s minimum target rate) at least 10-bits before
+     * > the hexadecimal point and 14-bits after, as required for the
+     * > maximum PL by which it is multiplied.
+     *
+     * The TRLRC register stores the RF in 10.14 fixed-point format:
+     * - Bits 13:0: Fractional part
+     * - Bits 23:14: Integer part
+     *
+     * Combined, the lower 24 bits of the register (23:0) represent the
+     * RF directly.
+     */
+    rf = MAX(extract32(q->trlrc, 0, 24), 1 << 14);
+
+    /*
+     * Delay = PL (Packet Length) / Target-Rate

hw/net/igb_core.c igb_tx_enabled(IGBCore *core, const E1000ERingInfo *txi) · line 918

Quoted 10 lines
hw/net/igb_core.c +10 -0
+     *       = PL / (1Gb/s / RF)
+     *       = PL * RF / 1Gb/s
+     *       = PL * RF / (1G / b/B / ns/s) B/ns
+     *       = (bytes_sent * (RF_scaled / 2^14) / (1G / b/B / ns/s)) ns
+     *       = (bytes_sent * RF_scaled / (1G / b/B * 2^14 / ns/s)) ns
+     */
+    divisor = ((1000000000ULL / BITS_PER_BYTE) << 14) /
+              NANOSECONDS_PER_SECOND;
+
+    return (uint64_t)bytes_sent * rf / divisor;

Any reason for not using muldiv64()?

Quoted 44 lines
hw/net/igb_core.c +17 -1
+}
+
  static void
  igb_start_xmit(IGBCore *core, const IGB_TxRing *txr)
  {
@@ -883,12 +926,19 @@ igb_start_xmit(IGBCore *core, const IGB_TxRing *txr)
      union e1000_adv_tx_desc desc;
      const E1000ERingInfo *txi = txr->i;
      uint32_t eic = 0;
+    size_t bytes_sent = 0;
+    uint64_t delay_ns;
 
      if (!igb_tx_enabled(core, txi)) {
          trace_e1000e_tx_disabled();
          return;
      }
 
+    if (igb_trl_enabled(&core->trl[txi->idx]) &&
+        timer_pending(core->trl[txi->idx].timer)) {
+        return;
+    }
+
      d = pcie_sriov_get_vf_at_index(core->owner, txi->idx % 8);
      if (!d) {
          d = core->owner;
@@ -902,9 +952,16 @@ igb_start_xmit(IGBCore *core, const IGB_TxRing *txr)
          trace_e1000e_tx_descr((void *)(intptr_t)desc.read.buffer_addr,
                                desc.read.cmd_type_len, desc.wb.status);
 
-        igb_process_tx_desc(core, d, txr->tx, &desc, txi->idx);
+        bytes_sent += igb_process_tx_desc(core, d, txr->tx, &desc, txi->idx);
          igb_ring_advance(core, txi, 1);
          eic |= igb_txdesc_writeback(core, base, &desc, txi);
+
+        delay_ns = igb_trl_calculate_delay(&core->trl[txi->idx], bytes_sent);
+        if (delay_ns > 0) {
+            timer_mod(core->trl[txi->idx].timer,
+                      qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + delay_ns);
+            break;
+        }
      }
 
      if (eic) {

hw/net/igb_core.c igb_autoneg_resume(IGBCore *core) · line 4324

Quoted 4 lines
hw/net/igb_core.c +0 -1
@@ -4321,7 +4378,6 @@ igb_autoneg_resume(IGBCore *core)
                    qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500);
      }
  }
-

Hmm?

Quoted 7 lines
hw/net/igb_core.c +0 -0
  bool igb_trl_enabled(const IGBTrlQueue *q)
  {
      return q->trlrc & E1000_TRLRC_RS_ENA;
@@ -4329,7 +4385,11 @@ bool igb_trl_enabled(const IGBTrlQueue *q)
 
  static void igb_trl_timer_cb(void *opaque)

hw/net/igb_core.c bool igb_trl_enabled(const IGBTrlQueue *q) · line 4395

Quoted 10 lines
hw/net/igb_core.c +5 -1
  {
-    /* Stub */
+    IGBTrlQueue *trl = opaque;
+    IGB_TxRing txr;
+
+    igb_tx_ring_init(trl->core, &txr, trl->qidx);
+    igb_start_xmit(trl->core, &txr);
  }
 
  static void igb_trl_init(IGBCore *core)

Modulo muldiv:

#10 lore raw

Re: [PATCH v7 5/7] igb: Implement TRL throttling and timer resumption

Quoted 62 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Josh Hilke

Integrate throttling logic into the transmission path. In igb_start_xmit, check if the queue is currently throttled.  Accumulate bytes sent, calculate the transmission delay based on the configured target rate, and if a throttle is triggered, set the virtual timer, mark the queue as throttled, and defer remaining packets.  Implement the timer callback to clear the throttled state and resume transmission when the timer expires.

---
  hw/net/igb_core.c | 66 +++++++++++++++++++++++++++++++++++++++++++++
+++++++---

  1 file changed, 63 insertions(+), 3 deletions(-)
hw/net/igb_core.c +0 -0
index 9a8ef15..e158837 100644

hw/net/igb_core.c igb_receive_internal(IGBCore *core, const struct · line 100

Quoted 4 lines
hw/net/igb_core.c +1 -0
@@ -97,6 +97,7 @@ igb_receive_internal(IGBCore *core, const struct 
 iovec *iov, int iovcnt,
   static void igb_raise_interrupts(IGBCore *core, size_t index, uint32_t causes);
   static void igb_reset(IGBCore *core, bool sw);
+

Hmm?

Quoted 35 lines

  static inline void
  igb_raise_legacy_irq(IGBCore *core)
  {

hw/net/igb_core.c +27 -0
@@ -875,6 +876,48 @@ igb_tx_enabled(IGBCore *core, const 
 E1000ERingInfo *txi)
           (core->mac[TXDCTL0 + (qn * 16)] & E1000_TXDCTL_QUEUE_ENABLE);
   }
+static uint64_t igb_trl_calculate_delay(const IGBTrlQueue *q, size_t 
 bytes_sent)
+{
+    uint32_t divisor;
+    uint32_t rf;
+
+    if (!igb_trl_enabled(q)) {
+        return 0;
+    }
+
+    /*
+     * 7.8 Transmit Rate Limiting (TRL)
+     *
+     * > RF = 1Gb/s / Target-Rate (Rate Factor) is the ratio between the
+     * > nominal link rate and the target maximum rate to achieve for
+     * > that rate controlled queue. It is a decimal number ranging from
+     * > 1 to 1,000 (1 Mb/s minimum target rate) at least 10-bits before
+     * > the hexadecimal point and 14-bits after, as required for the
+     * > maximum PL by which it is multiplied.
+     *
+     * The TRLRC register stores the RF in 10.14 fixed-point format:
+     * - Bits 13:0: Fractional part
+     * - Bits 23:14: Integer part
+     *
+     * Combined, the lower 24 bits of the register (23:0) represent the
+     * RF directly.
+     */
+    rf = MAX(extract32(q->trlrc, 0, 24), 1 << 14);
Quoted 8 lines

hw/net/igb_core.c igb_tx_enabled(IGBCore *core, const E1000ERingInfo *txi) · line 913

Quoted 8 lines
hw/net/igb_core.c +8 -0
+
+    /*
+     * Delay = PL (Packet Length) / Target-Rate
+     *       = PL / (1Gb/s / RF)
+     *       = PL * RF / 1Gb/s
+     *       = PL * RF / (1G / b/B / ns/s) B/ns
+     *       = (bytes_sent * (RF_scaled / 2^14) / (1G / b/B / ns/s)) ns
+     *       = (bytes_sent * RF_scaled / (1G / b/B * 2^14 / ns/s)) ns

s/RF_scaled/RF/g since RF is defined as including 14-bits after the point, as quoted above. (i.e., RF is already defined as "scaled".)

Regards,
Akihiko Odaki

Quoted 77 lines

hw/net/igb_core.c igb_tx_enabled(IGBCore *core, const E1000ERingInfo *txi) · line 918

Quoted 5 lines
hw/net/igb_core.c +5 -0
+     */
+    divisor = ((1000000000ULL / BITS_PER_BYTE) << 14) /
+              NANOSECONDS_PER_SECOND;
+
+    return (uint64_t)bytes_sent * rf / divisor;

Any reason for not using muldiv64()?

Quoted 43 lines
hw/net/igb_core.c +2 -0
+}
+

  static void
  igb_start_xmit(IGBCore *core, const IGB_TxRing *txr) {

hw/net/igb_core.c +15 -1
@@ -883,12 +926,19 @@ igb_start_xmit(IGBCore *core, const IGB_TxRing 
 *txr)
       union e1000_adv_tx_desc desc;
       const E1000ERingInfo *txi = txr->i;
       uint32_t eic = 0;
+    size_t bytes_sent = 0;
+    uint64_t delay_ns;
       if (!igb_tx_enabled(core, txi)) {
           trace_e1000e_tx_disabled();
           return;
       }
+    if (igb_trl_enabled(&core->trl[txi->idx]) &&
+        timer_pending(core->trl[txi->idx].timer)) {
+        return;
+    }
+
       d = pcie_sriov_get_vf_at_index(core->owner, txi->idx % 8);
       if (!d) {
           d = core->owner;
@@ -902,9 +952,16 @@ igb_start_xmit(IGBCore *core, const IGB_TxRing *txr)
           trace_e1000e_tx_descr((void *)(intptr_t)desc.read.buffer_addr,
                                 desc.read.cmd_type_len, desc.wb.status);
-        igb_process_tx_desc(core, d, txr->tx, &desc, txi->idx);
+        bytes_sent += igb_process_tx_desc(core, d, txr->tx, &desc, 
 txi->idx);
           igb_ring_advance(core, txi, 1);
           eic |= igb_txdesc_writeback(core, base, &desc, txi);
+
+        delay_ns = igb_trl_calculate_delay(&core->trl[txi->idx], 
 bytes_sent);
+        if (delay_ns > 0) {
+            timer_mod(core->trl[txi->idx].timer,
+                      qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + delay_ns);
+            break;
+        }
       }
       if (eic) {

hw/net/igb_core.c igb_autoneg_resume(IGBCore *core) · line 4324

Quoted 4 lines
hw/net/igb_core.c +0 -1
@@ -4321,7 +4378,6 @@ igb_autoneg_resume(IGBCore *core)
                     qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500);
       }
   }
-

Hmm?

Quoted 5 lines
hw/net/igb_core.c +0 -0
   bool igb_trl_enabled(const IGBTrlQueue *q)
   {
       return q->trlrc & E1000_TRLRC_RS_ENA;
@@ -4329,7 +4385,11 @@ bool igb_trl_enabled(const IGBTrlQueue *q)
   static void igb_trl_timer_cb(void *opaque)

hw/net/igb_core.c bool igb_trl_enabled(const IGBTrlQueue *q) · line 4394

Quoted 10 lines
hw/net/igb_core.c +5 -1
   {
-    /* Stub */
+    IGBTrlQueue *trl = opaque;
+    IGB_TxRing txr;
+
+    igb_tx_ring_init(trl->core, &txr, trl->qidx);
+    igb_start_xmit(trl->core, &txr);
   }
   static void igb_trl_init(IGBCore *core)
 

Modulo muldiv:

author
#11 lore raw

PATCH v7 6/7 igb: Add QTest for Transmit Rate Limiter register multiplexing

In reply to Josh Hilke

Add a unit test to verify register writes/reads to the rate limit register (TRLC) return the correct value based on which queue is currently selected in the queue selection register (TRLDQSEL).

---
 tests/qtest/igb-test.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
tests/qtest/igb-test.c +51 -0
index 3d397ea..0a4d0b1 100644
@@ -45,6 +45,20 @@ static const struct eth_header packet = {
     .h_source = E1000E_ADDRESS,
 };
 
+/*
+ * Calculate TRL rate factor for a given target rate.
+ *
+ * Rate Factor = 1 Gbps / Target Rate.
+ *
+ * The hardware TRLRC register stores the rate factor as a fixed-point number
+ * with 14 fractional bits. Scale 1Gbps by 2^14 before dividing to preserve
+ * precision in integer arithmetic.
+ */
+static uint32_t igb_trl_get_rate_factor(uint64_t rate_bytes_s)
+{
+    return ((1000000000ULL / BITS_PER_BYTE) << 14) / rate_bytes_s;
+}
+
 static void igb_send_verify(QE1000E *d, int *test_sockets, QGuestAllocator *alloc)
 {
     union e1000_adv_tx_desc descr;
@@ -191,6 +205,41 @@ static void test_igb_multiple_transfers(void *obj, void *data,
 
 }
 
+/*
+ * Verify the rate limit value register (TRLC) returns the correct value based
+ * on which queue is selected (TRLDQSEL).
+ */
+static void test_igb_transmit_rate_limiter_regs(void *obj, void *data,
+                                                QGuestAllocator *alloc)
+{
+    QOSGraphObject *e_object = obj;
+    QE1000E_PCI *e1000e = obj;
+    QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
+    QE1000E *d = &e1000e->e1000e;
+    const int qidx0 = 0, qidx1 = 1;
+    uint32_t val0, val1;
+
+    if (qpci_check_buggy_msi(dev)) {
+        return;
+    }
+
+    e1000e_macreg_write(d, E1000_TRLDQSEL, qidx0);
+    val0 = E1000_TRLRC_RS_ENA |
+           igb_trl_get_rate_factor(125000);
+    e1000e_macreg_write(d, E1000_TRLRC, val0);
+
+    e1000e_macreg_write(d, E1000_TRLDQSEL, qidx1);
+    val1 = E1000_TRLRC_RS_ENA |
+           igb_trl_get_rate_factor(250000);
+    e1000e_macreg_write(d, E1000_TRLRC, val1);
+
+    e1000e_macreg_write(d, E1000_TRLDQSEL, qidx0);
+    g_assert_cmphex(e1000e_macreg_read(d, E1000_TRLRC), ==, val0);
+
+    e1000e_macreg_write(d, E1000_TRLDQSEL, qidx1);
+    g_assert_cmphex(e1000e_macreg_read(d, E1000_TRLRC), ==, val1);
+}
+
 static void data_test_clear(void *sockets)
 {
     int *test_sockets = sockets;
@@ -247,6 +296,8 @@ static void register_igb_test(void)
     qos_add_test("rx", "igb", test_igb_rx, &opts);
     qos_add_test("multiple_transfers", "igb",
                  test_igb_multiple_transfers, &opts);
+    qos_add_test("transmit_rate_limiter_regs", "igb",
+                 test_igb_transmit_rate_limiter_regs, &opts);
 #endif
 
     opts.before = data_test_init_no_socket;
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
author
#12 lore raw

PATCH v7 7/7 igb: Add QTest for Transmit Rate Limiter traffic throttling

In reply to Josh Hilke

Add a test for the IGB transmit rate limiting functionality. The test verifies that TRL is enabled by setting the appropriate registers and that data is transmitted at the appropriate rate based on chosen target rate.

---
 tests/qtest/igb-test.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 155 insertions(+)
tests/qtest/igb-test.c +155 -0
index 0a4d0b1..31f2bbe 100644
@@ -34,9 +34,11 @@
 #include "qemu/iov.h"
 #include "qemu/module.h"
 #include "qemu/bitops.h"
+#include "qemu/timer.h"
 #include "libqos/libqos-malloc.h"
 #include "libqos/e1000e.h"
 #include "hw/net/igb_regs.h"
+#include "hw/pci/pci_regs.h"
 
 #ifndef _WIN32
 
@@ -59,6 +61,58 @@ static uint32_t igb_trl_get_rate_factor(uint64_t rate_bytes_s)
     return ((1000000000ULL / BITS_PER_BYTE) << 14) / rate_bytes_s;
 }
 
+static void igb_trl_enable(QE1000E *d, uint64_t rate_bytes_s)
+{
+    /* Select Queue 0 */
+    e1000e_macreg_write(d, E1000_TRLDQSEL, 0);
+    /* Enable TRL with target rate */
+    e1000e_macreg_write(d, E1000_TRLRC,
+                        E1000_TRLRC_RS_ENA |
+                        igb_trl_get_rate_factor(rate_bytes_s));
+}
+
+static void igb_trl_disable(QE1000E *d)
+{
+    /* Select Queue 0 */
+    e1000e_macreg_write(d, E1000_TRLDQSEL, 0);
+    /* Disable TRL */
+    e1000e_macreg_write(d, E1000_TRLRC, 0);
+}
+
+static void igb_msix_clear_pending(QPCIDevice *dev, uint16_t entry)
+{
+    uint64_t vector_offset =
+        dev->msix_table_off + (entry * PCI_MSIX_ENTRY_SIZE);
+    uint32_t val = qpci_io_readl(dev, dev->msix_table_bar,
+                                 vector_offset + PCI_MSIX_ENTRY_VECTOR_CTRL);
+
+    /* Unmask (clears pending bit in QEMU) */
+    qpci_io_writel(dev, dev->msix_table_bar,
+                   vector_offset + PCI_MSIX_ENTRY_VECTOR_CTRL,
+                   val & ~PCI_MSIX_ENTRY_CTRL_MASKBIT);
+
+    /* Mask again */
+    qpci_io_writel(dev, dev->msix_table_bar,
+                   vector_offset + PCI_MSIX_ENTRY_VECTOR_CTRL,
+                   val);
+}
+
+static void igb_read_tx_tail(QE1000E *d, void *descr)
+{
+    QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e);
+    uint32_t last_entry;
+    uint32_t tail;
+    uint32_t len;
+
+    tail = e1000e_macreg_read(d, E1000_TDT_A(0));
+    len = e1000e_macreg_read(d, E1000_TDLEN_A(0)) / E1000_RING_DESC_LEN;
+    last_entry = (tail + len - 1) % len;
+
+    qtest_memread(d_pci->pci_dev.bus->qts,
+                  d->tx_ring + last_entry * E1000_RING_DESC_LEN, descr,
+                  E1000_RING_DESC_LEN);
+}
+
 static void igb_send_verify(QE1000E *d, int *test_sockets, QGuestAllocator *alloc)
 {
     union e1000_adv_tx_desc descr;
@@ -84,6 +138,14 @@ static void igb_send_verify(QE1000E *d, int *test_sockets, QGuestAllocator *allo
     /* Wait for TX WB interrupt */
     e1000e_wait_isr(d, E1000E_TX0_MSG_ID);
 
+    /*
+     * Read the descriptor back from guest memory again, now that WB has
+     * occurred. This is required because if the packet was delayed by the
+     * trasmit rate limiter, e1000e_tx_ring_push read it back before QEMU
+     * actually processed it.
+     */
+    igb_read_tx_tail(d, &descr);
+
     /* Check DD bit */
     g_assert_cmphex(le32_to_cpu(descr.wb.status) & E1000_TXD_STAT_DD, ==,
                     E1000_TXD_STAT_DD);
@@ -147,6 +209,29 @@ static void igb_receive_verify(QE1000E *d, int *test_sockets, QGuestAllocator *a
     guest_free(alloc, data);
 }
 
+/* Returns the amount of microseconds it takes to transmit a 64-byte packet.*/
+static uint64_t igb_send_and_measure(QE1000E *d, int *test_sockets,
+                                     QGuestAllocator *alloc)
+{
+    QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e);
+    QPCIDevice *pdev = &d_pci->pci_dev;
+    QTestState *qts = global_qtest;
+    uint64_t start_time, end_time;
+
+    /* Clear any stale pending interrupt for this vector before we start */
+    igb_msix_clear_pending(pdev, E1000E_TX0_MSG_ID);
+
+    /* Clear EICR to allow new interrupts to be raised in MSI-X mode */
+    e1000e_macreg_write(d, E1000_EICR, 0xFFFFFFFF);
+
+    /* Send a test packet and measure the time it takes. */
+    start_time = qtest_clock_step(qts, 1);
+    igb_send_verify(d, test_sockets, alloc);
+    end_time = qtest_clock_step(qts, 1);
+
+    return end_time - start_time;
+}
+
 static void test_e1000e_init(void *obj, void *data, QGuestAllocator * alloc)
 {
     /* init does nothing */
@@ -240,6 +325,74 @@ static void test_igb_transmit_rate_limiter_regs(void *obj, void *data,
     g_assert_cmphex(e1000e_macreg_read(d, E1000_TRLRC), ==, val1);
 }
 
+/*
+ * Test for Transmit Rate Limiter (TRL) traffic throttling.
+ *
+ * Verifies that:
+ * 1. Packets are transmitted without delay when TRL is disabled.
+ * 2. Enabling TRL on a queue throttles subsequent transmissions.
+ * 3. The delay matches the expected transmission time calculated from the
+ *    packet size and the configured target rate.
+ * 4. Disabling TRL restores normal (unthrottled) transmission behavior.
+ */
+static void test_igb_transmit_rate_limiter(void *obj, void *data,
+                                           QGuestAllocator *alloc)
+{
+    QOSGraphObject *e_object = obj;
+    QE1000E_PCI *e1000e = obj;
+    QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
+    QE1000E *d = &e1000e->e1000e;
+    const uint64_t expected_baseline_elapsed = 10 * SCALE_US;
+    const uint64_t expected_max_elapsed = 530 * SCALE_US;
+    const uint64_t expected_min_elapsed = 500 * SCALE_US;
+    uint64_t elapsed;
+
+    if (qpci_check_buggy_msi(dev)) {
+        return;
+    }
+
+    /* Send a test packet to verify there's no rate limit. */
+    elapsed = igb_send_and_measure(d, data, alloc);
+
+    /*
+     * QEMU doesn't emulate the hardware line rate of the device, so the packet
+     * is processed instantly (requiring 0 clock steps in wait_isr, which steps
+     * by 10us). Give a 10us margin for error.
+     */
+    g_assert_cmpint(elapsed, <, expected_baseline_elapsed);
+
+    /* Enable TRL and set the target rate to 125 KB/s */
+    igb_trl_enable(d, 125000);
+
+    /*
+     * Send Packet 1 (no delay)
+     * The first packet triggers rate limiting for subsequent transmissions.
+     */
+    elapsed = igb_send_and_measure(d, data, alloc);
+    g_assert_cmpint(elapsed, <, expected_baseline_elapsed);
+
+    /* Send Packet 2 (should be delayed) */
+    elapsed = igb_send_and_measure(d, data, alloc);
+    /*
+     * Expected delay: 64 byte packet / 125 KB/s = 512 us.
+     * Since QEMU steps the clock by 10 us on each wait_isr iteration,
+     * the delay is rounded up to the next 10 us step, which is 520 us.
+     */
+    g_assert_cmpint(elapsed, >=, expected_min_elapsed);
+    g_assert_cmpint(elapsed, <=, expected_max_elapsed);
+
+    /* Send Packet 3 (should also be delayed) */
+    elapsed = igb_send_and_measure(d, data, alloc);
+    g_assert_cmpint(elapsed, >=, expected_min_elapsed);
+    g_assert_cmpint(elapsed, <=, expected_max_elapsed);
+
+    igb_trl_disable(d);
+
+    /* Send Packet 4 (no delay since TRL is disabled) */
+    elapsed = igb_send_and_measure(d, data, alloc);
+    g_assert_cmpint(elapsed, <, expected_baseline_elapsed);
+}
+
 static void data_test_clear(void *sockets)
 {
     int *test_sockets = sockets;
@@ -298,6 +451,8 @@ static void register_igb_test(void)
                  test_igb_multiple_transfers, &opts);
     qos_add_test("transmit_rate_limiter_regs", "igb",
                  test_igb_transmit_rate_limiter_regs, &opts);
+    qos_add_test("transmit_rate_limiter", "igb",
+                 test_igb_transmit_rate_limiter, &opts);
 #endif
 
     opts.before = data_test_init_no_socket;
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
#13 lore raw
In reply to Josh Hilke

Hi Josh,

Quoted 7 lines · Josh Hilke

This is v7 of a patch series implementing the Transmit Rate Limiter (TRL) feature for the Intel 82576 (igb) network device emulation in QEMU.

v6: https://lists.gnu.org/archive/html/qemu-devel/2026-06/msg04562.html

Changelog:

Quoted 7 lines

v7:
- Inline igb_trl_disable() since it's only needed in one location,

     igb_core_set_link_status().

- Fix indentation in QTest.
- Don't set PCI_MSIX_ENTRY_CTRL_MASKBIT when clearing pending interrupts in Qtest.
- Fold calculations igb_trl_calculate_delay() to simplify logic.

I already reviewed some of these in your v4, should I review the patches again?

Quoted 24 lines

---
Josh Hilke (7):
igb: Define TRL registers and core state
igb: Add VMState support for TRL state
igb: Implement TRL register write and configuration
igb: Refactor TX path to return processed byte count
igb: Implement TRL throttling and timer resumption
igb: Add QTest for Transmit Rate Limiter register multiplexing
igb: Add QTest for Transmit Rate Limiter traffic throttling

  hw/net/igb.c           |  43 +++++++++++
  hw/net/igb_common.h    |   1 +
  hw/net/igb_core.c      | 142 ++++++++++++++++++++++++++++++++--
  hw/net/igb_core.h      |  12 +++
  hw/net/igb_regs.h      |   5 ++
  tests/qtest/igb-test.c | 206 +++++++++++++++++++++++++++++++++++++++++++++++++
  6 files changed, 404 insertions(+), 5 deletions(-)

---
base-commit: 98b060da3a4f92b2a994ead5b16a87e783baf77c
change-id: 20260608-igb-trl-19be198da6f2

Best regards,

author
#14 lore raw

No need to review again unless you want to. The updates in v7 are just responses to Akihiko's comments on v6. The changes are pretty minor at this point.

Quoted 47 lines · Philippe Mathieu-Daudé

Hi Josh,

Quoted 7 lines · Josh Hilke

This is v7 of a patch series implementing the Transmit Rate Limiter (TRL) feature for the Intel 82576 (igb) network device emulation in QEMU.

v6: https://lists.gnu.org/archive/html/qemu-devel/2026-06/msg04562.html

Changelog:

Quoted 7 lines

v7:
- Inline igb_trl_disable() since it's only needed in one location,

     igb_core_set_link_status().

- Fix indentation in QTest.
- Don't set PCI_MSIX_ENTRY_CTRL_MASKBIT when clearing pending interrupts in Qtest.
- Fold calculations igb_trl_calculate_delay() to simplify logic.

I already reviewed some of these in your v4, should I review the patches again?

Quoted 24 lines

---
Josh Hilke (7):
igb: Define TRL registers and core state
igb: Add VMState support for TRL state
igb: Implement TRL register write and configuration
igb: Refactor TX path to return processed byte count
igb: Implement TRL throttling and timer resumption
igb: Add QTest for Transmit Rate Limiter register multiplexing
igb: Add QTest for Transmit Rate Limiter traffic throttling

  hw/net/igb.c           |  43 +++++++++++
  hw/net/igb_common.h    |   1 +
  hw/net/igb_core.c      | 142 ++++++++++++++++++++++++++++++++--
  hw/net/igb_core.h      |  12 +++
  hw/net/igb_regs.h      |   5 ++
  tests/qtest/igb-test.c | 206 +++++++++++++++++++++++++++++++++++++++++++++++++
  6 files changed, 404 insertions(+), 5 deletions(-)

---
base-commit: 98b060da3a4f92b2a994ead5b16a87e783baf77c
change-id: 20260608-igb-trl-19be198da6f2

Best regards,

#15 lore raw
Quoted 3 lines · Josh Hilke

No need to review again unless you want to. The updates in v7 are just responses to Akihiko's comments on v6. The changes are pretty minor at this point.

OK, then for "pretty minor changes" please carry the reviewer tags from previous series, that save us time, otherwise we have to review again.

See https://www.qemu.org/docs/master/devel/submitting-a-patch.html#proper-use-of-reviewed-by-tags-can-aid-review:

When reviewing a large series, a reviewer can reply to some of the patches with a Reviewed-by tag, stating that they are happy with that patch in isolation (sometimes conditional on minor cleanup, like fixing whitespace, that doesn’t affect code content). You should then update those commit messages by hand to include the Reviewed-by tag, so that in the next revision, reviewers can spot which patches were already clean from the previous round. Conversely, if you significantly modify a patch that was previously reviewed, remove the reviewed-by tag out of the commit message, as well as listing the changes from the previous version, to make it easier to focus a reviewer’s attention to your changes.

Quoted 50 lines
Quoted 47 lines · Philippe Mathieu-Daudé

Hi Josh,

Quoted 7 lines · Josh Hilke

This is v7 of a patch series implementing the Transmit Rate Limiter (TRL) feature for the Intel 82576 (igb) network device emulation in QEMU.

v6: https://lists.gnu.org/archive/html/qemu-devel/2026-06/msg04562.html

Changelog:

Quoted 7 lines

v7:
- Inline igb_trl_disable() since it's only needed in one location, igb_core_set_link_status().
- Fix indentation in QTest.
- Don't set PCI_MSIX_ENTRY_CTRL_MASKBIT when clearing pending interrupts in Qtest.
- Fold calculations igb_trl_calculate_delay() to simplify logic.

I already reviewed some of these in your v4, should I review the patches again?

Quoted 24 lines

---
Josh Hilke (7):
igb: Define TRL registers and core state
igb: Add VMState support for TRL state
igb: Implement TRL register write and configuration
igb: Refactor TX path to return processed byte count
igb: Implement TRL throttling and timer resumption
igb: Add QTest for Transmit Rate Limiter register multiplexing
igb: Add QTest for Transmit Rate Limiter traffic throttling

   hw/net/igb.c           |  43 +++++++++++
   hw/net/igb_common.h    |   1 +
   hw/net/igb_core.c      | 142 ++++++++++++++++++++++++++++++++--
   hw/net/igb_core.h      |  12 +++
   hw/net/igb_regs.h      |   5 ++
   tests/qtest/igb-test.c | 206 +++++++++++++++++++++++++++++++++++++++++++++++++
   6 files changed, 404 insertions(+), 5 deletions(-)

---
base-commit: 98b060da3a4f92b2a994ead5b16a87e783baf77c
change-id: 20260608-igb-trl-19be198da6f2

Best regards,