selftests: net/forwarding: spawn sh inside vrf to speed up ping loop
authorJakub Kicinski <kuba@kernel.org>
Sat, 17 Aug 2024 20:36:59 +0000 (13:36 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 20 Aug 2024 22:17:58 +0000 (15:17 -0700)
Looking at timestamped output of netdev CI reveals that
most of the time in forwarding tests for custom route
hashing is spent on a single case, namely the test which
uses ping (mausezahn does not support flow labels).

On a non-debug kernel we spend 714 of 730 total test
runtime (97%) on this test case. While having flow label
support in a traffic gen tool / mausezahn would be best,
we can significantly speed up the loop by putting ip vrf exec
outside of the iteration.

In a test of 1000 pings using a normal loop takes 50 seconds
to finish. While using:

  ip vrf exec $vrf sh -c "$loop-body"

takes 12 seconds (1/4 of the time).

Some of the slowness is likely due to our inefficient virtualization
setup, but even on my laptop running "ip link help" 16k times takes
25-30 seconds, so I think it's worth optimizing even for fastest
setups.

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://patch.msgid.link/20240817203659.712085-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/forwarding/custom_multipath_hash.sh
tools/testing/selftests/net/forwarding/gre_custom_multipath_hash.sh
tools/testing/selftests/net/forwarding/ip6gre_custom_multipath_hash.sh

index 1783c10215e5ce3e9912404bc31e9e959627d767..7d531f7091e6f4a6f7a726f662d40ba8886711e0 100755 (executable)
@@ -224,10 +224,10 @@ send_dst_ipv6()
 send_flowlabel()
 {
        # Generate 16384 echo requests, each with a random flow label.
-       for _ in $(seq 1 16384); do
-               ip vrf exec v$h1 \
-                       $PING6 2001:db8:4::2 -F 0 -c 1 -q >/dev/null 2>&1
-       done
+       ip vrf exec v$h1 sh -c \
+               "for _ in {1..16384}; do \
+                       $PING6 2001:db8:4::2 -F 0 -c 1 -q >/dev/null 2>&1; \
+               done"
 }
 
 send_src_udp6()
index 9788bd0f6e8b37d70d12d3447461d756b76b227b..dda11a4a9450a8450abb73e2bbabf735f48434dc 100755 (executable)
@@ -319,10 +319,10 @@ send_dst_ipv6()
 send_flowlabel()
 {
        # Generate 16384 echo requests, each with a random flow label.
-       for _ in $(seq 1 16384); do
-               ip vrf exec v$h1 \
-                       $PING6 2001:db8:2::2 -F 0 -c 1 -q >/dev/null 2>&1
-       done
+       ip vrf exec v$h1 sh -c \
+               "for _ in {1..16384}; do \
+                       $PING6 2001:db8:2::2 -F 0 -c 1 -q >/dev/null 2>&1; \
+               done"
 }
 
 send_src_udp6()
index 2ab9eaaa5532ae1aeb4284ba541b7b2ed6c2495f..e28b4a079e5250a44a70486932304a67ae6269dc 100755 (executable)
@@ -321,10 +321,10 @@ send_dst_ipv6()
 send_flowlabel()
 {
        # Generate 16384 echo requests, each with a random flow label.
-       for _ in $(seq 1 16384); do
-               ip vrf exec v$h1 \
-                       $PING6 2001:db8:2::2 -F 0 -c 1 -q >/dev/null 2>&1
-       done
+       ip vrf exec v$h1 sh -c \
+               "for _ in {1..16384}; do \
+                       $PING6 2001:db8:2::2 -F 0 -c 1 -q >/dev/null 2>&1; \
+               done"
 }
 
 send_src_udp6()