Subversion Repositories shark

Rev

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