Skip to content

Commit d5417f9

Browse files
committed
selftests: net: Add busy_poll_test
JIRA: https://issues.redhat.com/browse/RHEL-77189 Upstream Status: linux.git Conflicts:\ - The chunk in the Makefile differs as upstream commit 9bb88c6 ("selftests: net: test extacks in netlink dumps") was backported before in c10s and as ncdevmem was not moved under drivers/net/hw yet in c10s. commit 347fcdc Author: Joe Damato <jdamato@fastly.com> Date: Sat Nov 9 05:02:35 2024 +0000 selftests: net: Add busy_poll_test Add an epoll busy poll test using netdevsim. This test is comprised of: - busy_poller (via busy_poller.c) - busy_poll_test.sh which loads netdevsim, sets up network namespaces, and runs busy_poller to receive data and socat to send data. The selftest tests two different scenarios: - busy poll (the pre-existing version in the kernel) - busy poll with suspend enabled (what this series adds) The data transmit is a 1MiB temporary file generated from /dev/urandom and the test is considered passing if the md5sum of the input file to socat matches the md5sum of the output file from busy_poller. netdevsim was chosen instead of veth due to netdevsim's support for netdev-genl. For now, this test uses the functionality that netdevsim provides. In the future, perhaps netdevsim can be extended to emulate device IRQs to more thoroughly test all pre-existing kernel options (like defer_hard_irqs) and suspend. Signed-off-by: Joe Damato <jdamato@fastly.com> Co-developed-by: Martin Karsten <mkarsten@uwaterloo.ca> Signed-off-by: Martin Karsten <mkarsten@uwaterloo.ca> Acked-by: Stanislav Fomichev <sdf@fomichev.me> Reviewed-by: Willem de Bruijn <willemb@google.com> Link: https://patch.msgid.link/20241109050245.191288-6-jdamato@fastly.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent 147cb25 commit d5417f9

File tree

4 files changed

+514
-1
lines changed

4 files changed

+514
-1
lines changed

tools/testing/selftests/net/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
bind_bhash
33
bind_timewait
44
bind_wildcard
5+
busy_poller
56
cmsg_sender
67
diag_uid
78
epoll_busy_poll

tools/testing/selftests/net/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ TEST_PROGS += vlan_hw_filter.sh
100100
TEST_PROGS += vlan_bridge_binding.sh
101101
TEST_PROGS += bpf_offload.py
102102
TEST_PROGS += ipv6_route_update_soft_lockup.sh
103+
TEST_PROGS += busy_poll_test.sh
103104

104105
# YNL files, must be before "include ..lib.mk"
105-
YNL_GEN_FILES := ncdevmem netlink-dumps
106+
YNL_GEN_FILES := ncdevmem busy_poller netlink-dumps
106107
TEST_GEN_FILES += $(YNL_GEN_FILES)
107108

108109
TEST_FILES := settings
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
source net_helper.sh
4+
5+
NSIM_SV_ID=$((256 + RANDOM % 256))
6+
NSIM_SV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_SV_ID
7+
NSIM_CL_ID=$((512 + RANDOM % 256))
8+
NSIM_CL_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_CL_ID
9+
10+
NSIM_DEV_SYS_NEW=/sys/bus/netdevsim/new_device
11+
NSIM_DEV_SYS_DEL=/sys/bus/netdevsim/del_device
12+
NSIM_DEV_SYS_LINK=/sys/bus/netdevsim/link_device
13+
NSIM_DEV_SYS_UNLINK=/sys/bus/netdevsim/unlink_device
14+
15+
SERVER_IP=192.168.1.1
16+
CLIENT_IP=192.168.1.2
17+
SERVER_PORT=48675
18+
19+
# busy poll config
20+
MAX_EVENTS=8
21+
BUSY_POLL_USECS=0
22+
BUSY_POLL_BUDGET=16
23+
PREFER_BUSY_POLL=1
24+
25+
# IRQ deferral config
26+
NAPI_DEFER_HARD_IRQS=100
27+
GRO_FLUSH_TIMEOUT=50000
28+
SUSPEND_TIMEOUT=20000000
29+
30+
setup_ns()
31+
{
32+
set -e
33+
ip netns add nssv
34+
ip netns add nscl
35+
36+
NSIM_SV_NAME=$(find $NSIM_SV_SYS/net -maxdepth 1 -type d ! \
37+
-path $NSIM_SV_SYS/net -exec basename {} \;)
38+
NSIM_CL_NAME=$(find $NSIM_CL_SYS/net -maxdepth 1 -type d ! \
39+
-path $NSIM_CL_SYS/net -exec basename {} \;)
40+
41+
# ensure the server has 1 queue
42+
ethtool -L $NSIM_SV_NAME combined 1 2>/dev/null
43+
44+
ip link set $NSIM_SV_NAME netns nssv
45+
ip link set $NSIM_CL_NAME netns nscl
46+
47+
ip netns exec nssv ip addr add "${SERVER_IP}/24" dev $NSIM_SV_NAME
48+
ip netns exec nscl ip addr add "${CLIENT_IP}/24" dev $NSIM_CL_NAME
49+
50+
ip netns exec nssv ip link set dev $NSIM_SV_NAME up
51+
ip netns exec nscl ip link set dev $NSIM_CL_NAME up
52+
53+
set +e
54+
}
55+
56+
cleanup_ns()
57+
{
58+
ip netns del nscl
59+
ip netns del nssv
60+
}
61+
62+
test_busypoll()
63+
{
64+
suspend_value=${1:-0}
65+
tmp_file=$(mktemp)
66+
out_file=$(mktemp)
67+
68+
# fill a test file with random data
69+
dd if=/dev/urandom of=${tmp_file} bs=1M count=1 2> /dev/null
70+
71+
timeout -k 1s 30s ip netns exec nssv ./busy_poller \
72+
-p${SERVER_PORT} \
73+
-b${SERVER_IP} \
74+
-m${MAX_EVENTS} \
75+
-u${BUSY_POLL_USECS} \
76+
-P${PREFER_BUSY_POLL} \
77+
-g${BUSY_POLL_BUDGET} \
78+
-i${NSIM_SV_IFIDX} \
79+
-s${suspend_value} \
80+
-o${out_file}&
81+
82+
wait_local_port_listen nssv ${SERVER_PORT} tcp
83+
84+
ip netns exec nscl socat -u $tmp_file TCP:${SERVER_IP}:${SERVER_PORT}
85+
86+
wait
87+
88+
tmp_file_md5sum=$(md5sum $tmp_file | cut -f1 -d' ')
89+
out_file_md5sum=$(md5sum $out_file | cut -f1 -d' ')
90+
91+
if [ "$tmp_file_md5sum" = "$out_file_md5sum" ]; then
92+
res=0
93+
else
94+
echo "md5sum mismatch"
95+
echo "input file md5sum: ${tmp_file_md5sum}";
96+
echo "output file md5sum: ${out_file_md5sum}";
97+
res=1
98+
fi
99+
100+
rm $out_file $tmp_file
101+
102+
return $res
103+
}
104+
105+
test_busypoll_with_suspend()
106+
{
107+
test_busypoll ${SUSPEND_TIMEOUT}
108+
109+
return $?
110+
}
111+
112+
###
113+
### Code start
114+
###
115+
116+
modprobe netdevsim
117+
118+
# linking
119+
120+
echo $NSIM_SV_ID > $NSIM_DEV_SYS_NEW
121+
echo $NSIM_CL_ID > $NSIM_DEV_SYS_NEW
122+
udevadm settle
123+
124+
setup_ns
125+
126+
NSIM_SV_FD=$((256 + RANDOM % 256))
127+
exec {NSIM_SV_FD}</var/run/netns/nssv
128+
NSIM_SV_IFIDX=$(ip netns exec nssv cat /sys/class/net/$NSIM_SV_NAME/ifindex)
129+
130+
NSIM_CL_FD=$((256 + RANDOM % 256))
131+
exec {NSIM_CL_FD}</var/run/netns/nscl
132+
NSIM_CL_IFIDX=$(ip netns exec nscl cat /sys/class/net/$NSIM_CL_NAME/ifindex)
133+
134+
echo "$NSIM_SV_FD:$NSIM_SV_IFIDX $NSIM_CL_FD:$NSIM_CL_IFIDX" > \
135+
$NSIM_DEV_SYS_LINK
136+
137+
if [ $? -ne 0 ]; then
138+
echo "linking netdevsim1 with netdevsim2 should succeed"
139+
cleanup_ns
140+
exit 1
141+
fi
142+
143+
test_busypoll
144+
if [ $? -ne 0 ]; then
145+
echo "test_busypoll failed"
146+
cleanup_ns
147+
exit 1
148+
fi
149+
150+
test_busypoll_with_suspend
151+
if [ $? -ne 0 ]; then
152+
echo "test_busypoll_with_suspend failed"
153+
cleanup_ns
154+
exit 1
155+
fi
156+
157+
echo "$NSIM_SV_FD:$NSIM_SV_IFIDX" > $NSIM_DEV_SYS_UNLINK
158+
159+
echo $NSIM_CL_ID > $NSIM_DEV_SYS_DEL
160+
161+
cleanup_ns
162+
163+
modprobe -r netdevsim
164+
165+
exit 0

0 commit comments

Comments
 (0)