Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*
2
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
8
 * (see authors.txt for full list of hartik's authors)
9
 *
10
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
11
 *
12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
/**
18
 ------------
19
 CVS :        $Id: testd.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
20
 
21
 File:        $File$
22
 Revision:    $Revision: 1.1.1.1 $
23
 Last update: $Date: 2002-09-02 09:37:48 $
24
 ------------
25
 
26
 Test Number 13 (D):
27
 
28
 this is a part of the classic Hartik demo Aster.
29
 
30
 it is based on test 10 (A), and use the CBS to serve the periodic tasks.
31
 
32
 There still remain some periodic tasks, that are guaranteed basing on their
33
 wcet.
34
 
35
 It also tests the shutdown...
36
 
37
 
38
**/
39
 
40
/*
41
 * Copyright (C) 2000 Paolo Gai
42
 *
43
 * This program is free software; you can redistribute it and/or modify
44
 * it under the terms of the GNU General Public License as published by
45
 * the Free Software Foundation; either version 2 of the License, or
46
 * (at your option) any later version.
47
 *
48
 * This program is distributed in the hope that it will be useful,
49
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
51
 * GNU General Public License for more details.
52
 *
53
 * You should have received a copy of the GNU General Public License
54
 * along with this program; if not, write to the Free Software
55
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
56
 *
57
 */
58
 
59
#include "kernel/kern.h"
60
#include "modules/edf.h"
61
#include "modules/cbs.h"
62
 
63
int num_aster = 0;
64
#define ASTER_LIM       60
65
#define DISPLAY_MAX     15
66
#define ASTER_MAX       70
67
#define STAT_Y           9
68
 
69
#define PER_MAX          5
70
#define APER_MAX         8
71
 
72
#define PER_WCET     25000
73
#define APER_WCET    53000
74
#define CLOCK_WCET    1000
75
#define ASTER_WCET    1000
76
#define SOFT_MET      6300
77
 
78
#define APER_REP     22000
79
 
80
PID aper_table[APER_MAX];
81
 
82
int shutting_down = 0;
83
 
84
TASK asteroide(void)
85
{
86
    int i;
87
    int y = rand() % 7 + 1;
88
 
89
    int load1,j;
90
 
91
    char s[2];
92
 
93
    s[0] = '*'; s[1] = 0;
94
 
95
    for (;;) {
96
      i = 1;
97
      while (i < ASTER_LIM) {
98
        load1 = 10000; //8000 + rand()%2000;
99
        for (j=0; j<load1; j++) {
100
          s[0] = '*' + rand() % 100;
101
          puts_xy(i,y,rand()%15+1,s);
102
        }
103
 
104
        task_activate(aper_table[rand()%APER_MAX]);
105
        task_endcycle();
106
 
107
        puts_xy(i,y,WHITE," ");
108
        i++;
109
      }
110
    }
111
    //num_aster--;
112
}
113
 
114
TASK aper_asteroid(void *a)
115
{
116
    int i;
117
    int y = rand() % 7 + 1;
118
 
119
    int load1,j;
120
    int c;
121
 
122
    char s[2];
123
 
124
    c = (int)a;
125
    s[0] = '*'; s[1] = 0;
126
 
127
    for (;;) {
128
      i = 1;
129
      while (i < ASTER_LIM) {
130
        load1 = APER_REP; //8000 + rand()%2000;
131
        for (j=0; j<load1; j++) {
132
          s[0] = '*' + rand() % 100;
133
          puts_xy(i,y,rand()%15+1,s);
134
        }
135
        s[0] = c;
136
        puts_xy(i,y,rand()%15+1,s);
137
 
138
        if (shutting_down) {
139
          kern_printf("±%d±",exec_shadow);
140
          return 0;
141
        }
142
 
143
        task_endcycle();
144
 
145
        puts_xy(i,y,WHITE," ");
146
        i++;
147
      }
148
    }
149
}
150
 
151
TASK soft_aster(void)
152
{
153
    int i;
154
    int y = rand() % 7 + 1;
155
 
156
    int load1,j;
157
 
158
    char s[2];
159
 
160
    s[0] = '*'; s[1] = 0;
161
 
162
    /*for (;;)*/ {
163
      i = 1;
164
      while (i < ASTER_LIM) {
165
        load1 = 1000 + rand()%9000;
166
        for (j=0; j<load1; j++) {
167
          s[0] = '*' + rand() % 100;
168
          puts_xy(i,y,rand()%15+1,s);
169
        }
170
        s[0] = 1;
171
        puts_xy(i,y,rand()%15+1,s);
172
 
173
        task_activate(aper_table[rand()%APER_MAX]);
174
        task_endcycle();
175
 
176
        puts_xy(i,y,WHITE," ");
177
        i++;
178
      }
179
    }
180
    num_aster--;
181
    return 0;
182
}
183
 
184
TASK aster()
185
{
186
    PID p;
187
 
188
    HARD_TASK_MODEL m;
189
    SOFT_TASK_MODEL m_soft;
190
    int r;
191
    int x; // adaptive bandwidth...
192
 
193
    srand(7);
194
 
195
    hard_task_default_model(m);
196
    hard_task_def_wcet(m,PER_WCET);
197
    hard_task_def_ctrl_jet(m);
198
    for (x=0; x<PER_MAX; x++) {
199
      r = (rand() % 200);
200
      hard_task_def_mit(m, (64+r)*1000);
201
      p = task_create("per",asteroide,&m,NULL);
202
      if (p!=-1) task_activate(p);
203
    }
204
 
205
    soft_task_default_model(m_soft);
206
    soft_task_def_met(m_soft,SOFT_MET);
207
    soft_task_def_ctrl_jet(m_soft);
208
 
209
    x = 64;
210
 
211
    while (1) {
212
        if (num_aster < ASTER_MAX) {
213
            r = (rand() % 200);
214
 
215
            soft_task_def_period(m_soft, (x+r)*1000);
216
            p = task_create("aaa",soft_aster,&m_soft,NULL);
217
            if (p == -1)
218
            {
219
              if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
220
              printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
221
            }
222
            else {
223
              num_aster++;
224
              printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
225
              task_activate(p);
226
              x /= 2;
227
              if (x<50) x = 50;
228
            }
229
        }
230
        task_endcycle();
231
    }
232
}
233
 
234
TASK clock()
235
{
236
    int s = 0, m = 0;
237
 
238
    while(1) {
239
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
240
        printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
241
        printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
242
        task_endcycle();
243
 
244
        if (++s > 59) {
245
            s = 0;
246
            m++;
247
        }
248
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
249
        printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
250
        printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
251
        task_endcycle();
252
    }
253
}
254
 
255
 
256
 
257
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
258
   and plot on the screen the elapsed times... */
259
TASK jetcontrol()
260
{
261
  int i;  /* a counter */
262
  TIME sum, max, curr, last[5];
263
  int nact;
264
  int j; /* the elements set by jet_gettable */
265
  PID p;
266
 
267
 
268
  kern_cli();
269
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
270
  kern_sti();
271
 
272
  for (;;) {
273
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
274
       if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 ||
275
           (proc_table[p].pclass & 0xFF00) == HARD_PCLASS) continue;
276
 
277
       for (j=0; j<5; j++) last[j] = 0;
278
       jet_gettable(p, &last[0], 5);
279
       kern_cli();
280
       if (proc_table[p].task_level == 4)
281
         printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
282
                   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]);
283
       else
284
         printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
285
                   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]);
286
       kern_sti();
287
       i++;
288
    }
289
  }
290
}
291
 
292
void fine()
293
{
294
  sys_end();
295
}
296
 
297
void exiting(void *arg)
298
{
299
  kern_printf("EXITING");
300
  shutting_down = 1;
301
}
302
 
303
int main(int argc, char **argv)
304
{
305
    PID p1,p2,p3; //,p4,p5,p6;
306
    HARD_TASK_MODEL m;
307
//    NRT_TASK_MODEL m_nrt;
308
    SOFT_TASK_MODEL m_aper;
309
    SOFT_TASK_MODEL m_soft;
310
    int i;
311
    struct timespec fineprg;
312
 
313
    sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN);
314
 
315
    hard_task_default_model(m);
316
    hard_task_def_wcet(m,ASTER_WCET);
317
    hard_task_def_mit(m,10000);
318
    hard_task_def_group(m,1);
319
    hard_task_def_ctrl_jet(m);
320
 
321
//    nrt_task_default_model(m_nrt);
322
//    nrt_task_def_group(m_nrt,1);
323
//    nrt_task_def_ctrl_jet(m_nrt);
324
 
325
    soft_task_default_model(m_soft);
326
    soft_task_def_met(m_soft,1000);
327
    soft_task_def_period(m_soft,100000);
328
    soft_task_def_group(m_soft,1);
329
    soft_task_def_ctrl_jet(m_soft);
330
    soft_task_def_aperiodic(m_soft);
331
 
332
 
333
    p1 = task_create("Aster",aster,&m,NULL);
334
    if (p1 == -1) {
335
        perror("test7.c(main): Could not create task <aster> ...");
336
        sys_end();
337
        l1_exit(-1);
338
    }
339
 
340
    hard_task_def_mit(m,500000);
341
    hard_task_def_wcet(m,CLOCK_WCET);
342
    p2 = task_create("Clock",clock,&m,NULL);
343
    if (p2 == -1) {
344
        perror("test7.c(main): Could not create task <Clock> ...");
345
        sys_end();
346
        l1_exit(-1);
347
    }
348
 
349
//    p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
350
    p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
351
    if (p3 == -1) {
352
        perror("test7.c(main): Could not create task <JetControl> ...");
353
        sys_end();
354
        l1_exit(-1);
355
    }
356
 
357
    soft_task_default_model(m_aper);
358
    soft_task_def_wcet(m_aper,APER_WCET);
359
    soft_task_def_ctrl_jet(m_aper);
360
    soft_task_def_system(m_aper);
361
    soft_task_def_aperiodic(m_aper);
362
 
363
    for (i=0; i<APER_MAX; i++) {
364
      soft_task_def_level(m_aper, i/4 + 2);
365
      soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±'));
366
      aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
367
      if (aper_table[i] == -1) {
368
        perror("test7.c(main): Could not create task <aper> ...");
369
        sys_end();
370
        l1_exit(-1);
371
      }
372
    }
373
 
374
    task_nopreempt();
375
    fineprg.tv_sec = 6;
376
    fineprg.tv_nsec = 0;
377
//    kern_event_post(&fineprg,fine,NULL);
378
    group_activate(1);
379
    return 0;
380
}
381