forked from heechul/memguard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
executable file
·637 lines (550 loc) · 11.9 KB
/
functions
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
#!/bin/bash
export PATH=$HOME/bin:$PATH:..
error()
{
echo "ERR: $*"
exit
}
if grep "Core(TM)2" /proc/cpuinfo; then
arch=core2
llc_miss_evt="7024"
elif grep "Core(TM) i5" /proc/cpuinfo; then
arch=snb
llc_miss_evt="8b0" #7024
else
arch=intel
llc_miss_evt="412e" # LLC misses
fi
if [ "$arch" = "core2" ]; then
RMIN="1200"
elif [ "$arch" = "snb" ]; then
RMIN="2400"
else
echo "arch is $arch. default=1100MB/s"
RMIN=1200
fi
if uname -a | grep x86_64; then
archbit="64"
else
archbit="32"
fi
PERIOD_US=1000
outputfile="log.txt"
echo "ARCH: $arch ($archbit bit)"
echo "llc_evt: 0x${llc_miss_evt}"
echo "rmin: $RMIN"
echo "period: $PERIOD_US us"
spec2006_xeon_high_rtas13="
470.lbm
462.libquantum
437.leslie3d
433.milc
482.sphinx3
450.soplex
434.zeusmp"
spec2006_xeon_rta13="
470.lbm
462.libquantum
437.leslie3d
433.milc
482.sphinx3
450.soplex
434.zeusmp
483.xalancbmk
436.cactusADM
403.gcc
473.astar
471.omnetpp
447.dealII
481.wrf
400.perlbench"
spec2006_xeon_high="
470.lbm
462.libquantum
459.GemsFDTD
437.leslie3d
433.milc
482.sphinx3
429.mcf
450.soplex
434.zeusmp
410.bwaves"
spec2006_xeon_medium="
483.xalancbmk
436.cactusADM
403.gcc
473.astar
471.omnetpp
447.dealII
481.wrf
400.perlbench"
spec2006_xeon_low="
445.gobmk
454.calculix
458.sjeng
401.bzip2
435.gromacs
456.hmmer
444.namd
464.h264ref
465.tonto
453.povray
416.gamess"
spec2006_xeon_all="$spec2006_xeon_high $spec2006_xeon_medium $spec2006_xeon_low"
allspec2006sorted_high="470.lbm
437.leslie3d
462.libquantum
410.bwaves
471.omnetpp
459.GemsFDTD
482.sphinx3
429.mcf
450.soplex"
allspec2006sorted_middle="433.milc
434.zeusmp
483.xalancbmk
436.cactusADM
403.gcc
456.hmmer
473.astar
401.bzip2
400.perlbench
447.dealII
454.calculix
464.h264ref"
allspec2006sorted_low="445.gobmk
458.sjeng
435.gromacs
481.wrf
444.namd
465.tonto
416.gamess
453.povray"
allspec2006sorted_highmiddle="$allspec2006sorted_high $allspec2006sorted_middle"
allspec2006sorted="470.lbm
437.leslie3d
462.libquantum
410.bwaves
471.omnetpp
459.GemsFDTD
482.sphinx3
429.mcf
450.soplex
433.milc
434.zeusmp
483.xalancbmk
436.cactusADM
403.gcc
456.hmmer
473.astar
401.bzip2
400.perlbench
447.dealII
454.calculix
464.h264ref
445.gobmk
458.sjeng
435.gromacs
481.wrf
444.namd
465.tonto
416.gamess
453.povray"
# 81 - 53 + 1 = 29
allspec2006="400.perlbench
401.bzip2
403.gcc
429.mcf
445.gobmk
456.hmmer
458.sjeng
462.libquantum
464.h264ref
471.omnetpp
473.astar
483.xalancbmk
410.bwaves
416.gamess
433.milc
434.zeusmp
435.gromacs
436.cactusADM
437.leslie3d
444.namd
447.dealII
450.soplex
453.povray
454.calculix
459.GemsFDTD
465.tonto
470.lbm
481.wrf
482.sphinx3"
# 101 - 84 + 1 = 18
midhighmem="401.bzip2
403.gcc
410.bwaves
429.mcf
433.milc
434.zeusmp
436.cactusADM
437.leslie3d
447.dealII
450.soplex
459.GemsFDTD
462.libquantum
465.tonto
471.omnetpp
473.astar
481.wrf
482.sphinx3
483.xalancbmk
"
stfm="462.libquantum
437.leslie3d
450.soplex
433.milc
470.lbm
482.sphinx3
459.GemsFDTD
436.cactusADM
483.xalancbmk
473.astar
471.omnetpp
401.bzip2
447.dealII
481.wrf
465.tonto
403.gcc
"
backup()
{
dir=$1
mkdir -p $dir
mv *.perf $dir
mv *.trace $dir
mv *.eps $dir
# mv *.scr $dir
mv xeon*.dat $dir
mv /run/out-*.txt $dir
chown -R heechul.heechul $dir
}
log_echo()
{
echo "LOG: $*"
echo "$*" >> $outputfile
}
finish()
{
sed 's/,//g' $outputfile | sed 's/ /,/g' > ${outputfile%.txt}.csv
backup backup-`date +%F-%H-%M`
rm -f backup-last
ln -s backup-`date +%F-%H-%M` backup-last
rmmod memguard
chown heechul.heechul $outputfile
log_echo "============================="
exit
}
check_root()
{
if [ `whoami` != "root" ]; then
error "root perm. is needed"
fi
}
disable_prefetcher()
{
[ "$arch" = "core2" ] || return
check_root
modprobe msr
[ -f "./disable_core2_prefetch" ] || error "Failed to disable prefetcher"
./disable_core2_prefetch >& /dev/null
log_echo "disable hardware prefetcher"
}
enable_prefetcher()
{
[ "$arch" = "core2" ] || return
check_root
modprobe msr
[ -f "./enable_core2_prefetch" ] || error "Failed to enable prefetcher"
./enable_core2_prefetch >& /dev/null
log_echo "enable hardware prefetcher"
}
set_cpus()
{
cpus=$1
idx=0
check_root
for v in $cpus; do
echo "Set CPU${idx} $v"
echo $v > /sys/devices/system/cpu/cpu${idx}/online
echo "performance" > /sys/devices/system/cpu/cpu${idx}/cpufreq/scaling_governor
idx=`expr $idx + 1`
done >& /dev/null
}
parse_log()
{
f=$1
if [ -f "$f" ]; then
cache=`grep $llc_miss_evt $f | awk '{ print $1 }'`
instr=`grep instructions $f | awk '{ print $1 }'`
elaps=`grep elapsed $f | awk '{ print $1 }'`
echo ${f%.*.*.perf} $instr $cache
fi
}
init_cgroup()
{
mount | grep cgroup || mount -t cgroup xxx /sys/fs/cgroup
[ ! -d "/sys/fs/cgroup/system" ] && mkdir /sys/fs/cgroup/system
cat /sys/devices/system/cpu/online > /sys/fs/cgroup/system/cpuset.cpus
echo 0 > /sys/fs/cgroup/system/cpuset.mems
for t in `cat /sys/fs/cgroup/tasks`; do
echo $t > /sys/fs/cgroup/system/tasks
done >& /dev/null
# cat /sys/fs/cgroup/system/tasks
echo 1024 > /sys/fs/cgroup/system/cpu.shares
[ ! -d "/sys/fs/cgroup/experiment" ] && mkdir /sys/fs/cgroup/experiment
cat /sys/devices/system/cpu/online > /sys/fs/cgroup/experiment/cpuset.cpus
echo 0 > /sys/fs/cgroup/experiment/cpuset.mems
echo $$ > /sys/fs/cgroup/experiment/tasks
echo 32768 > /sys/fs/cgroup/experiment/cpu.shares
tasks=`cat /sys/fs/cgroup/experiment/tasks`
echo "pid of exp. bash: $tasks"
}
# create cgroup. if exist, delete and re-create.
# do not assign tasks, address mask, and pattern:
# these are the user's reponsibility.
init_cgroup_color()
{
for c in 0 1 2 3; do
if [ -d "/sys/fs/cgroup/core$c" ]; then
cat /sys/fs/cgroup/core$c/tasks > /sys/fs/cgroup/tasks
rmdir /sys/fs/cgroup/core$c/
fi
mkdir /sys/fs/cgroup/core$c/
pushd /sys/fs/cgroup/core$c/
echo $c > cpuset.cpus
echo 0 > cpuset.mems
popd
done
} > /dev/null
print_settings()
{
cat /sys/kernel/debug/memguard/control
cat /sys/kernel/debug/memguard/limit
echo
}
print_stats()
{
cat /sys/kernel/debug/memguard/failcnt
cat /sys/kernel/debug/memguard/usage
echo
}
do_init_common()
{
check_root
local budgets=$1
local shares=$2
local reclaim=$3
local maxbw=$4
local exclusive=$5
local mbs=$6
local codebase=`(cd ~/Projects/memguard; git log | head -n 1)`
local option="g_hw_type=$arch g_budget_max_bw=$RMIN g_period_us=$PERIOD_US"
[ "$reclaim" = "1" ] && option="$option g_use_reclaim=1"
echo "loading module b$budgets s$shares m$mbs r$reclaim m$maxbw c$codebase"
lsmod | grep memguard && rmmod memguard
sleep 1
insmod ./memguard.ko $option
[ ! -z "$maxbw" ] && set_max_bw $maxbw
[ ! -z "$budgets" ] && set_limit "$budgets"
[ ! -z "$shares" ] && set_share "$shares"
[ ! -z "$exclusive" ] && set_exclusive_mode $exclusive
[ ! -z "$mbs" ] && set_limit_mb "$mbs"
echo "m$maxbw|b$budgets|s$shares|m$mbs|r$reclaim|e$exclusive|c$codebase" | sed 's/ /_/g' >> $outputfile
print_settings
}
do_init_budget()
{
do_init_common "$1" "" "$2" "$3" "$4"
}
do_init_share()
{
local shares="$1"
local reclaim=$2
local maxbw=$3
local exclusive=$4
do_init_common "" "$shares" "$reclaim" "$maxbw" "$exclusive"
}
do_init_mb()
{
local mbs="$1"
local reclaim=$2
local exclusive=$3
do_init_common "" "" "$reclaim" "" "$exclusive" "$mbs"
}
set_exclusive_mode()
{
check_root
local mode=$1
echo exclusive $mode > /sys/kernel/debug/memguard/control
# print_settings
}
set_reclaim()
{
check_root
echo reclaim $1 > /sys/kernel/debug/memguard/control
# print_settings
}
set_max_bw()
{
check_root
local maxbw=$1
echo maxbw $maxbw > /sys/kernel/debug/memguard/control
# print_settings
}
set_share()
{ # load module
check_root
local shares=$1
echo "reset" > /sys/kernel/debug/memguard/failcnt
echo $shares > /sys/kernel/debug/memguard/share
# print_settings
}
set_limit()
{
check_root
budgets=$1 #in pct
echo "reset" > /sys/kernel/debug/memguard/failcnt
echo $budgets > /sys/kernel/debug/memguard/limit
# print_settings
}
set_limit_mb()
{
check_root
local budgets=$1 #in pct
echo "reset" > /sys/kernel/debug/memguard/failcnt
echo mb $budgets > /sys/kernel/debug/memguard/limit
# print_settings
}
kill_spec()
{
kill -9 `ps x | grep gcc | grep -v perf | awk '{ print $1 }'` >& /dev/null
}
run_bench()
{
local name=$1
local core=$2
if [ "$name" = "000.bandwidth" ]; then
perf stat -e instructions:u -o C$core.$name.perf ./bandwidth -a read -c $core -t 10
elif [ "$name" = "000.latency" ]; then
perf stat -e instructions:u -o C$core.$name.perf ./latency -m 32768 -i 10000 -c $core
elif [ "$name" = "000.cpuhog" ]; then
taskset -c $core perf stat -e instructions:u -o C$core.$name.perf ./cpuhog
else
taskset -c $core perf stat -e instructions:u -o C$core.$name.perf /ssd/cpu2006/bin/specinvoke -d /ssd/cpu2006/benchspec/CPU2006/$name/run/run_base_ref_gcc43-${archbit}bit.0000 -e speccmds.err -o speccmds.stdout -f speccmds.cmd -C -q
fi
}
intval=1
set_cpu_interval()
{
intval=$1
echo "New interval: $intval"
}
do_exp_1core()
{
check_root
echo "" > /sys/kernel/debug/tracing/trace
local bench=$1
local core=$2
run_bench $bench $core &
echo $@ >> $outputfile
sleep 10
cat /sys/kernel/debug/memguard/failcnt
rmmod memguard
echo sending kill signal
kill -9 `ps x | grep gcc | grep -v perf | awk '{ print $1 }'` >& /dev/null
kill -9 `ps x | grep gcc | grep -v perf | awk '{ print $1 }'` >& /dev/null
killall -9 fps bandwidth latency cpuhog >& /dev/null
cat /sys/kernel/debug/tracing/trace > tmp.trace
output="`parse_log C$core.$bench.perf`"
cat tmp.trace | grep "$core\]" > C$core.$bench.trace
grep org C$core.$bench.trace | awk '{ print $7 }' > C$core.$bench.dat
log_echo $output
chown heechul.heechul $outputfile *.trace *.perf
chmod +w $outputfile
sync
}
do_exp_ncore()
{
check_root
echo "" > /sys/kernel/debug/tracing/trace
i=0
for var in "$@"
do
echo "Run $var at $i"
run_bench $var $i &
i=`expr $i + $intval`
done
echo $@ >> $outputfile
sleep 10
# log_echo `cat /sys/kernel/debug/memguard/failcnt | grep exclusive`
# log_echo `cat /sys/kernel/debug/memguard/failcnt | grep cpuhog`
cat /sys/kernel/debug/memguard/failcnt
rmmod memguard
echo sending kill signal
kill -9 `ps x | grep gcc | grep -v perf | awk '{ print $1 }'` >& /dev/null
kill -9 `ps x | grep gcc | grep -v perf | awk '{ print $1 }'` >& /dev/null
killall -9 fps bandwidth latency cpuhog >& /dev/null
cat /sys/kernel/debug/tracing/trace > ${#}core.trace
i=0
output=""
for var in "$@"; do
output="$output `parse_log C$i.$var.perf`"
cat ${#}core.trace | grep "$i\]" > C$i.$var.trace
grep org C$i.$var.trace | awk '{ print $7 }' > C$i.$var.dat
i=`expr $i + $intval`
done
log_echo $output
chown heechul.heechul $outputfile *.trace *.perf
chmod +w $outputfile
sync
}
plot()
{
# file msut be xxx.dat form
bench=$1
data=$2
xstart=$3
xfinish=$4
ymax=$5
[ -z "$xstart" ] && xstart=0
[ -z "$xfinish" ] && xfinish=10000
[ -z "$ymax" ] && ymax=500000
file="${bench}_${xstart}-${xfinish}"
cat > ${file}.scr <<EOF
set terminal postscript eps enhanced color "Times-Roman" 22
set yrange [0:$ymax]
set xrange [$xstart:$xfinish]
plot '$data' ti "$bench" w l
EOF
gnuplot ${file}.scr > ${file}.eps
epspdf ${file}.eps
}
stop_services()
{
check_root
service stop mysql
service stop apache2
dropbox stop
}
init_system()
{
echo "one time things"
echo 8 8 8 8 > /proc/sys/kernel/printk
echo 2048 > /sys/kernel/debug/tracing/buffer_size_kb
export PATH=$HOME/bin:$PATH
# init_cgroup
stop_services
check_root
rmmod memguard
} > /dev/null