| 1 | #!/bin/bashscip-shell filesystem . . `/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/outfilescip-shell filesystem . . `/usr/tmp/outfile`. |
| 12 | PRIO=1 |
| 13 | CPULIST=0 |
| 14 | SCHED="" |
| 15 | |
| 16 | usagescip-shell shell shell-project 0.0.0 usage().() |
| 17 | { |
| 18 | echoscip-shell system . . echo. "Usage:" |
| 19 | echoscip-shell system . . echo. "$(basenamescip-shell system . . basename. $0) [OPTIONS]" |
| 20 | echoscip-shell system . . echo. |
| 21 | echoscip-shell system . . echo. "-a cpulist" |
| 22 | echoscip-shell system . . echo. " List of processors to run on. The default is processor 0" |
| 23 | echoscip-shell system . . echo. " Numbers are separated by commas and may include ranges. Eg. 0,3,7-11" |
| 24 | echoscip-shell system . . echo. "-m maxlat" |
| 25 | echoscip-shell system . . echo. " maximum latency in nanoseconds. The default is 20000" |
| 26 | echoscip-shell system . . echo. " if the maximum is exceeded, that run of queuelat quits" |
| 27 | echoscip-shell system . . echo. "-n cycles" |
| 28 | echoscip-shell system . . echo. " Estimated number of cycles it takes to process one packet" |
| 29 | echoscip-shell system . . echo. " The default is 300" |
| 30 | echoscip-shell system . . echo. "-f" |
| 31 | echoscip-shell system . . echo. " Set the scheduling policy to SCHED_FIFO." |
| 32 | echoscip-shell system . . echo. " This is the default if not specified" |
| 33 | echoscip-shell system . . echo. "-r" |
| 34 | echoscip-shell system . . echo. " Set the scheduling policy to SCHED_RR". |
| 35 | echoscip-shell system . . echo. "-p priority" |
| 36 | echoscip-shell system . . echo. " default priority = 1. Valid numbers are from 1 to 99" |
| 37 | echoscip-shell system . . echo. "-h" |
| 38 | echoscip-shell system . . echo. " help" |
| 39 | echoscip-shell system . . echo. " print this help message and exit" |
| 40 | exit |
| 41 | } |
| 42 | |
| 43 | get_cpuinfo_mhzscip-shell shell shell-project 0.0.0 get_cpuinfo_mhz().() |
| 44 | { |
| 45 | # Try to determine MHz from /proc/cpuinfo |
| 46 | FREQ_MHZ=$(grepscip-shell system . . grep. "cpu MHz" /proc/cpuinfoscip-shell filesystem . . `/proc/cpuinfo`. | cutscip-shell system . . cut. -f 3 -d " " | sortscip-shell system . . sort. -rn | headscip-shell system . . head. -n1) |
| 47 | |
| 48 | # Try to determine MHz from /sys/firmware/devicetree/base/cpus/timebase-frequency |
| 49 | if [scip-shell system . . `[`. -z $FREQ_MHZ ]; then |
| 50 | FREQ_MHZ=$(($((16#$(hexdumpscip-shell system . . hexdump. -e '1/1 "%02X"' /sys/firmware/devicetree/base/cpus/timebase-frequencyscip-shell filesystem . . `/sys/firmware/devicetree/base/cpus/timebase-frequency`.)))/1000000)) |
| 51 | fi |
| 52 | |
| 53 | echoscip-shell system . . 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_schedscip-shell shell shell-project 0.0.0 check_sched().() |
| 59 | { |
| 60 | if [scip-shell system . . `[`. "${SCHED}" != "" ]; then |
| 61 | echoscip-shell system . . echo. "Specify -f or -r, but not both" |
| 62 | usagescip-shell shell shell-project 0.0.0 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_schedscip-shell shell shell-project 0.0.0 check_sched().; SCHED="-f" ;; |
| 73 | r ) check_schedscip-shell shell shell-project 0.0.0 check_sched().; SCHED="-r" ;; |
| 74 | p ) PRIO="${OPTARG}" ;; |
| 75 | h ) usagescip-shell shell shell-project 0.0.0 usage(). ;; |
| 76 | * ) echoscip-shell system . . echo. "no such option"; usagescip-shell shell shell-project 0.0.0 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 [scip-shell system . . `[`. "${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 | echoscip-shell system . . echo. "PRIO must be a number between 1 and 99" |
| 91 | usagescip-shell shell shell-project 0.0.0 usage(). |
| 92 | fi |
| 93 | |
| 94 | PREAMBLE="taskset -c ${CPULIST} chrt ${SCHED} ${PRIO}" |
| 95 | |
| 96 | echoscip-shell system . . echo. "Determining maximum mpps the machine can handle" |
| 97 | echoscip-shell system . . echo. "Will take a few minutes to determine mpps value" |
| 98 | echoscip-shell system . . echo. "And 10 minutes run to confirm the final mpps value is stable" |
| 99 | |
| 100 | for mpps in $(seqscip-shell system . . seq. 3 3 50); do |
| 101 | echoscip-shell system . . echo. testing "$mpps" Mpps |
| 102 | |
| 103 | OUTFILE=$(mktempscip-shell system . . mktemp.) |
| 104 | $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhzscip-shell shell shell-project 0.0.0 get_cpuinfo_mhz().)" -p "$mpps" -t 30 > "$OUTFILE" |
| 105 | |
| 106 | exceeded=$(grepscip-shell system . . grep. exceeded "$OUTFILE") |
| 107 | if [scip-shell system . . `[`. ! -z "$exceeded" ]; then |
| 108 | echoscip-shell system . . echo. mpps failed: "$mpps" |
| 109 | break; |
| 110 | fi |
| 111 | echoscip-shell system . . echo. success |
| 112 | done |
| 113 | echoscip-shell system . . echo. first loop mpps: "$mpps" |
| 114 | |
| 115 | first_mpps=$(($mpps - 1)) |
| 116 | for mpps in $(seqscip-shell system . . seq. $first_mpps -1 3); do |
| 117 | echoscip-shell system . . echo. testing "$mpps" Mpps |
| 118 | |
| 119 | OUTFILE=$(mktempscip-shell system . . mktemp.) |
| 120 | $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhzscip-shell shell shell-project 0.0.0 get_cpuinfo_mhz().)" -p "$mpps" -t 30 > "$OUTFILE" |
| 121 | |
| 122 | exceeded=$(grepscip-shell system . . grep. exceeded "$OUTFILE") |
| 123 | if [scip-shell system . . `[`. -z "$exceeded" ]; then |
| 124 | echoscip-shell system . . echo. mpps success "$mpps" |
| 125 | break; |
| 126 | fi |
| 127 | echoscip-shell system . . echo. failure |
| 128 | done |
| 129 | |
| 130 | second_mpps=$(echoscip-shell system . . echo. "$mpps + 0.3" | bc) |
| 131 | echoscip-shell system . . echo. second loop mpps: "$mpps" |
| 132 | |
| 133 | for mpps in $(seqscip-shell system . . seq. "$second_mpps" 0.3 $first_mpps); do |
| 134 | echoscip-shell system . . echo. testing "$mpps" Mpps |
| 135 | |
| 136 | OUTFILE=$(mktempscip-shell system . . mktemp.) |
| 137 | $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhzscip-shell shell shell-project 0.0.0 get_cpuinfo_mhz().)" -p "$mpps" -t 30 > "$OUTFILE" |
| 138 | |
| 139 | exceeded=$(grepscip-shell system . . grep. exceeded "$OUTFILE") |
| 140 | if [scip-shell system . . `[`. ! -z "$exceeded" ]; then |
| 141 | echoscip-shell system . . echo. mpps failure "$mpps" |
| 142 | break; |
| 143 | fi |
| 144 | echoscip-shell system . . echo. success |
| 145 | done |
| 146 | |
| 147 | echoscip-shell system . . echo. third loop mpps: "$mpps" |
| 148 | third_mpps=$(echoscip-shell system . . echo. "$mpps -0.1" | bc) |
| 149 | |
| 150 | for mpps in $(seqscip-shell system . . seq. "$third_mpps" -0.1 3); do |
| 151 | echoscip-shell system . . echo. testing "$mpps" Mpps |
| 152 | |
| 153 | OUTFILE=$(mktempscip-shell system . . mktemp.) |
| 154 | $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhzscip-shell shell shell-project 0.0.0 get_cpuinfo_mhz().)" -p "$mpps" -t 30 > "$OUTFILE" |
| 155 | |
| 156 | exceeded=$(grepscip-shell system . . grep. exceeded "$OUTFILE") |
| 157 | if [scip-shell system . . `[`. -z "$exceeded" ]; then |
| 158 | echoscip-shell system . . echo. mpps success "$mpps" |
| 159 | break; |
| 160 | fi |
| 161 | echoscip-shell system . . echo. failure |
| 162 | done |
| 163 | |
| 164 | export queuelat_failure=1 |
| 165 | while [scip-shell system . . `[`. $queuelat_failure == 1 ]; do |
| 166 | |
| 167 | export queuelat_failure=0 |
| 168 | |
| 169 | echoscip-shell system . . echo. -n "Starting 10 runs of 30 seconds with " |
| 170 | echoscip-shell system . . echo. "$mpps Mpps" |
| 171 | |
| 172 | for i in $(seqscip-shell system . . seq. 1 10); do |
| 173 | $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhzscip-shell shell shell-project 0.0.0 get_cpuinfo_mhz().)" -p "$mpps" -t 30 > "$OUTFILE" |
| 174 | exceeded=$(grepscip-shell system . . grep. exceeded "$OUTFILE") |
| 175 | |
| 176 | if [scip-shell system . . `[`. ! -z "$exceeded" ]; then |
| 177 | echoscip-shell system . . echo. "mpps failure (run $i) $mpps" |
| 178 | export queuelat_failure=1 |
| 179 | mpps=$(echoscip-shell system . . echo. "$mpps" - 0.1 | bc) |
| 180 | export mpps |
| 181 | break |
| 182 | fi |
| 183 | echoscip-shell system . . echo. "run $i success" |
| 184 | done |
| 185 | |
| 186 | done |
| 187 | |
| 188 | export queuelat_failure=1 |
| 189 | while [scip-shell system . . `[`. $queuelat_failure == 1 ]; do |
| 190 | |
| 191 | export queuelat_failure=0 |
| 192 | |
| 193 | echoscip-shell system . . echo. -n "Starting 10 minutes run with " |
| 194 | echoscip-shell system . . echo. "$mpps Mpps" |
| 195 | |
| 196 | $PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhzscip-shell shell shell-project 0.0.0 get_cpuinfo_mhz().)" -p "$mpps" -t 600 > "$OUTFILE" |
| 197 | exceeded=$(grepscip-shell system . . grep. exceeded "$OUTFILE") |
| 198 | |
| 199 | if [scip-shell system . . `[`. ! -z "$exceeded" ]; then |
| 200 | echoscip-shell system . . echo. "mpps failure (run $i) $mpps" |
| 201 | export queuelat_failure=1 |
| 202 | mpps=$(echoscip-shell system . . echo. "$mpps" - 0.1 | bc) |
| 203 | export mpps |
| 204 | continue |
| 205 | fi |
| 206 | echoscip-shell system . . echo. "run $i success" |
| 207 | done |
| 208 | |
| 209 | echoscip-shell system . . echo. Final mpps is: "$mpps" |
| 210 | |
| 211 | unset queuelat_failure |
| 212 | unset mpps |