Subversion Repositories shark

Rev

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