Skip to content

Commit

Permalink
qdisc: add TCA_XSTATS stats for fq qdisc.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Kangjie Xu committed Jun 5, 2024
1 parent 4d4ba14 commit 8e1ae8a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions class_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,13 @@ func parseTcStats2(data []byte) (*ClassStatistics, error) {

return stats, nil
}

func parseTcFqXStats(data []byte) (*nl.TcFqQdStats, error) {
buf := &bytes.Buffer{}
buf.Write(data)
stats := &nl.TcFqQdStats{}
if err := binary.Read(buf, native, stats); err != nil {
return nil, err
}
return stats, nil
}
18 changes: 18 additions & 0 deletions nl/tc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,24 @@ const (
TCA_FQ_HORIZON_DROP // drop packets beyond horizon, or cap their EDT
)

type TcFqQdStats struct {
GcFlows uint64
HighPrioPackets uint64
TcpRetrans uint64
Throttled uint64
FlowsPlimit uint64
PktsTooLong uint64
AllocationErrors uint64
TimeNextDelayedFlow int64
Flows uint32
InactiveFlows uint32
ThrottledFlows uint32
UnthrottleLatencyNs uint32
CeMark uint64 // packets above ce_threshold
HorizonDrops uint64
HorizonCaps uint64
}

const (
TCA_FQ_CODEL_UNSPEC = iota
TCA_FQ_CODEL_TARGET
Expand Down
4 changes: 4 additions & 0 deletions qdisc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package netlink
import (
"fmt"
"math"

"github.com/vishvananda/netlink/nl"
)

const (
Expand Down Expand Up @@ -308,6 +310,8 @@ type Fq struct {
LowRateThreshold uint32
Horizon uint32
HorizonDropPolicy uint8

Stats *nl.TcFqQdStats

Check failure on line 314 in qdisc.go

View workflow job for this annotation

GitHub Actions / build-macos

undefined: nl.TcFqQdStats
}

func (fq *Fq) String() string {
Expand Down
10 changes: 10 additions & 0 deletions qdisc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,16 @@ func (h *Handle) QdiscList(link Link) ([]Qdisc, error) {
return nil, err
}
base.Statistics = (*QdiscStatistics)(s)
case nl.TCA_XSTATS:
switch qdisc.Type() {
case "fq":
fq := qdisc.(*Fq)
s, err := parseTcFqXStats(attr.Value)
if err != nil {
return nil, err
}
fq.Stats = s
}
}
}
*qdisc.Attrs() = base
Expand Down
4 changes: 4 additions & 0 deletions qdisc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ func TestFqHorizon(t *testing.T) {
t.Fatal("HorizonDropPolicy does not match")
}

if fq.Stats.GcFlows != 0 || fq.Stats.ThrottledFlows != 0 || fq.Stats.HorizonDrops != 0 {
t.Fatal("Stats is not zero")
}

if err := QdiscDel(qdisc); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 8e1ae8a

Please sign in to comment.