int main (int argc, char * argv[]) { long mis_preds = 0; long num_branches = 0; uint32_t pc = 0; bool outcome = false; // Initialize the predictor init_predictor (); if (argc == 2) setup_trace (argv[1]); else setup_trace (NULL); // Read the number of instructions from the trace uint32_t stat_num_insts = 0; if (fread (&stat_num_insts, sizeof (uint32_t), 1, stream) != 1) { printf ("Could not read intput file\n"); return 1; } stat_num_insts = ntohl (stat_num_insts); // Read each branch from the trace while (read_branch (&pc, &outcome)) { pc = ntohl (pc); num_branches ++; // Make a prediction and compare with actual outcome if (make_prediction (pc) != outcome) mis_preds ++; // Train the predictor train_predictor (pc, outcome); } // Print out the mispredict statistics printf ("Branches\t\t%10d\n", num_branches); printf ("Incorrect\t\t%10d\n", mis_preds); float mis_pred_rate = 100*(float)mis_preds / float(num_branches); printf ("100*wrong_predicts/total branches is %8d / %8d = %7.3f\n", mis_preds, num_branches, mis_pred_rate); if (argc == 2) close_trace (); return 0; }
int main(int argc, char **argv) { int c; static struct option opts[] = { { "parv", 1, 0, 0 }, { "outv", 1, 0, 0 }, { "model", 1, 0, 0 }, { "mode", 1, 0, 0 }, { "trace", 1, 0, 0 }, {0,0,0,0} }; enum optt { PARV = 0, OUTV = 1, MODEL = 2, MODE = 3, TRACE = 4 }; struct dm_disk_if *d; struct dm_layout_g4 *l; struct trace *t; struct dsstuff *ds = calloc(1, sizeof(*ds)); struct lp_block *unm; setlinebuf(stdout); FILE *outfile = NULL; int optind; char *parv = 0; char *outv = 0; char *model = 0; char *trace = 0; while((c = getopt_long(argc, argv, "q", opts, &optind)) != -1) { switch(c) { case -1: break; case 0: switch(optind) { case PARV: parv = strdup(optarg); break; case OUTV: outv = strdup(optarg); break; case MODEL: model = strdup(optarg); break; case MODE: if(!strcmp(optarg, "calib")) { mode = CALIB; } else if(!strcmp(optarg, "gentrace")) { mode = GENTRACE; } else { fprintf(stderr, "*** bad mode %s\n", optarg); exit(1); } break; case TRACE: trace = strdup(optarg); break; default: ddbg_assert(0); break; } break; default: ddbg_assert(0); break; } } t = setup_trace(trace); if(mode == CALIB) { outfile = fopen(model, "w"); ddbg_assert(outfile); } ds->iface = disksim_interface_initialize(parv, outv, cb, schedule_callback, deschedule_callback, ds, 18, // argc nocache_over); d = disksim_getdiskmodel(ds->iface, 0); l = (struct dm_layout_g4 *)d->layout; do_idx(d, 0, l->root, l, ds, t, 0); extern struct lp_block* marshal_layout_g4(struct dm_layout_g4 *); if(mode == CALIB) { unm = marshal_layout_g4(l); unparse_block(unm, outfile); fclose(outfile); } free(ds); fclose(t->fp); free(t); return 0; }