/* register simulator-specific statistics */ void sim_reg_stats(struct stat_sdb_t *sdb) { stat_reg_counter(sdb, "sim_num_insn", "total number of instructions executed", &sim_num_insn, sim_num_insn, NULL); stat_reg_uint(sdb, "sim_cycles", "total number of cycles", &sim_cycle, 0, NULL); stat_reg_formula(sdb, "sim_cpi", "cycles per instruction (CPI)", "sim_cycles / sim_num_insn", NULL); stat_reg_counter(sdb, "sim_num_refs", "total number of loads and stores executed", &sim_num_refs, 0, NULL); stat_reg_int(sdb, "sim_elapsed_time", "total simulation time in seconds", &sim_elapsed_time, 0, NULL); stat_reg_formula(sdb, "sim_inst_rate", "simulation speed (in insts/sec)", "sim_num_insn / sim_elapsed_time", NULL); ld_reg_stats(sdb); mem_reg_stats(mem, sdb); }
/* register simulator-specific statistics */ void ld_reg_stats(struct stat_sdb_t *sdb) /* stats data base */ { stat_reg_addr(sdb, "ld_text_base", "program text (code) segment base", &ld_text_base, ld_text_base, "0x%08p"); stat_reg_addr(sdb, "ld_text_bound", "program text (code) segment bound", &ld_text_bound, ld_text_bound, "0x%08p"); stat_reg_uint(sdb, "ld_text_size", "program text (code) size in bytes", &ld_text_size, ld_text_size, NULL); stat_reg_addr(sdb, "ld_data_base", "program initialized data segment base", &ld_data_base, ld_data_base, "0x%08p"); stat_reg_addr(sdb, "ld_data_bound", "program initialized data segment bound", &ld_data_bound, ld_data_bound, "0x%08p"); stat_reg_uint(sdb, "ld_data_size", "program init'ed `.data' and uninit'ed `.bss' size in bytes", &ld_data_size, ld_data_size, NULL); stat_reg_addr(sdb, "ld_stack_base", "program stack segment base (highest address in stack)", &ld_stack_base, ld_stack_base, "0x%08p"); #if 0 /* FIXME: broken... */ stat_reg_addr(sdb, "ld_stack_min", "program stack segment lowest address", &ld_stack_min, ld_stack_min, "0x%08p"); #endif stat_reg_uint(sdb, "ld_stack_size", "program initial stack size", &ld_stack_size, ld_stack_size, NULL); stat_reg_addr(sdb, "ld_prog_entry", "program entry point (initial PC)", &ld_prog_entry, ld_prog_entry, "0x%08p"); stat_reg_addr(sdb, "ld_environ_base", "program environment base address address", &ld_environ_base, ld_environ_base, "0x%08p"); stat_reg_int(sdb, "ld_target_big_endian", "target executable endian-ness, non-zero if big endian", &ld_target_big_endian, ld_target_big_endian, NULL); }
/* register simulator-specific statistics */ void ld_reg_stats(struct stat_sdb_t *sdb, int threadid) /* stats data base */ { context *current; current = thecontexts[threadid]; stat_reg_uint(sdb, "threadid", "Thread id", ¤t->id, current->id, "0x%010p"); stat_reg_addr(sdb, "ld_text_base", "program text (code) segment base", ¤t->ld_text_base, current->ld_text_base, "0x%010p"); stat_reg_uint(sdb, "ld_text_size", "program text (code) size in bytes", ¤t->ld_text_size, current->ld_text_size, NULL); stat_reg_addr(sdb, "ld_data_base", "program initialized data segment base", ¤t->ld_data_base, current->ld_data_base, "0x%010p"); stat_reg_uint(sdb, "ld_data_size", "program init'ed `.data' and uninit'ed `.bss' size in bytes", ¤t->ld_data_size, current->ld_data_size, NULL); stat_reg_addr(sdb, "ld_stack_base", "program stack segment base (highest address in stack)", ¤t->ld_stack_base, current->ld_stack_base, "0x%010p"); #if 0 /* FIXME: broken... */ stat_reg_addr(sdb, "ld_stack_min", "program stack segment lowest address", ¤t->ld_stack_min, current->ld_stack_min, "0x%010p"); #endif stat_reg_uint(sdb, "ld_stack_size", "program initial stack size", ¤t->ld_stack_size, current->ld_stack_size, NULL); stat_reg_addr(sdb, "ld_prog_entry", "program entry point (initial PC)", ¤t->ld_prog_entry, current->ld_prog_entry, "0x%010p"); stat_reg_addr(sdb, "ld_environ_base", "program environment base address address", ¤t->ld_environ_base, current->ld_environ_base, "0x%010p"); stat_reg_int(sdb, "ld_target_big_endian", "target executable endian-ness, non-zero if big endian", ¤t->ld_target_big_endian, current->ld_target_big_endian, NULL); }
int main(int argc, char **argv, char **envp) { char *s; int i, exit_code; #ifndef _MSC_VER /* catch SIGUSR1 and dump intermediate stats */ signal(SIGUSR1, signal_sim_stats); /* catch SIGUSR2 and dump final stats and exit */ signal(SIGUSR2, signal_exit_now); #endif /* _MSC_VER */ /* register an error handler */ fatal_hook(sim_print_stats); /* set up a non-local exit point */ if ((exit_code = setjmp(sim_exit_buf)) != 0) { /* special handling as longjmp cannot pass 0 */ exit_now(exit_code-1); } /* register global options */ sim_odb = opt_new(orphan_fn); opt_reg_flag(sim_odb, "-h", "print help message", &help_me, /* default */FALSE, /* !print */FALSE, NULL); opt_reg_flag(sim_odb, "-v", "verbose operation", &verbose, /* default */FALSE, /* !print */FALSE, NULL); #ifdef DEBUG opt_reg_flag(sim_odb, "-d", "enable debug message", &debugging, /* default */FALSE, /* !print */FALSE, NULL); #endif /* DEBUG */ opt_reg_flag(sim_odb, "-i", "start in Dlite debugger", &dlite_active, /* default */FALSE, /* !print */FALSE, NULL); opt_reg_int(sim_odb, "-seed", "random number generator seed (0 for timer seed)", &rand_seed, /* default */1, /* print */TRUE, NULL); opt_reg_flag(sim_odb, "-q", "initialize and terminate immediately", &init_quit, /* default */FALSE, /* !print */FALSE, NULL); opt_reg_string(sim_odb, "-chkpt", "restore EIO trace execution from <fname>", &sim_chkpt_fname, /* default */NULL, /* !print */FALSE, NULL); /* stdio redirection options */ opt_reg_string(sim_odb, "-redir:sim", "redirect simulator output to file (non-interactive only)", &sim_simout, /* default */NULL, /* !print */FALSE, NULL); opt_reg_string(sim_odb, "-redir:prog", "redirect simulated program output to file", &sim_progout, /* default */NULL, /* !print */FALSE, NULL); #ifndef _MSC_VER /* scheduling priority option */ opt_reg_int(sim_odb, "-nice", "simulator scheduling priority", &nice_priority, /* default */NICE_DEFAULT_VALUE, /* print */TRUE, NULL); #endif /* FIXME: add stats intervals and max insts... */ /* register all simulator-specific options */ sim_reg_options(sim_odb); /* parse simulator options */ exec_index = -1; opt_process_options(sim_odb, argc, argv); /* redirect I/O? */ if (sim_simout != NULL) { /* send simulator non-interactive output (STDERR) to file SIM_SIMOUT */ fflush(stderr); if (!freopen(sim_simout, "w", stderr)) fatal("unable to redirect simulator output to file `%s'", sim_simout); } if (sim_progout != NULL) { /* redirect simulated program output to file SIM_PROGOUT */ sim_progfd = fopen(sim_progout, "w"); if (!sim_progfd) fatal("unable to redirect program output to file `%s'", sim_progout); } /* need at least two argv values to run */ if (argc < 2) { banner(stderr, argc, argv); usage(stderr, argc, argv); exit(1); } /* opening banner */ banner(stderr, argc, argv); if (help_me) { /* print help message and exit */ usage(stderr, argc, argv); exit(1); } /* seed the random number generator */ if (rand_seed == 0) { /* seed with the timer value, true random */ mysrand(time((time_t *)NULL)); } else { /* seed with default or user-specified random number generator seed */ mysrand(rand_seed); } /* exec_index is set in orphan_fn() */ if (exec_index == -1) { /* executable was not found */ fprintf(stderr, "error: no executable specified\n"); usage(stderr, argc, argv); exit(1); } /* else, exec_index points to simulated program arguments */ /************modification for XAMP*************/ cseq_outfile=argv[exec_index]; /***************end****************************/ /* check simulator-specific options */ sim_check_options(sim_odb, argc, argv); #ifndef _MSC_VER /* set simulator scheduling priority */ if (nice(0) < nice_priority) { if (nice(nice_priority - nice(0)) < 0) fatal("could not renice simulator process"); } #endif /* default architected value... */ sim_num_insn = 0; #ifdef BFD_LOADER /* initialize the bfd library */ bfd_init(); #endif /* BFD_LOADER */ /* initialize the instruction decoder */ md_init_decoder(); /* initialize all simulation modules */ sim_init(); /* initialize architected state */ sim_load_prog(argv[exec_index], argc-exec_index, argv+exec_index, envp); /* register all simulator stats */ sim_sdb = stat_new(); sim_reg_stats(sim_sdb); #if 0 /* not portable... :-( */ stat_reg_uint(sim_sdb, "sim_mem_usage", "total simulator (data) memory usage", &sim_mem_usage, sim_mem_usage, "%11dk"); #endif /* record start of execution time, used in rate stats */ sim_start_time = time((time_t *)NULL); /* emit the command line for later reuse */ fprintf(stderr, "sim: command line: "); for (i=0; i < argc; i++) fprintf(stderr, "%s ", argv[i]); fprintf(stderr, "\n"); /* output simulation conditions */ s = ctime(&sim_start_time); if (s[strlen(s)-1] == '\n') s[strlen(s)-1] = '\0'; fprintf(stderr, "\nsim: simulation started @ %s, options follow:\n", s); opt_print_options(sim_odb, stderr, /* short */TRUE, /* notes */TRUE); sim_aux_config(stderr); fprintf(stderr, "\n"); /* omit option dump time from rate stats */ sim_start_time = time((time_t *)NULL); if (init_quit) exit_now(0); running = TRUE; sim_main(); /* simulation finished early */ exit_now(0); return 0; }
void main(void) { struct stat_sdb_t *sdb; struct stat_stat_t *stat, *stat1, *stat2, *stat3, *stat4, *stat5; int an_int; unsigned int a_uint; float a_float; double a_double; static char *my_imap[8] = { "foo", "bar", "uxxe", "blah", "gaga", "dada", "mama", "googoo" }; /* make stats database */ sdb = stat_new(); /* register stat variables */ stat_reg_int(sdb, "stat.an_int", "An integer stat variable.", &an_int, 1, NULL); stat_reg_uint(sdb, "stat.a_uint", "An unsigned integer stat variable.", &a_uint, 2, "%u (unsigned)"); stat_reg_float(sdb, "stat.a_float", "A float stat variable.", &a_float, 3, NULL); stat_reg_double(sdb, "stat.a_double", "A double stat variable.", &a_double, 4, NULL); stat_reg_formula(sdb, "stat.a_formula", "A double stat formula.", "stat.a_float / stat.a_uint", NULL); stat_reg_formula(sdb, "stat.a_formula1", "A double stat formula #1.", "2 * (stat.a_formula / (1.5 * stat.an_int))", NULL); stat_reg_formula(sdb, "stat.a_bad_formula", "A double stat formula w/error.", "stat.a_float / (stat.a_uint - 2)", NULL); stat = stat_reg_dist(sdb, "stat.a_dist", "An array distribution.", 0, 8, 1, PF_ALL, NULL, NULL, NULL); stat1 = stat_reg_dist(sdb, "stat.a_dist1", "An array distribution #1.", 0, 8, 4, PF_ALL, NULL, NULL, NULL); stat2 = stat_reg_dist(sdb, "stat.a_dist2", "An array distribution #2.", 0, 8, 1, (PF_PDF|PF_CDF), NULL, NULL, NULL); stat3 = stat_reg_dist(sdb, "stat.a_dist3", "An array distribution #3.", 0, 8, 1, PF_ALL, NULL, my_imap, NULL); stat4 = stat_reg_sdist(sdb, "stat.a_sdist", "A sparse array distribution.", 0, PF_ALL, NULL, NULL); stat5 = stat_reg_sdist(sdb, "stat.a_sdist1", "A sparse array distribution #1.", 0, PF_ALL, "0x%08lx %10lu %6.2f %6.2f", NULL); /* print initial stats */ fprintf(stdout, "** Initial stats...\n"); stat_print_stats(sdb, stdout); /* adjust stats */ an_int++; a_uint++; a_float *= 2; a_double *= 4; stat_add_sample(stat, 8); stat_add_sample(stat, 8); stat_add_sample(stat, 1); stat_add_sample(stat, 3); stat_add_sample(stat, 4); stat_add_sample(stat, 4); stat_add_sample(stat, 7); stat_add_sample(stat1, 32); stat_add_sample(stat1, 32); stat_add_sample(stat1, 1); stat_add_sample(stat1, 12); stat_add_sample(stat1, 17); stat_add_sample(stat1, 18); stat_add_sample(stat1, 30); stat_add_sample(stat2, 8); stat_add_sample(stat2, 8); stat_add_sample(stat2, 1); stat_add_sample(stat2, 3); stat_add_sample(stat2, 4); stat_add_sample(stat2, 4); stat_add_sample(stat2, 7); stat_add_sample(stat3, 8); stat_add_sample(stat3, 8); stat_add_sample(stat3, 1); stat_add_sample(stat3, 3); stat_add_sample(stat3, 4); stat_add_sample(stat3, 4); stat_add_sample(stat3, 7); stat_add_sample(stat4, 800); stat_add_sample(stat4, 800); stat_add_sample(stat4, 1123); stat_add_sample(stat4, 3332); stat_add_sample(stat4, 4000); stat_add_samples(stat4, 4001, 18); stat_add_sample(stat4, 7); stat_add_sample(stat5, 800); stat_add_sample(stat5, 800); stat_add_sample(stat5, 1123); stat_add_sample(stat5, 3332); stat_add_sample(stat5, 4000); stat_add_samples(stat5, 4001, 18); stat_add_sample(stat5, 7); /* print final stats */ fprintf(stdout, "** Final stats...\n"); stat_print_stats(sdb, stdout); /* all done */ stat_delete(sdb); exit(0); }