forked from thaink/SDFscheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Schedule_evaluate.m
119 lines (108 loc) · 4.07 KB
/
Schedule_evaluate.m
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
function [nSchedule, constraint_OK, nProcessors, nBuffers] = Schedule_evaluate(SDFgraph, Schedule, verbose)
if nargin < 3
verbose = 1;
end
%list of time events
events = table;
nProcessors = length(Schedule.taskGroup.scheduleGroups);
for idx = 1:nProcessors
scheduleGroup = Schedule.taskGroup.scheduleGroups(idx);
ntask = length(scheduleGroup.tasks);
for jdx = 1:ntask
task = scheduleGroup.tasks(jdx);
repetition = task.repetition;
rtime = task.startTime;
ractor = task.name;
ractoridx = SDFgraph.map_name2idx(ractor);
rexec = SDFgraph.actors(ractoridx).execTime;
for rdx = 0:repetition-1
%add start time
event.actor = ractor;
event.thread= idx;
event.time = rtime + rdx * rexec;
event.type = "start";
events = [events; struct2table(event)];
event.time = event.time + rexec;
event.type = "finish";
events = [events; struct2table(event)];
end
assert(task.endTime == event.time, 'event time mismatched.');
end
end
events = sortrows(events,'type');
events = sortrows(events,'time');
clear idx jdx rdx ntask event rtime task repetition rtime ractor ractoridx rexec scheduleGroup
%time requirement
t0 = events(1,:).time;
t2 = events(end,:).time;
ntimes = [];
for idx=1:nProcessors
mEvents = events(events.thread == idx, :);
ntime = mEvents(end,:).time - (mEvents(1,:).time - t0);
ntimes = [ntimes; ntime];
end
t1 = max(ntimes);
period_duration = t1 - t0;
constraint_OK = 0;
if(period_duration <= SDFgraph.timeConstraints)
disp_verbose(verbose,['Period ' num2str(period_duration) '. Constraint ' num2str(SDFgraph.timeConstraints) '. Satisfied.']);
constraint_OK = 1;
else
disp_verbose(verbose,['Period ' num2str(period_duration) '. Constraint ' num2str(SDFgraph.timeConstraints) '. Not Satisfied.']);
end
%add events of next period
% events_pure = events;
% for tt = t1:period_duration:t2
% for idx=1:size(events_pure,1)
% event = events_pure(idx,:);
% event.time = event.time + tt;
% if (event.time < t2)
% events = [events; event];
% end
% end
% end
% events = sortrows(events,'type');
% events = sortrows(events,'time');
clear mEvents event ntimes ntime idx tt t0 t1 t2
%number of buffer
matrix_buffers = zeros(size(SDFgraph.channels));
for idx = 1:size(matrix_buffers,1)
for jdx = 1:size(matrix_buffers,2)
if(~isempty(SDFgraph.channels{idx,jdx}))
matrix_buffers(idx, jdx) = SDFgraph.channels{idx,jdx}.initialTokens;
end
end
end %end init
max_buffers = matrix_buffers;
init_buffers= matrix_buffers;
nevents = size(events, 1);
for idx = 1:nevents
event = events(idx,:);
ractor_idx = SDFgraph.map_name2idx(event.actor);
if (event.type == "start")
for jdx = 1:size(SDFgraph.channels,1)
if(~isempty(SDFgraph.channels{jdx, ractor_idx}))
matrix_buffers(jdx, ractor_idx) = matrix_buffers(jdx, ractor_idx) - SDFgraph.channels{jdx, ractor_idx}.rate_out;
assert(matrix_buffers(jdx, ractor_idx) >= 0, 'schedule not satisfied input/output constrain.');
end
end
else
for jdx = 1:size(SDFgraph.channels,2)
if(~isempty(SDFgraph.channels{ractor_idx, jdx}))
matrix_buffers(ractor_idx, jdx) = matrix_buffers(ractor_idx, jdx) + SDFgraph.channels{ractor_idx, jdx}.rate_in;
if (matrix_buffers(ractor_idx, jdx) > max_buffers(ractor_idx, jdx))
max_buffers(ractor_idx, jdx) = matrix_buffers(ractor_idx, jdx);
end
end
end
end
end
nBuffers = sum(max_buffers(:));
diff = matrix_buffers - init_buffers;
assert(sum(diff(:)) == 0, 'buffer after period different from initial buffer');
nSchedule = Schedule;
nSchedule.taskGroup.buffer = nBuffers;
disp_verbose(verbose,['number of processor: ' num2str(nProcessors)]);
disp_verbose(verbose,['number of buffer: ' num2str(nBuffers)]);
clear idx jdx nevents event ractor_idx init_buffers max_buffers diff
end