Docsity

Lab Assignment 4: Evaluating Cache Hit Rates for Different Cache Architectures - Prof. Jam, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
Score:______ Section:____________ Date:__________ Name:______________________________
ECE 3055 Laboratory Assignment 4
Due Date: Tuesday, March 31
In this lab, you will use C/C++ to write a program that will evaluate and compare the cache hit rates for
several cache architectures. Given a particular cache memory organization, the program will read a file
containing a memory trace (a sequence of memory addresses) and determine which of the memory
references will cause cache hits. The program should keep track of the total number of hits and misses
generated by each cache over the entire trace. The hit rate should be plotted for different cache memory
sizes and architectures (as detailed below). You only need to keep track of hits and misses and do not need
to save all of the data values.
The trace file is available from the Lab Web page:
http://www.ece.gatech.edu/~hamblen/3055/gcc_trace2.zip
There are 1,000,000 memory references in the trace file stored one per line. These were collected from the
gcc C compiler while it was running on a MIPS processor. Each line has three fields. The address is the
second field on the line. The first field gives the type of the memory reference (2 for instruction fetch, 1 for
a store’s data memory write, and 0 for a load’s data memory read). The third field gives the instruction
value for a fetch and is always 0 for loads and stores. Keep track of miss rate for instructions and data. To
help you get started on the lab, a simple program that reads the trace file, extracts the address, and performs
some simple bit-wise operations similar to what is needed to extract bit fields from the address to determine
the cache address is available at the URL below in C and setup as a complete Visual Studio 2005 Project
Win32 API Console Application (no complex GUI – text only window for output).
http://www.ece.gatech.edu/~hamblen/3055/read_trace.zip
Use File-> Open ->Project/Solution to open a VS project. Use Build ->Build Solution to compile, and
then Debug -> Start Debugging to run. Use File->Open->File to view and edit source code.
(60%) Part 1: On a single page, plot the cache miss rates versus cache memory size for a processor with
two direct-mapped caches. The I cache is used for Instruction fetches only and the D cache is used only for
data (lw, sw memory data operands). The separate Instruction and Data cache architecture is used in most
modern processors. The size of each cache is the same. The simulation should output data points for cache
memory sizes starting at 256 to 16K in powers of two. 1K means 1K cached data locations in each cache.
Do not count writes in the hit rate calculation. Assume byte addressing and the block size is one 32-bit
word. Generate a plot of miss rate vs. cache size, with one curve for instructions and one curve for data.
(40%) Part 2- Repeat part 1 for a set associative cache with a set size of 1, 2, 4 and 8 sets in the cache with
the same number of cache data locations as in part 1. Generate two plots (one for instructions and one for
data) where the total data locations held in the cache are constant while the number of sets varies – like
Figure 5.30 in the text. Use true LRU replacement, so design a data structure that allows you to determine
LRU.
You do not have to write code to plot the data, only to calculate it. The plotting can be done by any
method you wish, e.g. by hand on graph paper or with any available plotting program such as MS Excel.
NOTE: You can run this program on any of the ECE lab PCs or your own computer. For your home
computer, Visual Studio is available free for ECE students at:
http://msdn02.e-academy.com/elms/Storefront/Storefront.aspx?campus=git_ece
pf2

Partial preview of the text

Download Lab Assignment 4: Evaluating Cache Hit Rates for Different Cache Architectures - Prof. Jam and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

Score:______ Section:____________ Date:__________ Name:______________________________

ECE 3055 Laboratory Assignment 4

Due Date: Tuesday, March 31

In this lab, you will use C/C++ to write a program that will evaluate and compare the cache hit rates for

several cache architectures. Given a particular cache memory organization, the program will read a file

containing a memory trace (a sequence of memory addresses) and determine which of the memory

references will cause cache hits. The program should keep track of the total number of hits and misses

generated by each cache over the entire trace. The hit rate should be plotted for different cache memory

sizes and architectures (as detailed below). You only need to keep track of hits and misses and do not need

to save all of the data values.

The trace file is available from the Lab Web page:

http://www.ece.gatech.edu/~hamblen/3055/gcc_trace2.zip

There are 1,000,000 memory references in the trace file stored one per line. These were collected from the

gcc C compiler while it was running on a MIPS processor. Each line has three fields. The address is the

second field on the line. The first field gives the type of the memory reference (2 for instruction fetch, 1 for

a store’s data memory write, and 0 for a load’s data memory read). The third field gives the instruction

value for a fetch and is always 0 for loads and stores. Keep track of miss rate for instructions and data. To

help you get started on the lab, a simple program that reads the trace file, extracts the address, and performs

some simple bit-wise operations similar to what is needed to extract bit fields from the address to determine

the cache address is available at the URL below in C and setup as a complete Visual Studio 2005 Project

Win32 API Console Application (no complex GUI – text only window for output).

http://www.ece.gatech.edu/~hamblen/3055/read_trace.zip

Use File-> Open ->Project/Solution to open a VS project. Use Build ->Build Solution to compile, and

then Debug -> Start Debugging to run. Use File->Open->File to view and edit source code.

( 60% ) Part 1: On a single page, plot the cache miss rates versus cache memory size for a processor with

two direct-mapped caches. The I cache is used for Instruction fetches only and the D cache is used only for

data (lw, sw memory data operands). The separate Instruction and Data cache architecture is used in most

modern processors. The size of each cache is the same. The simulation should output data points for cache

memory sizes starting at 256 to 16K in powers of two. 1K means 1K cached data locations in each cache.

Do not count writes in the hit rate calculation. Assume byte addressing and the block size is one 32-bit

word. Generate a plot of miss rate vs. cache size, with one curve for instructions and one curve for data.

( 40% ) Part 2 - Repeat part 1 for a set associative cache with a set size of 1, 2, 4 and 8 sets in the cache with

the same number of cache data locations as in part 1. Generate two plots (one for instructions and one for

data) where the total data locations held in the cache are constant while the number of sets varies – like

Figure 5.30 in the text. Use true LRU replacement, so design a data structure that allows you to determine

LRU.

You do not have to write code to plot the data, only to calculate it. The plotting can be done by any

method you wish, e.g. by hand on graph paper or with any available plotting program such as MS Excel.

NOTE: You can run this program on any of the ECE lab PCs or your own computer. For your home

computer, Visual Studio is available free for ECE students at:

http://msdn02.e-academy.com/elms/Storefront/Storefront.aspx?campus=git_ece

// read_trace.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "Windows.h" int _tmain(int argc, _TCHAR* argv[]) { FILE *fp; int i, type; unsigned int address, instr; unsigned int masked_addr; // open trace file for reading – will need to change path for your setup fp = fopen("c:\Users\Hamblen\Documents\3055OS\gcc_trace2.txt", "r"); if (fp == NULL) printf("data file open error"); // read first 100 lines of trace file; // address holds address in unsigned int format; // N.B. - your program must read all 1,000,000 lines but // you might want to test it on the first 100 lines // or so before running it on the entire trace file! for (i=0; i<100; ++i) { // read 1 line of trace file fscanf_s(fp, "%d %x %x", &type, &address, &instr); // example of bit-wise operation in C; // mask off all but the 2nd least significant hex digit, // shift right by 4 bits, and print address in hex and // masked shifted address in decimal masked_addr = (address & 0x000000f0) >> 4; printf("%8x %2d\n", address, masked_addr); } // Delay a bit to see output Sleep(5000); return 0; }