Note - This programme is not tested for all test cases, thus necessary modification may be needed if some test case fails.
HOW TO MAKE EXECUTABLE AND RUN PROGRAMME****
Note make a output folder in outer directory
Step-1 : modify the paths in ssl_grade.py. give the absolute path of the submissions directory, output directory and the trace directory.
Step-2 : Execute ssl_grade.py with the following command "python3 ssl_grade.py" and it will grade all the submissions and save the scores in csv format (score.csv) in the same directory.
or
Step-1 : Run Make Command in Submission folder and see programme working
or
Make new test cases in test case file
Problem Statment
find the optimal cache configuration for defining the baseline for your research. To set up the baseline, you need to design a cache simulator for finding the best overall cache configuration for the given memory traces. You are expected to design and implement a cache simulator to compare and study the effectiveness of various cache configurations. Your simulator would be provided with the memory access trace from the trace file and expected to simulate the cache operations in response to the memory access pattern. Subsequently, furnish the statistics to an output file.
Each line in the memory access pattern has three fields namely: memory access type, memory address and data corresponding either fetched from the disk or needs to be written into the disk. The first field is either l or s, where l is for load and s is for store operation. The second field is a 32-bit memory address provided in hexadecimal. You can use the third field for populating the cache data structure. Note: We assume that each load or store in the trace accesses data of at most 4 bytes of data and do not read data that spans over multiple lines in the cache.
Your cache simulator can be configured with the following design parameters, which would be provided as command-line arguments while executing “make run”: ● number of sets in the cache (a positive power-of-2) ● number of blocks in each set (a positive power-of-2) ● number of bytes in each block (a positive power-of-2, at least 4) ● LFU (least-frequently-used) or LRU (least-recently-used) or FIFO (first in first out) evictions With only the statistics of the cache hits and cache misses we will not be able to evaluate our cache design. We have assumed that we are using a write allocate scheme and write back scheme for handling the data transfer between the cache and the memory. To find the latency required by your designed cache simulator, we assume the following latencies:
- Load / Store from/to the cache takes 1 processor cycle.
- Load / Store from/to the memory takes 100 processor cycles for each 4-byte word. We can ignore the other delays associated with the cache as we cannot design a cycle-accurate simulator with limited information. You must provide a Makefile such that: ● make clean, remove all object files and executables. ● make sim, compile and link your program, producing an executable called sim. ● make run num_sets= num_blocks= size_block=<size of block, at least 4> eviction_policy=<LRU || LFU || FIFO> trace_file=<trace_file_location> output_file=<output_file_location>, runs the cache simulator with the defined design parameters. make run num_sets=256 num_blocks=1024 size_block=32 eviction_policy=LFU trace_file=read01.trace output_file=output.txt ● Your code should compile cleanly with GCC-9 compiler flags: -Wall -Wextra --pedantic.
Result
- all test cases are working fine (except one test case (cycle value) which taken intentionally wrong) and running python code with full score
- I have used simple concept of enum for to keep track of policy
- for each policy I have a dedeicated block of codes
- I have used the fact that a address is made up of tag bits and set bits and block offset in set associative cache
- I have used the concept of dirty bits also which keep track of blocks which are updated re replace them by inccuring extra cycles which have dirty bits set
- If dirty bit is not set these blocks are not replced to in memory
- if dity bit is set then 2*100 cycles needed for each 4 byte word
- if dirty bit not set then as usual 100 cycles needed for each 4 byte word
- I have used 100 cycles for replacement by memory as satated by Sir
- I have also initialized all the variables which can be changed by sending arguments
- I have used similar format as given by Submission folder
- Makefile and basic initialization is same as given is Sir's submission folder sim.c example
- I have not used/took help of any other content except Sir's given folder
- I have first calculated no of lines in input and then store their data in a array
- Now for each policy I have seperate codes but has many common parts
- first found out no of loads and misses by increment
- then convert given address in bits
- then convert set bits and tags bits to integer value
- then if tags value of address matches any of the tag value of line of set of given adress then it is a hit otherwise miss.
- Miss can be handle in 2 ways - there is some unfilled line then only cycles to transfer data from memory to programme ; there is no empty line in this case replacement policy is needde
- I have also a array for replacement policy for each line of set which stores that what is the state of that line which determines its replacement
- for fifo I have maintained a global state counter(like time) and if some hit is done then no update of state of that line, in case of replacement lowest state value is seen and is replaced.
- for LRU I have maintained a global state counter and if some hit is done we update its state to new state and in case of replacement we find lowest state value in that set and replace it.
- for LFU I have maintaine a simple counter when some hit occurs it incremment itself, in case of replacemnt we find low value of counter and replace it
- note we start filling cache set line in top to bottom manner (0 to n) for a set
- also in case of tie we follow fifo proprty almost everywhere because of filling and finding first in top to bottom manner.
- Also dirty bit replacement is set accordingly
- As no particular input size is given so I have assumed all values to be int which can be changed to other types appropiately, conter or max value can overflow in this
- code can be shortened by removing repeated lines.
- Kindly use absolute address for giving address