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: testcash.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
20
 
21
 File:        $File$
22
 Revision:    $Revision: 1.1.1.1 $
23
 Last update: $Date: 2002-09-02 09:37:41 $
24
 ------------
25
 
26
 testcash.c
27
 test for the CASH Module, directly derived from  Test Number 13 (D)
28
 
29
**/
30
 
31
/*
32
 * Copyright (C) 2000 Paolo Gai
33
 *
34
 * This program is free software; you can redistribute it and/or modify
35
 * it under the terms of the GNU General Public License as published by
36
 * the Free Software Foundation; either version 2 of the License, or
37
 * (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
47
 *
48
 */
49
 
50
#include "kernel/kern.h"
51
#include "modules/edf.h"
52
#include "cash.h"
53
#include <math.h>
54
#include <string.h>
55
 
56
#define ASTER_LIM       60
57
#define DISPLAY_MAX     15
58
 
59
#define STAT_Y           9
60
 
61
#define INPUT            0.5
62
 
63
 
64
 
65
#define MAX_STAT     10000
66
#define RVAL             1
67
#define XVAL             2
68
#define DVAL             3
69
 
70
 
71
struct statistic {
72
  TIME r_time;
73
  TIME ex_time;
74
  long dead_post;
75
};
76
 
77
 
78
 
79
 struct statistic stat[MAX_STAT];
80
 TIME   val[MAX_STAT];
81
 
82
int    n_stat = 0;
83
 
84
TASK hard_asteroide(void)
85
{
86
    int i;
87
    int y = rand() % 7 + 1;
88
    double avg, l, fix, u;
89
    double wcet = 40200;
90
    int load1,j;
91
 
92
    char s[2];
93
 
94
    s[0] = 'H'; s[1] = 0;
95
    /* exponential distribution parameters */
96
    fix = wcet - 10.0/9.0 * wcet * (1 - INPUT);
97
    avg = 1.0/9.0 * wcet * (1 - INPUT);
98
    l = 10.0 / 9.0 * wcet * (1 - INPUT);
99
 
100
    for (;;) {
101
      i = 1;
102
      while (i < ASTER_LIM) {
103
        /* exponential distribution */
104
        u = (double)rand();
105
 
106
        u = u / (double)RAND_MAX;
107
 
108
        u = -avg * log(u);
109
        if (u > l)
110
          u = avg;
111
 
112
 
113
        load1 = fix + u;
114
 
115
        for (j=0; j<load1; j++) {
116
          puts_xy(i,y,rand()%15+1,s);
117
        }
118
        //kern_cli();
119
        //stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow);
120
        //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1);
121
        //kern_sti();
122
        //n_stat++;
123
        task_endcycle();
124
        puts_xy(i,y,WHITE," ");
125
        i++;
126
      }
127
    }
128
}
129
 
130
 
131
TASK hard_asteroide1(void)
132
{
133
    int i;
134
    int y = rand() % 7 + 1;
135
 
136
    int load1,j;
137
 
138
    char s[2];
139
 
140
    s[0] = 'H'; s[1] = 0;
141
 
142
    for (;;) {
143
      i = 1;
144
      while (i < ASTER_LIM) {
145
        load1 = 40000 + rand()%20000;
146
        for (j=0; j<load1; j++) {
147
          puts_xy(i,y,rand()%15+1,s);
148
        }
149
        //kern_cli();
150
        //stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow);
151
        //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1);
152
        //kern_sti();
153
        //n_stat++;
154
        task_endcycle();
155
        puts_xy(i,y,WHITE," ");
156
        i++;
157
      }
158
    }
159
}
160
 
161
 
162
TASK hard_asteroide2(void)
163
{
164
    int i;
165
    int y = rand() % 7 + 1;
166
 
167
    int load1,j;
168
 
169
    char s[2];
170
 
171
    s[0] = 'H'; s[1] = 0;
172
 
173
    for (;;) {
174
      i = 1;
175
      while (i < ASTER_LIM) {
176
        load1 = 80500; // + rand()%6000;
177
        for (j=0; j<load1; j++) {
178
          puts_xy(i,y,rand()%15+1,s);
179
        }
180
        //kern_cli();
181
        //stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow);
182
        //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1);
183
        //kern_sti();
184
        //n_stat++;
185
        task_endcycle();
186
        puts_xy(i,y,WHITE," ");
187
        i++;
188
      }
189
    }
190
}
191
 
192
TASK hard_asteroide3(void)
193
{
194
    int i;
195
    int y = rand() % 7 + 1;
196
 
197
    int load1,j;
198
 
199
    char s[2];
200
 
201
    s[0] = 'T'; s[1] = 0;
202
 
203
    for (;;) {
204
      i = 1;
205
      while (i < ASTER_LIM) {
206
        load1 = 27000;
207
        for (j=0; j<load1; j++) {
208
          puts_xy(i,y,rand()%15+1,s);
209
        }
210
        //kern_cli();
211
        //stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow);
212
        //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1);
213
        //kern_sti();
214
        //n_stat++;
215
        task_endcycle();
216
        puts_xy(i,y,WHITE," ");
217
        i++;
218
      }
219
    }
220
}
221
 
222
 
223
TASK clock()
224
{
225
    int s = 0, m = 0;
226
 
227
    while(1) {
228
      printf_xy(62,1,WHITE,"%2d:%2d",m,s);
229
      printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH);
230
      printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
231
      printf_xy(62,4,WHITE,"Ucbs=%12u",CBSGHD_usedbandwidth(1));
232
      task_endcycle();
233
 
234
      if (++s > 59) {
235
        s = 0;
236
        m++;
237
      }
238
      printf_xy(62,1,WHITE,"%2d:%2d",m,s);
239
      printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH);
240
      printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
241
      printf_xy(62,4,WHITE,"Ucbs=%12u",CBSGHD_usedbandwidth(1));
242
      task_endcycle();
243
    }
244
}
245
 
246
 
247
 
248
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
249
   and plot on the screen the elapsed times... */
250
TASK jetcontrol()
251
{
252
  int i;  /* a counter */
253
  TIME sum, max, curr, last[5];
254
  int nact;
255
  int j; /* the elements set by jet_gettable */
256
  PID p;
257
 
258
 
259
  kern_cli();
260
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
261
  kern_sti();
262
 
263
  for (;;) {
264
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
265
       if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
266
 
267
       for (j=0; j<5; j++) last[j] = 0;
268
       jet_gettable(p, &last[0], 5);
269
       kern_cli();
270
       printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6ld ³ %-6ld ³ %-4d ³ %-7ld ³ %-5ld ³ %-5ld ³ %-5ld ³ %-5ld ³ %-5ld", p, sum/(nact==0 ? 1 : nact), max,
271
                 nact, curr, last[0], last[1], last[2], last[3], last[4]);
272
       kern_sti();
273
       i++;
274
    }
275
    task_endcycle();
276
  }
277
}
278
 
279
 
280
void save_stat(struct statistic p[], int n, char *name, int type)
281
{
282
    DOS_FILE *f;
283
    int i;
284
    char outstring[500];
285
 
286
 
287
    for(i = 0; i < 500; i++)
288
      outstring[i] = '0';
289
 
290
    f = DOS_fopen(name, "w");
291
    if (!f) {
292
       cprintf("Cannot open %s!!!", name);
293
       goto end1;
294
    }
295
 
296
    for(i = 0; i < n; i++) {
297
        if (type == RVAL)
298
            val[i] = p[i].r_time;
299
        if (type == XVAL)
300
            val[i] = p[i].ex_time;
301
        if (type == DVAL)
302
            val[i] = p[i].dead_post;
303
    }
304
 
305
    memset(outstring, 0, 300);
306
    sprintf(outstring, "%ld \n", (long int)n);
307
    cprintf("%s", outstring);
308
    DOS_fwrite(outstring, 1, strlen(outstring), f);
309
 
310
    for(i = 0; i < n; i++) {      
311
      memset(outstring, 0, 300);
312
      sprintf(outstring, "%ld           %lu\n", (long int)i, val[i]);
313
      //cprintf("%s", outstring);
314
      DOS_fwrite(outstring, 1, strlen(outstring), f);
315
    }
316
    DOS_fclose(f);
317
end1:cprintf("OK?");
318
}
319
 
320
 
321
void result_save(void *p)
322
{
323
    save_stat(stat, n_stat, "stat1.tim", RVAL);
324
}
325
 
326
 
327
void fine()
328
{
329
  sys_end();
330
}
331
 
332
int main(int argc, char **argv)
333
{
334
    PID p1,p2,p3, p4, p5, p6, p7;
335
 
336
    ELASTIC_HARD_TASK_MODEL m;
337
    //    int i;
338
    struct timespec fineprg;
339
 
340
 
341
    //sys_atrunlevel(result_save, NULL, RUNLEVEL_AFTER_EXIT);
342
    srand(7);
343
 
344
    elastic_hard_task_default_model(m);
345
    elastic_hard_task_def_wcet(m,500);
346
    elastic_hard_task_def_maxperiod(m,500000);
347
    elastic_hard_task_def_cnormal(m,500);
348
    elastic_hard_task_def_period(m,500000);
349
    elastic_hard_task_def_group(m,1);
350
    elastic_hard_task_def_ctrl_jet(m);
351
 
352
 
353
    p1 = task_create("Clock",clock,&m,NULL);
354
    if (p1 == -1) {
355
        perror("testhd.c(main): Could not create task <Clock> ...");
356
        sys_end();
357
    }
358
 
359
 
360
 
361
 
362
    elastic_hard_task_def_wcet(m,1000);
363
    elastic_hard_task_def_maxperiod(m,100000);
364
    elastic_hard_task_def_cnormal(m,1000);
365
    elastic_hard_task_def_period(m,100000);
366
 
367
 
368
    p2 = task_create("JetControl",jetcontrol,&m,NULL);
369
    if (p2 == -1) {
370
        perror("testhd.c(main): Could not create task <JetControl> ...");
371
        sys_end();
372
    }
373
 
374
 
375
 
376
    elastic_hard_task_def_wcet(m,21000);
377
    elastic_hard_task_def_maxperiod(m,155000);
378
    elastic_hard_task_def_cnormal(m,21000);
379
    elastic_hard_task_def_period(m,155000);
380
 
381
 
382
    p3 = task_create("Hard_asteroide1",hard_asteroide1,&m,NULL);
383
    if (p3 == -1) {
384
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
385
        sys_end();
386
    }
387
 
388
    elastic_hard_task_def_wcet(m,12000);
389
    elastic_hard_task_def_maxperiod(m,61000);
390
    elastic_hard_task_def_cnormal(m,12000);
391
    elastic_hard_task_def_period(m,61000);
392
 
393
 
394
 
395
 
396
    p4 = task_create("Hard_asteroide2",hard_asteroide,&m,NULL);
397
    if (p4 == -1) {
398
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
399
        sys_end();
400
    }
401
 
402
 
403
    elastic_hard_task_def_wcet(m,30000);
404
    elastic_hard_task_def_maxperiod(m,200000);
405
    elastic_hard_task_def_cnormal(m,30000);
406
    elastic_hard_task_def_period(m,200000);
407
 
408
 
409
    p5 = task_create("Hard_asteroide3",hard_asteroide2,&m,NULL);
410
    if (p5 == -1) {
411
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
412
        sys_end();
413
    }
414
 
415
    elastic_hard_task_def_wcet(m,30000);
416
    elastic_hard_task_def_maxperiod(m,100000);
417
    elastic_hard_task_def_cnormal(m,30000);
418
    elastic_hard_task_def_period(m,100000);
419
 
420
 
421
    p6 = task_create("Hard_asteroide3",hard_asteroide2,&m,NULL);
422
    if (p6 == -1) {
423
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
424
        sys_end();
425
    }
426
 
427
    elastic_hard_task_def_wcet(m,10000);
428
    elastic_hard_task_def_maxperiod(m,200000);
429
    elastic_hard_task_def_cnormal(m,2500);
430
    elastic_hard_task_def_period(m,49000);
431
 
432
 
433
    p7 = task_create("Hard_asteroide3",hard_asteroide3,&m,NULL);
434
    if (p7 == -1) {
435
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
436
        sys_end();
437
    }
438
 
439
 
440
 
441
 
442
    printf_xy(0,STAT_Y + 15,WHITE,"Hard asteroide PID= %-3d ",p3);
443
    printf_xy(0,STAT_Y + 17,WHITE,"Clock PID= %-3d ",p1);
444
    printf_xy(0,STAT_Y + 18,WHITE,"JetControl PID= %-3d ",p2);
445
 
446
 
447
 
448
    task_nopreempt();
449
    fineprg.tv_sec = 30;
450
    fineprg.tv_nsec = 0;
451
    kern_event_post(&fineprg,fine,NULL);
452
    group_activate(1);
453
    return 0;
454
}
455