Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1549 | pj | 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 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /* |
||
20 | * Copyright (C) 2000 Paolo Gai |
||
21 | * |
||
22 | * This program is free software; you can redistribute it and/or modify |
||
23 | * it under the terms of the GNU General Public License as published by |
||
24 | * the Free Software Foundation; either version 2 of the License, or |
||
25 | * (at your option) any later version. |
||
26 | * |
||
27 | * This program is distributed in the hope that it will be useful, |
||
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
30 | * GNU General Public License for more details. |
||
31 | * |
||
32 | * You should have received a copy of the GNU General Public License |
||
33 | * along with this program; if not, write to the Free Software |
||
34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
35 | * |
||
36 | * |
||
37 | * CVS : $Id: shutdown.c,v 1.1 2005-01-08 14:38:27 pj Exp $ |
||
38 | |||
39 | Shutdown demo, used to test system shutdown. |
||
40 | |||
41 | - derived from demo aster4 |
||
42 | |||
43 | - the aper_asteroid task simulates some system tasks that have to |
||
44 | finish prior system shutdown. |
||
45 | |||
46 | - note that if you remove the nanosleep in aper_asteroid |
||
47 | the system does not shut down correctly because the system |
||
48 | tasks does not receive any CPU time!!! |
||
49 | */ |
||
50 | |||
51 | /* |
||
52 | * Copyright (C) 2000 Paolo Gai |
||
53 | * |
||
54 | * This program is free software; you can redistribute it and/or modify |
||
55 | * it under the terms of the GNU General Public License as published by |
||
56 | * the Free Software Foundation; either version 2 of the License, or |
||
57 | * (at your option) any later version. |
||
58 | * |
||
59 | * This program is distributed in the hope that it will be useful, |
||
60 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
61 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
62 | * GNU General Public License for more details. |
||
63 | * |
||
64 | * You should have received a copy of the GNU General Public License |
||
65 | * along with this program; if not, write to the Free Software |
||
66 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
67 | * |
||
68 | */ |
||
69 | |||
70 | #include "kernel/kern.h" |
||
71 | #include "modules/edf.h" |
||
72 | #include "modules/cbs.h" |
||
73 | |||
74 | #include <time.h> |
||
75 | |||
76 | #include <drivers/shark_linuxc26.h> |
||
77 | #include <drivers/shark_input26.h> |
||
78 | #include <drivers/shark_keyb26.h> |
||
79 | |||
80 | int num_aster = 0; |
||
81 | #define ASTER_LIM 60 |
||
82 | #define DISPLAY_MAX 10 |
||
83 | #define ASTER_MAX 70 |
||
84 | #define STAT_Y 24 |
||
85 | |||
86 | #define PER_MAX 5 |
||
87 | #define APER_MAX 8 |
||
88 | |||
89 | // These numbers works on a Pentium 133 */ |
||
90 | #define PER_WCET 25000 |
||
91 | #define APER_WCET 53000 |
||
92 | #define CLOCK_WCET 1000 |
||
93 | #define ASTER_WCET 1000 |
||
94 | #define SOFT_MET 6300 |
||
95 | |||
96 | #define APER_REP 22000 |
||
97 | |||
98 | PID aper_table[APER_MAX]; |
||
99 | |||
100 | int shutting_down = 0; |
||
101 | int nobandwidth; |
||
102 | |||
103 | TASK asteroide(void *arg) |
||
104 | { |
||
105 | int i; |
||
106 | |||
107 | for (;;) { |
||
108 | i = 1; |
||
109 | for (i=1; i < ASTER_LIM; i++) { |
||
110 | puts_xy(i,20,WHITE,"*"); |
||
111 | task_endcycle(); |
||
112 | puts_xy(i,20,WHITE," "); |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | |||
117 | |||
118 | TASK system_asteroide(void *arg) |
||
119 | { |
||
120 | int i; |
||
121 | struct timespec t; |
||
122 | t.tv_sec = 0; |
||
123 | |||
124 | for (;;) { |
||
125 | i = 1; |
||
126 | for (i=1; i < ASTER_LIM; i++) { |
||
127 | puts_xy(i,21,WHITE,"s"); |
||
128 | |||
129 | if (shutting_down) { |
||
130 | cprintf("Ending System Task %d\n",(int)arg); |
||
131 | return 0; |
||
132 | } |
||
133 | |||
134 | t.tv_nsec = 1000000*(100+rand()%200); |
||
135 | nanosleep(&t,NULL); |
||
136 | |||
137 | puts_xy(i,21,WHITE," "); |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | |||
143 | TASK aster() |
||
144 | { |
||
145 | PID p; |
||
146 | |||
147 | SOFT_TASK_MODEL m_soft; |
||
148 | int r; |
||
149 | int x; // adaptive bandwidth... |
||
150 | |||
151 | |||
152 | soft_task_default_model(m_soft); |
||
153 | soft_task_def_met(m_soft,SOFT_MET); |
||
154 | soft_task_def_ctrl_jet(m_soft); |
||
155 | |||
156 | x = 64; |
||
157 | |||
158 | while (1) { |
||
159 | if (num_aster < ASTER_MAX) { |
||
160 | r = (rand() % 200); |
||
161 | |||
162 | soft_task_def_period(m_soft, (x+r)*1000); |
||
163 | p = task_create("aaa",asteroide,&m_soft,NULL); |
||
164 | if (p == -1) |
||
165 | { |
||
166 | if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
||
167 | } |
||
168 | else { |
||
169 | num_aster++; |
||
170 | task_activate(p); |
||
171 | x /= 2; |
||
172 | if (x<50) x = 50; |
||
173 | } |
||
174 | } |
||
175 | task_endcycle(); |
||
176 | } |
||
177 | } |
||
178 | |||
179 | |||
180 | /* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
||
181 | and plot on the screen the elapsed times... */ |
||
182 | TASK jetcontrol() |
||
183 | { |
||
184 | int i; /* a counter */ |
||
185 | TIME curr; |
||
186 | PID p; |
||
187 | struct timespec t; |
||
188 | t.tv_sec=0; |
||
189 | t.tv_nsec=100000; |
||
190 | |||
191 | |||
192 | kern_cli(); |
||
193 | printf_xy(0,STAT_Y,WHITE,"PID ³ Curr. ³ status ³ name"); |
||
194 | kern_sti(); |
||
195 | |||
196 | for (;;) { |
||
197 | for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
||
198 | if (proc_table[p].status==FREE) continue; |
||
199 | |||
200 | curr = 0; |
||
201 | jet_getstat(p, NULL, NULL, NULL, &curr); |
||
202 | |||
203 | kern_cli(); |
||
204 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-7d ³ %-6d ³ %s ", |
||
205 | p, (int)curr, proc_table[p].status, proc_table[p].name); |
||
206 | kern_sti(); |
||
207 | i++; |
||
208 | } |
||
209 | |||
210 | for (; i<DISPLAY_MAX+5;i++) { |
||
211 | printf_xy(0,STAT_Y+i+1,WHITE," ³ ³ ³ "); |
||
212 | } |
||
213 | |||
214 | if (!nobandwidth) nanosleep(&t, NULL); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | void endfun(KEY_EVT *k) |
||
219 | { |
||
220 | exit(0); |
||
221 | } |
||
222 | |||
223 | void exiting(void *arg) |
||
224 | { |
||
225 | cprintf("System shut down...\n"); |
||
226 | shutting_down = 1; |
||
227 | } |
||
228 | |||
229 | int main(int argc, char **argv) |
||
230 | { |
||
231 | KEY_EVT k; |
||
232 | |||
233 | PID p1,p3; |
||
234 | HARD_TASK_MODEL m; |
||
235 | SOFT_TASK_MODEL m_soft; |
||
236 | NRT_TASK_MODEL m_nrt; |
||
237 | int i; |
||
238 | |||
239 | srand(7); |
||
240 | |||
241 | clear(); |
||
242 | cprintf("REMEMBER: RUN THIS DEMO IN 80x50 TEXT MODE!!!\n"); |
||
243 | cprintf("use \"mode con lines=50\" to put the screen in 80x50.\n\n"); |
||
244 | cprintf("Press SPACE for a typical WRONG shutdown sequence\n"); |
||
245 | cprintf(" where the shutdown task does not receive bandwidth\n\n"); |
||
246 | cprintf("Press another key for a clear shutdown\n"); |
||
247 | nobandwidth = !(keyb_getch(BLOCK) - ' '); |
||
248 | |||
249 | |||
250 | k.flag = 0; |
||
251 | k.scan = KEY_ENT; |
||
252 | k.ascii = 13; |
||
253 | k.status = KEY_PRESSED; |
||
254 | keyb_hook(k, endfun, FALSE); |
||
255 | |||
256 | |||
257 | |||
258 | clear(); |
||
259 | if (nobandwidth) |
||
260 | cprintf("ENTER to end the demo WITH A TIMEOUT...\n"); |
||
261 | else |
||
262 | cprintf("ENTER to end the demo SHUTTING DOWN THE SYSTEM TASKS...\n"); |
||
263 | |||
264 | |||
265 | sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN); |
||
266 | |||
267 | |||
268 | hard_task_default_model(m); |
||
269 | hard_task_def_wcet(m,ASTER_WCET); |
||
270 | hard_task_def_mit(m,10000); |
||
271 | hard_task_def_group(m,1); |
||
272 | hard_task_def_ctrl_jet(m); |
||
273 | p1 = task_create("Aster",aster,&m,NULL); |
||
274 | if (p1 == -1) { |
||
275 | sys_shutdown_message("(main): Could not create task <aster> ..."); |
||
276 | exit(0); |
||
277 | } |
||
278 | |||
279 | |||
280 | soft_task_default_model(m_soft); |
||
281 | soft_task_def_met(m_soft,1000); |
||
282 | soft_task_def_period(m_soft,100000); |
||
283 | soft_task_def_group(m_soft,1); |
||
284 | soft_task_def_aperiodic(m_soft); |
||
285 | soft_task_def_system(m_soft); |
||
286 | soft_task_def_ctrl_jet(m_soft); |
||
287 | soft_task_def_nokill(m_soft); |
||
288 | p3 = task_create("JetControl",jetcontrol,&m_soft,NULL); |
||
289 | if (p3 == -1) { |
||
290 | sys_shutdown_message("(main): Could not create task <JetControl> ..."); |
||
291 | exit(0); |
||
292 | } |
||
293 | |||
294 | |||
295 | /* These are the tasks that simulate the system tasks */ |
||
296 | |||
297 | nrt_task_default_model(m_nrt); |
||
298 | nrt_task_def_ctrl_jet(m_nrt); |
||
299 | nrt_task_def_system(m_nrt); |
||
300 | nrt_task_def_group(m_nrt,1); |
||
301 | |||
302 | cprintf("creating system tasks: "); |
||
303 | for (i=0; i<APER_MAX; i++) { |
||
304 | char systemtaskname[]="mysystemtask0"; |
||
305 | nrt_task_def_arg(m_nrt,(void *)i); |
||
306 | systemtaskname[12]='0'+i; |
||
307 | aper_table[i] = task_create(systemtaskname,system_asteroide,&m_nrt,NULL); |
||
308 | if (aper_table[i] == -1) { |
||
309 | sys_shutdown_message("(main): Could not create task <mysystemtask> ..."); exit(0); |
||
310 | } |
||
311 | else |
||
312 | cprintf(" %d",i); |
||
313 | } |
||
314 | cprintf("\n"); |
||
315 | |||
316 | |||
317 | |||
318 | group_activate(1); |
||
319 | return 0; |
||
320 | } |
||
321 |