Cache Simulator

This is a discussion on Cache Simulator within the C Programming forums, part of the General Programming Boards category; hi: I have two methods to write in this cache simulator: Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> ...

  1. #1
    sparklezilla3
    Join Date
    Mar 2010
    Posts
    41

    Cache Simulator

    hi:

    I have two methods to write in this cache simulator:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    #include <assert.h>
    
    struct cache_blk_t {
      unsigned long tag;
      char valid;
      char dirty;
    
      cache_blk_t *way_next;
      cache_blk_t *way_prev;
    };
    
    struct cache_set_t {
      cache_blk_t *way_head;
      cache_blk_t *way_tail;
    
      unsigned int FIFO_counter;
    };
    
    enum cache_policy {
      LRU,
      Random,
      FIFO
    };
    
    struct cache_t {
      int nsets;		// # sets
      int bsize;		// block size
      int assoc;		// associativity
    
      enum cache_policy policy;
    
      // statistics
      unsigned long accesses;
      unsigned long hits;
      unsigned long misses;
      unsigned long replacements;
      unsigned long writebacks;
    
      struct cache_set_t *sets;
    };
    
    void
    cache_create(int A, int B, int C, enum cache_policy policy)
    {
      create cache based on A, B, and C
      allocate sets
      allocate blocks in each set
      remember the replacement policy setting
      initialize statistics data
    }
    
    int
    cache_access(struct cache_t *cp, unsigned long address, char access_type)
    {
      based on address determine the set to access in cp
      examine blocks in the set to check hit/miss
      if miss, determine the victim in the set to replace
      if LRU is used, update the block list
    }
    In the Cache create, and cache access method, can anyone help translate my sudo code?

    Thanks,

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ok, first, create a cache based on A, B and C. Then, allocate sets. Allocate blocks for each set. Remember your replacement policy settings. Initialize the statistics data. That'll cover the cache_create function.

    Next, the cache_access function, based on the address, determine the set to access. Look at the blocks in the set and see where you have hits and misses, and handle accordingly.


    See, you're just going to get smart ass answers until you tell us specifically what you have problems with. No, we're not going to "translate your sudo code" into real code for you.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with cache simulator!
    By dtogers123 in forum C Programming
    Replies: 3
    Last Post: 04-30-2008, 07:18 PM
  2. Resource manager tree
    By VirtualAce in forum Game Programming
    Replies: 23
    Last Post: 09-07-2007, 11:27 PM
  3. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  4. cache miss/hit
    By xddxogm3 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 07:51 PM
  5. destroywindow() problem
    By algi in forum Windows Programming
    Replies: 6
    Last Post: 03-27-2005, 11:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21