drm/bridge: adv7511: Switch to atomic operations
[drm/drm-misc.git] / tools / testing / selftests / net / rps_default_mask.sh
blob4287a85298907969dbd7df7da0e1969494f7857e
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 readonly ksft_skip=4
5 readonly cpus=$(nproc)
6 ret=0
8 [ $cpus -gt 2 ] || exit $ksft_skip
10 readonly INITIAL_RPS_DEFAULT_MASK=$(cat /proc/sys/net/core/rps_default_mask)
11 readonly TAG="$(mktemp -u XXXXXX)"
12 readonly VETH="veth${TAG}"
13 readonly NETNS="ns-${TAG}"
15 setup() {
16 ip netns add "${NETNS}"
17 ip -netns "${NETNS}" link set lo up
20 cleanup() {
21 echo $INITIAL_RPS_DEFAULT_MASK > /proc/sys/net/core/rps_default_mask
22 ip netns del $NETNS
25 chk_rps() {
26 local rps_mask expected_rps_mask=$4
27 local dev_name=$3
28 local netns=$2
29 local cmd="cat"
30 local msg=$1
32 [ -n "$netns" ] && cmd="ip netns exec $netns $cmd"
34 rps_mask=$($cmd /sys/class/net/$dev_name/queues/rx-0/rps_cpus)
35 printf "%-60s" "$msg"
37 # In case there is more than 32 CPUs we need to remove commas from masks
38 rps_mask=${rps_mask//,}
39 expected_rps_mask=${expected_rps_mask//,}
40 if [ $rps_mask -eq $expected_rps_mask ]; then
41 echo "[ ok ]"
42 else
43 echo "[fail] expected $expected_rps_mask found $rps_mask"
44 ret=1
48 trap cleanup EXIT
50 echo 0 > /proc/sys/net/core/rps_default_mask
51 setup
52 chk_rps "empty rps_default_mask" $NETNS lo 0
53 cleanup
55 echo 1 > /proc/sys/net/core/rps_default_mask
56 setup
57 chk_rps "changing rps_default_mask dont affect existing devices" "" lo $INITIAL_RPS_DEFAULT_MASK
59 echo 3 > /proc/sys/net/core/rps_default_mask
60 chk_rps "changing rps_default_mask dont affect existing netns" $NETNS lo 0
62 ip link add name $VETH type veth peer netns $NETNS name $VETH
63 ip link set dev $VETH up
64 ip -n $NETNS link set dev $VETH up
65 chk_rps "changing rps_default_mask affect newly created devices" "" $VETH 3
66 chk_rps "changing rps_default_mask don't affect newly child netns[II]" $NETNS $VETH 0
67 ip link del dev $VETH
68 ip netns del $NETNS
70 setup
71 chk_rps "rps_default_mask is 0 by default in child netns" "$NETNS" lo 0
73 ip netns exec $NETNS sysctl -qw net.core.rps_default_mask=1
74 ip link add name $VETH type veth peer netns $NETNS name $VETH
75 chk_rps "changing rps_default_mask in child ns don't affect the main one" "" lo $INITIAL_RPS_DEFAULT_MASK
76 chk_rps "changing rps_default_mask in child ns affects new childns devices" $NETNS $VETH 1
77 chk_rps "changing rps_default_mask in child ns don't affect existing devices" $NETNS lo 0
79 exit $ret