Skip to content

About

cache handling

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cache-Aware Programming: LRU Cache Simulator

A configurable command-line cache simulator written in C. It reads hexadecimal memory-address traces, models a set-associative cache, and reports hits, misses, miss rate, and estimated execution time using least recently used (LRU) replacement.

Features

  • Configurable address, set-index, associativity, and block-offset widths
  • LRU replacement within each cache set
  • Per-access hit/miss output and aggregate performance statistics
  • Included sample memory traces
  • Warning-enabled build and smoke-test commands

How it works

Each address is divided into tag | set index | block offset. The simulator uses the set-index bits to locate a set and compares the tag against every valid line in that set. On a miss, it fills an empty line or evicts the least recently used line.

Project structure

.
├── examples/              # Sample hexadecimal address traces
├── include/cachelab.h     # Timing constants and result interface
├── src/cache_simulator.c  # Simulator implementation
├── Makefile               # Build, run, test, and clean targets
└── README.md

Build

Requirements: a C11-compatible compiler and make.

make

The executable is created at build/cachelab.

Usage

./build/cachelab -m 64 -s 4 -e 0 -b 4 -i examples/address01.txt -r lru
Option Meaning
-m Address width in bits
-s Set-index bits; sets = 2^s
-e Log2 of lines per set; lines = 2^e
-b Block-offset bits; block size = 2^b bytes
-i Hexadecimal address-trace path
-r Replacement policy (currently lru)

For this example, the simulator models 16 sets, one line per set, and 16-byte blocks.

Test

make test

This builds the project with strict compiler warnings and runs every included trace.

Possible next steps

  • Add FIFO and random replacement policies
  • Support Valgrind-style load/store traces
  • Report eviction counts and per-set statistics
  • Add automated unit tests and continuous integration

Author

Aditya Raj Singh — Computer Science student at SUNY Oswego

About

cache handling

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages