summaryrefslogtreecommitdiffstats
path: root/run_case_study.py
blob: bcbaca6fe616c12d8061a600cc8ce44cf0ebafd1 (plain) (blame)
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
import os
import sys
import re
import csv
import time
import subprocess

all_pids=[]
def run(command):
    print(command)
    os.system(command)
def addpid(pid):
    with open("./pids.txt", "a") as f:
        f.write(str(pid) + "\n")


def main():
    with open("./pids.txt", "w") as f:
        f.write("")

    pathName = sys.argv[1]
    tacle_pairs_path = "./all_pairs"
    tacle_baseline_path = "./baseline"
    dis_path = "./dis"
    all_tasks = []
    levelAB = []
    levelC = []
    levelC_s = []
    dis_inputs = dict()
    dis_inputs["field"] = "./gen_input.py field inputs/Field/in0 2097152"
    dis_inputs["matrix"] = "gen_input.py matrix inputs/Matrix/in0 2097152"
    dis_inputs["neighborhood"] = "./gen_input.py neighborhood inputs/Neighborhood/in0 2097152"
    dis_inputs["pointer"] = "./gen_input.py pointer inputs/Pointer/in0 2097152"
    dis_inputs["transitive"] = "./gen_input.py transitive inputs/Transitive/in0 2097152"
    dis_inputs["update"] = "./gen_input.py update inputs/Update/in0 2097152"

    with open(pathName+"/all_tasks.csv", "r") as csv_file:
        csv_reader = csv.reader(csv_file, delimiter = ',')
        line = 0
        for row in csv_reader:
            if line > 0:
                all_tasks.append(row)
            line += 1 
    with open(pathName+"/levelAB_pairs.csv", "r") as csv_file:
        csv_reader = csv.reader(csv_file, delimiter = ',')
        line = 0
        for row in csv_reader:
            if line > 0:
                levelAB.append(row)
            line += 1
    with open(pathName+"/levelC_threads.csv", "r") as csv_file:
        csv_reader = csv.reader(csv_file, delimiter = ',')
        line = 0
        ccx = "0"
        threaded = True
        for row in csv_reader:
            if(len(row) < 3):
                continue
            if(row[0] == "threaded" or row[0] == "solo"):
                threaded = row[0] == "threaded"
                if(row[1] == "4"):
                    ccx = "1"
                else:
                    ccx = "0"
                continue
            if(row[0] != "task id" and row[0] != ""):
                row.append(ccx)
                if(threaded):
                    row.append("t")
                else:
                    row.append("s")
                levelC.append(row)
            line += 1
    run('mount -t resctrl resctrl /sys/fs/resctrl')
    run('sudo echo "L3:0=0000,1=0000,2=0000,3=0000" > sudo /sys/fs/resctrl/schemata')

    with open(pathName+"/l3alloc.csv", "r") as csv_file:
        csv_reader = csv.reader(csv_file, delimiter = ',')
        line = 0
        ccx = 0
        for row in csv_reader:
            if line > 0:
                core = int(row[0])
                way_AB = int(row[1])
                way_C = int(row[3])
                # Level C allocation
                if(core == 1):
                    run("mkdir -p /sys/fs/resctrl/level-c-ccx-0")
                    run('sudo echo "L3:0=' + ("%0.4x" % (int("1"*way_C, 2))) + ',1=0000,2=0000,3=0000" > sudo /sys/fs/resctrl/level-c-ccx-0/schemata')

                if(core == 4):
                    run("mkdir -p /sys/fs/resctrl/level-c-ccx-1")
                    run('sudo echo "L3:0=0000, 1=' + ("%0.4x" % (int("1"*way_C, 2))) + ',2=0000,3=0000" > sudo /sys/fs/resctrl/level-c-ccx-1/schemata')
                run('mkdir -p /sys/fs/resctrl/level-ab-core-' + str(core))
                if(core < 4):
                    run('sudo echo "L3:0=' + ("%0.4x" % (int("1"*way_AB + "0"*(16-way_AB), 2))) + ',1=0000,2=0000,3=0000" > sudo /sys/fs/resctrl/level-ab-core-' + str(core) + '/schemata')
                else:
                    run('sudo echo "L3:0=0000,1=' + ("%0.4x" % (int("1"*way_AB + "0"*(16-way_AB), 2))) + ',2=0000,3=0000" > sudo /sys/fs/resctrl/level-ab-core-' + str(core) + '/schemata')
            line += 1
    run("sudo rm -rf /dev/shm/*")
    pairID = 0
    i = 0
    for task in levelAB:
        task1 = int(task[2])
        task2 = int(task[5])
        name1 = all_tasks[task1][2]
        name2 = all_tasks[task2][2]
        if(name1 == "rijndael_e"):
            name1 = "rijndael_enc"

        if(name2 == "rijndael_e"):
            name2 = "rijndael_enc"
        period1 = all_tasks[task1][5]
        period2 = all_tasks[task2][5]
        suite1 = all_tasks[task1][1]
        suite2 = all_tasks[task2][1]
        core = task[0]
        criticality = task[1]
        binary = ""
        binary1 = ""
        binary2 = ""
        arg = ""
        if(task1 == task2):
            arg = " NULL -1 " + core + " NULL 0 " + period1 + " " + criticality

            if(suite1 == "TACLe"):
                binary = "./baseline/bin/" + name1 +  arg
            else:
                binary = dis_inputs[name1] + " | ./dis/" + name1 + arg
            proc = subprocess.Popen([binary], shell = True)
            #print(binary + " &" )
            pid = proc.pid
            run("sudo echo " + str(pid) + " > sudo /sys/fs/resctrl/level-ab-core-" + core + "/tasks")
            addpid(pid)
        else:
            pairID += 1
            arg1 =  " NULL -1 " + core + " 0 NULL NULL 0 " + str(pairID) + " " + period1 + " " + criticality
            arg2 =  " NULL -1 " + str(int(core)+16) + " 0 NULL NULL 0 " + str(pairID) + " " + period2 + " " + criticality

            if(suite1 == "TACLe"):
                binary1 = "./all_pairs/bin/" + name1 +  arg1
                binary2 = "./all_pairs/bin/" + name2 + arg2
            else:
                binary1 =  dis_inputs[name1] + " | ./dis/" + name1 + "_all" + arg1
                binary2 =  dis_inputs[name2] + " | ./dis/" + name2 + "_all" + arg2
            proc1 = subprocess.Popen(["sudo numactl --membind=0 " + binary1], shell = True)
            proc2 = subprocess.Popen(["sudo numactl --membind=1 " + binary2], shell = True)
            #print("sudo numactl --membind=0 " + binary1 + " &")
            #print("sudo numactl --membind=1 " + binary2 + " &")
            pid1 = proc2.pid + 1
            pid2 = proc2.pid + 3

            run("sudo echo " + str(pid1) + " > sudo /sys/fs/resctrl/level-ab-core-" + core + "/tasks")
            run("sudo echo " + str(pid2) + " > sudo /sys/fs/resctrl/level-ab-core-" + core + "/tasks")
            addpid(pid1)
            addpid(pid2)

    for task in levelC:
        continue
        i+=1
        if(i>8):
            break
        tid = int(task[0])
        name = all_tasks[tid][2]
        period = all_tasks[tid][5]
        suite = all_tasks[tid][1]
        ccx = task[3]
        threaded = task[4] == "t"
        arg = ""

        if(name == "rijndael_e"):
            name = "rijndael_enc"
        if(not threaded):
            arg = " NULL -1 " + ccx + " NULL 0 " + period + " 2"
        else:
            pairID += 1
            arg =  " NULL -1 " + ccx + " 0 NULL NULL 0 " + str(pairID) + " " + period + " 2"
        if(suite1 == "TACLe"):
            binary = "./baseline/bin/" + name1 + arg
        else:
            binary = dis_inputs[name1] + " | ./dis/" + name1 + "_all" + arg

        print(binary + " &")
        proc = subprocess.Popen([binary + " &"], shell = True)
        pid = proc.pid
        run("sudo echo " + str(pid) + " > sudo /sys/fs/resctrl/level-ab-ccx-" + ccx + "/tasks")
    #os.system("/playpen/mc2/liblitmus/release_ts")
    #os.system("ls")
    time.sleep(3)

if __name__ == "__main__":
    main()