Subversion Repositories shark

Rev

Go to most recent revision | 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: perf2.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
 Performance Test 2:
27
 
28
 This test tries to measure the time spent into the event handlers.
29
 It is based on test D.
30
 
31
 WARNING: the symbol __PERF_TEST2__ must be defined into the file
32
 kernel/config.h
33
 
34
 
35
**/
36
 
37
/*
38
 * Copyright (C) 2000 Paolo Gai
39
 *
40
 * This program is free software; you can redistribute it and/or modify
41
 * it under the terms of the GNU General Public License as published by
42
 * the Free Software Foundation; either version 2 of the License, or
43
 * (at your option) any later version.
44
 *
45
 * This program is distributed in the hope that it will be useful,
46
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
48
 * GNU General Public License for more details.
49
 *
50
 * You should have received a copy of the GNU General Public License
51
 * along with this program; if not, write to the Free Software
52
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
53
 *
54
 */
55
 
56
#include "kernel/kern.h"
57
#include "modules/edf.h"
58
#include "modules/cbs.h"
59
 
60
int num_aster = 0;
61
#define ASTER_LIM       60
62
#define DISPLAY_MAX     15
63
#define ASTER_MAX       70
64
#define STAT_Y           9
65
 
66
#define PER_MAX          5
67
#define APER_MAX         8
68
 
69
#define PER_WCET      8200
70
#define APER_WCET    20400
71
#define CLOCK_WCET    1600
72
#define ASTER_WCET    1600
73
#define SOFT_MET      3300
74
 
75
#define APER_REP     22000
76
 
77
PID aper_table[APER_MAX];
78
 
79
int shutting_down = 0;
80
 
81
TASK asteroide(void)
82
{
83
    int i;
84
    int y = rand() % 7 + 1;
85
 
86
    int load1,j;
87
 
88
    char s[2];
89
 
90
    s[0] = '*'; s[1] = 0;
91
 
92
    for (;;) {
93
      i = 1;
94
      while (i < ASTER_LIM) {
95
        load1 = 10000; //8000 + rand()%2000;
96
        for (j=0; j<load1; j++) {
97
          s[0] = '*' + rand() % 100;
98
          puts_xy(i,y,rand()%15+1,s);
99
        }
100
 
101
        task_activate(aper_table[rand()%APER_MAX]);
102
        task_endcycle();
103
 
104
        puts_xy(i,y,WHITE," ");
105
        i++;
106
      }
107
    }
108
    //num_aster--;
109
}
110
 
111
TASK aper_asteroid(void *a)
112
{
113
    int i;
114
    int y = rand() % 7 + 1;
115
 
116
    int load1,j;
117
    int c;
118
 
119
    char s[2];
120
 
121
    c = (int)a;
122
    s[0] = '*'; s[1] = 0;
123
 
124
    for (;;) {
125
      i = 1;
126
      while (i < ASTER_LIM) {
127
        load1 = APER_REP; //8000 + rand()%2000;
128
        for (j=0; j<load1; j++) {
129
          s[0] = '*' + rand() % 100;
130
          puts_xy(i,y,rand()%15+1,s);
131
        }
132
        s[0] = c;
133
        puts_xy(i,y,rand()%15+1,s);
134
 
135
        if (shutting_down) {
136
          kern_printf("±%d±",exec_shadow);
137
          return 0;
138
        }
139
 
140
        task_endcycle();
141
 
142
        puts_xy(i,y,WHITE," ");
143
        i++;
144
      }
145
    }
146
}
147
 
148
TASK soft_aster(void)
149
{
150
    int i;
151
    int y = rand() % 7 + 1;
152
 
153
    int load1,j;
154
 
155
    char s[2];
156
 
157
    s[0] = '*'; s[1] = 0;
158
 
159
    /*for (;;)*/ {
160
      i = 1;
161
      while (i < ASTER_LIM) {
162
        load1 = 1000 + rand()%9000;
163
        for (j=0; j<load1; j++) {
164
          s[0] = '*' + rand() % 100;
165
          puts_xy(i,y,rand()%15+1,s);
166
        }
167
        s[0] = 1;
168
        puts_xy(i,y,rand()%15+1,s);
169
 
170
        task_activate(aper_table[rand()%APER_MAX]);
171
        task_endcycle();
172
 
173
        puts_xy(i,y,WHITE," ");
174
        i++;
175
      }
176
    }
177
    num_aster--;
178
    return 0;
179
}
180
 
181
TASK aster()
182
{
183
    PID p;
184
 
185
    HARD_TASK_MODEL m;
186
    SOFT_TASK_MODEL m_soft;
187
    int r;
188
    int x; // adaptive bandwidth...
189
 
190
    srand(7);
191
 
192
    hard_task_default_model(m);
193
    hard_task_def_wcet(m,PER_WCET);
194
    hard_task_def_ctrl_jet(m);
195
    for (x=0; x<PER_MAX; x++) {
196
      r = (rand() % 200);
197
      hard_task_def_mit(m, (64+r)*1000);
198
      p = task_create("per",asteroide,&m,NULL);
199
      if (p!=-1) task_activate(p);
200
    }
201
 
202
    soft_task_default_model(m_soft);
203
    soft_task_def_met(m_soft,SOFT_MET);
204
    soft_task_def_ctrl_jet(m_soft);
205
 
206
    x = 64;
207
 
208
    while (1) {
209
        if (num_aster < ASTER_MAX) {
210
            r = (rand() % 200);
211
 
212
            soft_task_def_period(m_soft, (x+r)*1000);
213
            p = task_create("aaa",soft_aster,&m_soft,NULL);
214
            if (p == -1)
215
            {
216
              if (x < 500 && errno != ENO_AVAIL_TASK)  x += 1;
217
              printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
218
            }
219
            else {
220
              num_aster++;
221
              printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
222
              task_activate(p);
223
              x /= 2;
224
              if (x<50) x = 50;
225
            }
226
        }
227
        task_endcycle();
228
    }
229
}
230
 
231
TASK clock()
232
{
233
    int s = 0, m = 0;
234
 
235
    while(1) {
236
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
237
        printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
238
        printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
239
        task_endcycle();
240
 
241
        if (++s > 59) {
242
            s = 0;
243
            m++;
244
        }
245
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
246
        printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
247
        printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
248
        task_endcycle();
249
    }
250
}
251
 
252
 
253
 
254
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
255
   and plot on the screen the elapsed times... */
256
TASK jetcontrol()
257
{
258
  int i;  /* a counter */
259
  TIME sum, max, curr, last[5];
260
  int nact;
261
  int j; /* the elements set by jet_gettable */
262
  PID p;
263
 
264
 
265
  kern_cli();
266
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
267
  kern_sti();
268
 
269
  for (;;) {
270
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
271
       if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 ||
272
           (proc_table[p].pclass & 0xFF00) == HARD_PCLASS) continue;
273
 
274
       for (j=0; j<5; j++) last[j] = 0;
275
       jet_gettable(p, &last[0], 5);
276
       kern_cli();
277
       if (proc_table[p].task_level == 4)
278
         printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
279
                   p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)CBS_get_nact(4,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
280
       else
281
         printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
282
                   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]);
283
       kern_sti();
284
       i++;
285
    }
286
  }
287
}
288
 
289
void fine()
290
{
291
  sys_end();
292
}
293
 
294
void exiting(void *arg)
295
{
296
  kern_printf("EXITING");
297
  shutting_down = 1;
298
}
299
 
300
TIME perftime_prol[10001];
301
TIME perftime_epil[10001];
302
int  perftime_count = 0;
303
 
304
void perftest_stat(void *arg)
305
{
306
  int i;
307
  TIME d, sum=0, max=0;
308
 
309
  for (i=0; i<9000; i++) {
310
    d = perftime_epil[i]-perftime_prol[i];
311
    sum += d;
312
    if (max < d) max = d;
313
    kern_printf("Û%ld %ldÛ",perftime_epil[i],perftime_prol[i]);
314
  }
315
  kern_printf("\n°°° perftime_count=%u sum=%lu max=%lu   °°°\n",perftime_count, sum, max);
316
}
317
 
318
int main(int argc, char **argv)
319
{
320
    PID p1,p2,p3; //,p4,p5,p6;
321
    HARD_TASK_MODEL m;
322
//    NRT_TASK_MODEL m_nrt;
323
    SOFT_TASK_MODEL m_aper;
324
    SOFT_TASK_MODEL m_soft;
325
    int i;
326
    struct timespec fineprg;
327
 
328
    kern_cli();
329
 
330
    kern_sti();
331
 
332
    sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN);
333
    sys_atrunlevel(perftest_stat, NULL, RUNLEVEL_BEFORE_EXIT);
334
 
335
    hard_task_default_model(m);
336
    hard_task_def_wcet(m,ASTER_WCET);
337
    hard_task_def_mit(m,10000);
338
    hard_task_def_group(m,1);
339
    hard_task_def_ctrl_jet(m);
340
 
341
//    nrt_task_default_model(m_nrt);
342
//    nrt_task_def_group(m_nrt,1);
343
//    nrt_task_def_ctrl_jet(m_nrt);
344
 
345
    soft_task_default_model(m_soft);
346
    soft_task_def_met(m_soft,1000);
347
    soft_task_def_period(m_soft,100000);
348
    soft_task_def_group(m_soft,1);
349
    soft_task_def_ctrl_jet(m_soft);
350
    soft_task_def_aperiodic(m_soft);
351
 
352
 
353
    p1 = task_create("Aster",aster,&m,NULL);
354
    if (p1 == -1) {
355
        perror("test7.c(main): Could not create task <aster> ...");
356
        sys_end();
357
        l1_exit(-1);
358
    }
359
 
360
    hard_task_def_mit(m,500000);
361
    hard_task_def_wcet(m,CLOCK_WCET);
362
    p2 = task_create("Clock",clock,&m,NULL);
363
    if (p2 == -1) {
364
        perror("test7.c(main): Could not create task <Clock> ...");
365
        sys_end();
366
        l1_exit(-1);
367
    }
368
 
369
//    p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
370
    p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
371
    if (p3 == -1) {
372
        perror("test7.c(main): Could not create task <JetControl> ...");
373
        sys_end();
374
        l1_exit(-1);
375
    }
376
 
377
    soft_task_default_model(m_aper);
378
    soft_task_def_wcet(m_aper,APER_WCET);
379
    soft_task_def_ctrl_jet(m_aper);
380
    soft_task_def_system(m_aper);
381
    soft_task_def_aperiodic(m_aper);
382
 
383
    for (i=0; i<APER_MAX; i++) {
384
      soft_task_def_level(m_aper, i/4 + 2);
385
      soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±'));
386
      aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
387
      if (aper_table[i] == -1) {
388
        perror("test7.c(main): Could not create task <aper> ...");
389
        sys_end();
390
        l1_exit(-1);
391
      }
392
    }
393
 
394
    task_nopreempt();
395
    fineprg.tv_sec = 60;
396
    fineprg.tv_nsec = 0;
397
    kern_event_post(&fineprg,fine,NULL);
398
    group_activate(1);
399
    return 0;
400
}
401