Subversion Repositories shark

Rev

Rev 1597 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1099 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
 *
1597 tullio 37
 * CVS :        $Id: aster3.c,v 1.11 2006-07-05 08:26:37 tullio Exp $
1099 pj 38
 
39
 Test Number 10 (A):
40
 
41
 this is a part of the classic Hartik demo Aster.
42
 
43
 it is based on aster2.c, with the use of TBS to serve a set of aperiodic
44
 tasks.
45
 
46
 There are APER_MAX tasks sleeping, and when an asteroide task finish
47
 the current activation, it activate also an aperiodic task chosen
48
 randomly (if the task chosen is already active, the task_activate do
49
 nothing!)
50
 
51
 
52
*/
53
 
54
#include "kernel/kern.h"
1552 pj 55
#include "edf/edf/edf.h"
1099 pj 56
 
57
int num_aster = 0;
58
#define ASTER_LIM       60
59
#define DISPLAY_MAX     15
60
#define ASTER_MAX       70
61
#define STAT_Y           9
62
 
63
#define APER_MAX         8
64
 
65
/* first numbers runs on a pentium 133, second numbers on a celeron 366 */
66
#define PER_WCET     30000 /* 6200 */
1588 tullio 67
#define APER_WCET    50000 /* 18400 */
1099 pj 68
#define CLOCK_WCET   1000 /* 200 */
69
#define ASTER_WCET   1000 /* 200 */
70
#define MIN_PERIOD   200  /* 64, in ms */
71
 
72
#define APER_REP     22000
73
 
74
PID aper_table[APER_MAX];
75
 
76
TASK asteroide(void)
77
{
78
  int i;
79
  int y = rand() % 7 + 1;
80
 
81
  int load1,j;
82
 
83
  char s[2];
84
 
85
  s[0] = '*'; s[1] = 0;
86
 
87
  /*for (;;)*/ {
88
    i = 1;
89
    while (i < ASTER_LIM) {
90
      load1 = 10000; //8000 + rand()%2000;
91
      for (j=0; j<load1; j++) {
92
        s[0] = '*' + rand() % 100;
93
        puts_xy(i,y,rand()%15+1,s);
94
      }
95
 
96
      task_activate(aper_table[rand()%APER_MAX]);
97
      task_endcycle();
98
 
99
      puts_xy(i,y,WHITE," ");
100
      i++;
101
    }
102
  }
103
  num_aster--;
104
  return 0;
105
}
106
 
107
TASK aper_asteroid(void *a)
108
{
109
  int i;
110
  int y = rand() % 7 + 1;
111
 
112
  int load1,j;
113
  int c;
114
 
115
  char s[2];
116
 
117
  c = (int)a;
118
  s[0] = '*'; s[1] = 0;
119
 
120
  for (;;) {
121
    i = 1;
122
    while (i < ASTER_LIM) {
123
      load1 = APER_REP; //8000 + rand()%2000;
124
      for (j=0; j<load1; j++) {
125
        s[0] = '*' + rand() % 100;
126
        puts_xy(i,y,rand()%15+1,s);
127
      }
128
      s[0] = c;
129
      puts_xy(i,y,rand()%15+1,s);
130
 
131
      task_endcycle();
132
 
133
      puts_xy(i,y,WHITE," ");
134
      i++;
135
    }
136
  }
137
}
138
 
139
TASK aster()
140
{
141
  PID p;
142
 
143
  HARD_TASK_MODEL m;
144
  int r;
145
  int x; // adaptive bandwidth...
146
 
147
  hard_task_default_model(m);
148
  hard_task_def_wcet(m,PER_WCET);
149
  hard_task_def_ctrl_jet(m);
150
 
151
  x = MIN_PERIOD;
152
 
153
  srand(7);
154
  while (1) {
155
    if (num_aster < ASTER_MAX) {
156
      r = (rand() % 200);
157
 
158
      hard_task_def_arg(m,(void *)((rand() % 7)+1));
159
      hard_task_def_mit(m, (x+r)*1000);
160
      p = task_create("aaa",asteroide,&m,NULL);
161
      if (p == -1)
162
        {
163
          if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
1119 pj 164
          printf_xy(62,3,WHITE,"adapt=%3u err=%d",
165
                    iq_query_first(&freedesc),errno);
1099 pj 166
        }
167
      else {
168
        num_aster++;
169
        printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
170
        task_activate(p);
171
        x /= 2;
172
        if (x<50) x = 50;
173
      }
174
    }
175
    task_endcycle();
176
  }
177
}
178
 
179
TASK clock()
180
{
181
  int s = 0, m = 0;
182
 
183
  while(1) {
184
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
1388 giacomo 185
    printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(1));
1099 pj 186
    task_endcycle();
187
 
188
    if (++s > 59) {
189
      s = 0;
190
      m++;
191
    }
192
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
1388 giacomo 193
    printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(1));
1099 pj 194
    task_endcycle();
195
  }
196
}
197
 
198
 
199
 
200
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
201
   and plot on the screen the elapsed times... */
202
TASK jetcontrol()
203
{
204
  int i;  /* a counter */
205
  TIME sum, max, curr, last[5];
206
  int nact;
207
  int j; /* the elements set by jet_gettable */
208
  PID p;
209
 
210
 
211
  kern_cli();
212
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
213
  kern_sti();
214
 
215
  for (;;) {
216
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
217
      if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
218
 
219
      for (j=0; j<5; j++) last[j] = 0;
220
      jet_gettable(p, &last[0], 5);
221
      kern_cli();
222
      printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
223
                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]);
224
      kern_sti();
225
      i++;
226
    }
227
    task_endcycle();
228
  }
229
}
230
 
231
int main(int argc, char **argv)
232
{
233
  PID p1,p2;//,p3,p4,p5,p6;
234
  HARD_TASK_MODEL m;
235
  NRT_TASK_MODEL m_nrt;
236
  SOFT_TASK_MODEL m_aper;
237
  int i;
238
 
239
  clear();
240
 
241
  hard_task_default_model(m);
242
  hard_task_def_wcet(m,ASTER_WCET);
243
  hard_task_def_mit(m,10000);
244
  hard_task_def_group(m,1);
245
  hard_task_def_ctrl_jet(m);
246
 
247
  nrt_task_default_model(m_nrt);
248
  nrt_task_def_group(m_nrt,1);
249
  nrt_task_def_ctrl_jet(m_nrt);
250
 
251
  p1 = task_create("Aster",aster,&m,NULL);
252
  if (p1 == -1) {
1577 tullio 253
    sys_shutdown_message("aster3.c(main): Could not create task <aster> ...");
1547 pj 254
    exit(1);
1099 pj 255
  }
256
 
257
  hard_task_def_mit(m,500000);
258
  hard_task_def_wcet(m,CLOCK_WCET);
259
  p2 = task_create("Clock",clock,&m,NULL);
260
  if (p2 == -1) {
1577 tullio 261
    sys_shutdown_message("aster3.c(main): Could not create task <Clock> ...");
1547 pj 262
    exit(1);
1099 pj 263
  }
264
 
265
  soft_task_default_model(m_aper);
266
  soft_task_def_wcet(m_aper,APER_WCET);
267
  soft_task_def_ctrl_jet(m_aper);
268
  soft_task_def_aperiodic(m_aper);
269
 
1388 giacomo 270
  soft_task_def_level(m_aper, 3);
1099 pj 271
  aper_table[0] = task_create("JetControl",jetcontrol,&m_aper,NULL);
272
  if (aper_table[0] == -1) {
1577 tullio 273
    sys_shutdown_message("aster3.c(main): Could not create task <JetControl> ...");
1547 pj 274
    exit(1);
1099 pj 275
  }
1587 tullio 276
 
277
        char st[80];
1099 pj 278
 
279
  for (i=1; i<APER_MAX; i++) {
1597 tullio 280
    soft_task_def_level(m_aper, i/4 + 2);
1099 pj 281
    soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±'));
282
    aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
283
    if (aper_table[i] == -1) {
1587 tullio 284
                        sprintf(st, "aster3.c(main): Could not create task <aper> #%d...", i);
285
      sys_shutdown_message(st);
1547 pj 286
      exit(1);
1099 pj 287
    }
288
  }
289
 
290
 
291
  group_activate(1);
292
 
293
  {
294
    struct timespec t;
295
    do {
296
      sys_gettime(&t);
297
    } while (t.tv_sec < 60);
298
  }
299
 
1547 pj 300
  exit(0);
1099 pj 301
  return 0;
302
}
303