"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

sim-cheetah.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "host.h"
#include "misc.h"
#include "machine.h"
#include "regs.h"
#include "memory.h"
#include "loader.h"
#include "syscall.h"
#include "dlite.h"
#include "options.h"
#include "stats.h"
#include "libcheetah/libcheetah.h"
#include "sim.h"
#include "machine.def"

Include dependency graph for sim-cheetah.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define CONNECT OP   
 

#define CPC   (regs.regs_PC)
 

Definition at line 386 of file sim-cheetah.c.

#define DECLARE_FAULT FAULT       { fault = (FAULT); break; }
 

#define DEFINST OP,
MSK,
NAME,
OPFORM,
RES,
FLAGS,
O1,
O2,
I1,
I2,
I3   
 

Value:

case OP:                                                        \
          SYMCAT(OP,_IMPL);                                             \
          break;

#define DEFLINK OP,
MSK,
NAME,
MASK,
SHIFT   
 

Value:

case OP:                                                        \
          panic("attempted to execute a linking opcode");

#define FPCR   (regs.regs_C.fpcr)
 

Definition at line 419 of file sim-cheetah.c.

#define FPR N       (regs.regs_F.d[N])
 

Definition at line 415 of file sim-cheetah.c.

#define FPR_Q N       (regs.regs_F.q[N])
 

Definition at line 413 of file sim-cheetah.c.

#define GPR N       (regs.regs_R[N])
 

Definition at line 389 of file sim-cheetah.c.

#define LIBCHEETAH_MAX_INST   2147483647
 

Definition at line 119 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

#define READ_BYTE SRC,
FAULT   
 

Value:

(addr = (SRC),                                                  \
   ((refs & REFS_DATA) ? cheetah_access(addr) : (void)0),               \
   (FAULT) = md_fault_none, MEM_READ_BYTE(mem, addr))

Definition at line 429 of file sim-cheetah.c.

#define READ_HALF SRC,
FAULT   
 

Value:

(addr = (SRC),                                                  \
   ((refs & REFS_DATA) ? cheetah_access(addr) : (void)0),               \
   (FAULT) = md_fault_none, MEM_READ_HALF(mem, addr))

Definition at line 433 of file sim-cheetah.c.

#define READ_WORD SRC,
FAULT   
 

Value:

(addr = (SRC),                                                  \
   ((refs & REFS_DATA) ? cheetah_access(addr) : (void)0),               \
   (FAULT) = md_fault_none, MEM_READ_WORD(mem, addr))

Definition at line 437 of file sim-cheetah.c.

#define REFS_DATA   0x02
 

Definition at line 165 of file sim-cheetah.c.

Referenced by cheetah_access_fn(), and sim_check_options().

#define REFS_INST   0x01
 

Definition at line 164 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_main().

#define SET_FPCR EXPR       (regs.regs_C.fpcr = (EXPR))
 

Definition at line 420 of file sim-cheetah.c.

#define SET_FPR N,
EXPR       (regs.regs_F.d[N] = (EXPR))
 

Definition at line 416 of file sim-cheetah.c.

#define SET_FPR_Q N,
EXPR       (regs.regs_F.q[N] = (EXPR))
 

Definition at line 414 of file sim-cheetah.c.

#define SET_GPR N,
EXPR       (regs.regs_R[N] = (EXPR))
 

Definition at line 390 of file sim-cheetah.c.

#define SET_NPC EXPR       (regs.regs_NPC = (EXPR))
 

Definition at line 383 of file sim-cheetah.c.

#define SET_UNIQ EXPR       (regs.regs_C.uniq = (EXPR))
 

Definition at line 422 of file sim-cheetah.c.

#define SYSCALL INST       sys_syscall(&regs, cheetah_access_fn, mem, INST, TRUE)
 

Definition at line 481 of file sim-cheetah.c.

#define UNIQ   (regs.regs_C.uniq)
 

Definition at line 421 of file sim-cheetah.c.

#define WRITE_BYTE SRC,
DST,
FAULT   
 

Value:

(addr = (DST),                                                  \
   ((refs & REFS_DATA) ? cheetah_access(addr) : (void)0),               \
   (FAULT) = md_fault_none, MEM_WRITE_BYTE(mem, addr, (SRC)))

Definition at line 448 of file sim-cheetah.c.

#define WRITE_HALF SRC,
DST,
FAULT   
 

Value:

(addr = (DST),                                                  \
   ((refs & REFS_DATA) ? cheetah_access(addr) : (void)0),               \
   (FAULT) = md_fault_none, MEM_WRITE_HALF(mem, addr, (SRC)))

Definition at line 452 of file sim-cheetah.c.

#define WRITE_WORD SRC,
DST,
FAULT   
 

Value:

(addr = (DST),                                                  \
   ((refs & REFS_DATA) ? cheetah_access(addr) : (void)0),               \
   (FAULT) = md_fault_none, MEM_WRITE_WORD(mem, addr, (SRC)))

Definition at line 456 of file sim-cheetah.c.


Function Documentation

enum md_fault_type cheetah_access_fn struct mem_t   mem,
enum mem_cmd    cmd,
md_addr_t    addr,
void *    p,
int    nbytes
 

Definition at line 469 of file sim-cheetah.c.

References cheetah_access(), mem_access(), mem_cmd, refs, and REFS_DATA.

00474 {
00475   if (refs & REFS_DATA)
00476     cheetah_access(addr);
00477   return mem_access(mem, cmd, addr, p, nbytes);
00478 }

char* cheetah_mstate_obj FILE *    stream,
char *    cmd,
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 315 of file sim-cheetah.c.

References cheetah_stats(), MAX, stat_print_stats(), and TRUE.

Referenced by sim_load_prog().

00319 {
00320   sim_end_time = time((time_t *)NULL);
00321   sim_elapsed_time = MAX(sim_end_time - sim_start_time, 1);
00322 
00323   /* print simulation stats */
00324   fprintf(stream, "\nsim: ** simulation statistics **\n");
00325   stat_print_stats(sim_sdb, stream);
00326 
00327   /* print libcheetah stats */
00328   cheetah_stats(stream, /* mid */TRUE);
00329 
00330   /* no error */
00331   return NULL;
00332 }

void sim_aux_config FILE *    stream
 

Definition at line 352 of file sim-cheetah.c.

References cheetah_config().

00353 {
00354   /* print libcheetah configuration */
00355   cheetah_config(stream);
00356 }

void sim_aux_stats FILE *    stream
 

Definition at line 360 of file sim-cheetah.c.

References cheetah_stats(), and FALSE.

00361 {
00362   /* print libcheetah stats */
00363   cheetah_stats(stream, /* final */FALSE);
00364 }

void sim_check_options struct opt_odb_t   odb,
int    argc,
char **    argv
 

Definition at line 224 of file sim-cheetah.c.

References cache_interval, cache_size, conf_str, fatal(), lib_argc, lib_argv, LIBCHEETAH_MAX_INST, line_size, max_assoc, max_cache, max_insts, max_sets, min_sets, mystrdup(), ref_stream, refs, REFS_DATA, REFS_INST, repl_str, and warn().

00225 {
00226   char buf[512];
00227 
00228   fprintf(stderr,
00229           "Portions Copyright (C) 1989-1993 by "
00230           "Rabin A. Sugumar and Santosh G. Abraham.\n");
00231 
00232   if (max_insts == 0 || max_insts > LIBCHEETAH_MAX_INST)
00233     {
00234       warn("sim-cheetah can only process %d instructions",
00235            LIBCHEETAH_MAX_INST);
00236       max_insts = LIBCHEETAH_MAX_INST;
00237     }
00238 
00239   if (!strcmp(ref_stream, "none"))
00240     refs = 0;
00241   else if (!strcmp(ref_stream, "inst"))
00242     refs = REFS_INST;
00243   else if (!strcmp(ref_stream, "data"))
00244     refs = REFS_DATA;
00245   else if (!strcmp(ref_stream, "unified"))
00246     refs = (REFS_INST|REFS_DATA);
00247   else
00248     fatal("bad reference stream specifier, use {inst|data|unified}");
00249 
00250   /* marshall up the libcheetah arguments */
00251   lib_argc = 0;
00252 
00253   sprintf(buf, "-R%s", repl_str);
00254   lib_argv[lib_argc++] = mystrdup(buf);
00255 
00256   sprintf(buf, "-C%s", conf_str);
00257   lib_argv[lib_argc++] = mystrdup(buf);
00258 
00259   sprintf(buf, "-a%d", min_sets);
00260   lib_argv[lib_argc++] = mystrdup(buf);
00261 
00262   sprintf(buf, "-b%d", max_sets);
00263   lib_argv[lib_argc++] = mystrdup(buf);
00264 
00265   sprintf(buf, "-l%d", line_size);
00266   lib_argv[lib_argc++] = mystrdup(buf);
00267 
00268   sprintf(buf, "-n%d", max_assoc);
00269   lib_argv[lib_argc++] = mystrdup(buf);
00270 
00271   sprintf(buf, "-i%d", cache_interval);
00272   lib_argv[lib_argc++] = mystrdup(buf);
00273 
00274   sprintf(buf, "-M%d", max_cache);
00275   lib_argv[lib_argc++] = mystrdup(buf);
00276 
00277   sprintf(buf, "-c%d", cache_size);
00278   lib_argv[lib_argc++] = mystrdup(buf);
00279 }

void sim_init void   
 

Definition at line 301 of file sim-cheetah.c.

References mem_create(), mem_init(), regs_init(), and sim_num_refs.

00302 {
00303   sim_num_refs = 0;
00304 
00305   /* allocate and initialize register file */
00306   regs_init(&regs);
00307 
00308   /* allocate and initialize memory space */
00309   mem = mem_create("mem");
00310   mem_init(mem);
00311 }

void sim_load_prog char *    fname,
int    argc,
char **    argv,
char **    envp
 

Definition at line 336 of file sim-cheetah.c.

References cheetah_init(), cheetah_mstate_obj(), dlite_init(), ld_load_prog(), lib_argc, lib_argv, and TRUE.

00339 {
00340   /* load program text and data, set up environment, memory, and regs */
00341   ld_load_prog(fname, argc, argv, envp, &regs, mem, TRUE);
00342 
00343   /* initialize the DLite debugger */
00344   dlite_init(md_reg_obj, dlite_mem_obj, cheetah_mstate_obj);
00345 
00346   /* initialize libcheetah */
00347   cheetah_init(lib_argc, lib_argv);
00348 }

void sim_main void   
 

Definition at line 485 of file sim-cheetah.c.

References ACCESS_READ, ACCESS_WRITE, cheetah_access(), md_fpr_t::d, dlite_check_break, dlite_main(), FALSE, fatal(), max_insts, MD_FETCH_INST, MD_OP_FLAGS, MD_SET_OPCODE, panic(), refs, REFS_INST, regs_t::regs_F, regs_t::regs_NPC, regs_t::regs_PC, regs_t::regs_R, sim_num_refs, and TRUE.

00486 {
00487   md_inst_t inst;
00488   register md_addr_t addr;
00489   enum md_opcode op;
00490   register int is_write;
00491   enum md_fault_type fault;
00492 
00493   fprintf(stderr, "sim: ** starting functional simulation **\n");
00494 
00495   /* set up initial default next PC */
00496   regs.regs_NPC = regs.regs_PC + sizeof(md_inst_t);
00497 
00498   /* check for DLite debugger entry condition */
00499   if (dlite_check_break(regs.regs_PC, /* no access */0, /* addr */0, 0, 0))
00500     dlite_main(regs.regs_PC - sizeof(md_inst_t), regs.regs_PC,
00501                sim_num_insn, &regs, mem);
00502 
00503   while (TRUE)
00504     {
00505       /* maintain $r0 semantics */
00506       regs.regs_R[MD_REG_ZERO] = 0;
00507 #ifdef TARGET_ALPHA
00508       regs.regs_F.d[MD_REG_ZERO] = 0.0;
00509 #endif /* TARGET_ALPHA */
00510 
00511       /* get the next instruction to execute */
00512       if (refs & REFS_INST)
00513         cheetah_access(regs.regs_PC);
00514       MD_FETCH_INST(inst, mem, regs.regs_PC);
00515 
00516       /* keep an instruction count */
00517       sim_num_insn++;
00518 
00519       /* set default reference address and access mode */
00520       addr = 0; is_write = FALSE;
00521 
00522       /* set default fault - none */
00523       fault = md_fault_none;
00524 
00525       /* decode the instruction */
00526       MD_SET_OPCODE(op, inst);
00527 
00528       /* execute the instruction */
00529       switch (op)
00530         {
00531 #define DEFINST(OP,MSK,NAME,OPFORM,RES,FLAGS,O1,O2,I1,I2,I3)            \
00532         case OP:                                                        \
00533           SYMCAT(OP,_IMPL);                                             \
00534           break;
00535 #define DEFLINK(OP,MSK,NAME,MASK,SHIFT)                                 \
00536         case OP:                                                        \
00537           panic("attempted to execute a linking opcode");
00538 #define CONNECT(OP)
00539 #define DECLARE_FAULT(FAULT)                                            \
00540           { fault = (FAULT); break; }
00541 #include "machine.def"
00542         default:
00543           panic("attempted to execute a bogus opcode");
00544       }
00545 
00546       if (fault != md_fault_none)
00547         fatal("fault (%d) detected @ 0x%08p", fault, regs.regs_PC);
00548 
00549       if (MD_OP_FLAGS(op) & F_MEM)
00550         {
00551           sim_num_refs++;
00552           if (MD_OP_FLAGS(op) & F_STORE)
00553             is_write = TRUE;
00554         }
00555 
00556       /* check for DLite debugger entry condition */
00557       if (dlite_check_break(regs.regs_NPC,
00558                             is_write ? ACCESS_WRITE : ACCESS_READ,
00559                             addr, sim_num_insn, sim_num_insn))
00560         dlite_main(regs.regs_PC, regs.regs_NPC, sim_num_insn, &regs, mem);
00561 
00562       /* go to the next instruction */
00563       regs.regs_PC = regs.regs_NPC;
00564       regs.regs_NPC += sizeof(md_inst_t);
00565 
00566       /* finish early? */
00567       if (max_insts && sim_num_insn >= max_insts)
00568         return;
00569     }
00570 }

void sim_reg_options struct opt_odb_t   odb
 

Definition at line 170 of file sim-cheetah.c.

References cache_interval, cache_size, conf_str, LIBCHEETAH_MAX_INST, line_size, max_assoc, max_cache, max_insts, max_sets, min_sets, opt_reg_header(), opt_reg_int(), opt_reg_string(), opt_reg_uint(), ref_stream, repl_str, and TRUE.

00171 {
00172   opt_reg_header(odb, 
00173 "sim-cheetah: This program implements a functional simulator driver for\n"
00174 "Cheetah.  Cheetah is a cache simulation package written by Rabin Sugumar\n"
00175 "and Santosh Abraham which can efficiently simulate multiple cache\n"
00176 "configurations in a single run of a program.  Specifically, Cheetah can\n"
00177 "simulate ranges of single level set-associative and fully-associative\n"
00178 "caches.  See the directory libcheetah/ for more details on Cheetah.\n"
00179                  );
00180 
00181   /* instruction limit */
00182   opt_reg_uint(odb, "-max:inst", "maximum number of inst's to execute",
00183                &max_insts, /* default */LIBCHEETAH_MAX_INST,
00184                /* print */TRUE, /* format */NULL);
00185 
00186   opt_reg_string(odb, "-refs",
00187                  "reference stream to analyze, i.e., {none|inst|data|unified}",
00188                  &ref_stream, "data", /* print */TRUE, /* format */NULL);
00189 
00190   opt_reg_string(odb, "-R", "replacement policy, i.e., lru or opt",
00191                  &repl_str, "lru", /* print */TRUE, /* format */NULL);
00192 
00193   opt_reg_string(odb, "-C", "cache configuration, i.e., fa, sa, or dm",
00194                  &conf_str, "sa", /* print */TRUE, /* format */NULL);
00195 
00196   opt_reg_int(odb, "-a", "min number of sets (log base 2, line size for DM)",
00197               &min_sets, 7, /* print */TRUE, /* format */NULL);
00198 
00199   opt_reg_int(odb, "-b", "max number of sets (log base 2, line size for DM)",
00200               &max_sets, 14, /* print */TRUE, /* format */NULL);
00201 
00202   opt_reg_int(odb, "-l", "line size of the caches (log base 2)",
00203               &line_size, 4, /* print */TRUE, /* format */NULL);
00204 
00205   opt_reg_int(odb, "-n", "max degree of associativity to analyze (log base 2)",
00206               &max_assoc, 1, /* print */TRUE, /* format */NULL);
00207 
00208   opt_reg_int(odb, "-in", "cache size intervals at which miss ratio is shown",
00209               &cache_interval, 512, /* print */TRUE, /* format */NULL);
00210 
00211   opt_reg_int(odb, "-M", "maximum cache size of interest",
00212               &max_cache, 524288, /* print */TRUE, /* format */NULL);
00213 
00214   opt_reg_int(odb, "-c", "size of cache (log base 2) for DM analysis",
00215               &cache_size, 16, /* print */TRUE, /* format */NULL);
00216 }

void sim_reg_stats struct stat_sdb_t   sdb
 

Definition at line 283 of file sim-cheetah.c.

References sim_num_refs, stat_reg_counter, stat_reg_formula(), and stat_reg_int().

00284 {
00285   stat_reg_counter(sdb, "sim_num_insn",
00286                    "total number of instructions executed",
00287                    &sim_num_insn, sim_num_insn, NULL);
00288   stat_reg_counter(sdb, "sim_num_refs",
00289                    "total number of loads and stores executed",
00290                    &sim_num_refs, 0, NULL);
00291   stat_reg_int(sdb, "sim_elapsed_time",
00292                "total simulation time in seconds",
00293                (int *)&sim_elapsed_time, 0, NULL);
00294   stat_reg_formula(sdb, "sim_inst_rate",
00295                    "simulation speed (in insts/sec)",
00296                    "sim_num_insn / sim_elapsed_time", NULL);
00297 }

void sim_uninit void   
 

Definition at line 368 of file sim-cheetah.c.

00369 {
00370   /* nada */
00371 }


Variable Documentation

int cache_interval [static]
 

Definition at line 152 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

int cache_size [static]
 

Definition at line 158 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

char* conf_str [static]
 

Definition at line 137 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

int lib_argc = 0 [static]
 

Definition at line 219 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_load_prog().

char* lib_argv[16] [static]
 

Definition at line 220 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_load_prog().

int line_size [static]
 

Definition at line 146 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

int max_assoc [static]
 

Definition at line 149 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

int max_cache [static]
 

Definition at line 155 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

unsigned int max_insts [static]
 

Definition at line 131 of file sim-cheetah.c.

Referenced by sim_check_options(), sim_main(), and sim_reg_options().

int max_sets [static]
 

Definition at line 143 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

struct mem_t* mem = NULL [static]
 

Definition at line 125 of file sim-cheetah.c.

int min_sets [static]
 

Definition at line 140 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

char* ref_stream [static]
 

Definition at line 161 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

int refs [static]
 

Definition at line 166 of file sim-cheetah.c.

Referenced by cheetah_access_fn(), sim_check_options(), and sim_main().

struct regs_t regs [static]
 

Definition at line 122 of file sim-cheetah.c.

char* repl_str [static]
 

Definition at line 134 of file sim-cheetah.c.

Referenced by sim_check_options(), and sim_reg_options().

counter_t sim_num_refs = 0 [static]
 

Definition at line 128 of file sim-cheetah.c.

Referenced by sim_init(), sim_main(), and sim_reg_stats().



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214