-
Notifications
You must be signed in to change notification settings - Fork 4
/
uperf-client
executable file
·243 lines (226 loc) · 6.33 KB
/
uperf-client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/bash
exec >uperf-client-stderrout.txt
exec 2>&1
. /usr/bin/uperf-base || (echo "/usr/bin/uperf-base not found"; exit 1)
dump_runtime
validate_label
validate_sw_prereqs jq ss uperf getopt ip
# defaults
nthreads=1
protocol="tcp"
wsize=1024
rsize=1024
think=0.001 # time in seconds
duration=60
remotehost=""
control_port=""
data_port=""
test_type="stream"
uopts=""
cpu_pin=""
longopts="test-type:,protocol:,rsize:,wsize:,nthreads:,remotehost:,duration:,cpu-pin:,think:,passthru:"
opts=$(getopt -q -o "" --longoptions "$longopts" -n "getopt.sh" -- "$@");
if [ $? -ne 0 ]; then
exit_error "Unrecognized option specified"
fi
eval set -- "$opts";
while true; do
case "$1" in
--cpu-pin)
shift;
cpu_pin=$1
echo "cpu_pin=${cpu_pin}"
shift;
;;
--test-type)
shift;
test_type=$1
echo "test_type=$test_type"
if [ ! -e /tmp/xml-files/$test_type.xml ]; then
exit_error "could not find /tmp/xml-files/$test_type.xml"
fi
shift;
;;
--nthreads)
shift;
nthreads=$1
echo "nthreads=$nthreads"
shift;
;;
--protocol)
shift;
protocol=$1
echo "protocol=$protocol"
shift
;;
--rsize)
shift;
rsize=$1
echo "rsize=$rsize"
shift
;;
--wsize)
shift;
wsize=$1
echo "wsize=$wsize"
shift
;;
--think)
shift;
think=$1
echo "think=$think"
shift
;;
--remotehost)
shift;
remotehost=$1
echo "remotehost=$remotehost"
shift
;;
--duration)
shift;
duration=$1
echo "duration=$duration"
shift
;;
--passthru) # uperf options that user wants passthru
shift;
pt_opts=$1
echo "pt_opts=$pt_opts"
shift
;;
--)
shift;
break
;;
*)
exit_error "Invalid option: $1"
esac
done
case "${cpu_pin}" in
""|"numa")
;;
*)
exit_error "unsupported cpu-pin value '${cpu_pin}'"
;;
esac
if [ ! -e /tmp/xml-files/$test_type.xml ]; then
exit_error "/tmp/xml-files/$test_type.xml was not found"
fi
# Unless the user specifies a specific remotehost argument, this must
# be sourced from the endpoint (which gets it from the client)
if [ -z "$remotehost" ]; then
echo "--remotehost was not set via cmdline args, checking any messages from the endpoint"
echo "These files exist in ./msgs/rx:"
/bin/ls -l msgs/rx
file="msgs/rx/endpoint-start-end:1"
if [ ! -e "${file}" ]; then
echo -n "Did not fine ${file}"
file="msgs/rx/server-start-end:1"
echo ", trying ${file}"
fi
if [ ! -e "${file}" ]; then
echo -n "Did not find ${file}"
file="msgs/rx/client-start:1"
echo ", trying ${file}"
fi
if [ -e "$file" ]; then
echo "Found $file"
ipaddr=`jq -r '.svc.ip' $file`
if [ ! -z "$ipaddr" ]; then
echo "Found server IP $ipaddr"
remotehost=$ipaddr
fi
port=`jq -r '.svc.ports[0]' $file`
if [ ! -z "$port" ]; then
echo "Found server control port $port"
control_port=$port
fi
port=`jq -r '.svc.ports[1]' $file`
if [ ! -z "$port" ]; then
echo "Found server data port $port"
data_port=$port
fi
else
echo "Did not find $file, so cannot get an IP from the server/endpoint"
fi
fi
# Confirm we have a remotehost (server) and ports
if [ -z "$remotehost" ]; then
exit_error "remotehost is not set"
fi
# TODO: validate $remotehost with regex
ifname=$(ip route get ${remotehost} | head -n 1 | awk -F" dev " '{ print $2 }' | awk -F" src " '{ print $1 }')
if [ ! -e /sys/class/net/${ifname} ]; then
exit_error "invalid interface '${ifname}' found"
fi
ifname_numa_node=-1
ifname_numa_node_cpus=-1
if [ -e /sys/class/net/${ifname}/device/numa_node ]; then
ifname_numa_node=$(cat /sys/class/net/${ifname}/device/numa_node)
if [ $ifname_numa_node == "-1" ] && [ "${cpu_pin}" == "numa" ]; then
exit_error "PCIe has no NUMA locality, but cpu-pin is numa"
fi
ifname_numa_node_cpus=$(cat /sys/devices/system/node/node${ifname_numa_node}/cpulist)
elif [ "${cpu_pin}" == "numa" ]; then
exit_error "cannot determine numa node for interface '${ifname}' and cpu-pin is numa"
fi
# These ports should come from the endpoint, but if for some
# reason they don't the default port numbers are calculated
# in this way:
if [ -z "$control_port" ]; then
let "control_port = 2 * $id"
let "control_port = $control_port + 30000"
echo "control_port was not set, using default of $control_port"
fi
if [ -z "$data_port" ]; then
let "data_port = $control_port + 1"
echo "data_port was not set, using default of $data_port"
fi
if [[ "$test_type" = "crr" ]]; then
# show more details of connect/disconnect
uopts="-tTfa"
fi
/bin/cp /tmp/xml-files/$test_type.xml test.xml
echo "ifname=${ifname}"
echo "ifname_numa_node=${ifname_numa_node}"
echo "remotehost=$remotehost"
echo "control_port=$control_port"
echo "data_port=$data_port"
echo "duration=$duration"
echo "wsize=$wsize"
echo "rsize=$rsize"
echo "think=$think"
echo "nthreads=$nthreads"
echo "protocol=$protocol"
cpu_pin_cmd=""
case "${cpu_pin}" in
"numa")
cpu_pin_cmd="taskset --cpu-list ${ifname_numa_node_cpus}"
;;
esac
cmd+="${cpu_pin_cmd} uperf -R -m test.xml -P $control_port $uopts"
# strip ',' from the passthru options
passthru_opts=$(echo "$pt_opts" | sed 's/,/ /g')
options+=" $passthru_opts"
echo "passthu options: $options"
cmd+="$options"
echo "going to run: ${cmd}"
nthreads=$nthreads \
protocol=$protocol \
remotehost=$remotehost \
duration=$duration \
wsize=$wsize \
rsize=$rsize \
think=$think \
port=$data_port \
${cmd} > uperf-client-result.txt 2>&1
uperf_rc=$?
uperf_errors=$(grep -i error uperf-client-result.txt)
if [ ${uperf_rc} -gt 0 -o -z "${uperf_errors}" ]; then
if [ $test_type == "crr" ]; then
# Do not error on this, as it is sadly common for CRR, and the test will resume anyway
exit 0
fi
exit_error "$uperf_errors"
fi