/* mtask.c * program to interleave dinero traces to simulate multi-tasking * * Usage: mtask n file1 [... filen] * Example: mtask 1000 filea.din fileb.din filec.din * would interleave 1000 line intervals from 3 files filea.din * fileb.din and filec.din. It stops producing output at the * first end-of-file encountered on file reading. * * mtask XOR's the task number into the high 8 bits of the 64-bit * address to reduce the chance that tasks map into the same * addresses (no guarantee, but ought to work in most cases) * * P. Koopman 2/98 18-742 CMU */ #define MAXFILES 256 #include void main(int argc, char *argv[]) { int interleave; int lines=0, remaining; int this_file=0, max_file=0; long tag, addr, twiddle; FILE *fp_array[MAXFILES]; if (argc < 3) { printf("Usage: mtask n file0 [file1 ... filen]\n"); exit(-1); } if (sscanf(argv[1], "%d", &interleave) != 1) { printf("Usage: mtask n file0 [file1 ... filen]\n"); exit(-2); } fprintf(stderr, "mtask interleave=%d\n", interleave); for (max_file = 0; max_file < argc-2; max_file++) { fp_array[max_file] = fopen(argv[max_file+2], "r"); if( !fp_array[max_file] ) { fprintf(stderr, "\nUnable to open input file: %s\n", argv[max_file+2]); exit(-3); } } this_file = 0; lines = 0; twiddle=0; remaining = interleave; do { if (fscanf(fp_array[this_file], "%ld",&tag) != 1) break; printf("%ld ", tag); /* print dinero type */ if (fscanf(fp_array[this_file], "%lx",&addr) != 1) break; printf("%lx\n", addr ^ twiddle ); /* print twiddled address */ /* read through any comments */ while (!feof(fp_array[this_file])) { if( fgetc(fp_array[this_file]) == '\n') break; } lines++; remaining--; if (remaining < 1) { remaining = interleave; this_file = (this_file + 1) % max_file; twiddle = this_file; twiddle = twiddle << 56; } } while (!feof(fp_array[this_file])); fprintf(stderr, "\n%d lines generated\n", lines); }