Subversion Repositories shark

Rev

Rev 1123 | Rev 1393 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1120 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 Giorgio Buttazzo, Paolo Gai, Massimiliano Giorgi
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
 *
1377 giacomo 37
 * CVS :        $Id: aster7.c,v 1.3 2004-04-17 11:36:12 giacomo Exp $
1120 pj 38
 
39
 this is a part of the classic Hartik demo Aster.
40
 
41
 it is based on test 10(A), and test the PS with RM.
42
 
43
 The JetControl is served by a dedicated Polling Server, too.
44
 
45
 There are APER_MAX tasks sleeping, and when an asteroide task finish
46
 the current activation, it activate also an aperiodic task chosen
47
 randomly (if the task chosen is already active, the task_activate do
48
 nothing!)
49
 
50
*/
51
 
52
#include "kernel/kern.h"
1377 giacomo 53
#include "modules/edf.h"
1120 pj 54
 
1377 giacomo 55
#include <drivers/shark_linuxc26.h>
56
#include <drivers/shark_input26.h>
57
#include <drivers/shark_keyb26.h>
58
 
1120 pj 59
int num_aster = 0;
60
#define ASTER_LIM       60
61
#define DISPLAY_MAX     15
62
#define ASTER_MAX       70
63
#define STAT_Y           9
64
 
65
#define APER_MAX         8
66
 
67
/* Pentium 133 / Celeron 366 */
68
#define PER_WCET     25000 /* 7800 */
69
#define APER_WCET     5500 /* 1400 */
70
#define CLOCK_WCET     500 /* 200 */
71
#define ASTER_WCET     500 /* 200 */
72
 
73
#define APER_REP     2200
74
 
75
PID aper_table[APER_MAX];
76
 
1377 giacomo 77
PID shutdown_task_PID = -1;
78
 
79
int device_drivers_init() {
80
 
81
        KEYB_PARMS kparms = BASE_KEYB;
82
 
83
        LINUXC26_register_module();
84
 
85
        keyb_def_ctrlC(kparms, NULL);
86
 
87
        INPUT26_init();
88
 
89
        KEYB26_init(&kparms);
90
 
91
        return 0;
92
 
93
}
94
 
95
int device_drivers_close() {
96
 
97
        KEYB26_close();
98
 
99
        INPUT26_close();
100
 
101
        return 0;
102
 
103
}
104
 
105
TASK shutdown_task_body(void *arg) {
106
 
107
        device_drivers_close();
108
 
109
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
110
 
111
        sys_end();
112
 
113
        return NULL;
114
 
115
}
116
 
117
void set_shutdown_task() {
118
 
119
        NRT_TASK_MODEL nrt;
120
 
121
        nrt_task_default_model(nrt);
122
 
123
        shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
124
        if (shutdown_task_PID == NIL) {
125
                sys_shutdown_message("Error: Cannot create shutdown task\n");
126
                sys_end();
127
        }
128
 
129
}
130
 
1120 pj 131
TASK asteroide(void)
132
{
133
    int i;
134
    int y = rand() % 7 + 1;
135
 
136
    int load1,j;
137
 
138
    char s[2];
139
 
140
    s[0] = '*'; s[1] = 0;
141
 
142
    /*for (;;)*/ {
143
      i = 1;
144
      while (i < ASTER_LIM) {
145
        load1 = 10000; //8000 + rand()%2000;
146
        for (j=0; j<load1; j++) {
147
          s[0] = '*' + rand() % 100;
148
          puts_xy(i,y,rand()%15+1,s);
149
        }
150
 
151
        task_activate(aper_table[rand()%APER_MAX]);
152
        task_endcycle();
153
 
154
        puts_xy(i,y,WHITE," ");
155
        i++;
156
      }
157
    }
158
    num_aster--;
159
    return 0;
160
}
161
 
162
TASK aper_asteroid(void *a)
163
{
164
    int i;
165
    int y = rand() % 7 + 1;
166
 
167
    int load1,j;
168
    int c;
169
 
170
    char s[2];
171
 
172
    c = (int)a;
173
    s[0] = '*'; s[1] = 0;
174
 
175
    for (;;) {
176
      i = 1;
177
      while (i < ASTER_LIM) {
178
        load1 = APER_REP; //8000 + rand()%2000;
179
        for (j=0; j<load1; j++) {
180
          s[0] = '*' + rand() % 100;
181
          puts_xy(i,y,rand()%15+1,s);
182
        }
183
        s[0] = c;
184
        puts_xy(i,y,rand()%15+1,s);
185
 
186
        task_endcycle();
187
 
188
        puts_xy(i,y,WHITE," ");
189
        i++;
190
      }
191
    }
192
}
193
 
194
TASK aster()
195
{
196
    PID p;
197
 
198
    HARD_TASK_MODEL m;
199
    int r;
200
    int x; // adaptive bandwidth...
201
 
202
    hard_task_default_model(m);
203
    hard_task_def_wcet(m,PER_WCET);
204
    hard_task_def_ctrl_jet(m);
205
 
206
    x = 200;
207
 
208
    srand(7);
209
    while (1) {
210
        if (num_aster < ASTER_MAX) {
211
            r = (rand() % 200);
212
 
213
            hard_task_def_arg(m,(void *)((rand() % 7)+1));
214
            hard_task_def_mit(m, (x+r)*1000);
215
            p = task_create("aaa",asteroide,&m,NULL);
216
            if (p == -1)
217
            {
218
              if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
219
              printf_xy(62,3,WHITE,"adapt=%3u err=%d",
220
                        iq_query_first(&freedesc),errno);
221
            }
222
            else {
223
              num_aster++;
224
              printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
225
              task_activate(p);
226
              x /= 2;
227
              if (x<50) x = 50;
228
            }
229
        }
230
        task_endcycle();
231
    }
232
}
233
 
234
TASK clock()
235
{
236
    int s = 0, m = 0;
237
 
238
    while(1) {
239
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
240
        printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
241
        task_endcycle();
242
 
243
        if (++s > 59) {
244
            s = 0;
245
            m++;
246
        }
247
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
248
        printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
249
        task_endcycle();
250
    }
251
}
252
 
253
 
254
 
255
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
256
   and plot on the screen the elapsed times... */
257
TASK jetcontrol()
258
{
259
  int i;  /* a counter */
260
  TIME sum, max, curr, last[5];
261
  int nact;
262
  int j; /* the elements set by jet_gettable */
263
  PID p;
264
 
265
 
266
  kern_cli();
267
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
268
  kern_sti();
269
 
270
  for (;;) {
271
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
272
       if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
273
 
274
       for (j=0; j<5; j++) last[j] = 0;
275
       jet_gettable(p, &last[0], 5);
276
       kern_cli();
277
       printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
278
                 p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
279
       kern_sti();
280
       i++;
281
    }
282
  }
283
}
284
 
285
 
286
void fine(KEY_EVT *e)
287
{
1377 giacomo 288
  task_activate(shutdown_task_PID);
1120 pj 289
}
290
 
291
 
292
int main(int argc, char **argv)
293
{
294
    PID p1,p2,p3; //,p4,p5,p6;
295
    HARD_TASK_MODEL m;
296
    NRT_TASK_MODEL m_nrt;
297
    SOFT_TASK_MODEL m_aper;
298
    int i;
299
 
1377 giacomo 300
    set_shutdown_task();
301
 
302
    device_drivers_init();
303
 
1120 pj 304
    KEY_EVT emerg;
305
 
306
    clear();
307
 
308
    cprintf("Press Alt-x to end the demo...");
309
 
310
    //keyb_set_map(itaMap);
311
    emerg.ascii = 'x';
312
    emerg.scan = KEY_X;
313
    emerg.flag = ALTL_BIT;
1377 giacomo 314
    emerg.status = KEY_PRESSED;
315
    keyb_hook(emerg,fine,FALSE);
1120 pj 316
 
317
    hard_task_default_model(m);
318
    hard_task_def_wcet(m,ASTER_WCET);
319
    hard_task_def_mit(m,10000);
320
    hard_task_def_group(m,1);
321
    hard_task_def_ctrl_jet(m);
322
 
323
    nrt_task_default_model(m_nrt);
324
    nrt_task_def_group(m_nrt,1);
325
    nrt_task_def_ctrl_jet(m_nrt);
326
 
327
    p1 = task_create("Aster",aster,&m,NULL);
328
    if (p1 == -1) {
1377 giacomo 329
        sys_shutdown_message("test7.c(main): Could not create task <aster> ...");
330
        task_activate(shutdown_task_PID);
331
        return 0;
1120 pj 332
    }
333
 
334
    hard_task_def_mit(m,500000);
335
    hard_task_def_wcet(m,CLOCK_WCET);
336
    p2 = task_create("Clock",clock,&m,NULL);
337
    if (p2 == -1) {
1377 giacomo 338
        sys_shutdown_message("test7.c(main): Could not create task <Clock> ...");
339
        task_activate(shutdown_task_PID);
340
        return 0;
1120 pj 341
    }
342
 
343
    soft_task_default_model(m_aper);
344
    soft_task_def_ctrl_jet(m_aper);
345
    soft_task_def_level(m_aper, 1);
346
    soft_task_def_group(m_aper,1);
347
    soft_task_def_aperiodic(m_aper);
348
    p3 = task_create("JetControl",jetcontrol,&m_aper,NULL);
349
    if (p3 == -1) {
1377 giacomo 350
        sys_shutdown_message("test7.c(main): Could not create task <JetControl> ...");
351
        task_activate(shutdown_task_PID);
352
        return 0;
1120 pj 353
    }
354
 
355
    soft_task_def_wcet(m_aper,APER_WCET);
356
    soft_task_def_ctrl_jet(m_aper);
357
    soft_task_def_aperiodic(m_aper);
358
 
359
    for (i=0; i<APER_MAX; i++) {
360
      soft_task_def_level(m_aper, i/4 + 3);
361
      soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±'));
362
      aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
363
      if (aper_table[i] == -1) {
1377 giacomo 364
        sys_shutdown_message("test7.c(main): Could not create task <aper> ...");
365
        task_activate(shutdown_task_PID);
366
        return 0;
1120 pj 367
      }
368
    }
369
 
370
    group_activate(1);
371
    return 0;
372
}
373