Subversion Repositories shark

Rev

Rev 1085 | Details | Compare with Previous | 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: testa.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 10 (A):
27
 
28
 this is a part of the classic Hartik demo Aster.
29
 
30
 it is based on test 7, with the use of TBS to serve a set of aperiodic
31
 tasks.
32
 
33
 There are APER_MAX tasks sleeping, and when an asteroide task finish
34
 the current activation, it activate also an aperiodic task chosen
35
 randomly (if the task chosen is already active, the task_activate do
36
 nothing!)
37
 
38
 
39
**/
40
 
41
/*
42
 * Copyright (C) 2000 Paolo Gai
43
 *
44
 * This program is free software; you can redistribute it and/or modify
45
 * it under the terms of the GNU General Public License as published by
46
 * the Free Software Foundation; either version 2 of the License, or
47
 * (at your option) any later version.
48
 *
49
 * This program is distributed in the hope that it will be useful,
50
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
51
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
52
 * GNU General Public License for more details.
53
 *
54
 * You should have received a copy of the GNU General Public License
55
 * along with this program; if not, write to the Free Software
56
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
57
 *
58
 */
59
 
60
#include "kernel/kern.h"
61
#include "modules//edf.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 APER_MAX         8
70
 
71
#define PER_WCET      6200
72
#define APER_WCET    18400
73
#define CLOCK_WCET     200
74
#define ASTER_WCET     200
75
 
76
#define APER_REP     22000
77
 
78
PID aper_table[APER_MAX];
79
 
80
TASK asteroide(void)
81
{
82
    int i;
83
    int y = rand() % 7 + 1;
84
 
85
    int load1,j;
86
 
87
    char s[2];
88
 
89
    s[0] = '*'; s[1] = 0;
90
 
91
    /*for (;;)*/ {
92
      i = 1;
93
      while (i < ASTER_LIM) {
94
        load1 = 10000; //8000 + rand()%2000;
95
        for (j=0; j<load1; j++) {
96
          s[0] = '*' + rand() % 100;
97
          puts_xy(i,y,rand()%15+1,s);
98
        }
99
 
100
        task_activate(aper_table[rand()%APER_MAX]);
101
        task_endcycle();
102
 
103
        puts_xy(i,y,WHITE," ");
104
        i++;
105
      }
106
    }
107
    num_aster--;
108
    return 0;
109
}
110
 
111
TASK aper_asteroid(void *a)
112
{
113
    int i;
114
    int y = rand() % 7 + 1;
115
 
116
    int load1,j;
117
    int c;
118
 
119
    char s[2];
120
 
121
    c = (int)a;
122
    s[0] = '*'; s[1] = 0;
123
 
124
    for (;;) {
125
      i = 1;
126
      while (i < ASTER_LIM) {
127
        load1 = APER_REP; //8000 + rand()%2000;
128
        for (j=0; j<load1; j++) {
129
          s[0] = '*' + rand() % 100;
130
          puts_xy(i,y,rand()%15+1,s);
131
        }
132
        s[0] = c;
133
        puts_xy(i,y,rand()%15+1,s);
134
 
135
        task_endcycle();
136
 
137
        puts_xy(i,y,WHITE," ");
138
        i++;
139
      }
140
    }
141
}
142
 
143
TASK aster()
144
{
145
    PID p;
146
 
147
    HARD_TASK_MODEL m;
148
    int r;
149
    int x; // adaptive bandwidth...
150
 
151
    hard_task_default_model(m);
152
    hard_task_def_wcet(m,PER_WCET);
153
    hard_task_def_ctrl_jet(m);
154
 
155
    x = 64;
156
 
157
    srand(7);
158
    while (1) {
159
        if (num_aster < ASTER_MAX) {
160
            r = (rand() % 200);
161
 
162
            hard_task_def_arg(m,(void *)((rand() % 7)+1));
163
            hard_task_def_mit(m, (x+r)*1000);
164
            p = task_create("aaa",asteroide,&m,NULL);
165
            if (p == -1)
166
            {
167
              if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
168
              printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
169
            }
170
            else {
171
              num_aster++;
172
              printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
173
              task_activate(p);
174
              x /= 2;
175
              if (x<50) x = 50;
176
            }
177
        }
178
        task_endcycle();
179
    }
180
}
181
 
182
TASK clock()
183
{
184
    int s = 0, m = 0;
185
 
186
    while(1) {
187
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
188
        printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
189
        task_endcycle();
190
 
191
        if (++s > 59) {
192
            s = 0;
193
            m++;
194
        }
195
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
196
        printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
197
        task_endcycle();
198
    }
199
}
200
 
201
 
202
 
203
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
204
   and plot on the screen the elapsed times... */
205
TASK jetcontrol()
206
{
207
  int i;  /* a counter */
208
  TIME sum, max, curr, last[5];
209
  int nact;
210
  int j; /* the elements set by jet_gettable */
211
  PID p;
212
 
213
 
214
  kern_cli();
215
  printf_xy(0,STAT_Y,WHITE,"PID  Mean T. Max T.  N.A.  Curr.    Last1  Last2  Last3  Last4  Last5");
216
  kern_sti();
217
 
218
  for (;;) {
219
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
220
       if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
221
 
222
       for (j=0; j<5; j++) last[j] = 0;
223
       jet_gettable(p, &last[0], 5);
224
       kern_cli();
225
       printf_xy(0,STAT_Y+i+1,WHITE,"%-3d  %-6d  %-6d  %-4d  %-7d  %-5d  %-5d  %-5d  %-5d  %-5d",
226
                 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]);
227
       kern_sti();
228
       i++;
229
    }
230
    task_endcycle();
231
  }
232
}
233
 
234
int main(int argc, char **argv)
235
{
236
    PID p1,p2;//,p3,p4,p5,p6;
237
    HARD_TASK_MODEL m;
238
    NRT_TASK_MODEL m_nrt;
239
    SOFT_TASK_MODEL m_aper;
240
    int i;
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
        l1_exit(-1);
257
    }
258
 
259
    hard_task_def_mit(m,500000);
260
    hard_task_def_wcet(m,CLOCK_WCET);
261
    p2 = task_create("Clock",clock,&m,NULL);
262
    if (p2 == -1) {
263
        perror("test7.c(main): Could not create task <Clock> ...");
264
        sys_end();
265
        l1_exit(-1);
266
    }
267
 
268
    soft_task_default_model(m_aper);
269
    soft_task_def_wcet(m_aper,APER_WCET);
270
    soft_task_def_ctrl_jet(m_aper);
271
    soft_task_def_system(m_aper);
272
    soft_task_def_aperiodic(m_aper);
273
 
274
    soft_task_def_level(m_aper, 2);
275
    aper_table[0] = task_create("JetControl",jetcontrol,&m_aper,NULL);
276
    if (aper_table[0] == -1) {
277
        perror("test7.c(main): Could not create task <JetControl> ...");
278
        sys_end();
279
        l1_exit(-1);
280
    }
281
 
282
    for (i=1; i<APER_MAX; i++) {
283
      soft_task_def_level(m_aper, i/4 + 2);
284
      soft_task_def_arg(m_aper, (void *)(i/4 ? '' : ''));
285
      aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
286
      if (aper_table[i] == -1) {
287
        perror("test7.c(main): Could not create task <aper> ...");
288
        sys_end();
289
        l1_exit(-1);
290
      }
291
    }
292
 
293
 
294
    group_activate(1);
295
 
296
    {
297
      struct timespec t;
298
      do {
299
        kern_cli();
300
        ll_gettime(TIME_EXACT, &t);
301
        kern_sti();
302
      } while (t.tv_sec < 6);
303
    }
304
    //sys_status(SCHED_STATUS);
305
    sys_end();
306
    return 0;
307
}
308