-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication-ok.cpp
More file actions
123 lines (90 loc) · 2.57 KB
/
application-ok.cpp
File metadata and controls
123 lines (90 loc) · 2.57 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
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
113
114
115
116
117
118
119
120
121
122
123
/*Claudio Praticò 340404, Giuseppe Gabriele Tarollo 343707*/
#include "executive.h"
#include "busy_wait.h"
#define BUSY_WAIT_GENERATION
#define N_MS 8 //In funzione della CPU utilizzata potrebbero verificarsi Deadline Miss, è possibile abbassare la busy waiting qui
Executive exec(5, 4);
std::random_device rd; // inizializzazione
std::mt19937 gen(rd()); // generatore
std::uniform_int_distribution<> dis(0, 4); // random
unsigned int rand_gen = (int) dis(gen);
unsigned int count = 0;
void task0()
{
std::cout << "- Task 0 start execution" << std::endl;
#ifdef BUSY_WAIT_GENERATION
busy_wait(1*N_MS);
#endif
std::cout << "- Task 0 stop execution" << std::endl;
}
void task1()
{
std::cout << "- Task 1 start execution" << std::endl;
#ifdef BUSY_WAIT_GENERATION
busy_wait(2*N_MS);
#endif
std::cout << "- Task 1 stop execution" << std::endl;
}
void task2()
{
std::cout << "- Task 2 start execution" << std::endl;
#ifdef BUSY_WAIT_GENERATION
busy_wait(1*N_MS);
#endif
std::cout << "- Task 2 stop execution" << std::endl;
}
void task3()
{
std::cout << "- Task 3 start execution" << std::endl;
#ifdef BUSY_WAIT_GENERATION
busy_wait(1*N_MS);
#endif
if(++count == rand_gen) { // ap_ task lanciato in modo sporadico;
std::cout << " Launching aperiodic request..." << std::endl;
exec.ap_task_request();
rand_gen = dis(gen); // random cambia ad ogni esecuzione di ap_task;
count = 0;
}
std::cout << "- Task 3 stop execution" << std::endl;
}
void task4()
{
std::cout << "- Task 4 start execution" << std::endl;
#ifdef BUSY_WAIT_GENERATION
busy_wait(1*N_MS);
#endif
std::cout << "- Task 4 stop execution" << std::endl;
}
/* Nota: nel codice di uno o piu' task periodici e' lecito chiamare Executive::ap_task_request() */
void ap_task()
{
std::cout << "- Task Aperiodico start execution" << std::endl;
#ifdef BUSY_WAIT_GENERATION
busy_wait(2*N_MS);
#endif
std::cout << "- Task Aperiodico stop execution" << std::endl;
}
int main()
{
if (getuid()){
std::cout<<"Need to start with sudo!"<<std::endl;
exit(-1);
}
busy_wait_init();
// wcet= tempo massimo di esecuzione previsto
exec.set_periodic_task(0, task0, 1); // tau_1
exec.set_periodic_task(1, task1, 2); // tau_2
exec.set_periodic_task(2, task2, 1); // tau_3,1
exec.set_periodic_task(3, task3, 3); // tau_3,2
exec.set_periodic_task(4, task4, 1); // tau_3,3
/* ... */
exec.set_aperiodic_task(ap_task, 2);
exec.add_frame({0,1,2});
exec.add_frame({0,3});
exec.add_frame({0,1});
exec.add_frame({0,1});
exec.add_frame({0,1,4});
/* ... */
exec.run();
return 0;
}