int main(int argc, char* argv[]) { int opt; uint64_t c = DEFAULT_C; uint64_t b = DEFAULT_B; uint64_t s = DEFAULT_S; uint64_t v = DEFAULT_V; uint64_t k = DEFAULT_K; FILE* fin = stdin; char* file_name; /* Read arguments */ while(-1 != (opt = getopt(argc, argv, "c:b:s:i:v:k:h"))) { switch(opt) { case 'c': c = atoi(optarg); break; case 'b': b = atoi(optarg); break; case 's': s = atoi(optarg); break; case 'v': v = atoi(optarg); break; case 'k': k = atoi(optarg); break; case 'i': fin = fopen(optarg, "r"); file_name = optarg; break; case 'h': /* Fall through */ default: //print_help_and_exit(); break; } } printf("Cache Settings\n"); printf("C: %" PRIu64 "\n", c); printf("B: %" PRIu64 "\n", b); printf("S: %" PRIu64 "\n", s); printf("V: %" PRIu64 "\n", v); printf("K: %" PRIu64 "\n", k); printf("\n"); // printf("C: %" PRIu64 ":: B: %" PRIu64 ":: S: %" PRIu64 ":: V: %" PRIu64 ":: K: %" PRIu64 "\n", c, b, s, v, k); if( (48*pow(2,10)*8) < ( pow(2,c-b)*pow(2,b)*8 + pow(2,c-b)*(64-(c-s)+2) + v*pow(2,b)*8 + v*(64-b+2) ) ) { return 0; } /* Setup the cache */ setup_cache(c, b, s, v, k); /* Setup statistics */ struct cache_stats_t stats; memset(&stats, 0, sizeof(struct cache_stats_t)); /* Begin reading the file */ char rw; uint64_t address; while (!feof(fin)) { int ret = fscanf(fin, "%c %" PRIx64 "\n", &rw, &address); if(ret == 2) { cache_access(rw, address, &stats); } } complete_cache(&stats); //printf("%" PRIu64 "|%" PRIu64 "|%" PRIu64 "|%" PRIu64 "|%" PRIu64 "|%s", c, b, s, v, k, file_name); print_statistics(&stats); return 0; }
int main(int argc, char* argv[]) { int opt; uint64_t c = DEFAULT_C; uint64_t b = DEFAULT_B; uint64_t s = DEFAULT_S; uint64_t v = DEFAULT_V; char st = DEFAULT_ST; char r = DEFAULT_R; FILE* fin = stdin; /* Read arguments */ while(-1 != (opt = getopt(argc, argv, "c:b:s:t:i:v:r:h"))) { switch(opt) { case 'c': c = atoi(optarg); break; case 'b': b = atoi(optarg); break; case 's': s = atoi(optarg); break; case 't': if(optarg[0] == BLOCKING || optarg[0] == SUBBLOCKING) { st = optarg[0]; } break; case 'v': v = atoi(optarg); break; case 'r': if(optarg[0] == LRU || optarg[0] == NMRU_FIFO) { r = optarg[0]; } break; case 'i': fin = fopen(optarg, "r"); break; case 'h': /* Fall through */ default: print_help_and_exit(); break; } } printf("Cache Settings\n"); printf("C: %" PRIu64 "\n", c); printf("B: %" PRIu64 "\n", b); printf("S: %" PRIu64 "\n", s); printf("V: %" PRIu64 "\n", v); printf("F: %s\n", st == BLOCKING ? "BLOCKING" : "SUBBLOCKING"); printf("R: %s\n", r == LRU ? "LRU" : "NMRU_FIFO"); printf("\n"); /* Setup the cache */ setup_cache(c, b, s, v, st, r); /* Setup statistics */ cache_stats_t stats; memset(&stats, 0, sizeof(cache_stats_t)); /* Begin reading the file */ char rw; uint64_t address; while (!feof(fin)) { int ret = fscanf(fin, "%c %" PRIx64 "\n", &rw, &address); if(ret == 2) { cache_access(rw, address, &stats); } } complete_cache(&stats); print_statistics(&stats); return 0; }
int main(int argc, char* argv[]) { int opt; uint64_t c = DEFAULT_C; uint64_t b = DEFAULT_B; uint64_t s = DEFAULT_S; char f = DEFAULT_F; char r = DEFAULT_R; /* Read arguments */ while(-1 != (opt = getopt(argc, argv, "c:b:s:f:r:h"))) { switch(opt) { case 'c': c = atoi(optarg); break; case 'b': b = atoi(optarg); break; case 's': s = atoi(optarg); break; case 'f': if(optarg[0] == BLOCKING || optarg[0] == EAGER) { f = optarg[0]; } break; case 'r': if(optarg[0] == LRU || optarg[0] == NMRU_FIFO) { r = optarg[0]; } break; case 'h': /* Fall through */ default: print_help_and_exit(); break; } } printf("Cache Settings\n"); printf("C: %llu\n", c); printf("B: %llu\n", b); printf("S: %llu\n", s); printf("F: %s\n", f == BLOCKING ? "BLOCKING" : "EAGER"); printf("R: %s\n", r == LRU ? "LRU" : "NMRU_FIFO"); printf("\n"); /* Setup the cache */ setup_cache(c, b, s, f, r); /* Setup statistics */ cache_stats_t stats; memset(&stats, 0, sizeof(cache_stats_t)); /* Begin reading the file */ char rw; uint64_t address; while (!feof(stdin)) { int ret = fscanf(stdin, "%c %llx\n", &rw, &address); if(ret == 2) { cache_access(rw, address, &stats); } } complete_cache(&stats); print_statistics(&stats); return 0; }
int main(int argc, char* argv[]) { int opt; uint64_t c = DEFAULT_C; uint64_t b = DEFAULT_B; uint64_t s = DEFAULT_S; uint64_t v = DEFAULT_V; uint64_t k = DEFAULT_K; FILE* fin = stdin; FILE* fout = stdout; char inputfile[100]; char outputfile[100]; /* Read arguments */ while(-1 != (opt = getopt(argc, argv, "c:b:s:i:v:k:h"))) { switch(opt) { case 'i': strcpy(inputfile, optarg); strcpy(outputfile, optarg); strcat(outputfile, ".out"); break; case 'c': c = atoi(optarg); break; case 'b': b = atoi(optarg); break; case 's': s = atoi(optarg); break; case 'v': v = atoi(optarg); break; case 'k': k = atoi(optarg); break; case 'h': /* Fall through */ default: print_help_and_exit(); break; } } fout = fopen(outputfile, "w"); fprintf(fout, "%s:\n\n", inputfile); double AAT_min = AAT_MAX; uint64_t AAT_min_c = DEFAULT_C; uint64_t AAT_min_b = DEFAULT_B; uint64_t AAT_min_s = DEFAULT_S; uint64_t AAT_min_v = DEFAULT_V; uint64_t AAT_min_k = DEFAULT_K; for (c = 12; c <= 15; ++c) { for (b = 3; b <= 6; ++b) { for (s = 0; s <= c - b; ++s) { // for (v = 0; v <= 4; ++v) { // for (k = 0; k <= 4; ++k) { printf("%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t", c, b, s, v, k); fprintf(fout, "%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t", c, b, s, v, k); /* calculate memory budge */ uint64_t data_storage = (1 << b) * 8; // printf("data storage: %" PRIu64 "\n", data_storage); uint64_t cache_memory = (1 << (c - b)) * (64 - c + s + 1 + data_storage); // printf("cache memory: %" PRIu64 "\n", cache_memory); uint64_t vc_memory = v * (64 - b + 1 + data_storage); // printf("vc memory: %" PRIu64 "\n", vc_memory); double total_memory_kb = (cache_memory + vc_memory) / double((1 << 10) * 8); printf("%f\t", total_memory_kb); fprintf(fout, "%f\t", total_memory_kb); /* skip if memory limitation exceeded */ if (total_memory_kb > 48) { printf("\n"); fprintf(fout, "\n"); continue; } /* Setup the cache */ setup_cache(c, b, s, v, k); /* Setup statistics */ cache_stats_t stats; memset(&stats, 0, sizeof(cache_stats_t)); /* Begin reading the file */ fin = fopen(inputfile, "r"); char rw; uint64_t address; while (!feof(fin)) { int ret = fscanf(fin, "%c %" PRIx64 "\n", &rw, &address); if (ret == 2) { cache_access(rw, address, &stats); } } fclose(fin); complete_cache(&stats); printf("%f\n", stats.avg_access_time); fprintf(fout, "%f\n", stats.avg_access_time); // update optimal setting if (stats.avg_access_time < AAT_min) { AAT_min = stats.avg_access_time; AAT_min_c = c; AAT_min_b = b; AAT_min_s = s; AAT_min_v = v; AAT_min_k = k; } // } // } } } } printf("\nBest AAT: %f\n", AAT_min); fprintf(fout, "\nBest AAT: %f\n", AAT_min); printf("Setting: %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 "\n", AAT_min_c, AAT_min_b, AAT_min_s, AAT_min_v, AAT_min_k); fprintf(fout, "Setting: %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 "\n", AAT_min_c, AAT_min_b, AAT_min_s, AAT_min_v, AAT_min_k); fclose(fout); return 0; }