diff mbox series

[net-next,4/5] selftest: netdevsim: Add devlink rate police sub-test

Message ID 20220620152647.2498927-5-dchumak@nvidia.com (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series devlink rate police limiter | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 11 maintainers not CCed: daniel@iogearbox.net songliubraving@fb.com ast@kernel.org bpf@vger.kernel.org linux-kselftest@vger.kernel.org yhs@fb.com john.fastabend@gmail.com kafai@fb.com shuah@kernel.org andrii@kernel.org kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success net selftest script(s) already in Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Dima Chumak June 20, 2022, 3:26 p.m. UTC
Test verifies that netdevsim VFs and groups can set and retrieve
the new rate limit_type police attributes via devlink API.

Signed-off-by: Dima Chumak <dchumak@nvidia.com>
---
 .../drivers/net/netdevsim/devlink.sh          | 215 ++++++++++++++++--
 1 file changed, 200 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
index 9de1d123f4f5..40392dcbb30e 100755
--- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
@@ -534,6 +534,15 @@  rate_attr_set()
 	devlink port function rate set $handle $name $value$units
 }
 
+rate_police_attr_set()
+{
+	local handle=$1
+	local name=$2
+	local value=$3
+
+	devlink port function rate set $handle limit_type police $name $value
+}
+
 rate_attr_get()
 {
 	local handle=$1
@@ -542,7 +551,7 @@  rate_attr_get()
 	cmd_jq "devlink port function rate show $handle -j" '.[][].'$name
 }
 
-rate_attr_tx_rate_check()
+rate_attr_shaping_rate_check()
 {
 	local handle=$1
 	local name=$2
@@ -563,6 +572,35 @@  rate_attr_tx_rate_check()
 	check_err $? "Unexpected $name attr value $api_value != $rate"
 }
 
+rate_attr_police_rate_check()
+{
+	local handle=$1
+	local name=$2
+	local rate=$3
+	local debug_file=$4
+
+	rate_police_attr_set $handle $name $rate
+	check_err $? "Failed to set $name value"
+
+	local debug_value=$(cat $debug_file)
+	check_err $? "Failed to read $name value from debugfs"
+
+	# undo bits->bytes conversion forced by devlink
+	case $name in ([rt]x_max) debug_value=$((debug_value * 8)) ;; esac
+
+	[ "$debug_value" == "$rate" ]
+	check_err $? "Unexpected $name debug value $debug_value != $rate"
+
+	local api_value=$(rate_attr_get $handle $name)
+	check_err $? "Failed to get $name attr value"
+
+	# undo bits->bytes conversion forced by devlink
+	case $name in ([rt]x_max) api_value=$((api_value * 8)) ;; esac
+
+	[ "$api_value" == "$rate" ]
+	check_err $? "Unexpected $name attr value $api_value != $rate"
+}
+
 rate_attr_parent_check()
 {
 	local handle=$1
@@ -586,8 +624,9 @@  rate_attr_parent_check()
 rate_node_add()
 {
 	local handle=$1
+	local limit_type=${2:+limit_type $2}
 
-	devlink port function rate add $handle
+	devlink port function rate add $handle $limit_type
 }
 
 rate_node_del()
@@ -597,21 +636,14 @@  rate_node_del()
 	devlink port function rate del $handle
 }
 
-rate_test()
+rate_shaping_test()
 {
-	RET=0
-
-	echo $VF_COUNT > /sys/bus/netdevsim/devices/$DEV_NAME/sriov_numvfs
-	devlink dev eswitch set $DL_HANDLE mode switchdev
-	local leafs=`rate_leafs_get $DL_HANDLE`
-	local num_leafs=`echo $leafs | wc -w`
-	[ "$num_leafs" == "$VF_COUNT" ]
-	check_err $? "Expected $VF_COUNT rate leafs but got $num_leafs"
+	local leafs=$1
 
 	rate=10
 	for r_obj in $leafs
 	do
-		rate_attr_tx_rate_check $r_obj tx_share $rate \
+		rate_attr_shaping_rate_check $r_obj tx_share $rate \
 			$DEBUGFS_DIR/ports/${r_obj##*/}/tx_share
 		rate=$(($rate+10))
 	done
@@ -619,11 +651,19 @@  rate_test()
 	rate=100
 	for r_obj in $leafs
 	do
-		rate_attr_tx_rate_check $r_obj tx_max $rate \
+		rate_attr_shaping_rate_check $r_obj tx_max $rate \
 			$DEBUGFS_DIR/ports/${r_obj##*/}/tx_max
 		rate=$(($rate+100))
 	done
 
+	for r_obj in $leafs
+	do
+		rate_attr_shaping_rate_check $r_obj tx_share 0 \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/tx_share
+		rate_attr_shaping_rate_check $r_obj tx_max 0 \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/tx_max
+	done
+
 	local node1_name='group1'
 	local node1="$DL_HANDLE/$node1_name"
 	rate_node_add "$node1"
@@ -634,11 +674,11 @@  rate_test()
 	check_err $? "Expected 1 rate node in output but got $num_nodes"
 
 	local node_tx_share=10
-	rate_attr_tx_rate_check $node1 tx_share $node_tx_share \
+	rate_attr_shaping_rate_check $node1 tx_share $node_tx_share \
 		$DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_share
 
 	local node_tx_max=100
-	rate_attr_tx_rate_check $node1 tx_max $node_tx_max \
+	rate_attr_shaping_rate_check $node1 tx_max $node_tx_max \
 		$DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_max
 
 	rate_node_del "$node1"
@@ -668,6 +708,151 @@  rate_test()
 	check_err $? "Failed to unset $r_obj parent node"
 	rate_node_del "$node1"
 	check_err $? "Failed to delete node $node1"
+}
+
+rate_police_test()
+{
+	local leafs=$1
+
+	local rate=$((100 * 1000**2 * 8))
+	for r_obj in $leafs
+	do
+		rate_attr_police_rate_check $r_obj tx_max $rate \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/tx_max
+		rate=$(($rate + 10 * 1000**2 * 8))
+	done
+
+	local size=$((1024**2))
+	for r_obj in $leafs
+	do
+		rate_attr_police_rate_check $r_obj tx_burst $size \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/tx_burst
+		size=$(($size * 2))
+	done
+
+	rate=$((100 * 1000**2 * 8))
+	for r_obj in $leafs
+	do
+		rate_attr_police_rate_check $r_obj rx_max $rate \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/rx_max
+		rate=$(($rate + 10 * 1000**2 * 8))
+	done
+
+	size=$((1024**2))
+	for r_obj in $leafs
+	do
+		rate_attr_police_rate_check $r_obj rx_burst $size \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/rx_burst
+		size=$(($size * 2))
+	done
+
+	local packets=1000
+	for r_obj in $leafs
+	do
+		rate_attr_police_rate_check $r_obj tx_pkts $packets \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/tx_pkts
+		packets=$(($packets * 2))
+	done
+
+	size=$((1024**2))
+	for r_obj in $leafs
+	do
+		rate_attr_police_rate_check $r_obj tx_pkts_burst $size \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/tx_pkts_burst
+		size=$(($size * 2))
+	done
+
+	packets=1000
+	for r_obj in $leafs
+	do
+		rate_attr_police_rate_check $r_obj rx_pkts $packets \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/rx_pkts
+		packets=$(($packets * 2))
+	done
+
+	size=$((1024**2))
+	for r_obj in $leafs
+	do
+		rate_attr_police_rate_check $r_obj rx_pkts_burst $size \
+			$DEBUGFS_DIR/ports/${r_obj##*/}/rx_pkts_burst
+		size=$(($size * 2))
+	done
+
+	local node1_name='group1'
+	local node1="$DL_HANDLE/$node1_name"
+	rate_node_add "$node1" police
+	check_err $? "Failed to add node $node1"
+
+	local num_nodes=`rate_nodes_get $DL_HANDLE | wc -w`
+	[ $num_nodes == 1 ]
+	check_err $? "Expected 1 rate node in output but got $num_nodes"
+
+	rate_attr_police_rate_check $node1 tx_max $((200 * 1000**2 * 8)) \
+		$DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_max
+
+	rate_attr_police_rate_check $node1 tx_burst $((2 * 1024**2)) \
+		$DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_burst
+
+	rate_attr_police_rate_check $node1 rx_max $((300 * 1000**2 * 8)) \
+		$DEBUGFS_DIR/rate_nodes/${node1##*/}/rx_max
+
+	rate_attr_police_rate_check $node1 rx_burst $((3 * 1024**2)) \
+		$DEBUGFS_DIR/rate_nodes/${node1##*/}/rx_burst
+
+	rate_attr_police_rate_check $node1 tx_pkts 4000 \
+		$DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_pkts
+
+	rate_attr_police_rate_check $node1 tx_pkts_burst $((4 * 1024**2)) \
+		$DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_pkts_burst
+
+	rate_attr_police_rate_check $node1 rx_pkts 5000 \
+		$DEBUGFS_DIR/rate_nodes/${node1##*/}/rx_pkts
+
+	rate_attr_police_rate_check $node1 rx_pkts_burst $((5 * 1024**2)) \
+		$DEBUGFS_DIR/rate_nodes/${node1##*/}/rx_pkts_burst
+
+	rate_node_del "$node1"
+	check_err $? "Failed to delete node $node1"
+	num_nodes=`rate_nodes_get $DL_HANDLE | wc -w`
+	[ $num_nodes == 0 ]
+	check_err $? "Expected 0 rate node but got $num_nodes"
+
+	rate_node_add "$node1" police
+	check_err $? "Failed to add node $node1"
+
+	rate_attr_parent_check $r_obj $node1_name \
+		$DEBUGFS_DIR/ports/${r_obj##*/}/rate_parent
+
+	local node2_name='group2'
+	local node2="$DL_HANDLE/$node2_name"
+	rate_node_add "$node2" police
+	check_err $? "Failed to add node $node2"
+
+	rate_attr_parent_check $node2 $node1_name \
+		$DEBUGFS_DIR/rate_nodes/$node2_name/rate_parent
+	rate_node_del "$node2"
+	check_err $? "Failed to delete node $node2"
+	rate_attr_set "$r_obj" noparent
+	check_err $? "Failed to unset $r_obj parent node"
+	rate_node_del "$node1"
+	check_err $? "Failed to delete node $node1"
+}
+
+rate_test()
+{
+	RET=0
+
+	echo $VF_COUNT > /sys/bus/netdevsim/devices/$DEV_NAME/sriov_numvfs
+	devlink dev eswitch set $DL_HANDLE mode switchdev
+	local leafs=`rate_leafs_get $DL_HANDLE`
+	local num_leafs=`echo $leafs | wc -w`
+	[ "$num_leafs" == "$VF_COUNT" ]
+	check_err $? "Expected $VF_COUNT rate leafs but got $num_leafs"
+
+	rate_shaping_test "$leafs"
+	if devlink port function rate help |& grep -qF 'limit_type police' ; then
+		rate_police_test "$leafs"
+	fi
 
 	log_test "rate test"
 }