Skip to content

Commit

Permalink
following the merge of RedHatInsights/insights-core#3561, adding supp…
Browse files Browse the repository at this point in the history
…ort for 9,10,11 and 13 columns, unitest has also more case

Signed-off-by: remi <[email protected]>
  • Loading branch information
remijouannet committed Nov 7, 2022
1 parent 1828aed commit 9fa034a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 57 deletions.
72 changes: 32 additions & 40 deletions net_softnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ import (
// For the proc file format details,
// See:
// * Linux 2.6.23 https://elixir.bootlin.com/linux/v2.6.23/source/net/core/dev.c#L2343
// * Linux 4.17 https://elixir.bootlin.com/linux/v4.17/source/net/core/net-procfs.c#L162
// * Linux 5.10 https://elixir.bootlin.com/linux/v5.10/source/net/core/net-procfs.c#L172
// * https://elixir.bootlin.com/linux/v4.17/source/include/linux/netdevice.h#L2810
// * https://elixir.bootlin.com/linux/v5.10/source/include/linux/netdevice.h#L3181
// * Linux 2.6.39 https://elixir.bootlin.com/linux/v2.6.39/source/net/core/dev.c#L4086
// * Linux 4.18 https://elixir.bootlin.com/linux/v4.18/source/net/core/net-procfs.c#L162
// * Linux 5.14 https://elixir.bootlin.com/linux/v5.14/source/net/core/net-procfs.c#L169

// SoftnetStat contains a single row of data from /proc/net/softnet_stat.
type SoftnetStat struct {
Expand All @@ -46,11 +45,11 @@ type SoftnetStat struct {
ReceivedRps uint32
// number of times flow limit has been reached.
FlowLimitCount uint32
// Softnet Backlog status.
// Softnet backlog status.
SoftnetBacklogLen uint32
// CPU id owning this softnet_data.
Index uint32
// softnet_data's Width
// softnet_data's Width.
Width int
}

Expand Down Expand Up @@ -80,64 +79,57 @@ func parseSoftnet(r io.Reader) ([]SoftnetStat, error) {
for s.Scan() {
columns := strings.Fields(s.Text())
width := len(columns)
softnetStat := SoftnetStat{}

if width < minColumns {
return nil, fmt.Errorf("%d columns were detected, but at least %d were expected", width, minColumns)
}

// * Linux 2.6.23 https://elixir.bootlin.com/linux/v2.6.23/source/net/core/dev.c#L2343
if width == minColumns {
// Linux 2.6.23 https://elixir.bootlin.com/linux/v2.6.23/source/net/core/dev.c#L2347
if width >= minColumns {
us, err := parseHexUint32s(columns[0:9])
if err != nil {
return nil, err
}

stats = append(stats, SoftnetStat{
Processed: us[0],
Dropped: us[1],
TimeSqueezed: us[2],
CPUCollision: us[8],
Width: width,
})
softnetStat.Processed = us[0]
softnetStat.Dropped = us[1]
softnetStat.TimeSqueezed = us[2]
softnetStat.CPUCollision = us[8]
}

// * Linux 4.17 https://elixir.bootlin.com/linux/v4.17/source/net/core/net-procfs.c#L162
if width == 11 {
us, err := parseHexUint32s(columns[0:11])
// Linux 2.6.39 https://elixir.bootlin.com/linux/v2.6.39/source/net/core/dev.c#L4086
if width >= 10 {
us, err := parseHexUint32s(columns[9:10])
if err != nil {
return nil, err
}

stats = append(stats, SoftnetStat{
Processed: us[0],
Dropped: us[1],
TimeSqueezed: us[2],
CPUCollision: us[8],
ReceivedRps: us[9],
FlowLimitCount: us[10],
Width: width,
})
softnetStat.ReceivedRps = us[0]
}

// * Linux 5.10 https://elixir.bootlin.com/linux/v5.10/source/net/core/net-procfs.c#L172
// Linux 4.18 https://elixir.bootlin.com/linux/v4.18/source/net/core/net-procfs.c#L162
if width >= 11 {
us, err := parseHexUint32s(columns[10:11])
if err != nil {
return nil, err
}

softnetStat.FlowLimitCount = us[0]
}

// Linux 5.14 https://elixir.bootlin.com/linux/v5.14/source/net/core/net-procfs.c#L169
if width >= 13 {
us, err := parseHexUint32s(columns[0:13])
us, err := parseHexUint32s(columns[11:13])
if err != nil {
return nil, err
}

stats = append(stats, SoftnetStat{
Processed: us[0],
Dropped: us[1],
TimeSqueezed: us[2],
CPUCollision: us[8],
ReceivedRps: us[9],
FlowLimitCount: us[10],
SoftnetBacklogLen: us[11],
Index: us[12],
Width: width,
})
softnetStat.SoftnetBacklogLen = us[0]
softnetStat.Index = us[1]
}
softnetStat.Width = width
stats = append(stats, softnetStat)
}

return stats, nil
Expand Down
36 changes: 22 additions & 14 deletions net_softnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@ func TestNetSoftnet(t *testing.T) {

want := []SoftnetStat{
{
Processed: 0x0446fcea,
Dropped: 0x0012e8f8,
Processed: 0x00358fe3,
Dropped: 0x00006283,
TimeSqueezed: 0x00000000,
CPUCollision: 0x00000000,
ReceivedRps: 0x015f20c8,
FlowLimitCount: 0x00000000,
ReceivedRps: 0x000855fc,
FlowLimitCount: 0x00000076,
SoftnetBacklogLen: 0x00000000,
Index: 0x00000033,
Index: 0x00000000,
Width: 13,
},
{
Processed: 0x00031f27,
Dropped: 0x00020e76,
TimeSqueezed: 0x00000000,
Processed: 0x00953d1a,
Dropped: 0x00000446,
TimeSqueezed: 0x000000b1,
CPUCollision: 0x00000000,
ReceivedRps: 0x00020e76,
FlowLimitCount: 0x00020e76,
SoftnetBacklogLen: 0x00000000,
ReceivedRps: 0x008eeb9a,
FlowLimitCount: 0x0000002b,
SoftnetBacklogLen: 0x000000dc,
Index: 0x00000001,
Width: 13,
},
{
Processed: 0x00015c73,
Dropped: 0x00020e76,
TimeSqueezed: 0xf0000769,
CPUCollision: 0x00000000,
ReceivedRps: 0x00020e76,
FlowLimitCount: 0x00000000,
CPUCollision: 0x00000004,
ReceivedRps: 0x00000003,
FlowLimitCount: 0x00000002,
Width: 11,
},
{
Expand All @@ -64,6 +64,14 @@ func TestNetSoftnet(t *testing.T) {
CPUCollision: 0x00020e76,
Width: 9,
},
{
Processed: 0x00008e78,
Dropped: 0x00000001,
TimeSqueezed: 0x00000011,
CPUCollision: 0x00000020,
ReceivedRps: 0x00000010,
Width: 10,
},
}

got, err := fs.NetSoftnetStat()
Expand Down
9 changes: 6 additions & 3 deletions testdata/fixtures.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -2378,9 +2378,12 @@ FRAG6: inuse 0 memory 0
Mode: 444
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/proc/net/softnet_stat
Lines: 2
00015c73 00020e76 F0000769 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
01663fb2 00000000 000109a4 00000000 00000000 00000000 00000000 00000000 00000000
Lines: 5
00358fe3 00006283 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000855fc 00000076 00000000 00000000
00953d1a 00000446 000000b1 00000000 00000000 00000000 00000000 00000000 00000000 008eeb9a 0000002b 000000dc 00000001
00015c73 00020e76 f0000769 00000000 00000000 00000000 00000000 00000000 00000004 00000003 00000002
01663fb2 00000000 000109a4 00000000 00000000 00000000 00000000 00000000 00020e76
00008e78 00000001 00000011 00000000 00000000 00000000 00000000 00000000 00000020 00000010
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/proc/net/softnet_stat.broken
Expand Down

0 comments on commit 9fa034a

Please sign in to comment.