Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 25th, 2008, 3:41 AM   #1
Natsoumi_Maya
Newbie
 
Join Date: Apr 2008
Posts: 1
Rep Power: 0 Natsoumi_Maya is on a distinguished road
cache simulator..PLZ HELP

What im trying to do is implement the cache using C. I have to find out the hit and miss rate of the cache. my code is pretty long so i'll just show u the parts i've implemented and the parts i need help with. If u have any inqueries PLZ feel free to ask. Thank you in advance for any help provided.
This is the part i have implemented. The code basically implements the Full associative, set associative and direct mapped cache.

cache - array of SETS
int i;
if(MAX_SET==1)        // Fully Associative Cache 
{
     i = 0;
     while (i <=BLOCKS_PER_SET)   // Dividing the SET into 
                                                       //Blocks of size "BYTES_PER_BLOCK" 
     {
         cache[i].block = (struct BLOCK *)malloc(BYTES_PER_BLOCK)    // Not Sure about "  cache[i].block "  
         i ++;
      }
      cache --;
}
else
{
    while (cache )   //THINK OF CONDITION: while the array of SETS is not FULL
    {
        if (MAX_SET == BLOCKS_PER_SET) //Direct Mapped Cache
        {
             while (MAX_SET != 0)
             {
                i = 0;
	while (i <=BLOCKS_PER_SET) // Dividing the SET into BLOCKS 
                                                               //of size "BYETS_PER_BLOCK"
	{
	    cache[i].block = (struct BLOCK *)malloc 
                    BYTES_PER_BLOCK)    //CHECK the "cache[i].block"
	     i ++;
	}
	MAX_SET --;
             }
         }
         else // Set Associative Cache
         {
             while (MAX_SET != 0)
             {
	 i = 0;
	while (i <=BLOCKS_PER_SET) // Dividing the SET into BLOCKS of 
                                                               //size "BYTES_PER_BLOCK"
	{
	    cache[i].block = (struct BLOCK *)malloc(BLOCKS_PER_SET)    		    i ++;
	}
	MAX_SET --;
              }
           }
           cache --;
        }
}

Since my program is incomplete, im not able to test it, SO i was wondering if In the part i implemented
cache[i].block = (struct BLOCK *)malloc(BLOCKS_PER_SET)
is correct (Syntax wise).

This is the part i need help with. I have the algorithim down but im not sure how to implement. Again, any help is most appreciated:

 BOOL simulate(unsigned int address)
{
	/* Algorithm:
     * - Find the index for current address
	 * - For that set, search all valid blocks for matching tags
	 * - If a match is found, you have a hit:
  	 *   + update timestamp of block and LRU of set
	 *   + return true
	 * - If there is no match, you have a miss:
	 *   + Search for an invalid block and use it to store new block
	 *   + If there are no invalid blocks, replace the LRU block
	 *   + update timestamp of block and LRU of set
	 *   + return false
	 */
	/******* Fully Associative Cache*******/
	
	/********* Direct Mapped Cache*********/
	/******** SET Associative Cache********/
}
Natsoumi_Maya is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting Cache errors. sixstringartist C++ 10 Jun 7th, 2007 7:31 PM
When is it faster to cache? Sane Python 5 Apr 2nd, 2006 3:11 PM
Clearing cache coldblue JavaScript and Client-Side Browser Scripting 5 Feb 13th, 2006 6:41 AM
Cache class feedback clsk C++ 0 Jan 29th, 2006 12:20 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC