-
Notifications
You must be signed in to change notification settings - Fork 40
/
cxl-global.sh
executable file
·408 lines (339 loc) · 10.8 KB
/
cxl-global.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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#!/bin/bash
#
# Global functions commonly used for CXL-memory emulation
#
# Huaicheng Li <lhcwhu@gmail.com>
#
source /users/hcli/proj/run/run-globals.sh
#-------------------------------------------------------------------------------
get_sysinfo()
{
uname -a
echo "--------------------------"
sudo numactl --hardware
echo "--------------------------"
lscpu
echo "--------------------------"
cat /proc/meminfo
}
flush_fs_caches()
{
echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null 2>&1
sleep 10
}
disable_nmi_watchdog()
{
echo 0 | sudo tee /proc/sys/kernel/nmi_watchdog >/dev/null 2>&1
}
disable_turbo()
{
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo >/dev/null 2>&1
}
# 0: no randomization, everyting is static
# 1: conservative randomization, shared libraries, stack, mmap(), VDSO and heap
# are randomized
# 2: full randomization, the above points in 1 plus brk()
disable_va_aslr()
{
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space >/dev/null 2>&1
}
disable_swap()
{
sudo swapoff -a
}
disable_ksm()
{
echo 0 | sudo tee /sys/kernel/mm/ksm/run >/dev/null 2>&1
}
disable_numa_balancing()
{
echo 0 | sudo tee /proc/sys/kernel/numa_balancing >/dev/null 2>&1
}
# disable transparent hugepages
disable_thp()
{
echo "never" | sudo tee /sys/kernel/mm/transparent_hugepage/enabled >/dev/null 2>&1
}
enable_turbo()
{
echo 0 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo >/dev/null 2>&1
}
disable_ht()
{
echo off | sudo tee /sys/devices/system/cpu/smt/control >/dev/null 2>&1
}
disable_node1_cpus()
{
echo 0 | sudo tee /sys/devices/system/node/node1/cpu*/online >/dev/null 2>&1
}
bring_all_cpus_online()
{
echo 1 | sudo tee /sys/devices/system/cpu/cpu*/online >/dev/null 2>&1
}
set_performance_mode()
{
#echo " ===> Placing CPUs in performance mode ..."
for governor in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
echo performance | sudo tee $governor >/dev/null 2>&1
done
}
disable_node1_mem()
{
echo 0 | sudo tee /sys/devices/system/node/node1/memory*/online >/dev/null 2>&1
}
check_pmqos()
{
local pmqospid=$(ps -ef | grep pmqos | grep -v grep | grep -v sudo | awk '{print $2}')
#echo $pmqospid
set_performance_mode
[[ -n "$pmqospid" ]] && return
sudo nohup ${TOPDIR}/pmqos >/dev/null 2>&1 &
sleep 3
# double check
pmqospid=$(ps -ef | grep pmqos | grep -v grep | grep -v sudo | awk '{print $2}')
if [[ -z "$pmqospid" ]]; then
echo "==> Error: failed to start pmqos!!!!"
exit
fi
}
# Keep all cores on Node 0 online while keeping all cores on Node 1 offline
configure_cxl_exp_cores()
{
# To be safe, let's bring all the cores online first
echo 1 | sudo tee /sys/devices/system/cpu/cpu*/online >/dev/null 2>&1
# Disable all cores on Node 1
echo 0 | sudo tee /sys/devices/system/node/node1/cpu*/online >/dev/null 2>&1
}
configure_base_exp_cores()
{
# To be safe, let's bring all the cores online first
echo 1 | sudo tee /sys/devices/system/cpu/cpu*/online >/dev/null 2>&1
# Leave half of the cores online for both Node 0 and Node 1
local cores_per_socket=$(lscpu | grep -i 'Core(s) per socket' | awk '{print $4}')
local half_cores_per_socket=$((cores_per_socket / 2))
local total_cores=$((cores_per_socket * 2))
for ((i = half_cores_per_socket; i < cores_per_socket; i++)); do
echo 0 | sudo tee /sys/devices/system/cpu/cpu$i/online >/dev/null 2>&1
done
for ((i = cores_per_socket + half_cores_per_socket; i < total_cores; i++)); do
echo 0 | sudo tee /sys/devices/system/cpu/cpu$i/online >/dev/null 2>&1
done
}
check_base_conf()
{
disable_nmi_watchdog
disable_va_aslr
disable_ksm
disable_numa_balancing
disable_thp
disable_ht
disable_turbo
configure_base_exp_cores
check_pmqos
disable_swap
nc=$(sudo numactl --hardware | grep 'node 1 cpus' | awk -F: '{print $2}')
# Everything looks correct
[[ ! -z $nc ]] && return
# Bummer, let's try bring the cores on Node 1 up...
echo "===> Warning: Base experiment environment NOT properly setup"
echo " All cores on Node 1 are offline..."
echo "===> Enabling all the cores on Node 1 now ..."
echo 1 | sudo tee /sys/devices/system/node/node1/cpu*/online >/dev/null 2>&1
nc=$(sudo numactl --hardware | grep 'node 1 cpus' | awk -F: '{print $2}')
[[ -z $nc ]] && echo "===> Failed to bring up all the cores on Node 1 for Base experiments ..." && exit
sleep 60
}
check_cxl_conf()
{
disable_nmi_watchdog
disable_va_aslr
disable_ksm
disable_numa_balancing
disable_thp
disable_ht
disable_turbo
configure_cxl_exp_cores
check_pmqos
disable_swap
nc=$(sudo numactl --hardware | grep 'node 1 cpus' | awk -F: '{print $2}')
# Everything looks correct
[[ -z $nc ]] && return
# Bummer, for CXL-emulation, let's take the cores on Node 1 offline...
echo "===> Warning: CXL experiment environment NOT properly setup"
echo " I see online cores [$nc] on Node 1..."
echo "===> Disabling all the cores on Node 1 now ..."
echo 0 | sudo tee /sys/devices/system/node/node1/cpu*/online >/dev/null 2>&1
nc=$(sudo numactl --hardware | grep 'node 1 cpus' | awk -F: '{print $2}')
[[ ! -z $nc ]] && echo "===> Failed to disable all the cores on Node 1 for CXL experiments ..." && exit
sleep 60
}
reset_base() {
disable_nmi_watchdog
disable_va_aslr
disable_ksm
disable_numa_balancing
disable_thp
disable_ht
disable_turbo
configure_cxl_exp_cores
check_pmqos
# make sure all cores are online
bring_all_cpus_online
}
monitor_resource_util()
{
while true; do
local o=$(sudo numactl --hardware)
local node0_free_mb=$(echo "$o" | grep "node 0 free" | awk '{print $4}')
local node1_free_mb=$(echo "$o" | grep "node 1 free" | awk '{print $4}')
echo "$(date +"%D %H%M%S") ${node0_free_mb} ${node1_free_mb}"
#pidstat -r -u -d -l -p ALL -U -h 5 100000000 > pidstat.log &
sleep 5
done
}
#-------------------------------------------------------------------------------
# For Emon Run
#-------------------------------------------------------------------------------
# $1: CXL experiment type array, EXL_EXPARR, (pass array by name!)
# $2: Base experiment type array
# $3: Result directory
init_emon_profiling()
{
# Attention: we are passing array name, and need convert it into an internal
# array format
local cxl_exparr_name=$1[@]
local cxl_exparr=( "${!cxl_exparr_name}" )
local base_exparr_name=$2[@]
local base_exparr=( "${!base_exparr_name}" )
local rstdir=$3
mkdir -p $rstdir
# CXL
for ((et = 0; et < ${#cxl_exparr[@]}; et++)); do
e=${cxl_exparr[$et]}
if [[ $e == "L100" ]]; then
run_cmd="numactl --cpunodebind 0 --membind 0 -- bash ./cmd.sh"
elif [[ $e == "L0" ]]; then
run_cmd="numactl --cpunodebind 0 --membind 1 -- bash ./cmd.sh"
elif [[ $e == "CXL-Interleave" ]]; then
run_cmd="numactl --cpunodebind 0 --interleave=all -- bash ./cmd.sh"
else
echo "==> Error: unsupported experiment type: [$e]"
exit
fi
echo "${run_cmd}" > emon-$e.sh
chmod u+x emon-$e.sh
# Keep one copy for record
cat cmd.sh > $rstdir/emon-${e}.cmd
cat emon-$e.sh >> $rstdir/emon-${e}.cmd
done
# BASE
for ((et = 0; et < ${#base_exparr[@]}; et++)); do
e=${base_exparr[$et]}
if [[ $e == "Base-Interleave" ]]; then
run_cmd="numactl --interleave=all -- bash ./cmd.sh"
else
echo "==> Error: unsupported experiment type: [$et]"
exit
fi
echo "${run_cmd}" > emon-$e.sh
chmod u+x emon-$e.sh
# Keep one copy for record
cat cmd.sh > $rstdir/emon-${e}.sh
cat emon-$e.sh >> $rstdir/emon-${e}.sh
done
}
# $1: CXL experiment type array, EXL_EXPARR, (pass array by name!)
# $2: Base experiment type array
cleanup_emon_profiling()
{
# Attention: we are passing array name, and need convert it into an internal
# array format
local cxl_exparr_name=$1[@]
local cxl_exparr=( "${!cxl_exparr_name}" )
local base_exparr_name=$2[@]
local base_exparr=( "${!base_exparr_name}" )
# CXL
for ((et = 0; et < ${#cxl_exparr[@]}; et++)); do
e=${cxl_exparr[$et]}
rm -rf emon-$e.sh
done
# BASE
for ((et = 0; et < ${#base_exparr[@]}; et++)); do
e=${base_exparr[$et]}
rm -rf emon-$e.sh
done
}
# Run emon for one workload
# $1: experiment type, e.g. "L100", "CXL-Interleave", etc.
# $2: experiment id, e.g., "1", "2", etc.
# $3: result directory
# $4: memory footprint in MB (for running more splits)
run_emon_one()
{
local e=$1
local id=$2
local rstdir=$3
local m=$4
# log files
local sysinfof=$rstdir/${e}-${id}-emon.sysinfo
local pidstatf=$rstdir/${e}-${id}-emon.pidstat
local memf=$rstdir/${e}-${id}-emon.mem
local emonvf=$rstdir/${e}-${id}-emon.v
local emonmf=$rstdir/${e}-${id}-emon.m
local emondatf=$rstdir/${e}-${id}-emon.dat
local epid
flush_fs_caches
get_sysinfo > $sysinfof 2>&1
sudo ${EMON} -v > $emonvf
sudo ${EMON} -M > $emonmf
# if needed, run memeater first
# TODO ...
# Run emon along with the workload
./emon-${e}.sh > $rstdir/out-${e}-${id} &
local c=$(basename ${PWD} | awk -F- '{print $1}')
epid=$!
#epid=$(ps -ef | grep "${GAPBS_DIR}/$c" | grep -v grep | awk '{print $2}')
echo " => $e"
sudo ${EMON} -i ${EMON_EVENT_FILE} -f "$emondatf" >/dev/null 2>&1 &
pidstat -r -u -d -l -v -T ALL -p ALL -U -h 5 1000000 > $pidstatf &
echo "Date Time Node0-Free-Mem-MB Node1-Free-Mem-MB" > $memf
monitor_resource_util >>$memf 2>&1 &
mpid=$!
disown $mpid # avoid the "killed" message
wait $epid
sudo $EMON -stop
killall pidstat >/dev/null 2>&1
kill -9 $mpid >/dev/null 2>&1
}
# $1: "CXL" or "Base"
# $2: Experiment type array
# $3: Experiment id
# $4: Result directory
# $5: Memory footprint in MB (for running more splits)
run_emon_all()
{
# Attention: we are passing array name, and need convert it into an internal
# array format
local exparr_name=$2[@]
local exparr=( "${!exparr_name}" )
local id=$3
local rstdir=$4
local m=$5
if [[ $1 == "CXL" ]]; then
check_cxl_conf
elif [[ $1 == "BASE" ]]; then
check_base_conf
else
echo ""
echo "===> Error: only support CXL or Base!"
echo ""
exit
fi
mkdir -p $rstdir
sudo $EMON -v > $rstdir/emon-v.dat
sudo $EMON -M > $rstdir/emon-m.dat
# CXL emon profiling
for ((et = 0; et < ${#exparr[@]}; et++)); do
run_emon_one "${exparr[$et]}" "${id}" "${rstdir}" "${m}"
done
}