diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-03-24 14:29:40 -0400 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-03-24 14:29:40 -0400 |
commit | a697002746edc145d2617c34c231da60df799f3e (patch) | |
tree | 66a95fe23bbae717bbeea76f48bc23c9fa5df5e0 | |
parent | e776e480143ef3dddf0d6ec877a562d15b5b2b07 (diff) |
Write experimental data to result file.
Optionally, with parameter encoding.
-rw-r--r-- | bin/cache_cost.c | 65 |
1 files changed, 52 insertions, 13 deletions
diff --git a/bin/cache_cost.c b/bin/cache_cost.c index dc4c0fe..195e23d 100644 --- a/bin/cache_cost.c +++ b/bin/cache_cost.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <sched.h> | 8 | #include <sched.h> |
9 | 9 | ||
10 | #include <sys/io.h> | 10 | #include <sys/io.h> |
11 | #include <sys/utsname.h> | ||
11 | 12 | ||
12 | #include "litmus.h" | 13 | #include "litmus.h" |
13 | #include "asm.h" | 14 | #include "asm.h" |
@@ -125,7 +126,8 @@ static int touch_mem(int *mem, int wss, int write_cycle) | |||
125 | return sum; | 126 | return sum; |
126 | } | 127 | } |
127 | 128 | ||
128 | static void do_random_experiment(int num_cpus, int wss, | 129 | static void do_random_experiment(FILE* outfile, |
130 | int num_cpus, int wss, | ||
129 | int sleep_min, int sleep_max, | 131 | int sleep_min, int sleep_max, |
130 | int write_cycle) | 132 | int write_cycle) |
131 | { | 133 | { |
@@ -185,15 +187,16 @@ static void do_random_experiment(int num_cpus, int wss, | |||
185 | 187 | ||
186 | /* run, write ratio, wss, delay, from, to, cold, hot1, hot2, | 188 | /* run, write ratio, wss, delay, from, to, cold, hot1, hot2, |
187 | * hot3, after_resume */ | 189 | * hot3, after_resume */ |
188 | printf("%6ld, %3d, %6d, %6d, %3d, %3d, " | 190 | fprintf(outfile, |
189 | "%" CYCLES_FMT ", " | 191 | "%6ld, %3d, %6d, %6d, %3d, %3d, " |
190 | "%" CYCLES_FMT ", " | 192 | "%" CYCLES_FMT ", " |
191 | "%" CYCLES_FMT ", " | 193 | "%" CYCLES_FMT ", " |
192 | "%" CYCLES_FMT ", " | 194 | "%" CYCLES_FMT ", " |
193 | "%" CYCLES_FMT "\n", | 195 | "%" CYCLES_FMT ", " |
194 | counter++, write_cycle, | 196 | "%" CYCLES_FMT "\n", |
195 | wss, delay, last_cpu, next_cpu, cold, hot1, hot2, hot3, | 197 | counter++, write_cycle, |
196 | after_resume); | 198 | wss, delay, last_cpu, next_cpu, cold, hot1, hot2, hot3, |
199 | after_resume); | ||
197 | last_cpu = next_cpu; | 200 | last_cpu = next_cpu; |
198 | deallocate(mem); | 201 | deallocate(mem); |
199 | } | 202 | } |
@@ -201,7 +204,7 @@ static void do_random_experiment(int num_cpus, int wss, | |||
201 | 204 | ||
202 | static void on_sigalarm(int signo) | 205 | static void on_sigalarm(int signo) |
203 | { | 206 | { |
204 | fprintf(stderr, "SIGALARM\n"); | 207 | /*fprintf(stderr, "SIGALARM\n");*/ |
205 | exit(0); | 208 | exit(0); |
206 | } | 209 | } |
207 | 210 | ||
@@ -211,7 +214,7 @@ static void usage(char *error) { | |||
211 | } | 214 | } |
212 | 215 | ||
213 | 216 | ||
214 | #define OPTSTR "m:w:l:s:" | 217 | #define OPTSTR "m:w:l:s:o:x:y:n" |
215 | 218 | ||
216 | int main(int argc, char** argv) | 219 | int main(int argc, char** argv) |
217 | { | 220 | { |
@@ -221,6 +224,10 @@ int main(int argc, char** argv) | |||
221 | int sleep_max = 1000; | 224 | int sleep_max = 1000; |
222 | int exit_after = 0; /* seconds */ | 225 | int exit_after = 0; /* seconds */ |
223 | int write_cycle = 0; /* every nth cycle is a write; 0 means read-only */ | 226 | int write_cycle = 0; /* every nth cycle is a write; 0 means read-only */ |
227 | FILE* out = stdout; | ||
228 | char fname[255]; | ||
229 | struct utsname utsname; | ||
230 | int auto_name_file = 0; | ||
224 | int opt; | 231 | int opt; |
225 | 232 | ||
226 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { | 233 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { |
@@ -237,6 +244,20 @@ int main(int argc, char** argv) | |||
237 | case 'l': | 244 | case 'l': |
238 | exit_after = atoi(optarg); | 245 | exit_after = atoi(optarg); |
239 | break; | 246 | break; |
247 | case 'o': | ||
248 | out = fopen(optarg, "w"); | ||
249 | if (out == NULL) | ||
250 | usage("could not open file"); | ||
251 | break; | ||
252 | case 'n': | ||
253 | auto_name_file = 1; | ||
254 | break; | ||
255 | case 'x': | ||
256 | sleep_min = atoi(optarg); | ||
257 | break; | ||
258 | case 'y': | ||
259 | sleep_max = atoi(optarg); | ||
260 | break; | ||
240 | case ':': | 261 | case ':': |
241 | usage("Argument missing."); | 262 | usage("Argument missing."); |
242 | break; | 263 | break; |
@@ -253,6 +274,9 @@ int main(int argc, char** argv) | |||
253 | if (wss <= 0) | 274 | if (wss <= 0) |
254 | usage("The working set size must be positive."); | 275 | usage("The working set size must be positive."); |
255 | 276 | ||
277 | if (sleep_min < 0 || sleep_min > sleep_max) | ||
278 | usage("Invalid minimum sleep time"); | ||
279 | |||
256 | if (write_cycle < 0) | 280 | if (write_cycle < 0) |
257 | usage("Write cycle may not be negative."); | 281 | usage("Write cycle may not be negative."); |
258 | 282 | ||
@@ -265,11 +289,26 @@ int main(int argc, char** argv) | |||
265 | if (lock_memory() != 0) | 289 | if (lock_memory() != 0) |
266 | die("Could not lock memory."); | 290 | die("Could not lock memory."); |
267 | 291 | ||
292 | if (auto_name_file) { | ||
293 | uname(&utsname); | ||
294 | snprintf(fname, 255, | ||
295 | "pmo_host=%s_wss=%d_wcyle=%d_smin=%d_smax=%d.csv", | ||
296 | utsname.nodename, wss, write_cycle, sleep_min, sleep_max); | ||
297 | out = fopen(fname, "w"); | ||
298 | if (out == NULL) { | ||
299 | fprintf(stderr, "Can't open %s.", fname); | ||
300 | die("I/O"); | ||
301 | } | ||
302 | } | ||
303 | |||
268 | if (exit_after > 0) { | 304 | if (exit_after > 0) { |
269 | signal(SIGALRM, on_sigalarm); | 305 | signal(SIGALRM, on_sigalarm); |
270 | alarm(exit_after); | 306 | alarm(exit_after); |
271 | } | 307 | } |
272 | 308 | ||
273 | do_random_experiment(num_cpus, wss, sleep_min, sleep_max, write_cycle); | 309 | do_random_experiment(out, |
310 | num_cpus, wss, sleep_min, | ||
311 | sleep_max, write_cycle); | ||
312 | fclose(out); | ||
274 | return 0; | 313 | return 0; |
275 | } | 314 | } |