Subversion Repositories shark

Rev

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