-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
80 lines (68 loc) · 1.99 KB
/
main.c
File metadata and controls
80 lines (68 loc) · 1.99 KB
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
/* Assumption:-
If 2 jobs have different absolute deadlines, the one with earliest deadline will be executed first.
If the absolute deadlines of 2 jobs is same the one which is cache hot or alreadly been executed will
be executed first
If both have have same deadline and neither has been executed job with lower task_id is executed.*/
/*To compile use command: gcc main.c edf.c
./a.out */
#include <stdio.h>
#include <stdlib.h>
#include "edf.h"
//Time that will count till hyperperiod
int time = 0;
int main()
{
task *t;
int n=8, hyper_period, task_id=TASK_ID;
double cpu;
t = malloc(n * sizeof(task));
n=get_tasks(t);
cpu= cpu_util(t, n);
printf("CPU Utilization %f\n", cpu);
hyper_period = hyperperiod_calc(t, n);
printf("Hyper Period: %d\n",hyper_period);
if (cpu<= 1.000000)
printf("Tasks can be scheduled as :\n");
else
{
printf("Schedule is not possible for given input\n");
exit(0);
}
//initializing all variables of task
copy_exec(t, n, 1);
update_abs_arr(t, n, 0, 1);
update_abs_dead(t, n, 1);
while (time < hyper_period)
{
if (update_availability(t, time, n))//if at least one task is alive find task with minimum deadline
{
task_id = min_deadline(t, n);
}
if (task_id == TASK_ID)//if task_id is not updated idle state
{
printf("%d - %d Idle\n", time,time+1);
}
if (task_id != TASK_ID)
{
if (t[task_id].T[temp_exec] != 0)
{
t[task_id].T[temp_exec]--;//reduce execution unit by 1
t[task_id].T[last_exec]=time;
printf("%d - %d Task %d Job %d\n", time,time+1, task_id + 1,t[task_id].job+1);
}
if (t[task_id].T[temp_exec] == 0)//execution complete
{
t[task_id].job++;
t[task_id].available = 0;
//reinitialize all variables of task
copy_exec(t, task_id, 0);
update_abs_arr(t, task_id, t[task_id].job, 0);
update_abs_dead(t, task_id, 0);
task_id = min_deadline(t, n);
}
}
++time;
}
free(t);
return 0;
}