Skip to content

Commit

Permalink
Fix softnet CPU Index
Browse files Browse the repository at this point in the history
When parsing older kernel versoins, we assume the CPU is indexed based
on the parsed line, rather than an explicit index column.

Signed-off-by: SuperQ <superq@gmail.com>
  • Loading branch information
SuperQ committed May 11, 2023
1 parent 718836a commit 7634144
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions net_softnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func parseSoftnet(r io.Reader) ([]SoftnetStat, error) {
s := bufio.NewScanner(r)

var stats []SoftnetStat
cpuIndex := 0
for s.Scan() {
columns := strings.Fields(s.Text())
width := len(columns)
Expand Down Expand Up @@ -127,9 +128,13 @@ func parseSoftnet(r io.Reader) ([]SoftnetStat, error) {

softnetStat.SoftnetBacklogLen = us[0]
softnetStat.Index = us[1]
} else {
// For older kernels, create the Index based on the scan line number.
softnetStat.Index = uint32(cpuIndex)
}
softnetStat.Width = width
stats = append(stats, softnetStat)
cpuIndex += 1
}

return stats, nil
Expand Down
3 changes: 3 additions & 0 deletions net_softnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ func TestNetSoftnet(t *testing.T) {
CPUCollision: 0x00000004,
ReceivedRps: 0x00000003,
FlowLimitCount: 0x00000002,
Index: 0x00000002,
Width: 11,
},
{
Processed: 0x01663fb2,
Dropped: 0x00000000,
TimeSqueezed: 0x0109a4,
CPUCollision: 0x00020e76,
Index: 0x00000003,
Width: 9,
},
{
Expand All @@ -70,6 +72,7 @@ func TestNetSoftnet(t *testing.T) {
TimeSqueezed: 0x00000011,
CPUCollision: 0x00000020,
ReceivedRps: 0x00000010,
Index: 0x00000004,
Width: 10,
},
}
Expand Down

0 comments on commit 7634144

Please sign in to comment.