ethtool-coalesce.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0-only
  3. source ethtool-common.sh
  4. function get_value {
  5. local query="${SETTINGS_MAP[$1]}"
  6. echo $(ethtool -c $NSIM_NETDEV | \
  7. awk -F':' -v pattern="$query:" '$0 ~ pattern {gsub(/[ \t]/, "", $2); print $2}')
  8. }
  9. function update_current_settings {
  10. for key in ${!SETTINGS_MAP[@]}; do
  11. CURRENT_SETTINGS[$key]=$(get_value $key)
  12. done
  13. echo ${CURRENT_SETTINGS[@]}
  14. }
  15. if ! ethtool -h | grep -q coalesce; then
  16. echo "SKIP: No --coalesce support in ethtool"
  17. exit 4
  18. fi
  19. NSIM_NETDEV=$(make_netdev)
  20. set -o pipefail
  21. declare -A SETTINGS_MAP=(
  22. ["rx-frames-low"]="rx-frame-low"
  23. ["tx-frames-low"]="tx-frame-low"
  24. ["rx-frames-high"]="rx-frame-high"
  25. ["tx-frames-high"]="tx-frame-high"
  26. ["rx-usecs"]="rx-usecs"
  27. ["rx-frames"]="rx-frames"
  28. ["rx-usecs-irq"]="rx-usecs-irq"
  29. ["rx-frames-irq"]="rx-frames-irq"
  30. ["tx-usecs"]="tx-usecs"
  31. ["tx-frames"]="tx-frames"
  32. ["tx-usecs-irq"]="tx-usecs-irq"
  33. ["tx-frames-irq"]="tx-frames-irq"
  34. ["stats-block-usecs"]="stats-block-usecs"
  35. ["pkt-rate-low"]="pkt-rate-low"
  36. ["rx-usecs-low"]="rx-usecs-low"
  37. ["tx-usecs-low"]="tx-usecs-low"
  38. ["pkt-rate-high"]="pkt-rate-high"
  39. ["rx-usecs-high"]="rx-usecs-high"
  40. ["tx-usecs-high"]="tx-usecs-high"
  41. ["sample-interval"]="sample-interval"
  42. )
  43. declare -A CURRENT_SETTINGS=(
  44. ["rx-frames-low"]=""
  45. ["tx-frames-low"]=""
  46. ["rx-frames-high"]=""
  47. ["tx-frames-high"]=""
  48. ["rx-usecs"]=""
  49. ["rx-frames"]=""
  50. ["rx-usecs-irq"]=""
  51. ["rx-frames-irq"]=""
  52. ["tx-usecs"]=""
  53. ["tx-frames"]=""
  54. ["tx-usecs-irq"]=""
  55. ["tx-frames-irq"]=""
  56. ["stats-block-usecs"]=""
  57. ["pkt-rate-low"]=""
  58. ["rx-usecs-low"]=""
  59. ["tx-usecs-low"]=""
  60. ["pkt-rate-high"]=""
  61. ["rx-usecs-high"]=""
  62. ["tx-usecs-high"]=""
  63. ["sample-interval"]=""
  64. )
  65. declare -A EXPECTED_SETTINGS=(
  66. ["rx-frames-low"]=""
  67. ["tx-frames-low"]=""
  68. ["rx-frames-high"]=""
  69. ["tx-frames-high"]=""
  70. ["rx-usecs"]=""
  71. ["rx-frames"]=""
  72. ["rx-usecs-irq"]=""
  73. ["rx-frames-irq"]=""
  74. ["tx-usecs"]=""
  75. ["tx-frames"]=""
  76. ["tx-usecs-irq"]=""
  77. ["tx-frames-irq"]=""
  78. ["stats-block-usecs"]=""
  79. ["pkt-rate-low"]=""
  80. ["rx-usecs-low"]=""
  81. ["tx-usecs-low"]=""
  82. ["pkt-rate-high"]=""
  83. ["rx-usecs-high"]=""
  84. ["tx-usecs-high"]=""
  85. ["sample-interval"]=""
  86. )
  87. # populate the expected settings map
  88. for key in ${!SETTINGS_MAP[@]}; do
  89. EXPECTED_SETTINGS[$key]=$(get_value $key)
  90. done
  91. # test
  92. for key in ${!SETTINGS_MAP[@]}; do
  93. value=$((RANDOM % $((2**32-1))))
  94. ethtool -C $NSIM_NETDEV "$key" "$value"
  95. EXPECTED_SETTINGS[$key]="$value"
  96. expected=${EXPECTED_SETTINGS[@]}
  97. current=$(update_current_settings)
  98. check $? "$current" "$expected"
  99. set +x
  100. done
  101. # bool settings which ethtool displays on the same line
  102. ethtool -C $NSIM_NETDEV adaptive-rx on
  103. s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: off")
  104. check $? "$s" ""
  105. ethtool -C $NSIM_NETDEV adaptive-tx on
  106. s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: on")
  107. check $? "$s" ""
  108. if [ $num_errors -eq 0 ]; then
  109. echo "PASSED all $((num_passes)) checks"
  110. exit 0
  111. else
  112. echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
  113. exit 1
  114. fi