|
1 | | -# Plugin LRU Hooks Example |
| 1 | +# Plugin V2 Example - LRU Cache with Hooks |
2 | 2 |
|
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. |
4 | 4 |
|
5 | 5 | ## Files |
6 | 6 |
|
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 |
11 | 10 |
|
12 | 11 | ## Building |
13 | 12 |
|
|
21 | 20 | ``` |
22 | 21 |
|
23 | 22 | 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 |
26 | 25 |
|
27 | | -## Plugin Interface |
| 26 | +## Plugin Architecture |
28 | 27 |
|
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: |
30 | 29 |
|
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) |
33 | 39 | - `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 |
35 | 41 | - `cache_remove_hook()` - Remove specific object from cache |
36 | 42 |
|
37 | 43 | ## Usage |
38 | 44 |
|
| 45 | +### With cachesim Binary |
39 | 46 |
|
| 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" |
40 | 51 | ``` |
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 |
42 | 60 | ``` |
43 | 61 |
|
| 62 | +The test compares the plugin LRU implementation against libCacheSim's built-in LRU to ensure identical behavior. |
| 63 | + |
44 | 64 | ## Dependencies |
45 | 65 |
|
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