"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  

saclru.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 saclru.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define B80000000   0x80000000
 

Definition at line 29 of file saclru.c.

Referenced by init_saclru().

#define INVALID   0
 

Definition at line 30 of file saclru.c.

#define MEM_AVAIL_HITARR   2097152
 

Definition at line 31 of file saclru.c.

Referenced by init_saclru().

#define ONE   1U
 

Definition at line 27 of file saclru.c.

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

#define TWO   2
 

Definition at line 28 of file saclru.c.

Referenced by init_saclru().


Function Documentation

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 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 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 }


Variable Documentation

int A
 

Definition at line 33 of file saclru.c.

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

unsigned* arr [static]
 

Definition at line 53 of file saclru.c.

Referenced by init_saclru(), and sacnmul_woarr().

int B
 

Definition at line 33 of file saclru.c.

Referenced by init_saclru().

int BASE [static]
 

Definition at line 43 of file saclru.c.

Referenced by init_saclru(), and sacnmul_woarr().

unsigned* base_pwr_array [static]
 

Definition at line 57 of file saclru.c.

Referenced by init_saclru().

int BASE_PWR_MAX_DEPTH_PLUS_ONE [static]
 

Definition at line 43 of file saclru.c.

Referenced by init_saclru().

unsigned* depths = NULL [static]
 

Definition at line 66 of file saclru.c.

Referenced by init_saclru(), and sacnmul_woarr().

int DIFF_SET_MASK [static]
 

Definition at line 43 of file saclru.c.

Referenced by init_saclru(), and sacnmul_woarr().

int* hitarr [static]
 

Definition at line 55 of file saclru.c.

Referenced by init_saclru().

int hitarr0 = 0
 

Definition at line 67 of file saclru.c.

Referenced by outpr_saclru(), and sacnmul_woarr().

int L
 

Definition at line 33 of file saclru.c.

Referenced by outpr_saclru(), and sacnmul_woarr().

unsigned MAX_DEPTH [static]
 

Definition at line 42 of file saclru.c.

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

int N
 

Definition at line 33 of file saclru.c.

Referenced by init_saclru().

unsigned long next_save_time [static]
 

Definition at line 65 of file saclru.c.

Referenced by init_saclru(), and sacnmul_woarr().

int P_INTERVAL
 

Definition at line 33 of file saclru.c.

Referenced by sacnmul_woarr().

unsigned* rm_arr [static]
 

Definition at line 58 of file saclru.c.

Referenced by init_saclru(), and sacnmul_woarr().

unsigned** sac_hits
 

Definition at line 54 of file saclru.c.

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

int SAVE_INTERVAL
 

Definition at line 33 of file saclru.c.

Referenced by init_saclru(), and sacnmul_woarr().

int SET_MASK [static]
 

Definition at line 43 of file saclru.c.

Referenced by init_saclru(), and sacnmul_woarr().

int SIZE_OF_TREE [static]
 

Definition at line 43 of file saclru.c.

Referenced by init_saclru(), and sacnmul_woarr().

int T
 

Definition at line 33 of file saclru.c.

unsigned t_entries [static]
 

Definition at line 60 of file saclru.c.

Referenced by outpr_saclru(), and sacnmul_woarr().

unsigned tag = 0
 

Definition at line 68 of file saclru.c.

Referenced by cache_access(), cache_flush_addr(), cache_probe(), dmvl(), and sacnmul_woarr().

int TWO_POWER_MAX_DEPTH [static]
 

Definition at line 43 of file saclru.c.

Referenced by init_saclru().

unsigned TWO_PWR_N [static]
 

Definition at line 41 of file saclru.c.

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