0% found this document useful (0 votes)
14 views5 pages

Cache Memory Simulation Exercise

This document provides instructions for using two MARS tools - the Data Cache Simulator and Memory Reference Visualization tool. It walks through running sample programs to analyze cache performance and visualize memory access patterns. The Data Cache Simulator allows configuring and observing cache hit rates. The Memory Reference Visualization tool paints a grid to show frequency of memory word access. Together these tools help understand effects of memory hierarchy and reference patterns.

Uploaded by

Diện Nghiêm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Cache Memory Simulation Exercise

This document provides instructions for using two MARS tools - the Data Cache Simulator and Memory Reference Visualization tool. It walks through running sample programs to analyze cache performance and visualize memory access patterns. The Data Cache Simulator allows configuring and observing cache hit rates. The Memory Reference Visualization tool paints a grid to show frequency of memory word access. Together these tools help understand effects of memory hierarchy and reference patterns.

Uploaded by

Diện Nghiêm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Laboratory Exercise 12

Cache Memory

Running the Data Cache Simulator tool

1. Close any MIPS programs you are currently using.

2. Open the program [Link] from the Examples folder. This program
will traverse a 16 by 16 element integer matrix in row-major order, assigning
elements the values 0 through 255 in order. It performs the following algorithm:

for (row = 0; row < 16; row++)


for (col = 0; col < 16; col++)
data[row][col] = value++;

3. Assemble the program.

4. From the Tools menu, select Data Cache Simulator. A new frame will appear in the
middle of the screen.

This is a MARS Tool that will simulate the use and performance of cache memory
when the underlying MIPS program executes. Notice its three major sections:
 Cache Organization: You can use the combo boxes to specify how the cache
will be configured for this run. Feel free to explore the different settings, but
the default is fine for now.

Page 1
 Cache Performance: With each memory access during program execution,
the simulator will determine whether or not that access can be satisfied from
cache and update the performance display accordingly.
 Tool Control: These buttons perform generic control functions as described
by their labels.

5. Click the tool's Connect to MIPS button. This causes the tool to register as an
observer of MIPS memory and thus respond during program execution.

6. Back in MARS, adjust the Run Speed slider to 30 instructions per second. It is
located at the right side of the toolbar. This slows execution so you can watch the
Cache Performance animation.

7. In MARS, run the program using the Run toolbar button , the menu item or
keyboard shortcut. Watch the Cache Performance animate as it is updated with every
access to MIPS memory.

8. What was the final cache hit rate? _____________. With each miss, a block of 4
words are written into the cache. In a row-major traversal, matrix elements are
accessed in the same order they are stored in memory. Thus each cache miss is
followed by 3 hits as the next 3 elements are found in the same cache block. This is
followed by another miss when Direct Mapping maps to the next cache block, and the
patterns repeats itself. So 3 of every 4 memory accesses will be resolved in cache.

9. Given that explanation, what do you predict the hit rate will be if the block size is
increased from 4 words to 8 words? ______________. Decreased from 4 words to 2
words? ___________.

10. Verify your predictions by modifying the block size and re-running the program
from step 7.
NOTE: when you modify the Cache Organization, the performance values are
automatically reset (you can always use the tool's Reset button).

NOTE: You have to reset the MIPS program before you can re-run it.
NOTE: Feel free to adjust the Run Speed slider to maximum speed anytime you
want.

11. Repeat steps 2 through 10 for program [Link] from the


Examples folder. This program will traverse a 16 by 16 element integer matrix in
column-major order, assigning elements the values 0 through 255 in order. It
performs the following algorithm:

for (col = 0; col < 16; col++)

Page 2
for (row = 0; row < 16; row++)
data[row][col] = value++;

NOTE: You can leave the Cache Simulator in place, move it out of the way, or close
it. It will not interfere with the actions needed to open, assemble, or run this new
program and will remain connected to MIPS memory. If you do not close the tool,
then skip steps 4 and 5.

12. What was the cache performance for this program? ____________. The
problem is the memory locations are now accessed not sequentially as before, but
each access is 16 words beyond the previous one (circularly). With the settings we've
used, no two consecutive memory accesses occur in the same block so every access is
a miss.

13. Change the block size to 16. Note this will reset the tool.

14. Create a second instance of the Cache Simulator by once again selecting Data
Cache Simulator from the Tools menu. Adjust the two frames so you can view both
at the same time. Connect the new tool instance to MIPS, change its block size to 16
and change its number of blocks to 16.

15. Re-run the program. What is the cache performance of the original tool instance?
____________. Block size 16 didn't help because there was still only one access to
each block, the initial miss, before that block was replaced with a new one. What is
the cache performance of the second tool instance? ____________. At this point,
the entire matrix will fit into cache and so once a block is read in it is never replaced.
Only the first access to a block results in a miss.

Page 3
The Memory Reference Visualization tool

1. Open the program [Link] from the Examples folder if it is not already
open.

2. Assemble the program.

3. From the Tools menu, select Memory Reference Visualization. A new frame will
appear in the middle of the screen.

This tool will paint a grid unit each time the corresponding MIPS memory word is
referenced. The base address, the first static data segment (.data directive) word,
corresponds to the upper-left grid unit. Address correspondence continues in row-
major order (left to right, then next row down).

The color depends on the number of times the word has been referenced. Black is 0,
blue is 1, green is 2, yellow is 3 and 4, orange is 5 through 9, red is 10 or higher.
View the scale using the tool’s slider control. You can change the color (but not the
reference count) by clicking on the color patch.

4. Click the tool's Connect to MIPS button. This causes the tool to register as an
observer of MIPS memory and thus respond during program execution.

5. Back in MARS, adjust the Run Speed slider to 30 instructions per second.
6. Run the program. Watch the tool animate as it is updated with every access to MIPS
memory. Feel free to stop the program at any time.

Page 4
7. Hopefully you observed that the animation sequence corresponded to the expected
memory access sequence of the [Link] program. If you have trouble seeing
the blue, reset the tool, move the slider to position 1, change the color to something
brighter, and re-run.

8. Repeat steps 2 through 7, for [Link]. You should observe that the
animation sequence corresponded to the expected memory access sequence of this
program.

9. Repeat again for [Link] to observe the animated pattern of memory


references. Adjust the run speed and re-run if necessary.

10. (Optional) Create a new instance of the Data Cache Simulator. Move the two frames
around so you can see both. Connect the cache simulator to MIPS and reset the
Memory Reference Visualization. Re-run the program. This exercise illustrates that
two different tools can be used simultaneously.

The Memory Reference Visualization tool could be useful in an operating systems course
to illustrate spatial and temporal locality and memory reference patterns in general.

Page 5

Common questions

Powered by AI

In row-major order traversal, elements are accessed sequentially, often allowing multiple accesses to be resolved in the same cache block, leading to fewer misses and a higher hit rate. In contrast, column-major order results in each memory access being substantially apart in memory, leading every access to be a miss under the same cache configuration, particularly when the block size is less than the size of a matrix column .

In column-major traversal, each access is to a different cache block due to the large stride between access addresses. Thus, even if the entire matrix fits into cache, each access still results in a cache miss due to non-contiguous access patterns that do not take advantage of temporal locality like row-major access does .

The Memory Reference Visualization tool uses color indicators to represent the number of times a memory word is accessed. This visual representation helps in understanding the density and frequency of memory accesses, thereby illustrating spatial and temporal locality. For example, frequently accessed words become red, indicating high access, while rarely accessed ones may be black or blue, facilitating a clear visual stratification of access patterns .

When the block size equals the number of columns in a column-major traversal, each column's data fits entirely within a single cache block, ensuring that after the first access miss, all subsequent accesses in that column are hits. This reduces the miss rate compared to smaller block sizes where frequent misses occur due to accesses spanning multiple cache blocks .

The Memory Reference Visualization tool can visually demonstrate memory access patterns such as spatial and temporal locality, which are crucial concepts in operating systems. By observing how memory is accessed and reused over time, students can better understand concepts like cache management and virtual memory systems, providing a practical complement to theoretical learning .

To compare different cache efficiencies using multiple instances of the Data Cache Simulator, you can configure each instance separately by selecting the Data Cache Simulator from the Tools menu multiple times. Connect each instance to MIPS, modify settings such as block size or number of blocks uniquely for each instance to simulate different scenarios, and observe the performance results during program execution .

The 'Connect to MIPS' function in both tools allows them to act as observers of MIPS memory during program execution. This connection enables the tools to update their displays in real-time as memory accesses occur, which is vital for visualizing cache performance and memory reference patterns dynamically .

Increasing the cache block size from 4 words to 8 words during a row-major order traversal of a matrix improves the cache hit rate. With a block size of 8, multiple consecutive elements are accessed before a miss occurs. As such, a larger block size reduces the number of cache misses and improves performance, since each miss fetches more elements aligned with the traversal pattern .

Adjusting the run speed slider in the MARS simulator allows slowing down or speeding up the execution of instructions, which impacts the visibility of cache and memory reference pattern animations. Slowing down offers a clearer view of how frequently and in what patterns memory is accessed, while speeding up accelerates execution when detailed observation is unnecessary .

Row-major traversal is more efficient because it exploits spatial locality; consecutive matrix elements are stored and accessed sequentially, fitting within the same cache block and resulting in fewer cache misses. On the other hand, column-major traversal results in memory accesses that skip across rows, preventing efficient use of cache due to frequent cache block replacements .

You might also like