Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1120 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 2002-11-11 08:24:49 pj Exp $
20
 
21
 File:        $File$
22
 Revision:    $Revision: 1.1 $
23
 Last update: $Date: 2002-11-11 08:24:49 $
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",
218
                        iq_query_first(&freedesc), errno);
219
            }
220
            else {
221
              num_aster++;
222
              printf_xy(62,3,WHITE,"adapt=%3u           ",x);//,errno);
223
              task_activate(p);
224
              x /= 2;
225
              if (x<50) x = 50;
226
            }
227
        }
228
        task_endcycle();
229
    }
230
}
231
 
232
TASK clock()
233
{
234
    int s = 0, m = 0;
235
 
236
    while(1) {
237
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
238
        printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
239
        printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
240
        task_endcycle();
241
 
242
        if (++s > 59) {
243
            s = 0;
244
            m++;
245
        }
246
        printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
247
        printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
248
        printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
249
        task_endcycle();
250
    }
251
}
252
 
253
 
254
 
255
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
256
   and plot on the screen the elapsed times... */
257
TASK jetcontrol()
258
{
259
  int i;  /* a counter */
260
  TIME sum, max, curr, last[5];
261
  int nact;
262
  int j; /* the elements set by jet_gettable */
263
  PID p;
264
 
265
 
266
  kern_cli();
267
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
268
  kern_sti();
269
 
270
  for (;;) {
271
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
272
       if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 ||
273
           (proc_table[p].pclass & 0xFF00) == HARD_PCLASS) continue;
274
 
275
       for (j=0; j<5; j++) last[j] = 0;
276
       jet_gettable(p, &last[0], 5);
277
       kern_cli();
278
       if (proc_table[p].task_level == 4)
279
         printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
280
                   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]);
281
       else
282
         printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
283
                   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]);
284
       kern_sti();
285
       i++;
286
    }
287
  }
288
}
289
 
290
void fine()
291
{
292
  sys_end();
293
}
294
 
295
void exiting(void *arg)
296
{
297
  kern_printf("EXITING");
298
  shutting_down = 1;
299
}
300
 
301
TIME perftime_prol[10001];
302
TIME perftime_epil[10001];
303
int  perftime_count = 0;
304
 
305
void perftest_stat(void *arg)
306
{
307
  int i;
308
  TIME d, sum=0, max=0;
309
 
310
  for (i=0; i<9000; i++) {
311
    d = perftime_epil[i]-perftime_prol[i];
312
    sum += d;
313
    if (max < d) max = d;
314
    kern_printf("Û%ld %ldÛ",perftime_epil[i],perftime_prol[i]);
315
  }
316
  kern_printf("\n°°° perftime_count=%u sum=%lu max=%lu   °°°\n",perftime_count, sum, max);
317
}
318
 
319
int main(int argc, char **argv)
320
{
321
    PID p1,p2,p3; //,p4,p5,p6;
322
    HARD_TASK_MODEL m;
323
//    NRT_TASK_MODEL m_nrt;
324
    SOFT_TASK_MODEL m_aper;
325
    SOFT_TASK_MODEL m_soft;
326
    int i;
327
    struct timespec fineprg;
328
 
329
    kern_cli();
330
 
331
    kern_sti();
332
 
333
    sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN);
334
    sys_atrunlevel(perftest_stat, NULL, RUNLEVEL_BEFORE_EXIT);
335
 
336
    hard_task_default_model(m);
337
    hard_task_def_wcet(m,ASTER_WCET);
338
    hard_task_def_mit(m,10000);
339
    hard_task_def_group(m,1);
340
    hard_task_def_ctrl_jet(m);
341
 
342
//    nrt_task_default_model(m_nrt);
343
//    nrt_task_def_group(m_nrt,1);
344
//    nrt_task_def_ctrl_jet(m_nrt);
345
 
346
    soft_task_default_model(m_soft);
347
    soft_task_def_met(m_soft,1000);
348
    soft_task_def_period(m_soft,100000);
349
    soft_task_def_group(m_soft,1);
350
    soft_task_def_ctrl_jet(m_soft);
351
    soft_task_def_aperiodic(m_soft);
352
 
353
 
354
    p1 = task_create("Aster",aster,&m,NULL);
355
    if (p1 == -1) {
356
        perror("test7.c(main): Could not create task <aster> ...");
357
        sys_end();
358
        l1_exit(-1);
359
    }
360
 
361
    hard_task_def_mit(m,500000);
362
    hard_task_def_wcet(m,CLOCK_WCET);
363
    p2 = task_create("Clock",clock,&m,NULL);
364
    if (p2 == -1) {
365
        perror("test7.c(main): Could not create task <Clock> ...");
366
        sys_end();
367
        l1_exit(-1);
368
    }
369
 
370
//    p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
371
    p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
372
    if (p3 == -1) {
373
        perror("test7.c(main): Could not create task <JetControl> ...");
374
        sys_end();
375
        l1_exit(-1);
376
    }
377
 
378
    soft_task_default_model(m_aper);
379
    soft_task_def_wcet(m_aper,APER_WCET);
380
    soft_task_def_ctrl_jet(m_aper);
381
    soft_task_def_system(m_aper);
382
    soft_task_def_aperiodic(m_aper);
383
 
384
    for (i=0; i<APER_MAX; i++) {
385
      soft_task_def_level(m_aper, i/4 + 2);
386
      soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±'));
387
      aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
388
      if (aper_table[i] == -1) {
389
        perror("test7.c(main): Could not create task <aper> ...");
390
        sys_end();
391
        l1_exit(-1);
392
      }
393
    }
394
 
395
    task_nopreempt();
396
    fineprg.tv_sec = 60;
397
    fineprg.tv_nsec = 0;
398
    kern_event_post(&fineprg,fine,NULL);
399
    group_activate(1);
400
    return 0;
401
}
402