Skip to content

Commit e2e5ae4

Browse files
committed
Add basic tc_fq_qd_stats support
Add statistics specific to the fq scheduler to QdiscInfo: GcFlows, Throttled and FlowsPlimit.
1 parent 2c7e72d commit e2e5ae4

2 files changed

Lines changed: 73 additions & 19 deletions

File tree

get.go

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,35 @@ type TC_Stats2 struct {
5757
Overlimits uint32
5858
}
5959

60+
// See struct tc_fq_qd_stats /usr/include/linux/pkt_sched.h
61+
type TC_Fq_Qd_Stats struct {
62+
GcFlows uint64
63+
HighprioPackets uint64
64+
TcpRetrans uint64
65+
Throttled uint64
66+
FlowsPlimit uint64
67+
PktsTooLong uint64
68+
AllocationErrors uint64
69+
TimeNextDelayedFlow int64
70+
Flows uint32
71+
InactiveFlows uint32
72+
ThrottledFlows uint32
73+
UnthrottleLatencyNs uint32
74+
}
75+
6076
type QdiscInfo struct {
61-
IfaceName string
62-
Parent uint32
63-
Handle uint32
64-
Kind string
65-
Bytes uint64
66-
Packets uint32
67-
Drops uint32
68-
Requeues uint32
69-
Overlimits uint32
77+
IfaceName string
78+
Parent uint32
79+
Handle uint32
80+
Kind string
81+
Bytes uint64
82+
Packets uint32
83+
Drops uint32
84+
Requeues uint32
85+
Overlimits uint32
86+
GcFlows uint64
87+
Throttled uint64
88+
FlowsPlimit uint64
7089
}
7190

7291
func parseTCAStats(attr netlink.Attribute) TC_Stats {
@@ -99,7 +118,28 @@ func parseTCAStats2(attr netlink.Attribute) TC_Stats2 {
99118
stats.Requeues = nlenc.Uint32(a.Data[12:16])
100119
stats.Overlimits = nlenc.Uint32(a.Data[16:20])
101120
default:
102-
// TODO: TCA_STATS_APP
121+
}
122+
}
123+
124+
return stats
125+
}
126+
127+
func parseTC_Fq_Qd_Stats(attr netlink.Attribute) TC_Fq_Qd_Stats {
128+
var stats TC_Fq_Qd_Stats
129+
130+
nested, _ := netlink.UnmarshalAttributes(attr.Data)
131+
132+
for _, a := range nested {
133+
switch a.Type {
134+
case TCA_STATS_APP:
135+
stats.GcFlows = nlenc.Uint64(a.Data[0:8])
136+
stats.HighprioPackets = nlenc.Uint64(a.Data[8:16])
137+
stats.TcpRetrans = nlenc.Uint64(a.Data[16:24])
138+
stats.Throttled = nlenc.Uint64(a.Data[24:32])
139+
stats.FlowsPlimit = nlenc.Uint64(a.Data[32:40])
140+
stats.PktsTooLong = nlenc.Uint64(a.Data[40:48])
141+
stats.AllocationErrors = nlenc.Uint64(a.Data[48:56])
142+
default:
103143
}
104144
}
105145

@@ -129,6 +169,7 @@ func parseMessage(msg netlink.Message) (QdiscInfo, error) {
129169
var m QdiscInfo
130170
var s TC_Stats
131171
var s2 TC_Stats2
172+
var s_fq TC_Fq_Qd_Stats
132173

133174
/*
134175
struct tcmsg {
@@ -168,6 +209,16 @@ func parseMessage(msg netlink.Message) (QdiscInfo, error) {
168209
m.Kind = nlenc.String(attr.Data)
169210
case TCA_STATS2:
170211
s2 = parseTCAStats2(attr)
212+
s_fq = parseTC_Fq_Qd_Stats(attr)
213+
if s_fq.GcFlows > 0 {
214+
m.GcFlows = s_fq.GcFlows
215+
}
216+
if s_fq.Throttled > 0 {
217+
m.Throttled = s_fq.Throttled
218+
}
219+
if s_fq.FlowsPlimit > 0 {
220+
m.FlowsPlimit = s_fq.FlowsPlimit
221+
}
171222
m.Bytes = s2.Bytes
172223
m.Packets = s2.Packets
173224
m.Drops = s2.Drops

get_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,18 @@ func TestGetAndParseOK(t *testing.T) {
7575

7676
expect := []QdiscInfo{
7777
{
78-
IfaceName: "lo",
79-
Parent: 0,
80-
Handle: 2147549184,
81-
Kind: "fq",
82-
Bytes: 258943627,
83-
Packets: 1985695,
84-
Drops: 0,
85-
Requeues: 22,
86-
Overlimits: 0,
78+
IfaceName: "lo",
79+
Parent: 0,
80+
Handle: 2147549184,
81+
Kind: "fq",
82+
Bytes: 258943627,
83+
Packets: 1985695,
84+
Drops: 0,
85+
Requeues: 22,
86+
Overlimits: 0,
87+
GcFlows: 24957,
88+
Throttled: 13515,
89+
FlowsPlimit: 0,
8790
},
8891
}
8992

0 commit comments

Comments
 (0)