Subversion Repositories shark

Rev

Details | 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: test7.ori,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 7:
27
 
28
 this is a part of the classic Hartik demo Aster.
29
 
30
 It checks:
31
 - jet functions
32
 - The EDF level with many task, with almost full bandwidth used
33
 
34
**/
35
 
36
/*
37
 * Copyright (C) 2000 Paolo Gai
38
 *
39
 * This program is free software; you can redistribute it and/or modify
40
 * it under the terms of the GNU General Public License as published by
41
 * the Free Software Foundation; either version 2 of the License, or
42
 * (at your option) any later version.
43
 *
44
 * This program is distributed in the hope that it will be useful,
45
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47
 * GNU General Public License for more details.
48
 *
49
 * You should have received a copy of the GNU General Public License
50
 * along with this program; if not, write to the Free Software
51
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
52
 *
53
 */
54
 
55
#include "kernel/kern.h"
56
#include "modules//edf.h"
57
 
58
int num_aster = 0;
59
#define ASTER_LIM	60
60
#define DISPLAY_MAX     15
61
#define ASTER_MAX       70
62
#define STAT_Y           9
63
 
64
//#define PER_WCET      6200
65
//#define CLOCK_WCET     100
66
//#define ASTER_WCET     100
67
#define PER_WCET      20000
68
#define CLOCK_WCET     1000
69
#define ASTER_WCET     1000
70
 
71
TASK asteroide(void)
72
{
73
    int i;
74
    int y = rand() % 7 + 1;
75
 
76
    int load1,j;
77
 
78
    char s[2];
79
 
80
    s[0] = '*'; s[1] = 0;
81
 
82
    /*for (;;)*/ {
83
      i = 1;
84
      while (i < ASTER_LIM) {
85
        load1 = 10000; // 5000 + rand()%5000;
86
        for (j=0; j<load1; j++) {
87
          s[0] = '*' + rand() % 100;
88
          puts_xy(i,y,rand()%15+1,s);
89
        }
90
 
91
	task_endcycle();
92
 
93
	puts_xy(i,y,WHITE," ");
94
	i++;
95
      }
96
    }
97
    num_aster--;
98
    return 0;
99
}
100
 
101
TASK aster()
102
{
103
    PID p;
104
 
105
    HARD_TASK_MODEL m;
106
    int r;
107
    int x; // adaptive bandwidth...
108
 
109
    hard_task_default_model(m);
110
    hard_task_def_wcet(m,PER_WCET);
111
    hard_task_def_ctrl_jet(m);
112
 
113
    x = 64;
114
 
115
    srand(7);
116
    while (1) {
117
	if (num_aster < ASTER_MAX) {
118
	    r = (rand() % 200);
119
 
120
	    hard_task_def_arg(m,(void *)((rand() % 7)+1));
121
	    hard_task_def_mit(m, (x+r)*1000);
122
	    p = task_create("aaa",asteroide,&m,NULL);
123
	    if (p == -1)
124
            {
125
              if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
126
              printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
127
            }
128
            else {
129
              num_aster++;
130
              printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
131
              task_activate(p);
132
              x /= 2;
133
              if (x<50) x = 50;
134
            }
135
	}
136
        task_endcycle();
137
    }
138
}
139
 
140
TASK clock()
141
{
142
    int s = 0, m = 0;
143
 
144
    while(1) {
145
	printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
146
	printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
147
	task_endcycle();
148
 
149
	if (++s > 59) {
150
	    s = 0;
151
	    m++;
152
	}
153
	printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
154
	printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
155
	task_endcycle();
156
    }
157
}
158
 
159
 
160
 
161
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
162
   and plot on the screen the elapsed times... */
163
TASK jetcontrol()
164
{
165
  int i;  /* a counter */
166
  TIME sum, max, curr, last[5];
167
  int nact;
168
  int j; /* the elements set by jet_gettable */
169
  PID p;
170
 
171
 
172
  kern_cli();
173
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
174
  kern_sti();
175
 
176
  for (;;) {
177
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
178
       if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
179
 
180
       for (j=0; j<5; j++) last[j] = 0;
181
       jet_gettable(p, &last[0], 5);
182
       kern_cli();
183
       printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
184
                 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]);
185
       kern_sti();
186
       i++;
187
    }
188
  }
189
}
190
 
191
int main(int argc, char **argv)
192
{
193
    PID p1,p2,p3; //,p4,p5,p6;
194
    HARD_TASK_MODEL m;
195
    NRT_TASK_MODEL m_nrt;
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
	exit(-1);
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) {
218
	perror("test7.c(main): Could not create task <Clock> ...");
219
	sys_end();
220
	exit(-1);
221
    }
222
 
223
    p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
224
    if (p2 == -1) {
225
	perror("test7.c(main): Could not create task <JetControl> ...");
226
	sys_end();
227
	exit(-1);
228
    }
229
 
230
    group_activate(1);
231
 
232
    {
233
      struct timespec t;
234
      do {
235
        kern_cli();
236
        ll_gettime(TIME_EXACT, &t);
237
        kern_sti();
238
      } while (t.tv_sec < 6);
239
    }
240
    //sys_status(SCHED_STATUS);
241
    sys_end();
242
    return 0;
243
}
244