Skip to content

Commit 04d7a66

Browse files
committed
update dcd and cxlmemsim_legacy
1 parent 4d2a86f commit 04d7a66

84 files changed

Lines changed: 114580 additions & 112815 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ endif()
4444
set(SOURCE_FILES
4545
src/cxlcontroller.cpp
4646
src/cxlendpoint.cpp
47+
src/dcd_gfam.cpp
48+
src/hdm_decoder.cpp
49+
src/coherency_engine.cpp
4750
src/policy.cpp
4851
src/helper.cpp
4952
)
@@ -54,6 +57,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
5457
src/uncore.cpp
5558
src/perf.cpp
5659
src/monitor.cpp
60+
src/rob.cpp
61+
src/lbr.cpp
62+
src/pebs.cpp
63+
src/perf.cpp
5764
)
5865
endif()
5966

@@ -63,6 +70,8 @@ add_library(cxlmemsim STATIC ${SOURCE_FILES})
6370
target_include_directories(cxlmemsim PUBLIC include ${spdlog_INCLUDE_DIR})
6471
target_link_libraries(cxlmemsim spdlog::spdlog_header_only)
6572

73+
enable_testing()
74+
6675
# Build latency calculator
6776
add_executable(cxlmemsim_latency src/calculateLatency.cc)
6877
set_target_properties(cxlmemsim_latency PROPERTIES
@@ -85,7 +94,7 @@ else()
8594
endif()
8695

8796
# Server library (shared between server executable and tests)
88-
set(SERVER_LIB_SOURCES src/shared_memory_manager.cc src/shm_communication.cpp src/distributed_server.cpp src/tcp_communication.cpp src/rdma_communication.cpp src/hdm_decoder.cpp src/coherency_engine.cpp)
97+
set(SERVER_LIB_SOURCES src/shared_memory_manager.cc src/shm_communication.cpp src/distributed_server.cpp src/tcp_communication.cpp src/rdma_communication.cpp)
8998
add_library(cxlmemsim_server_lib STATIC ${SERVER_LIB_SOURCES})
9099
target_include_directories(cxlmemsim_server_lib PUBLIC include src ${spdlog_INCLUDE_DIR})
91100
target_link_libraries(cxlmemsim_server_lib cxlmemsim spdlog::spdlog_header_only ${RT_LIB} ${RDMA_LIBS})
@@ -95,14 +104,46 @@ add_executable(cxlmemsim_server src/main_server.cc)
95104
target_include_directories(cxlmemsim_server PRIVATE include src ${spdlog_INCLUDE_DIR})
96105
target_link_libraries(cxlmemsim_server cxlmemsim_server_lib cxlmemsim spdlog::spdlog_header_only ${RT_LIB} ${ATOMIC_LIB})
97106

98-
# Distributed SHM test
107+
# Build legacy CXLMemSim
108+
add_executable(cxlmemsim_legacy src/main.cc)
109+
target_include_directories(cxlmemsim_legacy PRIVATE include src ${spdlog_INCLUDE_DIR})
110+
target_link_libraries(cxlmemsim_legacy cxlmemsim_server_lib cxlmemsim spdlog::spdlog_header_only ${RT_LIB} ${ATOMIC_LIB})
111+
112+
# Distributed SHM integration test. It opens shared-memory transport state and
113+
# may start TCP helpers, so build it but keep it out of always-on CTest.
99114
add_executable(test_distributed_shm tests/test_distributed_shm.cpp)
100115
target_include_directories(test_distributed_shm PRIVATE include src ${spdlog_INCLUDE_DIR})
101116
target_link_libraries(test_distributed_shm cxlmemsim_server_lib cxlmemsim spdlog::spdlog_header_only ${RT_LIB} ${ATOMIC_LIB})
102117

118+
# DCD/GFAM unit test (standalone; no server dependencies)
119+
add_executable(test_dcd_gfam tests/test_dcd_gfam.cpp src/dcd_gfam.cpp)
120+
target_include_directories(test_dcd_gfam PRIVATE include)
121+
add_test(NAME test_dcd_gfam COMMAND test_dcd_gfam)
122+
123+
# ROB/O3CPU trace tests
124+
add_executable(test_rob tests/test_rob.cc src/rob.cpp)
125+
target_include_directories(test_rob PRIVATE include src ${spdlog_INCLUDE_DIR})
126+
target_link_libraries(test_rob cxlmemsim spdlog::spdlog_header_only ${RT_LIB} ${ATOMIC_LIB})
127+
add_test(NAME test_rob COMMAND test_rob)
128+
129+
add_executable(test_mem_stall tests/test_mem_stall.cc src/rob.cpp)
130+
target_include_directories(test_mem_stall PRIVATE include src ${spdlog_INCLUDE_DIR})
131+
target_link_libraries(test_mem_stall cxlmemsim spdlog::spdlog_header_only ${RT_LIB} ${ATOMIC_LIB})
132+
add_test(NAME test_mem_stall COMMAND test_mem_stall)
133+
134+
# Integration-style test clients. They require an external server/DAX setup, so
135+
# CMake builds them but does not register them as always-on CTest tests.
136+
add_executable(test_back_invalidation tests/test_back_invalidation.cpp)
137+
target_include_directories(test_back_invalidation PRIVATE include src)
138+
target_link_libraries(test_back_invalidation ${RT_LIB} ${ATOMIC_LIB})
139+
140+
add_executable(test_dax_back_invalidation tests/test_dax_back_invalidation.cpp)
141+
target_include_directories(test_dax_back_invalidation PRIVATE include src)
142+
target_link_libraries(test_dax_back_invalidation ${RT_LIB} ${ATOMIC_LIB})
143+
103144
# Installation targets
104145
install(TARGETS cxlmemsim_server
105146
RUNTIME DESTINATION bin)
106147

107-
install(FILES include/tcp_communication.h include/rdma_communication.h
148+
install(FILES include/tcp_communication.h include/rdma_communication.h include/dcd_gfam.h
108149
DESTINATION include/cxlmemsim)

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2026 Regents of the University of California, UC Santa Cruz Sluglab.
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ microbench/ Microbenchmarks
1919
tests/ Server/distributed-mode tests
2020
qemu_integration/ Launch scripts and guest-side integration
2121
qemu_integration/guest_libcuda/ Guest CUDA Driver API shim for CXL Type 2 GPU
22+
gem5_integration/ gem5-CXL launch wrapper and O3CPU trace setup
2223
lib/qemu/ QEMU tree with CXL Type 2/Type 3 device changes
2324
lib/qemu/hw/cxl/cxl_type2.c QEMU CXL Type 2 device model
2425
lib/qemu/hw/cxl/cxl_hetgpu.c Host GPU backend bridge
@@ -76,7 +77,8 @@ CXLMemSim adds a server-oriented CXL memory backend. The top-level build always
7677
- `cxlmemsim`, a static library with the core simulator.
7778
- `cxlmemsim_server`, the Type 3 memory server.
7879
- `cxlmemsim_latency`, a latency calculator.
79-
- `test_distributed_shm`, a distributed shared-memory test.
80+
- built test binaries for unit and integration checks.
81+
- CTest targets for DCD/GFAM, ROB, and memory-stall unit behavior.
8082

8183
The server entry point is `src/main_server.cc`. It creates a CXL controller, adds a CXL memory expander endpoint, loads the topology, initializes a shared memory pool, and then serves requests from QEMU or test clients.
8284

@@ -88,6 +90,8 @@ Supported request classes include:
8890
- atomic compare-and-swap,
8991
- memory fences,
9092
- Label Storage Area reads and writes.
93+
- Dynamic Capacity Device add, release, and query operations.
94+
- GFAM host map, unmap, access-check, and query operations.
9195

9296
The server supports several communication modes:
9397

@@ -100,6 +104,8 @@ The server supports several communication modes:
100104

101105
The memory pool is managed by `SharedMemoryManager`. It can use POSIX shared memory or a regular file as a backing store. The shared-memory header records a magic value, format version, total size, data offset, base address, and cache-line count. The default cache-line data area is mapped with `mmap()` and is reused when the backing object already exists.
102106

107+
The server CLI uses local parse-result structs in `src/main_server.cc`, `src/main.cc`, and `src/rob.cc`, so command-line parsing is handled in-tree.
108+
103109
## Coherency and Distributed Memory
104110

105111
The distributed path is implemented in:
@@ -289,7 +295,7 @@ multiple QEMU guests or server nodes
289295

290296
## Build
291297

292-
The project uses CMake and C++20. It depends on `cxxopts` and header-only `spdlog`. RDMA support is enabled when `librdmacm` and `libibverbs` are found.
298+
The project uses CMake and C++20. It depends on header-only `spdlog`; the server and ROB tools use in-tree argument parsing. RDMA support is enabled when `librdmacm` and `libibverbs` are found.
293299

294300
```bash
295301
mkdir -p build
@@ -381,6 +387,9 @@ The launcher reads the following runtime variables:
381387
| `CXL_PGAS_SHM` | `/cxlmemsim_pgas` | POSIX shared-memory object used by QEMU SHM mode. |
382388
| `CXL_MEMSIM_SERVER_BINARY` | package `bin/cxlmemsim_server` | Server binary started before QEMU. |
383389
| `CXL_MEMSIM_SERVER_AUTOSTART` | `auto` | Set to `1` to require server startup or `0` to disable it. |
390+
| `CXL_DCD_ENABLE` | `0` | Enables DCD reporting in integration wrappers. |
391+
| `CXL_GFAM_ENABLE` | `0` | Enables GFAM reporting in integration wrappers. |
392+
| `CXL_GFAM_HOST_ID` | `0` | Host ID passed to fabric-aware integrations. |
384393

385394
QEMU's `shm` transport uses the PGAS shared-memory protocol, so the packaged launcher maps `CXL_TRANSPORT_MODE=shm` to the server's `--comm-mode pgas-shm`.
386395

@@ -401,6 +410,8 @@ CXL_MEMSIM_PORT=9999 \
401410
qemu_launch_cxl.sh
402411
```
403412

413+
When QEMU connects to `cxlmemsim_server`, the Type 3 device now queries the DCD and GFAM protocol state. If DCD is enabled, QEMU logs the dynamic allocated, total, and free capacity reported by the server. If GFAM is enabled, QEMU logs host, mapping, operation, denied-access, and average-latency counters. Server-side DCD or GFAM denials are returned to QEMU as memory transaction errors instead of being silently treated as successful reads or writes.
414+
404415
Inside the guest, quick checks are:
405416

406417
```bash
@@ -448,6 +459,24 @@ File-backed memory pool:
448459
--capacity=1024
449460
```
450461

462+
Dynamic Capacity Device and GFAM:
463+
464+
```bash
465+
./build/cxlmemsim_server \
466+
--comm-mode=tcp \
467+
--port=9999 \
468+
--capacity=10000 \
469+
--default_latency=400 \
470+
--topology=topology.txt \
471+
--enable-dcd \
472+
--dcd-granularity-mb=1 \
473+
--dcd-initial-capacity=10000 \
474+
--enable-gfam \
475+
--gfam-hosts=16 \
476+
--gfam-fabric-latency=80 \
477+
--gfam-bandwidth=64
478+
```
479+
451480
Useful options:
452481

453482
| Option | Meaning |
@@ -458,8 +487,17 @@ Useful options:
458487
| `--topology` | Topology file using Newick-style syntax. |
459488
| `--comm-mode` | `tcp`, `shm`, `pgas-shm`, or `distributed`. |
460489
| `--backing-file` | Use a regular file instead of POSIX shared memory. |
490+
| `--enable-dcd` | Enable the Dynamic Capacity Device model. |
491+
| `--dcd-granularity-mb` | DCD allocation granularity in MB. |
492+
| `--dcd-initial-capacity` | Initial DCD capacity in MB. Omit it to allocate the full `--capacity`. |
493+
| `--enable-gfam` | Enable GFAM access control and fabric latency accounting. |
494+
| `--gfam-hosts` | Number of GFAM host IDs to register. |
495+
| `--gfam-fabric-latency` | Per-access GFAM fabric latency in ns. |
496+
| `--gfam-bandwidth` | Aggregate GFAM bandwidth in GB/s. |
461497
| `SPDLOG_LEVEL` | Runtime log level, for example `debug` or `trace`. |
462498

499+
DCD/GFAM protocol operations are available over TCP and the PGAS shared-memory protocol. Query responses use the 64-byte response data area: DCD query returns total capacity, free capacity, active extents, and failed requests; GFAM query returns mappings, shared mappings, read/write/atomic operations, denied accesses, and average access latency.
500+
463501
## Distributed Mode
464502

465503
Coordinator node:
@@ -594,6 +632,62 @@ Available tests include:
594632
- `cxl_pointer_sharing_test`
595633
- `cxl_bias_benchmark`
596634

635+
## Tests
636+
637+
Configure with CMake and run the self-contained unit tests through CTest:
638+
639+
```bash
640+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
641+
cmake --build build -j
642+
ctest --test-dir build --output-on-failure
643+
```
644+
645+
The top-level CMake file builds every test source in `tests/`:
646+
647+
| Target | Purpose | CTest |
648+
| --- | --- | --- |
649+
| `test_dcd_gfam` | Standalone DCD allocation and GFAM access-control checks. | Yes |
650+
| `test_rob` | Parses O3CPU/LSQ debug lines and feeds derived instructions into the ROB model. | Yes |
651+
| `test_mem_stall` | Compares O3CPU memory-stall debug intervals against modeled ROB stalls. | Yes |
652+
| `test_distributed_shm` | Two in-process distributed memory servers over SHM/TCP helper paths. | Built only |
653+
| `test_back_invalidation` | TCP/PGAS client for external back-invalidation experiments. | Built only |
654+
| `test_dax_back_invalidation` | DAX plus TCP client for external guest/device experiments. | Built only |
655+
656+
`test_rob` and `test_mem_stall` use gem5-style O3CPU, LSQ, and MemDepUnit debug text. Generate compatible traces with gem5 debug flags such as `O3CPU,LSQ,MemDepUnit`.
657+
658+
## gem5-CXL Integration
659+
660+
`gem5_integration/run.py` is a small launcher for SlugLab's gem5-CXL fork at <https://github.com/SlugLab/gem5-CXL>. It locates a gem5 binary, selects a config script, sets CXLMemSim environment variables, and enables O3CPU trace debug output by default.
661+
662+
Dry-run example:
663+
664+
```bash
665+
./gem5_integration/run.py \
666+
--gem5-root /path/to/gem5-CXL \
667+
--config /path/to/gem5-CXL/configs/example/se.py \
668+
--cmd /bin/true \
669+
--enable-dcd \
670+
--enable-gfam \
671+
--dry-run
672+
```
673+
674+
Full-system runs can pass kernel, disk image, workload script, memory size, CXL memory size, and extra gem5 config arguments:
675+
676+
```bash
677+
./gem5_integration/run.py \
678+
--gem5-root /path/to/gem5-CXL \
679+
--kernel /path/to/vmlinux \
680+
--disk-image /path/to/disk.img \
681+
--script boot.rcS \
682+
--mem-size 4GB \
683+
--cxl-mem-size 16GB \
684+
--cxl-host 127.0.0.1 \
685+
--cxl-port 9999 \
686+
--enable-dcd \
687+
--enable-gfam \
688+
-- --cpu-type=O3CPU
689+
```
690+
597691
## Legacy Application-Level Simulator Invocation
598692

599693
The original CXLMemSim application-level invocation accepts a target executable, sampling interval, CPU set, DRAM latency, bandwidth/latency vectors, capacity vectors, heuristic weights, and topology.

0 commit comments

Comments
 (0)