forked from nils.hoelscher/RTSA-lab02-SchedTest
successully implemented TDA
This commit is contained in:
parent
317b8a1a9c
commit
71de5bf9b5
|
@ -21,43 +21,31 @@ def test(tasks):
|
||||||
# This makes implementing TDA a lot easier
|
# This makes implementing TDA a lot easier
|
||||||
shape = tasks.shape
|
shape = tasks.shape
|
||||||
sortedtasks = tasks[tasks[:, 0].argsort()]
|
sortedtasks = tasks[tasks[:, 0].argsort()]
|
||||||
isSchedulable = True
|
|
||||||
global set_num
|
|
||||||
set_num += 1
|
|
||||||
|
|
||||||
print(f"\n======= TASK SET #{set_num} =======\n")
|
|
||||||
# For each tasks in the ordered set
|
# For each tasks in the ordered set
|
||||||
for i in range(len(sortedtasks)):
|
|
||||||
|
|
||||||
print(f'Task #{i} {tasks[i]}:')
|
# calculate the time points for the demand function
|
||||||
|
t_old = 10**-3
|
||||||
|
i = 0
|
||||||
|
|
||||||
# calculate the time points for the demand function
|
while True:
|
||||||
# t = j * P_k for k = 1, 2,...i and j = 1, 2,...,math.ceil(P_i / P_k)
|
t_new = workload_func(sortedtasks, i, t_old)
|
||||||
# list_of_t = [
|
# if the workload of task i exceeds the deadline
|
||||||
# j * TH.P_i(sortedtasks, k)
|
if t_new > TH.D_i(sortedtasks, i):
|
||||||
# for k in range(i-1)
|
return False # task not schedulable
|
||||||
# for j in range(1, int(math.ceil(TH.D_i(sortedtasks, i) / TH.P_i(sortedtasks, k))))
|
|
||||||
# ]
|
|
||||||
# list_of_t = [TH.P_i(sortedtasks, k-1) for k in range(i+1)]
|
|
||||||
list_of_t = []
|
|
||||||
for k in range(i):
|
|
||||||
list_of_t.append(TH.P_i(sortedtasks, k-1))
|
|
||||||
|
|
||||||
print(f'\t list of t: {list_of_t}')
|
if t_new == t_old:
|
||||||
|
i += 1
|
||||||
# at any time t between 0 and and TH.P_i
|
t_old = 10**-3
|
||||||
for j in range(len(list_of_t)):
|
# chech array out of bounds
|
||||||
# for t in range(int(TH.C_i(sortedtasks, i)), int(TH.P_i(sortedtasks, i)+1), int(step)):
|
if i == len(sortedtasks):
|
||||||
|
return True
|
||||||
# if the demand for CPU time of task i exceeds the available time t
|
t_old = t_new
|
||||||
if time_demand_func(sortedtasks, i, list_of_t[j]) > list_of_t[j]:
|
|
||||||
isSchedulable = False # then the task i will not meet its deadline, hence taskset not schedulable
|
|
||||||
print(f'\t time-demand for t := {list_of_t[j]} ---> {time_demand_func(sortedtasks, i, list_of_t[j])} is schedulable: {isSchedulable}')
|
|
||||||
return isSchedulable
|
|
||||||
|
|
||||||
|
|
||||||
def time_demand_func(tasks, i, t):
|
|
||||||
|
def workload_func(tasks, i, t):
|
||||||
sum = 0
|
sum = 0
|
||||||
for k in range(i-1):
|
for k in range(i):
|
||||||
sum += math.ceil(t / TH.P_i(tasks, k)) * TH.C_i(tasks, k)
|
sum += math.ceil(t / TH.P_i(tasks, k)) * TH.C_i(tasks, k)
|
||||||
return TH.C_i(tasks, i) + sum
|
return TH.C_i(tasks, i) + sum
|
||||||
|
|
Reference in New Issue