"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.h File Reference

#include <stdio.h>

Include dependency graph for libcheetah.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

Variables


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 }

void dmvl md_addr_t    addr
 

Definition at line 119 of file dmvl.c.

References lm_arr, next_save_time, ONE, outpr_dmvl(), P_INTERVAL, RCACHE_SZ, rhits_arr, RMAX_LINE_SZ, RMIN_LINE_SZ, RNO_LINES, rset_arr, rtag_arr, RTAG_MASK, RTAG_SET1_MASK, SAVE_INTERVAL, t_entries, and tag.

Referenced by cheetah_access().

00120 {
00121   unsigned orig_tag,            /* Tag field of address */
00122         tag;            /* Tag removed from prev level */
00123         
00124   /* addr = tt111112222llll . t-tag 1-set;fld 1;2-set fld 2;l-ln fld */
00125   unsigned set1,                /* Set field 1 of addr. For selecting BT */
00126         orig_set2,              /* Set field 2 of addr. Stored in BT */
00127         set2;           /* Set field 2 removed from prev level */
00128   unsigned st, tg;              /* Temps used ot reduce array refns */
00129   int entry,                    /* Scratch */
00130         pos;                    /* Array posn. being examined */
00131   int depth,                    /* Level being examined */
00132         set2_match;             /* Scratch */
00133   unsigned *rtag_arr_set1, *rset_arr_set1;
00134 
00135   t_entries++;
00136   if ((t_entries % P_INTERVAL) == 0)
00137     fprintf(stderr, "libcheetah: addresses processed  %d\n", t_entries);
00138 
00139   set1 = (addr & RTAG_MASK) >> RMAX_LINE_SZ;
00140   orig_tag = addr >> RCACHE_SZ;
00141   orig_set2 = (addr & RTAG_SET1_MASK) >> RMIN_LINE_SZ;
00142 #ifdef PERF
00143   ++compares;
00144 #endif
00145   if (rset_arr[set1][0] == orig_set2)
00146     {
00147       if (rtag_arr[set1][0] == orig_tag)
00148         {
00149           /* Level 0 hit */
00150           ++rhits_arr[0][RNO_LINES-1];
00151         } 
00152       else
00153         rtag_arr[set1][0] = orig_tag;
00154     }
00155   else
00156     {
00157       rtag_arr_set1 = *(rtag_arr + set1);
00158       rset_arr_set1 = *(rset_arr + set1);
00159       tg = rtag_arr_set1[0];
00160       st = rset_arr_set1[0];
00161       depth = 0;
00162       set2_match = lm_arr[(st ^ orig_set2)];
00163       if (tg == orig_tag)
00164         ++rhits_arr[0][set2_match];
00165       depth = set2_match + 1;
00166       tag = tg;
00167       rtag_arr_set1[0] = orig_tag;
00168       set2 = st;
00169       rset_arr_set1[0] = orig_set2;
00170       entry = set2 >> (RNO_LINES - depth );
00171       pos = entry + (ONE << (depth - 1));
00172 
00173       while ((unsigned)depth < RNO_LINES)
00174         {
00175 #ifdef PERF
00176           ++compares;
00177 #endif
00178           tg = rtag_arr_set1[pos];
00179           st = rset_arr_set1[pos];
00180           if (st == orig_set2)
00181             {
00182               if (tg == orig_tag)
00183                 { 
00184                   /* Hit at level 1 or greater */
00185                   ++rhits_arr[depth][RNO_LINES-1];
00186                 }
00187               rtag_arr_set1[pos] = tag;
00188               rset_arr_set1[pos] = set2;
00189               break;
00190             }
00191           set2_match = lm_arr[(st ^ orig_set2)];
00192           if (tg == orig_tag)
00193             ++rhits_arr[depth][set2_match];
00194           depth = set2_match + 1;
00195           rtag_arr_set1[pos] = tag;
00196           tag = tg;
00197           rset_arr_set1[pos] = set2;
00198           set2 = st;
00199           entry = set2 >> (RNO_LINES - depth );
00200           pos = entry + (ONE << (depth - 1));
00201         }
00202     }
00203   if (t_entries > next_save_time)
00204     {
00205       outpr_dmvl(stderr);
00206       next_save_time += SAVE_INTERVAL;
00207     }
00208 }

void ft_hash_del md_addr_t    addr
 

Definition at line 138 of file ppopt.c.

References ft_hash_table::addr, ft_slot, ft_slot_flag, HASHNO, LA_Add_to_free_list(), ft_hash_table::nxt, and ft_hash_table::pt.

Referenced by gfsoptls(), and process_groups().

00139 {
00140   int loc;             /* Scratch variables */
00141   struct ft_hash_table *ptr, *oldptr;
00142 
00143   loc = addr % HASHNO;
00144   if (ft_slot_flag[loc] == 0)
00145     printf ("Error: addr not found in hash_table\n");
00146   else if (ft_slot[loc].addr == addr)
00147     {
00148       if (ft_slot[loc].nxt == NULL)
00149         ft_slot_flag[loc] = 0;
00150       else
00151         {
00152           ft_slot[loc].addr = ft_slot[loc].nxt->addr;
00153           ft_slot[loc].pt = ft_slot[loc].nxt->pt;
00154           ptr = ft_slot[loc].nxt;
00155           ft_slot[loc].nxt = ft_slot[loc].nxt->nxt;
00156           LA_Add_to_free_list(ptr);
00157         }
00158     }
00159   else
00160     {
00161       ptr = &ft_slot[loc];
00162       while (ptr)
00163         {
00164           if (ptr->addr == addr)
00165             break;
00166           oldptr = ptr;
00167           ptr = ptr->nxt;
00168         }
00169       if (ptr)
00170         {
00171           oldptr->nxt = ptr->nxt;
00172           LA_Add_to_free_list(ptr);
00173         }
00174       else
00175         printf("Error: addr not found in hash_table\n");
00176     }
00177 }

void inf_handler_fa md_addr_t    addr,
int    cur_time
 

Definition at line 1287 of file facopt.c.

References tree_node::addr, Delete(), group_desc::first, Get_first_unknown_wobacking(), tree_node::grpno, group_desc::grpno, ihcount, Insert(), group_desc::last, MAXINT, group_desc::nxt, tree_node::prty, unk_hash_del_fa(), and unknowns.

01288 {
01289   struct tree_node *line_to_be_ins, /* scratch pointers */
01290         *line_to_be_del,
01291         *prev_entry;
01292   struct group_desc *grpptr;    /* scratch */
01293   int addr_grptime,             /* group time marker for unknown */
01294         addr_prty;
01295   int priority, /* fn of cur_time */
01296         del_prty;       /* prty of deleted entry (during rearrangement) */
01297   static struct tree_node dummy_for_del_line;
01298   /* One extra node is allocated for del_line which changes */
01299   static struct tree_node *del_line = &dummy_for_del_line;
01300 
01301   ++ihcount;
01302 
01303   priority = MAXINT - cur_time; /* assumes a priority function */
01304 
01305   if ((headgrp.first != NULL) && (headgrp.first->addr == addr))
01306     {
01307       if (headgrp.first->prty > 0)
01308         fprintf(stderr, "libcheetah: unknown has > 0 prty\n");
01309       else
01310         headgrp.first->prty = priority;
01311       return;
01312     }
01313 
01314   addr_grptime = unk_hash_del_fa (addr, &addr_prty);
01315   if (addr_grptime == 0)
01316     return;
01317 
01318   --unknowns;
01319 
01320   grpptr = headgrp.nxt; /* assumed that a unknown is not fixed
01321                            when it is at the top */
01322 
01323   /*printf ("inf_handler addr: %d %d\n", addr, addr_grptime);
01324     traverse(root);*/
01325 
01326   while (grpptr)
01327     {
01328       if (grpptr->grpno < addr_grptime)
01329         grpptr = grpptr->nxt;
01330       else
01331         break;
01332     }
01333 
01334   /* if (grpptr == NULL)
01335      printf ("Error in inf_handler: addr_grptime not found\n"); */
01336 
01337   while (grpptr)
01338     {
01339       if (grpptr->last->prty > 0)
01340         grpptr  = grpptr->nxt;
01341       else
01342         break;
01343     }
01344 
01345   /* if (grpptr == NULL)
01346      printf ("Error in inf_handler: no unknowns found\n"); */
01347 
01348   line_to_be_ins = del_line;
01349   line_to_be_ins->prty = priority;
01350   line_to_be_ins->addr = addr;
01351 
01352   del_prty = 0;
01353   while (grpptr)
01354     {
01355       line_to_be_del =
01356         Get_first_unknown_wobacking (grpptr->grpno, addr_prty, del_prty);
01357       if (line_to_be_del != NULL)
01358         {
01359           line_to_be_ins->grpno = grpptr->grpno;
01360           Insert(line_to_be_ins);
01361           if (line_to_be_ins->prty > grpptr->first->prty)
01362             grpptr->first = line_to_be_ins;
01363           line_to_be_ins = Delete(line_to_be_del, &prev_entry);
01364           if (grpptr->last == line_to_be_del)
01365             grpptr->last = prev_entry;
01366           if (line_to_be_del->prty == addr_prty)
01367             break;
01368           del_prty = line_to_be_ins->prty;
01369         }
01370       grpptr = grpptr->nxt;
01371     }
01372   del_line = line_to_be_ins;
01373 
01374   /* if (grpptr == NULL)
01375      printf ("Error in inf_handler: unknown not found\n"); */
01376 }

void inf_handler_sa md_addr_t    addr,
int    cur_time
 

Definition at line 548 of file sacopt.c.

References A, all_hit_flag, B, BASE_CACHE_SIZE, MAXINT, ONE, prty_arr, SET_SIZE, tag_arr, TWO, TWO_PWR_N, unk_hash_del_sa(), and unknowns.

00549 {
00550   unsigned setno, orig_tag, cache_size,
00551         de_tag, rem_tag, prev_addr,
00552         cache_ptr, set_ptr, base_setno;
00553   int de_prty, rem_prty,
00554         old_prty, priority,
00555         real_prty;
00556   int i, j;
00557 
00558   old_prty = unk_hash_del_sa(addr);
00559   if (old_prty == 0)
00560     return;
00561 
00562   --unknowns;
00563 
00564   priority = MAXINT - cur_time; /* Assumes a priority function */
00565 
00566   base_setno = addr & ((ONE << A) -1);
00567   if (all_hit_flag[base_setno])
00568     {
00569       all_hit_flag[base_setno] = 0;
00570       real_prty = prty_arr[base_setno * SET_SIZE];
00571       prev_addr = (tag_arr[base_setno * SET_SIZE] << A) | base_setno;
00572       cache_ptr = BASE_CACHE_SIZE;
00573       for (i=A+1; i<=B; i++)
00574         {
00575           setno = prev_addr & ((ONE << i) - 1);
00576           set_ptr = cache_ptr + (setno * SET_SIZE);
00577           prty_arr[set_ptr] = real_prty;
00578           cache_ptr = TWO*cache_ptr + BASE_CACHE_SIZE;
00579         }
00580     }
00581   orig_tag = addr >> A;
00582   i = A;
00583   cache_size = BASE_CACHE_SIZE;
00584   cache_ptr = 0;
00585   while (i <= B)
00586     {
00587       de_tag = orig_tag;
00588       de_prty = priority;
00589       setno = addr & ((ONE << i) - 1);
00590       set_ptr = cache_ptr + (setno * SET_SIZE);
00591       for (j=0; j < TWO_PWR_N; j++)
00592         {
00593 #ifdef PERF
00594           ++compares;
00595 #endif
00596           if (tag_arr[set_ptr + j] == orig_tag)
00597             {
00598               if (prty_arr[set_ptr + j] > 0)
00599                 fprintf(stderr, "libcheetah: inconsistency in inf_handler\n");
00600               else
00601                 {
00602                   tag_arr[set_ptr + j] = de_tag;
00603                   prty_arr[set_ptr + j] = de_prty;
00604                   break;
00605                 }
00606             }
00607           else if (prty_arr[set_ptr + j] < 0)
00608             {
00609               if (old_prty < prty_arr[set_ptr + j])
00610                 {
00611                   if (de_prty > prty_arr[set_ptr + j])
00612                     {
00613                       rem_tag = tag_arr[set_ptr + j];
00614                       tag_arr[set_ptr + j] = de_tag;
00615                       de_tag = rem_tag;
00616                       rem_prty = prty_arr[set_ptr + j];
00617                       prty_arr[set_ptr + j] = de_prty;
00618                       de_prty = rem_prty;
00619                     }
00620                 }
00621             }
00622         } /*for*/
00623       cache_ptr += cache_size;
00624       cache_size += cache_size;
00625       ++i;
00626     } /*while*/
00627 }

void init_dmvl void   
 

Definition at line 219 of file dmvl.c.

References CACHE_SZ, fatal(), hits, hits_arr, idim2(), lm_arr, MAX_LINE_SZ, MAX_SET_SZ, MIN_LINE_SZ, MIN_SET_SZ, next_save_time, NO_LINES, ONE, RCACHE_SZ, rhits_arr, RMAX_LINE_SZ, RMIN_LINE_SZ, RNO_LINES, rset_arr, rtag_arr, RTAG_MASK, RTAG_SET1_MASK, SAVE_INTERVAL, set_arr, SUB_ZERO, t, tag_arr, TAG_MASK, and TAG_SET1_MASK.

Referenced by cheetah_init().

00220 {
00221   int i;
00222   unsigned depth, k;
00223   unsigned st, t;
00224 
00225   MIN_LINE_SZ = A;
00226   MAX_LINE_SZ = B;
00227   CACHE_SZ = C;
00228 
00229   NO_LINES = MAX_LINE_SZ - MIN_LINE_SZ + 1;
00230   MAX_SET_SZ =  (CACHE_SZ - MIN_LINE_SZ);
00231   MIN_SET_SZ =  (CACHE_SZ - MAX_LINE_SZ);
00232 
00233   TAG_MASK = (( ONE << CACHE_SZ) - ONE );
00234   TAG_SET1_MASK = ((ONE << MAX_LINE_SZ) - ONE);
00235 
00236 
00237   tag_arr = idim2((ONE << MIN_SET_SZ), (ONE << (NO_LINES-1)));
00238   set_arr = idim2((ONE << MIN_SET_SZ), (ONE << (NO_LINES-1)));
00239   hits_arr = idim2((NO_LINES), (NO_LINES));
00240 
00241   lm_arr = calloc((ONE << (NO_LINES - 1)), sizeof(int));
00242   if (!lm_arr)
00243     fatal("out of virtual memory");
00244 
00245   hits = calloc((MAX_LINE_SZ+1), sizeof(int));
00246   if (!hits)
00247     fatal("out of virtual memory");
00248   
00249   for (i=0; i < (ONE<<MIN_SET_SZ); i++)
00250     {
00251       set_arr[i][0] = 0;
00252       tag_arr[i][0] = SUB_ZERO;
00253       for (depth= 1; depth < NO_LINES; depth++)
00254         {
00255           st = ONE << (depth-1);
00256           t = ONE << (NO_LINES - depth);
00257           set_arr[i][st] = ONE << (NO_LINES-depth-1);
00258           tag_arr[i][st] = SUB_ZERO;
00259           for (k=1; k<st; k++)
00260             {
00261               set_arr[i][st+k] = set_arr[i][st+k-1] + t;
00262               tag_arr[i][st+k] = SUB_ZERO;
00263             }
00264         }
00265     }
00266 
00267   t = ONE;
00268   st = NO_LINES - 1;
00269   for (i=0; i < (ONE << (NO_LINES - 1)); i++)
00270     {
00271       if (t > (unsigned)i)
00272         lm_arr[i] = st;
00273       else
00274         {
00275           t <<= ONE;
00276           st -= 1;
00277           lm_arr[i] = st;
00278         }
00279     }
00280 
00281   rtag_arr = tag_arr;
00282   rset_arr = set_arr;
00283   rhits_arr = hits_arr;
00284   next_save_time = SAVE_INTERVAL;
00285 
00286   RTAG_MASK=TAG_MASK;
00287   RMAX_LINE_SZ=MAX_LINE_SZ;
00288   RCACHE_SZ=CACHE_SZ;
00289   RTAG_SET1_MASK=TAG_SET1_MASK;
00290   RMIN_LINE_SZ=MIN_LINE_SZ;
00291   RNO_LINES=NO_LINES;
00292 }

void init_faclru void   
 

Definition at line 399 of file faclru.c.

References tree_node::addr, fatal(), hash_lookup_add(), INPUT_BUFFER_SIZE, tree_node::inum, tree_node::lft, MAX_LINES, next_save_time, out_stack, tree_node::rt, tree_node::rtwt, SAVE_INTERVAL, t_entries, and tot_addrs.

Referenced by cheetah_init().

00400 {
00401   unsigned addr;
00402 
00403   next_save_time = SAVE_INTERVAL;
00404 
00405   /* Stack is not cut off precisely at MAX_LINES */
00406   out_stack = calloc((MAX_LINES+INPUT_BUFFER_SIZE), sizeof (unsigned));
00407   if (!out_stack)
00408     fatal("out of virtual memory");
00409 
00410   p_stack = calloc(MAX_LINES, sizeof (struct tree_node *));
00411   if (!p_stack)
00412     fatal("out of virtual memory");
00413 
00414   addr = 1;     /* Assumes that the first address is 1. */
00415   ++t_entries;  /* Kludge to avoid a warning in hash_del */
00416   hash_lookup_add(addr);
00417   t_entries = 0;
00418   tot_addrs = 0;/* Resets tot_addrs which is incremented in hash_lookup_add */
00419 
00420   root = calloc(1, sizeof(struct tree_node));
00421   if (!root)
00422     fatal("out of virtual memory");
00423 
00424   root->inum = t_entries;
00425   root->addr = addr;
00426   root->rtwt = 0;
00427   root->lft = root->rt = NULL;
00428 }

void init_facopt void   
 

Definition at line 1143 of file facopt.c.

References CLEAN_INTERVAL, fatal(), MAX_LINES, next_clean_time, next_save_time, out_stack, and SAVE_INTERVAL.

Referenced by cheetah_init().

01144 {
01145   CLEAN_INTERVAL = 10000000;
01146   next_save_time = SAVE_INTERVAL;
01147 
01148   /* Stack is not cut off precisely at MAX_LINES */
01149   out_stack = calloc(MAX_LINES, sizeof (unsigned));
01150   if (!out_stack)
01151     fatal("out of virtual memory");
01152 
01153   p_stack = calloc((MAX_LINES+1000), sizeof (struct tree_node *));
01154   if (!p_stack)
01155     fatal("out of virtual memory");
01156 
01157   next_clean_time = CLEAN_INTERVAL;
01158 }

void init_optpp void   
 

Definition at line 198 of file ppopt.c.

References base, LA_DIST, and la_limit.

Referenced by cheetah_init().

00199 {
00200   la_limit = 2*LA_DIST;
00201   base = 0;
00202 }

void init_saclru void   
 

Definition at line 127 of file saclru.c.

References A, arr, B, B80000000, BASE, base_pwr_array, BASE_PWR_MAX_DEPTH_PLUS_ONE, depths, DIFF_SET_MASK, fatal(), hitarr, idim2(), MAX_DEPTH, MEM_AVAIL_HITARR, N, next_save_time, ONE, power(), rm_arr, sac_hits, SAVE_INTERVAL, SET_MASK, SIZE_OF_TREE, TWO, TWO_POWER_MAX_DEPTH, and TWO_PWR_N.

Referenced by cheetah_init().

00128 {
00129   unsigned i, j, k, l;
00130   unsigned init_value;
00131   unsigned *arr_ptr, *slot_ptr;
00132 
00133   next_save_time = SAVE_INTERVAL;
00134   TWO_PWR_N = (ONE << N);
00135   MAX_DEPTH = B-A;
00136   TWO_POWER_MAX_DEPTH = (ONE << MAX_DEPTH);
00137   SET_MASK = ((ONE << A) - 1);
00138   DIFF_SET_MASK = ((ONE << MAX_DEPTH) - 1);
00139   BASE = (TWO_PWR_N+1);
00140   SIZE_OF_TREE = (TWO_POWER_MAX_DEPTH * TWO * BASE);
00141 
00142   arr = calloc(((ONE << A)*TWO_POWER_MAX_DEPTH*TWO*BASE), sizeof(int));
00143   if (!arr)
00144     fatal("out of virtual memory");
00145 
00146   BASE_PWR_MAX_DEPTH_PLUS_ONE = power(BASE, MAX_DEPTH+1);
00147   if ((BASE_PWR_MAX_DEPTH_PLUS_ONE * sizeof(unsigned)) < MEM_AVAIL_HITARR)
00148     {
00149       hitarr = calloc(BASE_PWR_MAX_DEPTH_PLUS_ONE, sizeof(int));
00150       if (!hitarr)
00151         fatal("out of virtual memory");
00152     }
00153 
00154   base_pwr_array = calloc((MAX_DEPTH+1), sizeof(unsigned));
00155   if (!base_pwr_array)
00156     fatal("out of virtual memory");
00157 
00158   rm_arr = calloc((TWO_POWER_MAX_DEPTH), sizeof(unsigned));
00159   if (!rm_arr)
00160     fatal("out of virtual memory");
00161 
00162   sac_hits = idim2((TWO_PWR_N), (MAX_DEPTH + 2));
00163 
00164   for (i=0; i < ONE << A; i++)
00165     {
00166       arr_ptr = arr + i * SIZE_OF_TREE;
00167       init_value = B80000000;
00168       slot_ptr = arr_ptr;
00169       *slot_ptr = 1;
00170       for (l=1; l<=TWO_PWR_N; l++)
00171         *(slot_ptr + l) = init_value;
00172       ++init_value;
00173       for (j=1; j <= MAX_DEPTH; j++)
00174         {
00175           for (k=((ONE << j) - 1);
00176                k < (((ONE << j) - 1) + (ONE << (j-1)));
00177                k++)
00178             {
00179               *(arr_ptr + (k*(TWO_PWR_N+1))) = TWO_PWR_N+1;
00180             }
00181           for (k= (((ONE << j) - 1) + (ONE << (j-1)));
00182                k < ((ONE << (j+1)) - 1);
00183                k++)
00184             {
00185               slot_ptr = arr_ptr + (k * (TWO_PWR_N+1));
00186               *slot_ptr = 1;
00187               for (l=1; l<=TWO_PWR_N; l++)
00188                 *(slot_ptr + l) = init_value;
00189               ++init_value;
00190             }
00191         }
00192     }
00193   rm_arr[0] = MAX_DEPTH;
00194   for (i=1; i < (ONE << MAX_DEPTH); i++)
00195     {
00196       for (j=0; j<=MAX_DEPTH; j++)
00197         {
00198           if (i & (ONE << j))
00199             {
00200               rm_arr[i] = j;
00201               break;
00202             }
00203         }
00204     }
00205   j = 1;
00206   for (i=0; i<=MAX_DEPTH; i++)
00207     {
00208       base_pwr_array[i] = j;
00209       j *= BASE;
00210     }
00211 
00212   depths = calloc((MAX_DEPTH+1), sizeof(unsigned));
00213   if (!depths)
00214     fatal("out of virtual memory");
00215 
00216   for (i=0;i<=MAX_DEPTH;i++)
00217     depths[i] = 0;
00218 }

void init_sacopt void   
 

Definition at line 489 of file sacopt.c.

References A, all_hit_flag, B, BASE_CACHE_SIZE, CLEAN_INTERVAL, DIFF_SET_MASK, fatal(), hits, idim2(), MAX_DEPTH, MAXINT, N, next_save_time, ONE, prty_arr, SAVE_INTERVAL, SET_MASK, SET_SIZE, slot_flag, tag_arr, time_of_next_clean, TWO, TWO_POWER_MAX_DEPTH, TWO_PWR_N, and WORD_SIZE.

Referenced by cheetah_init().

00491 {
00492   unsigned i;
00493 
00494   TWO_PWR_N = (ONE << N);
00495   MAX_DEPTH = B-A;
00496   TWO_POWER_MAX_DEPTH = (ONE << MAX_DEPTH);
00497   SET_MASK = ((ONE << A) - 1);
00498   DIFF_SET_MASK = ((ONE << MAX_DEPTH) - 1);
00499   SET_SIZE = WORD_SIZE*TWO_PWR_N;
00500   BASE_CACHE_SIZE = (ONE<<A)*SET_SIZE;
00501 
00502   next_save_time = SAVE_INTERVAL;
00503 
00504   tag_arr = calloc((TWO * (ONE << B) * TWO_PWR_N), sizeof(unsigned));
00505   if (!tag_arr)
00506     fatal("out of virtual memory");
00507 
00508   prty_arr = calloc((TWO * (ONE << B) * TWO_PWR_N), sizeof(unsigned));
00509   if (!prty_arr)
00510     fatal("out of virtual memory");
00511 
00512   all_hit_flag = calloc((ONE << A), sizeof(short));
00513   if (!all_hit_flag)
00514     fatal("out of virtual memory");
00515 
00516   hits = idim2 ((MAX_DEPTH + 2), (TWO_PWR_N));
00517 
00518   slot = calloc((ONE << B), sizeof(struct hash_table));
00519   if (!slot)
00520     fatal("out of virtual memory");
00521 
00522   slot_flag = calloc((ONE << B), sizeof(short));
00523   if (!slot_flag)
00524     fatal("out of virtual memory");
00525 
00526   for (i=0; i < (TWO * (ONE << B) * TWO_PWR_N); i++)
00527     {
00528       tag_arr[i] = 0xffffffff;
00529       prty_arr[i] = (5-MAXINT);
00530     }
00531 
00532   time_of_next_clean = CLEAN_INTERVAL;
00533 }

void optpp md_addr_t    addr,
int    L,
int(*    stack_proc)(int start, int end),
void(*    inf_handler)(md_addr_t addr, int cur_time)
 

Definition at line 205 of file ppopt.c.

References addr_array, base, end, ft_hash(), LA_DIST, la_limit, oe_flag, p_inum, start, time_array, and toggle.

Referenced by cheetah_access().

00208 {
00209   int prev_time, sf;
00210 
00211   if (p_inum > la_limit-1)
00212     {
00213       start = (la_limit % (2*LA_DIST));
00214       end = start + LA_DIST;
00215       if ((sf = (*stack_proc)(start, end))  == 1)
00216         return;
00217       la_limit += LA_DIST;
00218       toggle(oe_flag);          
00219       if (oe_flag)
00220         base += 2*LA_DIST;
00221     }
00222   addr >>= L;
00223   addr_array[(p_inum - base) % (2*LA_DIST)] = addr;
00224   if ((prev_time = ft_hash(addr)) >= 0)
00225     {
00226       if ((la_limit - prev_time) <= 2*LA_DIST)
00227         time_array[(prev_time - base) % (2*LA_DIST)] = p_inum;
00228       else
00229         (*inf_handler)(addr, p_inum);
00230     }
00231   else
00232     (*inf_handler)(addr, p_inum);
00233   ++p_inum;
00234 }

void outpr_dmvl FILE *    fd
 

Definition at line 92 of file dmvl.c.

References CACHE_SZ, hits, hits_arr, MIN_LINE_SZ, NO_LINES, ONE, and t_entries.

Referenced by cheetah_stats(), and dmvl().

00093 {
00094   unsigned i, j, k;
00095 
00096   fprintf(fd, "Direct Mapped Caches\n");
00097   fprintf(fd, "Addresses processed %d\n", t_entries);
00098   fprintf(fd, "Cache size: %d bytes\n", (ONE << CACHE_SZ));
00099 #ifdef PERF
00100   fprintf(fd, "compares %d\n", compares);
00101 #endif
00102   fprintf(fd, "Line size (bytes)\tMiss ratio\n");
00103   for (i= 0; i <= NO_LINES-1; i++)
00104     {
00105       hits[i+MIN_LINE_SZ] = 0;
00106       for (j= 0; j <= (NO_LINES- i - 1); j++)
00107         {
00108           for (k=(NO_LINES-i-1); k <= (NO_LINES-1); k++)
00109             hits[i+MIN_LINE_SZ] += hits_arr[j][k];
00110         }
00111       fprintf(fd, "%d\t\t\t%f\n", (ONE << (i+MIN_LINE_SZ)), 
00112               (1.0 - ((double) hits[i+MIN_LINE_SZ]/(double) t_entries)));
00113     }
00114   fprintf(fd, "\n");
00115 }

void outpr_faclru FILE *    fd
 

Definition at line 73 of file faclru.c.

References L, MAX_LINES, min, MISS_RATIO_INTERVAL, ONE, out_stack, t_entries, and tot_addrs.

Referenced by cheetah_stats(), and ptc().

00074 {
00075   int i;
00076   int stack_end;
00077   unsigned sum = 0;
00078 
00079   fprintf(fd, "Addresses processed : %d\n", t_entries);
00080   fprintf(fd, "Line size : %d bytes \n", (ONE << L));
00081   fprintf(fd, "Number of distinct lines  %d\n", tot_addrs); 
00082 #ifdef PERF
00083   fprintf(fd, "Number of Comparisons %lf\n", comp);
00084   fprintf(fd, "Number of balance steps %lf\n", no_splay_steps);
00085 #endif
00086   fprintf(fd, "Cache size (bytes)\tMiss Ratio\n");
00087   stack_end = min (tot_addrs, MAX_LINES);
00088    
00089   for (i = 1; i <= stack_end; i++)
00090     {
00091       sum += out_stack[i];
00092       if ((i % MISS_RATIO_INTERVAL) == 0)
00093         fprintf(fd, "%d\t\t\t%1.6f\n", (i * (ONE << L)),
00094                 (1.0 - ((double)sum/(double)t_entries)));
00095     }
00096   if ((unsigned)stack_end == tot_addrs)
00097     fprintf(fd, "Miss ratio is %f for all bigger caches\n",
00098             (1.0 - ((double)sum/(double)t_entries)));
00099   fprintf(fd, "\n");
00100 }

void outpr_facopt FILE *    fd
 

Definition at line 341 of file facopt.c.

References comp_del, comp_ins, grps_passd, ihcount, L, MAX_LINES, min, MISS_RATIO_INTERVAL, no_splay_steps, ONE, out_stack, t_entries, and tot_addrs.

Referenced by cheetah_stats(), and stack_proc_fa().

00342 {
00343   int sum = 0, i;
00344   int stack_end;
00345 
00346   fprintf(fd, "Addresses processed : %d\n", t_entries);
00347   fprintf(fd, "Line size : %d bytes \n", (ONE << L));
00348   fprintf(fd, "Number of distinct addresses  %d\n", tot_addrs);
00349 #ifdef PERF
00350   fprintf(fd, "Total Number of groups passed\t%d\n\n", grps_passd);
00351   fprintf(fd, "Total Number of splay steps\t%d\n\n", no_splay_steps);
00352   fprintf(fd, "Number of insert comparisons\t%d\n", comp_ins);
00353   fprintf(fd, "Number of delete comparisons\t%d\n", comp_del);
00354   fprintf(fd, "Number of times inf_handler called\t%d\n", ihcount);
00355 #endif
00356 
00357   fprintf(fd, "Cache size (bytes)\tMiss Ratio\n");
00358   stack_end = min ((unsigned)tot_addrs, MAX_LINES);
00359    
00360   for (i = 1; i <= stack_end; i++)
00361     {
00362       sum += out_stack[i];
00363       if ((i % MISS_RATIO_INTERVAL) == 0)
00364         fprintf(fd, "%d\t\t\t%1.6f\n", (i * (ONE << L)),
00365                 (1.0 - ((double)sum/(double)t_entries)));
00366     }
00367   if (stack_end == tot_addrs)
00368     fprintf(fd, "Miss ratio is %f for all bigger caches\n",
00369             (1.0 - ((double)sum/(double)t_entries)));
00370   fprintf(fd, "\n\n\n");
00371 }

void outpr_saclru FILE *    fd
 

Definition at line 79 of file saclru.c.

References A, hitarr0, L, MAX_DEPTH, ONE, sac_hits, t_entries, and TWO_PWR_N.

Referenced by cheetah_stats(), and sacnmul_woarr().

00080 {
00081   unsigned i, j;
00082   int sum;
00083 
00084   for (i=0; i<=MAX_DEPTH;i++)
00085     sac_hits[0][i] += hitarr0;
00086   hitarr0 = 0;
00087   
00088   fprintf(fd, "Addresses processed: %d\n", t_entries);
00089   fprintf(fd, "Line size: %d bytes\n", (ONE << L));
00090 #ifdef PERF
00091   fprintf(fd, "compares  %d\n", compares);
00092 #endif
00093   fprintf(fd, "\n");
00094   fprintf(fd, "Miss Ratios\n");
00095   fprintf(fd, "___________\n\n");
00096   fprintf(fd, "\t\tAssociativity\n");
00097   fprintf(fd, "\t\t");
00098   for (i=0;i<TWO_PWR_N;i++)
00099     fprintf(fd, "%d\t\t", (i+1));
00100   fprintf(fd, "\n");
00101   fprintf(fd, "No. of sets\n");
00102   for (i=0; i <= MAX_DEPTH; i++)
00103     {
00104       sum = 0;
00105       fprintf(fd, "%d\t\t", (ONE << (i+A)));
00106       for (j=0; j < TWO_PWR_N; j++)
00107         {
00108           sum += sac_hits[j][i];
00109           fprintf(fd, "%f\t", (1.0 - ((double)sum/(double)t_entries)));
00110         }
00111       fprintf(fd, "\n");
00112     }
00113   fprintf(fd, "\n");
00114 }

void outpr_sacopt FILE *    fd
 

Definition at line 229 of file sacopt.c.

References A, B, hit0, hits, L, MAX_DEPTH, ONE, t_entries, and TWO_PWR_N.

Referenced by cheetah_stats(), and stack_proc_sa().

00230 {
00231   int i, j;
00232   int sum;
00233 
00234   for (i=0; i <= (B-A); i++)
00235     hits[i][0] += hit0;
00236   hit0 = 0;
00237 
00238   fprintf(fd, "Addresses processed: %d\n", t_entries);
00239   fprintf(fd, "Line size: %d bytes\n", (ONE << L));
00240 #ifdef PERF
00241   fprintf(fd, "compares  %d\n", compares);
00242 #endif
00243   fprintf(fd, "\n");
00244   fprintf(fd, "Miss Ratios\n");
00245   fprintf(fd, "___________\n\n");
00246   fprintf(fd, "\t\tAssociativity\n");
00247   fprintf(fd, "\t\t");
00248   for (i=0;i<TWO_PWR_N;i++)
00249     fprintf(fd, "%d\t\t", (i+1));
00250   fprintf(fd, "\n");
00251   fprintf(fd, "No. of sets\n");
00252   for (i=0; i<=MAX_DEPTH; i++)
00253     {
00254       sum = 0;
00255       fprintf(fd, "%d\t\t", (ONE << (i+A)));
00256       for (j=0; j<TWO_PWR_N; j++)
00257         {
00258           sum += hits[i][j];
00259           fprintf(fd, "%f\t", (1.0 - ((double)sum/(double)t_entries)));
00260         }
00261       fprintf(fd, "\n");
00262     }
00263   fprintf (fd, "\n\n\n");
00264 }

void ptc md_addr_t    addr
 

Definition at line 441 of file faclru.c.

References tree_node::addr, delete_node(), fatal(), hash_del(), hash_lookup_add(), tree_node::inum, L, tree_node::lft, MAX_LINES, next_save_time, outpr_faclru(), P_INTERVAL, ref_tree(), tree_node::rt, tree_node::rtwt, SAVE_INTERVAL, size_exceeded, t_entries, toggle, and tot_addrs.

Referenced by cheetah_access().

00442 { 
00443   unsigned i_inum;              /* Key lookup */
00444   struct tree_node *nnode;      /* New tree node */
00445   
00446   if (tot_addrs > MAX_LINES)
00447     {
00448       if (size_exceeded == 0)
00449         {
00450           toggle (size_exceeded);
00451           fprintf(stderr, "libcheetah: distinct entries limit exceeded\n");
00452           fprintf(stderr, "libcheetah: addresses processed %d\n", t_entries);
00453         }
00454     }
00455 
00456   if (t_entries > next_save_time)
00457     {
00458       outpr_faclru(stderr);
00459       next_save_time += SAVE_INTERVAL;
00460     }
00461     
00462   ++t_entries;
00463   if ((t_entries % P_INTERVAL) == 0)
00464     fprintf(stderr, "libcheetah: addresses processed %d\n", t_entries);
00465     
00466   addr >>= L;
00467   if (size_exceeded == 0)
00468     {
00469       if ((i_inum = hash_lookup_add(addr)) != 0)
00470         ref_tree(i_inum, addr); 
00471       else
00472         {
00473           nnode = calloc(1, sizeof(struct tree_node));
00474           if (!nnode)
00475             fatal("out of virtual memory");
00476 
00477           nnode->inum = t_entries;
00478           nnode->addr = addr;
00479           nnode->lft = root;
00480           nnode->rt = NULL;
00481           nnode->rtwt = 0;
00482           root = nnode;
00483         }
00484     }
00485   else
00486     {
00487       if ((i_inum = hash_lookup_add(addr)) != 0)
00488         ref_tree(i_inum, addr);
00489       else
00490         {
00491           nnode = delete_node();
00492           hash_del(nnode->addr);
00493           nnode->inum = t_entries;
00494           nnode->addr = addr;
00495           nnode->lft = root;
00496           nnode->rt = NULL;
00497           nnode->rtwt = 0;
00498           root = nnode;
00499         }
00500     }
00501 }

void sacnmul_woarr md_addr_t    addr
 

Definition at line 231 of file saclru.c.

References A, arr, BASE, depths, DIFF_SET_MASK, hitarr0, L, MAX_DEPTH, next_save_time, ONE, outpr_saclru(), P_INTERVAL, rm_arr, sac_hits, SAVE_INTERVAL, SET_MASK, SIZE_OF_TREE, t, t_entries, tag, and TWO_PWR_N.

Referenced by cheetah_access().

00232 {
00233   unsigned t, t1;
00234   int i, fst;
00235   unsigned orig_tag,  atag, depth, entry, set_no; 
00236   unsigned sum, hit;
00237   unsigned *arr_ptr, *slot_ptr;
00238   
00239   
00240   if (t_entries > next_save_time)
00241     {
00242 #if 0 /* tma: is this needed? */
00243       for (i=0; i<=MAX_DEPTH;i++)
00244         sac_hits[0][i] += hitarr0;
00245       hitarr0 = 0;
00246 #endif
00247       outpr_saclru(stderr);
00248       next_save_time += SAVE_INTERVAL;
00249     }
00250 
00251   ++t_entries;
00252   if ((t_entries % P_INTERVAL) == 0)
00253     fprintf(stderr, "libcheetah: addresses processed %d\n", t_entries);
00254       
00255   addr >>= L;
00256   set_no = addr & SET_MASK;
00257   arr_ptr = arr + set_no * SIZE_OF_TREE;
00258   orig_tag = addr >> A;
00259 #ifdef PERF
00260   ++compares;
00261 #endif
00262   if (*(arr_ptr + 1) == orig_tag)
00263     ++hitarr0;
00264   else
00265     {
00266       atag = orig_tag;
00267       depth = 0;
00268       hit = 0;
00269       fst = 1;
00270       slot_ptr = arr_ptr;
00271       while (depth <= MAX_DEPTH)
00272         {
00273           for (i=fst; i<=(int)TWO_PWR_N; i++)
00274             {
00275 #ifdef PERF
00276               ++compares;
00277 #endif
00278               if ((t1 = *(slot_ptr + i)) == orig_tag)
00279                 {
00280                   *(slot_ptr+i) = tag;
00281                   hit = 1;
00282                   break;
00283                 }
00284               t = rm_arr[(orig_tag ^ t1) & DIFF_SET_MASK];
00285               ++depths[t];
00286               *(slot_ptr + i) = tag;
00287               tag = t1;
00288             }
00289           ++*slot_ptr;
00290           entry =
00291             (((ONE << depth) + (atag & ((ONE << depth) - 1))) - 1) * BASE;
00292           slot_ptr = arr_ptr + entry;
00293           --*slot_ptr;
00294           slot_ptr[*slot_ptr] = atag;
00295           if (hit==1)
00296             {
00297               sum = 0;
00298               i = MAX_DEPTH;
00299               while (i >= 0)
00300                 {
00301                   sum += depths[i];
00302                   if (sum < TWO_PWR_N)
00303                     {
00304                       ++sac_hits[sum][i];       
00305                       --i;
00306                     }
00307                   else
00308                     break;
00309                 }
00310               break;
00311             }
00312           ++depth;
00313           atag = tag;
00314           entry =
00315             (((ONE << depth) + (orig_tag & ((ONE << depth)-1)))-1) * BASE;
00316           while ((depth <= MAX_DEPTH) && (*(arr_ptr + entry) > TWO_PWR_N))
00317             {
00318               ++depth;
00319               entry =
00320                 (((ONE << depth) + (orig_tag & ((ONE << depth)-1)))-1) * BASE;
00321             }
00322           if (depth <= MAX_DEPTH)
00323             {
00324               slot_ptr = arr_ptr + entry;
00325               fst = *slot_ptr;
00326             }
00327         }
00328 
00329       for (i=0;i<=(int)MAX_DEPTH;i++)
00330         depths[i] = 0;
00331     } /* else */
00332 }

int stack_proc_fa int    start,
int    end
 

Definition at line 1019 of file facopt.c.

References tree_node::addr, addr_array, CLEAN_INTERVAL, fatal(), group_desc::first, group_desc::grpno, tree_node::grpno, hash_clean_fa(), group_desc::last, tree_node::lft, log_tot_addrs, MAX_LINES, MAXINT, next_clean_time, next_save_time, next_two_pwr, group_desc::nxt, out_stack, outpr_facopt(), P_INTERVAL, Priority_fa(), process_groups(), tree_node::prty, tree_node::rt, SAVE_INTERVAL, size_exceeded, T, t_entries, time_array, toggle, tot_addrs, unk_hash_add_fa(), and group_desc::wt.

01021 {
01022    int i, l;
01023    unsigned addr;
01024    int priority, new_addrs;
01025    struct tree_node *nnode;
01026 
01027    if (t_entries == 0)
01028      {
01029        root = calloc(1, sizeof(struct tree_node));
01030        if (!root)
01031          fatal("out of virtual memory");
01032 
01033        root->rt = root->lft = NULL;
01034        root->prty = Priority_fa(0);
01035        root->addr = addr_array[0];
01036        root->grpno = 0;
01037 
01038        l = 0;
01039        while ((addr_array[l] == addr_array[0]) && (l < end))
01040          ++l;
01041 
01042        nnode = calloc(1, sizeof(struct tree_node));
01043        if (!nnode)
01044          fatal("out of virtual memory");
01045 
01046        nnode->rt = nnode->lft = NULL;
01047        priority = Priority_fa(l-1);
01048        nnode->prty = priority;
01049        nnode->addr = root->addr;
01050        if (nnode->prty < 0)
01051          unk_hash_add_fa(addr_array[l-1], MAXINT, priority);
01052        nnode->grpno = MAXINT;
01053        priority = Priority_fa(l);
01054        root->prty = priority;
01055        root->addr = addr_array[l];
01056        root->lft = nnode;
01057        headgrp.first = headgrp.last = root;
01058        headgrp.grpno = 0;
01059 
01060        headgrp.nxt = calloc(1, sizeof (struct group_desc));
01061        if (!headgrp.nxt)
01062          fatal("out of virtual memory");
01063 
01064        headgrp.nxt->first = nnode;
01065        headgrp.nxt->last = nnode;
01066        headgrp.nxt->grpno = MAXINT;
01067        headgrp.nxt->wt = 1;
01068        headgrp.nxt->nxt = NULL;
01069 
01070        out_stack[1] += l-1;
01071        tot_addrs = 2;
01072        log_tot_addrs = 1;
01073        next_two_pwr = 4;
01074        for (i=0; i<=l; i++)
01075          {
01076            addr_array[i] = 0;
01077            time_array[i] = 0;
01078          }
01079        start = l+1;
01080        t_entries = l+1;
01081      }
01082 
01083    for (l=start; l<end; l++)
01084      {
01085        ++t_entries;
01086        addr = addr_array[l];
01087        if (t_entries > next_save_time)
01088          {
01089            outpr_facopt(stderr);
01090            next_save_time += SAVE_INTERVAL;
01091          }
01092        if (t_entries > next_clean_time)
01093          {
01094            if (size_exceeded)
01095              hash_clean_fa();
01096            next_clean_time += CLEAN_INTERVAL;
01097          }
01098 
01099        if ((t_entries % P_INTERVAL) == 0)
01100          fprintf(stderr, "libcheetah: addresses processed  %d\n", t_entries);
01101 
01102        priority = Priority_fa(l);
01103 
01104        if ((new_addrs = process_groups(addr, priority)) == 1)
01105          {
01106            ++tot_addrs;
01107            if ((unsigned)tot_addrs > next_two_pwr)
01108              {
01109                ++log_tot_addrs;
01110                next_two_pwr *= 2;
01111              }
01112            if (size_exceeded == 0)
01113              {
01114                if ((unsigned)tot_addrs > MAX_LINES)
01115                  {
01116                    toggle(size_exceeded);
01117                    fprintf(stderr,
01118                            "libcheetah: tot_addrs limit exceeded, "
01119                            "t_entries=%d\n",
01120                            t_entries);
01121                  }
01122              }
01123          }
01124        addr_array[l] = 0;
01125        time_array[l] = 0;
01126        if (t_entries > T)
01127          return 1;
01128      } /* for */
01129 
01130    return 0;
01131 }

int stack_proc_sa int    start,
int    end
 

Definition at line 442 of file sacopt.c.

References addr_array, gfsoptls(), next_save_time, outpr_sacopt(), P_INTERVAL, Priority_sa(), SAVE_INTERVAL, T, t_entries, time_array, and unk_hash_add_sa().

00444 {
00445   int l;
00446   unsigned addr;
00447   int priority;
00448 
00449   for (l=start; l<end; l++)
00450     {
00451       ++t_entries;
00452 
00453       if ((t_entries % P_INTERVAL) == 0)
00454         fprintf(stderr, "libcheetah: addresses processed %d\n", t_entries);
00455       if (t_entries > next_save_time)
00456         {
00457           outpr_sacopt(stderr);
00458           next_save_time += SAVE_INTERVAL;
00459         }
00460 
00461       addr = addr_array[l];
00462 
00463       priority = Priority_sa(l);
00464       if (priority < 0)
00465         unk_hash_add_sa(addr, priority);
00466 
00467       gfsoptls(addr, priority);
00468 
00469       addr_array[l] = 0;
00470       time_array[l] = 0;
00471       if (t_entries > (unsigned)T)
00472         return 1;
00473     } /* for */
00474 
00475   return 0;
00476 }

void term_optpp int(*    stack_proc)()
 

Definition at line 239 of file ppopt.c.

References base, end, LA_DIST, la_limit, oe_flag, p_inum, start, and toggle.

Referenced by cheetah_stats().

00240 {
00241   start = la_limit % (2*LA_DIST);
00242   end = start + LA_DIST;
00243   if (p_inum < LA_DIST)
00244     end = p_inum; /* For small traces */
00245   (*stack_proc)(start, end);
00246   if (p_inum >= LA_DIST)
00247     {
00248       toggle(oe_flag);
00249       if (oe_flag)
00250         base += 2*LA_DIST;
00251       la_limit += LA_DIST;
00252       start = la_limit % (2*LA_DIST);
00253       end = start + (((p_inum % LA_DIST) == 0) ? LA_DIST : (p_inum % LA_DIST));
00254       (*stack_proc)(start, end);
00255     }
00256 }


Variable Documentation

unsigned** sac_hits
 

Definition at line 29 of file libcheetah.h.

Referenced by init_saclru(), outpr_saclru(), and sacnmul_woarr().



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