Skip to content

Commit 2f08378

Browse files
committed
clean up
1 parent a061a4b commit 2f08378

2 files changed

Lines changed: 58 additions & 27 deletions

File tree

example/plugin_v2/CMakeLists.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
cmake_minimum_required(VERSION 3.12)
22

33
# Set the project name
4-
project(plugin_lru_hooks)
4+
project(plugin_lru_example)
5+
56

67
# Set C++ standard
78
set(CMAKE_CXX_STANDARD 17)
@@ -55,14 +56,6 @@ target_link_libraries(plugin_lru_hooks
5556
${LIBCACHESIM_LIBRARY}
5657
)
5758

58-
# Set library properties
59-
# set_target_properties(plugin_lru_hooks PROPERTIES
60-
# VERSION 1.0.0
61-
# SOVERSION 1
62-
# OUTPUT_NAME "plugin_lru_hooks"
63-
# )
64-
65-
# Optional: Add test executable if test file exists
6659
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test_hooks_plugin.c")
6760
add_executable(test_hooks_plugin test_hooks_plugin.c)
6861
target_include_directories(test_hooks_plugin PRIVATE

example/plugin_v2/README.md

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
# Plugin LRU Hooks Example
1+
# Plugin V2 Example - LRU Cache with Hooks
22

3-
This example demonstrates how to create a plugin for libCacheSim using the hook-based system implemented in `plugin_cache.c`.
3+
This example demonstrates how to create a plugin for libCacheSim using the v2 hook-based plugin system. The plugin implements a standalone LRU (Least Recently Used) cache algorithm that integrates with libCacheSim's plugin_cache.c framework.
44

55
## Files
66

7-
- `plugin_lru_hooks.cpp` - The main LRU cache plugin implementation with hooks
8-
- `plugin_func.cpp` - Additional plugin functions
9-
- `test_hooks_plugin.c` - Test program for the plugin
10-
- `CMakeLists.txt` - Build configuration for creating a shared library
7+
- `plugin_lru.cpp` - The main LRU cache plugin implementation using hooks
8+
- `test_hooks_plugin.c` - Comprehensive test program for the plugin
9+
- `CMakeLists.txt` - Build configuration for creating the shared library
1110

1211
## Building
1312

@@ -21,29 +20,68 @@ make
2120
```
2221

2322
This will create:
24-
- `libplugin_lru_hooks.so` - The shared library containing the plugin
25-
- `test_hooks_plugin` - A test executable (if test file exists)
23+
- `libplugin_lru_hooks.so` - Shared library
24+
- `test_hooks_plugin` - Test executable for validation
2625

27-
## Plugin Interface
26+
## Plugin Architecture
2827

29-
The plugin implements the following hook functions expected by libCacheSim's plugin system:
28+
The plugin implements a standalone LRU cache using C++ with a C interface for compatibility with libCacheSim. It uses:
3029

31-
- `cache_init_hook()` - Initialize the cache data structure
32-
- `cache_hit_hook()` - Handle cache hits (move to head of LRU list)
30+
- **StandaloneLRU Class**: C++ implementation with doubly-linked list and hash map
31+
- **Hook Functions**: C interface functions that plugin_cache.c calls
32+
33+
### Hook Functions
34+
35+
The plugin implements these required hook functions:
36+
37+
- `cache_init_hook()` - Initialize the LRU cache data structure
38+
- `cache_hit_hook()` - Handle cache hits (move object to head of LRU list)
3339
- `cache_miss_hook()` - Handle cache misses (insert new object)
34-
- `cache_eviction_hook()` - Evict least recently used object
40+
- `cache_eviction_hook()` - Evict least recently used object and return its ID
3541
- `cache_remove_hook()` - Remove specific object from cache
3642

3743
## Usage
3844

45+
### With cachesim Binary
3946

47+
```bash
48+
# Run cachesim with the plugin
49+
./bin/cachesim ../data/cloudPhysicsIO.vscsi vscsi lru,pluginCache 0.01,0.1 \
50+
-e "plugin_path=/path/to/libCacheSim/example/plugin_v2/build/libplugin_lru_hooks.so"
4051
```
41-
./bin/cachesim ../data/cloudPhysicsIO.vscsi vscsi lru,pluginCache 0.01,0.1 -e "plugin=/proj/cache-PG0/jason/libCacheSim/example/pluginv2/_build/libplugin_lru_hooks.so.1.0.0"
52+
53+
### Testing the Plugin
54+
55+
Run the included test to verify plugin functionality:
56+
57+
```bash
58+
cd build
59+
./test_hooks_plugin
4260
```
4361

62+
The test compares the plugin LRU implementation against libCacheSim's built-in LRU to ensure identical behavior.
63+
4464
## Dependencies
4565

46-
- libCacheSim headers
47-
- GLib (for basic data types)
48-
- C++17 compiler
49-
- CMake 3.12 or higher
66+
- **libCacheSim**: Headers and libraries from the main project
67+
- **CMake 3.12+**: Build system
68+
69+
## Plugin Parameter Format
70+
71+
When using the plugin with cachesim or other libCacheSim tools, use the format:
72+
```
73+
plugin_path=/full/path/to/libplugin_lru_hooks.so
74+
```
75+
76+
## Implementation Notes
77+
78+
- The plugin uses C++ internally but exports C functions for compatibility
79+
- Memory management is handled automatically by the StandaloneLRU destructor
80+
- The implementation maintains the same LRU semantics as libCacheSim's built-in LRU
81+
- Thread safety is not implemented - suitable for single-threaded use cases
82+
83+
## Troubleshooting
84+
85+
- Ensure the plugin path uses the `plugin_path=` prefix format
86+
- Verify all dependencies are available (check with `ldd libplugin_lru_hooks.so`)
87+
- Use absolute paths when specifying the plugin location

0 commit comments

Comments
 (0)