public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH for-faizal 0/4] tc-taprio selftests
@ 2023-12-21 13:25 Vladimir Oltean
  2023-12-21 13:25 ` [RFC PATCH for-faizal 1/4] selftests: net: forwarding: allow veth pairs to be created with multiple queues Vladimir Oltean
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Vladimir Oltean @ 2023-12-21 13:25 UTC (permalink / raw)
  To: netdev; +Cc: Abdul Rahim, Faizal

Unfortunately the isochron version from debian will not work on veth
pairs, I had to make some changes and add the --omit-hwts option to
the sender and receiver programs. The modified version is on this branch
here, I will merge the changes to 'master' once I have enough confidence
in them.
https://github.com/vladimiroltean/isochron/tree/omit-hwts

For testing the tc-taprio software scheduling path, we don't need PTP
synchronization or hardware timestamps anyway.

This is just a skeleton that I'm hoping Faizal can pick up and extend
with more test cases for dynamic schedule changes. It should run
primarily on the veth driver, but should behave the same on any network
driver as well, including those who also have tc-taprio offload.

Vladimir Oltean (4):
  selftests: net: forwarding: allow veth pairs to be created with
    multiple queues
  selftests: net: tsn: push --txtime out of isochron_do()
  selftests: net: tsn: allow isochron_do() to skip sync monitoring on
    sender too
  selftests: net: tsn: add tc-taprio test cases (WIP)

 .../selftests/drivers/net/ocelot/psfp.sh      |   1 +
 .../testing/selftests/net/forwarding/Makefile |   1 +
 tools/testing/selftests/net/forwarding/lib.sh |   3 +-
 .../selftests/net/forwarding/tc_taprio.sh     | 143 ++++++++++++++++++
 .../selftests/net/forwarding/tsn_lib.sh       |  70 +++++++--
 5 files changed, 205 insertions(+), 13 deletions(-)
 create mode 100755 tools/testing/selftests/net/forwarding/tc_taprio.sh

-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC PATCH for-faizal 1/4] selftests: net: forwarding: allow veth pairs to be created with multiple queues
  2023-12-21 13:25 [RFC PATCH for-faizal 0/4] tc-taprio selftests Vladimir Oltean
@ 2023-12-21 13:25 ` Vladimir Oltean
  2023-12-21 13:25 ` [RFC PATCH for-faizal 2/4] selftests: net: tsn: push --txtime out of isochron_do() Vladimir Oltean
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Vladimir Oltean @ 2023-12-21 13:25 UTC (permalink / raw)
  To: netdev; +Cc: Abdul Rahim, Faizal

For tc-taprio testing on veth, the veth pairs must have multiple TX
queues. Allow certain tests to provide VETH_OPTS="numtxqueues 8 numrxqueues 8",
while keeping the default unchanged.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 tools/testing/selftests/net/forwarding/lib.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index 69ef2a40df21..c0736a591ca0 100755
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -28,6 +28,7 @@ REQUIRE_MTOOLS=${REQUIRE_MTOOLS:=no}
 STABLE_MAC_ADDRS=${STABLE_MAC_ADDRS:=no}
 TCPDUMP_EXTRA_FLAGS=${TCPDUMP_EXTRA_FLAGS:=}
 TROUTE6=${TROUTE6:=traceroute6}
+VETH_OPTS=${VETH_OPTS:=}
 
 relative_path="${BASH_SOURCE%/*}"
 if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
@@ -260,7 +261,7 @@ create_netif_veth()
 
 		ip link show dev ${NETIFS[p$i]} &> /dev/null
 		if [[ $? -ne 0 ]]; then
-			ip link add ${NETIFS[p$i]} type veth \
+			ip link add ${NETIFS[p$i]} ${VETH_OPTS} type veth \
 				peer name ${NETIFS[p$j]}
 			if [[ $? -ne 0 ]]; then
 				echo "Failed to create netif"
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH for-faizal 2/4] selftests: net: tsn: push --txtime out of isochron_do()
  2023-12-21 13:25 [RFC PATCH for-faizal 0/4] tc-taprio selftests Vladimir Oltean
  2023-12-21 13:25 ` [RFC PATCH for-faizal 1/4] selftests: net: forwarding: allow veth pairs to be created with multiple queues Vladimir Oltean
@ 2023-12-21 13:25 ` Vladimir Oltean
  2023-12-21 13:25 ` [RFC PATCH for-faizal 3/4] selftests: net: tsn: allow isochron_do() to skip sync monitoring on sender too Vladimir Oltean
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Vladimir Oltean @ 2023-12-21 13:25 UTC (permalink / raw)
  To: netdev; +Cc: Abdul Rahim, Faizal

Not all isochron tests should use the --txtime option. Make the
sender_extra_args and receiver_extra_args be provided by the caller, and
move --txtime to the ocelot psfp.sh test.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 .../selftests/drivers/net/ocelot/psfp.sh      |  1 +
 .../selftests/net/forwarding/tsn_lib.sh       | 21 +++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/ocelot/psfp.sh b/tools/testing/selftests/drivers/net/ocelot/psfp.sh
index bed748dde4b0..e6042b678c09 100755
--- a/tools/testing/selftests/drivers/net/ocelot/psfp.sh
+++ b/tools/testing/selftests/drivers/net/ocelot/psfp.sh
@@ -270,6 +270,7 @@ run_test()
 		"${STREAM_VID}" \
 		"${STREAM_PRIO}" \
 		"" \
+		"--txtime" "" \
 		"${isochron_dat}"
 
 	# Count all received packets by looking at the non-zero RX timestamps
diff --git a/tools/testing/selftests/net/forwarding/tsn_lib.sh b/tools/testing/selftests/net/forwarding/tsn_lib.sh
index b91bcd8008a9..f081cebb1c65 100644
--- a/tools/testing/selftests/net/forwarding/tsn_lib.sh
+++ b/tools/testing/selftests/net/forwarding/tsn_lib.sh
@@ -186,9 +186,9 @@ isochron_do()
 	local vid=$1; shift
 	local priority=$1; shift
 	local dst_ip=$1; shift
+	local sender_extra_args="$1"; shift
+	local receiver_extra_args="$1"; shift
 	local isochron_dat=$1; shift
-	local extra_args=""
-	local receiver_extra_args=""
 	local vrf="$(master_name_get ${sender_if_name})"
 	local use_l2="true"
 
@@ -205,19 +205,19 @@ isochron_do()
 	fi
 
 	if [ -z "${receiver_uds}" ]; then
-		extra_args="${extra_args} --omit-remote-sync"
+		sender_extra_args="${sender_extra_args} --omit-remote-sync"
 	fi
 
 	if ! [ -z "${shift_time}" ]; then
-		extra_args="${extra_args} --shift-time=${shift_time}"
+		sender_extra_args="${sender_extra_args} --shift-time=${shift_time}"
 	fi
 
 	if [ "${use_l2}" = "true" ]; then
-		extra_args="${extra_args} --l2 --etype=0xdead ${vid}"
-		receiver_extra_args="--l2 --etype=0xdead"
+		sender_extra_args="${sender_extra_args} --l2 --etype=0xdead ${vid}"
+		receiver_extra_args="${receiver_extra_args} --l2 --etype=0xdead"
 	else
-		extra_args="${extra_args} --l4 --ip-destination=${dst_ip}"
-		receiver_extra_args="--l4"
+		sender_extra_args="${sender_extra_args} --l4 --ip-destination=${dst_ip}"
+		receiver_extra_args="${receiver_extra_args} --l4"
 	fi
 
 	cpufreq_max ${ISOCHRON_CPU}
@@ -232,7 +232,6 @@ isochron_do()
 		--cycle-time ${cycle_time} \
 		--num-frames ${num_pkts} \
 		--frame-size 64 \
-		--txtime \
 		--utc-tai-offset ${UTC_TAI_OFFSET} \
 		--cpu-mask $((1 << ${ISOCHRON_CPU})) \
 		--sched-fifo \
@@ -240,8 +239,8 @@ isochron_do()
 		--client 127.0.0.1 \
 		--sync-threshold 5000 \
 		--output-file ${isochron_dat} \
-		${extra_args} \
-		--quiet
+		--quiet \
+		${sender_extra_args}
 
 	isochron_recv_stop 5000
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH for-faizal 3/4] selftests: net: tsn: allow isochron_do() to skip sync monitoring on sender too
  2023-12-21 13:25 [RFC PATCH for-faizal 0/4] tc-taprio selftests Vladimir Oltean
  2023-12-21 13:25 ` [RFC PATCH for-faizal 1/4] selftests: net: forwarding: allow veth pairs to be created with multiple queues Vladimir Oltean
  2023-12-21 13:25 ` [RFC PATCH for-faizal 2/4] selftests: net: tsn: push --txtime out of isochron_do() Vladimir Oltean
@ 2023-12-21 13:25 ` Vladimir Oltean
  2023-12-21 13:25 ` [RFC PATCH for-faizal 4/4] selftests: net: tsn: add tc-taprio test cases (WIP) Vladimir Oltean
  2023-12-22  6:28 ` [RFC PATCH for-faizal 0/4] tc-taprio selftests Hangbin Liu
  4 siblings, 0 replies; 6+ messages in thread
From: Vladimir Oltean @ 2023-12-21 13:25 UTC (permalink / raw)
  To: netdev; +Cc: Abdul Rahim, Faizal

For testing the tc-taprio software scheduling path, we don't need PTP
synchronization at all, but isochron_do() was written assuming that we
do.

Allow skipping the UNIX domain socket for the ptp4l instance on the
sender, and pass --omit-sync to isochron instead, so that it sends right
away and does not monitor the PTP quality.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 tools/testing/selftests/net/forwarding/tsn_lib.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/forwarding/tsn_lib.sh b/tools/testing/selftests/net/forwarding/tsn_lib.sh
index f081cebb1c65..189bf27bad76 100644
--- a/tools/testing/selftests/net/forwarding/tsn_lib.sh
+++ b/tools/testing/selftests/net/forwarding/tsn_lib.sh
@@ -204,6 +204,12 @@ isochron_do()
 		vid="--vid=${vid}"
 	fi
 
+	if [ -z "${sender_uds}" ]; then
+		sender_extra_args="${sender_extra_args} --omit-sync"
+	else
+		sender_extra_args="${sender_extra_args} --unix-domain-socket ${sender_uds}"
+	fi
+
 	if [ -z "${receiver_uds}" ]; then
 		sender_extra_args="${sender_extra_args} --omit-remote-sync"
 	fi
@@ -226,7 +232,6 @@ isochron_do()
 
 	isochron send \
 		--interface ${sender_if_name} \
-		--unix-domain-socket ${sender_uds} \
 		--priority ${priority} \
 		--base-time ${base_time} \
 		--cycle-time ${cycle_time} \
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH for-faizal 4/4] selftests: net: tsn: add tc-taprio test cases (WIP)
  2023-12-21 13:25 [RFC PATCH for-faizal 0/4] tc-taprio selftests Vladimir Oltean
                   ` (2 preceding siblings ...)
  2023-12-21 13:25 ` [RFC PATCH for-faizal 3/4] selftests: net: tsn: allow isochron_do() to skip sync monitoring on sender too Vladimir Oltean
@ 2023-12-21 13:25 ` Vladimir Oltean
  2023-12-22  6:28 ` [RFC PATCH for-faizal 0/4] tc-taprio selftests Hangbin Liu
  4 siblings, 0 replies; 6+ messages in thread
From: Vladimir Oltean @ 2023-12-21 13:25 UTC (permalink / raw)
  To: netdev; +Cc: Abdul Rahim, Faizal

Obviously this is unfinished. While we were discussing about tc-taprio
behavior during schedule changes in particular, it would be much better
if the tests could slowly build up towards that complicated case, and
make sure that the simpler cases work well first: a packet gets sent
when it should (when it's sent in band with its time slot), gets blocked
when it's sent out of band with its time slot, etc.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 .../testing/selftests/net/forwarding/Makefile |   1 +
 .../selftests/net/forwarding/tc_taprio.sh     | 143 ++++++++++++++++++
 .../selftests/net/forwarding/tsn_lib.sh       |  42 +++++
 3 files changed, 186 insertions(+)
 create mode 100755 tools/testing/selftests/net/forwarding/tc_taprio.sh

diff --git a/tools/testing/selftests/net/forwarding/Makefile b/tools/testing/selftests/net/forwarding/Makefile
index 452693514be4..8e8ed75a3aac 100644
--- a/tools/testing/selftests/net/forwarding/Makefile
+++ b/tools/testing/selftests/net/forwarding/Makefile
@@ -97,6 +97,7 @@ TEST_PROGS = bridge_fdb_learning_limit.sh \
 	tc_mpls_l2vpn.sh \
 	tc_police.sh \
 	tc_shblocks.sh \
+	tc_taprio.sh \
 	tc_tunnel_key.sh \
 	tc_vlan_modify.sh \
 	vxlan_asymmetric_ipv6.sh \
diff --git a/tools/testing/selftests/net/forwarding/tc_taprio.sh b/tools/testing/selftests/net/forwarding/tc_taprio.sh
new file mode 100755
index 000000000000..387cc0860d4f
--- /dev/null
+++ b/tools/testing/selftests/net/forwarding/tc_taprio.sh
@@ -0,0 +1,143 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+ALL_TESTS="in_band out_of_band cycle_extension"
+NUM_NETIFS=2
+VETH_OPTS="numtxqueues 8 numrxqueues 8"
+source lib.sh
+source tsn_lib.sh
+
+in_band()
+{
+	local basetime=$(clock_gettime CLOCK_REALTIME)
+	local window_size=$((NSEC_PER_SEC / 2))
+	local cycletime=$((2 * window_size))
+	local expected=1
+	local isochron_dat="$(mktemp)"
+	local window_start
+	local window_end
+
+	basetime=$((basetime + UTC_TAI_OFFSET * NSEC_PER_SEC))
+	basetime=$(round_up_with_margin $basetime $NSEC_PER_SEC $NSEC_PER_SEC)
+
+	tc qdisc replace dev $h1 root stab overhead 24 taprio num_tc 2 \
+		map 0 1 \
+		queues 1@0 1@1 \
+		base-time $basetime \
+		sched-entry S 0x3 500000000 \
+		sched-entry S 0x0 500000000 \
+		clockid CLOCK_TAI \
+		flags 0x0
+
+	isochron_do \
+		$h1 $h2 \
+		"" "" \
+		$((basetime + 2 * cycletime)) \
+		$cycletime \
+		0 \
+		${expected} \
+		"" \
+		1 \
+		"" \
+		"--omit-hwts --taprio --window-size $window_size" \
+		"--omit-hwts" \
+		"${isochron_dat}"
+
+	# Count all received packets by looking at the non-zero RX timestamps
+	received=$(isochron report \
+		--input-file "${isochron_dat}" \
+		--printf-format "%u\n" --printf-args "r" | \
+		grep -w -v '0' | wc -l)
+
+	if [ "${received}" = "${expected}" ]; then
+		RET=0
+	else
+		RET=1
+		echo "Expected isochron to receive ${expected} packets but received ${received}"
+	fi
+
+	tx_tstamp=$(isochron report \
+		--input-file "${isochron_dat}" \
+		--printf-format "%u\n" --printf-args "t")
+
+	window_start=$((basetime + 2 * cycletime))
+	window_end=$((window_start + window_size))
+
+	if (( tx_tstamp >= window_start && tx_tstamp <= window_end )); then
+		RET=0
+	else
+		RET=1
+		printf "Isochron TX timestamp %s sent outside expected window (%s - %s)\n" \
+			$(ns_to_time $tx_tstamp) \
+			$(ns_to_time $window_start) \
+			$(ns_to_time $window_end)
+	fi
+
+	log_test "${test_name}"
+
+	rm ${isochron_dat} 2> /dev/null
+
+	tc qdisc del dev $h1 root
+}
+
+out_of_band()
+{
+	:
+}
+
+cycle_extension()
+{
+	:
+}
+
+h1_create()
+{
+	simple_if_init $h1 192.0.2.1/24
+}
+
+h1_destroy()
+{
+	simple_if_fini $h1 192.0.2.1/24
+}
+
+h2_create()
+{
+	simple_if_init $h2 192.0.2.2/24
+}
+
+h2_destroy()
+{
+	simple_if_fini $h2 192.0.2.2/24
+}
+
+setup_prepare()
+{
+	h1=${NETIFS[p1]}
+	h2=${NETIFS[p2]}
+
+	vrf_prepare
+
+	h1_create
+	h2_create
+}
+
+cleanup()
+{
+	pre_cleanup
+
+	isochron_recv_stop
+
+	h2_destroy
+	h1_destroy
+
+	vrf_cleanup
+}
+
+trap cleanup EXIT
+
+setup_prepare
+setup_wait
+
+tests_run
+
+exit $EXIT_STATUS
diff --git a/tools/testing/selftests/net/forwarding/tsn_lib.sh b/tools/testing/selftests/net/forwarding/tsn_lib.sh
index 189bf27bad76..e72a18a1dee0 100644
--- a/tools/testing/selftests/net/forwarding/tsn_lib.sh
+++ b/tools/testing/selftests/net/forwarding/tsn_lib.sh
@@ -5,6 +5,8 @@
 REQUIRE_ISOCHRON=${REQUIRE_ISOCHRON:=yes}
 REQUIRE_LINUXPTP=${REQUIRE_LINUXPTP:=yes}
 
+NSEC_PER_SEC=1000000000
+
 # Tunables
 UTC_TAI_OFFSET=37
 ISOCHRON_CPU=1
@@ -18,6 +20,7 @@ fi
 if [[ "$REQUIRE_LINUXPTP" = "yes" ]]; then
 	require_command phc2sys
 	require_command ptp4l
+	require_command phc_ctl
 fi
 
 phc2sys_start()
@@ -251,3 +254,42 @@ isochron_do()
 
 	cpufreq_restore ${ISOCHRON_CPU}
 }
+
+# Convert a time specifier from 1.23456789 format to nanoseconds
+time_to_ns()
+{
+	local time="$1"
+	local sec=${time%%.*}
+	local nsec=${time##*.}
+
+	echo $((sec * NSEC_PER_SEC + 10#$nsec))
+}
+
+ns_to_time()
+{
+	local nsec="$1"
+	local sec=$((nsec / NSEC_PER_SEC))
+
+	nsec=$((nsec - (sec * NSEC_PER_SEC)))
+
+	printf "%d.%09lld" $sec $nsec
+}
+
+clock_gettime()
+{
+	local clkid=$1; shift
+	local time=$(phc_ctl $clkid get | awk '/clock time is/ { print $5 }')
+
+	echo $(time_to_ns $time)
+}
+
+# Round up value to next multiple, leaving a specified margin
+round_up_with_margin()
+{
+	local val=$1; shift
+	local multiple=$1; shift
+	local margin=$1; shift
+
+	val=$((val + margin))
+	echo $((((val + margin - 1) / margin) * margin))
+}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH for-faizal 0/4] tc-taprio selftests
  2023-12-21 13:25 [RFC PATCH for-faizal 0/4] tc-taprio selftests Vladimir Oltean
                   ` (3 preceding siblings ...)
  2023-12-21 13:25 ` [RFC PATCH for-faizal 4/4] selftests: net: tsn: add tc-taprio test cases (WIP) Vladimir Oltean
@ 2023-12-22  6:28 ` Hangbin Liu
  4 siblings, 0 replies; 6+ messages in thread
From: Hangbin Liu @ 2023-12-22  6:28 UTC (permalink / raw)
  To: Vladimir Oltean; +Cc: netdev, Abdul Rahim, Faizal

On Thu, Dec 21, 2023 at 03:25:17PM +0200, Vladimir Oltean wrote:
> Unfortunately the isochron version from debian will not work on veth
> pairs, I had to make some changes and add the --omit-hwts option to
> the sender and receiver programs. The modified version is on this branch
> here, I will merge the changes to 'master' once I have enough confidence
> in them.
> https://github.com/vladimiroltean/isochron/tree/omit-hwts
> 
> For testing the tc-taprio software scheduling path, we don't need PTP
> synchronization or hardware timestamps anyway.
> 
> This is just a skeleton that I'm hoping Faizal can pick up and extend
> with more test cases for dynamic schedule changes. It should run
> primarily on the veth driver, but should behave the same on any network
> driver as well, including those who also have tc-taprio offload.

Tested-by: Hangbin Liu <liuhangbin@gmail.com>
Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-22  6:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-21 13:25 [RFC PATCH for-faizal 0/4] tc-taprio selftests Vladimir Oltean
2023-12-21 13:25 ` [RFC PATCH for-faizal 1/4] selftests: net: forwarding: allow veth pairs to be created with multiple queues Vladimir Oltean
2023-12-21 13:25 ` [RFC PATCH for-faizal 2/4] selftests: net: tsn: push --txtime out of isochron_do() Vladimir Oltean
2023-12-21 13:25 ` [RFC PATCH for-faizal 3/4] selftests: net: tsn: allow isochron_do() to skip sync monitoring on sender too Vladimir Oltean
2023-12-21 13:25 ` [RFC PATCH for-faizal 4/4] selftests: net: tsn: add tc-taprio test cases (WIP) Vladimir Oltean
2023-12-22  6:28 ` [RFC PATCH for-faizal 0/4] tc-taprio selftests Hangbin Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox