Subversion Repositories shark

Rev

Rev 1123 | Rev 1377 | 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, Gerardo Lamastra and Giuseppe Lipari
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
 *
1309 giacomo 37
 * CVS :        $Id: aster6.c,v 1.3 2004-01-17 18:43:07 giacomo Exp $
1120 pj 38
 
39
 this is a part of the classic Hartik demo Aster.
40
 
41
 it is based on test 17 (h), and the JobControl Task uses an
42
 SOFT_TASK_MODEL served by a polling server
43
 
44
*/
45
 
46
#include "kernel/kern.h"
47
#include "modules/edf.h"
48
#include "modules/cbs.h"
49
#include "drivers/keyb.h"
50
 
51
int num_aster = 0;
52
#define ASTER_LIM       60
53
#define DISPLAY_MAX     15
54
#define ASTER_MAX       70
55
#define STAT_Y           9
56
 
57
#define PER_MAX          5
58
#define APER_MAX         8
59
 
60
#define PER_WCET      6200
61
#define APER_WCET    18400
62
#define JET_WCET     10000
63
 
64
#define APER_REP     22000
65
 
66
PID aper_table[APER_MAX];
67
 
68
mutex_t m1;
69
 
70
 
71
#define PIMUTEX
72
//#define NPPMUTEX
73
//#define NOPMUTEX
74
 
1309 giacomo 75
//#define LONGSC
1120 pj 76
 
77
#ifdef LONGSC
78
#define SOFT_MET      3000 /* 12000 */
79
#define CLOCK_WCET     200 /* 300*/
80
#define ASTER_WCET     200 /* 300*/
81
#else
82
#define SOFT_MET     80000 /* 4500 */
83
#define CLOCK_WCET    2000 /* 200*/
84
#define ASTER_WCET    2000 /* 200*/
85
#endif
86
 
87
TASK asteroide(void)
88
{
89
  int i;
90
  int y = rand() % 7 + 1;
91
 
92
  int load1,j;
93
 
94
  char s[2];
95
 
96
  s[0] = '*'; s[1] = 0;
97
 
98
  for (;;) {
99
    i = 1;
100
    while (i < ASTER_LIM) {
101
      load1 = 10000; //8000 + rand()%2000;
102
#ifdef LONGSC
103
      mutex_lock(&m1);
104
#endif
105
      for (j=0; j<load1; j++) {
106
        s[0] = '*' + rand() % 100;
107
#ifndef LONGSC
108
        mutex_lock(&m1);
109
#endif
110
        puts_xy(i,y,rand()%15+1,s);
111
#ifndef LONGSC
112
        mutex_unlock(&m1);
113
#endif
114
      }
115
#ifdef LONGSC
116
      mutex_unlock(&m1);
117
#endif
118
 
119
      task_activate(aper_table[rand()%APER_MAX]);
120
      task_endcycle();
121
 
122
      mutex_lock(&m1);
123
      puts_xy(i,y,WHITE," ");
124
      mutex_unlock(&m1);
125
      i++;
126
    }
127
  }
128
  //num_aster--;
129
}
130
 
131
TASK aper_asteroid(void *a)
132
{
133
  int i;
134
  int y = rand() % 7 + 1;
135
 
136
  int load1,j;
137
  int c;
138
 
139
  char s[2];
140
 
141
  c = (int)a;
142
  s[0] = '*'; s[1] = 0;
143
 
144
  for (;;) {
145
    i = 1;
146
    while (i < ASTER_LIM) {
147
      load1 = APER_REP; //8000 + rand()%2000;
148
#ifdef LONGSC
149
      mutex_lock(&m1);
150
#endif
151
      for (j=0; j<load1; j++) {
152
        s[0] = '*' + rand() % 100;
153
#ifndef LONGSC
154
        mutex_lock(&m1);
155
#endif
156
        puts_xy(i,y,rand()%15+1,s);
157
#ifndef LONGSC
158
        mutex_unlock(&m1);
159
#endif
160
      }
161
      s[0] = c;
162
#ifndef LONGSC
163
      mutex_lock(&m1);
164
#endif
165
      puts_xy(i,y,rand()%15+1,s);
166
      mutex_unlock(&m1);
167
 
168
      task_endcycle();
169
 
170
      mutex_lock(&m1);
171
      puts_xy(i,y,WHITE," ");
172
      mutex_unlock(&m1);
173
      i++;
174
    }
175
  }
176
}
177
 
178
TASK soft_aster(void)
179
{
180
  int i;
181
  int y = rand() % 7 + 1;
182
 
183
  int load1,j;
184
 
185
  char s[2];
186
 
187
  s[0] = '*'; s[1] = 0;
188
 
189
  /*for (;;)*/ {
190
    i = 1;
191
    while (i < ASTER_LIM) {
192
      load1 = 1000 + rand()%9000;
193
#ifdef LONGSC
194
      mutex_lock(&m1);
195
#endif
196
      for (j=0; j<load1; j++) {
197
        s[0] = '*' + rand() % 100;
198
#ifndef LONGSC
199
        mutex_lock(&m1);
200
#endif
201
        puts_xy(i,y,rand()%15+1,s);
202
#ifndef LONGSC
203
        mutex_unlock(&m1);
204
#endif
205
      }
206
      s[0] = 1;
207
#ifndef LONGSC
208
      mutex_lock(&m1);
209
#endif
210
      puts_xy(i,y,rand()%15+1,s);
211
      mutex_unlock(&m1);
212
 
213
      task_activate(aper_table[rand()%APER_MAX]);
214
      task_endcycle();
215
 
216
      mutex_lock(&m1);
217
      puts_xy(i,y,WHITE," ");
218
      mutex_unlock(&m1);
219
      i++;
220
    }
221
  }
222
  num_aster--;
223
  return 0;
224
}
225
 
226
TASK aster()
227
{
228
  PID p;
229
 
230
  //    HARD_TASK_MODEL m;
231
  SOFT_TASK_MODEL m_soft;
232
  int r;
233
  int x; // adaptive bandwidth...
234
 
235
  srand(7);
236
 
237
  /*    periodic_task_default_model(m,0,PER_WCET);
238
        periodic_task_def_ctrl_jet(m);
239
        for (x=0; x<PER_MAX; x++) {
240
        r = (rand() % 200);
241
        periodic_task_def_period(m, (64+r)*1000);
242
        p = task_create("per",asteroide,&m,NULL);
243
        if (p!=-1) task_activate(p);
244
        }
245
  */
246
  soft_task_default_model(m_soft);
247
  soft_task_def_met(m_soft,SOFT_MET);
248
  soft_task_def_ctrl_jet(m_soft);
249
 
250
  x = 128; //64;
251
 
252
  while (1) {
253
    /*        {
254
              PID p;
255
              int x;
256
              p = level_table[0]->level_scheduler(0);
257
              printf_xy(1,8,WHITE,"                                                                               ");
258
 
259
              x = 0;
260
              do {
261
              printf_xy(3*x+1,8,WHITE,"%3d",p);
262
              p = proc_table[p].next;
263
              x++;
264
              } while (p != NIL);
265
              }
266
    */
267
    if (num_aster < ASTER_MAX) {
268
      r = (rand() % 200);
269
 
270
      soft_task_def_period(m_soft, (x+r)*1000);
271
      p = task_create("aaa",soft_aster,&m_soft,NULL);
272
      if (p == -1)
273
        {
274
          if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
275
          mutex_lock(&m1);
276
          printf_xy(62,3,WHITE,"adapt=%3u err=%d",
277
                    iq_query_first(&freedesc),errno);
278
          mutex_unlock(&m1);
279
        }
280
      else {
281
        num_aster++;
282
        mutex_lock(&m1);
283
        printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
284
        mutex_unlock(&m1);
285
        task_activate(p);
286
        x /= 2;
287
        if (x<50) x = 50;
288
      }
289
    }
290
    task_endcycle();
291
  }
292
}
293
 
294
TASK clock()
295
{
296
  int s = 0, m = 0;
297
 
298
  while(1) {
299
    mutex_lock(&m1);
300
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
301
    printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
302
    printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2));
303
 
304
    mutex_unlock(&m1);
1123 pj 305
 
1120 pj 306
    task_endcycle();
307
 
308
    if (++s > 59) {
309
      s = 0;
310
      m++;
311
    }
312
    mutex_lock(&m1);
313
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
314
    printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
315
    printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2));
316
    mutex_unlock(&m1);
317
    task_endcycle();
318
  }
319
}
320
 
321
 
322
 
323
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
324
   and plot on the screen the elapsed times... */
325
TASK jetcontrol()
326
{
327
  int i;  /* a counter */
328
  TIME sum, max, curr, last[5];
329
  int nact;
330
  int j; /* the elements set by jet_gettable */
331
  PID p;
332
 
333
 
334
  mutex_lock(&m1);
335
  printf_xy(0,STAT_Y,WHITE,"PID  Mean T. Max T.  N.A.  Curr.    Last1  Last2  Last3  Last4  Last5");
336
  mutex_unlock(&m1);
337
 
338
  for (;;) {
339
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
340
      if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 /*||
341
                                                           (proc_table[p].pclass & 0xFF00) == APERIODIC_PCLASS ||
342
                                                           (proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue;
343
 
344
      for (j=0; j<5; j++) last[j] = 0;
345
      jet_gettable(p, &last[0], 5);
346
      mutex_lock(&m1);
347
      if (proc_table[p].task_level == 2)
348
        printf_xy(0,STAT_Y+i+1,WHITE,"%-3d  %-6d  %-6d  %-4d  %-7d  %-5d  %-5d  %-5d  %-5d  %-5d",
349
                  p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)CBS_get_nact(2,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
350
      //                   p, sum/(nact==0 ? 1 : nact), max, proc_table[p].avail_time, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , CBS_get_nact(2,p), last[4]);
351
      else
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, (int)nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
354
      //                   p, sum/(nact==0 ? 1 : nact), max, nact, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , last[3], last[4]);
355
      mutex_unlock(&m1);
356
      i++;
357
    }
358
  }
359
}
360
 
361
void fine(KEY_EVT *e)
362
{
363
  sys_end();
364
}
365
 
366
int main(int argc, char **argv)
367
{
368
  PID p1,p2,p3; //,p4,p5,p6;
369
  HARD_TASK_MODEL m;
370
  //    NRT_TASK_MODEL m_nrt;
371
  SOFT_TASK_MODEL m_aper;
372
  SOFT_TASK_MODEL m_soft;
373
  //    int i;
374
  struct timespec fineprg;
375
 
376
#ifdef PIMUTEX
377
  PI_mutexattr_t a;
378
#endif
379
 
380
#ifdef NPPMUTEX
381
  NPP_mutexattr_t a;
382
#endif
383
 
384
#ifdef NOPMUTEX
385
  NOP_mutexattr_t a;
386
#endif
387
 
388
 
389
  KEY_EVT emerg;
390
  //keyb_set_map(itaMap);
391
  emerg.ascii = 'x';
392
  emerg.scan = KEY_X;
393
  emerg.flag = ALTL_BIT;
394
  keyb_hook(emerg,fine);
395
 
396
  clear();
397
 
398
  hard_task_default_model(m);
399
  hard_task_def_mit(m,100000);
400
  hard_task_def_wcet(m,ASTER_WCET);
401
  hard_task_def_group(m,1);
402
  hard_task_def_ctrl_jet(m);
403
 
404
  //    nrt_task_default_model(m_nrt);
405
  //    nrt_task_def_group(m_nrt,1);
406
  //    nrt_task_def_ctrl_jet(m_nrt);
407
 
408
 
409
  soft_task_default_model(m_aper);
410
  soft_task_def_group(m_aper,1);
411
  soft_task_def_ctrl_jet(m_aper);
412
  soft_task_def_aperiodic(m_aper);
413
 
414
  soft_task_default_model(m_soft);
415
  soft_task_def_period(m_soft,100000);
416
  soft_task_def_met(m_soft,JET_WCET);
417
  soft_task_def_group(m_soft,1);
418
  soft_task_def_ctrl_jet(m_soft);
419
  soft_task_def_aperiodic(m_soft);
420
 
421
 
422
  p1 = task_create("Aster",aster,&m,NULL);
423
  if (p1 == -1) {
424
    perror("test7.c(main): Could not create task <aster> ...");
425
    sys_end();
426
    l1_exit(-1);
427
  }
428
 
429
  hard_task_def_mit(m,500000);
430
  hard_task_def_wcet(m,CLOCK_WCET);
431
  p2 = task_create("Clock",clock,&m,NULL);
432
  if (p2 == -1) {
433
    perror("test7.c(main): Could not create task <Clock> ...");
434
    sys_end();
435
    l1_exit(-1);
436
  }
437
 
438
  //    p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
439
  p3 = task_create("JetControl",jetcontrol,&m_aper,NULL);
440
  if (p3 == -1) {
441
    perror("test7.c(main): Could not create task <JetControl> ...");
442
    sys_end();
443
    l1_exit(-1);
444
  }
445
  /*
446
    aperiodic_task_default_model(m_aper,APER_WCET);
447
    aperiodic_task_def_ctrl_jet(m_aper);
448
    aperiodic_task_def_system(m_aper);
449
 
450
    for (i=0; i<APER_MAX; i++) {
451
    aperiodic_task_def_level(m_aper, i/4 + 2);
452
    aperiodic_task_def_arg(m_aper, (i/4 ? '' : ''));
453
    aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
454
    if (aper_table[i] == -1) {
455
    perror("test7.c(main): Could not create task <aper> ...");
456
    sys_end();
457
    l1_exit(-1);
458
    }
459
    }
460
  */
461
  task_nopreempt();
462
 
463
#ifdef PIMUTEX
464
  PI_mutexattr_default(a);
465
#endif
466
 
467
#ifdef NPPMUTEX
468
  NPP_mutexattr_default(a);
469
#endif
470
 
471
#ifdef NOPMUTEX
472
  NOP_mutexattr_default(a);
473
#endif
474
 
475
  mutex_init(&m1, &a);
476
 
477
  fineprg.tv_sec = 1800;
478
  fineprg.tv_nsec = 0;
479
  kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
480
  group_activate(1);
1123 pj 481
 
1120 pj 482
  return 0;
483
}
484