Skip to content

Anish-Yadav-git/Cache-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cache Simulator

A comprehensive, modular C++ cache simulator that models real computer memory cache behavior with support for various cache configurations, replacement policies, and write strategies.

โœจ Features

Core Simulation

  • ๐Ÿ—๏ธ Multiple Cache Types: Direct-mapped, Set-associative, Fully associative
  • ๐Ÿ”„ Replacement Policies: LRU (Least Recently Used), FIFO (First In First Out), Random
  • โœ๏ธ Write Policies: Write-through, Write-back with dirty bit tracking
  • ๐Ÿ“ Write Miss Policies: Write-allocate, No-write-allocate
  • ๐Ÿ“Š Detailed Statistics: Hit rate, miss rate, read/write breakdown with performance analysis
  • ๐Ÿงฉ Modular Design: Easy to extend with new policies and configurations
  • ๐ŸŽฏ Educational Focus: Perfect for learning computer architecture concepts

User Interfaces

  • ๐ŸŽจ Qt GUI: Modern desktop application with real-time cache visualization (gui/qt/)
  • โŒจ๏ธ Command Line Interface: Comprehensive CLI with configuration options
  • ๐ŸŽฎ Interactive Mode: Real-time cache experimentation and testing
  • ๐ŸŒ Web Interface: Browser-based GUI with REST API backend (gui/web/)

Advanced Features

  • ๐Ÿ”ง Debug Support: Cache contents visualization and comprehensive logging
  • ๐Ÿ“‹ Batch Processing: Support for custom memory access patterns and trace files
  • ๐Ÿ“„ File I/O: Read trace files and write detailed statistics reports
  • ๐ŸŽฏ Real-time Visualization: Live cache state display with color-coded blocks
  • ๐Ÿ“ก Network API: RESTful API for integration with other tools

๐Ÿš€ Quick Start

Build and Run

# Build the project (includes Qt GUI)
make

# Run Qt GUI (recommended)
./bin/cache_gui

# Run command-line version
./bin/cache_simulator

# Run web server backend
./bin/cache_server

# Show help
./bin/cache_simulator --help

GUI Usage

# Start the Qt GUI application
./bin/cache_gui

# Or use the web interface:
# 1. Start the backend server
./bin/cache_server

# 2. Open browser to: gui/web/interface/index.html

Command Line Usage

# Process trace file
./bin/cache_simulator -t examples/traces/sample_trace.txt -o examples/output/results.txt

# Custom cache configuration
./bin/cache_simulator -s 2048 -b 64 -a 8 -r LRU -w WRITE_BACK

# Interactive mode
./bin/cache_simulator --interactive

๐Ÿ“ Project Structure

cache-simulator/
โ”œโ”€โ”€ ๐Ÿ“ docs/                    # Documentation
โ”œโ”€โ”€ ๐Ÿ“ examples/                # Example files and traces
โ”‚   โ”œโ”€โ”€ traces/                 # Sample trace files
โ”‚   โ””โ”€โ”€ output/                 # Output files (git-ignored)
โ”œโ”€โ”€ ๐Ÿ“ include/                 # Header files
โ”œโ”€โ”€ ๐Ÿ“ src/                     # Source files
โ”œโ”€โ”€ ๐Ÿ“ tests/                   # Test files
โ”œโ”€โ”€ ๐Ÿ“ gui/                     # GUI implementations
โ”‚   โ”œโ”€โ”€ qt/                     # Qt-based GUI
โ”‚   โ””โ”€โ”€ web/                    # Web-based GUI
โ”œโ”€โ”€ ๐Ÿ“ build/                   # Build artifacts (git-ignored)
โ”œโ”€โ”€ ๐Ÿ“ bin/                     # Executables (git-ignored)
โ”œโ”€โ”€ CMakeLists.txt              # CMake configuration
โ”œโ”€โ”€ Makefile                    # Build wrapper
โ”œโ”€โ”€ .gitignore                  # Git ignore rules
โ””โ”€โ”€ LICENSE                     # MIT License

๐Ÿ› ๏ธ Building

Prerequisites

  • C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 2017+)
  • CMake 3.14 or higher
  • Make utility
  • Qt 6.x (for GUI applications)
  • Network libraries (for web interface)

Build Commands

# Quick build and run
make run

# Build all targets
make

# Clean build
make clean && make

# Run tests
make test

# Build debug version
make debug

๐Ÿ“– Documentation

๐Ÿงช Testing

# Run comprehensive tests
make test

# Run functionality verification
./tests/test_comprehensive.sh

๐Ÿ”ง Configuration Options

Option Description Default
-s, --cache-size Cache size in bytes 1024
-b, --block-size Block size in bytes 32
-a, --associativity Associativity (1=direct, 0=fully) 4
-r, --replacement Replacement policy (LRU/FIFO/RANDOM) LRU
-w, --write-policy Write policy (WRITE_THROUGH/WRITE_BACK) WRITE_THROUGH
-t, --trace-file Input trace file -
-o, --output-file Output statistics file stats.txt
-i, --interactive Interactive mode false
-v, --verbose Verbose output false
-q, --quiet Suppress console output false

๐Ÿ“Š Example Output

Cache Statistics:
  Total Accesses: 36
  Hits: 32
  Misses: 4
  Hit Rate: 88.89%
  Miss Rate: 11.11%

  Read Accesses: 22
  Write Accesses: 14
  Read Hit Rate: 90.91%
  Write Hit Rate: 85.71%

๐ŸŽฏ Use Cases

  • Academic Research: Analyze real program traces and cache behavior
  • Education: Learn computer architecture concepts with hands-on simulation
  • Performance Analysis: Evaluate cache configurations for specific workloads
  • Algorithm Development: Test and compare replacement policies

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Computer Architecture textbooks and research papers
  • Open-source cache simulation tools
  • Educational institutions using this for teaching

Made with โค๏ธ for computer architecture education and research

About

A comprehensive, modular C++ cache simulator that models real computer memory cache behavior with support for various cache configurations, replacement policies, and write strategies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors