Subversion Repositories shark

Rev

Rev 1120 | Rev 1388 | 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 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
 *
1377 giacomo 37
 * CVS :        $Id: aster4.c,v 1.2 2004-04-17 11:36:12 giacomo Exp $
1120 pj 38
 
39
 Test Number 13 (D):
40
 
41
 this is a part of the classic Hartik demo Aster, and it is based on aster 3.
42
 
43
 The demo creates:
44
 - a set of TBS tasks assigned to 2 TBS servers initialized with different bandwidth.
45
 
46
 - a set of periodic tasks, just to make noise (function asteroide)
47
 
48
 - a set of CBS tasks that are created to fill the available free
49
   bandwidth (function soft_aster)
50
 
51
 - a few service task (the one that creates the CBS tasks (aster), a clock,
52
   JET info visualization
53
 
54
 - a set of never ending "system tasks" that simulate a device driver
55
   task that will end only at shutdown (function aper_asteroid)
56
 
57
 - a keyboard task that will execute an hook to terminate the system
58
 
59
*/
60
 
61
/*
62
 * Copyright (C) 2000 Paolo Gai
63
 *
64
 * This program is free software; you can redistribute it and/or modify
65
 * it under the terms of the GNU General Public License as published by
66
 * the Free Software Foundation; either version 2 of the License, or
67
 * (at your option) any later version.
68
 *
69
 * This program is distributed in the hope that it will be useful,
70
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
71
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
72
 * GNU General Public License for more details.
73
 *
74
 * You should have received a copy of the GNU General Public License
75
 * along with this program; if not, write to the Free Software
76
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
77
 *
78
 */
79
 
80
#include "kernel/kern.h"
81
#include "modules/edf.h"
82
#include "modules/cbs.h"
83
 
1377 giacomo 84
#include <drivers/shark_linuxc26.h>
85
#include <drivers/shark_input26.h>
86
#include <drivers/shark_keyb26.h>
87
 
1120 pj 88
int num_aster = 0;
89
#define ASTER_LIM       60
90
#define DISPLAY_MAX     15
91
#define ASTER_MAX       70
92
#define STAT_Y           9
93
 
94
#define PER_MAX          5
95
#define APER_MAX         8
96
 
97
// These numbers works on a Pentium 133 */
98
#define PER_WCET     25000
99
#define APER_WCET    53000
100
#define CLOCK_WCET    1000
101
#define ASTER_WCET    1000
102
#define SOFT_MET      6300
103
 
104
#define APER_REP     22000
105
 
106
PID aper_table[APER_MAX];
107
 
1377 giacomo 108
PID shutdown_task_PID = -1;
1120 pj 109
 
1377 giacomo 110
int device_drivers_init() {
111
 
112
        KEYB_PARMS kparms = BASE_KEYB;
113
 
114
        LINUXC26_register_module();
115
 
116
        keyb_def_ctrlC(kparms, NULL);
117
 
118
        INPUT26_init();
119
 
120
        KEYB26_init(&kparms);
121
 
122
        return 0;
123
 
124
}
125
 
126
int device_drivers_close() {
127
 
128
        KEYB26_close();
129
 
130
        INPUT26_close();
131
 
132
        return 0;
133
 
134
}
135
 
136
TASK shutdown_task_body(void *arg) {
137
 
138
        device_drivers_close();
139
 
140
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
141
 
142
        sys_end();
143
 
144
        return NULL;
145
 
146
}
147
 
148
void set_shutdown_task() {
149
 
150
        NRT_TASK_MODEL nrt;
151
 
152
        nrt_task_default_model(nrt);
153
 
154
        shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
155
        if (shutdown_task_PID == NIL) {
156
                sys_shutdown_message("Error: Cannot create shutdown task\n");
157
                sys_end();
158
        }
159
 
160
}
161
 
1120 pj 162
TASK asteroide(void)
163
{
164
  int i;
165
  int y = rand() % 7 + 1;
166
 
167
  int load1,j;
168
 
169
  char s[2];
170
 
171
  s[0] = '*'; s[1] = 0;
172
 
173
  for (;;) {
174
    i = 1;
175
    while (i < ASTER_LIM) {
176
      load1 = 10000; //8000 + rand()%2000;
177
      for (j=0; j<load1; j++) {
178
        s[0] = '*' + rand() % 100;
179
        puts_xy(i,y,rand()%15+1,s);
180
      }
181
 
182
      task_activate(aper_table[rand()%APER_MAX]);
183
      task_endcycle();
184
 
185
      puts_xy(i,y,WHITE," ");
186
      i++;
187
    }
188
  }
189
  //num_aster--;
190
}
191
 
192
TASK aper_asteroid(void *a)
193
{
194
  int i;
195
  int y = rand() % 7 + 1;
196
 
197
  int load1,j;
198
  int c;
199
 
200
  char s[2];
201
 
202
  c = (int)a;
203
  s[0] = '*'; s[1] = 0;
204
 
205
  for (;;) {
206
    i = 1;
207
    while (i < ASTER_LIM) {
208
      load1 = APER_REP; //8000 + rand()%2000;
209
      for (j=0; j<load1; j++) {
210
        s[0] = '*' + rand() % 100;
211
        puts_xy(i,y,rand()%15+1,s);
212
      }
213
      s[0] = c;
214
      puts_xy(i,y,rand()%15+1,s);
215
 
216
      task_endcycle();
217
 
218
      puts_xy(i,y,WHITE," ");
219
      i++;
220
    }
221
  }
222
}
223
 
224
TASK soft_aster(void)
225
{
226
  int i;
227
  int y = rand() % 7 + 1;
228
 
229
  int load1,j;
230
 
231
  char s[2];
232
 
233
  s[0] = '*'; s[1] = 0;
234
 
235
  i = 1;
236
  while (i < ASTER_LIM) {
237
    load1 = 1000 + rand()%9000;
238
    for (j=0; j<load1; j++) {
239
      s[0] = '*' + rand() % 100;
240
      puts_xy(i,y,rand()%15+1,s);
241
    }
242
    s[0] = 1;
243
    puts_xy(i,y,rand()%15+1,s);
244
 
245
    task_activate(aper_table[rand()%APER_MAX]);
246
    task_endcycle();
247
 
248
    puts_xy(i,y,WHITE," ");
249
    i++;
250
  }
251
  num_aster--;
252
  return 0;
253
}
254
 
255
TASK aster()
256
{
257
  PID p;
258
 
259
  HARD_TASK_MODEL m;
260
  SOFT_TASK_MODEL m_soft;
261
  int r;
262
  int x; // adaptive bandwidth...
263
 
264
  srand(7);
265
 
266
  /* create a set of periodic tasks, just to make noise */
267
  hard_task_default_model(m);
268
  hard_task_def_wcet(m,PER_WCET);
269
  hard_task_def_ctrl_jet(m);
270
  for (x=0; x<PER_MAX; x++) {
271
    r = (rand() % 200);
272
    hard_task_def_mit(m, (64+r)*1000);
273
    p = task_create("per",asteroide,&m,NULL);
274
    if (p!=-1) task_activate(p);
275
  }
276
 
277
  soft_task_default_model(m_soft);
278
  soft_task_def_met(m_soft,SOFT_MET);
279
  soft_task_def_ctrl_jet(m_soft);
280
 
281
  x = 64;
282
 
283
  while (1) {
284
    if (num_aster < ASTER_MAX) {
285
      r = (rand() % 200);
286
 
287
      soft_task_def_period(m_soft, (x+r)*1000);
288
      p = task_create("aaa",soft_aster,&m_soft,NULL);
289
      if (p == -1)
290
        {
291
          if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
292
          printf_xy(62,3,WHITE,"adapt=%3u err=%d",
293
                    iq_query_first(&freedesc),errno);
294
        }
295
      else {
296
        num_aster++;
297
        printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
298
        task_activate(p);
299
        x /= 2;
300
        if (x<50) x = 50;
301
      }
302
    }
303
    task_endcycle();
304
  }
305
}
306
 
307
TASK clock()
308
{
309
  int s = 0, m = 0;
310
 
311
  while(1) {
312
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
313
    printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
314
    printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
315
    task_endcycle();
316
 
317
    if (++s > 59) {
318
      s = 0;
319
      m++;
320
    }
321
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
322
    printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
323
    printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
324
    task_endcycle();
325
  }
326
}
327
 
328
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
329
   and plot on the screen the elapsed times... */
330
TASK jetcontrol()
331
{
332
  int i;  /* a counter */
333
  TIME sum, max, curr, last[5];
334
  int nact;
335
  int j; /* the elements set by jet_gettable */
336
  PID p;
337
 
338
 
339
  kern_cli();
340
  printf_xy(0,STAT_Y,WHITE,"PID  Mean T. Max T.  N.A.  Curr.    Last1  Last2  Last3  Last4  Last5");
341
  kern_sti();
342
 
343
  for (;;) {
344
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
345
      if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 ||
346
          (proc_table[p].pclass & 0xFF00) == HARD_PCLASS) continue;
347
 
348
      for (j=0; j<5; j++) last[j] = 0;
349
      jet_gettable(p, &last[0], 5);
350
      kern_cli();
351
      if (proc_table[p].task_level == 4)
352
        printf_xy(0,STAT_Y+i+1,WHITE,"%-3d  %-6d  %-6d  %-4d  %-7d  %-5d  %-5d  %-5d  %-5d  %-5d",
353
                  p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)CBS_get_nact(4,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
354
      else
355
        printf_xy(0,STAT_Y+i+1,WHITE,"%-3d  %-6d  %-6d  %-4d  %-7d  %-5d  %-5d  %-5d  %-5d  %-5d",
356
                  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]);
357
      kern_sti();
358
      i++;
359
    }
360
  }
361
}
362
 
363
void endfun(KEY_EVT *k)
364
{
1377 giacomo 365
  task_activate(shutdown_task_PID);
1120 pj 366
}
367
 
368
int main(int argc, char **argv)
369
{
370
  KEY_EVT k;
371
 
372
  PID p1,p2,p3;
373
  HARD_TASK_MODEL m;
374
  SOFT_TASK_MODEL m_aper;
375
  SOFT_TASK_MODEL m_soft;
376
  int i;
377
 
1377 giacomo 378
  set_shutdown_task();
379
 
380
  device_drivers_init();
381
 
1120 pj 382
  k.flag = 0;
383
  k.scan = KEY_ENT;
384
  k.ascii = 13;
1377 giacomo 385
  k.status = KEY_PRESSED;
386
  keyb_hook(k, endfun, FALSE);
1120 pj 387
 
388
  clear();
389
  cprintf("Press ENTER to end the demo...");
390
 
391
  hard_task_default_model(m);
392
  hard_task_def_wcet(m,ASTER_WCET);
393
  hard_task_def_mit(m,10000);
394
  hard_task_def_group(m,1);
395
  hard_task_def_ctrl_jet(m);
396
 
397
  soft_task_default_model(m_soft);
398
  soft_task_def_met(m_soft,1000);
399
  soft_task_def_period(m_soft,100000);
400
  soft_task_def_group(m_soft,1);
401
  soft_task_def_ctrl_jet(m_soft);
402
  soft_task_def_aperiodic(m_soft);
403
 
404
  p1 = task_create("Aster",aster,&m,NULL);
405
  if (p1 == -1) {
1377 giacomo 406
    sys_shutdown_message("aster4.c(main): Could not create task <aster> ...");
407
    task_activate(shutdown_task_PID);
408
    return 0;
1120 pj 409
  }
410
 
411
  hard_task_def_mit(m,500000);
412
  hard_task_def_wcet(m,CLOCK_WCET);
413
  p2 = task_create("Clock",clock,&m,NULL);
414
  if (p2 == -1) {
1377 giacomo 415
    sys_shutdown_message("aster4.c(main): Could not create task <Clock> ...");
416
    task_activate(shutdown_task_PID);
417
    return 0;
1120 pj 418
  }
419
 
420
  p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
421
  if (p3 == -1) {
1377 giacomo 422
    sys_shutdown_message("aster4.c(main): Could not create task <JetControl> ...");
423
    task_activate(shutdown_task_PID);
424
    return 0;
1120 pj 425
  }
426
 
427
  soft_task_default_model(m_aper);
428
  soft_task_def_wcet(m_aper,APER_WCET);
429
  soft_task_def_ctrl_jet(m_aper);
430
  soft_task_def_system(m_aper);
431
  soft_task_def_aperiodic(m_aper);
432
 
433
  for (i=0; i<APER_MAX; i++) {
434
    soft_task_def_level(m_aper, i/4 + 2);
435
    soft_task_def_arg(m_aper, (void *)(i/4 ? '' : ''));
436
    aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
437
    if (aper_table[i] == -1) {
1377 giacomo 438
      sys_shutdown_message("aster4.c(main): Could not create task <aper> ...");
439
      task_activate(shutdown_task_PID);
440
      return 0;
1120 pj 441
    }
442
  }
443
 
444
  group_activate(1);
445
  return 0;
446
}
447