Skip to content

Commit 03da3a1

Browse files
authored
handle more columns from softnet_data (#473)
* handle more column from softnet_data * add CPUCollision for linux 2.6 * add ReceivedRps and FlowLimitCount for linux >4.17 * add SoftnetBacklogLen and Index for linux 5.10 torvalds/linux@7d58e65 * add Width so anyone can choose to use Index instead of line index, see * the commit torvalds/linux@7d58e65 * following the merge of RedHatInsights/insights-core#3561, adding support for 9,10,11 and 13 columns, unitest has also more case Signed-off-by: remi <[email protected]>
1 parent 42aaf8e commit 03da3a1

File tree

3 files changed

+110
-20
lines changed

3 files changed

+110
-20
lines changed

net_softnet.go

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import (
2727
// For the proc file format details,
2828
// See:
2929
// * Linux 2.6.23 https://elixir.bootlin.com/linux/v2.6.23/source/net/core/dev.c#L2343
30-
// * Linux 4.17 https://elixir.bootlin.com/linux/v4.17/source/net/core/net-procfs.c#L162
31-
// and https://elixir.bootlin.com/linux/v4.17/source/include/linux/netdevice.h#L2810.
30+
// * Linux 2.6.39 https://elixir.bootlin.com/linux/v2.6.39/source/net/core/dev.c#L4086
31+
// * Linux 4.18 https://elixir.bootlin.com/linux/v4.18/source/net/core/net-procfs.c#L162
32+
// * Linux 5.14 https://elixir.bootlin.com/linux/v5.14/source/net/core/net-procfs.c#L169
3233

3334
// SoftnetStat contains a single row of data from /proc/net/softnet_stat.
3435
type SoftnetStat struct {
@@ -38,6 +39,18 @@ type SoftnetStat struct {
3839
Dropped uint32
3940
// Number of times processing packets ran out of quota.
4041
TimeSqueezed uint32
42+
// Number of collision occur while obtaining device lock while transmitting.
43+
CPUCollision uint32
44+
// Number of times cpu woken up received_rps.
45+
ReceivedRps uint32
46+
// number of times flow limit has been reached.
47+
FlowLimitCount uint32
48+
// Softnet backlog status.
49+
SoftnetBacklogLen uint32
50+
// CPU id owning this softnet_data.
51+
Index uint32
52+
// softnet_data's Width.
53+
Width int
4154
}
4255

4356
var softNetProcFile = "net/softnet_stat"
@@ -66,22 +79,57 @@ func parseSoftnet(r io.Reader) ([]SoftnetStat, error) {
6679
for s.Scan() {
6780
columns := strings.Fields(s.Text())
6881
width := len(columns)
82+
softnetStat := SoftnetStat{}
6983

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

74-
// We only parse the first three columns at the moment.
75-
us, err := parseHexUint32s(columns[0:3])
76-
if err != nil {
77-
return nil, err
88+
// Linux 2.6.23 https://elixir.bootlin.com/linux/v2.6.23/source/net/core/dev.c#L2347
89+
if width >= minColumns {
90+
us, err := parseHexUint32s(columns[0:9])
91+
if err != nil {
92+
return nil, err
93+
}
94+
95+
softnetStat.Processed = us[0]
96+
softnetStat.Dropped = us[1]
97+
softnetStat.TimeSqueezed = us[2]
98+
softnetStat.CPUCollision = us[8]
99+
}
100+
101+
// Linux 2.6.39 https://elixir.bootlin.com/linux/v2.6.39/source/net/core/dev.c#L4086
102+
if width >= 10 {
103+
us, err := parseHexUint32s(columns[9:10])
104+
if err != nil {
105+
return nil, err
106+
}
107+
108+
softnetStat.ReceivedRps = us[0]
78109
}
79110

80-
stats = append(stats, SoftnetStat{
81-
Processed: us[0],
82-
Dropped: us[1],
83-
TimeSqueezed: us[2],
84-
})
111+
// Linux 4.18 https://elixir.bootlin.com/linux/v4.18/source/net/core/net-procfs.c#L162
112+
if width >= 11 {
113+
us, err := parseHexUint32s(columns[10:11])
114+
if err != nil {
115+
return nil, err
116+
}
117+
118+
softnetStat.FlowLimitCount = us[0]
119+
}
120+
121+
// Linux 5.14 https://elixir.bootlin.com/linux/v5.14/source/net/core/net-procfs.c#L169
122+
if width >= 13 {
123+
us, err := parseHexUint32s(columns[11:13])
124+
if err != nil {
125+
return nil, err
126+
}
127+
128+
softnetStat.SoftnetBacklogLen = us[0]
129+
softnetStat.Index = us[1]
130+
}
131+
softnetStat.Width = width
132+
stats = append(stats, softnetStat)
85133
}
86134

87135
return stats, nil

net_softnet_test.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,54 @@ func TestNetSoftnet(t *testing.T) {
2525
t.Fatal(err)
2626
}
2727

28-
want := []SoftnetStat{{
29-
Processed: 0x00015c73,
30-
Dropped: 0x00020e76,
31-
TimeSqueezed: 0xf0000769,
32-
},
28+
want := []SoftnetStat{
29+
{
30+
Processed: 0x00358fe3,
31+
Dropped: 0x00006283,
32+
TimeSqueezed: 0x00000000,
33+
CPUCollision: 0x00000000,
34+
ReceivedRps: 0x000855fc,
35+
FlowLimitCount: 0x00000076,
36+
SoftnetBacklogLen: 0x00000000,
37+
Index: 0x00000000,
38+
Width: 13,
39+
},
40+
{
41+
Processed: 0x00953d1a,
42+
Dropped: 0x00000446,
43+
TimeSqueezed: 0x000000b1,
44+
CPUCollision: 0x00000000,
45+
ReceivedRps: 0x008eeb9a,
46+
FlowLimitCount: 0x0000002b,
47+
SoftnetBacklogLen: 0x000000dc,
48+
Index: 0x00000001,
49+
Width: 13,
50+
},
51+
{
52+
Processed: 0x00015c73,
53+
Dropped: 0x00020e76,
54+
TimeSqueezed: 0xf0000769,
55+
CPUCollision: 0x00000004,
56+
ReceivedRps: 0x00000003,
57+
FlowLimitCount: 0x00000002,
58+
Width: 11,
59+
},
3360
{
3461
Processed: 0x01663fb2,
62+
Dropped: 0x00000000,
3563
TimeSqueezed: 0x0109a4,
36-
}}
64+
CPUCollision: 0x00020e76,
65+
Width: 9,
66+
},
67+
{
68+
Processed: 0x00008e78,
69+
Dropped: 0x00000001,
70+
TimeSqueezed: 0x00000011,
71+
CPUCollision: 0x00000020,
72+
ReceivedRps: 0x00000010,
73+
Width: 10,
74+
},
75+
}
3776

3877
got, err := fs.NetSoftnetStat()
3978
if err != nil {

testdata/fixtures.ttar

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,9 +2482,12 @@ FRAG6: inuse 0 memory 0
24822482
Mode: 444
24832483
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24842484
Path: fixtures/proc/net/softnet_stat
2485-
Lines: 2
2486-
00015c73 00020e76 F0000769 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
2487-
01663fb2 00000000 000109a4 00000000 00000000 00000000 00000000 00000000 00000000
2485+
Lines: 5
2486+
00358fe3 00006283 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000855fc 00000076 00000000 00000000
2487+
00953d1a 00000446 000000b1 00000000 00000000 00000000 00000000 00000000 00000000 008eeb9a 0000002b 000000dc 00000001
2488+
00015c73 00020e76 f0000769 00000000 00000000 00000000 00000000 00000000 00000004 00000003 00000002
2489+
01663fb2 00000000 000109a4 00000000 00000000 00000000 00000000 00000000 00020e76
2490+
00008e78 00000001 00000011 00000000 00000000 00000000 00000000 00000000 00000020 00000010
24882491
Mode: 644
24892492
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24902493
Path: fixtures/proc/net/softnet_stat.broken

0 commit comments

Comments
 (0)