Subversion Repositories shark

Rev

Rev 1119 | Rev 1388 | Go to most recent revision | Details | Compare with Previous | 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
 *
1377 giacomo 37
 * CVS :        $Id: aster2.c,v 1.3 2004-04-17 11:36:12 giacomo Exp $
1099 pj 38
 
39
 this is a part of the classic Hartik demo Aster.
40
 
41
 It checks:
42
 - jet functions
43
 - The EDF level with many task, with almost full bandwidth used
44
 
45
*/
46
 
47
 
48
#include "kernel/kern.h"
1377 giacomo 49
#include "modules/edf.h"
1099 pj 50
 
51
int num_aster = 0;
52
#define ASTER_LIM       60
53
#define DISPLAY_MAX     15
54
#define ASTER_MAX       70
55
#define STAT_Y           9
56
 
57
// first numbers for wcet and periods are for a 486/25, the others for a 
58
// celeron 366
59
 
60
#define PER_WCET     13000 /*6200*/
61
#define CLOCK_WCET    1200 /* 100*/
62
#define ASTER_WCET    1200 /* 100*/
63
 
64
#define ASTER_MEAN_PERIOD 64 /*64*/
65
 
66
#define END_TEST_TIME  60
67
 
68
TASK asteroide(void)
69
{
70
  int i;
71
  int y = rand() % 7 + 1;
72
 
73
  int load1,j;
74
 
75
  char s[2];
76
 
77
  s[0] = '*'; s[1] = 0;
78
 
79
  /*for (;;)*/ {
80
    i = 1;
81
    while (i < ASTER_LIM) {
82
      load1 = 1000; //10000; // 5000 + rand()%5000;
83
      for (j=0; j<load1; j++) {
84
        s[0] = '*' + rand() % 100;
85
        puts_xy(i,y,rand()%15+1,s);
86
      }
87
 
88
      task_endcycle();
89
 
90
      puts_xy(i,y,WHITE," ");
91
      i++;
92
    }
93
  }
94
  num_aster--;
95
  return 0;
96
}
97
 
98
TASK aster()
99
{
100
  PID p;
101
 
102
  HARD_TASK_MODEL m;
103
  int r;
104
  int x; // adaptive bandwidth...
105
 
106
  hard_task_default_model(m);
107
  hard_task_def_wcet(m,PER_WCET);
108
  hard_task_def_ctrl_jet(m);
109
 
110
  x = ASTER_MEAN_PERIOD;
111
 
112
  srand(7);
113
  while (1) {
114
    if (num_aster < ASTER_MAX) {
115
      r = (rand() % 200);
116
 
117
      hard_task_def_arg(m,(void *)((rand() % 7)+1));
118
      hard_task_def_mit(m, (x+r)*1000);
119
      p = task_create("aaa",asteroide,&m,NULL);
120
      if (p == -1)
121
        {
122
          if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
1119 pj 123
          printf_xy(62,3,WHITE,"adapt=%3u err=%d",
124
                    iq_query_first(&freedesc),errno);
1099 pj 125
        }
126
      else {
127
        num_aster++;
128
        printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
129
        task_activate(p);
130
        x /= 2;
131
        if (x<50) x = 50;
132
      }
133
    }
134
    task_endcycle();
135
  }
136
}
137
 
138
TASK clock()
139
{
140
  int s = 0, m = 0;
141
 
142
  while(1) {
143
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
144
    printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
145
    task_endcycle();
146
 
147
    if (++s > 59) {
148
      s = 0;
149
      m++;
150
    }
151
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
152
    printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
153
    task_endcycle();
154
  }
155
}
156
 
157
 
158
 
159
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
160
   and plot on the screen the elapsed times... */
161
TASK jetcontrol()
162
{
163
  int i;  /* a counter */
164
  TIME sum, max, curr, last[5];
165
  int nact;
166
  int j; /* the elements set by jet_gettable */
167
  PID p;
168
 
169
 
170
  kern_cli();
171
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
172
  kern_sti();
173
 
174
  for (;;) {
175
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
176
      if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
177
 
178
      for (j=0; j<5; j++) last[j] = 0;
179
      jet_gettable(p, &last[0], 5);
180
      kern_cli();
181
      printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
182
                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]);
183
      kern_sti();
184
      i++;
185
    }
186
  }
187
}
188
 
189
int main(int argc, char **argv)
190
{
191
  PID p1,p2,p3; //,p4,p5,p6;
192
  HARD_TASK_MODEL m;
193
  NRT_TASK_MODEL m_nrt;
194
  struct timespec t;
195
 
196
  clear();
197
 
198
  hard_task_default_model(m);
199
  hard_task_def_wcet(m,ASTER_WCET);
200
  hard_task_def_mit(m,10000);
201
  hard_task_def_group(m,1);
202
  hard_task_def_ctrl_jet(m);
203
 
204
  nrt_task_default_model(m_nrt);
205
  nrt_task_def_group(m_nrt,1);
206
  nrt_task_def_ctrl_jet(m_nrt);
207
 
208
  p1 = task_create("Aster",aster,&m,NULL);
209
  if (p1 == -1) {
1377 giacomo 210
    sys_shutdown_message("test7.c(main): Could not create task <aster> ...");
1099 pj 211
    sys_end();
212
  }
213
 
214
  hard_task_def_mit(m,500000);
215
  hard_task_def_wcet(m,CLOCK_WCET);
216
  p2 = task_create("Clock",clock,&m,NULL);
217
  if (p2 == -1) {
1377 giacomo 218
    sys_shutdown_message("test7.c(main): Could not create task <Clock> ...");
1099 pj 219
    sys_end();
220
  }
221
 
222
  p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
223
  if (p2 == -1) {
1377 giacomo 224
    sys_shutdown_message("test7.c(main): Could not create task <JetControl> ...");
1099 pj 225
    sys_end();
226
  }
227
 
228
  group_activate(1);
229
 
230
  do {
231
    sys_gettime(&t);
232
  } while (t.tv_sec < END_TEST_TIME);
233
 
234
  sys_end();
235
 
236
  return 0;
237
}
238
 
239
 
240
 
241