Skip to content

Commit 8e1ae8a

Browse files
author
Kangjie Xu
committed
qdisc: add TCA_XSTATS stats for fq qdisc.
When using fq, we rely on xstats useful metrics to check fq behavior and diangosis, it is what can be seen from iproute2 tools, `tc -s qdisc show` as well. It exposes metrics as: https://github.com/iproute2/iproute2/blob/main/include/uapi/linux/pkt_sched.h#L847 Signed-off-by: Kangjie Xu <[email protected]>
1 parent 4d4ba14 commit 8e1ae8a

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

class_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,13 @@ func parseTcStats2(data []byte) (*ClassStatistics, error) {
398398

399399
return stats, nil
400400
}
401+
402+
func parseTcFqXStats(data []byte) (*nl.TcFqQdStats, error) {
403+
buf := &bytes.Buffer{}
404+
buf.Write(data)
405+
stats := &nl.TcFqQdStats{}
406+
if err := binary.Read(buf, native, stats); err != nil {
407+
return nil, err
408+
}
409+
return stats, nil
410+
}

nl/tc_linux.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,24 @@ const (
954954
TCA_FQ_HORIZON_DROP // drop packets beyond horizon, or cap their EDT
955955
)
956956

957+
type TcFqQdStats struct {
958+
GcFlows uint64
959+
HighPrioPackets uint64
960+
TcpRetrans uint64
961+
Throttled uint64
962+
FlowsPlimit uint64
963+
PktsTooLong uint64
964+
AllocationErrors uint64
965+
TimeNextDelayedFlow int64
966+
Flows uint32
967+
InactiveFlows uint32
968+
ThrottledFlows uint32
969+
UnthrottleLatencyNs uint32
970+
CeMark uint64 // packets above ce_threshold
971+
HorizonDrops uint64
972+
HorizonCaps uint64
973+
}
974+
957975
const (
958976
TCA_FQ_CODEL_UNSPEC = iota
959977
TCA_FQ_CODEL_TARGET

qdisc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package netlink
33
import (
44
"fmt"
55
"math"
6+
7+
"github.com/vishvananda/netlink/nl"
68
)
79

810
const (
@@ -308,6 +310,8 @@ type Fq struct {
308310
LowRateThreshold uint32
309311
Horizon uint32
310312
HorizonDropPolicy uint8
313+
314+
Stats *nl.TcFqQdStats
311315
}
312316

313317
func (fq *Fq) String() string {

qdisc_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,16 @@ func (h *Handle) QdiscList(link Link) ([]Qdisc, error) {
488488
return nil, err
489489
}
490490
base.Statistics = (*QdiscStatistics)(s)
491+
case nl.TCA_XSTATS:
492+
switch qdisc.Type() {
493+
case "fq":
494+
fq := qdisc.(*Fq)
495+
s, err := parseTcFqXStats(attr.Value)
496+
if err != nil {
497+
return nil, err
498+
}
499+
fq.Stats = s
500+
}
491501
}
492502
}
493503
*qdisc.Attrs() = base

qdisc_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,10 @@ func TestFqHorizon(t *testing.T) {
515515
t.Fatal("HorizonDropPolicy does not match")
516516
}
517517

518+
if fq.Stats.GcFlows != 0 || fq.Stats.ThrottledFlows != 0 || fq.Stats.HorizonDrops != 0 {
519+
t.Fatal("Stats is not zero")
520+
}
521+
518522
if err := QdiscDel(qdisc); err != nil {
519523
t.Fatal(err)
520524
}

0 commit comments

Comments
 (0)