-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_multi.sh
executable file
·384 lines (341 loc) · 11.5 KB
/
run_multi.sh
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/bash
#
# run_multi.sh: Run the ("multi-")benchmarks, assuming everything is set
#
# ckatsak, Thu 10 Feb 2022 12:17:15 PM EET
#
# Assumptions:
# - All previous build steps have been completed.
# - All participating benchmarks' snapshots initially live at:
# `$SCRIPT_DIR/snapshot/$BENCH/{snapshot,memory}-$IDh.file`.
# - All participating benchmarks' rootfs images initially live at:
# `$SCRIPT_DIR/rootfs/$BENCH/$BENCH-$IDh.ext4`.
# - Runs on a machine with multiple NUMA nodes.
# - DCPM module is mounted on NUMA node 0 (Firecracker gets pinned there).
#
# Results directory outline:
# $OUTDIR
# +--chameleon
# | +--dcpm
# | | + run00.csv
# | | + run01.csv
# | | + ...
# | | + run$RUNS.csv
# | +--nvme
# | | + run00.csv
# | | + run01.csv
# | | + ...
# | | + run$RUNS.csv
# | +--ssd
# | | + run0.csv
# | | + run1.csv
# | | + ...
# | | + run$RUNS.csv
# +--cnn_serving
# | +--dcpm
# | | + run00.csv
# | | + run01.csv
# | | + ...
# | | + run$RUNS.csv
# | +--nvme
# | | + run00.csv
# | | + run01.csv
# | | + ...
# | | + run$RUNS.csv
# | +--ssd
# | | + run00.csv
# | | + run01.csv
# | | + ...
# | | + run$RUNS.csv
# + ...
set -euo pipefail
SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
# shellcheck source=config # <-- assuming SC is run from repository's root
source "$SCRIPT_DIR/config"
NOW="$(date '+%Y%m%d%H%M%S')"
WHOSE="${WHOSE:=$(who am i | awk '{print $1}')}"
QUIET=false
# Paths to useful binaries
set +e
NUMACTL="$(command -v 'numactl')"
[ -z "$NUMACTL" ] && echo "ERROR: 'numactl' is required" && exit 1
TASKSET="$(command -v 'taskset')"
[ -z "$TASKSET" ] && echo "ERROR: 'taskset' is required" && exit 1
KILLALL="$(command -v 'killall')"
[ -z "$KILLALL" ] && echo "ERROR: 'killall' is required" && exit 1
IP="$(command -v 'ip')"
[ -z "$IP" ] && echo "ERROR: 'iproute2' is required" && exit 1
CP="$(command -v 'rsync')"
[ -z "$CP" ] && echo "ERROR: 'rsync' is required" && exit 1
FFORGET="$(command -v 'fforget')"
# To install it: $ cargo install --git https://github.com/ckatsak/fforget-bin
[ -z "$FFORGET" ] && echo "ERROR: 'fforget' is required" && exit 1
set -e
CP2M="$SCRIPT_DIR/scripts/cp_2M/cp_2M"
[ ! -f "$CP2M" ] \
&& echo "ERROR: Building 'cp_2M' is required" && exit 1
FBPML_MULTICLIENT="$SCRIPT_DIR/fbpml-rs/target/release/fbpml-multiclient"
[ ! -f "$FBPML_MULTICLIENT" ] \
&& echo "ERROR: Building 'fbpml-multiclient' is required" && exit 1
# Makes sure the requested number of TAP interfaces are currently present.
#
# Parameters:
# $1: Expected number of TAP interfaces
function taps_check() {
local -r expected="$1"
local found
set +e
found="$("$IP" a s | grep -c 'fcpmem01')"
set -e
if [ "$found" -lt "$expected" ]; then
echo "ERROR: Expected $expected 'fcpmem01.*' tap interfaces; found $found."
exit 2
fi
}
# Fills the global $PHYS_CORES array with the physical cores of the provided
# NUMA node.
#
# Parameters:
# $1: NUMA node number (e.g., 0, 1, ...)
function physical_cores() {
local -r NODE="$1"
local cores cs ce
PHYS_CORES=()
cores="$(lscpu | grep "node$NODE" | cut -d':' -f2 | tr -d '[:space:]')"
cs="$(cut -d'-' -f1 <<< "$cores")"
ce="$(cut -d'-' -f2 <<< "$cores")"
for c in $(seq "$cs" 1 "$ce"); do
PHYS_CORES+=("$c")
done
}
# Fills the global $LOG_CORES array with the logical cores of the provided
# NUMA node.
#
# Parameters:
# $1: NUMA node number (e.g., 0, 1, ...)
function logical_cpus() {
local -r NODE="$1"
LOG_CORES=()
# Add the first hyperthread of each core of the given node
local ht0z ht0z_s ht0z_e
ht0z="$(lscpu | grep "node$NODE" | cut -d':' -f2 | tr -d '[:space:]' \
| cut -d',' -f1)"
ht0z_s="$(cut -d'-' -f1 <<< "$ht0z")"
ht0z_e="$(cut -d'-' -f2 <<< "$ht0z")"
for c in $(seq "$ht0z_s" 1 "$ht0z_e"); do
LOG_CORES+=("$c")
done
# Add the second hyperthread of each core of the given node
local ht1z ht1z_s ht1z_e
ht1z="$(lscpu | grep "node$NODE" | cut -d':' -f2 | tr -d '[:space:]' \
| cut -d',' -f2)"
ht1z_s="$(cut -d'-' -f1 <<< "$ht1z")"
ht1z_e="$(cut -d'-' -f2 <<< "$ht1z")"
for c in $(seq "$ht1z_s" 1 "$ht1z_e"); do
LOG_CORES+=("$c")
done
}
function log_progress() {
local b d out
b="$(printf "Bench: %16s" "$2")"
d="$(printf "Device: %6s" "$3")"
out="$(printf "$b $d : run %2d" "$1")"
[ "$QUIET" = false ] && [ -t 2 ] && [ -n "$TERM" ] \
&& echo -e "$(tput setab 8)[$(date -Ins)] $(tput setaf 2)$out$(tput sgr0)" 1>&2
}
function show_help() {
cat <<-EOF
$(show_version)
USAGE:
${0##*/} [OPTION]...
OPTION:
-h, --help Show this help message and exit
-V, --version Show version and exit
-v, --verbose Print commands & args as they are executed
-q, --quiet Do not log progress to stderr at all
-b, --benchmark The name of the benchmark to run
--num-uvms # of MicroVMs to run in parallel [default=$DEFAULT_MANY]
-p, --pmem-path <PATH> Snapshots' directory on mounted PMEM device
-n, --nvme-path <PATH> Snapshots' directory on mounted NVMe device
-s, --ssd-path <PATH> Snapshots' dir on mounted Flash SSD device
-r, --runs <RUNS> Number of runs of each benchmark [default=$DEFAULT_RUNS]
--pre-warm <RUNS> Number of warm runs before measuring warm
-o, --outdir <PATH> Directory path to dump the resulting CSVs
NOTE: By running this as root, attempts will be made to drop all page, dentries
& inode caches caches between runs, whereas 'fforget' will be employed to only
"uncache" specific files in the case of running this as a common unprivileged
user.
EOF
}
function show_version() {
echo "${0##*/} -- $(basename "$SCRIPT_DIR") v$VERSION"
}
long='help,version,verbose,quiet,benchmark:,num-uvms:,pmem-path:,nvme-path:,ssd-path:,runs:,pre-warm:,outdir:'
short='h,V,v,q,b:,p:,n:,s:,r:,o:'
opts="$(getopt -l "$long" -o "$short" -- "$@")"
[ $? -ne 0 ] && show_help && exit 1
[ $# -eq 0 ] && show_help && exit 1
eval set -- "$opts"
while true; do
case "$1" in
-h|--help) show_help ; exit 0 ;;
-V|--version) show_version ; exit 0 ;;
-v|--verbose) set -x ; shift ;;
-q|--quiet) QUIET=true ; shift ;;
-b|--benchmark) BENCH="$2" ; shift 2 ;;
--num-uvms) MANY="$2" ; shift 2 ;;
-p|--pmem-path) PMEM_PATH="$2" ; shift 2 ;;
-n|--nvme-path) NVME_PATH="$2" ; shift 2 ;;
-s|--ssd-path) SSD_PATH="$2" ; shift 2 ;;
-r|--runs) RUNS="$2" ; shift 2 ;;
--pre-warm) PREWARM="$2" ; shift 2 ;;
-o|--outdir) OUTDIR="$2" ; shift 2 ;;
--) shift ; break ;;
esac
done
VM_ADDR_FMT='10.0.ID.2:50051'
RUNS="${RUNS:-$DEFAULT_RUNS}"
MANY="${MANY:-$DEFAULT_MANY}"
PREWARM="${PREWARM:-0}" # no pre-warming by default
OUTDIR="${OUTDIR:-${DEFAULT_OUTDIR}_${NOW}}" # avoid overwriting
FC_NN=0 # Firecracker NUMA node (matters for NVDIMM bus)
CL_NN=1 # fbpml-client NUMA node (must not interfere with Firecracker)
#logical_cpus "$FC_NN" # Populate the global $LOG_CORES array
physical_cores "$FC_NN" # Populate the global $PHYS_CORES array
# The root directory of all rootfs images
ROOTFS_PATH="$SCRIPT_DIR/rootfs"
# Benchmarks' input arguments.
declare -A INPUTS=(
['chameleon']='10 15'
['cnn_serving']='0'
['helloworld']=''
['image_rotate']='2'
['json_serdes']='0'
['matmul_fb']='512 512'
['matmul_fbpml']=''
['lr_serving']='0'
['lr_training']='0'
['pyaes']=''
['rnn_serving']='0'
['video_processing']='0'
)
# Parse $BENCH's input arguments into the $ARGS array
IFS=' ' read -r -a ARGS <<< "${INPUTS["$BENCH"]}"
# Commonly-indexed arrays of devices and their final snapshot paths, based on
# the provided command-line arguments
set +u
DEVICES=()
DEVICE_PATHS=()
if [ -z "$PMEM_PATH" ]; then
echo 'WARNING: Skipping runs on persistent memory; no such path was provided.'
else
DEVICES+=('dcpm')
DEVICE_PATHS+=("$PMEM_PATH")
fi
if [ -z "$NVME_PATH" ]; then
echo 'WARNING: Skipping runs on NVMe; no such path was provided.'
else
DEVICES+=('nvme')
DEVICE_PATHS+=("$NVME_PATH")
fi
if [ -z "$SSD_PATH" ]; then
echo 'WARNING: Skipping runs on Flash SSD; no such path was provided.'
else
DEVICES+=('ssd')
DEVICE_PATHS+=("$SSD_PATH")
fi
set -u
# Make sure all TAP interfaces are there
taps_check "$MANY"
# API socket path FMT string
SOCK_FMT="/tmp/firecracker-$BENCH-IDh.socket"
for d in "${!DEVICES[@]}"; do
device="${DEVICES[$d]}"
outdir="$OUTDIR/$BENCH/$device"
mkdir -vp "$outdir"
# Remove any existing old snapshots that may still be lying around from
# earlier?
#rm -rvf "${DEVICE_PATHS[$d]:?}/$BENCH"
# Create the directory
mkdir -vp "${DEVICE_PATHS[$d]}/$BENCH"
state_file_fmt="${DEVICE_PATHS[$d]}/$BENCH/snapshot-IDh.file"
memory_file_fmt="${DEVICE_PATHS[$d]}/$BENCH/memory-IDh.file"
# Copy benchmark's snapshot files in the given path.
for id in $(seq 0 1 $((MANY - 1))); do
idh="$(printf "%02X" "$id")"
sf="${state_file_fmt//IDh/$idh}"
mf="${memory_file_fmt//IDh/$idh}"
if [ "$device" = 'dcpm' ]; then
if [ -f "$sf" ]; then
echo "Snapshot $sf is already here. Skipping copying it..."
else
"$CP2M" "$SCRIPT_DIR/snapshot/$BENCH/snapshot-$idh.file" "$sf"
"$CP2M" "$SCRIPT_DIR/snapshot/$BENCH/memory-$idh.file" "$mf"
fi
else
"$CP" -av "$SCRIPT_DIR/snapshot/$BENCH/snapshot-$idh.file" "$sf"
"$CP" -av "$SCRIPT_DIR/snapshot/$BENCH/memory-$idh.file" "$mf"
fi
done
# Begin the runs for this device
for run in $(seq 1 1 "$RUNS"); do
outfile="$outdir/run$(printf "%02d" "$run").csv"
# Remove snapshot and rootfs files from the cache
echo 'Flushing all data to disk...'
sync
if [ "$EUID" -ne 0 ]; then
echo 'Attempting to remove related files from the page cache...'
shopt -s nullglob
"$FFORGET" \
"$(dirname "$state_file_fmt")"/*.file \
"$ROOTFS_PATH/$BENCH"/*.ext4
shopt -u nullglob
else
echo 'Dropping all page, dentry & inode caches...'
echo 3 >/proc/sys/vm/drop_caches
fi
# Spawn all Firecracker instances
sleep .2
for id in $(seq 0 1 $((MANY - 1))); do
idh="$(printf "%02X" "$id")"
# Unlink any old API socket
sock="${SOCK_FMT//IDh/$idh}"
rm -vf "$sock"
# Spawn a firecracker microVM, pinning all its threads (API server
# and VCPU(s) (any others?)) to a physical core.
# NOTE: There is no way to specify memory allocation policy using
# `taskset` (vs `numactl`), but the default policy is to allocate
# memory on the node of the core that triggers the allocation (see
# set_mempolicy(2), flag MPOL_DEFAULT).
"$TASKSET" \
--all-tasks \
--cpu-list "${PHYS_CORES[$((id % ${#PHYS_CORES[@]}))]}" \
"$FC_BIN" \
--id "${BENCH//_/-}-$idh" \
--api-sock "$sock" \
>/dev/null \
&
done
log_progress "$run" "$BENCH" "$device"
sleep .2
# Run multiclient
"$NUMACTL" \
--localalloc \
--cpunodebind="$CL_NN" \
"$FBPML_MULTICLIENT" \
--server-addr-fmt "$VM_ADDR_FMT" \
--num-uvms "$MANY" \
--pre-warm "$PREWARM" \
restore \
--api-sock "$SOCK_FMT" \
--state-file "$state_file_fmt" \
--memory-file "$memory_file_fmt" \
"${BENCH//_/-}" \
"${ARGS[@]}" \
>>"$outfile"
# Wait for all MicroVMs to terminate so that all API sockets and tap
# interfaces are released for the next run
"$KILLALL" --wait -TERM 'firecracker'
done
done
chown -R "$WHOSE":root "$OUTDIR"