Ejemplo n.º 1
1
/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
  access_cache(0);
  int i = 1;
  while (access_cache(i) == TRUE) {
    i++;
  }
  return i;
}
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int size) {
  flush_cache();
  
  int block_size = get_block_size();
  int try_block = 0, try_addr = 0;
  while(1){
      try_addr = try_block* block_size;
      access_cache(try_addr);
      
      int replace_addr  = 0;
      int replace_found = 0;
      for(;replace_addr < try_addr && !replace_found;replace_addr ++){
          if(!access_cache(replace_addr)){
              replace_found = 1;
              break;
          }
      }
      if(replace_found) break;
      
      try_block++;    
  }

  flush_cache();
  return try_block * block_size;
}
Ejemplo n.º 3
0
/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
	/* YOUR CODE GOES HERE */
	int count = 0;
	flush_cache();
	access_cache(0);
	while(access_cache(count))
		count++;
	return count;
}
/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
  flush_cache();

  int try_addr = 0;
  access_cache(try_addr);
  while(access_cache(++try_addr));

  flush_cache();
  return try_addr;
}
Ejemplo n.º 5
0
/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
  /* YOUR CODE GOES HERE */
  int i = 0;
  flush_cache();
  access_cache(i);
  while (access_cache(i)) {
    i++;
  }
  return i;
}
/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
  /* YOUR CODE GOES HERE */
  flush_cache();
  int addr = 0;
  access_cache(0);
  while(access_cache(addr+1)){
    addr ++;
  }
  return addr + 1 ;
}
Ejemplo n.º 7
0
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int cache_size) {
	/* YOUR CODE GOES HERE */
	int assoc = 0;
	int i;
	while(1){
		assoc++;
		for(i = 0;i <= assoc;i++)
			access_cache(i * cache_size);
		if(!access_cache(0))
			return assoc;
	}
}
Ejemplo n.º 8
0
/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
  /* YOUR CODE GOES HERE */
  int idx = 0;
  int size = 0;
  flush_cache();
  access_cache(0);
  while(access_cache(idx)) {
    idx++;
    size++;
  }
  return size;
}
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int size) {
  /* YOUR CODE GOES HERE */
   
  int assoc = 0;
  while (1) {
        flush_cache();
        assoc += size; 
	for (int i = 0; i <= assoc; i += size)
		access_cache(i);
	if (!access_cache(0))
		return assoc / size;
}
}
Ejemplo n.º 10
0
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int size) {
  flush_cache();
  int count = 0;
  int i;
  while(1) {
    access_cache(count);
    for(i = 0; i < count; i += size)
      if(!access_cache(i))
        return count;
    count += size;
  }
  return -1;  //something went wrong
}
/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
  /* YOUR CODE GOES HERE */
  access_cache(0);
  int x = 1; 
  while (TRUE) {
    if (access_cache(x) == TRUE) {
      x *= 2;
    } else {
      break;
    }
  }
  return x;
}
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int size) {
  /* YOUR CODE GOES HERE */
    unsigned long long count = 0;
    unsigned int i = 0;
    while (1)
    {
        flush_cache();
	count += size;
	for (i = 0; i < count; i += size)
		access_cache(i);
	if (!access_cache(0))
	      return count - size;	
    } 
}
Ejemplo n.º 13
0
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int block_size) {
	/* YOUR CODE GOES HERE */
	unsigned long count = 0;
	unsigned long i = 0;
	while(1){
		count += block_size;
		flush_cache();
		for(i = 0;i < count;i += block_size){
			access_cache(i);
		}
		if(!access_cache(0))
			return count - block_size;
	}
}
Ejemplo n.º 14
0
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int size) {
  /* YOUR CODE GOES HERE */
  flush_cache();
  int i = 0;
  access_cache(0);
  while(access_cache(0)){
    i++;
    flush_cache();
    int addr;
    for(addr=0; addr<i*size;addr+=size){
      access_cache(addr);
    }
  }
  return (i-1)*size;
}
Ejemplo n.º 15
0
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int size) {
  int i, j;
  flush_cache();
  access_cache(0);
  for (i = 1; i < 10000; i++) {
    access_cache(i * size);
    for (j = 0; j <= i*size; j+=size) {
      if (access_cache(j) == FALSE) {
        return i;
      }
    }
  }
  return -1;
  
}
Ejemplo n.º 16
0
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int size) {
  /* YOUR CODE GOES HERE */
  flush_cache();
  int s = 1;
  access_cache(0);
  while(access_cache(0)){
    flush_cache();
    int i;
    for(i=0; i<=s; i++){
      access_cache(i*size);
    }    
    s++;
  }
  return s-1;
}
Ejemplo n.º 17
0
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int block_size) {
  /* YOUR CODE GOES HERE */
  int i = 0;
  int cache_check = block_size;
  flush_cache();
  access_cache(0);
  while (access_cache(0)) {
    i = block_size;
    while (i <= cache_check) {
      i += block_size;
      access_cache(i);
    }
    cache_check += block_size;
  }
  return i;
}
Ejemplo n.º 18
0
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int size) {
  while(1) {
    int count = 0;
    int i;
    int test_cache = size;
    while(1) {
      access_cache(test_cache);
      for(i = size; i < test_cache; i += size)
        if(!access_cache(i))
          return count;
      test_cache += size;
      count++;
    }
  }
  return -1;
}
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int size) {
  /* YOUR CODE GOES HERE */
  flush_cache();
  int i = 1;
  while (TRUE) {
    flush_cache();
    for (int j = 0; j < i; j += 1) {
      access_cache(j * size);
    }
    if (access_cache(0) == FALSE) {
      break;
    } else {
      i++;
    }
  }
  return i - 1;
}
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int size) {
  /* YOUR CODE GOES HERE */
  long long base = 0;
  int i, j;
  for (i = 1; ; i++)
  {
    access_cache(base);
    for (j = 0; j < i; j++)
    {
      access_cache(base + j * size);
    }

    if (!access_cache(base))
      return (j-1);
  }
  return -1;
}
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc() {
  flush_cache();
  //int block_size = get_block_size();
  int cache_size = get_cache_size(0);
  int block_size = get_block_size();
  int addr = 0, replace_addr = 0;

  for (; addr < cache_size; addr += block_size){
      access_cache(addr);
  }

  int special_addr = cache_size * 2 - block_size; // 11111...
  access_cache(special_addr);
  for(; replace_addr < cache_size && access_cache(replace_addr); replace_addr += block_size);

  return cache_size / (replace_addr + block_size);
}
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int size) {
  /* YOUR CODE GOES HERE */
  flush_cache();
  int i = size;
  while (TRUE) {
    flush_cache();
    for (int j = 0; j < i; j += size) {
      access_cache(j);
    }
    if (access_cache(0) == FALSE) {
      break;
    } else {
      i *= 2;
    }
  }
  return i;
}
Ejemplo n.º 23
0
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int size) {
  /* YOUR CODE GOES HERE */
  int i;
  flush_cache();
  access_cache(0);
  i = 0;
  while (access_cache(0)) {
    flush_cache();
    access_cache(0);
    int j = 1;
    while (j <= i + 1) {
      access_cache(j * size);
      j++;
    }
    i++;
  }
  return i;
}
Ejemplo n.º 24
0
/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int cache_size) {
  /* YOUR CODE GOES HERE */
  int i = 0;
  int cache_check = 1;
  int assoc = 0;
  flush_cache();
  access_cache(0);
  while (access_cache(0)) {
    i = cache_size;
    assoc = 0;
    while (i <= cache_check) {
      i += cache_size;
      assoc++;
      access_cache(i);
    }
    cache_check += cache_size;
  }
  return assoc;
}
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int size) {
  /* YOUR CODE GOES HERE */
  long long base = 0; 
  //long long addr = base + size;
  int i = 1, j = 0;
  
  for (i = 1; i <= 65536/size + 10; i++)
  {
    access_cache(base);

    for (j = 1; j < i + 1; j++)
    {
      access_cache(base + j * size);
    }

    j--;
    if (!access_cache(base))
	return (base + j * size);
  }

  return -1;
}
Ejemplo n.º 26
0
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int size) {
  /* YOUR CODE GOES HERE */
  int i, bsize;
  flush_cache();
  bsize = get_block_size();
  i = 0;
  while (1) {
    flush_cache();
    access_cache(0);
    int j = 1;
    while (j <= i) {
      access_cache(j * bsize);
      j++;
    }
    if (access_cache(0)) {
      i++;
    } else {
      break;
    }
  }

  return i * bsize;
}
/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
  /* YOUR CODE GOES HERE */
  long long base = 0;
  long long addr = base;
  flush_cache();
  if (!access_cache(addr))
  {
    for (addr = 1; ; addr++)
    {
	if (!access_cache(addr))
	{
	  break;
	}
    }

    return addr - base;
  }
  else
  {
    printf("Error, %d", __LINE__);
  }

  return -1;
}
Ejemplo n.º 28
0
/* Run Command:  ./sim_cache <Block Size> <L1 Size> <L1 Associativity> <Victim Cache Number of Blocks> <L2 Size> <L2 Associativity> <Trace File> */
int main(int argc, char *argv[])
{
        if(argc <= 7)
        {
                printf("Usage: ./sim_cache <Block Size> <L1 Size> <L1 Associativity> <Victim Cache Number of Blocks> <L2 Size> <L2 Associativity> <Trace File>.\n");
                return 0;
        }

        unsigned int blocksize = atoi(argv[1]);
        unsigned int L1_size = atoi(argv[2]);
        unsigned int L1_assoc = atoi(argv[3]);
        unsigned int L1_vc_blocks = atoi(argv[4]);
        unsigned int L2_size = atoi(argv[5]);
        unsigned int L2_assoc = atoi(argv[6]);
        
        struct cache *L1 = (struct cache*)malloc(sizeof(struct cache));
        struct cache *L2 = NULL;
        struct cache *vc = NULL;
        L1 = create_cache(blocksize,L1_assoc,L1_size,"L1");
        
        if(L1_vc_blocks > 0)
        {
             vc = (struct cache*)malloc(sizeof(struct cache));
             vc = create_cache(blocksize,L1_vc_blocks,L1_vc_blocks*blocksize,"VC");
             L1->vc = vc;
        }

        if(L2_size > 0 && L2_assoc >= 1)
        {
            L2 = (struct cache*)malloc(sizeof(struct cache));
            L2 = create_cache(blocksize,L2_assoc,L2_size,"L2");
            L1->next = L2;
        }

        if(L1_vc_blocks > 0 && L2_size > 0 && L2_assoc >= 1)
        {
            vc->next = L2;
        }

        strcpy(L1->trace,argv[7]);
        FILE *trace = fopen(argv[7],"r");
        if(trace == NULL)
        {
                printf("Error: Could not open file.\n");
                return 0;
        }
        
        char str[12],address[12];
        unsigned long num_addr;
        int i;
        unsigned int instr = 0;
        print_simulator_config(L1);
        while(fgets(str, 12, trace) != NULL)
        {
                for(i=0;i<strlen(str);i++)
                    if(str[i] == '\n')
                      str[i] = '\0';

                for(i=2;i<=strlen(str);i++)
                {
                        address[i-2] = str[i];
                }
                address[i-2] = '\0';
                num_addr = (int)strtoul(address, NULL, 16);
                
                instr++;
                if(str[0] == 'r')
                {
                        if (DEBUG == 1 ) {printf("----------------------------------------\n");}
                        if (DEBUG == 1 ) {printf("# %d: read %lx\n",instr,num_addr);}
                        access_cache(L1,num_addr, str[0]);
                }
                else if(str[0] == 'w')
                {
                        if (DEBUG == 1 ) {printf("----------------------------------------\n");}
                        if (DEBUG == 1 ) {printf("# %d: write %lx\n",instr,num_addr);}
                        access_cache(L1,num_addr, str[0]);
                }
                else if(str[0] == ' ')
                {
                        printf("Null character in trace");
                }
                //DEBUG HELP: print_cache(L1);
                //DEBUG HELP: print_cache(L1->vc);
                //DEBUG HELP: print_cache(L2);
        }
        fclose(trace);

        printf("===== L1 contents =====\n");
        print_cache(L1);
        
        if(L1_vc_blocks > 0)
        {
            printf("\n===== VC contents =====\n");
            print_cache(vc);
        }
    
        if(L2_size >= 0 && L2_assoc >= 1)
        {
            printf("\n===== L2 contents =====\n");
            print_cache(L1->next);
        }
        print_simulation_summary(L1);

        if(L2_size > 0 && L2_assoc >= 1)
        {
            delete_cache(L2);
        }
        else
        {
            free(L2);
        }
        
        if(L1_vc_blocks > 0)
        {
            delete_cache(vc);
        }
        else
        {
            free(vc);
        }
        delete_cache(L1);
        
        return 0;
}
Ejemplo n.º 29
0
/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
  int size= 0;
  access_cache(size);
  while(access_cache(++size));
  return size;
}
Ejemplo n.º 30
-1
/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int size) {
  int i, j;
  flush_cache();
  for (i = 0; i < 1000000; i+=size) {
    access_cache(i);
    for (j = 0; j <= i; j+=size) {
      if (access_cache(j) == FALSE) {
        return i;
      }
    }
  }
  return -1;
}