Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/*
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
 *
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
 *               Gerardo Lamastra <gerardo@sssup.it>
 *
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
 * (see authors.txt for full list of hartik's authors)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://hartik.sssup.it
 */


/**
 ------------
 CVS :        $Id: testcash.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $

 File:        $File$
 Revision:    $Revision: 1.1.1.1 $
 Last update: $Date: 2002-09-02 09:37:41 $
 ------------

 testcash.c
 test for the CASH Module, directly derived from  Test Number 13 (D)

**/


/*
 * Copyright (C) 2000 Paolo Gai
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#include "kernel/kern.h"
#include "modules/edf.h"
#include "cash.h"
#include <math.h>
#include <string.h>

#define ASTER_LIM       60
#define DISPLAY_MAX     15

#define STAT_Y           9

#define INPUT            0.5



#define MAX_STAT     10000
#define RVAL             1
#define XVAL             2
#define DVAL             3


struct statistic {
  TIME r_time;
  TIME ex_time;
  long dead_post;
};



 struct statistic stat[MAX_STAT];
 TIME   val[MAX_STAT];

int    n_stat = 0;

TASK hard_asteroide(void)
{
    int i;
    int y = rand() % 7 + 1;
    double avg, l, fix, u;
    double wcet = 40200;
    int load1,j;

    char s[2];

    s[0] = 'H'; s[1] = 0;
    /* exponential distribution parameters */
    fix = wcet - 10.0/9.0 * wcet * (1 - INPUT);
    avg = 1.0/9.0 * wcet * (1 - INPUT);
    l = 10.0 / 9.0 * wcet * (1 - INPUT);
 
    for (;;) {
      i = 1;
      while (i < ASTER_LIM) {
        /* exponential distribution */
        u = (double)rand();
       
        u = u / (double)RAND_MAX;
       
        u = -avg * log(u);
        if (u > l)
          u = avg;

       
        load1 = fix + u;
       
        for (j=0; j<load1; j++) {
          puts_xy(i,y,rand()%15+1,s);
        }
        //kern_cli();
        //stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow);
        //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1);
        //kern_sti();
        //n_stat++;
        task_endcycle();
        puts_xy(i,y,WHITE," ");
        i++;
      }
    }
}


TASK hard_asteroide1(void)
{
    int i;
    int y = rand() % 7 + 1;

    int load1,j;

    char s[2];

    s[0] = 'H'; s[1] = 0;

    for (;;) {
      i = 1;
      while (i < ASTER_LIM) {
        load1 = 40000 + rand()%20000;
        for (j=0; j<load1; j++) {
          puts_xy(i,y,rand()%15+1,s);
        }
        //kern_cli();
        //stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow);
        //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1);
        //kern_sti();
        //n_stat++;
        task_endcycle();
        puts_xy(i,y,WHITE," ");
        i++;
      }
    }
}


TASK hard_asteroide2(void)
{
    int i;
    int y = rand() % 7 + 1;

    int load1,j;

    char s[2];

    s[0] = 'H'; s[1] = 0;

    for (;;) {
      i = 1;
      while (i < ASTER_LIM) {
        load1 = 80500; // + rand()%6000;
        for (j=0; j<load1; j++) {
          puts_xy(i,y,rand()%15+1,s);
        }
        //kern_cli();
        //stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow);
        //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1);
        //kern_sti();
        //n_stat++;
        task_endcycle();
        puts_xy(i,y,WHITE," ");
        i++;
      }
    }
}

TASK hard_asteroide3(void)
{
    int i;
    int y = rand() % 7 + 1;

    int load1,j;

    char s[2];

    s[0] = 'T'; s[1] = 0;

    for (;;) {
      i = 1;
      while (i < ASTER_LIM) {
        load1 = 27000;
        for (j=0; j<load1; j++) {
          puts_xy(i,y,rand()%15+1,s);
        }
        //kern_cli();
        //stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow);
        //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1);
        //kern_sti();
        //n_stat++;
        task_endcycle();
        puts_xy(i,y,WHITE," ");
        i++;
      }
    }
}


TASK clock()
{
    int s = 0, m = 0;

    while(1) {
      printf_xy(62,1,WHITE,"%2d:%2d",m,s);
      printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH);
      printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
      printf_xy(62,4,WHITE,"Ucbs=%12u",CBSGHD_usedbandwidth(1));
      task_endcycle();
     
      if (++s > 59) {
        s = 0;
        m++;
      }
      printf_xy(62,1,WHITE,"%2d:%2d",m,s);
      printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH);
      printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
      printf_xy(62,4,WHITE,"Ucbs=%12u",CBSGHD_usedbandwidth(1));
      task_endcycle();
    }
}



/* we consider the first ASTER_MAX + 2 tasks from the PID 2
   and plot on the screen the elapsed times... */

TASK jetcontrol()
{
  int i;  /* a counter */
  TIME sum, max, curr, last[5];
  int nact;
  int j; /* the elements set by jet_gettable */
  PID p;


  kern_cli();
  printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr.   ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
  kern_sti();

  for (;;) {
    for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
       if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;

       for (j=0; j<5; j++) last[j] = 0;
       jet_gettable(p, &last[0], 5);
       kern_cli();
       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,
                 nact, curr, last[0], last[1], last[2], last[3], last[4]);
       kern_sti();
       i++;
    }
    task_endcycle();
  }
}


void save_stat(struct statistic p[], int n, char *name, int type)
{
    DOS_FILE *f;
    int i;
    char outstring[500];
   
   
    for(i = 0; i < 500; i++)
      outstring[i] = '0';
   
    f = DOS_fopen(name, "w");
    if (!f) {
       cprintf("Cannot open %s!!!", name);
       goto end1;
    }
 
    for(i = 0; i < n; i++) {
        if (type == RVAL)
            val[i] = p[i].r_time;
        if (type == XVAL)
            val[i] = p[i].ex_time;
        if (type == DVAL)
            val[i] = p[i].dead_post;
    }
   
    memset(outstring, 0, 300);
    sprintf(outstring, "%ld \n", (long int)n);
    cprintf("%s", outstring);
    DOS_fwrite(outstring, 1, strlen(outstring), f);

    for(i = 0; i < n; i++) {      
      memset(outstring, 0, 300);
      sprintf(outstring, "%ld           %lu\n", (long int)i, val[i]);
      //cprintf("%s", outstring);
      DOS_fwrite(outstring, 1, strlen(outstring), f);
    }
    DOS_fclose(f);
end1:cprintf("OK?");
}


void result_save(void *p)
{
    save_stat(stat, n_stat, "stat1.tim", RVAL);
}


void fine()
{
  sys_end();
}

int main(int argc, char **argv)
{
    PID p1,p2,p3, p4, p5, p6, p7;

    ELASTIC_HARD_TASK_MODEL m;
    //    int i;
    struct timespec fineprg;


    //sys_atrunlevel(result_save, NULL, RUNLEVEL_AFTER_EXIT);
    srand(7);

    elastic_hard_task_default_model(m);
    elastic_hard_task_def_wcet(m,500);
    elastic_hard_task_def_maxperiod(m,500000);
    elastic_hard_task_def_cnormal(m,500);
    elastic_hard_task_def_period(m,500000);
    elastic_hard_task_def_group(m,1);
    elastic_hard_task_def_ctrl_jet(m);


    p1 = task_create("Clock",clock,&m,NULL);
    if (p1 == -1) {
        perror("testhd.c(main): Could not create task <Clock> ...");
        sys_end();
    }




    elastic_hard_task_def_wcet(m,1000);
    elastic_hard_task_def_maxperiod(m,100000);
    elastic_hard_task_def_cnormal(m,1000);
    elastic_hard_task_def_period(m,100000);
 
   
    p2 = task_create("JetControl",jetcontrol,&m,NULL);
    if (p2 == -1) {
        perror("testhd.c(main): Could not create task <JetControl> ...");
        sys_end();
    }

 
   
    elastic_hard_task_def_wcet(m,21000);
    elastic_hard_task_def_maxperiod(m,155000);
    elastic_hard_task_def_cnormal(m,21000);
    elastic_hard_task_def_period(m,155000);


    p3 = task_create("Hard_asteroide1",hard_asteroide1,&m,NULL);
    if (p3 == -1) {
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
        sys_end();
    }

    elastic_hard_task_def_wcet(m,12000);
    elastic_hard_task_def_maxperiod(m,61000);
    elastic_hard_task_def_cnormal(m,12000);
    elastic_hard_task_def_period(m,61000);

   


    p4 = task_create("Hard_asteroide2",hard_asteroide,&m,NULL);
    if (p4 == -1) {
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
        sys_end();
    }


    elastic_hard_task_def_wcet(m,30000);
    elastic_hard_task_def_maxperiod(m,200000);
    elastic_hard_task_def_cnormal(m,30000);
    elastic_hard_task_def_period(m,200000);


    p5 = task_create("Hard_asteroide3",hard_asteroide2,&m,NULL);
    if (p5 == -1) {
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
        sys_end();
    }

    elastic_hard_task_def_wcet(m,30000);
    elastic_hard_task_def_maxperiod(m,100000);
    elastic_hard_task_def_cnormal(m,30000);
    elastic_hard_task_def_period(m,100000);


    p6 = task_create("Hard_asteroide3",hard_asteroide2,&m,NULL);
    if (p6 == -1) {
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
        sys_end();
    }
   
    elastic_hard_task_def_wcet(m,10000);
    elastic_hard_task_def_maxperiod(m,200000);
    elastic_hard_task_def_cnormal(m,2500);
    elastic_hard_task_def_period(m,49000);


    p7 = task_create("Hard_asteroide3",hard_asteroide3,&m,NULL);
    if (p7 == -1) {
        perror("testhd.c(main): Could not create task <Hard asteroide> ...");
        sys_end();
    }


   

    printf_xy(0,STAT_Y + 15,WHITE,"Hard asteroide PID= %-3d ",p3);
    printf_xy(0,STAT_Y + 17,WHITE,"Clock PID= %-3d ",p1);
    printf_xy(0,STAT_Y + 18,WHITE,"JetControl PID= %-3d ",p2);
   

   
    task_nopreempt();
    fineprg.tv_sec = 30;
    fineprg.tv_nsec = 0;
    kern_event_post(&fineprg,fine,NULL);
    group_activate(1);
    return 0;
}