"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  

libcheetah.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include "../host.h"
#include "../misc.h"
#include "../machine.h"
#include "util.h"
#include "libcheetah.h"

Include dependency graph for libcheetah.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define BASIC   5
 

Definition at line 35 of file libcheetah.c.

#define BYTES_PER_LINE   35
 

Definition at line 39 of file libcheetah.c.

Referenced by cheetah_init().

#define DIN   7
 

Definition at line 37 of file libcheetah.c.

#define DM   4
 

Definition at line 34 of file libcheetah.c.

Referenced by cheetah_access(), cheetah_config(), cheetah_init(), and cheetah_stats().

#define FA   3
 

Definition at line 33 of file libcheetah.c.

Referenced by cheetah_access(), cheetah_config(), cheetah_init(), and cheetah_stats().

#define LRU   0
 

Definition at line 30 of file libcheetah.c.

Referenced by cheetah_access(), cheetah_init(), and cheetah_stats().

#define MAX_PHYSICAL_MEM   8388608
 

Definition at line 28 of file libcheetah.c.

Referenced by cheetah_init().

#define NOT   !
 

Definition at line 26 of file libcheetah.c.

Referenced by cheetah_init().

#define ONE   1U
 

Definition at line 27 of file libcheetah.c.

Referenced by cheetah_config(), and cheetah_init().

#define OPT   1
 

Definition at line 31 of file libcheetah.c.

Referenced by cheetah_access(), cheetah_init(), and cheetah_stats().

#define PIXIE   6
 

Definition at line 36 of file libcheetah.c.

#define SA   2
 

Definition at line 32 of file libcheetah.c.

Referenced by cheetah_access(), cheetah_config(), cheetah_init(), and cheetah_stats().


Function Documentation

void cheetah_access md_addr_t    addr
 

Definition at line 344 of file libcheetah.c.

References DM, dmvl(), FA, L, LRU, OPT, optpp(), ptc(), repl, SA, and sacnmul_woarr().

Referenced by cheetah_access_fn(), and sim_main().

00345 {
00346   switch (trace_config)
00347     {
00348     case SA:
00349       if (repl == LRU)
00350         sacnmul_woarr(addr);
00351       else if (repl == OPT)
00352         optpp(addr, L, stack_proc_sa, inf_handler_sa);
00353       break;
00354 
00355     case FA:
00356       if (repl == LRU)
00357         ptc(addr);
00358       else if (repl == OPT)
00359         optpp(addr, L, stack_proc_fa, inf_handler_fa);
00360       break;
00361 
00362     case DM:
00363       dmvl(addr);
00364       break;
00365     
00366     default:
00367       fprintf (stderr, "libcheetah: configuration wrongly set\n");
00368       exit (1);
00369     }
00370 }

void cheetah_config FILE *    fd
 

Definition at line 306 of file libcheetah.c.

References A, B, C, DM, FA, L, MAX_CACHE_SIZE, N, ONE, outstrings, repl, SA, and trace_config.

Referenced by sim_aux_config().

00307 {
00308   fprintf(fd, "\nlibcheetah: ** simulation parameters **\n");
00309   if (trace_config != DM)
00310     fprintf(fd, "libcheetah: %s %s caches being simulated\n",
00311             outstrings[repl], outstrings[trace_config]);
00312   else
00313     fprintf(fd, "libcheetah: %s caches being simulated\n",
00314             outstrings[trace_config]);
00315 
00316   switch (trace_config)
00317     {
00318     case SA:
00319       fprintf(fd, "libcheetah: number of sets from %d to %d\n",
00320               (ONE << A), (ONE << B));
00321       fprintf(fd, "libcheetah: maximum associativity is %d\n", (ONE << N));
00322       fprintf(fd, "libcheetah: line size is %d bytes\n", (ONE << L));
00323       break;
00324     
00325     case FA:
00326       fprintf(fd, "libcheetah: max cache size is %d bytes\n", MAX_CACHE_SIZE);
00327       fprintf(fd, "libcheetah: line size is %d bytes\n", (ONE << L));
00328       break;
00329 
00330     case DM:
00331       fprintf(fd, "libcheetah: cache size is %d bytes\n", (ONE << C));
00332       fprintf(fd, "libcheetah: line sizes from %d to %d bytes\n",
00333               (ONE << A), (ONE << B));
00334       break;
00335 
00336     default:
00337       fprintf(stderr, "libcheetah: configuration wrongly set.\n");
00338       exit (1);
00339     }
00340 }

void cheetah_init int    argc,
char **    argv
 

Definition at line 92 of file libcheetah.c.

References A, B, BYTES_PER_LINE, C, DM, FA, init_dmvl(), init_faclru(), init_facopt(), init_optpp(), init_saclru(), init_sacopt(), initialized, L, LRU, MAX_CACHE_SIZE, MAX_LINES, MAX_PHYSICAL_MEM, MISS_RATIO_INTERVAL, N, NOT, ONE, OPT, P_INTERVAL, repl, SA, SAVE_INTERVAL, T, and trace_config.

Referenced by sim_load_prog().

00093 {
00094   short i;
00095 
00096   if (initialized)
00097     {
00098       fprintf(stderr, "libcheetah: already initialized\n");
00099       exit(1);
00100     }
00101   initialized = 1;
00102 
00103   /* Default Settings */
00104   A = 7;
00105   B = 14;
00106   L = 4;
00107   N = 1;
00108   C = 16;
00109   T = 0x7fffffff;
00110   MAX_CACHE_SIZE = 524288;
00111   MISS_RATIO_INTERVAL = 512;
00112   P_INTERVAL = 0x7fffffff;
00113   SAVE_INTERVAL = 0x7fffffff;
00114   trace_config = SA;
00115   repl = LRU;
00116 
00117   /* Command line settings */
00118   for (i=0; i < argc; i++)
00119     {
00120       if (argv[i][0] != '-')
00121         {
00122           fprintf(stderr, "libcheetah: illegal argument `%s'\n", argv[i]);
00123           exit(1);
00124         }
00125       else
00126         {
00127           switch(argv[i][1])
00128             {
00129             /* -R<repl> replacement policy */
00130             case 'R':
00131               if ((NOT strcmp ("lru", &argv[i][2]))
00132                   || (NOT strcmp ("LRU", &argv[i][2])))
00133                 repl = LRU;
00134               else if ((NOT strcmp ("opt", &argv[i][2]))
00135                        || (NOT strcmp ("OPT", &argv[i][2])))
00136                 {
00137                   repl = OPT;
00138                 }
00139               else
00140                 {
00141                   fprintf (stderr,
00142                            "libcheetah: replacement policy `%s' "
00143                            "not supported\n",
00144                            &argv[i][2]);
00145                   exit (1);
00146                 }
00147               break;
00148 
00149             /* -C<config> cache configuration */
00150             case 'C':
00151               if ((NOT strcmp ("fa", &argv[i][2]))
00152                   || (NOT strcmp ("FA", &argv[i][2])))
00153                 trace_config = FA;
00154               else if ((NOT strcmp ("sa", &argv[i][2]))
00155                        || (NOT strcmp ("SA", &argv[i][2])))
00156                 trace_config = SA;
00157               else if ((NOT strcmp ("dm", &argv[i][2]))
00158                        || (NOT strcmp ("DM", &argv[i][2])))
00159                 trace_config = DM;
00160               else
00161                 {
00162                   fprintf (stderr,
00163                            "libcheetah: configuration `%s' not supported\n",
00164                            &argv[i][2]);
00165                   exit (1);
00166                 }
00167               break;
00168 
00169             /* -a<num> minimum number of sets */
00170             case 'a':
00171               A = atoi(&argv[i][2]);
00172               break;
00173 
00174             /* -b<num> maximum number of sets */
00175             case 'b':
00176               B = atoi(&argv[i][2]);
00177               break;
00178 
00179             /* -l<num> log of the line size of the caches */
00180             case 'l':
00181               L = atoi(&argv[i][2]);
00182               break;
00183 
00184             /* -n<num> log of the maximum degree of associativity */
00185             case 'n':
00186               N = atoi(&argv[i][2]);
00187               break;
00188 
00189             /* -i<num> cache size intervals at which miss ratio is desired */
00190             case 'i':
00191               MISS_RATIO_INTERVAL = atoi(&argv[i][2]);
00192               break;
00193 
00194             /* -M<num> maximum cache size of interest */
00195             case 'M':
00196               MAX_CACHE_SIZE = atoi(&argv[i][2]);
00197               break;
00198 
00199             case 'c':
00200               C = atoi(&argv[i][2]);
00201               break;
00202 
00203 #if 0 /* unneeded */
00204             case 't':
00205               T = atoi(&argv[i][2]);
00206               break;
00207 #endif
00208 
00209 #if 0 /* unneeded */
00210             case 's':
00211               SAVE_INTERVAL = atoi(&argv[i][2]);
00212               break;
00213 #endif
00214 
00215 #if 0 /* unneeded */
00216             case 'p':
00217               P_INTERVAL = atoi(&argv[i][2]);
00218               break;
00219 #endif
00220 
00221             default:
00222               fprintf(stderr, "libcheetah: `-%c' is not a valid option\n",
00223                       argv[i][1]);
00224             }
00225         }
00226     }
00227 
00228   /* initialize modules */
00229   switch (trace_config)
00230     {
00231     case SA:
00232       if (A > B)
00233         {
00234           fprintf(stderr, "libcheetah: min number of sets greater than max\n");
00235           exit (1);
00236         }
00237     
00238       if (repl == LRU)
00239         init_saclru();
00240       else if (repl == OPT)
00241         {
00242           init_sacopt();
00243           init_optpp();
00244         }
00245       break;
00246     
00247     case FA:
00248       if ((int)(ONE << L) > MISS_RATIO_INTERVAL)
00249         {
00250           fprintf(stderr, "libcheetah: line size > output interval!!\n");
00251           fprintf(stderr,
00252                   "libcheetah: output interval changed to line size\n");
00253           MISS_RATIO_INTERVAL = 1;
00254         }
00255       else
00256         MISS_RATIO_INTERVAL = MISS_RATIO_INTERVAL/(ONE << L);
00257     
00258       if (MAX_CACHE_SIZE < (ONE << L))
00259         {
00260           fprintf(stderr,
00261                   "libcheetah: max cache size is less than line size\n");
00262           exit (1);
00263         }
00264       else
00265         {
00266           MAX_LINES = MAX_CACHE_SIZE / (ONE << L);
00267           if ((MAX_LINES*BYTES_PER_LINE) > MAX_PHYSICAL_MEM)
00268             fprintf(stderr,
00269                     "libcheetah: warning: mem limit may be exceeded\n");
00270         }
00271     
00272       if (repl == LRU)
00273         init_faclru();
00274       else if (repl == OPT)
00275         {
00276           init_facopt();
00277           init_optpp();
00278         }
00279       break;
00280 
00281     case DM:
00282       if (A > B)
00283         {
00284           fprintf (stderr,
00285                    "libcheetah: min line size greater than max line\n");
00286           exit (1);
00287         }
00288       if (B > C)
00289         {
00290           fprintf (stderr,
00291                    "libcheetah: max line size greater than cache size\n");
00292           exit (1);
00293         }
00294     
00295       init_dmvl();
00296       break;
00297     
00298     default:
00299       fprintf (stderr, "libcheetah: configuration wrongly set\n");
00300       exit (1);
00301     }
00302 }

void cheetah_stats FILE *    fd,
int    mid
 

Definition at line 374 of file libcheetah.c.

References DM, FA, LRU, OPT, outpr_dmvl(), outpr_faclru(), outpr_facopt(), outpr_saclru(), outpr_sacopt(), repl, SA, and term_optpp().

Referenced by cheetah_mstate_obj(), and sim_aux_stats().

00376 {
00377   fprintf(fd, "\nlibcheetah: ** end of simulation **\n");
00378 
00379   switch (trace_config)
00380     {
00381     case SA:
00382       if (repl == LRU)
00383         outpr_saclru(fd);
00384       else if (repl == OPT)
00385         {
00386           if (!mid) term_optpp(stack_proc_sa);
00387           outpr_sacopt(fd);
00388         }
00389       break;
00390 
00391     case FA:
00392       if (repl == LRU)
00393         outpr_faclru(fd);
00394       else if (repl == OPT)
00395         {
00396           if (!mid) term_optpp(stack_proc_fa);
00397           outpr_facopt(fd);
00398         }
00399       break;
00400 
00401     case DM:
00402       outpr_dmvl(fd);
00403       break;
00404 
00405     default:
00406       fprintf(stderr, "libcheetah: configuration wrongly set\n");
00407       exit(1);
00408     }
00409 }


Variable Documentation

int A
 

Definition at line 43 of file libcheetah.c.

Referenced by cheetah_config(), and cheetah_init().

int B
 

Definition at line 42 of file libcheetah.c.

Referenced by cheetah_config(), and cheetah_init().

int C
 

Definition at line 45 of file libcheetah.c.

Referenced by cheetah_config(), and cheetah_init().

int initialized = 0 [static]
 

Definition at line 88 of file libcheetah.c.

Referenced by cheetah_init().

int L
 

Definition at line 44 of file libcheetah.c.

Referenced by cheetah_access(), cheetah_config(), cheetah_init(), and outpr_sacopt().

unsigned MAX_CACHE_SIZE
 

Definition at line 49 of file libcheetah.c.

Referenced by cheetah_config(), and cheetah_init().

unsigned MAX_LINES
 

Definition at line 50 of file libcheetah.c.

Referenced by cheetah_init(), init_facopt(), outpr_facopt(), process_groups(), and stack_proc_fa().

int MISS_RATIO_INTERVAL
 

Definition at line 51 of file libcheetah.c.

Referenced by cheetah_init(), and outpr_facopt().

int N
 

Definition at line 41 of file libcheetah.c.

Referenced by cheetah_config(), cheetah_init(), and init_sacopt().

char* outstrings[]
 

Initial value:

 {  "LRU",
                        "OPT",
                        "Set-associative",
                        "Fully-associative",
                        "Direct-mapped",
                        "Basic",
                        "Pixie",
                        "DIN",
                        "an instruction",
                        "a load",
                        " ",
                        "a store",
                        " ",
                        "a data",
                        "a unified"
                     }

Definition at line 55 of file libcheetah.c.

Referenced by cheetah_config().

int P_INTERVAL
 

Definition at line 47 of file libcheetah.c.

Referenced by cheetah_init(), and stack_proc_sa().

short repl
 

Definition at line 85 of file libcheetah.c.

Referenced by cheetah_access(), cheetah_config(), cheetah_init(), and cheetah_stats().

int SAVE_INTERVAL
 

Definition at line 52 of file libcheetah.c.

Referenced by cheetah_init(), init_sacopt(), and stack_proc_sa().

int T
 

Definition at line 46 of file libcheetah.c.

Referenced by cheetah_init().

int trace_config
 

Definition at line 82 of file libcheetah.c.

Referenced by cheetah_config(), and cheetah_init().



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