Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1663 pj 1
/*
2
 * step 3: generation of the configuration file for CRUNCH
3
 */
4
 
5
#include <stdio.h>
6
 
7
// Patterns
8
#define MAX_PATTERN 10000
9
int max_hpattern = 0;
10
int hpattern_t[MAX_PATTERN];
11
int hpattern_period[MAX_PATTERN];
12
int hpattern_wcet[MAX_PATTERN];
13
int hpattern_iter[MAX_PATTERN];
14
 
15
int hpattern_index=0;
16
 
17
 
18
int max_vpattern = 0;
19
int vpattern_t[MAX_PATTERN];
20
int vpattern_period[MAX_PATTERN];
21
int vpattern_wcet[MAX_PATTERN];
22
int vpattern_iter[MAX_PATTERN];
23
int vpattern_value[MAX_PATTERN];
24
int vpattern_penalty[MAX_PATTERN];
25
 
26
int vpattern_index=0;
27
 
28
// Data structores needed for crunch
29
#define MAX_CRUNCH 10000
30
int crunch_max = 0;
31
int crunch_t[MAX_CRUNCH];
32
int crunch_type[MAX_CRUNCH];
33
int crunch_dline[MAX_CRUNCH];
34
int crunch_wcet[MAX_CRUNCH];
35
int crunch_iterations[MAX_CRUNCH];
36
int crunch_value[MAX_CRUNCH];
37
int crunch_penalty[MAX_CRUNCH];
38
 
39
 
40
 
41
 
42
void read_hpattern(char *);
43
void read_vpattern(char *);
44
void merge_dat(void);
45
void write_dat(void);
46
 
47
 
48
int main(int argc, char **argv)
49
{
50
  if (argc != 3) {
51
    fprintf(stderr,"Usage: step4 hpattern.dat vpattern.dat\n\n");
52
    exit(0);
53
  }
54
 
55
  read_hpattern(argv[1]);
56
 
57
  read_vpattern(argv[2]);
58
 
59
  merge_dat();
60
 
61
  write_dat();
62
 
63
  return 0;
64
}
65
 
66
 
67
/*
68
 *
69
 * Reading/Writing patterns
70
 *
71
 */
72
 
73
/*
74
 * This function read from a file written in the format of
75
 * hpattern.dat, and fills the internal pattern data structure.
76
 */
77
void read_hpattern(char *name)
78
{
79
  int i;
80
  FILE *f;
81
 
82
  f = fopen(name,"r");
83
 
84
 
85
  fscanf(f,"%d", &max_hpattern);
86
 
87
  for (i=0; i<max_hpattern; i++) {
88
    fscanf(f,"%d %d %d %d", &hpattern_t[i], &hpattern_period[i],
89
          &hpattern_wcet[i], &hpattern_iter[i]);
90
 
91
//    printf("Hard %d %d %d %d\n", hpattern_t[i], hpattern_period[i],
92
//          hpattern_wcet[i], hpattern_iter[i]);
93
 
94
  }
95
}
96
 
97
/*
98
 * This function read from a file written in the format of
99
 * vpattern.dat, and fills the internal pattern data structure.
100
 */
101
void read_vpattern(char *name)
102
{
103
  int i;
104
  FILE *f;
105
 
106
  f = fopen(name,"r");
107
 
108
 
109
  fscanf(f,"%d", &max_vpattern);
110
 
111
  for (i=0; i<max_vpattern; i++) {
112
    fscanf(f,"%d %d %d %d %d %d",
113
          &vpattern_t[i], &vpattern_period[i],
114
          &vpattern_wcet[i], &vpattern_iter[i],
115
          &vpattern_value[i], &vpattern_penalty[i]);
116
 
117
//    printf("Value %d %d %d %d %d %d\n", vpattern_t[i], vpattern_period[i],
118
//          vpattern_wcet[i], vpattern_iter[i],
119
//          vpattern_value[i], vpattern_penalty[i]);
120
 
121
  }
122
}
123
 
124
#define INSERT_V 1
125
#define INSERT_H 2
126
 
127
void merge_dat(void)
128
{
129
  int h_i, v_i;
130
  int todo = 0;
131
 
132
  h_i = 0;
133
  v_i = 0;
134
 
135
  while (!(h_i == max_hpattern && v_i == max_vpattern)) {
136
    if (h_i < max_hpattern)
137
      // there are h available
138
      if (v_i < max_vpattern)
139
        // random and bad available
140
        if (vpattern_t[v_i] < hpattern_t[h_i])
141
          todo = INSERT_V;
142
        else
143
          todo = INSERT_H;
144
      else
145
        // only H
146
        todo = INSERT_H;
147
    else
148
      // only bad available
149
      todo = INSERT_V;
150
 
151
    if (todo == INSERT_V) {
152
      crunch_t[crunch_max] = vpattern_t[v_i];
153
      crunch_type[crunch_max] = 1;
154
      crunch_dline[crunch_max] = vpattern_period[v_i];
155
      crunch_wcet[crunch_max] = vpattern_wcet[v_i];
156
      crunch_iterations[crunch_max] = vpattern_iter[v_i];
157
      crunch_value[crunch_max] = vpattern_value[v_i];
158
      crunch_penalty[crunch_max] = vpattern_penalty[v_i];
159
 
160
      crunch_max++;
161
      v_i++;
162
    }
163
    else {
164
      crunch_t[crunch_max] = hpattern_t[h_i];
165
      crunch_type[crunch_max] = 0;
166
      crunch_dline[crunch_max] = hpattern_period[h_i];
167
      crunch_wcet[crunch_max] = hpattern_wcet[h_i];
168
      crunch_iterations[crunch_max] = hpattern_iter[h_i];
169
      crunch_value[crunch_max] = 0;
170
      crunch_penalty[crunch_max] = 0;
171
 
172
      crunch_max++;
173
      h_i++;
174
    }
175
  }
176
}
177
 
178
void write_dat(void)
179
{
180
  int i;
181
 
182
  printf("%d\n", crunch_max);
183
 
184
  for (i=0; i<crunch_max; i++)
185
    printf("%d %d %d %d %d %d %d\n",
186
           crunch_t[i], crunch_type[i], crunch_dline[i], crunch_wcet[i],
187
           crunch_iterations[i], crunch_value[i], crunch_penalty[i]);
188
}
189