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