Skip to content

Commit

Permalink
Format comments
Browse files Browse the repository at this point in the history
  • Loading branch information
berkayurun authored and aewag committed May 3, 2023
1 parent 0bfbd0d commit 89dd0f9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 65 deletions.
18 changes: 9 additions & 9 deletions calculate_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def find_tb_info_row(tb_id, goldenrun_tb_info):

def allign_fault_to_instruction(address, tbinfo_size, tbinfo_assembler, tbinfo_id):
asm_addresses = []
"Start searching for instruction addresses"
# Start searching for instruction addresses
split = tbinfo_assembler.split("[ ")
for sp in split[1:]:
"Find end of address"
# Find end of address
s = sp.split("]")
"Convert and append to list"
# Convert and append to list
asm_addresses.append(int("0x" + s[0].strip(), 0))
asm_addresses.append(tbinfo_id + tbinfo_size)
for i in range(0, len(asm_addresses) - 1, 1):
Expand Down Expand Up @@ -82,7 +82,7 @@ def find_fault(
matching_tbs_with_positions = goldenrun_tb_exec.query("tb in @matching_tb_ids")
idx = matching_tbs_with_positions.index

"""Identify desired occurrence"""
# Identify desired occurrence
if trigger_occurrences > len(idx):
return [-1, 0]
idx = idx[trigger_occurrences - 1]
Expand Down Expand Up @@ -129,7 +129,7 @@ def search_for_fault_location(
return [fault_address, 0, fault_lifespan]
idtbinfo = find_tb_info_row(goldenrun_tb_exec.at[idx, "tb"], goldenrun_tb_info)
if trigger_not_in_same_tb == 1:
"""Is current tb to short for trigger position"""
# Is current tb to short for trigger position
if trigger_position > goldenrun_tb_info.at[idtbinfo, "ins_count"]:
idx = idx - 1
trigger_position = (
Expand All @@ -146,19 +146,19 @@ def search_for_fault_location(
else:
tb_id = goldenrun_tb_exec.at[idx, "tb"]
for filt in filter_lists:
"""found matching filter"""
# found matching filter
if filt[0] != tb_id:
continue
for i in range(0, len(filt), 1):
if filt[i] != ins:
continue
"""Case ins is in the current tb"""
# Case ins is in the current tb
if i >= trigger_position:
i -= trigger_position
ins = filt[i]
trigger_position = 0
else:
"""Case ins is not in the current tb"""
# Case ins is not in the current tb
trigger_not_in_same_tb = 1
trigger_position -= i
idx -= 1
Expand Down Expand Up @@ -223,7 +223,7 @@ def calculate_trigger_addresses(fault_list, goldenrun_tb_exec, goldenrun_tb_info
}
)

"check every fault list"
# check every fault list
cache_dict = dict()
lists = build_filters(goldenrun_tb_info)
for list in lists:
Expand Down
14 changes: 7 additions & 7 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,38 +383,38 @@ def controller(
del mem_list[0 : len(mem_list) - 6 * num_workers + 4]
mem_max = max(mem_list)

"Calculate length of running processes"
# Calculate length of running processes
times.clear()
time_max = 0
current_time = time.time()
for i in range(len(p_list)):
p = p_list[i]
tmp = current_time - p["start_time"]
"If the current processing time is lower than moving average, do not punish the time "
# If the current processing time is lower than moving average, do not punish the time
if tmp < p_time_mean:
times.append(0)
else:
times.append(tmp - p_time_mean)
"""Find max time in list (This list will show the longest running
process minus the moving average)"""
# Find max time in list (This list will show the longest running
# process minus the moving average)
if len(times) > 0:
time_max = max(times)

for i in range(len(p_list)):
p = p_list[i]
"Find finished processes"
# Find finished processes
p["process"].join(timeout=0)
if p["process"].is_alive() is False:
# Update the progress bar
pbar.update(1)
"Recalculate moving average"
# Recalculate moving average
p_time_list.append(current_time - p["start_time"])
len_p_time_list = len(p_time_list)
if len_p_time_list > num_workers + 2:
p_time_list.pop(0)
p_time_mean = sum(p_time_list) / len_p_time_list
clogger.debug("Current running Average {}".format(p_time_mean))
"Remove process from list"
# Remove process from list
p_list.pop(i)
break

Expand Down
89 changes: 44 additions & 45 deletions faultclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,24 +286,24 @@ def build_filters(tbinfogolden):
Build for each tb in tbinfo a filter
"""
filter_return = []
"""Each assembler string"""
# Each assembler string
for tb in tbinfogolden["assembler"]:
tb_filter = []
"""remove first split, as it is empty"""
# remove first split, as it is empty
split = tb.split("[ ")
"""For each line"""
# For each line
for sp in split[1:]:
"""select address"""
# select address
s = sp.split("]")
"""Add to filter"""
# Add to filter
tb_filter.append(int("0x" + s[0].strip(), 0))
"""Sort addresses"""
# Sort addresses
tb_filter.sort()
"""Reverse list so that last element is first"""
# Reverse list so that last element is first
tb_filter.reverse()
"""Append to filter list"""
# Append to filter list
filter_return.append(tb_filter)
"""Filter list for length of filter, so that the longest one is tested first"""
# Filter list for length of filter, so that the longest one is tested first
filter_return.sort(key=len)
filter_return.reverse()
return filter_return
Expand All @@ -313,34 +313,34 @@ def recursive_filter(tbexecpd, tbinfopd, index, filt):
"""
Search if each element in filt exists in tbexec after index
"""
"""Make sure we do not leave Pandas frame"""
# Make sure we do not leave Pandas frame
if not ((index >= 0) and index < len(tbexecpd)):
return [False, tbexecpd, tbinfopd]
"""Select element to test"""
# Select element to test
tb = tbexecpd.loc[index]
"""Make sure it is part of filter"""
# Make sure it is part of filter
if tb["tb"] == filt[0]:
if len(filt) == 1:
"""Reached start of original tb"""
# Reached start of original tb
return [True, tbexecpd, tbinfopd]
else:
"""pop filter element and increase index in tbexec pandas frame"""
# pop filter element and increase index in tbexec pandas frame
fi = filt.pop(0)
index = index + 1
"""Call recursively"""
# Call recursively
[flag, tbexecpd, tbinfopd] = recursive_filter(
tbexecpd, tbinfopd, index, filt
)
index = index - 1
"""If true, we have a match"""
# If true, we have a match
if flag is True:
"""Invalidate element in tb exec list"""
# Invalidate element in tb exec list
tbexecpd.at[index, "tb"] = -1
tbexecpd.at[index, "tb-1"] = -1
"""Search tb in tb info"""
# Search tb in tb info
idx = tbinfopd.index[tbinfopd["id"] == fi]
for ind in idx:
"""Only invalidate if tb only contains one element, as these are artefacts of singlestep"""
# Only invalidate if tb only contains one element, as these are artefacts of singlestep
if tbinfopd.at[ind, "ins_count"] == 1:
tbinfopd.at[ind, "num_exec"] = tbinfopd.at[ind, "num_exec"] - 1
return [flag, tbexecpd, tbinfopd]
Expand All @@ -351,7 +351,7 @@ def recursive_filter(tbexecpd, tbinfopd, index, filt):
def decrese_tb_info_element(tb_id, number, tbinfopd):
"""Find all matches to the tb id"""
idx = tbinfopd.index[tbinfopd["id"] == tb_id]
"""Decrement all matches by number of occurrence in tb exec"""
# Decrement all matches by number of occurrence in tb exec
for i in idx:
tbinfopd.at[i, "num_exec"] = tbinfopd.at[i, "num_exec"] - number

Expand All @@ -360,22 +360,22 @@ def filter_function(tbexecpd, filt, tbinfopd):
"""Find all possible matches for first element of filter"""
idx = tbexecpd.index[(tbexecpd["tb"] == filt[0])]
for f in filt[1:]:
"""Increment to next possible match position"""
# Increment to next possible match position
idx = idx + 1
"""Find all possible matches for next filter value"""
# Find all possible matches for next filter value
tmp = tbexecpd.index[(tbexecpd["tb"]) == f]
"""Find matching indexes between both indexes"""
# Find matching indexes between both indexes
idx = idx.intersection(tmp)
"""We now will step through the filter backwards"""
# We now will step through the filter backwards
filt.reverse()
for f in filt[1:]:
"""Decrement positions"""
# Decrement positions
idx = idx - 1
for i in idx:
"""Invalidate all positions"""
# Invalidate all positions
tbexecpd.at[i, "tb"] = -1
tbexecpd.at[i, "tb-1"] = -1
"""Decrement artefacts in tb info list"""
# Decrement artefacts in tb info list
decrese_tb_info_element(f, len(idx), tbinfopd)


Expand All @@ -385,39 +385,39 @@ def filter_tb(tbexeclist, tbinfo, tbexecgolden, tbinfogolden, id_num):
"""
filters = build_filters(tbinfogolden)
tbexecpd = tbexeclist
"""Sort and re-index tb exec list"""
# Sort and re-index tb exec list
tbexecpd.sort_values(by=["pos"], ascending=False, inplace=True)
tbexecpd.reset_index(drop=True, inplace=True)
tbexecpd["tb-1"] = tbexecpd["tb"].shift(periods=-1, fill_value=0)
"""Generate pandas frame for tbinfo"""
# Generate pandas frame for tbinfo
tbinfopd = pd.DataFrame(tbinfo)
for filt in filters:
"""Only if filter has more than one element"""
# Only if filter has more than one element
if len(filt) > 1:
"""Perform search and invalidation of found matches"""
# Perform search and invalidation of found matches
filter_function(tbexecpd, filt, tbinfopd)

diff = len(tbexecpd)
""" Search found filter matches """
# Search found filter matches
idx = tbexecpd.index[tbexecpd["tb-1"] == -1]
"""Drop them from table"""
# Drop them from table
tbexecpd.drop(idx, inplace=True)
"""Drop temporary column"""
# Drop temporary column
tbexecpd.drop(columns=["tb-1"], inplace=True)
"""Reverse list, because it is given reversed from qemu"""
# Reverse list, because it is given reversed from qemu
tbexecpd.sort_values(by=["pos"], inplace=True)
""" Fix broken position index"""
# Fix broken position index
tbexecpd.reset_index(drop=True, inplace=True)
tbexecpd["pos"] = tbexecpd.index
"""Again reverse list to go back to original orientation"""
# Again reverse list to go back to original orientation
tbexecpd = tbexecpd.iloc[::-1]
logger.debug(
"worker {} length diff of tbexec {}".format(id_num, diff - len(tbexecpd))
)
diff = len(tbinfopd)
"""Search each tb info, that was completely removed from tbexec list"""
# Search each tb info, that was completely removed from tbexec list
idx = tbinfopd.index[tbinfopd["num_exec"] <= 0]
"""Drop the now not relevant tbinfo elements"""
# Drop the now not relevant tbinfo elements
tbinfopd.drop(idx, inplace=True)
logger.debug(
"worker {} Length diff of tbinfo {}".format(id_num, diff - len(tbinfopd))
Expand Down Expand Up @@ -755,7 +755,7 @@ def python_worker(
output of qemu
"""

"""Setup qemu python part"""
# Setup qemu python part
p_qemu = None
try:
if index >= 0:
Expand Down Expand Up @@ -804,15 +804,14 @@ def python_worker(
)

logger.debug("Started QEMU")
"""Write faults to config pipe"""
# Write faults to config pipe
res = write_fault_list_to_pipe(fault_list, config_fifo)
if res != 0:
logger.error("Fault message could not be written to the config pipe!")
logger.debug("Wrote config to qemu")
"""
From here Qemu has started execution. Now prepare for
data extraction
"""

# From here Qemu has started execution. Now prepare for
# data extraction
mem = readout_data(
data_fifo,
index,
Expand Down
6 changes: 2 additions & 4 deletions goldenrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,8 @@ def checktriggers_in_tb(faultconfig, data):
valid_triggers.append(fault.trigger.address)
continue

"""
If Fault is instruction fault and hitcounter 0 let it pass independent
of the fault trigger address, as it is not used by the faultplugin
"""
# If Fault is instruction fault and hitcounter 0 let it pass independent
# of the fault trigger address, as it is not used by the faultplugin
if fault.trigger.hitcounter == 0 and fault.model == 3:
continue

Expand Down

0 comments on commit 89dd0f9

Please sign in to comment.