Subversion Repositories shark

Rev

Rev 1119 | Go to most recent revision | Details | 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
 *
37
 * CVS :        $Id: aster2.c,v 1.1 2002-10-28 08:13:37 pj Exp $
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"
49
#include "modules//edf.h"
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;
123
          printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
124
        }
125
      else {
126
        num_aster++;
127
        printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
128
        task_activate(p);
129
        x /= 2;
130
        if (x<50) x = 50;
131
      }
132
    }
133
    task_endcycle();
134
  }
135
}
136
 
137
TASK clock()
138
{
139
  int s = 0, m = 0;
140
 
141
  while(1) {
142
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
143
    printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
144
    task_endcycle();
145
 
146
    if (++s > 59) {
147
      s = 0;
148
      m++;
149
    }
150
    printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
151
    printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
152
    task_endcycle();
153
  }
154
}
155
 
156
 
157
 
158
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
159
   and plot on the screen the elapsed times... */
160
TASK jetcontrol()
161
{
162
  int i;  /* a counter */
163
  TIME sum, max, curr, last[5];
164
  int nact;
165
  int j; /* the elements set by jet_gettable */
166
  PID p;
167
 
168
 
169
  kern_cli();
170
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
171
  kern_sti();
172
 
173
  for (;;) {
174
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
175
      if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
176
 
177
      for (j=0; j<5; j++) last[j] = 0;
178
      jet_gettable(p, &last[0], 5);
179
      kern_cli();
180
      printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
181
                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]);
182
      kern_sti();
183
      i++;
184
    }
185
  }
186
}
187
 
188
int main(int argc, char **argv)
189
{
190
  PID p1,p2,p3; //,p4,p5,p6;
191
  HARD_TASK_MODEL m;
192
  NRT_TASK_MODEL m_nrt;
193
  struct timespec t;
194
 
195
  clear();
196
 
197
  hard_task_default_model(m);
198
  hard_task_def_wcet(m,ASTER_WCET);
199
  hard_task_def_mit(m,10000);
200
  hard_task_def_group(m,1);
201
  hard_task_def_ctrl_jet(m);
202
 
203
  nrt_task_default_model(m_nrt);
204
  nrt_task_def_group(m_nrt,1);
205
  nrt_task_def_ctrl_jet(m_nrt);
206
 
207
  p1 = task_create("Aster",aster,&m,NULL);
208
  if (p1 == -1) {
209
    perror("test7.c(main): Could not create task <aster> ...");
210
    sys_end();
211
  }
212
 
213
  hard_task_def_mit(m,500000);
214
  hard_task_def_wcet(m,CLOCK_WCET);
215
  p2 = task_create("Clock",clock,&m,NULL);
216
  if (p2 == -1) {
217
    perror("test7.c(main): Could not create task <Clock> ...");
218
    sys_end();
219
  }
220
 
221
  p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
222
  if (p2 == -1) {
223
    perror("test7.c(main): Could not create task <JetControl> ...");
224
    sys_end();
225
  }
226
 
227
  group_activate(1);
228
 
229
  do {
230
    sys_gettime(&t);
231
  } while (t.tv_sec < END_TEST_TIME);
232
 
233
  sys_end();
234
 
235
  return 0;
236
}
237
 
238
 
239
 
240