# cache_stash **Repository Path**: cloudyyy1234/cache_stash ## Basic Information - **Project Name**: cache_stash - **Description**: 本仓库用于cache_stash测试 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-13 - **Last Updated**: 2026-02-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LLC Stash Control Driver This kernel driver provides a sysfs interface to enable or disable LLC (Last Level Cache) stash functionality on ARM Linux systems. ## Overview LLC stash functionality is controlled by manipulating specific bits (15:14) in IOB_RX registers. The addresses of these registers are calculated dynamically based on hardware topology using the formula: `Register address = socket base + IODie offset + PCIe core offset + submodule offset + register offset` Hardware parameters: - Socket base: socketID * 0x200000000000 - IODie offset: ioDieID * 0x8000000000 - PCIe core offsets: 0x101000000, 0x302000000, 0x303000000 (3 cores per IOdie) - Submodule offset: 0x4000 - Register offset: 0x1C50 (IOB_RX register) - Enable: Set bits 15:14 to 0 - Disable: Set bits 15:14 to 3 ## Building the Driver To build the driver: ```bash make ``` This will create `cache_stash.ko`, the loadable kernel module. ## Loading the Driver Load the driver using insmod: ```bash sudo insmod cache_stash.ko ``` ## Using the SysFS Interface Once loaded, the driver creates a directory `/sys/kernel/cache_stash/` with the following files: ### `llc_enable` Controls whether LLC stash is enabled or disabled. - Read to check current status (returns 1 if enabled, 0 if disabled) - Write to change status (`echo 1 > llc_enable` to enable, `echo 0 > llc_enable` to disable) ### `l2_enable` Controls whether L2 stash is enabled or disabled. - Read to check current status (returns 1 if enabled, 0 if disabled) - Write to change status (`echo 1 > l2_enable` to enable, `echo 0 > l2_enable` to disable) ### `l2_target` Controls the L2 stash target configuration. - Read to check current configuration - Write to change target (format: `echo "use_specific_core target_core_number" > l2_target`) ### `status` Read-only file that displays the current status of both LLC and L2 stash, along with number of registers being controlled and detailed register values. ## Example Usage Check current status: ```bash cat /sys/kernel/cache_stash/status ``` Enable LLC stash: ```bash echo 1 | sudo tee /sys/kernel/cache_stash/llc_enable ``` Disable LLC stash: ```bash echo 0 | sudo tee /sys/kernel/cache_stash/llc_enable ``` Enable L2 stash: ```bash echo 1 | sudo tee /sys/kernel/cache_stash/l2_enable ``` Configure L2 stash to target specific core (e.g., core 2): ```bash echo "1 2" | sudo tee /sys/kernel/cache_stash/l2_target ``` View current register values: ```bash cat /sys/kernel/cache_stash/status ``` ## Testing the Driver The project includes a comprehensive shell-based test suite: 1. **test_functional.sh**: An automated shell script that validates driver functionality 2. **test_boundary.sh**: A specialized script for boundary and edge case testing 3. **test_driver.sh**: A master script to orchestrate building, loading, testing, and cleanup ### Running Tests To run the full test cycle: ```bash # Make scripts executable (on Linux) chmod +x test_driver.sh test_functional.sh test_boundary.sh # Run the full test cycle (build, load, functional tests, boundary tests, cleanup) sudo ./test_driver.sh run-all ``` Or run specific test types: ```bash # Build the module ./test_driver.sh build # Load the module sudo ./test_driver.sh load # Run functional tests only sudo ./test_driver.sh test # Run boundary tests only sudo ./test_driver.sh boundary # Run both functional and boundary tests sudo ./test_driver.sh run-all # Run only functional tests (build, load, test, unload) sudo ./test_driver.sh run-functional # Run only boundary tests (build, load, boundary test, unload) sudo ./test_driver.sh run-boundary # Unload the module sudo ./test_driver.sh unload # Clean up ./test_driver.sh clean ``` ### Functional Tests (test_functional.sh) - Verifies sysfs interface availability - Tests reading and writing of all attributes - Validates state persistence after changes - Checks register value reporting - Performs stress testing with multiple read/write cycles ### Boundary Tests (test_boundary.sh) - Tests invalid input values (out of range values) - Tests malformed input (non-numeric, too many parameters) - Tests edge cases for L2 target values - Performs rapid toggling to detect race conditions - Tests error handling for non-existent attributes - Attempts large string injection to detect buffer issues - Validates consistent behavior under load ## Unloading the Driver Unload the driver using rmmod: ```bash sudo rmmod cache_stash ``` ## Hardware Compatibility This driver dynamically detects hardware topology including number of sockets and IODies per socket. The PCIe core offset values are currently hardcoded but can be modified in the configuration header if needed for different hardware platforms. ## Important Notes - Requires root privileges to operate - Direct hardware register access requires careful handling - Only tested on ARM Linux platforms - The driver automatically discovers hardware topology at initialization time