Subversion Repositories shark

Rev

Rev 1119 | Go to most recent revision | Details | 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
 *
37
 * CVS :        $Id: aster3.c,v 1.1 2002-10-28 08:13:37 pj Exp $
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"
55
#include "modules//edf.h"
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 */
67
#define APER_WCET    50000 /* 18400 */
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;
164
          printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
165
        }
166
      else {
167
        num_aster++;
168
        printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
169
        task_activate(p);
170
        x /= 2;
171
        if (x<50) x = 50;
172
      }
173
    }
174
    task_endcycle();
175
  }
176
}
177
 
178
TASK clock()
179
{
180
  int s = 0, m = 0;
181
 
182
  while(1) {
183
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
184
    printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
185
    task_endcycle();
186
 
187
    if (++s > 59) {
188
      s = 0;
189
      m++;
190
    }
191
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
192
    printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
193
    task_endcycle();
194
  }
195
}
196
 
197
 
198
 
199
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
200
   and plot on the screen the elapsed times... */
201
TASK jetcontrol()
202
{
203
  int i;  /* a counter */
204
  TIME sum, max, curr, last[5];
205
  int nact;
206
  int j; /* the elements set by jet_gettable */
207
  PID p;
208
 
209
 
210
  kern_cli();
211
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
212
  kern_sti();
213
 
214
  for (;;) {
215
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
216
      if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
217
 
218
      for (j=0; j<5; j++) last[j] = 0;
219
      jet_gettable(p, &last[0], 5);
220
      kern_cli();
221
      printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
222
                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]);
223
      kern_sti();
224
      i++;
225
    }
226
    task_endcycle();
227
  }
228
}
229
 
230
int main(int argc, char **argv)
231
{
232
  PID p1,p2;//,p3,p4,p5,p6;
233
  HARD_TASK_MODEL m;
234
  NRT_TASK_MODEL m_nrt;
235
  SOFT_TASK_MODEL m_aper;
236
  int i;
237
 
238
  clear();
239
 
240
  set_exchandler_grx();
241
 
242
  hard_task_default_model(m);
243
  hard_task_def_wcet(m,ASTER_WCET);
244
  hard_task_def_mit(m,10000);
245
  hard_task_def_group(m,1);
246
  hard_task_def_ctrl_jet(m);
247
 
248
  nrt_task_default_model(m_nrt);
249
  nrt_task_def_group(m_nrt,1);
250
  nrt_task_def_ctrl_jet(m_nrt);
251
 
252
  p1 = task_create("Aster",aster,&m,NULL);
253
  if (p1 == -1) {
254
    perror("test7.c(main): Could not create task <aster> ...");
255
    sys_end();
256
  }
257
 
258
  hard_task_def_mit(m,500000);
259
  hard_task_def_wcet(m,CLOCK_WCET);
260
  p2 = task_create("Clock",clock,&m,NULL);
261
  if (p2 == -1) {
262
    perror("test7.c(main): Could not create task <Clock> ...");
263
    sys_end();
264
  }
265
 
266
  soft_task_default_model(m_aper);
267
  soft_task_def_wcet(m_aper,APER_WCET);
268
  soft_task_def_ctrl_jet(m_aper);
269
  soft_task_def_aperiodic(m_aper);
270
 
271
  soft_task_def_level(m_aper, 2);
272
  aper_table[0] = task_create("JetControl",jetcontrol,&m_aper,NULL);
273
  if (aper_table[0] == -1) {
274
    perror("test7.c(main): Could not create task <JetControl> ...");
275
    sys_end();
276
  }
277
 
278
  for (i=1; i<APER_MAX; i++) {
279
    soft_task_def_level(m_aper, i/4 + 2);
280
    soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±'));
281
    aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
282
    if (aper_table[i] == -1) {
283
      perror("test7.c(main): Could not create task <aper> ...");
284
      sys_end();
285
    }
286
  }
287
 
288
 
289
  group_activate(1);
290
 
291
  {
292
    struct timespec t;
293
    do {
294
      sys_gettime(&t);
295
    } while (t.tv_sec < 60);
296
  }
297
 
298
  sys_end();
299
  return 0;
300
}
301