2022-06-01 16:11:48 +02:00
|
|
|
import numpy as np
|
|
|
|
import math
|
|
|
|
import include.TasksHelper as TH
|
|
|
|
|
|
|
|
# The tasks is an Array with three columns and n Rows
|
|
|
|
# Each Row represents one Task
|
|
|
|
# The columns hold the Tasks parameters
|
|
|
|
# column 0 is period P,
|
|
|
|
# column 1 is deadline D
|
|
|
|
# column 2 is WCET C
|
|
|
|
# P_i is accessed as: tasks[i][0]
|
|
|
|
# D_i is accessed as: tasks[i][1]
|
|
|
|
# C_i is accessed as: tasks[i][2]
|
|
|
|
# The number of tasks can be accessed as: tasks.shape[0]
|
|
|
|
|
2022-06-27 00:22:45 +02:00
|
|
|
# The Time Demand Analysis Test
|
2022-06-30 14:06:36 +02:00
|
|
|
set_num = 0
|
2022-06-27 00:22:45 +02:00
|
|
|
|
2022-06-01 16:11:48 +02:00
|
|
|
def test(tasks):
|
2022-06-27 00:22:45 +02:00
|
|
|
# Sorting Taskset by Period/Deadline
|
|
|
|
# This makes implementing TDA a lot easier
|
2022-06-01 16:11:48 +02:00
|
|
|
shape = tasks.shape
|
|
|
|
sortedtasks = tasks[tasks[:, 0].argsort()]
|
2022-06-30 15:39:13 +02:00
|
|
|
|
2022-06-27 00:22:45 +02:00
|
|
|
# For each tasks in the ordered set
|
2022-06-30 14:06:36 +02:00
|
|
|
|
2022-06-30 15:39:13 +02:00
|
|
|
# calculate the time points for the demand function
|
|
|
|
t_old = 10**-3
|
|
|
|
i = 0
|
2022-06-27 00:22:45 +02:00
|
|
|
|
2022-06-30 15:39:13 +02:00
|
|
|
while True:
|
|
|
|
t_new = workload_func(sortedtasks, i, t_old)
|
|
|
|
# if the workload of task i exceeds the deadline
|
|
|
|
if t_new > TH.D_i(sortedtasks, i):
|
|
|
|
return False # task not schedulable
|
2022-06-27 00:22:45 +02:00
|
|
|
|
2022-06-30 15:39:13 +02:00
|
|
|
if t_new == t_old:
|
|
|
|
i += 1
|
|
|
|
t_old = 10**-3
|
|
|
|
# chech array out of bounds
|
|
|
|
if i == len(sortedtasks):
|
|
|
|
return True
|
|
|
|
t_old = t_new
|
|
|
|
|
2022-06-27 00:22:45 +02:00
|
|
|
|
2022-06-01 16:11:48 +02:00
|
|
|
|
2022-06-30 15:39:13 +02:00
|
|
|
def workload_func(tasks, i, t):
|
2022-06-27 00:22:45 +02:00
|
|
|
sum = 0
|
2022-06-30 15:39:13 +02:00
|
|
|
for k in range(i):
|
2022-06-30 14:06:36 +02:00
|
|
|
sum += math.ceil(t / TH.P_i(tasks, k)) * TH.C_i(tasks, k)
|
2022-06-27 00:22:45 +02:00
|
|
|
return TH.C_i(tasks, i) + sum
|