Skip to contentSkip to conversation

README: add note about kernel version compatibility

PATCH New Stephen Hemminger 2 participants 4 messages Mar 8, 2024 – Mar 13, 2024

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

PATCH 1/3 README: add note about kernel version compatibility

Since next netem changes will break some usages of out of support kernels, add an explicit policy about range of kernel versions.

---
 README | 13 +++++++++++++
 1 file changed, 13 insertions(+)
README +13 -0
index 4eb9390a3ffa..a7d283cb809d 100644
@@ -12,6 +12,19 @@ Stable version repository:
 Development repository:
     git://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git
 
+Compatibility
+-------------
+A new release of iproute2 is done with each kernel version, but
+there is a wide range of compatibility. Newer versions of iproute2
+will still work with older kernels, but there are some limitations.
+
+If an iproute2 command with a new feature is used with an older
+kernel, the kernel may report an error or silently ignore the new
+attribute. Likewise if older iproute2 is used with an newer kernel,
+it is not possible to use or see new features. The range of
+compatibility extends back as far as the oldest supported Long Term
+Support (LTS) kernel version.
+
 How to compile this.
 --------------------
 1. libdbm
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/3 netem: use 64 bit value for latency and jitter

The current version of netem in iproute2 has a maximum of 4.3 seconds because of scaled 32 bit clock values. Some users would like to be able to use larger delays to emulate things like storage delays.

Since kernel version 4.15, netem qdisc had netlink parameters to express wider range of delays in nanoseconds. But the iproute2 side was never updated to use them.

This does break compatibility with older kernels (4.14 and earlier). With these out of support kernels, the latency/delay parameter will end up being ignored.

---
 tc/q_netem.c | 83 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 46 insertions(+), 37 deletions(-)
tc/q_netem.c +46 -37
index 4ce9ab6e529b..86cabbfe7b3a 100644
@@ -170,26 +170,6 @@ static int get_distribution(const char *type, __s16 *data, int maxdata)
 #define NEXT_IS_SIGNED_NUMBER() \
 	(NEXT_ARG_OK() && (isdigit(argv[1][0]) || argv[1][0] == '-'))
 
-/*
- * Adjust for the fact that psched_ticks aren't always usecs
- *  (based on kernel PSCHED_CLOCK configuration
- */
-static int get_ticks(__u32 *ticks, const char *str)
-{
-	unsigned int t;
-
-	if (get_time(&t, str))
-		return -1;
-
-	if (tc_core_time2big(t)) {
-		fprintf(stderr, "Illegal %u time (too large)\n", t);
-		return -1;
-	}
-
-	*ticks = tc_core_time2tick(t);
-	return 0;
-}
-
 static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 			   struct nlmsghdr *n, const char *dev)
 {
@@ -208,6 +188,8 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	__s16 *slot_dist_data = NULL;
 	__u16 loss_type = NETEM_LOSS_UNSPEC;
 	int present[__TCA_NETEM_MAX] = {};
+	__s64 latency64 = 0;
+	__s64 jitter64 = 0;
 	__u64 rate64 = 0;
 	__u64 seed = 0;
 
@@ -221,14 +203,20 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 		} else if (matches(*argv, "latency") == 0 ||
 			   matches(*argv, "delay") == 0) {
 			NEXT_ARG();
-			if (get_ticks(&opt.latency, *argv)) {
+
+			/* Old latency value in opt is no longer used. */
+			present[TCA_NETEM_LATENCY64] = 1;
+
+			if (get_time64(&latency64, *argv)) {
 				explain1("latency");
 				return -1;
 			}
 
 			if (NEXT_IS_NUMBER()) {
 				NEXT_ARG();
-				if (get_ticks(&opt.jitter, *argv)) {
+
+				present[TCA_NETEM_JITTER64] = 1;
+				if (get_time64(&jitter64, *argv)) {
 					explain1("latency");
 					return -1;
 				}
@@ -552,7 +540,7 @@ random_loss_model:
 	tail = NLMSG_TAIL(n);
 
 	if (reorder.probability) {
-		if (opt.latency == 0) {
+		if (latency64 == 0) {
 			fprintf(stderr, "reordering not possible without specifying some delay\n");
 			explain();
 			return -1;
@@ -573,7 +561,7 @@ random_loss_model:
 		}
 	}
 
-	if (dist_data && (opt.latency == 0 || opt.jitter == 0)) {
+	if (dist_data && (latency64 == 0 || jitter64 == 0)) {
 		fprintf(stderr, "distribution specified but no latency and jitter values\n");
 		explain();
 		return -1;
@@ -582,6 +570,14 @@ random_loss_model:
 	if (addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)) < 0)
 		return -1;
 
+	if (present[TCA_NETEM_LATENCY64] &&
+	    addattr_l(n, 1024, TCA_NETEM_LATENCY64, &latency64, sizeof(latency64)) < 0)
+		return -1;
+
+	if (present[TCA_NETEM_JITTER64] &&
+	    addattr_l(n, 1024, TCA_NETEM_JITTER64, &jitter64, sizeof(jitter64)) < 0)
+		return -1;
+
 	if (present[TCA_NETEM_CORR] &&
 	    addattr_l(n, 1024, TCA_NETEM_CORR, &cor, sizeof(cor)) < 0)
 		return -1;
@@ -676,6 +672,8 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	__u64 seed = 0;
 	int len;
 	__u64 rate64 = 0;
+	__u64 latency64 = 0;
+	__u64 jitter64 = 0;
 
 	SPRINT_BUF(b1);
 
@@ -734,6 +732,18 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 				return -1;
 			rate64 = rta_getattr_u64(tb[TCA_NETEM_RATE64]);
 		}
+		if (tb[TCA_NETEM_LATENCY64]) {
+			if (RTA_PAYLOAD(tb[TCA_NETEM_LATENCY64]) < sizeof(latency64))
+				return -1;
+			latency64 = rta_getattr_u64(tb[TCA_NETEM_LATENCY64]);
+
+		}
+		if (tb[TCA_NETEM_JITTER64]) {
+			if (RTA_PAYLOAD(tb[TCA_NETEM_JITTER64]) < sizeof(jitter64))
+				return -1;
+			jitter64 = rta_getattr_u64(tb[TCA_NETEM_JITTER64]);
+
+		}
 		if (tb[TCA_NETEM_SLOT]) {
 			if (RTA_PAYLOAD(tb[TCA_NETEM_SLOT]) < sizeof(*slot))
 				return -1;
@@ -749,24 +759,23 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 
 	print_uint(PRINT_ANY, "limit", "limit %d", qopt.limit);
 
-	if (qopt.latency) {
+
+	if (latency64 != 0) {
 		open_json_object("delay");
-		if (!is_json_context()) {
-			print_string(PRINT_FP, NULL, " delay %s",
-				     sprint_ticks(qopt.latency, b1));
 
-			if (qopt.jitter)
-				print_string(PRINT_FP, NULL, "  %s",
-					     sprint_ticks(qopt.jitter, b1));
-		} else {
+		if (is_json_context()) {
 			print_float(PRINT_JSON, "delay", NULL,
-				    tc_core_tick2time(qopt.latency) /
-				    1000000.);
+				    (double)latency64 / 1000000000.);
 			print_float(PRINT_JSON, "jitter", NULL,
-				    tc_core_tick2time(qopt.jitter) /
-				    1000000.);
+				    (double)jitter64 / 1000000000.);
+		} else {
+			print_string(PRINT_FP, NULL, " delay %s",
+				     sprint_time64(latency64, b1));
+			if (jitter64 != 0)
+				print_string(PRINT_FP, NULL, "  %s",
+					     sprint_time64(jitter64, b1));
 		}
-		print_corr(qopt.jitter && cor && cor->delay_corr,
+		print_corr(jitter64 && cor && cor->delay_corr,
 			   cor ? cor->delay_corr : 0);
 		close_json_object();
 	}
Signature · 1 line
2.43.0
#2 lore raw

PATCH 3/3 tc: remove no longer used helpers

In reply to Stephen Hemminger

The removal of tick usage in netem, means that some of the helper functions in tc are no longer used and can be safely removed. Other functions can be made static.

---
 tc/tc_core.c | 15 +++------------
 tc/tc_core.h |  2 --
 tc/tc_util.c |  5 -----
 tc/tc_util.h |  1 -
 4 files changed, 3 insertions(+), 20 deletions(-)
tc/tc_core.c +3 -12
index 871ceb45ff58..37547e9b3395 100644
@@ -23,23 +23,14 @@
 static double tick_in_usec = 1;
 static double clock_factor = 1;
 
-int tc_core_time2big(unsigned int time)
+static unsigned int tc_core_time2tick(unsigned int time)
 {
-	__u64 t = time;
-
-	t *= tick_in_usec;
-	return (t >> 32) != 0;
-}
-
-
-unsigned int tc_core_time2tick(unsigned int time)
-{
-	return time*tick_in_usec;
+	return time * tick_in_usec;
 }
 
 unsigned int tc_core_tick2time(unsigned int tick)
 {
-	return tick/tick_in_usec;
+	return tick / tick_in_usec;
 }
 
 unsigned int tc_core_time2ktime(unsigned int time)
tc/tc_core.h +0 -2
index 6dab2727d199..7a986ac27a44 100644
@@ -12,8 +12,6 @@ enum link_layer {
 };
 
 
-int  tc_core_time2big(unsigned time);
-unsigned tc_core_time2tick(unsigned time);
 unsigned tc_core_tick2time(unsigned tick);
 unsigned tc_core_time2ktime(unsigned time);
 unsigned tc_core_ktime2time(unsigned ktime);
tc/tc_util.c +0 -5
index aa7cf60faa6d..c293643dc80d 100644
@@ -257,11 +257,6 @@ tc_print_rate(enum output_type t, const char *key, const char *fmt,
 	print_rate(use_iec, t, key, fmt, rate);
 }
 
-char *sprint_ticks(__u32 ticks, char *buf)
-{
-	return sprint_time(tc_core_tick2time(ticks), buf);
-}
-
 int get_size_and_cell(unsigned int *size, int *cell_log, char *str)
 {
 	char *slash = strchr(str, '/');
tc/tc_util.h +0 -1
index 623d9888a5ad..b7b9a097acd3 100644
@@ -86,7 +86,6 @@ void tc_print_rate(enum output_type t, const char *key, const char *fmt,
 void print_devname(enum output_type type, int ifindex);
 
 char *sprint_tc_classid(__u32 h, char *buf);
-char *sprint_ticks(__u32 ticks, char *buf);
 char *sprint_linklayer(unsigned int linklayer, char *buf);
 
 void print_tcstats_attr(FILE *fp, struct rtattr *tb[],
Signature · 1 line
2.43.0
#3 lore raw
In reply to Stephen Hemminger
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 7 lines · On Fri, 8 Mar 2024 09:15:59 -0800 you wrote:

Since next netem changes will break some usages of out of support kernels, add an explicit policy about range of kernel versions.

---
 README | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Here is the summary with links:
- [iproute2-next,1/3] README: add note about kernel version compatibility

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=56511223ef26
  - [iproute2-next,2/3] netem: use 64 bit value for latency and jitter
    (no matching commit)
  - [iproute2-next,3/3] tc: remove no longer used helpers
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=38656eeb35bd

You are awesome, thank you!

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