Subversion Repositories shark

Rev

Rev 1377 | Go to most recent revision | Details | 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
 *
37
 * CVS :        $Id: aster4.c,v 1.1 2002-11-11 08:22:45 pj Exp $
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
#include "drivers/keyb.h"
84
 
85
int num_aster = 0;
86
#define ASTER_LIM       60
87
#define DISPLAY_MAX     15
88
#define ASTER_MAX       70
89
#define STAT_Y           9
90
 
91
#define PER_MAX          5
92
#define APER_MAX         8
93
 
94
// These numbers works on a Pentium 133 */
95
#define PER_WCET     25000
96
#define APER_WCET    53000
97
#define CLOCK_WCET    1000
98
#define ASTER_WCET    1000
99
#define SOFT_MET      6300
100
 
101
#define APER_REP     22000
102
 
103
PID aper_table[APER_MAX];
104
 
105
int shutting_down = 0;
106
 
107
TASK asteroide(void)
108
{
109
  int i;
110
  int y = rand() % 7 + 1;
111
 
112
  int load1,j;
113
 
114
  char s[2];
115
 
116
  s[0] = '*'; s[1] = 0;
117
 
118
  for (;;) {
119
    i = 1;
120
    while (i < ASTER_LIM) {
121
      load1 = 10000; //8000 + rand()%2000;
122
      for (j=0; j<load1; j++) {
123
        s[0] = '*' + rand() % 100;
124
        puts_xy(i,y,rand()%15+1,s);
125
      }
126
 
127
      task_activate(aper_table[rand()%APER_MAX]);
128
      task_endcycle();
129
 
130
      puts_xy(i,y,WHITE," ");
131
      i++;
132
    }
133
  }
134
  //num_aster--;
135
}
136
 
137
TASK aper_asteroid(void *a)
138
{
139
  int i;
140
  int y = rand() % 7 + 1;
141
 
142
  int load1,j;
143
  int c;
144
 
145
  char s[2];
146
 
147
  c = (int)a;
148
  s[0] = '*'; s[1] = 0;
149
 
150
  for (;;) {
151
    i = 1;
152
    while (i < ASTER_LIM) {
153
      load1 = APER_REP; //8000 + rand()%2000;
154
      for (j=0; j<load1; j++) {
155
        s[0] = '*' + rand() % 100;
156
        puts_xy(i,y,rand()%15+1,s);
157
      }
158
      s[0] = c;
159
      puts_xy(i,y,rand()%15+1,s);
160
 
161
      if (shutting_down) {
162
        cprintf("Ending System Task %d\n",exec_shadow);
163
        return 0;
164
      }
165
 
166
      task_endcycle();
167
 
168
      puts_xy(i,y,WHITE," ");
169
      i++;
170
    }
171
  }
172
}
173
 
174
TASK soft_aster(void)
175
{
176
  int i;
177
  int y = rand() % 7 + 1;
178
 
179
  int load1,j;
180
 
181
  char s[2];
182
 
183
  s[0] = '*'; s[1] = 0;
184
 
185
  i = 1;
186
  while (i < ASTER_LIM) {
187
    load1 = 1000 + rand()%9000;
188
    for (j=0; j<load1; j++) {
189
      s[0] = '*' + rand() % 100;
190
      puts_xy(i,y,rand()%15+1,s);
191
    }
192
    s[0] = 1;
193
    puts_xy(i,y,rand()%15+1,s);
194
 
195
    task_activate(aper_table[rand()%APER_MAX]);
196
    task_endcycle();
197
 
198
    puts_xy(i,y,WHITE," ");
199
    i++;
200
  }
201
  num_aster--;
202
  return 0;
203
}
204
 
205
TASK aster()
206
{
207
  PID p;
208
 
209
  HARD_TASK_MODEL m;
210
  SOFT_TASK_MODEL m_soft;
211
  int r;
212
  int x; // adaptive bandwidth...
213
 
214
  srand(7);
215
 
216
  /* create a set of periodic tasks, just to make noise */
217
  hard_task_default_model(m);
218
  hard_task_def_wcet(m,PER_WCET);
219
  hard_task_def_ctrl_jet(m);
220
  for (x=0; x<PER_MAX; x++) {
221
    r = (rand() % 200);
222
    hard_task_def_mit(m, (64+r)*1000);
223
    p = task_create("per",asteroide,&m,NULL);
224
    if (p!=-1) task_activate(p);
225
  }
226
 
227
  soft_task_default_model(m_soft);
228
  soft_task_def_met(m_soft,SOFT_MET);
229
  soft_task_def_ctrl_jet(m_soft);
230
 
231
  x = 64;
232
 
233
  while (1) {
234
    if (num_aster < ASTER_MAX) {
235
      r = (rand() % 200);
236
 
237
      soft_task_def_period(m_soft, (x+r)*1000);
238
      p = task_create("aaa",soft_aster,&m_soft,NULL);
239
      if (p == -1)
240
        {
241
          if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
242
          printf_xy(62,3,WHITE,"adapt=%3u err=%d",
243
                    iq_query_first(&freedesc),errno);
244
        }
245
      else {
246
        num_aster++;
247
        printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
248
        task_activate(p);
249
        x /= 2;
250
        if (x<50) x = 50;
251
      }
252
    }
253
    task_endcycle();
254
  }
255
}
256
 
257
TASK clock()
258
{
259
  int s = 0, m = 0;
260
 
261
  while(1) {
262
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
263
    printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
264
    printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
265
    task_endcycle();
266
 
267
    if (++s > 59) {
268
      s = 0;
269
      m++;
270
    }
271
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
272
    printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
273
    printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
274
    task_endcycle();
275
  }
276
}
277
 
278
 
279
 
280
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
281
   and plot on the screen the elapsed times... */
282
TASK jetcontrol()
283
{
284
  int i;  /* a counter */
285
  TIME sum, max, curr, last[5];
286
  int nact;
287
  int j; /* the elements set by jet_gettable */
288
  PID p;
289
 
290
 
291
  kern_cli();
292
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
293
  kern_sti();
294
 
295
  for (;;) {
296
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
297
      if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 ||
298
          (proc_table[p].pclass & 0xFF00) == HARD_PCLASS) continue;
299
 
300
      for (j=0; j<5; j++) last[j] = 0;
301
      jet_gettable(p, &last[0], 5);
302
      kern_cli();
303
      if (proc_table[p].task_level == 4)
304
        printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
305
                  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]);
306
      else
307
        printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
308
                  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]);
309
      kern_sti();
310
      i++;
311
    }
312
  }
313
}
314
 
315
void endfun(KEY_EVT *k)
316
{
317
  sys_end();
318
}
319
 
320
void exiting(void *arg)
321
{
322
  cprintf("System shut down...\n");
323
  shutting_down = 1;
324
}
325
 
326
int main(int argc, char **argv)
327
{
328
  KEY_EVT k;
329
 
330
  PID p1,p2,p3;
331
  HARD_TASK_MODEL m;
332
  SOFT_TASK_MODEL m_aper;
333
  SOFT_TASK_MODEL m_soft;
334
  int i;
335
 
336
  k.flag = 0;
337
  k.scan = KEY_ENT;
338
  k.ascii = 13;
339
  keyb_hook(k, endfun);
340
 
341
  clear();
342
  cprintf("Press ENTER to end the demo...");
343
 
344
  sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN);
345
 
346
  hard_task_default_model(m);
347
  hard_task_def_wcet(m,ASTER_WCET);
348
  hard_task_def_mit(m,10000);
349
  hard_task_def_group(m,1);
350
  hard_task_def_ctrl_jet(m);
351
 
352
  soft_task_default_model(m_soft);
353
  soft_task_def_met(m_soft,1000);
354
  soft_task_def_period(m_soft,100000);
355
  soft_task_def_group(m_soft,1);
356
  soft_task_def_ctrl_jet(m_soft);
357
  soft_task_def_aperiodic(m_soft);
358
 
359
 
360
  p1 = task_create("Aster",aster,&m,NULL);
361
  if (p1 == -1) {
362
    perror("aster4.c(main): Could not create task <aster> ...");
363
    sys_end();
364
  }
365
 
366
  hard_task_def_mit(m,500000);
367
  hard_task_def_wcet(m,CLOCK_WCET);
368
  p2 = task_create("Clock",clock,&m,NULL);
369
  if (p2 == -1) {
370
    perror("aster4.c(main): Could not create task <Clock> ...");
371
    sys_end();
372
  }
373
 
374
  p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
375
  if (p3 == -1) {
376
    perror("aster4.c(main): Could not create task <JetControl> ...");
377
    sys_end();
378
  }
379
 
380
  soft_task_default_model(m_aper);
381
  soft_task_def_wcet(m_aper,APER_WCET);
382
  soft_task_def_ctrl_jet(m_aper);
383
  soft_task_def_system(m_aper);
384
  soft_task_def_aperiodic(m_aper);
385
 
386
  for (i=0; i<APER_MAX; i++) {
387
    soft_task_def_level(m_aper, i/4 + 2);
388
    soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±'));
389
    aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
390
    if (aper_table[i] == -1) {
391
      perror("aster4.c(main): Could not create task <aper> ...");
392
      sys_end();
393
    }
394
  }
395
 
396
  group_activate(1);
397
  return 0;
398
}
399