summaryrefslogtreecommitdiffstats
path: root/run_case_study_dag.py
diff options
context:
space:
mode:
Diffstat (limited to 'run_case_study_dag.py')
-rwxr-xr-xrun_case_study_dag.py244
1 files changed, 244 insertions, 0 deletions
diff --git a/run_case_study_dag.py b/run_case_study_dag.py
new file mode 100755
index 0000000..9ff1809
--- /dev/null
+++ b/run_case_study_dag.py
@@ -0,0 +1,244 @@
1#/usr/bin/python3
2# Make sure to run this as root!!!!!
3import os
4import sys
5import re
6import csv
7import time
8import subprocess
9
10
11# Single tasks:
12# 0, binary_name, task_name, iterations, my_core, runID, save?, period, criticality, phase, cost, deadline
13# Paired tasks:
14# 1, binary_name, task_name, iterations, my_core, runID, save?, period, criticality, phase, cost, deadline, other_binary_name, other_task_name, other_cost, other_deadline
15
16
17binary_path = "./SD-VBS/dag_binaries/"
18stderr_file = open("./deadline_misses", 'w+')
19
20LITMUS = True
21
22BINARY_NAME = 1
23TASK_NAME = 2
24NUM_ITERS = 3
25CORE_NUM = 4
26RUN_ID = 5
27SAVE_RESULT = 6
28PERIOD = 7
29CRT_LEVEL = 8
30PHASE= 9
31COST = 10
32DEADLINE = 11
33
34OTHER_BINARY_NAME = 12
35OTHER_TASK_NAME = 13
36OTHER_COST = 14
37OTHER_DEADLINE = 15
38# OTHER_CORE_NUM = 12
39# PAIR_ID = 12
40
41all_pids=[]
42def run(command):
43 print(command)
44 os.system(command)
45
46def addpid(pid):
47 with open("./pids.txt", "a") as f:
48 f.write(str(pid) + "\n")
49def ID2PID(lookupID):
50 res = None
51 # Find benchmark PID (avoid getting shell or numactl PID)
52 try:
53 res = subprocess.check_output("pgrep -af '" + lookupID + "' | grep -v numactl", shell=True)
54 except:
55 res = None
56 if res:
57 # Ignore the newline
58 return res.decode("utf-8").split(" ")[0].strip()
59 else:
60 return None
61
62def main(pathName):
63
64
65 with open("./pids.txt", "w") as f:
66 f.write("")
67
68 input_cmd = {}
69 # Load input command for each binary
70
71 with open("SD-VBS/sd-vbsNames.txt") as f:
72 for line in f:
73 name, cmd = line.split(maxsplit=1)
74 input_cmd[name.replace("./", "")] = cmd.replace("./", "./SD-VBS/").strip()
75
76 task_launches = []
77 max_core = 0
78 all_cores = set()
79 # Load task specifications
80 with open(pathName, "r") as file:
81 for line in file:
82 parameters = line.split(",")
83 task_launches.append(parameters)
84 core_num = int(parameters[CORE_NUM]) % 16
85 # if max_core < core_num:
86 # max_core = core_num
87 all_cores.add(core_num)
88 # if parameters[0] == '1':
89 # other_core_num = int(parameters[OTHER_CORE_NUM]) % 16
90 # if other_core_num > max_core:
91 # max_core = other_core_num
92
93 core_count = max_core+1
94 # print(parameters)
95
96 # Turn off power management
97 run('sudo echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor')
98
99 ### Allocate Cache Ways ###
100 run('mount -t resctrl resctrl /sys/fs/resctrl')
101 # run('sudo echo "L3:0=0000;1=0000;2=0000;3=ffff" | sudo tee /sys/fs/resctrl/schemata')
102 run('sudo echo "L3:0=0000;1=0000;2=0000;3=000f" | sudo tee /sys/fs/resctrl/schemata')
103 for core in range(16):
104 if core not in all_cores:
105 continue
106 run("mkdir -p /sys/fs/resctrl/core-{}".format(core))
107 ccx = core // 4
108 in_ccx = core % 4
109 mask = "0000"
110 # mask = "ffff"
111 mask = mask[:in_ccx] +'f'+ mask[in_ccx+1:]
112 run('echo {},{} > /sys/fs/resctrl/core-{}/cpus_list'.format(core,core+16, core))
113 # run('echo {} > /sys/fs/resctrl/core-{}/cpus_list'.format(core, core))
114 if ccx == 0:
115 # run('echo {},{} > /sys/fs/resctrl/core-{}/cpus_list'.format(core, core))
116 run('echo "L3:0=' + mask + ';1=0000;2=0000;3=0000" > /sys/fs/resctrl/core-{}/schemata'.format(core))
117 # run('echo "L3:0=ffff;1=0000;2=0000;3=0000" > /sys/fs/resctrl/core-{}/schemata'.format(core))
118 if ccx == 1:
119 # run('echo {},{} > /sys/fs/resctrl/core-{}/cpus_list'.format(core, core))
120 run('echo "L3:0=0000;1=' + mask + ';2=0000;3=0000" > /sys/fs/resctrl/core-{}/schemata'.format(core))
121 if ccx == 2:
122 # run('echo {},{} > /sys/fs/resctrl/core-{}/cpus_list'.format(core, core))
123 run('echo "L3:0=0000;1=0000;2=' + mask + ';3=0000" > /sys/fs/resctrl/core-{}/schemata'.format(core))
124 if ccx == 3:
125 # run('echo {},{} > /sys/fs/resctrl/core-{}/cpus_list'.format(core, core))
126 run('echo "L3:0=0000;1=0000;2=0000;3=' + mask + '" > /sys/fs/resctrl/core-{}/schemata'.format(core))
127
128 # return 1
129 run("rm -rf /dev/shm/*")
130
131
132 pairID = 0
133 ### Dispatch tasks
134 for launch in task_launches:
135 binary_name = launch[BINARY_NAME].strip()
136 task_name = launch[TASK_NAME].strip()
137 num_iters = launch[NUM_ITERS].strip()
138 core_num =launch[CORE_NUM].strip()
139 run_id = launch[RUN_ID].strip()
140 save_result = launch[SAVE_RESULT].strip()
141 if LITMUS:
142 period = launch[PERIOD].strip()
143 crt_level = launch[CRT_LEVEL].strip()
144 phase = launch[PHASE].strip()
145 cost = launch[COST].strip()
146 deadline = launch[DEADLINE].strip()
147 if(int(cost) > int(deadline)):
148 print("----Error: task {} cost = {} > {} = deadline!----".format(task_name, int(cost), int(deadline)))
149 continue
150
151
152 phys_core = int(core_num) % 16
153 if ID2PID(task_name):
154 print("----ERROR: Task Name {} is already running! Did you end the previous case study?---- ".format(task_name))
155 return 1
156 # single tasks
157 if launch[0] == '0':
158 if LITMUS:
159 binary = binary_path + binary_name + "_single"
160 # Arg format: <unique name> <num_iters> <core> <NULL runID> <save?> <period> <crit lvl> <phase> <cost> <deadline>
161 arg = " " + task_name + " " + num_iters +" " + core_num +" " + run_id +" " + save_result+" " + period +" " + crt_level + " "+ phase + " " + cost + " " + deadline
162 bench_tsk = subprocess.Popen(input_cmd[binary_name] + " | numactl --interleave=all " + binary + arg, shell=True, executable='/bin/bash', stderr=stderr_file)
163
164 else:
165 # Arg format: <unique name> <num_iters> <core> <NULL runID> <save?>
166 binary = binary_path + binary_name + "_single_no_litmus"
167 arg = " " + task_name + " " + num_iters +" " + core_num +" " + run_id +" " + save_result+" "
168 bench_tsk = subprocess.Popen(input_cmd[binary_name] + " | numactl --interleave=all taskset -c " + core_num + " " + binary + arg, shell=True, executable='/bin/bash', stderr=stderr_file)
169
170 print(input_cmd[binary_name] + " | numactl --interleave=all " + binary + arg)
171 # print(binary)
172 # print(arg)
173 pid_str = ID2PID(binary + " " + task_name)
174 if not pid_str:
175 print("Unable to launch {} as a solo task! Exiting...".format(task_name))
176 return 1
177 # run("echo " + pid_str + " > /sys/fs/resctrl/core-" + str(phys_core) + "/tasks")
178 else:
179 # Paried tasks
180 other_binary_name = launch[OTHER_BINARY_NAME].strip()
181 other_task_name = launch[OTHER_TASK_NAME].strip()
182 other_core_num = str(int(core_num)+16)
183 if LITMUS:
184 other_cost = launch[OTHER_COST].strip()
185 other_deadline = launch[OTHER_DEADLINE].strip()
186 if(int(other_cost) > int(other_deadline)):
187 print("----Error: task {} cost = {} > {} = deadline!----".format(other_task_name, int(other_cost), int(other_deadline)))
188 continue
189 #Check if SMT-paired correctly
190 # assert(abs(int(core_num)-int(other_core_num)) == 16)
191 if ID2PID(other_task_name):
192 print("----ERROR: Task Name {} is already running! Did you end the previous case study?----".format(other_task_name))
193 return 1
194 if LITMUS:
195 binary = binary_path + binary_name + "_pair"
196 other_binary = binary_path + other_binary_name + "_pair"
197 # Arg format: <unique name> <num iters> <core> <0 other core> <other name> <runID> <save?> <pairID> <period> <crit lvl> <phase> <other_cost> <other_deadline>
198 arg1 = " " + task_name + " " + num_iters +" " + core_num +" " + other_core_num+" "+ other_task_name+" "+ run_id +" " + save_result+" " +str(pairID) +" "+ period +" " + crt_level +" "+phase + " " + cost + " " + deadline
199 arg2 = " " + other_task_name + " " + num_iters +" " + other_core_num +" " + core_num+" "+ task_name+" "+ run_id +" " + save_result+" " +str(pairID) +" "+ period +" " + crt_level+" " +phase + " " + other_cost + " " + other_deadline
200 # print(input_cmd[binary_name] + " | numactl --membind=0 " + binary + arg1)
201 # print(input_cmd[other_binary_name] + " | numactl --membind=1 " + other_binary + arg2)
202 bench_tsk1 = subprocess.Popen(input_cmd[binary_name] + " | numactl --membind=0 " + binary + arg1, shell=True, executable='/bin/bash', stderr=stderr_file)
203 bench_tsk2 = subprocess.Popen(input_cmd[other_binary_name] + " | numactl --membind=1 " + other_binary + arg2, shell=True, executable='/bin/bash', stderr=stderr_file)
204 else: