Subversion Repositories shark

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

/*
 * Project: S.Ha.R.K.
 *
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
 *               Paolo Gai <pj@hartik.sssup.it>
 *
 * Authors     : Marco Caccamo and Paolo Gai
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


/**
 ------------
 CVS :        $Id: prova.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 Marco Caccamo and 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 <modules/edf.h>
#include "cbs_ft.h"
#include <math.h>
#include <stdlib.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_aster1p(void)
{
    int i;
    int y = 1;
    int load1,j;

    char s[2];

    s[0] = 'P'; s[1] = 0;
 
 
    for (;;) {
      i = 1;
      while (i < ASTER_LIM) {
        load1 = 20000; //+ rand() % 25000;
        for (j=0; j<load1; j++) {
          if (CBS_FT_Checkpoint())
            break;
          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_aster1b(void)
{
    int i;
    int y = 1;

    int load1,j;

    char s[2];

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

    for (;;) {
      i = 1;
      while (i < ASTER_LIM) {
        load1 = 20000;// + rand()%4000;
        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_aster2p(void)
{
    int i;
    int y = 3;

    int load1,j;

    char s[2];

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

    for (;;) {
      i = 1;
      while (i < ASTER_LIM) {
        load1 = 20000 + rand() % 20000;
        for (j=0; j<load1; j++) {
            if (CBS_FT_Checkpoint())
               break;
            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_aster2b(void)
{
    int i;
    int y = 3;

    int load1,j;

    char s[2];

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

    for (;;) {
      i = 1;
      while (i < ASTER_LIM) {
        load1 = 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(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",CBS_FT_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",CBS_FT_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()
{
  ll_abort(666);
}

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

    HARD_TASK_MODEL m;
    FT_TASK_MODEL ftb;
    FT_TASK_MODEL ftp;
   
    //    int i;
    struct timespec fineprg;


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

    hard_task_default_model(m);
    hard_task_def_wcet(m,500);
    hard_task_def_mit(m,500000);
    hard_task_def_periodic(m);
    hard_task_def_group(m,1);
    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();
    }


    hard_task_def_wcet(m,500);
    hard_task_def_periodic(m);
    hard_task_def_mit(m,100000);
 
   
    p2 = task_create("JetControl",jetcontrol,&m,NULL);
    if (p2 == -1) {
        perror("testhd.c(main): Could not create task <JetControl> ...");
        sys_end();
    }


    ft_task_default_model(ftb);
    ft_task_def_usemath(ftb);        
    ft_task_def_backup(ftb);
    ft_task_def_ctrl_jet(ftb);
    ft_task_def_backup_wcet(ftb, 7000);
   
   

    p3 = task_create("Hard_aster1b", hard_aster1b, &ftb,NULL);
    if (p3 == -1) {
        perror("testhd.c(main): Could not create task <aster1b> ...");
        sys_end();
    }

    ft_task_default_model(ftp);
    ft_task_def_usemath(ftp);        
    ft_task_def_ctrl_jet(ftp);
    ft_task_def_group(ftp, 1);
    ft_task_def_period(ftp, 50000);
    ft_task_def_budget(ftp, 15000);
    ft_task_def_primary_exec(ftp, 7300);
    ft_task_def_primary(ftp);
    ft_task_def_backup_task(ftp, p3);  
   
         
    p4 = task_create("Hard_aster1p", hard_aster1p, &ftp, NULL);
    if (p4 == -1) {
      perror("testhd.c(main): Could not create task <aster1p> ...");
      sys_end();
    }


    ft_task_def_backup_wcet(ftb, 6700);

         
    p5 = task_create("Hard_aster2b", hard_aster2b, &ftb, NULL);
    if (p5 == -1) {
      perror("testhd.c(main): Could not create task <aster2b> ...");
      sys_end();
    }


    ft_task_def_period(ftp, 100000);
    ft_task_def_budget(ftp, 8000);
    ft_task_def_primary_exec(ftp, 11000);
    ft_task_def_backup_task(ftp, p5);  
   
         
    p6 = task_create("Hard_aster2p", hard_aster2p, &ftp, NULL);
    if (p6 == -1) {
    perror("testhd.c(main): Could not create task <aster2p> ...");
      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 = 10;
    fineprg.tv_nsec = 0;
    kern_event_post(&fineprg,fine,NULL);
    group_activate(1);
    return 0;
}