Rev 1490 | Rev 1493 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1489 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * |
||
11 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
12 | * |
||
13 | * http://www.sssup.it |
||
14 | * http://retis.sssup.it |
||
15 | * http://shark.sssup.it |
||
16 | */ |
||
17 | |||
18 | /* The tracer instrumentation ideas come from the York PWCET analisys tool |
||
19 | * |
||
20 | * Real-Time System Group |
||
21 | * University of York |
||
22 | * |
||
23 | */ |
||
24 | |||
25 | #include <kernel/kern.h> |
||
26 | #include <tracer.h> |
||
27 | |||
1490 | giacomo | 28 | #define IPOINT(a) TRACER_LOGEVENT(FTrace_EVT_ipoint,(a),0); |
29 | |||
1489 | giacomo | 30 | int num_aster = 0; |
31 | #define ASTER_LIM 67 |
||
32 | #define ASTER_MAX 90 |
||
33 | |||
34 | TASK asteroide(void) |
||
35 | { |
||
36 | int i = 1; |
||
37 | int y = 0; |
||
38 | |||
1490 | giacomo | 39 | IPOINT(1000); |
1489 | giacomo | 40 | |
41 | y = rand() % 20 + 1; |
||
42 | |||
43 | while (i < ASTER_LIM) { |
||
44 | |||
1490 | giacomo | 45 | IPOINT(1001); |
1489 | giacomo | 46 | |
47 | puts_xy(i,y,WHITE,"*"); |
||
48 | |||
1490 | giacomo | 49 | IPOINT(1002); |
50 | task_testcancel(); |
||
1489 | giacomo | 51 | task_endcycle(); |
52 | |||
53 | puts_xy(i,y,WHITE," "); |
||
54 | i++; |
||
55 | } |
||
56 | |||
1490 | giacomo | 57 | IPOINT(1003); |
1489 | giacomo | 58 | num_aster--; |
59 | |||
1490 | giacomo | 60 | IPOINT(1004); |
1489 | giacomo | 61 | return 0; |
62 | |||
63 | } |
||
64 | |||
65 | DWORD taskCreated = 0; |
||
66 | |||
67 | TASK aster(void) |
||
68 | { |
||
69 | PID p; |
||
70 | |||
71 | HARD_TASK_MODEL m; |
||
72 | int r; |
||
73 | |||
1490 | giacomo | 74 | IPOINT(2000); |
1489 | giacomo | 75 | |
76 | hard_task_default_model(m); |
||
77 | hard_task_def_wcet(m,500); |
||
1490 | giacomo | 78 | hard_task_def_group(m,3); |
1489 | giacomo | 79 | |
80 | while (1) { |
||
81 | |||
1490 | giacomo | 82 | IPOINT(2001); |
1489 | giacomo | 83 | |
84 | if (num_aster < ASTER_MAX) { |
||
85 | |||
1490 | giacomo | 86 | IPOINT(2002); |
1489 | giacomo | 87 | |
88 | r = (rand() % 50) - 25; |
||
89 | |||
90 | hard_task_def_arg(m,(void *)((rand() % 7)+1)); |
||
91 | hard_task_def_mit(m, (50+r)*1000); |
||
92 | p = task_create("aaa",asteroide,&m,NULL); |
||
93 | taskCreated++; |
||
94 | task_activate(p); |
||
95 | num_aster++; |
||
96 | } |
||
97 | |||
1490 | giacomo | 98 | IPOINT(2003); |
99 | task_testcancel(); |
||
1489 | giacomo | 100 | task_endcycle(); |
101 | |||
102 | } |
||
103 | |||
1490 | giacomo | 104 | IPOINT(2004); |
1489 | giacomo | 105 | |
106 | } |
||
107 | |||
108 | TASK clock() |
||
109 | { |
||
110 | int s = 0, m = 0; |
||
111 | |||
1490 | giacomo | 112 | IPOINT(3000); |
1489 | giacomo | 113 | |
114 | while(1) { |
||
115 | |||
1490 | giacomo | 116 | IPOINT(3001); |
1489 | giacomo | 117 | |
118 | printf_xy(70,1,WHITE,"%2d : %2d",m,s); |
||
1490 | giacomo | 119 | IPOINT(3002); |
1489 | giacomo | 120 | task_endcycle(); |
121 | |||
122 | if (++s > 59) { |
||
123 | |||
1490 | giacomo | 124 | IPOINT(3003); |
1489 | giacomo | 125 | s = 0; |
126 | m++; |
||
127 | |||
128 | } |
||
1490 | giacomo | 129 | IPOINT(3004); |
1489 | giacomo | 130 | |
131 | printf_xy(70,1,WHITE,"%2d : %2d",m,s); |
||
132 | |||
1490 | giacomo | 133 | IPOINT(3005); |
1491 | giacomo | 134 | task_testcancel(); |
1489 | giacomo | 135 | task_endcycle(); |
136 | |||
137 | } |
||
1490 | giacomo | 138 | IPOINT(3006); |
1489 | giacomo | 139 | |
140 | } |
||
141 | |||
142 | void instrumented_routine() { |
||
143 | |||
144 | PID p1,p2; |
||
145 | HARD_TASK_MODEL m; |
||
146 | struct timespec t; |
||
147 | |||
148 | cprintf("Start\n"); |
||
149 | |||
150 | clear(); |
||
151 | |||
152 | hard_task_default_model(m); |
||
153 | hard_task_def_mit(m,10000); |
||
154 | hard_task_def_wcet(m,2000); |
||
1490 | giacomo | 155 | hard_task_def_group(m,2); |
1489 | giacomo | 156 | |
157 | p1 = task_create("Aster",aster,&m,NULL); |
||
158 | if (p1 == -1) { |
||
159 | sys_shutdown_message("Aster.C(main): Could not create task <aster> ..."); |
||
160 | sys_end(); |
||
161 | } |
||
162 | |||
163 | hard_task_def_mit(m,500000); |
||
164 | p2 = task_create("Clock",clock,&m,NULL); |
||
165 | if (p2 == -1) { |
||
166 | sys_shutdown_message("Aster.C(main): Could not create task <Clock> ..."); |
||
167 | sys_end(); |
||
168 | } |
||
169 | |||
1490 | giacomo | 170 | group_activate(2); |
1489 | giacomo | 171 | |
172 | do { |
||
173 | sys_gettime(&t); |
||
174 | } while (t.tv_sec < 10); |
||
175 | |||
176 | cprintf("Done\n"); |
||
177 | |||
178 | } |
||
179 | |||
180 | int main(int argc, char **argv) |
||
181 | { |
||
182 | |||
183 | int a,b,c; |
||
1491 | giacomo | 184 | struct timespec t,start,end,diff; |
1489 | giacomo | 185 | |
186 | srand(sys_gettime(NULL)); |
||
187 | |||
188 | a = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC); |
||
189 | b = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_JTN); |
||
190 | c = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC); |
||
191 | |||
192 | FTrace_chunk_link(a,b); |
||
193 | FTrace_chunk_link(b,c); |
||
194 | |||
1491 | giacomo | 195 | FTrace_actual_chunk_select(a); |
196 | |||
1489 | giacomo | 197 | kern_gettime(&start); |
198 | FTrace_enable(); |
||
199 | |||
200 | TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0); |
||
201 | |||
202 | instrumented_routine(); |
||
203 | |||
204 | TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0); |
||
205 | |||
206 | FTrace_disable(); |
||
207 | kern_gettime(&end); |
||
208 | |||
209 | SUBTIMESPEC(&end,&start,&diff); |
||
210 | |||
211 | printf_xy(1,21,WHITE,"Logged Time %d s %d us",(int)diff.tv_sec,(int)diff.tv_nsec/1000); |
||
212 | |||
1490 | giacomo | 213 | group_kill(2); |
214 | group_kill(3); |
||
215 | |||
1491 | giacomo | 216 | do { |
217 | sys_gettime(&t); |
||
218 | } while (t.tv_sec < 12); |
||
219 | |||
1490 | giacomo | 220 | FTrace_OSD_init_udp(1, "192.168.82.43", "192.168.82.20"); |
221 | |||
222 | FTrace_send_chunk(a, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC); |
||
223 | |||
1489 | giacomo | 224 | return 0; |
225 | |||
226 | } |
||
227 |