Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/*
 * step 3: generation of the configuration file for CRUNCH
 */


#include <stdio.h>

// Patterns
#define MAX_PATTERN 10000
int max_hpattern = 0;
int hpattern_t[MAX_PATTERN];
int hpattern_period[MAX_PATTERN];
int hpattern_wcet[MAX_PATTERN];
int hpattern_iter[MAX_PATTERN];

int hpattern_index=0;


int max_vpattern = 0;
int vpattern_t[MAX_PATTERN];
int vpattern_period[MAX_PATTERN];
int vpattern_wcet[MAX_PATTERN];
int vpattern_iter[MAX_PATTERN];
int vpattern_value[MAX_PATTERN];
int vpattern_penalty[MAX_PATTERN];

int vpattern_index=0;

// Data structores needed for crunch
#define MAX_CRUNCH 10000
int crunch_max = 0;
int crunch_t[MAX_CRUNCH];
int crunch_type[MAX_CRUNCH];
int crunch_dline[MAX_CRUNCH];
int crunch_wcet[MAX_CRUNCH];
int crunch_iterations[MAX_CRUNCH];
int crunch_value[MAX_CRUNCH];
int crunch_penalty[MAX_CRUNCH];




void read_hpattern(char *);
void read_vpattern(char *);
void merge_dat(void);
void write_dat(void);


int main(int argc, char **argv)
{
  if (argc != 3) {
    fprintf(stderr,"Usage: step4 hpattern.dat vpattern.dat\n\n");
    exit(0);
  }

  read_hpattern(argv[1]);

  read_vpattern(argv[2]);

  merge_dat();

  write_dat();

  return 0;
}


/*
 *
 * Reading/Writing patterns
 *
 */


/*
 * This function read from a file written in the format of
 * hpattern.dat, and fills the internal pattern data structure.
 */

void read_hpattern(char *name)
{
  int i;
  FILE *f;

  f = fopen(name,"r");


  fscanf(f,"%d", &max_hpattern);

  for (i=0; i<max_hpattern; i++) {
    fscanf(f,"%d %d %d %d", &hpattern_t[i], &hpattern_period[i],
          &hpattern_wcet[i], &hpattern_iter[i]);

//    printf("Hard %d %d %d %d\n", hpattern_t[i], hpattern_period[i],
//          hpattern_wcet[i], hpattern_iter[i]);

  }
}

/*
 * This function read from a file written in the format of
 * vpattern.dat, and fills the internal pattern data structure.
 */

void read_vpattern(char *name)
{
  int i;
  FILE *f;

  f = fopen(name,"r");


  fscanf(f,"%d", &max_vpattern);

  for (i=0; i<max_vpattern; i++) {
    fscanf(f,"%d %d %d %d %d %d",
          &vpattern_t[i], &vpattern_period[i],
          &vpattern_wcet[i], &vpattern_iter[i],
          &vpattern_value[i], &vpattern_penalty[i]);

//    printf("Value %d %d %d %d %d %d\n", vpattern_t[i], vpattern_period[i],
//          vpattern_wcet[i], vpattern_iter[i],
//          vpattern_value[i], vpattern_penalty[i]);

  }
}

#define INSERT_V 1
#define INSERT_H 2

void merge_dat(void)
{
  int h_i, v_i;
  int todo = 0;

  h_i = 0;
  v_i = 0;

  while (!(h_i == max_hpattern && v_i == max_vpattern)) {
    if (h_i < max_hpattern)
      // there are h available
      if (v_i < max_vpattern)
        // random and bad available
        if (vpattern_t[v_i] < hpattern_t[h_i])
          todo = INSERT_V;
        else
          todo = INSERT_H;
      else
        // only H
        todo = INSERT_H;
    else
      // only bad available
      todo = INSERT_V;

    if (todo == INSERT_V) {
      crunch_t[crunch_max] = vpattern_t[v_i];
      crunch_type[crunch_max] = 1;
      crunch_dline[crunch_max] = vpattern_period[v_i];
      crunch_wcet[crunch_max] = vpattern_wcet[v_i];
      crunch_iterations[crunch_max] = vpattern_iter[v_i];
      crunch_value[crunch_max] = vpattern_value[v_i];
      crunch_penalty[crunch_max] = vpattern_penalty[v_i];
 
      crunch_max++;
      v_i++;
    }
    else {
      crunch_t[crunch_max] = hpattern_t[h_i];
      crunch_type[crunch_max] = 0;
      crunch_dline[crunch_max] = hpattern_period[h_i];
      crunch_wcet[crunch_max] = hpattern_wcet[h_i];
      crunch_iterations[crunch_max] = hpattern_iter[h_i];
      crunch_value[crunch_max] = 0;
      crunch_penalty[crunch_max] = 0;
 
      crunch_max++;
      h_i++;
    }
  }
}

void write_dat(void)
{
  int i;

  printf("%d\n", crunch_max);

  for (i=0; i<crunch_max; i++)
    printf("%d %d %d %d %d %d %d\n",
           crunch_t[i], crunch_type[i], crunch_dline[i], crunch_wcet[i],
           crunch_iterations[i], crunch_value[i], crunch_penalty[i]);
}