From 49c1a64e52ef2630e9c8925c6be516278f0de50d Mon Sep 17 00:00:00 2001 From: Mukendi Mputu Date: Mon, 27 Jun 2022 00:22:45 +0200 Subject: [PATCH] started with TDA --- schedTests/LiuAndLaylandBound.py | 6 ++--- schedTests/TimeDemandAnalysis.py | 41 ++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/schedTests/LiuAndLaylandBound.py b/schedTests/LiuAndLaylandBound.py index 6f6cb1a..2b846b5 100644 --- a/schedTests/LiuAndLaylandBound.py +++ b/schedTests/LiuAndLaylandBound.py @@ -19,9 +19,9 @@ def test(tasks): U_lub = n * ((2 ** (1 / n)) - 1) # for fewer tasks than 10, we use the exact computed least upper bound - if n < 10: - return U <= U_lub + # if n < 10: + # return U <= U_lub # from 10 tasks up unlimited, we use the limes of n(2 ** 1/n - 1) - return U <= np.log(2) # round to 0.7 ? + return U <= U_lub # np.log(2) diff --git a/schedTests/TimeDemandAnalysis.py b/schedTests/TimeDemandAnalysis.py index 6ff254b..5833180 100644 --- a/schedTests/TimeDemandAnalysis.py +++ b/schedTests/TimeDemandAnalysis.py @@ -13,15 +13,42 @@ import include.TasksHelper as TH # C_i is accessed as: tasks[i][2] # The number of tasks can be accessed as: tasks.shape[0] -#The Time Demand Analysis Test +# The Time Demand Analysis Test + + def test(tasks): - #Sorting Taskset by Period/Deadline - #This makes implementing TDA a lot easier + # Sorting Taskset by Period/Deadline + # This makes implementing TDA a lot easier shape = tasks.shape sortedtasks = tasks[tasks[:, 0].argsort()] - ##################### - #YOUR CODE GOES HERE# - ##################### + print("\n======= TASK SET =======") + # For each tasks in the ordered set + for i in range(len(sortedtasks)): - return False + print(f'Task #{i} {tasks[i]}:') + + # calculate the time points for the demand function + # t = j * P_k for k = 1, 2,...i and j = 1, 2,...,math.ceil(P_i / P_k) + list_of_t = [TH.P_i(sortedtasks, k) * j for k in range(1, i) + for j in range(1, int(np.ceil(TH.D_i(sortedtasks, i) / TH.P_i(sortedtasks, k))))] + + # print(f'\t list of ts: {list_of_t}') + + # at any time t between 0 and and TH.P_i + for t in np.sort(list_of_t): + # for t in range(TH.C_i(sortedtasks, i), TH.P_i(sortedtasks, i)+1, TH.P_i(sortedtasks, i)): + + print(f'\tTime-Demand for t ({t}): {time_demand_func(sortedtasks, i, t)} ') + + # if the demand for CPU time of task i exceeds the available time t + if time_demand_func(sortedtasks, i, t) > t: + return False # then the task i will not meet its deadline, hence taskset not schedulable + return True + + +def time_demand_func(tasks, i, delta=0): + sum = 0 + for k in range(1, i-1): + sum += math.ceil(delta / TH.P_i(tasks, k)) * TH.C_i(tasks, k) + return TH.C_i(tasks, i) + sum