Cache Implementation (Fall, 2018)
Computer Architecture
Prof. HyungJune Lee
3. Overall Flow
First, in main(), initialize memory and cache using init_memory_content() and init_cache_content().
Read address and data type from input file ‘accessed_input.txt’ line by line while input file pointer does not meet EOF(end of file).
After read data from input file, global_timestamp increase at each line read.
Get data from cache or memory with retrieve_data(). retrieve_data() needs 2 arguments, void pointer type addr and character type data_type.
main() pass addr and data type that reads from input file.
In retrieve_data(), get accessed_data by invoking check_cache_data_hit().
check_cache_data_hit() needs 2 arguments same as retrieve_data(). retrieve_data() pass 2 arguments received from main() to check_cache_data_hit().
In check_cache_data_hit(), if it can access data using cache return that accessed data to retrieve_data() and increase num_cach_hits.
If not, return -1 so retrieve_data() invoke access_memory().
After invoking check_cache_data_hit(), if value_returned is -1, it means cache miss, so invoke access_memory().
access_memory() needs 2 arguments same with check_cache_data_hit().
In access_memory(), increase num_cache_memory and invoke find_entry_index_in_set() to find entry index.
Using entry index that found by find_entry_index_set(), save data into cache from memory. And return the data to retrieve_data().
Increase num_bytes according to data_type to calculate bandwidth. Finally, returned the accessed_data to main().
If there are errors in access memory, -1 will be returned.
Print the accessed data received by retrieve_data() and accessed_addr, accessed_data type to an output file every time accessed.
After finish reading the input file, print the hit ratio and bandwidth.
Comments
Post a Comment