Debian Codegraph @

src/queuelat/determine_maximum_mpps.sh

raw symbols SCIP
1 #!/bin/bash
2
3 # SPDX-License-Identifier: GPL-2.0-or-later
4 # Copyright (C) 2018 Marcelo Tosatti <[email protected]>
5
6 # A script to determine the maximum mpps. Logic:
7 # Increase mpps in 0.5 units
8 #
9 MAXLAT="20000"
10 CYCLES_PER_PACKET="300"
11 OUTFILE=/usr/tmp/outfile
12 PRIO=1
13 CPULIST=0
14 SCHED=""
15
16 usage()
17 {
18 echo "Usage:"
19 echo "$(basename $0) [OPTIONS]"
20 echo
21 echo "-a cpulist"
22 echo " List of processors to run on. The default is processor 0"
23 echo " Numbers are separated by commas and may include ranges. Eg. 0,3,7-11"
24 echo "-m maxlat"
25 echo " maximum latency in nanoseconds. The default is 20000"
26 echo " if the maximum is exceeded, that run of queuelat quits"
27 echo "-n cycles"
28 echo " Estimated number of cycles it takes to process one packet"
29 echo " The default is 300"
30 echo "-f"
31 echo " Set the scheduling policy to SCHED_FIFO."
32 echo " This is the default if not specified"
33 echo "-r"
34 echo " Set the scheduling policy to SCHED_RR".
35 echo "-p priority"
36 echo " default priority = 1. Valid numbers are from 1 to 99"
37 echo "-h"
38 echo " help"
39 echo " print this help message and exit"
40 exit
41 }
42
43 get_cpuinfo_mhz()
44 {
45 # Try to determine MHz from /proc/cpuinfo
46 FREQ_MHZ=$(grep "cpu MHz" /proc/cpuinfo | cut -f 3 -d " " | sort -rn | head -n1)
47
48 # Try to determine MHz from /sys/firmware/devicetree/base/cpus/timebase-frequency
49 if [ -z $FREQ_MHZ ]; then
50 FREQ_MHZ=$(($((16#$(hexdump -e '1/1 "%02X"' /sys/firmware/devicetree/base/cpus/timebase-frequency)))/1000000))
51 fi
52
53 echo "$FREQ_MHZ"
54 }
55
56 # Check that the scheduling policy hasn't already been set
57 # Exit with an error message if it has
58 check_sched()
59 {
60 if [ "${SCHED}" != "" ]; then
61 echo "Specify -f or -r, but not both"
62 usage
63 fi
64 }
65
66 # Process command line options
67 while getopts ":a:frp:m:n:h" opt; do
68 case ${opt} in
69 a ) CPULIST="${OPTARG}" ;;
70 m ) MAXLAT="${OPTARG}" ;;
71 n ) CYCLES_PER_PACKET="${OPTARG}" ;;
72 f ) check_sched; SCHED="-f" ;;
73 r ) check_sched; SCHED="-r" ;;
74 p ) PRIO="${OPTARG}" ;;
75 h ) usage ;;
76 * ) echo "no such option"; usage ;;
77 esac
78 done
79
80 shift $((OPTIND -1 ))
81
82 # If the user hasn't specified a scheduling policy
83 # then set it to the default SCHED_FIFO
84 if [ "${SCHED}" == "" ]; then
85 SCHED="-f"
86 fi
87
88 # Error checking that the user entered a priority between 1 and 99
89 if [[ "${PRIO}" -lt "1" ]] || [[ "${PRIO}" -gt "99" ]]; then
90 echo "PRIO must be a number between 1 and 99"
91 usage
92 fi
93
94 PREAMBLE="taskset -c ${CPULIST} chrt ${SCHED} ${PRIO}"
95
96 echo "Determining maximum mpps the machine can handle"
97 echo "Will take a few minutes to determine mpps value"
98 echo "And 10 minutes run to confirm the final mpps value is stable"
99
100 for mpps in $(seq 3 3 50); do
101 echo testing "$mpps" Mpps
102
103 OUTFILE=$(mktemp)
104 $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
105
106 exceeded=$(grep exceeded "$OUTFILE")
107 if [ ! -z "$exceeded" ]; then
108 echo mpps failed: "$mpps"
109 break;
110 fi
111 echo success
112 done
113 echo first loop mpps: "$mpps"
114
115 first_mpps=$(($mpps - 1))
116 for mpps in $(seq $first_mpps -1 3); do
117 echo testing "$mpps" Mpps
118
119 OUTFILE=$(mktemp)
120 $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
121
122 exceeded=$(grep exceeded "$OUTFILE")
123 if [ -z "$exceeded" ]; then
124 echo mpps success "$mpps"
125 break;
126 fi
127 echo failure
128 done
129
130 second_mpps=$(echo "$mpps + 0.3" | bc)
131 echo second loop mpps: "$mpps"
132
133 for mpps in $(seq "$second_mpps" 0.3 $first_mpps); do
134 echo testing "$mpps" Mpps
135
136 OUTFILE=$(mktemp)
137 $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
138
139 exceeded=$(grep exceeded "$OUTFILE")
140 if [ ! -z "$exceeded" ]; then
141 echo mpps failure "$mpps"
142 break;
143 fi
144 echo success
145 done
146
147 echo third loop mpps: "$mpps"
148 third_mpps=$(echo "$mpps -0.1" | bc)
149
150 for mpps in $(seq "$third_mpps" -0.1 3); do
151 echo testing "$mpps" Mpps
152
153 OUTFILE=$(mktemp)
154 $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
155
156 exceeded=$(grep exceeded "$OUTFILE")
157 if [ -z "$exceeded" ]; then
158 echo mpps success "$mpps"
159 break;
160 fi
161 echo failure
162 done
163
164 export queuelat_failure=1
165 while [ $queuelat_failure == 1 ]; do
166
167 export queuelat_failure=0
168
169 echo -n "Starting 10 runs of 30 seconds with "
170 echo "$mpps Mpps"
171
172 for i in $(seq 1 10); do
173 $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
174 exceeded=$(grep exceeded "$OUTFILE")
175
176 if [ ! -z "$exceeded" ]; then
177 echo "mpps failure (run $i) $mpps"
178 export queuelat_failure=1
179 mpps=$(echo "$mpps" - 0.1 | bc)
180 export mpps
181 break
182 fi
183 echo "run $i success"
184 done
185
186 done
187
188 export queuelat_failure=1
189 while [ $queuelat_failure == 1 ]; do
190
191 export queuelat_failure=0
192
193 echo -n "Starting 10 minutes run with "
194 echo "$mpps Mpps"
195
196 $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 600 > "$OUTFILE"
197 exceeded=$(grep exceeded "$OUTFILE")
198
199 if [ ! -z "$exceeded" ]; then
200 echo "mpps failure (run $i) $mpps"
201 export queuelat_failure=1
202 mpps=$(echo "$mpps" - 0.1 | bc)
203 export mpps
204 continue
205 fi
206 echo "run $i success"
207 done
208
209 echo Final mpps is: "$mpps"
210
211 unset queuelat_failure
212 unset mpps