-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.py
293 lines (255 loc) · 6.48 KB
/
templates.py
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
#!/usr/bin/env python
PREAMBLE = """#!/bin/bash
RTPID=""
TRACERS=""
BG_TASKS=""
DURATION={duration}
echo "Running {name} for $DURATION seconds under {sched}..."
function progress_wait()
{{
COUNT=0
while (( $COUNT < $1 ))
do
echo -n ". "
sleep 1
COUNT=$((COUNT + 1))
done
echo
}}
function cleanup_tracers()
{{
if [ -n "$TRACERS" ]
then
kill -SIGUSR1 $TRACERS
echo "Sent SIGUSR1 to stop tracers..."
wait $TRACERS
fi
}}
function cleanup_background()
{{
if [ -n "$BG_TASKS" ]
then
kill -SIGTERM $BG_TASKS
echo "Sent SIGTERM to stop background tasks..."
wait $BG_TASKS
fi
}}
function cleanup_tasks()
{{
if [ -n "$RTPID" ]
then
kill $RTPID
echo "Sent SIGTERM to stop experiment tasks..."
wait $RTPID
fi
}}
function backup_file()
{{
SRC=$1
TGT=$2
if [ -z "$TGT" ]
then
TGT=$SRC
fi
if ! [ -e "$TGT" ]
then
cp "$SRC" "$TGT"
else
CNT=1
while [ -e "$TGT.$CNT" ]
do
CNT=$((CNT + 1))
done
cp "$SRC" "$TGT.$CNT"
fi
}}
function die()
{{
cleanup_background
cleanup_tasks
cleanup_tracers
setsched Linux
exit 1
}}
trap 'die' SIGUSR1 SIGTERM SIGINT
# Make sure the scheduler that we want to run actually is available.
if ! grep -q {sched} /proc/litmus/plugins/loaded 2>/dev/null
then
echo "Error: scheduler {sched} is not supported by this kernel."
die
fi
# Make sure we have access to liblitmus
which release_ts > /dev/null
if [ "$?" -ne 0 ]
then
echo "Cannot find release_ts in PATH."
echo "Make sure liblitmus is part of the shell's search path."
die
fi
# Auto-discover cache topology
SOCKETS=`cat /sys/devices/system/cpu/*/topology/physical_package_id | sort | uniq`
declare -A CPUS_IN_SOCKET
for S in $SOCKETS
do
CPUS_IN_SOCKET[$S]=`grep -l $S /sys/devices/system/cpu/*/topology/physical_package_id | egrep -o '[0-9]+'`
done
declare -a CORE
M=0
for S in $SOCKETS
do
for C in ${{CPUS_IN_SOCKET[$S]}}
do
CORE[$M]=$C
M=$((M + 1))
done
done
"""
SET_DSP = """
echo "Setting processor {scheduling_core} to be the dedicated scheduling core."
echo {scheduling_core} > /proc/litmus/release_master
if [ "$?" -ne 0 ]
then
echo "Could not set release master"
die
fi
"""
SET_SCHEDULER = """
setsched {scheduler}
if [ "$?" -ne 0 ]
then
echo "Scheduler {scheduler} could not be activated"
die
fi
"""
DEBUG_TRACE = """
echo "Launching TRACE() debug tracer."
LOG_FILE="debug_host=$(hostname)_scheduler=$(showsched)_trace={name}.log"
# Check environmental variable
if ! [ -z "$KEEP_DEBUG_LOGS" ]
then
# Keep a copy of the old log if we are debugging.
[ -e $LOG_FILE ] && backup_file $LOG_FILE
fi
{taskset}cat /dev/litmus/log > $LOG_FILE &
TRACERS="$TRACERS $!"
"""
OVERHEAD_TRACE = """
# Make sure we have access to the ft-trace-overheads wrapper script
which ft-trace-overheads > /dev/null
if [ "$?" -ne 0 ]
then
echo "Cannot find ft-trace-overheads in PATH"
die
fi
echo -n "Launching Feather-Trace overhead tracer..."
FT_OUT=`mktemp`
{taskset}ft-trace-overheads -s {name} > "$FT_OUT" &
TRACERS="$TRACERS $!"
while ! grep -q 'Waiting for SIGUSR1' "$FT_OUT"
do
sleep 0.1
done
echo ' ok.'
"""
PROCESS_OVERHEAD_TRACE = """
which ft-sort-traces > /dev/null
if [ "$?" -ne 0 ]
then
echo "Cannot find ft-sort-traces in PATH"
die
fi
function fail() {{
echo
echo "Overhead processing failed."
exit 2
}}
echo "**** [{name}] ****" >> overhead-processing.log
# See https://github.com/LITMUS-RT/feather-trace-tools/blob/master/doc/howto-trace-and-process-overheads.md
# (1) Sort
echo -n "Sorting overhead traces..."
ft-sort-traces overheads_host=*_trace={name}_{{msg,cpu}}=*.bin >> overhead-processing.log 2>&1 || fail
echo " ok."
# (2) Split
echo -n "Extracting samples..."
ft-extract-samples overheads_host=*_trace={name}_{{msg,cpu}}=*.bin >> overhead-processing.log 2>&1 || fail
echo " ok."
# Clean up...
echo -n "Moving raw overhead files to $(pwd)/raw-overhead-files ..."
mkdir -p raw-overhead-files/ >> overhead-processing.log 2>&1 || fail
mv -v overheads_host=*_trace={name}_{{msg,cpu}}=*.bin raw-overhead-files/ >> overhead-processing.log 2>&1 || fail
echo " ok."
# (3) Combine
echo -n "Aggregating samples..."
ft-combine-samples --std overheads_host=*_trace={name}_{{msg,cpu}}=*_overhead=*.float32 >> overhead-processing.log 2>&1
echo " ok."
# Clean up...
echo -n "Moving aggregated sample files to $(pwd)/overhead-samples ..."
mkdir -p overhead-samples/ >> overhead-processing.log 2>&1 || fail
mv -v overheads_host=*_trace={name}_{{msg,cpu}}=*_overhead=*.float32 overhead-samples/ >> overhead-processing.log 2>&1 || fail
echo " ok."
echo "Hint: run ft-compute-stats combined-overheads_*.float32 > stats.csv to obtain summary statistics."
"""
CLEAN_UP_RAW_FILES = """
echo -n "Cleaning up raw overhead files..."
rm -vf raw-overhead-files/overheads_host=*_trace={name}_{{msg,cpu}}=*.bin >> overhead-processing.log 2>&1 || fail
rm -vf overhead-samples/overheads_host=*_trace={name}_{{msg,cpu}}=*_overhead=*.float32 >> overhead-processing.log 2>&1 || fail
echo " ok."
"""
SCHEDULE_TRACE = """
which st_trace > /dev/null
if [ "$?" -ne 0 ]
then
echo "Cannot find st_trace in PATH"
die
fi
echo -n "Launching sched_trace schedule tracer..."
ST_OUT=`mktemp`
{taskset}st_trace -s {name} > "$ST_OUT" &
TRACERS="$TRACERS $!"
while ! grep -q 'Waiting for SIGUSR1' "$ST_OUT"
do
sleep 0.1
done
echo ' ok.'
"""
SET_AFFINITY_MASK = "taskset 0x{affinity_mask:x} "
SET_AFFINITY = "taskset -c {core_list} "
TASK_LAUNCH_PREFIX = """
echo -n "Launching {num_tasks} real-time tasks..."
"""
RTSPIN = """
# Task {tid}
{taskset}rtspin -w -s {scale} {partition} {prio} {reservation} {wss} {timer} {cost:.2f} {period:.2f} $DURATION &
RTPID="$RTPID $!"
"""
RT_LAUNCH = """
# Task {tid}
{taskset}rt_launch -w {partition} {prio} {reservation} {cost:.2f} {period:.2f} -- {cmd} &
RTPID="$RTPID $!"
# Launch killer task to timeout the launched command
(sleep $DURATION; kill $! 2>/dev/null) &
RTPID="$RTPID $!"
"""
TASK_LAUNCH_SUFFIX = """
# Wait for tasks to finish launching
release_ts -W {num_tasks}
echo ' ok.'
"""
MAIN_EXP = """
release_ts -f {num_tasks}
progress_wait $DURATION
wait $RTPID
echo All tasks finished.
cleanup_background
cleanup_tracers
"""
BACKGROUND_WORKLOAD="""
NUM_CPUS=`getconf _NPROCESSORS_ONLN`
echo -n "Launching $NUM_CPUS background tasks with a WSS of {wss_in_pages} pages each..."
for core in `seq 1 $NUM_CPUS`
do
taskset -c $(($core - 1)) nice rtspin -B -m {wss_in_pages} &
BG_TASKS="$BG_TASKS $!"
done
echo " ok."
"""