Skip to content

Commit c4bbdd7

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 c4bbdd7

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-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+
}

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)