FQ-PIE schedules independent PIE controllers per flow but exposes no per-flow AQM state. Without class-level statistics there is no way to observe the per-flow drop probability, queue delay, deficit or dequeue rate from userspace. Extend tc_fq_pie_xstats with a type discriminator and tc_fq_pie_cl_stats for per-flow metrics. The nine existing __u32 counters keep their offsets, type is appended at offset 36 and class_stats follows it, growing the structure from 36 to 64 bytes. Wire up fq_pie_class_ops with walk, dump, and dump_stats only so that 'tc -s class show' reports per-flow state (prob, delay, deficit, avg_dq_rate - the last if dq_rate_estimating is enabled). leaf and find are also added, but as required stubs. Filter attachment callbacks (.tcf_block, .bind_tcf, .unbind_tcf) are omitted. Used WRITE_ONCE() macro to guard following variables: - deficit - qlen - backlog - vars.accu_prob The changes here have a companion iproute2 change, "tc: fq_pie: add support for printing per-flow PIE statistics". Signed-off-by: Hemendra M. Naik Signed-off-by: Vishal Kamath Signed-off-by: Mohit P. Tahiliani --- include/uapi/linux/pkt_sched.h | 17 ++++++ net/sched/sch_fq_pie.c | 108 +++++++++++++++++++++++++++++---- 2 files changed, 114 insertions(+), 11 deletions(-) diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h index 490efd288526..fef848eaaab2 100644 --- a/include/uapi/linux/pkt_sched.h +++ b/include/uapi/linux/pkt_sched.h @@ -953,6 +953,21 @@ enum { }; #define TCA_FQ_PIE_MAX (__TCA_FQ_PIE_MAX - 1) +enum { + TCA_FQ_PIE_XSTATS_QDISC, + TCA_FQ_PIE_XSTATS_CLASS, +}; + +struct tc_fq_pie_cl_stats { + __u64 prob; /* current probability */ + __u32 delay; /* current delay in microseconds */ + __s32 deficit; /* number of remaining byte credits */ + __u32 avg_dq_rate; /* current average dq_rate in + * bytes/second + */ + __u32 dq_rate_estimating; /* is avg_dq_rate being calculated? */ +}; + struct tc_fq_pie_xstats { __u32 packets_in; /* total number of packets enqueued */ __u32 dropped; /* packets dropped due to fq_pie_action */ @@ -963,6 +978,8 @@ struct tc_fq_pie_xstats { __u32 new_flows_len; /* count of flows in new list */ __u32 old_flows_len; /* count of flows in old list */ __u32 memory_usage; /* total memory across all queues */ + __u32 type; + struct tc_fq_pie_cl_stats class_stats; }; /* CBS */ diff --git a/net/sched/sch_fq_pie.c b/net/sched/sch_fq_pie.c index 5982847df8f8..d66fd56bfaed 100644 --- a/net/sched/sch_fq_pie.c +++ b/net/sched/sch_fq_pie.c @@ -190,17 +190,17 @@ static int fq_pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch, if (list_empty(&sel_flow->flowchain)) { list_add_tail(&sel_flow->flowchain, &q->new_flows); q->new_flow_count++; - sel_flow->deficit = q->quantum; - sel_flow->qlen = 0; - sel_flow->backlog = 0; + WRITE_ONCE(sel_flow->deficit, q->quantum); + WRITE_ONCE(sel_flow->qlen, 0); + WRITE_ONCE(sel_flow->backlog, 0); } - sel_flow->qlen++; - sel_flow->backlog += pkt_len; + WRITE_ONCE(sel_flow->qlen, sel_flow->qlen + 1); + WRITE_ONCE(sel_flow->backlog, sel_flow->backlog + pkt_len); return NET_XMIT_SUCCESS; } out: q->stats.dropped++; - sel_flow->vars.accu_prob = 0; + WRITE_ONCE(sel_flow->vars.accu_prob, 0); qdisc_drop_reason(skb, sch, to_free, reason); return NET_XMIT_CN; } @@ -254,7 +254,7 @@ static struct sk_buff *fq_pie_qdisc_dequeue(struct Qdisc *sch) flow = list_first_entry(head, struct fq_pie_flow, flowchain); /* Flow has exhausted all its credits */ if (flow->deficit <= 0) { - flow->deficit += q->quantum; + WRITE_ONCE(flow->deficit, flow->deficit + q->quantum); list_move_tail(&flow->flowchain, &q->old_flows); goto begin; } @@ -276,9 +276,9 @@ static struct sk_buff *fq_pie_qdisc_dequeue(struct Qdisc *sch) goto begin; } - flow->qlen--; - flow->deficit -= pkt_len; - flow->backlog -= pkt_len; + WRITE_ONCE(flow->qlen, flow->qlen - 1); + WRITE_ONCE(flow->deficit, flow->deficit - pkt_len); + WRITE_ONCE(flow->backlog, flow->backlog - pkt_len); q->memory_usage -= get_pie_cb(skb)->mem_usage; pie_process_dequeue(skb, &q->p_params, &flow->vars, flow->backlog); return skb; @@ -511,7 +511,11 @@ static int fq_pie_dump(struct Qdisc *sch, struct sk_buff *skb) static int fq_pie_dump_stats(struct Qdisc *sch, struct gnet_dump *d) { struct fq_pie_sched_data *q = qdisc_priv(sch); - struct tc_fq_pie_xstats st = { 0 }; + + struct tc_fq_pie_xstats st = { + .type = TCA_FQ_PIE_XSTATS_QDISC, + }; + struct list_head *pos; sch_tree_lock(sch); @@ -563,7 +567,89 @@ static void fq_pie_destroy(struct Qdisc *sch) kvfree(q->flows); } +static struct Qdisc *fq_pie_leaf(struct Qdisc *sch, unsigned long arg) +{ + return NULL; +} + +static unsigned long fq_pie_find(struct Qdisc *sch, u32 classid) +{ + return 0; +} + +static int fq_pie_dump_class(struct Qdisc *sch, unsigned long cl, + struct sk_buff *skb, struct tcmsg *tcm) +{ + tcm->tcm_handle |= TC_H_MIN(cl); + return 0; +} + +static int fq_pie_dump_class_stats(struct Qdisc *sch, unsigned long cl, + struct gnet_dump *d) +{ + struct fq_pie_sched_data *q = qdisc_priv(sch); + struct gnet_stats_queue qs = { 0 }; + struct tc_fq_pie_xstats xstats; + u32 idx = cl - 1; + + if (idx < q->flows_cnt) { + const struct fq_pie_flow *flow = &q->flows[idx]; + + memset(&xstats, 0, sizeof(xstats)); + xstats.type = TCA_FQ_PIE_XSTATS_CLASS; + xstats.class_stats.prob = + READ_ONCE(flow->vars.prob) << BITS_PER_BYTE; + xstats.class_stats.delay = + div_u64(PSCHED_TICKS2NS(READ_ONCE(flow->vars.qdelay)), + NSEC_PER_USEC); + xstats.class_stats.deficit = READ_ONCE(flow->deficit); + xstats.class_stats.dq_rate_estimating = + READ_ONCE(q->p_params.dq_rate_estimator); + + if (xstats.class_stats.dq_rate_estimating) { + xstats.class_stats.avg_dq_rate = + ((u64)READ_ONCE(flow->vars.avg_dq_rate) + * PSCHED_TICKS_PER_SEC) >> PIE_SCALE; + } + + qs.qlen = READ_ONCE(flow->qlen); + qs.backlog = READ_ONCE(flow->backlog); + } + if (gnet_stats_copy_queue(d, NULL, &qs, qs.qlen) < 0) + return -1; + if (idx < q->flows_cnt) + return gnet_stats_copy_app(d, &xstats, sizeof(xstats)); + return 0; +} + +static void fq_pie_walk(struct Qdisc *sch, struct qdisc_walker *arg) +{ + struct fq_pie_sched_data *q = qdisc_priv(sch); + unsigned int i; + + if (arg->stop) + return; + + for (i = 0; i < q->flows_cnt; i++) { + if (list_empty(&q->flows[i].flowchain)) { + arg->count++; + continue; + } + if (!tc_qdisc_stats_dump(sch, i + 1, arg)) + break; + } +} + +static const struct Qdisc_class_ops fq_pie_class_ops = { + .leaf = fq_pie_leaf, + .find = fq_pie_find, + .dump = fq_pie_dump_class, + .dump_stats = fq_pie_dump_class_stats, + .walk = fq_pie_walk, +}; + static struct Qdisc_ops fq_pie_qdisc_ops __read_mostly = { + .cl_ops = &fq_pie_class_ops, .id = "fq_pie", .priv_size = sizeof(struct fq_pie_sched_data), .enqueue = fq_pie_qdisc_enqueue, -- 2.43.0 Add tc-testing case 83c0: build a TBF + fq_pie hierarchy on $DUMMY, push traffic through it with ping, and verify that 'tc -s class show' reports an fq_pie class. The per-flow counters themselves (prob, delay, deficit) are printed with the companion iproute2 change, "tc: fq_pie: add support for printing per-flow PIE statistics" Signed-off-by: Hemendra M. Naik Signed-off-by: Vishal Kamath Signed-off-by: Mohit P. Tahiliani --- .../tc-testing/tc-tests/qdiscs/fq_pie.json | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/fq_pie.json b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/fq_pie.json index 229fe1bf4a90..15b2667285eb 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/fq_pie.json +++ b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/fq_pie.json @@ -40,5 +40,32 @@ "matchPattern": "qdisc fq_pie 1: root refcnt [0-9]+ limit 1p", "matchCount": "1", "teardown": ["$TC qdisc del dev $DEV1 handle 1: root"] + }, + { + "id": "83c0", + "name": "FQ-PIE class stats accessible via tc class show", + "category": [ + "qdisc", + "fq_pie" + ], + "plugins": { + "requires": "nsPlugin" + }, + "setup": [ + "$IP link set dev $DUMMY up || true", + "$IP addr add 10.10.11.10/24 dev $DUMMY || true", + "$TC qdisc add dev $DUMMY root handle 1: tbf rate 8bit burst 100b latency 100ms", + "$TC qdisc add dev $DUMMY parent 1:1 handle 2: fq_pie limit 100 flows 1", + "ping -c 50 -i 0.001 -W 0.01 -s 56 10.10.11.11 -I $DUMMY > /dev/null 2>&1 || true" + ], + "cmdUnderTest": "$TC -s class show dev $DUMMY", + "expExitCode": "0", + "verifyCmd": "$TC -s class show dev $DUMMY", + "matchPattern": "class fq_pie 2:[0-9]+ .*prob .*delay .*deficit", + "matchCount": "1", + "teardown": [ + "$TC qdisc del dev $DUMMY handle 1: root", + "$IP addr del 10.10.11.10/24 dev $DUMMY || true" + ] } ] -- 2.34.1 The comments describing struct tc_pie_xstats do not match the values exported by the kernel. Update the delay field comment to microseconds (PSCHED_TICKS2NS() / NSEC_PER_USEC). Update avg_dq_rate to bytes/second (avg_dq_rate * PSCHED_TICKS_PER_SEC >> PIE_SCALE). Documentation-only; no UAPI layout or runtime change. Touch include/uapi/linux/pkt_sched.h only Signed-off-by: Hemendra M. Naik Signed-off-by: Vishal Kamath Signed-off-by: Mohit P. Tahiliani --- include/uapi/linux/pkt_sched.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h index fef848eaaab2..445a041cd103 100644 --- a/include/uapi/linux/pkt_sched.h +++ b/include/uapi/linux/pkt_sched.h @@ -920,9 +920,9 @@ enum { struct tc_pie_xstats { __u64 prob; /* current probability */ - __u32 delay; /* current delay in ms */ + __u32 delay; /* current delay in microseconds */ __u32 avg_dq_rate; /* current average dq_rate in - * bits/pie_time + * bytes/second */ __u32 dq_rate_estimating; /* is avg_dq_rate being calculated? */ __u32 packets_in; /* total number of packets enqueued */ -- 2.34.1 Add the tc-fq-pie-cl-stats header for fq_pie per flow (class) stats in Documentation/netlink/specs/tc.yaml with its five fields: - prob - delay - deficit - avg-dq-rate - dq-rate-estimating Extend the tc-fq-pie-xstats fixed header with the type discriminator and the per-flow class_stats fields that follow the nine legacy __u32 qdisc counters in struct tc_fq_pie_xstats. Update the tc-pie-xstats delay, avg_dq_rate member comments to show units as microseconds, bytes/second respectively. Signed-off-by: Hemendra M. Naik Signed-off-by: Vishal Kamath Signed-off-by: Mohit P. Tahiliani --- Documentation/netlink/specs/tc.yaml | 56 +++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/Documentation/netlink/specs/tc.yaml b/Documentation/netlink/specs/tc.yaml index b6ccc645b0e3..ff71042e31c1 100644 --- a/Documentation/netlink/specs/tc.yaml +++ b/Documentation/netlink/specs/tc.yaml @@ -894,6 +894,31 @@ definitions: name: memory-limit type: u32 doc: Memory limit in bytes + - + name: tc-fq-pie-cl-stats + type: struct + members: + - + name: prob + type: u64 + doc: Current drop probability of the flow, scaled as an unsigned + 64-bit fixed-point fraction over [0, U64_MAX] (class dumps only) + - + name: delay + type: u32 + doc: Current queue delay of the flow in microseconds (class dumps only) + - + name: deficit + type: s32 + doc: Number of remaining byte credits (class dumps only) + - + name: avg-dq-rate + type: u32 + doc: Current average dq_rate in bytes/second (class dumps only) + - + name: dq-rate-estimating + type: u32 + doc: Is avg-dq-rate being calculated? (class dumps only) - name: tc-fq-pie-xstats type: struct @@ -901,39 +926,48 @@ definitions: - name: packets-in type: u32 - doc: Total number of packets enqueued + doc: Total number of packets enqueued (qdisc dumps only) - name: dropped type: u32 - doc: Packets dropped due to fq_pie_action + doc: Packets dropped due to fq_pie_action (qdisc dumps only) - name: overlimit type: u32 - doc: Dropped due to lack of space in queue + doc: Dropped due to lack of space in queue (qdisc dumps only) - name: overmemory type: u32 - doc: Dropped due to lack of memory in queue + doc: Dropped due to lack of memory in queue (qdisc dumps only) - name: ecn-mark type: u32 - doc: Packets marked with ECN + doc: Packets marked with ECN (qdisc dumps only) - name: new-flow-count type: u32 - doc: Count of new flows created by packets + doc: Count of new flows created by packets (qdisc dumps only) - name: new-flows-len type: u32 - doc: Count of flows in new list + doc: Count of flows in new list (qdisc dumps only) - name: old-flows-len type: u32 - doc: Count of flows in old list + doc: Count of flows in old list (qdisc dumps only) - name: memory-usage type: u32 - doc: Total memory across all queues + doc: Total memory across all queues (qdisc dumps only) + - + name: type + type: u32 + doc: TCA_FQ_PIE_XSTATS_QDISC (0) or TCA_FQ_PIE_XSTATS_CLASS (1) + - + name: class-stats + type: binary + struct: tc-fq-pie-cl-stats + doc: Class statistics of a particular flow (invoked via tc class show) - name: tc-fq-qd-stats type: struct @@ -1032,11 +1066,11 @@ definitions: - name: delay type: u32 - doc: Current delay in ms + doc: Current delay in microseconds - name: avg-dq-rate type: u32 - doc: Current average dq rate in bits/pie-time + doc: Current average dq rate in bytes/second - name: dq-rate-estimating type: u32 -- 2.34.1