2 # SPDX-License-Identifier: GPL-2.0
4 # extended toeplitz test: test rxhash plus, optionally, either (1) rss mapping
5 # from rxhash to rx queue ('-rss') or (2) rps mapping from rxhash to cpu
8 # irq-pattern-prefix can be derived from /sys/kernel/irq/*/action,
9 # which is a driver-specific encoding.
11 # invoke as ./toeplitz.sh (-i <iface>) -u|-t -4|-6 \
12 # [(-rss -irq_prefix <irq-pattern-prefix>)|(-rps <rps_map>)]
14 source setup_loopback.sh
15 readonly SERVER_IP4
="192.168.1.200/24"
16 readonly SERVER_IP6
="fda8::1/64"
17 readonly SERVER_MAC
="aa:00:00:00:00:02"
19 readonly CLIENT_IP4
="192.168.1.100/24"
20 readonly CLIENT_IP6
="fda8::2/64"
21 readonly CLIENT_MAC
="aa:00:00:00:00:01"
24 KEY
="$(</proc/sys/net/core/netdev_rss_key)"
31 # Return the number of rxqs among which RSS is configured to spread packets.
32 # This is determined by reading the RSS indirection table using ethtool.
33 get_rss_cfg_num_rxqs
() {
34 echo $
(ethtool
-x "${DEV}" |
35 grep -E [[:space
:]]+[0-9]+:[[:space
:]]+ |
43 # Return a list of the receive irq handler cpus.
44 # The list is ordered by the irqs, so first rxq-0 cpu, then rxq-1 cpu, etc.
45 # Reads /sys/kernel/irq/ in order, so algorithm depends on
46 # irq_{rxq-0} < irq_{rxq-1}, etc.
49 # sort so that irq 2 is read before irq 10
50 SORTED_IRQS
=$
(for i
in /sys
/kernel
/irq
/*; do echo $i; done |
sort -V)
51 # Consider only as many queues as RSS actually uses. We assume that
52 # if RSS_CFG_NUM_RXQS=N, then RSS uses rxqs 0-(N-1).
53 RSS_CFG_NUM_RXQS
=$
(get_rss_cfg_num_rxqs
)
56 for i
in ${SORTED_IRQS}
58 [[ "${RXQ_COUNT}" -lt "${RSS_CFG_NUM_RXQS}" ]] ||
break
59 # lookup relevant IRQs by action name
60 [[ -e "$i/actions" ]] ||
continue
61 cat "$i/actions" |
grep -q "${IRQ_PATTERN}" ||
continue
62 irqname
=$
(<"$i/actions")
64 # does the IRQ get called
65 irqcount
=$
(cat "$i/per_cpu_count" |
tr -d '0,')
66 [[ -n "${irqcount}" ]] ||
continue
70 cpu
=$
(cat "/proc/irq/$irq/smp_affinity_list")
72 if [[ -z "${CPUS}" ]]; then
77 RXQ_COUNT
=$
((RXQ_COUNT
+1))
83 get_disable_rfs_cmd
() {
84 echo "echo 0 > /proc/sys/net/core/rps_sock_flow_entries;"
87 get_set_rps_bitmaps_cmd
() {
89 for i
in /sys
/class
/net
/${DEV}/queues
/rx-
*/rps_cpus
91 CMD
="${CMD} echo $1 > ${i};"
97 get_disable_rps_cmd
() {
98 echo "$(get_set_rps_bitmaps_cmd 0)"
106 check_nic_rxhash_enabled
() {
107 local -r pattern
="receive-hashing:\ on"
109 ethtool
-k "${DEV}" |
grep -q "${pattern}" || die
"rxhash must be enabled"
116 while [[ "$1" =~
"-" ]]; do
117 if [[ "$1" = "-irq_prefix" ]]; then
119 IRQ_PATTERN
="^$1-[0-9]*$"
120 elif [[ "$1" = "-u" ||
"$1" = "-t" ]]; then
122 elif [[ "$1" = "-4" ]]; then
124 SERVER_IP
="${SERVER_IP4}"
125 CLIENT_IP
="${CLIENT_IP4}"
126 elif [[ "$1" = "-6" ]]; then
128 SERVER_IP
="${SERVER_IP6}"
129 CLIENT_IP
="${CLIENT_IP6}"
130 elif [[ "$1" = "-rss" ]]; then
132 elif [[ "$1" = "-rps" ]]; then
135 elif [[ "$1" = "-i" ]]; then
139 die
"Usage: ${prog} (-i <iface>) -u|-t -4|-6 \
140 [(-rss -irq_prefix <irq-pattern-prefix>)|(-rps <rps_map>)]"
147 setup_loopback_environment
"${DEV}"
149 # Set up server_ns namespace and client_ns namespace
150 setup_macvlan_ns
"${DEV}" $server_ns server \
151 "${SERVER_MAC}" "${SERVER_IP}"
152 setup_macvlan_ns
"${DEV}" $client_ns client \
153 "${CLIENT_MAC}" "${CLIENT_IP}"
157 cleanup_macvlan_ns
$server_ns server
$client_ns client
158 cleanup_loopback
"${DEV}"
166 check_nic_rxhash_enabled
168 # Actual test starts here
169 if [[ "${TEST_RSS}" = true
]]; then
170 # RPS/RFS must be disabled because they move packets between cpus,
171 # which breaks the PACKET_FANOUT_CPU identification of RSS decisions.
172 eval "$(get_disable_rfs_cmd) $(get_disable_rps_cmd)" \
173 ip netns
exec $server_ns .
/toeplitz
"${IP_FLAG}" "${PROTO_FLAG}" \
174 -d "${PORT}" -i "${DEV}" -k "${KEY}" -T 1000 \
175 -C "$(get_rx_irq_cpus)" -s -v &
176 elif [[ ! -z "${RPS_MAP}" ]]; then
177 eval "$(get_disable_rfs_cmd) $(get_set_rps_bitmaps_cmd ${RPS_MAP})" \
178 ip netns
exec $server_ns .
/toeplitz
"${IP_FLAG}" "${PROTO_FLAG}" \
179 -d "${PORT}" -i "${DEV}" -k "${KEY}" -T 1000 \
180 -r "0x${RPS_MAP}" -s -v &
182 ip netns
exec $server_ns .
/toeplitz
"${IP_FLAG}" "${PROTO_FLAG}" \
183 -d "${PORT}" -i "${DEV}" -k "${KEY}" -T 1000 -s -v &
188 ip netns
exec $client_ns .
/toeplitz_client.sh
"${PROTO_FLAG}" \
189 "${IP_FLAG}" "${SERVER_IP%%/*}" "${PORT}" &
195 kill -9 "${client_pid}"
196 if [[ "${exit_code}" -eq 0 ]]; then
197 echo "Test Succeeded!"