From dbd693b1d563be44c673ac9c2fef139fc8160139 Mon Sep 17 00:00:00 2001 From: Alexander Stephan Date: Sat, 21 Feb 2026 15:04:31 +0100 Subject: [PATCH] Add function to clear TX statistics for the ixgbe driver --- lua/driver/ixgbe.lua | 12 ++++++++++++ lua/stats.lua | 17 +++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lua/driver/ixgbe.lua b/lua/driver/ixgbe.lua index e189536..efbb2c0 100644 --- a/lua/driver/ixgbe.lua +++ b/lua/driver/ixgbe.lua @@ -64,6 +64,18 @@ function dev:clearRxStats() return end +-- clear TX counters. We want to clear the s/w statistics and also reg read to clear the h/w level +function dev:clearTxStats() + -- Read the hardware registers to clear them + dpdkc.read_reg32(self.id, GPTC) + dpdkc.read_reg32(self.id, GOTCL) + dpdkc.read_reg32(self.id, GOTCH) + -- Reset the software accumulation counters + self.txPkts = 0ULL + self.txBytes = 0ULL + return +end + -- necessary because of clear-on-read registers and the interaction with the normal rte_eth_stats_get() call function dev:getTxStats() self.txPkts = (self.txPkts or 0ULL) + dpdkc.read_reg32(self.id, GPTC) diff --git a/lua/stats.lua b/lua/stats.lua index 4cbbf35..fa83c24 100644 --- a/lua/stats.lua +++ b/lua/stats.lua @@ -377,12 +377,12 @@ function rxCounter:getStats(forceUpdate) end --- Device-based counter -function devRxCounter:getThroughput() - return self.dev:getRxStats() -end +function devRxCounter:getThroughput() + return self.dev:getRxStats() +end -function devRxCounter:clearThroughput() - return self.dev:clearRxStats() +function devRxCounter:clearThroughput() + return self.dev:clearRxStats() end --- Packet-based counter @@ -453,10 +453,16 @@ function mod:newDevTxCounter(name, dev, format, file) local obj = newCounter("dev", name, dev, format, file, "tx") obj.sleep = 50 setmetatable(obj, devTxCounter) + obj:clearThroughput() obj:getThroughput() -- reset stats on the NIC return obj end +-- Similiar to clearRxStats +function devTxCounter:clearThroughput() + return self.dev:clearTxStats() +end + --- Create a new tx counter that can be updated by passing packet buffers to it. --- @param name the name of the counter, included in the output --- @param format the output format, "CSV" and "plain" (default) are currently supported @@ -629,4 +635,3 @@ end __LIBMOON_STATS_TASK = statsTask return mod -