This is a very simple lab, with a direct code.
/*Coursera hw/sw interfacelab 4-mystery cachesmystery Cache geometries (for your to keep notes): Mystery0:block size = Cache Size = associativity =mystery1:block size = Cache size = associativity =mystery2:block size = Cache size = associativity =mystery3:block size = Cache Size = Associativity =*/#include<stdlib.h>#include<stdio.h>#include"mystery-cache.h"/** Note:when using Access_cache () you does not need to provide a "real" * memory addresses. You can use any convenient integer value as a * memory address, you should is not being able to cause a segmentation * fault by Providing a memory address out of your programs address * space as the argument to Access_cache. *//*Returns the size (in B) of each block in the cache.*/intGet_block_size (void) { /*YOUR CODE GOES here*/Cache_init (16000,4); Flush_cache (); intback =0x0000ff00; Access_cache (back); while(Access_cache (back)) { back+=1; } flush_cache (); intFront =0x0000ff00; Access_cache (front); while(Access_cache (front)) {Front-=1; } returnback-front-1; }/*Returns the size (in B) of the cache.*/intGet_cache_size (intsize) { /*YOUR CODE GOES here*/ //printf ("%d\n", s);Flush_cache (); intStart =0x00ffff00; inti = size/2; intp; Do{i*=2; P=start; Flush_cache (); Access_cache (start); while(P < start +i) {p+=size; Access_cache (P); } if(!Access_cache (start)) Break; } while(1); returni;}/*Returns The associativity of the cache.*/intGET_CACHE_ASSOC (intsize) { /*YOUR CODE GOES here*/ returnGet_cache_size (size)/size;}///anything BELOW this pointintMainvoid) { intsize; intAssoc; intblock_size; /*the cache needs to is initialized, but the parameters would be is ignored by the mystery caches, as they is hard cod Ed. You can test your geometry paramter discovery routines by calling Cache_init () w/your own size and block size Val UEs. */Cache_init (0,0); Block_size=get_block_size (); Size=get_cache_size (block_size); Assoc=Get_cache_assoc (size); printf ("Cache block Size:%d bytes\n", block_size); printf ("Cache Size:%d bytes\n", size); printf ("Cache associativity:%d\n", Assoc); returnexit_success;}
The code in Get_block_size means finding the starting point of the next line, the last line of the endpoint, and subtracting the two by 1 is the block size
The code in Get_cache_size means constant access to a row of caches, which, once accessed to a row, becomes an inaccessible state, indicating that the block was replaced, indicating that the cache size has been passed.
Get_cache_assoc and Get_cache_size are the same, but each time the addition is the cache size, so that each access is only within a group of access, once the initial group has not been accessed, it is replaced. This makes it possible to draw a set number of rows.
2015-09-28
Lab 4:cache Geometries