Rev 1303 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1254 | giacomo | 1 | #include "func.h" |
1259 | pj | 2 | #include "calibrate.h" |
1298 | giacomo | 3 | #include <tracer.h> |
1254 | giacomo | 4 | |
5 | extern int cal_cycles; |
||
6 | extern struct timespec zero_time; |
||
7 | extern struct loader_task loader_task_list[]; |
||
8 | extern struct loader_contract loader_contract_list[]; |
||
9 | extern int total_loader_task; |
||
10 | extern int total_loader_contract; |
||
11 | |||
1304 | giacomo | 12 | mutex_t mutex_table[MAX_MUTEX]; |
13 | |||
1266 | giacomo | 14 | /* Runtime Calibration */ |
1254 | giacomo | 15 | int calibrate_cycle() |
16 | { |
||
17 | long long i; |
||
18 | struct timespec start,end,diff; |
||
19 | |||
1255 | giacomo | 20 | if (cal_cycles != 0) return 0; |
1254 | giacomo | 21 | |
22 | kern_cli(); |
||
1303 | giacomo | 23 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
24 | "cpuid\n\t" |
||
25 | :::"eax","ebx","ecx","edx"); |
||
1254 | giacomo | 26 | kern_gettime(&start); |
27 | for (i=0;i<CALIBRATION_DELTA;i++) |
||
28 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
29 | "cpuid\n\t" |
||
30 | :::"eax","ebx","ecx","edx"); |
||
1303 | giacomo | 31 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
32 | "cpuid\n\t" |
||
33 | :::"eax","ebx","ecx","edx"); |
||
1254 | giacomo | 34 | kern_gettime(&end); |
35 | kern_sti(); |
||
36 | |||
37 | SUBTIMESPEC(&end,&start,&diff); |
||
38 | cal_cycles = TIMESPEC2USEC(&diff); |
||
39 | cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles); |
||
40 | |||
41 | return 0; |
||
42 | |||
43 | } |
||
44 | |||
45 | int get_server_from_contract(int contract) |
||
46 | { |
||
47 | |||
48 | int i; |
||
49 | |||
50 | for(i=0;i<total_loader_contract;i++) |
||
51 | if (loader_contract_list[i].number == contract) |
||
52 | return loader_contract_list[i].server; |
||
53 | |||
54 | return -1; |
||
55 | |||
56 | } |
||
57 | |||
58 | void *get_task_model(struct loader_task *current) { |
||
59 | if (current->local_scheduler == PAR_POSIX) { |
||
60 | static NRT_TASK_MODEL nrt; |
||
61 | |||
62 | nrt_task_default_model(nrt); |
||
63 | nrt_task_def_save_arrivals(nrt); |
||
64 | nrt_task_def_ctrl_jet(nrt); |
||
65 | nrt_task_def_group(nrt,current->group); |
||
66 | nrt_task_def_usemath(nrt); |
||
67 | |||
68 | return &nrt; |
||
69 | |||
70 | } |
||
71 | |||
72 | if (current->local_scheduler == PAR_EDF) { |
||
73 | static HARD_TASK_MODEL ht; |
||
74 | |||
75 | hard_task_default_model(ht); |
||
76 | hard_task_def_ctrl_jet(ht); |
||
77 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
||
78 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
79 | hard_task_def_group(ht,current->group); |
||
1265 | giacomo | 80 | hard_task_def_aperiodic(ht); |
1254 | giacomo | 81 | hard_task_def_usemath(ht); |
82 | return &ht; |
||
83 | } |
||
84 | |||
85 | |||
86 | if (current->local_scheduler == PAR_RM) { |
||
87 | static HARD_TASK_MODEL ht; |
||
88 | |||
89 | hard_task_default_model(ht); |
||
90 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
||
91 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
92 | hard_task_def_ctrl_jet(ht); |
||
93 | hard_task_def_group(ht,current->group); |
||
94 | hard_task_def_usemath(ht); |
||
95 | return &ht; |
||
96 | } |
||
97 | |||
98 | return NULL; |
||
99 | |||
1298 | giacomo | 100 | } |
1254 | giacomo | 101 | |
1298 | giacomo | 102 | TASK finish_task() { |
103 | |||
1303 | giacomo | 104 | extern __volatile__ unsigned int TracerEventsPresent; |
1298 | giacomo | 105 | unsigned int k; |
106 | |||
107 | SYS_FLAGS f; |
||
1304 | giacomo | 108 | |
109 | sleep(1); |
||
110 | |||
1303 | giacomo | 111 | tracer_init_udp(1,"192.168.1.10","192.168.1.1"); |
1298 | giacomo | 112 | |
113 | tracer_create_udp_task(NULL,80); |
||
114 | |||
115 | f = kern_fsave(); |
||
116 | k = TracerEventsPresent; |
||
117 | kern_frestore(f); |
||
118 | while(k > 0) { |
||
119 | f = kern_fsave(); |
||
1303 | giacomo | 120 | printf_xy(0,5,WHITE,"REM = %08d",k); |
1298 | giacomo | 121 | k = TracerEventsPresent; |
122 | kern_frestore(f); |
||
123 | } |
||
124 | |||
125 | tracer_flush_sent_events(); |
||
126 | |||
127 | sys_end(); |
||
128 | |||
129 | return NULL; |
||
130 | |||
131 | } |
||
132 | |||
133 | void end_simulation() { |
||
134 | |||
135 | int i; |
||
136 | struct loader_task *l = loader_task_list; |
||
1304 | giacomo | 137 | extern __volatile__ unsigned int TracerEventsPresent; |
1298 | giacomo | 138 | |
139 | NRT_TASK_MODEL nrt; |
||
140 | |||
141 | TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0,0); |
||
142 | |||
143 | tracer_disable(); |
||
144 | |||
1304 | giacomo | 145 | cprintf("Total Events Present %d\n",TracerEventsPresent); |
146 | |||
1298 | giacomo | 147 | i = 0; |
148 | while (i < total_loader_task) { |
||
149 | |||
150 | group_kill(l->group); |
||
151 | |||
152 | i++; |
||
153 | l=&loader_task_list[i]; |
||
154 | |||
155 | } |
||
156 | |||
157 | nrt_task_default_model(nrt); |
||
158 | |||
159 | task_activate(task_create("Finish",finish_task,&nrt,NULL)); |
||
160 | |||
161 | } |
||
162 | |||
1254 | giacomo | 163 | void set_simulation_time (struct timespec *total) { |
164 | struct timespec end_time; |
||
165 | |||
166 | ADDTIMESPEC(&zero_time,total,&end_time); |
||
1298 | giacomo | 167 | kern_event_post(&end_time,(void *)((void *)(end_simulation)),NULL); |
1254 | giacomo | 168 | |
1298 | giacomo | 169 | } |
1254 | giacomo | 170 | |
1266 | giacomo | 171 | /* Set the zero_time and post the first activation event */ |
1254 | giacomo | 172 | void start_simulation() { |
173 | |||
174 | int i; |
||
175 | struct loader_task *l = loader_task_list; |
||
176 | struct timespec end_time; |
||
1304 | giacomo | 177 | PI_mutexattr_t a; |
1254 | giacomo | 178 | |
1304 | giacomo | 179 | PI_mutexattr_default(a); |
180 | |||
1254 | giacomo | 181 | i = 0; |
182 | |||
1298 | giacomo | 183 | tracer_initialize(10000000); |
184 | |||
185 | tracer_enable(); |
||
186 | |||
187 | TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0,0); |
||
188 | |||
1254 | giacomo | 189 | kern_gettime(&zero_time); |
190 | |||
191 | while (i < total_loader_task) { |
||
192 | |||
1304 | giacomo | 193 | if (l->muxstatus == 1) { |
194 | mutex_init(&mutex_table[l->resource],&a); |
||
195 | l->muxstatus = 2; |
||
196 | } |
||
197 | |||
1254 | giacomo | 198 | if (l->act_number > 0) { |
199 | ADDTIMESPEC(&zero_time, &l->act[0], &end_time); |
||
200 | l->act_current++; |
||
201 | kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l); |
||
202 | } |
||
203 | |||
204 | i++; |
||
205 | l=&loader_task_list[i]; |
||
206 | |||
207 | } |
||
208 | |||
209 | } |
||
210 | |||
1266 | giacomo | 211 | /* Activate task and post the new activation event */ |
1254 | giacomo | 212 | void loader_task_activate(struct loader_task *l) { |
213 | |||
214 | struct timespec actual_time,end_time; |
||
215 | |||
216 | kern_gettime(&actual_time); |
||
217 | group_activate(l->group); |
||
218 | |||
219 | if (l->act_number > l->act_current) { |
||
220 | |||
221 | ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time); |
||
222 | |||
223 | l->act_current++; |
||
224 | kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l); |
||
225 | |||
226 | } |
||
227 | |||
228 | } |