Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 24 additions & 1 deletion docs/netlink/gotc-status.md

Large diffs are not rendered by default.

228 changes: 228 additions & 0 deletions docs/netlink/upstream/iproute2-tc-sched.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/gotc/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (r *runner) rtrealmN2A(id int32) string {
}
t := &r.realms
if !t.inited && t.names[0] == "" {
t.names[0] = "unknown"
t.names[0] = wordUnknown
}
if t.names[id] == "" && !t.inited {
t.inited = true
Expand Down
9 changes: 9 additions & 0 deletions internal/gotc/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ func (r *runner) printClassBody(m Msg, ti *xtcpnl.TcInfo, q *qdiscUtil) error {
if hasAttr(ti.Attrs, xtcpnl.TcaOptions) {
if q.printCopt != nil {
q.printCopt(r, q, ti.Options, true)
if err := r.takeKindErr(); err != nil {
return err
}
} else {
r.errf("[cannot parse class parameters]")
}
Expand All @@ -253,6 +256,9 @@ func (r *runner) printClassBody(m Msg, ti *xtcpnl.TcInfo, q *qdiscUtil) error {
}
if hasX && q.printXstats != nil {
q.printXstats(r, xs)
if err := r.takeKindErr(); err != nil {
return err
}
o.fp("\n")
}
o.closeObject()
Expand Down Expand Up @@ -347,6 +353,9 @@ func (r *runner) graphNodeShow(buf *strings.Builder, cls *graphNode) {
}
if q != nil && q.printCopt != nil {
q.printCopt(r, q, tb.Bytes(xtcpnl.TcaOptions), tb.Has(xtcpnl.TcaOptions))
if err := r.takeKindErr(); err != nil && r.cf.err == nil {
r.cf.err = err
}
}
if q != nil && r.stats > 0 {
r.graphStats(buf, cls, q, id, tb)
Expand Down
4 changes: 3 additions & 1 deletion internal/gotc/corpus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
// corpusRows is how many rows each space holds (V002).
var corpusRows = map[string]int{
"tcqdisc": 142, "tcclass": 82, "tcfilter": 159, "tcflower": 97, "tcaction": 138, "tcaction2": 105,
"tcsched": 87,
}

// corpusKnown are the rows gotc cannot match byte for byte, each with the
Expand All @@ -39,6 +40,7 @@ var corpusRefused = map[string]string{
var corpusWrites = map[string]bool{
"tcqdisc/ng-018": true, "tcclass/ng-011": true, "tcfilter/ng-024": true, "tcflower/ng-009": true,
"tcaction/ng-006": true, "tcaction2/ng-007": true,
"tcsched/ng-001": true, "tcsched/ng-002": true, "tcsched/ng-003": true, "tcsched/ng-004": true,
}

// pschedRow is the one row that reads the workbench's /proc/net/psched
Expand Down Expand Up @@ -187,7 +189,7 @@ func TestGotcCorpus(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for _, sp := range []string{"tcclass", "tcfilter", "tcflower", "tcaction", "tcaction2"} {
for _, sp := range []string{"tcclass", "tcfilter", "tcflower", "tcaction", "tcaction2", "tcsched"} {
more, err := filepath.Glob("../../pkg/xtcpnl/testdata/*/ws/" + sp)
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 2 additions & 0 deletions internal/gotc/gotc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type runner struct {
cf classFilter // tc_class.c's statics, kept across batch lines (Q30)
ff filterFilter // tc_filter.c's statics, kept across batch lines (Q29f)

kindErr error // a qdisc_util printer's refusal; see refuseKind

timestamp int // timestamp: -timestamp and -tshort each add one
tshort int // timestamp_short: -tshort
now func() time.Time // the monitor's clock (GOTC_NOW for a replay)
Expand Down
94 changes: 94 additions & 0 deletions internal/gotc/q_ets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package gotc

import (
"github.com/randomizedcoder/xtcp2/pkg/xtcpnl"
)

// tc/q_ets.c (iproute2 v7.2.0).

// printEtsOpt is ets_print_opt: NBANDS and PRIOMAP required ("Incomplete
// ETS options"), NSTRICT only when the kernel sends it, QUANTA only when
// some band is not strict (K25). A failed list leaves its JSON array open,
// as tc's `return -1` does (Q47).
func printEtsOpt(r *runner, _ *qdiscUtil, opt []byte, has bool) {
if !has {
return
}
tb := r.nested(opt, xtcpnl.TcaEtsMaxKnown)
if !tb.Has(xtcpnl.TcaEtsNbands) || !tb.Has(xtcpnl.TcaEtsPriomap) {
r.errf("Incomplete ETS options\n")
return
}
o := r.o
if !r.kindNeed(xtcpnl.TcKindEts, "nbands", tb.Bytes(xtcpnl.TcaEtsNbands), 1) {
return
}
nb, _ := tb.U8(xtcpnl.TcaEtsNbands)
o.uint(printAny, "bands", "bands "+u32s(uint32(nb))+" ", uint32(nb))
if tb.Has(xtcpnl.TcaEtsNstrict) {
if !r.kindNeed(xtcpnl.TcKindEts, "nstrict", tb.Bytes(xtcpnl.TcaEtsNstrict), 1) {
return
}
ns, _ := tb.U8(xtcpnl.TcaEtsNstrict)
o.uint(printAny, "strict", "strict "+u32s(uint32(ns))+" ", uint32(ns))
}
if tb.Has(xtcpnl.TcaEtsQuanta) {
if !r.etsList(tb.Bytes(xtcpnl.TcaEtsQuanta), "quanta", xtcpnl.TcaEtsQuantaBand, 4, 0, "No ETS band quantum") {
return
}
}
r.etsList(tb.Bytes(xtcpnl.TcaEtsPriomap), "priomap", xtcpnl.TcaEtsPriomapBand, 1, 3, "No ETS priomap band")
}

// etsList is ets_print_opt_quanta and ets_print_opt_priomap: at each
// offset, parse_rtattr from there to the end, the first band attribute
// printed as " %u", and the offset stepped by the rta_len there plus pad;
// the array closes with a text " " (Q45). No band attribute at an offset
// is tc's message and `return -1`, the array left open; ok is false then
// or after a refusal.
func (r *runner) etsList(b []byte, name string, band uint16, width, pad int, missing string) bool {
o := r.o
o.openArray(printAny, name)
for off := 0; off < len(b); {
tb := r.attrTable(b[off:], xtcpnl.TcaEtsMaxKnown, 0)
// The step reads the rta_len at the offset; with fewer than two
// bytes left that is past the list, but the missing band below
// returns before the offset is used again.
step := int(attrLenAt(b, off)) + pad
if !tb.Has(band) {
r.errf("%s\n", missing)
return false
}
if !r.kindNeed(xtcpnl.TcKindEts, name, tb.Bytes(band), width) {
return false
}
var v uint32
if width == 4 {
v, _ = tb.U32(band)
} else {
u, _ := tb.U8(band)
v = uint32(u)
}
o.uint(printAny, "", " "+u32s(v), v)
off += step
}
o.closeArray(printAny, " ")
return true
}

// printEtsCopt is ets_print_copt: a class's quantum, absent for a strict
// band, whose nest the kernel sends empty (Q46, K25).
func printEtsCopt(r *runner, _ *qdiscUtil, opt []byte, has bool) {
if !has {
return
}
tb := r.nested(opt, xtcpnl.TcaEtsMaxKnown)
if !tb.Has(xtcpnl.TcaEtsQuantaBand) {
return
}
if !r.kindNeed(xtcpnl.TcKindEts, "quantum", tb.Bytes(xtcpnl.TcaEtsQuantaBand), 4) {
return
}
v, _ := tb.U32(xtcpnl.TcaEtsQuantaBand)
r.o.uint(printAny, "quantum", "quantum "+u32s(v)+" ", v)
}
104 changes: 104 additions & 0 deletions internal/gotc/q_hfsc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package gotc

import (
"bytes"

"github.com/randomizedcoder/xtcp2/pkg/xtcpnl"
)

// tc/q_hfsc.c (iproute2 v7.2.0).

// printHfscOpt is hfsc_print_opt: the default class through print_0xhex
// with a leading space, so text has two spaces after `refcnt N`, JSON a
// string, and nothing at 0 (Q40). Nothing for a short struct.
func printHfscOpt(r *runner, _ *qdiscUtil, opt []byte, has bool) {
if !has {
return
}
q, err := xtcpnl.DecodeTcHfscQopt(opt)
if err != nil {
return
}
if q.Defcls != 0 {
d := uint64(q.Defcls)
r.o.hex0x(printAny, "default", " default "+cHashX(d)+" ", d)
}
}

// printHfscXstats is hfsc_print_xstats: work and rtwork only when nonzero
// (Q41), then a text-only _SL_ that, with print_class's own newline, leaves
// a blank line (Q42). Nothing for a short payload.
func printHfscXstats(r *runner, xs []byte) {
st, err := xtcpnl.DecodeTcHfscStats(xs)
if err != nil {
return
}
o := r.o
o.uint(printAny, "period", " period "+u32s(st.Period)+" ", st.Period)
if st.Work != 0 {
o.u64(printAny, "work", "work "+u64s(st.Work)+" bytes ", st.Work)
}
if st.Rtwork != 0 {
o.u64(printAny, "rtwork", "rtwork "+u64s(st.Rtwork)+" bytes ", st.Rtwork)
}
o.uint(printAny, "level", " level "+u32s(st.Level)+" ", st.Level)
o.fp(o.sl)
}

// hfscCurve is one class curve as hfsc_print_class_opt takes it: the
// payload when it holds a whole struct, nil otherwise.
func (r *runner) hfscCurve(tb xtcpnl.AttrTable, t uint16, name string) []byte {
if !tb.Has(t) {
return nil
}
b := tb.Bytes(t)
if len(b) < xtcpnl.TcServiceCurveSizeCst {
r.errf("HFSC: truncated %s option\n", name)
return nil
}
return b[:xtcpnl.TcServiceCurveSizeCst]
}

// printHfscClassOpt is hfsc_print_class_opt: rt and ls are one `sc` when
// their bytes match (Q43), and ul follows. A truncated curve is warned
// about and skipped.
func printHfscClassOpt(r *runner, _ *qdiscUtil, opt []byte, has bool) {
if !has {
return
}
tb := r.nested(opt, xtcpnl.TcaHfscMaxKnown)
rsc := r.hfscCurve(tb, xtcpnl.TcaHfscRsc, "realtime")
fsc := r.hfscCurve(tb, xtcpnl.TcaHfscFsc, "linkshare")
usc := r.hfscCurve(tb, xtcpnl.TcaHfscUsc, "upperlimit")
if rsc != nil && fsc != nil && bytes.Equal(rsc, fsc) {
r.hfscSc("sc", rsc)
} else {
if rsc != nil {
r.hfscSc("rt", rsc)
}
if fsc != nil {
r.hfscSc("ls", fsc)
}
}
if usc != nil {
r.hfscSc("ul", usc)
}
}

// hfscSc is hfsc_print_sc: d through tc_core_ktime2time, sprint_time in
// text and the number in JSON (Q44).
func (r *runner) hfscSc(name string, b []byte) {
sc, err := xtcpnl.DecodeTcServiceCurve(b)
if err != nil {
return
}
d := cDoubleToU32(float64(sc.D) / r.core.clockFactor)
o := r.o
o.openObject(name)
o.fp(name + " ")
o.rate(r.iec > 0, printAny, "m1", "m1 ", " ", uint64(sc.M1))
o.fp("d " + sprintTime(d) + " ")
o.uint(printJSON, "d", "", d)
o.rate(r.iec > 0, printAny, "m2", "m2 ", " ", uint64(sc.M2))
o.closeObject()
}
Loading