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 c4bbdd7
Show file tree
Hide file tree
Showing 4 changed files with 28 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) {

Check failure on line 402 in class_linux.go

View workflow job for this annotation

GitHub Actions / build

undefined: nl.TcFqQdStats
buf := &bytes.Buffer{}
buf.Write(data)
stats := &nl.TcFqQdStats{}

Check failure on line 405 in class_linux.go

View workflow job for this annotation

GitHub Actions / build

undefined: nl.TcFqQdStats
if err := binary.Read(buf, native, stats); err != nil {
return nil, err
}
return stats, nil
}
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

Check failure on line 314 in qdisc.go

View workflow job for this annotation

GitHub Actions / build

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 c4bbdd7

Please sign in to comment.