Skip to contentSkip to conversation

TCP usec and FQ fastpath

PATCH Applied Eric Dumazet 3 participants 9 messages Dec 4, 2023 – Dec 6, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover TCP usec and FQ fastpath

Add iproute2 patches to support recent TCP usec timestamps, and FQ changes landed in linux-6.7

Eric Dumazet (5):
ip route: add support for TCP usec TS
ss: add report of TCPI_OPT_USEC_TS
tc: fq: add TCA_FQ_PRIOMAP handling
tc: fq: add TCA_FQ_WEIGHTS handling
tc: fq: reports stats added in linux-6.7

 ip/iproute.c |   7 +++
 misc/ss.c    |   4 ++
 tc/q_fq.c    | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 137 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#1 lore raw

PATCH 1/5 ip route: add support for TCP usec TS

linux-6.7 got support for TCP usec resolution timestamps, using one bit in the features mask : RTAX_FEATURE_TCP_USEC_TS.

ip route add 10/8 ... features tcp_usec_ts

---
 ip/iproute.c | 7 +++++++
 1 file changed, 7 insertions(+)
ip/iproute.c +7 -0
index fdf1f9a9dd0a4b693516d0b29b12cd6463895317..73dbab48aa4533e2297a1b1dd43726b4b05466b9 100644
@@ -351,6 +351,11 @@ static void print_rtax_features(FILE *fp, unsigned int features)
 		features &= ~RTAX_FEATURE_ECN;
 	}
 
+	if (features & RTAX_FEATURE_TCP_USEC_TS) {
+		print_null(PRINT_ANY, "tcp_usec_ts", "tcp_usec_ts ", NULL);
+		features &= ~RTAX_FEATURE_TCP_USEC_TS;
+	}
+
 	if (features)
 		print_0xhex(PRINT_ANY,
 			    "features", "%#llx ", of);
@@ -1349,6 +1354,8 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
 
 				if (strcmp(*argv, "ecn") == 0)
 					features |= RTAX_FEATURE_ECN;
+				else if (strcmp(*argv, "tcp_usec_ts") == 0)
+					features |= RTAX_FEATURE_TCP_USEC_TS;
 				else
 					invarg("\"features\" value not valid\n", *argv);
 				break;
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#2 lore raw

PATCH 2/5 ss: add report of TCPI_OPT_USEC_TS

In reply to Eric Dumazet

linux-6.7 supports usec resolution in TCP TS values. ss -ie can show if a flow is using this new resolution.

$ ss -tie
 ...
State Recv-Q Send-Q           Local Address:Port           Peer Address:Port Process
ESTAB 0      12869632 [2002:a05:6608:295::]:37054 [2002:a05:6608:297::]:35721
	 ts usec_ts sack bbr2s wscale:12,12 ...
---
 misc/ss.c | 4 ++++
 1 file changed, 4 insertions(+)
misc/ss.c +4 -0
index 9438382b8e667529dc2cf4b020d8696a4175e992..3dacee48db0f805b3a7a3bd213771b86eceea1ab 100644
@@ -875,6 +875,7 @@ struct tcpstat {
 	unsigned long long  bytes_sent;
 	unsigned long long  bytes_retrans;
 	bool		    has_ts_opt;
+	bool		    has_usec_ts_opt;
 	bool		    has_sack_opt;
 	bool		    has_ecn_opt;
 	bool		    has_ecnseen_opt;
@@ -2562,6 +2563,8 @@ static void tcp_stats_print(struct tcpstat *s)
 
 	if (s->has_ts_opt)
 		out(" ts");
+	if (s->has_usec_ts_opt)
+		out(" usec_ts");
 	if (s->has_sack_opt)
 		out(" sack");
 	if (s->has_ecn_opt)
@@ -3037,6 +3040,7 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
 
 		if (show_options) {
 			s.has_ts_opt	   = TCPI_HAS_OPT(info, TCPI_OPT_TIMESTAMPS);
+			s.has_usec_ts_opt  = TCPI_HAS_OPT(info, TCPI_OPT_USEC_TS);
 			s.has_sack_opt	   = TCPI_HAS_OPT(info, TCPI_OPT_SACK);
 			s.has_ecn_opt	   = TCPI_HAS_OPT(info, TCPI_OPT_ECN);
 			s.has_ecnseen_opt  = TCPI_HAS_OPT(info, TCPI_OPT_ECN_SEEN);
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#3 lore raw

PATCH 3/5 tc: fq: add TCA_FQ_PRIOMAP handling

In reply to Eric Dumazet

linux-6.7 FQ packet scheduler gets 3-bands, and the ability to report or program the associated priomap.

$ tc qdisc show dev eth0
...
qdisc fq ... bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
$ tc qdisc change dev eth0 ... qdisc fq ... bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
---
 tc/q_fq.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
tc/q_fq.c +59 -0
index 3277ebc7c43702dfd663eb90100954c44e312fc3..d6f724569932906515cd012d4d7f815966523934 100644
@@ -25,6 +25,7 @@ static void explain(void)
 		"		[ quantum BYTES ] [ initial_quantum BYTES ]\n"
 		"		[ maxrate RATE ] [ buckets NUMBER ]\n"
 		"		[ [no]pacing ] [ refill_delay TIME ]\n"
+		"		[ bands 3 priomap P0 P1 ... P14 P15 ]\n"
 		"		[ low_rate_threshold RATE ]\n"
 		"		[ orphan_mask MASK]\n"
 		"		[ timer_slack TIME]\n"
@@ -48,6 +49,7 @@ static unsigned int ilog2(unsigned int val)
 static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 			struct nlmsghdr *n, const char *dev)
 {
+	struct tc_prio_qopt prio2band;
 	unsigned int plimit;
 	unsigned int flow_plimit;
 	unsigned int quantum;
@@ -74,6 +76,7 @@ static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	bool set_ce_threshold = false;
 	bool set_timer_slack = false;
 	bool set_horizon = false;
+	bool set_priomap = false;
 	int pacing = -1;
 	struct rtattr *tail;
 
@@ -193,6 +196,48 @@ static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 			pacing = 1;
 		} else if (strcmp(*argv, "nopacing") == 0) {
 			pacing = 0;
+		} else if (strcmp(*argv, "bands") == 0) {
+			int idx;
+
+			if (set_priomap) {
+				fprintf(stderr, "Duplicate \"bands\"\n");
+				return -1;
+			}
+			memset(&prio2band, 0, sizeof(prio2band));
+			NEXT_ARG();
+			if (get_integer(&prio2band.bands, *argv, 10)) {
+				fprintf(stderr, "Illegal \"bands\"\n");
+				return -1;
+			}
+			if (prio2band.bands != 3) {
+				fprintf(stderr, "\"bands\" must be 3\n");
+				return -1;
+			}
+			NEXT_ARG();
+			if (strcmp(*argv, "priomap") != 0) {
+				fprintf(stderr, "\"priomap\" expected\n");
+				return -1;
+			}
+			for (idx = 0; idx <= TC_PRIO_MAX; ++idx) {
+				unsigned band;
+
+				if (!NEXT_ARG_OK()) {
+					fprintf(stderr, "Not enough elements in priomap\n");
+					return -1;
+				}
+				NEXT_ARG();
+				if (get_unsigned(&band, *argv, 10)) {
+					fprintf(stderr, "Illegal \"priomap\" element, number in [0..%u] expected\n",
+							prio2band.bands - 1);
+					return -1;
+				}
+				if (band >= prio2band.bands) {
+					fprintf(stderr, "\"priomap\" element %u too big\n", band);
+					return -1;
+				}
+				prio2band.priomap[idx] = band;
+			}
+			set_priomap = true;
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -252,6 +297,9 @@ static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	if (horizon_drop != 255)
 		addattr_l(n, 1024, TCA_FQ_HORIZON_DROP,
 			  &horizon_drop, sizeof(horizon_drop));
+	if (set_priomap)
+		addattr_l(n, 1024, TCA_FQ_PRIOMAP,
+			  &prio2band, sizeof(prio2band));
 	addattr_nest_end(n, tail);
 	return 0;
 }
@@ -306,6 +354,17 @@ static int fq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 		if (pacing == 0)
 			print_bool(PRINT_ANY, "pacing", "nopacing ", false);
 	}
+	if (tb[TCA_FQ_PRIOMAP] &&
+	    RTA_PAYLOAD(tb[TCA_FQ_PRIOMAP]) >= sizeof(struct tc_prio_qopt)) {
+		struct tc_prio_qopt *prio2band = RTA_DATA(tb[TCA_FQ_PRIOMAP]);
+		int i;
+
+		print_uint(PRINT_ANY, "bands", "bands %u ", prio2band->bands);
+		open_json_array(PRINT_ANY, "priomap ");
+		for (i = 0; i <= TC_PRIO_MAX; i++)
+			print_uint(PRINT_ANY, NULL, "%d ", prio2band->priomap[i]);
+		close_json_array(PRINT_ANY, "");
+	}
 	if (tb[TCA_FQ_QUANTUM] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_QUANTUM]) >= sizeof(__u32)) {
 		quantum = rta_getattr_u32(tb[TCA_FQ_QUANTUM]);
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#4 lore raw

Re: [PATCH iproute2 3/5] tc: fq: add TCA_FQ_PRIOMAP handling

Quoted 11 lines · Eric Dumazet
tc/q_fq.c +7 -0
@@ -193,6 +196,48 @@ static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 			pacing = 1;
 		} else if (strcmp(*argv, "nopacing") == 0) {
 			pacing = 0;
+		} else if (strcmp(*argv, "bands") == 0) {
+			int idx;
+
+			if (set_priomap) {
+				fprintf(stderr, "Duplicate \"bands\"\n");
+				return -1;
+			}

tc/q_fq.c static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv, · line 215

Quoted 10 lines
tc/q_fq.c +10 -0
+			memset(&prio2band, 0, sizeof(prio2band));
+			NEXT_ARG();
+			if (get_integer(&prio2band.bands, *argv, 10)) {
+				fprintf(stderr, "Illegal \"bands\"\n");
+				return -1;
+			}
+			if (prio2band.bands != 3) {
+				fprintf(stderr, "\"bands\" must be 3\n");
+				return -1;
+			}

do you expect number of bands to change in the future? If not, why make it an option or just a flag?

#5 lore raw

Re: [PATCH iproute2 3/5] tc: fq: add TCA_FQ_PRIOMAP handling

Quoted 18 lines · David Ahern
Quoted 16 lines · Eric Dumazet
tc/q_fq.c +12 -0
@@ -193,6 +196,48 @@ static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
                      pacing = 1;
              } else if (strcmp(*argv, "nopacing") == 0) {
                      pacing = 0;
+             } else if (strcmp(*argv, "bands") == 0) {
+                     int idx;
+
+                     if (set_priomap) {
+                             fprintf(stderr, "Duplicate \"bands\"\n");
+                             return -1;
+                     }
+                     memset(&prio2band, 0, sizeof(prio2band));
+                     NEXT_ARG();
+                     if (get_integer(&prio2band.bands, *argv, 10)) {
+                             fprintf(stderr, "Illegal \"bands\"\n");
+                             return -1;
Quoted 8 lines

tc/q_fq.c static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv, · line 215

Quoted 5 lines
tc/q_fq.c +5 -0
+                     }
+                     if (prio2band.bands != 3) {
+                             fprintf(stderr, "\"bands\" must be 3\n");
+                             return -1;
+                     }

do you expect number of bands to change in the future? If not, why make it an option or just a flag?

We do not know yet if this would in the future (we have not changed it in the last ~9 years)

I used the same syntax as prio which would allow a future change if needed.

#6 lore raw

PATCH 4/5 tc: fq: add TCA_FQ_WEIGHTS handling

In reply to Eric Dumazet

Linux-6.7 FQ got WRR scheduling.

TCA_FQ_WEIGHTS attribute can report/change per-band weights.

tc qdisc show dev eth1
...
qdisc fq ... weights 589824 196608 65536 quantum 8364b ...

---
 tc/q_fq.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
tc/q_fq.c +43 -0
index d6f724569932906515cd012d4d7f815966523934..08bfbf4ef6db1838bca87d1d87d6923255a1a4f6 100644
@@ -26,6 +26,7 @@ static void explain(void)
 		"		[ maxrate RATE ] [ buckets NUMBER ]\n"
 		"		[ [no]pacing ] [ refill_delay TIME ]\n"
 		"		[ bands 3 priomap P0 P1 ... P14 P15 ]\n"
+		"		[ weights W1 W2 W3 ]\n"
 		"		[ low_rate_threshold RATE ]\n"
 		"		[ orphan_mask MASK]\n"
 		"		[ timer_slack TIME]\n"
@@ -77,6 +78,8 @@ static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	bool set_timer_slack = false;
 	bool set_horizon = false;
 	bool set_priomap = false;
+	bool set_weights = false;
+	int weights[FQ_BANDS];
 	int pacing = -1;
 	struct rtattr *tail;
 
@@ -238,6 +241,33 @@ static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 				prio2band.priomap[idx] = band;
 			}
 			set_priomap = true;
+		} else if (strcmp(*argv, "weights") == 0) {
+			int idx;
+
+			if (set_weights) {
+				fprintf(stderr, "Duplicate \"weights\"\n");
+				return -1;
+			}
+			NEXT_ARG();
+			for (idx = 0; idx < FQ_BANDS; ++idx) {
+				int val;
+
+				if (!NEXT_ARG_OK()) {
+					fprintf(stderr, "Not enough elements in weights\n");
+					return -1;
+				}
+				NEXT_ARG();
+				if (get_integer(&val, *argv, 10)) {
+					fprintf(stderr, "Illegal \"weights\" element, positive number expected\n");
+					return -1;
+				}
+				if (val < FQ_MIN_WEIGHT) {
+					fprintf(stderr, "\"weight\" element %d too small\n", val);
+					return -1;
+				}
+				weights[idx] = val;
+			}
+			set_weights = true;
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -300,6 +330,9 @@ static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	if (set_priomap)
 		addattr_l(n, 1024, TCA_FQ_PRIOMAP,
 			  &prio2band, sizeof(prio2band));
+	if (set_weights)
+		addattr_l(n, 1024, TCA_FQ_WEIGHTS,
+			  weights, sizeof(weights));
 	addattr_nest_end(n, tail);
 	return 0;
 }
@@ -365,6 +398,16 @@ static int fq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 			print_uint(PRINT_ANY, NULL, "%d ", prio2band->priomap[i]);
 		close_json_array(PRINT_ANY, "");
 	}
+	if (tb[TCA_FQ_WEIGHTS] &&
+	    RTA_PAYLOAD(tb[TCA_FQ_WEIGHTS]) >= FQ_BANDS * sizeof(int)) {
+		const int *weights = RTA_DATA(tb[TCA_FQ_WEIGHTS]);
+		int i;
+
+		open_json_array(PRINT_ANY, "weights ");
+		for (i = 0; i < FQ_BANDS; ++i)
+			print_uint(PRINT_ANY, NULL, "%d ", weights[i]);
+		close_json_array(PRINT_ANY, "");
+	}
 	if (tb[TCA_FQ_QUANTUM] &&
 	    RTA_PAYLOAD(tb[TCA_FQ_QUANTUM]) >= sizeof(__u32)) {
 		quantum = rta_getattr_u32(tb[TCA_FQ_QUANTUM]);
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#7 lore raw

PATCH 5/5 tc: fq: reports stats added in linux-6.7

In reply to Eric Dumazet

Report new fields added in linux-6.7:

- fastpath : Number of packets that have used the fast path.
- band[012]_pkts : Number of packets currently queued per band.
- band[012]_drops : Counters of dropped packets, per band (only printed if not zero)

---
 tc/q_fq.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
tc/q_fq.c +24 -1
index 08bfbf4ef6db1838bca87d1d87d6923255a1a4f6..7f8a2b80d441857ecadc19ea77545092b7f4f02f 100644
@@ -510,6 +510,10 @@ static int fq_print_xstats(struct qdisc_util *qu, FILE *f,
 	print_uint(PRINT_ANY, "throttled", " throttled %u)",
 		   st->throttled_flows);
 
+	print_uint(PRINT_ANY, "band0_pkts", " band0_pkts %u", st->band_pkt_count[0]);
+	print_uint(PRINT_ANY, "band1_pkts", " band1_pkts %u", st->band_pkt_count[1]);
+	print_uint(PRINT_ANY, "band2_pkts", " band2_pkts %u", st->band_pkt_count[2]);
+
 	if (st->time_next_delayed_flow > 0) {
 		print_lluint(PRINT_JSON, "next_packet_delay", NULL,
 			     st->time_next_delayed_flow);
@@ -522,6 +526,10 @@ static int fq_print_xstats(struct qdisc_util *qu, FILE *f,
 	print_lluint(PRINT_ANY, "highprio", " highprio %llu",
 		     st->highprio_packets);
 
+	if (st->fastpath_packets)
+		print_lluint(PRINT_ANY, "fastpath", " fastpath %llu",
+			     st->fastpath_packets);
+
 	if (st->tcp_retrans)
 		print_lluint(PRINT_ANY, "retrans", " retrans %llu",
 			     st->tcp_retrans);
@@ -544,7 +552,10 @@ static int fq_print_xstats(struct qdisc_util *qu, FILE *f,
 			     st->flows_plimit);
 
 	if (st->pkts_too_long || st->allocation_errors ||
-	    st->horizon_drops || st->horizon_caps) {
+	    st->horizon_drops || st->horizon_caps ||
+	    st->band_drops[0] ||
+	    st->band_drops[1] ||
+	    st->band_drops[2]) {
 		print_nl();
 		if (st->pkts_too_long)
 			print_lluint(PRINT_ANY, "pkts_too_long",
@@ -562,6 +573,18 @@ static int fq_print_xstats(struct qdisc_util *qu, FILE *f,
 			print_lluint(PRINT_ANY, "horizon_caps",
 				     "  horizon_caps %llu",
 				     st->horizon_caps);
+		if (st->band_drops[0])
+			print_lluint(PRINT_ANY, "band0_drops",
+				     " band0_drops %llu",
+				     st->band_drops[0]);
+		if (st->band_drops[1])
+			print_lluint(PRINT_ANY, "band1_drops",
+				     " band1_drops %llu",
+				     st->band_drops[1]);
+		if (st->band_drops[2])
+			print_lluint(PRINT_ANY, "band2_drops",
+				     " band2_drops %llu",
+				     st->band_drops[2]);
 	}
 
 	return 0;
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#8 lore raw
In reply to Eric Dumazet
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Hello:

This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Quoted 11 lines · On Mon, 4 Dec 2023 09:19:06 +0000 you wrote:

Add iproute2 patches to support recent TCP usec timestamps, and FQ changes landed in linux-6.7

Eric Dumazet (5):
ip route: add support for TCP usec TS
ss: add report of TCPI_OPT_USEC_TS
tc: fq: add TCA_FQ_PRIOMAP handling
tc: fq: add TCA_FQ_WEIGHTS handling
tc: fq: reports stats added in linux-6.7

[...]

Here is the summary with links:
- [iproute2,1/5] ip route: add support for TCP usec TS

    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=a043bea75002
  - [iproute2,2/5] ss: add report of TCPI_OPT_USEC_TS
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=467879b418ff
  - [iproute2,3/5] tc: fq: add TCA_FQ_PRIOMAP handling
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=73a31c945481
  - [iproute2,4/5] tc: fq: add TCA_FQ_WEIGHTS handling
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=567eb4e41045
  - [iproute2,5/5] tc: fq: reports stats added in linux-6.7
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=3086a339f681

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html