This repository was archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathspec-chop-tracer.sh
executable file
·154 lines (127 loc) · 6.24 KB
/
spec-chop-tracer.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
#!/usr/bin/env sh
#
# ----------------------------------------------------------------------------
#
# Copyright 2019 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ----------------------------------------------------------------------------
#
# SPEC-CHOP: ChopStiX support scripts to run SPEC benchmarks
#
# Author: Ramon Bertran Monfort <[email protected]>
#
# Copyright 2018 IBM Corporation
# IBM (c) 2018 All rights reserved
#
set -e # Finish right after a non-zero return command
set -u # Finish right after a undefined expression is used
set -a # All following variables are exported
SPEC_CHOP_PATH=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P )
. "$SPEC_CHOP_PATH/spec-chop.config"
for cspec in $SPEC_CHOP_BENCHMARKS; do
# Look for sample DB for benchmark
DB_NAME="$cspec.$SPEC_CHOP_SAMPLE_EVENT.$SPEC_CHOP_SAMPLE_PERIOD.db"
DB_PATH="$(find "$SPEC_CHOP_DB_BASEPATH/sample/$SPEC_CHOP_SAMPLE_EVENT/$SPEC_CHOP_SAMPLE_PERIOD/" -name "$DB_NAME")"
if [ -z "$DB_PATH" ]; then
scPrint "No database found for $cspec using SAMPLE_EVENT=$SPEC_CHOP_SAMPLE_EVENT and SAMPLE_PERIOD=$SPEC_CHOP_SAMPLE_PERIOD"
continue
fi
scPrint "Database found: $DB_PATH"
export CHOPSTIX_OPT_DATA="$DB_PATH"
scPrint "Executing chop-score-table to find the right set of settings for the given constraints ..."
temp=$(mktemp)
cache_file="${DB_PATH}.chop-score-table"
update_score=1
error=0
if [ -f "$cache_file" ]; then
scPrint "Cache file found $cache_file"
md5sum=$(echo "$(ls -ltha "$DB_PATH")" 0 "$SPEC_CHOP_MAX_FUNCTIONS" "$SPEC_CHOP_MIN_FUNCTION_SIZE" | md5sum)
if [ "$(head -n 1 < "$cache_file")" = "$md5sum" ]; then
scPrint "Cache contents up to date!"
update_score=0
cp -f "$cache_file" "$temp"
fi
fi
if [ "$update_score" -eq 1 ]; then
scPrint "No cache file found or requires update. Executing chop-score-table command ... "
echo "$(ls -ltha "$DB_PATH") 0 $SPEC_CHOP_MAX_FUNCTIONS $SPEC_CHOP_MIN_FUNCTION_SIZE" | md5sum > "$temp"
set +e
chop-score-table "$DB_PATH" 0 "$SPEC_CHOP_MAX_FUNCTIONS" "$SPEC_CHOP_MIN_FUNCTION_SIZE" >> "$temp"
set -e
cp -f "$temp" "$cache_file"
fi
set +e
grep "chop list functions" < "$temp" > /dev/null 2>&1
error=$?
set -e
if [ "$error" -ne 0 ]; then
scPrint "WARNING --------------------------------------------------------------------------------"
scPrint "WARNING Unable to find optimal settings for $cspec. Relax constraints of check input db "
scPrint "WARNING --------------------------------------------------------------------------------"
continue
fi
scPrint "Gathering information"
listcmd=$(grep "chop list functions" < "$temp")
coverage=$(grep "Best score" < "$temp" | cut -d " " -f 3 | cut -d "." -f 1)
scPrint "Best coverage: $coverage%"
if [ "$coverage" -lt "$SPEC_CHOP_MIN_COVERAGE" ]; then
scPrint "WARNING --------------------------------------------------------------------------------"
scPrint "WARNING Low coverage detected for $cspec. Use other tracing methods to increase coverage"
scPrint "WARNING --------------------------------------------------------------------------------"
fi
scPrint "Processing selected functions"
eval "$listcmd" | grep -v ^ID > "$temp"
while read -r line; do
funcname=$(echo "$line" | cut -f 2);
scPrint "Processing selected function: $funcname"
size=$(printf "%06d" "$(echo "$line" | cut -f 3)");
module=$(echo "$line" | cut -f 4);
coverage=$(echo "$line" | cut -f 5);
coverage=$(printf "%04d" "$(echo "$(echo "$coverage" | sed -e "s/%//") * 10" | bc | cut -d "." -f 1)")
scPrint "Searching for module $module ..."
module_file=$(find "$SPEC_CHOP_SPEC_INSTALL_DIR/benchspec/CPU/$cspec/exe/" -name "$module")
if [ -z "$module_file" ]; then
scPrint "WARNING --------------------------------------------------------------------------------"
scPrint "WARNING Unable to find module $module for $cspec"
scPrint "WARNING --------------------------------------------------------------------------------"
continue
fi
scPrint "Searching for addresses of $funcname in $module ..."
addrs_begin=$(chop-marks-ppc64 "$module_file" "$funcname" -cache | grep begin | cut -d ' ' -f 2 | paste -sd ",")
addrs_end=$(chop-marks-ppc64 "$module_file" "$funcname" -cache | grep end | cut -d ' ' -f 2 | paste -sd ",")
if [ -z "$addrs_begin" ] || [ -z "$addrs_end" ]; then
scPrint "WARNING --------------------------------------------------------------------------------"
scPrint "WARNING Unable to find module addresses for $funcname in $module of $cspec"
scPrint "WARNING --------------------------------------------------------------------------------"
continue
fi
cmd="$SPEC_CHOP_PATH/spec-chop-lsf-submit.sh"
cmd="$cmd WRAPPER $SPEC_CHOP_PATH/spec-chop-wrapper-trace.sh"
cmd="$cmd TRACE_PATH $SPEC_CHOP_DB_BASEPATH/trace/$SPEC_CHOP_SAMPLE_EVENT/$SPEC_CHOP_SAMPLE_PERIOD/$cspec/$coverage.$size.$module.$funcname"
# shellcheck disable=SC2089
cmd="$cmd BEGIN '$addrs_begin'"
cmd="$cmd END '$addrs_end'"
cmd="$cmd BENCHMARKS $cspec"
cmd="$cmd BENCH_NAME $cspec"
while [ "$(bjobs | grep -c "$(whoami)")" -gt "$SPEC_CHOP_MAX_LSF_JOBS" ]; do
scPrint "Wait jobs to finish ... (sleep a minute)"
sleep 60
done;
# shellcheck disable=SC2086,SC2090
SPEC_CHOP_BENCHMARKS=$cspec $cmd
done < "$temp"
rm -f "$temp"
done;
exit 0