~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/toeplitz.sh

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/net/toeplitz.sh (Architecture i386) and /tools/testing/selftests/net/toeplitz.sh (Architecture sparc)


  1 #!/bin/bash                                         1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3 #                                                   3 #
  4 # extended toeplitz test: test rxhash plus, op      4 # extended toeplitz test: test rxhash plus, optionally, either (1) rss mapping
  5 # from rxhash to rx queue ('-rss') or (2) rps       5 # from rxhash to rx queue ('-rss') or (2) rps mapping from rxhash to cpu
  6 # ('-rps <rps_map>')                                6 # ('-rps <rps_map>')
  7 #                                                   7 #
  8 # irq-pattern-prefix can be derived from /sys/      8 # irq-pattern-prefix can be derived from /sys/kernel/irq/*/action,
  9 # which is a driver-specific encoding.              9 # which is a driver-specific encoding.
 10 #                                                  10 #
 11 # invoke as ./toeplitz.sh (-i <iface>) -u|-t -     11 # invoke as ./toeplitz.sh (-i <iface>) -u|-t -4|-6 \
 12 # [(-rss -irq_prefix <irq-pattern-prefix>)|(-r     12 # [(-rss -irq_prefix <irq-pattern-prefix>)|(-rps <rps_map>)]
 13                                                    13 
 14 source setup_loopback.sh                           14 source setup_loopback.sh
 15 readonly SERVER_IP4="192.168.1.200/24"             15 readonly SERVER_IP4="192.168.1.200/24"
 16 readonly SERVER_IP6="fda8::1/64"                   16 readonly SERVER_IP6="fda8::1/64"
 17 readonly SERVER_MAC="aa:00:00:00:00:02"            17 readonly SERVER_MAC="aa:00:00:00:00:02"
 18                                                    18 
 19 readonly CLIENT_IP4="192.168.1.100/24"             19 readonly CLIENT_IP4="192.168.1.100/24"
 20 readonly CLIENT_IP6="fda8::2/64"                   20 readonly CLIENT_IP6="fda8::2/64"
 21 readonly CLIENT_MAC="aa:00:00:00:00:01"            21 readonly CLIENT_MAC="aa:00:00:00:00:01"
 22                                                    22 
 23 PORT=8000                                          23 PORT=8000
 24 KEY="$(</proc/sys/net/core/netdev_rss_key)"        24 KEY="$(</proc/sys/net/core/netdev_rss_key)"
 25 TEST_RSS=false                                     25 TEST_RSS=false
 26 RPS_MAP=""                                         26 RPS_MAP=""
 27 PROTO_FLAG=""                                      27 PROTO_FLAG=""
 28 IP_FLAG=""                                         28 IP_FLAG=""
 29 DEV="eth0"                                         29 DEV="eth0"
 30                                                    30 
 31 # Return the number of rxqs among which RSS is     31 # Return the number of rxqs among which RSS is configured to spread packets.
 32 # This is determined by reading the RSS indire     32 # This is determined by reading the RSS indirection table using ethtool.
 33 get_rss_cfg_num_rxqs() {                           33 get_rss_cfg_num_rxqs() {
 34         echo $(ethtool -x "${DEV}" |               34         echo $(ethtool -x "${DEV}" |
 35                 grep -E [[:space:]]+[0-9]+:[[:     35                 grep -E [[:space:]]+[0-9]+:[[:space:]]+ |
 36                 cut -d: -f2- |                     36                 cut -d: -f2- |
 37                 awk '{$1=$1};1' |                  37                 awk '{$1=$1};1' |
 38                 tr ' ' '\n' |                      38                 tr ' ' '\n' |
 39                 sort -u |                          39                 sort -u |
 40                 wc -l)                             40                 wc -l)
 41 }                                                  41 }
 42                                                    42 
 43 # Return a list of the receive irq handler cpu     43 # Return a list of the receive irq handler cpus.
 44 # The list is ordered by the irqs, so first rx     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 algorith     45 # Reads /sys/kernel/irq/ in order, so algorithm depends on
 46 # irq_{rxq-0} < irq_{rxq-1}, etc.                  46 # irq_{rxq-0} < irq_{rxq-1}, etc.
 47 get_rx_irq_cpus() {                                47 get_rx_irq_cpus() {
 48         CPUS=""                                    48         CPUS=""
 49         # sort so that irq 2 is read before ir     49         # sort so that irq 2 is read before irq 10
 50         SORTED_IRQS=$(for i in /sys/kernel/irq     50         SORTED_IRQS=$(for i in /sys/kernel/irq/*; do echo $i; done | sort -V)
 51         # Consider only as many queues as RSS      51         # Consider only as many queues as RSS actually uses. We assume that
 52         # if RSS_CFG_NUM_RXQS=N, then RSS uses     52         # if RSS_CFG_NUM_RXQS=N, then RSS uses rxqs 0-(N-1).
 53         RSS_CFG_NUM_RXQS=$(get_rss_cfg_num_rxq     53         RSS_CFG_NUM_RXQS=$(get_rss_cfg_num_rxqs)
 54         RXQ_COUNT=0                                54         RXQ_COUNT=0
 55                                                    55 
 56         for i in ${SORTED_IRQS}                    56         for i in ${SORTED_IRQS}
 57         do                                         57         do
 58                 [[ "${RXQ_COUNT}" -lt "${RSS_C     58                 [[ "${RXQ_COUNT}" -lt "${RSS_CFG_NUM_RXQS}" ]] || break
 59                 # lookup relevant IRQs by acti     59                 # lookup relevant IRQs by action name
 60                 [[ -e "$i/actions" ]] || conti     60                 [[ -e "$i/actions" ]] || continue
 61                 cat "$i/actions" | grep -q "${     61                 cat "$i/actions" | grep -q "${IRQ_PATTERN}" || continue
 62                 irqname=$(<"$i/actions")           62                 irqname=$(<"$i/actions")
 63                                                    63 
 64                 # does the IRQ get called          64                 # does the IRQ get called
 65                 irqcount=$(cat "$i/per_cpu_cou     65                 irqcount=$(cat "$i/per_cpu_count" | tr -d '0,')
 66                 [[ -n "${irqcount}" ]] || cont     66                 [[ -n "${irqcount}" ]] || continue
 67                                                    67 
 68                 # lookup CPU                       68                 # lookup CPU
 69                 irq=$(basename "$i")               69                 irq=$(basename "$i")
 70                 cpu=$(cat "/proc/irq/$irq/smp_     70                 cpu=$(cat "/proc/irq/$irq/smp_affinity_list")
 71                                                    71 
 72                 if [[ -z "${CPUS}" ]]; then        72                 if [[ -z "${CPUS}" ]]; then
 73                         CPUS="${cpu}"              73                         CPUS="${cpu}"
 74                 else                               74                 else
 75                         CPUS="${CPUS},${cpu}"      75                         CPUS="${CPUS},${cpu}"
 76                 fi                                 76                 fi
 77                 RXQ_COUNT=$((RXQ_COUNT+1))         77                 RXQ_COUNT=$((RXQ_COUNT+1))
 78         done                                       78         done
 79                                                    79 
 80         echo "${CPUS}"                             80         echo "${CPUS}"
 81 }                                                  81 }
 82                                                    82 
 83 get_disable_rfs_cmd() {                            83 get_disable_rfs_cmd() {
 84         echo "echo 0 > /proc/sys/net/core/rps_     84         echo "echo 0 > /proc/sys/net/core/rps_sock_flow_entries;"
 85 }                                                  85 }
 86                                                    86 
 87 get_set_rps_bitmaps_cmd() {                        87 get_set_rps_bitmaps_cmd() {
 88         CMD=""                                     88         CMD=""
 89         for i in /sys/class/net/${DEV}/queues/     89         for i in /sys/class/net/${DEV}/queues/rx-*/rps_cpus
 90         do                                         90         do
 91                 CMD="${CMD} echo $1 > ${i};"       91                 CMD="${CMD} echo $1 > ${i};"
 92         done                                       92         done
 93                                                    93 
 94         echo "${CMD}"                              94         echo "${CMD}"
 95 }                                                  95 }
 96                                                    96 
 97 get_disable_rps_cmd() {                            97 get_disable_rps_cmd() {
 98         echo "$(get_set_rps_bitmaps_cmd 0)"        98         echo "$(get_set_rps_bitmaps_cmd 0)"
 99 }                                                  99 }
100                                                   100 
101 die() {                                           101 die() {
102         echo "$1"                                 102         echo "$1"
103         exit 1                                    103         exit 1
104 }                                                 104 }
105                                                   105 
106 check_nic_rxhash_enabled() {                      106 check_nic_rxhash_enabled() {
107         local -r pattern="receive-hashing:\ on    107         local -r pattern="receive-hashing:\ on"
108                                                   108 
109         ethtool -k "${DEV}" | grep -q "${patte    109         ethtool -k "${DEV}" | grep -q "${pattern}" || die "rxhash must be enabled"
110 }                                                 110 }
111                                                   111 
112 parse_opts() {                                    112 parse_opts() {
113         local prog=$0                             113         local prog=$0
114         shift 1                                   114         shift 1
115                                                   115 
116         while [[ "$1" =~ "-" ]]; do               116         while [[ "$1" =~ "-" ]]; do
117                 if [[ "$1" = "-irq_prefix" ]];    117                 if [[ "$1" = "-irq_prefix" ]]; then
118                         shift                     118                         shift
119                         IRQ_PATTERN="^$1-[0-9]    119                         IRQ_PATTERN="^$1-[0-9]*$"
120                 elif [[ "$1" = "-u" || "$1" =     120                 elif [[ "$1" = "-u" || "$1" = "-t" ]]; then
121                         PROTO_FLAG="$1"           121                         PROTO_FLAG="$1"
122                 elif [[ "$1" = "-4" ]]; then      122                 elif [[ "$1" = "-4" ]]; then
123                         IP_FLAG="$1"              123                         IP_FLAG="$1"
124                         SERVER_IP="${SERVER_IP    124                         SERVER_IP="${SERVER_IP4}"
125                         CLIENT_IP="${CLIENT_IP    125                         CLIENT_IP="${CLIENT_IP4}"
126                 elif [[ "$1" = "-6" ]]; then      126                 elif [[ "$1" = "-6" ]]; then
127                         IP_FLAG="$1"              127                         IP_FLAG="$1"
128                         SERVER_IP="${SERVER_IP    128                         SERVER_IP="${SERVER_IP6}"
129                         CLIENT_IP="${CLIENT_IP    129                         CLIENT_IP="${CLIENT_IP6}"
130                 elif [[ "$1" = "-rss" ]]; then    130                 elif [[ "$1" = "-rss" ]]; then
131                         TEST_RSS=true             131                         TEST_RSS=true
132                 elif [[ "$1" = "-rps" ]]; then    132                 elif [[ "$1" = "-rps" ]]; then
133                         shift                     133                         shift
134                         RPS_MAP="$1"              134                         RPS_MAP="$1"
135                 elif [[ "$1" = "-i" ]]; then      135                 elif [[ "$1" = "-i" ]]; then
136                         shift                     136                         shift
137                         DEV="$1"                  137                         DEV="$1"
138                 else                              138                 else
139                         die "Usage: ${prog} (-    139                         die "Usage: ${prog} (-i <iface>) -u|-t -4|-6 \
140                              [(-rss -irq_prefi    140                              [(-rss -irq_prefix <irq-pattern-prefix>)|(-rps <rps_map>)]"
141                 fi                                141                 fi
142                 shift                             142                 shift
143         done                                      143         done
144 }                                                 144 }
145                                                   145 
146 setup() {                                         146 setup() {
147         setup_loopback_environment "${DEV}"       147         setup_loopback_environment "${DEV}"
148                                                   148 
149         # Set up server_ns namespace and clien    149         # Set up server_ns namespace and client_ns namespace
150         setup_macvlan_ns "${DEV}" $server_ns s    150         setup_macvlan_ns "${DEV}" $server_ns server \
151         "${SERVER_MAC}" "${SERVER_IP}"            151         "${SERVER_MAC}" "${SERVER_IP}"
152         setup_macvlan_ns "${DEV}" $client_ns c    152         setup_macvlan_ns "${DEV}" $client_ns client \
153         "${CLIENT_MAC}" "${CLIENT_IP}"            153         "${CLIENT_MAC}" "${CLIENT_IP}"
154 }                                                 154 }
155                                                   155 
156 cleanup() {                                       156 cleanup() {
157         cleanup_macvlan_ns $server_ns server $    157         cleanup_macvlan_ns $server_ns server $client_ns client
158         cleanup_loopback "${DEV}"                 158         cleanup_loopback "${DEV}"
159 }                                                 159 }
160                                                   160 
161 parse_opts $0 $@                                  161 parse_opts $0 $@
162                                                   162 
163 setup                                             163 setup
164 trap cleanup EXIT                                 164 trap cleanup EXIT
165                                                   165 
166 check_nic_rxhash_enabled                          166 check_nic_rxhash_enabled
167                                                   167 
168 # Actual test starts here                         168 # Actual test starts here
169 if [[ "${TEST_RSS}" = true ]]; then               169 if [[ "${TEST_RSS}" = true ]]; then
170         # RPS/RFS must be disabled because the    170         # RPS/RFS must be disabled because they move packets between cpus,
171         # which breaks the PACKET_FANOUT_CPU i    171         # which breaks the PACKET_FANOUT_CPU identification of RSS decisions.
172         eval "$(get_disable_rfs_cmd) $(get_dis    172         eval "$(get_disable_rfs_cmd) $(get_disable_rps_cmd)" \
173           ip netns exec $server_ns ./toeplitz     173           ip netns exec $server_ns ./toeplitz "${IP_FLAG}" "${PROTO_FLAG}" \
174           -d "${PORT}" -i "${DEV}" -k "${KEY}"    174           -d "${PORT}" -i "${DEV}" -k "${KEY}" -T 1000 \
175           -C "$(get_rx_irq_cpus)" -s -v &         175           -C "$(get_rx_irq_cpus)" -s -v &
176 elif [[ ! -z "${RPS_MAP}" ]]; then                176 elif [[ ! -z "${RPS_MAP}" ]]; then
177         eval "$(get_disable_rfs_cmd) $(get_set    177         eval "$(get_disable_rfs_cmd) $(get_set_rps_bitmaps_cmd ${RPS_MAP})" \
178           ip netns exec $server_ns ./toeplitz     178           ip netns exec $server_ns ./toeplitz "${IP_FLAG}" "${PROTO_FLAG}" \
179           -d "${PORT}" -i "${DEV}" -k "${KEY}"    179           -d "${PORT}" -i "${DEV}" -k "${KEY}" -T 1000 \
180           -r "0x${RPS_MAP}" -s -v &               180           -r "0x${RPS_MAP}" -s -v &
181 else                                              181 else
182         ip netns exec $server_ns ./toeplitz "$    182         ip netns exec $server_ns ./toeplitz "${IP_FLAG}" "${PROTO_FLAG}" \
183           -d "${PORT}" -i "${DEV}" -k "${KEY}"    183           -d "${PORT}" -i "${DEV}" -k "${KEY}" -T 1000 -s -v &
184 fi                                                184 fi
185                                                   185 
186 server_pid=$!                                     186 server_pid=$!
187                                                   187 
188 ip netns exec $client_ns ./toeplitz_client.sh     188 ip netns exec $client_ns ./toeplitz_client.sh "${PROTO_FLAG}" \
189   "${IP_FLAG}" "${SERVER_IP%%/*}" "${PORT}" &     189   "${IP_FLAG}" "${SERVER_IP%%/*}" "${PORT}" &
190                                                   190 
191 client_pid=$!                                     191 client_pid=$!
192                                                   192 
193 wait "${server_pid}"                              193 wait "${server_pid}"
194 exit_code=$?                                      194 exit_code=$?
195 kill -9 "${client_pid}"                           195 kill -9 "${client_pid}"
196 if [[ "${exit_code}" -eq 0 ]]; then               196 if [[ "${exit_code}" -eq 0 ]]; then
197         echo "Test Succeeded!"                    197         echo "Test Succeeded!"
198 fi                                                198 fi
199 exit "${exit_code}"                               199 exit "${exit_code}"
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php