Skip to content

Commit 8774de7

Browse files
committed
update
1 parent 0cd4384 commit 8774de7

4 files changed

Lines changed: 610 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ project(CXLMemSim VERSION 0.1.0)
33

44
option(CXLMEMSIM_BUILD_MICROBENCHMARKS "Build microbenchmarks" ON)
55
option(CXLMEMSIM_ENABLE_RDMA "Enable RDMA transport when libraries are available" ON)
6+
option(CXLMEMSIM_ENABLE_SLUGALLOCATOR "Enable cxltime SlugAllocator compiler instrumentation integration" ON)
7+
8+
if(CXLMEMSIM_ENABLE_SLUGALLOCATOR)
9+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
10+
include(SlugAllocator)
11+
endif()
612

713
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
814
add_compile_options (-fdiagnostics-color=always)

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,40 @@ cat /proc/sys/kernel/perf_event_paranoid
117117
ls /sys/bus/event_source/devices/
118118
```
119119

120+
## Compiler Observability with cxltime SlugAllocator
121+
122+
On macOS, CXLMemSim cannot rely on Linux PEBS/LBR or physical-address PMU sampling. The sibling `cxltime` checkout provides `SlugAllocator`, an LLVM pass plus runtime that instruments basic-block entries and IR memory operations (`load`, `store`, atomics, and memory intrinsics). CXLMemSim can build those tools and run instrumented workloads directly against `cxlmemsim_server`.
123+
124+
Build the SlugAllocator pass/runtime from CXLMemSim:
125+
126+
```bash
127+
cmake -S . -B build \
128+
-DCXLMEMSIM_ENABLE_SLUGALLOCATOR=ON \
129+
-DCXLMEMSIM_CXLTIME_ROOT=/Users/yiweiyang/Documents/Lanxin/cxltime
130+
cmake --build build --target slugallocator_tools
131+
```
132+
133+
Compile a workload with the pass:
134+
135+
```bash
136+
./script/cxlmemsim_slug.py compile \
137+
--cxltime-root /Users/yiweiyang/Documents/Lanxin/cxltime \
138+
-o app.slug app.c -- -O1 -g
139+
```
140+
141+
Run the CXL server and send Slug memory events to it:
142+
143+
```bash
144+
./build/cxlmemsim_server --comm-mode=tcp --port=9999 --capacity=256
145+
146+
./script/cxlmemsim_slug.py run \
147+
--trace slug.csv \
148+
--port 9999 \
149+
-- ./app.slug
150+
```
151+
152+
Useful runtime variables are `SLUG_TRACE`, `SLUG_CXL_HOST`, `SLUG_CXL_PORT`, `SLUG_REGION_BASE`, `SLUG_REGION_SIZE`, `SLUG_CXL_ADDR_BASE`, and `SLUG_TRACE_ALL=0` for region-only tracing. Without `SLUG_CXL_PORT`, the runtime only records CSV/statistics; with it, every instrumented memory access is split into cacheline-sized read/write requests and sent to CXLMemSim's TCP protocol.
153+
120154
## Coherency and Distributed Memory
121155

122156
The distributed path is implemented in:

cmake/SlugAllocator.cmake

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
include_guard(GLOBAL)
2+
3+
set(_CXLMEMSIM_SLUG_DEFAULT_ROOT "")
4+
get_filename_component(_CXLMEMSIM_SLUG_SIBLING_ROOT
5+
"${CMAKE_CURRENT_LIST_DIR}/../../cxltime" ABSOLUTE)
6+
if(EXISTS "${_CXLMEMSIM_SLUG_SIBLING_ROOT}/CMakeLists.txt")
7+
set(_CXLMEMSIM_SLUG_DEFAULT_ROOT "${_CXLMEMSIM_SLUG_SIBLING_ROOT}")
8+
endif()
9+
10+
set(CXLMEMSIM_CXLTIME_ROOT "${_CXLMEMSIM_SLUG_DEFAULT_ROOT}" CACHE PATH
11+
"Path to the cxltime checkout that contains tools/slug_allocator")
12+
13+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
14+
set(_CXLMEMSIM_SLUG_BUILD_NAME build-mac-slug)
15+
set(_CXLMEMSIM_SLUG_DYLIB_SUFFIX dylib)
16+
else()
17+
set(_CXLMEMSIM_SLUG_BUILD_NAME build-slug)
18+
set(_CXLMEMSIM_SLUG_DYLIB_SUFFIX so)
19+
endif()
20+
21+
if(CXLMEMSIM_CXLTIME_ROOT)
22+
get_filename_component(_CXLMEMSIM_SLUG_DEFAULT_BUILD
23+
"${CXLMEMSIM_CXLTIME_ROOT}/${_CXLMEMSIM_SLUG_BUILD_NAME}" ABSOLUTE)
24+
else()
25+
set(_CXLMEMSIM_SLUG_DEFAULT_BUILD "")
26+
endif()
27+
28+
set(CXLMEMSIM_SLUG_BUILD_DIR "${_CXLMEMSIM_SLUG_DEFAULT_BUILD}" CACHE PATH
29+
"Build directory for cxltime SlugAllocator artifacts")
30+
31+
set(_CXLMEMSIM_SLUG_DEFAULT_LLVM_DIR "")
32+
foreach(_CXLMEMSIM_LLVM_CANDIDATE
33+
/opt/homebrew/opt/llvm@21/lib/cmake/llvm
34+
/usr/local/opt/llvm@21/lib/cmake/llvm
35+
/opt/homebrew/opt/llvm/lib/cmake/llvm
36+
/usr/local/opt/llvm/lib/cmake/llvm)
37+
if(EXISTS "${_CXLMEMSIM_LLVM_CANDIDATE}/LLVMConfig.cmake")
38+
set(_CXLMEMSIM_SLUG_DEFAULT_LLVM_DIR "${_CXLMEMSIM_LLVM_CANDIDATE}")
39+
break()
40+
endif()
41+
endforeach()
42+
43+
set(CXLMEMSIM_SLUG_LLVM_DIR "${_CXLMEMSIM_SLUG_DEFAULT_LLVM_DIR}" CACHE PATH
44+
"LLVM CMake package directory used to build cxltime SlugAllocator")
45+
46+
set(CXLMEMSIM_SLUG_PASS
47+
"${CXLMEMSIM_SLUG_BUILD_DIR}/tools/slug_allocator/SlugAllocatorPass.${_CXLMEMSIM_SLUG_DYLIB_SUFFIX}"
48+
CACHE FILEPATH "Path to the built SlugAllocator LLVM pass plugin")
49+
set(CXLMEMSIM_SLUG_RUNTIME
50+
"${CXLMEMSIM_SLUG_BUILD_DIR}/tools/slug_allocator/libslug_allocator_runtime.${_CXLMEMSIM_SLUG_DYLIB_SUFFIX}"
51+
CACHE FILEPATH "Path to the built SlugAllocator runtime library")
52+
53+
if(NOT CXLMEMSIM_CXLTIME_ROOT OR NOT EXISTS "${CXLMEMSIM_CXLTIME_ROOT}/CMakeLists.txt")
54+
message(WARNING
55+
"CXLMemSim SlugAllocator integration is enabled, but cxltime was not found. "
56+
"Set CXLMEMSIM_CXLTIME_ROOT to a checkout that contains tools/slug_allocator.")
57+
return()
58+
endif()
59+
60+
if(NOT EXISTS "${CXLMEMSIM_CXLTIME_ROOT}/tools/slug_allocator/CMakeLists.txt")
61+
message(WARNING
62+
"CXLMEMSIM_CXLTIME_ROOT=${CXLMEMSIM_CXLTIME_ROOT} does not contain "
63+
"tools/slug_allocator; skipping SlugAllocator targets.")
64+
return()
65+
endif()
66+
67+
set(_CXLMEMSIM_SLUG_CONFIGURE_ARGS
68+
-S "${CXLMEMSIM_CXLTIME_ROOT}"
69+
-B "${CXLMEMSIM_SLUG_BUILD_DIR}"
70+
-DCMAKE_BUILD_TYPE=RelWithDebInfo
71+
-DBPFTIME_BUILD_WITH_LIBBPF=OFF
72+
-DBPFTIME_BUILD_KERNEL_BPF=OFF
73+
-DBUILD_BPFTIME_DAEMON=OFF
74+
-DBPFTIME_LLVM_JIT=OFF
75+
-DBPFTIME_UBPF_JIT=OFF
76+
-DBPFTIME_BUILD_RUNTIME=OFF
77+
-DBPFTIME_BUILD_ATTACH=OFF
78+
-DBPFTIME_BUILD_BPFTIME_TOOLS=OFF
79+
-DBPFTIME_BUILD_SLUG_ALLOCATOR=ON)
80+
81+
if(CXLMEMSIM_SLUG_LLVM_DIR)
82+
list(APPEND _CXLMEMSIM_SLUG_CONFIGURE_ARGS
83+
"-DLLVM_DIR=${CXLMEMSIM_SLUG_LLVM_DIR}")
84+
endif()
85+
86+
add_custom_target(slugallocator_tools
87+
COMMAND "${CMAKE_COMMAND}" ${_CXLMEMSIM_SLUG_CONFIGURE_ARGS}
88+
COMMAND "${CMAKE_COMMAND}" --build "${CXLMEMSIM_SLUG_BUILD_DIR}"
89+
--target SlugAllocatorPass slug_allocator_runtime --parallel
90+
BYPRODUCTS "${CXLMEMSIM_SLUG_PASS}" "${CXLMEMSIM_SLUG_RUNTIME}"
91+
USES_TERMINAL
92+
COMMENT "Building cxltime SlugAllocator pass and runtime")
93+
94+
add_custom_target(slugallocator_paths
95+
COMMAND "${CMAKE_COMMAND}" -E echo "cxltime root: ${CXLMEMSIM_CXLTIME_ROOT}"
96+
COMMAND "${CMAKE_COMMAND}" -E echo "build dir: ${CXLMEMSIM_SLUG_BUILD_DIR}"
97+
COMMAND "${CMAKE_COMMAND}" -E echo "LLVM_DIR: ${CXLMEMSIM_SLUG_LLVM_DIR}"
98+
COMMAND "${CMAKE_COMMAND}" -E echo "pass: ${CXLMEMSIM_SLUG_PASS}"
99+
COMMAND "${CMAKE_COMMAND}" -E echo "runtime: ${CXLMEMSIM_SLUG_RUNTIME}")
100+
101+
find_package(Python3 COMPONENTS Interpreter QUIET)
102+
if(Python3_Interpreter_FOUND)
103+
add_custom_target(slugallocator_smoke
104+
COMMAND "${Python3_EXECUTABLE}"
105+
"${PROJECT_SOURCE_DIR}/script/cxlmemsim_slug.py"
106+
smoke
107+
--cxltime-root "${CXLMEMSIM_CXLTIME_ROOT}"
108+
--build-dir "${CXLMEMSIM_SLUG_BUILD_DIR}"
109+
--llvm-dir "${CXLMEMSIM_SLUG_LLVM_DIR}"
110+
--pass "${CXLMEMSIM_SLUG_PASS}"
111+
--runtime "${CXLMEMSIM_SLUG_RUNTIME}"
112+
DEPENDS slugallocator_tools
113+
USES_TERMINAL
114+
COMMENT "Running SlugAllocator instrumentation smoke test")
115+
else()
116+
message(WARNING "Python3 interpreter not found; slugallocator_smoke target is unavailable")
117+
endif()

0 commit comments

Comments
 (0)