Skip to contentSkip to conversation

net/sched: sch_fq_pie: add per-flow class statistics

PATCH Superseded Hemendra M. Naik 2 participants 6 messages Jul 27 – Sep 1

Subsystems (4)

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v4 cover net/sched: sch_fq_pie: add per-flow class statistics

FQ-PIE runs an independent PIE controller per flow but exposes no per-flow statistics. This series wires up fq_pie_class_ops to expose per-flow AQM state (prob, delay, deficit, avg_dq_rate) via 'tc -s class show', following a similar pattern as FQ-CoDel.
---
Changelog:

v4:
- Fixed unaligned commit message; moved typo fixes to another patch.

v3: https://lore.kernel.org/netdev/[email protected]/
- No changes since v2.
- Resent after the previous submission was deferred due to the net-next tree closing during review.
- Updated corresponding iproute2 patch in response to review comments; kernel patches unchanged.

v2: https://lore.kernel.org/netdev/[email protected]/
- Addressed ABI backward compatibility issue for tc_fq_pie_xstats.

v1: https://lore.kernel.org/netdev/[email protected]/
- Initial submission

Hemendra M. Naik (3):
net/sched: sch_fq_pie: add per-flow statistics via class ops
selftests: tc-testing: add fq_pie per-flow class stats test net/sched: pie: correct tc_pie_xstats field documentation

 include/uapi/linux/pkt_sched.h                |  29 ++++-
 net/sched/sch_fq_pie.c                        | 109 +++++++++++++++++-
 tools/include/uapi/linux/pkt_sched.h          |   4 +-
 .../tc-testing/tc-tests/qdiscs/fq_pie.json    |  22 ++++
 4 files changed, 159 insertions(+), 5 deletions(-)

--
2.34.1

#1 lore raw

PATCH v4 1/3 net/sched: sch_fq_pie: add per-flow statistics via class ops

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 to support both qdisc and class-level extended statistics.

- Add enum with QDISC and CLASS type discriminators.
- Add struct tc_fq_pie_cl_stats for per-flow metrics (prob, delay, deficit, avg_dq_rate, dq_rate_estimating).
- Add empty struct tc_fq_pie_xqd_stats placeholder.

Wire up fq_pie_class_ops (.walk, .dump, .dump_stats) so that 'tc -s class show' against an fq_pie qdisc reports per-flow state:

  prob               per-flow PIE drop probability
  delay              per-flow queue sojourn time (microseconds)
  deficit            remaining DRR byte credits (signed integer)
  avg_dq_rate        dequeue rate estimate in bytes/second

(dq_rate_estimator mode only)
dq_rate_estimating flag indicating whether avg_dq_rate
is being calculated

---
 include/uapi/linux/pkt_sched.h |  25 ++++++++
 net/sched/sch_fq_pie.c         | 109 ++++++++++++++++++++++++++++++++-
 2 files changed, 133 insertions(+), 1 deletion(-)
include/uapi/linux/pkt_sched.h +25 -0
index 490efd288526..9a86fa4d6846 100644
@@ -953,6 +953,25 @@ 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_xqd_stats {
+	/* placeholder for new qdisc-level stats */
+};
+
 struct tc_fq_pie_xstats {
 	__u32 packets_in;	/* total number of packets enqueued */
 	__u32 dropped;		/* packets dropped due to fq_pie_action */
@@ -963,6 +982,12 @@ 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;
+	union {
+		struct tc_fq_pie_cl_stats class_stats;
+		struct tc_fq_pie_xqd_stats xqdisc_stats;
+	};
+
 };
 
 /* CBS */
net/sched/sch_fq_pie.c +108 -1

122 lines not on this page · raw message

--
2.34.1

reviewer
#2 lore raw

Re: [PATCH net-next v4 1/3] net/sched: sch_fq_pie: add per-flow statistics via class ops

On Mon, Jul 27, 2026 at 10:10:54PM +0530, Hemendra M. Naik wrote:

...

net/sched/sch_fq_pie.c static void fq_pie_destroy(struct Qdisc *sch) · line 594

Quoted 9 lines
net/sched/sch_fq_pie.c +9 -0
+static struct tcf_block *fq_pie_tcf_block(struct Qdisc *sch, unsigned long cl,
+					  struct netlink_ext_ack *extack)
+{
+	struct fq_pie_sched_data *q = qdisc_priv(sch);
+
+	if (cl)
+		return NULL;
+	return q->block;
+}

Hi,

The AI-generated review of this patch on netdev-ai [1] reports several findings. And while I'd appreciate it if you could look over each of them the one below seems to warrant highlighting here.

[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260727164056.106203-1-hemendranaik%40gmail.com?part=1

Is the side effect of making fq_pie filter-capable intended, and should it be described in the commit message?

Before this patch fq_pie_qdisc_ops had no .cl_ops, so filter attachment was rejected in net/sched/cls_api.c:__tcf_qdisc_find():

	cops = (*q)->ops->cl_ops;
	if (!cops) {
		NL_SET_ERR_MSG(extack, "Qdisc not classful");
		err = -EINVAL;

q->filter_list was therefore always NULL and the filter branch of fq_pie_classify() was unreachable since fq_pie was added. With .cl_ops present and fq_pie_tcf_block() returning q->block, 'tc filter add ... parent <fq_pie handle>' now succeeds and classifier verdicts plus classid-driven flow selection become live in the enqueue fast path.

That newly reachable code does not handle TC_ACT_CONSUMED:

   net/sched/sch_fq_pie.c:fq_pie_classify() {
	result = tcf_classify_qdisc(skb, filter, &res, false);
	if (result >= 0) {
		switch (result) {
		case TC_ACT_STOLEN:
		case TC_ACT_QUEUED:
		case TC_ACT_TRAP:
			*qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
			fallthrough;
		case TC_ACT_SHOT:
			return 0;
		}
		if (TC_H_MIN(res.classid) <= q->flows_cnt)
			return TC_H_MIN(res.classid);
	}

TC_ACT_CONSUMED is TC_ACT_VALUE_MAX + 1, so it is >= 0 and matches no case arm, and control reaches the classid path. act_ct produces it after the skb ownership has already been handed away:

net/sched/act_ct.c:tcf_ct_act() {
out_frag:

	if (err != -EINPROGRESS)
		tcf_action_inc_drop_qstats(&c->common);
	return TC_ACT_CONSUMED;

tcf_action_exec() propagates any value != TC_ACT_PIPE and __tcf_classify() returns it verbatim. For a filter such as
tc filter add dev eth0 parent 1: matchall action ct

with no flowid, res.classid is 0, TC_H_MIN(0) <= flows_cnt holds and 0 is returned, so fq_pie_qdisc_enqueue() frees the consumed skb a second time:

	idx = fq_pie_classify(skb, sch, &ret);
	if (idx == 0) {
		if (ret & __NET_XMIT_BYPASS)
			qdisc_qstats_drop(sch);
		__qdisc_drop(skb, to_free);

and with 'flowid 1:N' a valid flow index is returned instead, so flow_queue_add() links the already freed skb into q->flows[idx]. Can fragmented traffic hitting that qdisc then cause a double free or use-after-free?

That TC_ACT_CONSUMED is expected from qdisc-attached filter chains is also visible in net/sched/cls_api.c:tcf_qevent_handle(), which has an explicit case TC_ACT_CONSUMED: arm that must not free the skb.

fq_codel, sfq and cake have the same missing arm, but for fq_pie the path only becomes reachable with this patch.

...

#3 lore raw

Re: [PATCH net-next v4 1/3] net/sched: sch_fq_pie: add per-flow statistics via class ops

Hi Simon,

Thanks for the review and for the Sashiko pointer. We have been through all six findings and are working on v5. For each item below, a short note on what was raised, then what we plan to do:

(1) [High] Filter attachment and TC_ACT_CONSUMED — Sashiko noted that adding cl_ops with .tcf_block would let users attach tc filters to fq_pie for the first time, but fq_pie_classify() has no TC_ACT_CONSUMED case (risk of double-free if an action like ct consumes the skb).

We will remove .tcf_block, .bind_tcf, and .unbind_tcf from cl_ops. We only need walk/dump for tc -s class show; filter attach to fq_pie should stay disabled as before v1.

(2) [Medium] tc_fq_pie_xstats layout — Sashiko asked whether appending type/class fields after the nine qdisc counters breaks userspace, compared to fq_codel's type-first union layout.

We plan no struct change. fq_pie already shipped a flat 36-byte struct; we will keep appending after those counters so old tc binaries keep working. Class stats still need the matching iproute2 update.

(3) [Low] Empty tc_fq_pie_xqd_stats placeholder — Sashiko flagged the empty placeholder struct and unused union arm in pkt_sched.h.

We will remove the placeholder and the union; class_stats will be a direct member.

(4) [Low] Class handle at flows 65536 — Sashiko noted that with flows_cnt == 65536, fq_pie_dump_class() uses TC_H_MIN(cl) and the last flow's handle wraps to minor 0 in userspace.

We will cap flows at 65535 in fq_pie_change() and update selftest 83be to expect flows 65536 to fail.

(5) [Medium] Selftest case 83c0 — Sashiko noted v4 used matchCount 0 with no traffic, so the test passes even without class ops and never checks per-flow stats output.

We will rewrite 83c0 with real traffic (TBF + fq_pie, ping on $DUMMY) and matchCount 1 on tc -s class show (prob/delay/deficit).

(6) [Low] tools/ UAPI mirror — Sashiko noted patch 3/3 also touched tools/include/uapi/linux/pkt_sched.h, but that copy is already stale in layout; comment-only edits there do not help.

We will drop the tools/include hunk from patch 3/3 and touch only include/uapi/linux/pkt_sched.h there.

We will post v5 with these changes once ready.

Thanks,
Hemendra

#4 lore raw

PATCH v4 2/3 selftests: tc-testing: add fq_pie per-flow class stats test

In reply to Hemendra M. Naik

Add a tc-testing entry (id: 83c0) to verify the fq_pie class ops wired up in the previous patch do not crash and integrate cleanly with the tc class show path.

The test creates an fq_pie root qdisc on a dummy interface and runs 'tc -s class show'.

---
 .../tc-testing/tc-tests/qdiscs/fq_pie.json    | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/qdiscs/fq_pie.json +22 -0
index 229fe1bf4a90..88139f429430 100644
@@ -40,5 +40,27 @@
         "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": [
+            "$TC qdisc add dev $DUMMY handle 1: root fq_pie"
+        ],
+        "cmdUnderTest": "$TC -s class show dev $DUMMY",
+        "expExitCode": "0",
+        "verifyCmd": "$TC -s class show dev $DUMMY",
+        "matchPattern": "class fq_pie",
+        "matchCount": "0",
+        "teardown": [
+            "$TC qdisc del dev $DUMMY handle 1: root"
+        ]
     }
 ]

--
2.34.1

#5 lore raw

PATCH v4 3/3 net/sched: pie: correct tc_pie_xstats field documentation

In reply to Hemendra M. Naik

The comments describing struct tc_pie_xstats do not match the values exported by the kernel.

Update the delay field comment to indicate that the value is reported in microseconds, matching the PSCHED_TICKS2NS() / NSEC_PER_USEC conversion.

Similarly, update the avg_dq_rate field comment to indicate that the value is reported in bytes/second, matching the conversion performed by avg_dq_rate * PSCHED_TICKS_PER_SEC >> PIE_SCALE.

These are documentation-only changes and do not modify the UAPI layout or runtime behavior.

---
 include/uapi/linux/pkt_sched.h       | 4 ++--
 tools/include/uapi/linux/pkt_sched.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
include/uapi/linux/pkt_sched.h +2 -2
index 9a86fa4d6846..26b7e6964adb 100644
@@ -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 */
tools/include/uapi/linux/pkt_sched.h +2 -2
index 587481a19433..9bc190f0b3cf 100644
@@ -847,8 +847,8 @@ enum {
 
 struct tc_pie_xstats {
 	__u32 prob;             /* current probability */
-	__u32 delay;            /* current delay in ms */
-	__u32 avg_dq_rate;      /* current average dq_rate in bits/pie_time */
+	__u32 delay;            /* current delay in microseconds */
+	__u32 avg_dq_rate;      /* current average dq_rate in bytes/second */
 	__u32 packets_in;       /* total number of packets enqueued */
 	__u32 dropped;          /* packets dropped due to pie_action */
 	__u32 overlimit;        /* dropped due to lack of space in queue */

--
2.34.1