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