Subversion Repositories shark

Rev

Rev 1085 | Details | Compare with Previous | 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.c,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
// first numbers for wcet and periods are for a 486/25, the others for a 
65
// celeron 366
66
 
67
#define PER_WCET     13000 /*6200*/
68
#define CLOCK_WCET    1200 /* 100*/
69
#define ASTER_WCET    1200 /* 100*/
70
 
71
#define ASTER_MEAN_PERIOD 64 /*64*/
72
 
73
#define END_TEST_TIME  50
74
 
75
TASK asteroide(void)
76
{
77
    int i;
78
    int y = rand() % 7 + 1;
79
 
80
    int load1,j;
81
 
82
    char s[2];
83
 
84
    s[0] = '*'; s[1] = 0;
85
 
86
    /*for (;;)*/ {
87
      i = 1;
88
      while (i < ASTER_LIM) {
89
        load1 = 1000; //10000; // 5000 + rand()%5000;
90
        for (j=0; j<load1; j++) {
91
          s[0] = '*' + rand() % 100;
92
          puts_xy(i,y,rand()%15+1,s);
93
        }
94
 
95
        task_endcycle();
96
 
97
        puts_xy(i,y,WHITE," ");
98
        i++;
99
      }
100
    }
101
    num_aster--;
102
    return 0;
103
}
104
 
105
TASK aster()
106
{
107
    PID p;
108
 
109
    HARD_TASK_MODEL m;
110
    int r;
111
    int x; // adaptive bandwidth...
112
 
113
    hard_task_default_model(m);
114
    hard_task_def_wcet(m,PER_WCET);
115
    hard_task_def_ctrl_jet(m);
116
 
117
    x = ASTER_MEAN_PERIOD;
118
 
119
    srand(7);
120
    while (1) {
121
        if (num_aster < ASTER_MAX) {
122
            r = (rand() % 200);
123
 
124
            hard_task_def_arg(m,(void *)((rand() % 7)+1));
125
            hard_task_def_mit(m, (x+r)*1000);
126
            p = task_create("aaa",asteroide,&m,NULL);
127
            if (p == -1)
128
            {
129
              if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
130
              printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
131
            }
132
            else {
133
              num_aster++;
134
              printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
135
              task_activate(p);
136
              x /= 2;
137
              if (x<50) x = 50;
138
            }
139
        }
140
        task_endcycle();
141
    }
142
}
143
 
144
TASK clock()
145
{
146
    int s = 0, m = 0;
147
 
148
    while(1) {
149
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
150
        printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
151
        task_endcycle();
152
 
153
        if (++s > 59) {
154
            s = 0;
155
            m++;
156
        }
157
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
158
        printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
159
        task_endcycle();
160
    }
161
}
162
 
163
 
164
 
165
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
166
   and plot on the screen the elapsed times... */
167
TASK jetcontrol()
168
{
169
  int i;  /* a counter */
170
  TIME sum, max, curr, last[5];
171
  int nact;
172
  int j; /* the elements set by jet_gettable */
173
  PID p;
174
 
175
 
176
  kern_cli();
177
  printf_xy(0,STAT_Y,WHITE,"PID  Mean T. Max T.  N.A.  Curr.    Last1  Last2  Last3  Last4  Last5");
178
  kern_sti();
179
 
180
  for (;;) {
181
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
182
       if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
183
 
184
       for (j=0; j<5; j++) last[j] = 0;
185
       jet_gettable(p, &last[0], 5);
186
       kern_cli();
187
       printf_xy(0,STAT_Y+i+1,WHITE,"%-3d  %-6d  %-6d  %-4d  %-7d  %-5d  %-5d  %-5d  %-5d  %-5d",
188
                 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]);
189
       kern_sti();
190
       i++;
191
    }
192
  }
193
}
194
 
195
int main(int argc, char **argv)
196
{
197
    PID p1,p2,p3; //,p4,p5,p6;
198
    HARD_TASK_MODEL m;
199
    NRT_TASK_MODEL m_nrt;
200
 
201
    hard_task_default_model(m);
202
    hard_task_def_wcet(m,ASTER_WCET);
203
    hard_task_def_mit(m,10000);
204
    hard_task_def_group(m,1);
205
    hard_task_def_ctrl_jet(m);
206
 
207
    nrt_task_default_model(m_nrt);
208
    nrt_task_def_group(m_nrt,1);
209
    nrt_task_def_ctrl_jet(m_nrt);
210
 
211
    p1 = task_create("Aster",aster,&m,NULL);
212
    if (p1 == -1) {
213
        perror("test7.c(main): Could not create task <aster> ...");
214
        sys_end();
215
        l1_exit(-1);
216
    }
217
 
218
    hard_task_def_mit(m,500000);
219
    hard_task_def_wcet(m,CLOCK_WCET);
220
    p2 = task_create("Clock",clock,&m,NULL);
221
    if (p2 == -1) {
222
        perror("test7.c(main): Could not create task <Clock> ...");
223
        sys_end();
224
        l1_exit(-1);
225
    }
226
 
227
    p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
228
    if (p2 == -1) {
229
        perror("test7.c(main): Could not create task <JetControl> ...");
230
        sys_end();
231
        l1_exit(-1);
232
    }
233
 
234
    group_activate(1);
235
 
236
    {
237
      struct timespec t;
238
      do {
239
        kern_cli();
240
        ll_gettime(TIME_EXACT, &t);
241
        kern_sti();
242
      } while (t.tv_sec < END_TEST_TIME);
243
    }
244
    //sys_status(SCHED_STATUS);
245
    kern_printf("ora chiamo sys_end\n");
246
    sys_end();
247
    kern_printf("ho chiamato sys_end\n");
248
    return 0;
249
}
250
 
251
 
252
 
253