Subversion Repositories shark

Rev

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