Lab Assignment 1: Cache Memories
Table of Contents
Objective
The purpose of this lab is to understand the functionality of cache memories, and to get an insight into various trade-offs related to the design of systems with cache memories.
Time allocation
4 hours (2 lab sessions) are allocated for this lab.
Preparation
You should review the following resources before you start working on this lab:
- Lab 0: Using the Toolset
- Lecture notes about cache memories
- Chapter 4 (on cache memories) in the course book
- This link briefly describes different caching policies. It also provides tools to help visualize different cache structures.
Assignments
-
Cache basics
Solve the following problems and include the solution in the submitted report. -
Locality of data
This assignment requires you to usesim-cachefor the simulations on two different architectures.
You need to run two test programs (test1.ss, test2.ss) on each of the two architectures.The source code and the binaries of the test programs are of the
To complete this assignment, please follow the instructions listed below:.cand.sssuffix, respectively. The configuration files for simulations are of the.cfgsuffix. The source code, the test programs and the configuration files are already available in thesimplescalar/cde-rootdirectory - which you copied earlier in Lab 0.-
Look into the configuration files,
cache1.cfgandcache2.cfg, used for the simulations.
Compare the caches in the configuration files. - Report which fragments of the source code (in both test programs) exhibit spatial and temporal locality of the data.
-
Consider the nested loops in both test programs (Lines 22-26 in
test1.cand Lines 22-27 intest2.c). Analyze all four combinations of test program and cache configuration:
test1.cwithcache1.cfg,test1.cwithcache2.cfg,test2.cwithcache1.cfg,test2.cwithcache2.cfg.For each combination, calculate the cache miss ratio for the accesses to array
Athat are used to update the variablesum. The miss ratio is defined as the number of cache misses divided by the total number of accesses to arrayA.To help with the calculation, think about the access pattern to array
A: when does an access cause a cache miss, which elements ofAare then loaded into the cache, and where are they placed? Because of spatial locality, some subsequent accesses may hit in the cache until another element that is not currently cached is accessed and causes the next miss. Try to identify the repeating pattern of misses and hits. For example, a pattern such asM H H H M H H H ...corresponds to one miss every four accesses, giving a miss ratio of 1/4 = 0.25.Assume that the cache is empty when the nested loop starts and that an
intoccupies 4 bytes.Finally, identify which of the four combinations gives the lowest miss ratio and which gives the highest miss ratio.
-
Run simulations for each test program (
test1.ssandtest2.ss) using both configuration files (cache1.cfgandcache2.cfg). To run simulations with given configurations, please follow the instructions in preparations. Find the combination of the test program and cache configuration with the best and the worst miss ratio. Verify that your simulation results agree with your answer in the previous question. [Note that the miss ratios obtained from the simulations are not identical to your analysis.]
-
Look into the configuration files,
-
Evaluation of cache configurations
This assignment requires you to use
sim-cheetahin order to evaluate the performance of several cache configurations.- Create a configuration file for
sim-cheetah(by first dumping the default configuration file ofsim-cheetahas explained in lab0) so that the simulations cover the following cache configurations:- caches with a number of sets between 128 and 4096,
- caches with a level of associativity between 1 and 8,
- caches with a line size of 32 bytes and a LRU replacement policy.
Using the
go.ssbenchmark, run the simulation for the three cases in which the cache stores either only data (data cache), or only intructions (instruction cache), or both (unified cache). To specify whether the cache stores only data, instructions or both, modify the -refs parameter (# reference stream to analyze, i.e., {inst|data|unified}) in the configuartion file. Note: For the simulation with a certain reference stream, e.g., data, the miss ratio data for other reference streams (i.e., inst and unified) are not collected. This is to say, if you set up the reference stream to data, you still have the cache hardware for inst but the miss ratio for inst will not be included in the simulation output.Here is an example of runnning
go.sson SimpleScalar:./sim-cheetah -config config-file go.ss 3 7go.ssis a simple program that makes the computer run the game "Go" against itself using theconfig-fileconfiguration file. The first parameter (3) indicates the level of the player, while the second parameter (7) sets the go table size. - For each of the three simulations, extract the results from the output files, and create a plot graph which shows how the miss ratio depends on the associativity.
- Answer the following questions.
- What is the relation between the miss ratio and: the associativity and number of sets?
- You are required to design the cache system to run the application "go.ss". There are three alternative variants for the cache system: 1) Only data cache; 2) Only instruction cache; and 3) Data and instruction cache with equal size. Note that the cache sizes for the above three variants are the same. Based on your plot graphs (you may select appropriate data points in the graphs), explain which variant of cache you will choose. You can make assumptions on the relative amount of instruction accesses and data accesses in your discussion.
- Consider your plot graph for the instruction cache. Assume that a designer can spend at most 8000 SEK for an instruction cache and the cost to design each byte in an instruction cache is 0.01 SEK. For instance, with this budget and cost, we can have an instruction cache with the maximum cache size of 800000 bytes. Now, for the given maximum budget and the given cost-per-byte, find the exact cache configuration that minimizes the following cost function: cost function = (100000 * miss ratio) + (0.01 * cache size in bytes)
- Create a configuration file for
What to report
- Answers (with sufficient explanations) to each of the previous problems. You may use figures when necessary.
Page responsible: Zebo Peng
Last updated: 2026-09-25
