Skip to content

Commit 442e6d1

Browse files
committed
update
1 parent d7149c1 commit 442e6d1

File tree

5 files changed

+240
-12
lines changed

5 files changed

+240
-12
lines changed

qemu_integration/launch_qemu_cxl.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ VM_MEMORY=${VM_MEMORY:-2G}
77
CXL_MEMORY=${CXL_MEMORY:-4G}
88
DISK_IMAGE=${DISK_IMAGE:-plucky-server-cloudimg-amd64.img}
99

10-
export LD_PRELOAD=/usr/local/lib/libCXLMemSim.so
11-
export CXL_MEMSIM_HOST=$CXL_MEMSIM_HOST
12-
export CXL_MEMSIM_PORT=$CXL_MEMSIM_PORT
10+
export CXL_MEMSIM_MODE=shm
1311

1412
exec $QEMU_BINARY \
15-
--enable-kvm --cpu host \
13+
--enable-kvm -cpu qemu64,+xsave,+rdtscp,+avx,+avx2,+sse4.1,+sse4.2,+avx512f,+avx512dq,+avx512ifma,+avx512cd,+avx512bw,+avx512vl,+avx512vbmi,+clflushopt \
1614
-kernel /root/tdx-linux/arch/x86/boot/bzImage \
17-
-append "root=/dev/sda rw console=ttyS0,115200 ignore_loglevel nokaslr" \
18-
-netdev user,id=network0,hostfwd=tcp::2024-:22 \
19-
-device e1000,netdev=network0 \
20-
-drive file=/home/victoryang00/CXLMemSim/build/qemu.img,index=0,media=disk,format=raw \
15+
-append "root=/dev/sda rw console=ttyS0,115200 ignore_loglevel nokaslr nokaslr nosmp nopti nospectre_v2 mem=2G" \
16+
-netdev tap,id=network0,ifname=tap0,script=no,downscript=no \
17+
-device e1000,netdev=network0,mac=52:54:00:00:00:01 \
18+
-drive file=/home/victoryang00/CXLMemSim/build/qemu1.img,index=0,media=disk,format=raw \
2119
-M q35,cxl=on -m 4G,maxmem=8G,slots=8 -smp 4 \
2220
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
2321
-device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=0 \
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
QEMU_BINARY=$PWD/../lib/qemu/build/qemu-system-x86_64
4+
CXL_MEMSIM_HOST=${CXL_MEMSIM_HOST:-127.0.0.1}
5+
CXL_MEMSIM_PORT=${CXL_MEMSIM_PORT:-9999}
6+
VM_MEMORY=${VM_MEMORY:-2G}
7+
CXL_MEMORY=${CXL_MEMORY:-4G}
8+
DISK_IMAGE=${DISK_IMAGE:-plucky-server-cloudimg-amd64.img}
9+
10+
export CXL_MEMSIM_MODE=shm
11+
12+
exec $QEMU_BINARY \
13+
--enable-kvm -cpu qemu64,+xsave,+rdtscp,+avx,+avx2,+sse4.1,+sse4.2,+avx512f,+avx512dq,+avx512ifma,+avx512cd,+avx512bw,+avx512vl,+avx512vbmi,+clflushopt \
14+
-kernel /root/tdx-linux/arch/x86/boot/bzImage \
15+
-append "root=/dev/sda rw console=ttyS0,115200 ignore_loglevel nokaslr nokaslr nosmp nopti nospectre_v2 mem=2G memmap=256M\$0x100000000" \
16+
-netdev tap,id=network0,ifname=tap1,script=no,downscript=no \
17+
-device e1000,netdev=network0,mac=52:54:00:00:00:02 \
18+
-drive file=/home/victoryang00/CXLMemSim/build/qemu.img,index=0,media=disk,format=raw \
19+
-M q35,cxl=on -m 4G,maxmem=8G,slots=8 -smp 4 \
20+
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
21+
-device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=0 \
22+
-device cxl-rp,port=1,bus=cxl.1,id=root_port14,chassis=0,slot=1 \
23+
-device cxl-type3,bus=root_port13,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem0,sn=0x1 \
24+
-device cxl-type1,bus=root_port14,size=256M,cache-size=64M \
25+
-device virtio-cxl-accel-pci,bus=pcie.0 \
26+
-object memory-backend-file,id=cxl-mem1,share=on,mem-path=/tmp/cxltest.raw,size=256M \
27+
-object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/tmp/lsa.raw,size=256M \
28+
-M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G \
29+
-nographic

qemu_integration/setup_cxl_numa.sh

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/bin/bash
2+
3+
# CXL NUMA Configuration Script
4+
# This script automatically configures CXL memory as NUMA node 1 at boot
5+
6+
set -e
7+
8+
LOG_FILE="/var/log/cxl_numa_setup.log"
9+
CXL_REGION_SIZE="256M"
10+
MAX_RETRIES=10
11+
RETRY_DELAY=2
12+
13+
log() {
14+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
15+
}
16+
17+
wait_for_cxl_device() {
18+
local retries=0
19+
while [ $retries -lt $MAX_RETRIES ]; do
20+
if cxl list -M 2>/dev/null | grep -q "mem0"; then
21+
log "CXL device mem0 detected"
22+
return 0
23+
fi
24+
log "Waiting for CXL device... (attempt $((retries+1))/$MAX_RETRIES)"
25+
sleep $RETRY_DELAY
26+
retries=$((retries+1))
27+
done
28+
log "ERROR: CXL device not found after $MAX_RETRIES attempts"
29+
return 1
30+
}
31+
32+
setup_cxl_region() {
33+
log "Creating CXL region..."
34+
35+
# Check if region already exists
36+
if cxl list -R 2>/dev/null | grep -q "region0"; then
37+
log "Region0 already exists, skipping creation"
38+
return 0
39+
fi
40+
41+
# Create CXL region
42+
if cxl create-region -m -d decoder0.0 -w 1 mem0 -s "$CXL_REGION_SIZE" 2>&1 | tee -a "$LOG_FILE"; then
43+
log "CXL region created successfully"
44+
return 0
45+
else
46+
log "ERROR: Failed to create CXL region"
47+
return 1
48+
fi
49+
}
50+
51+
setup_dax_namespace() {
52+
log "Setting up DAX namespace..."
53+
54+
# Check if namespace already exists
55+
if ndctl list -N 2>/dev/null | grep -q "namespace"; then
56+
log "Namespace already exists"
57+
return 0
58+
fi
59+
60+
# Wait a bit for region to be fully initialized
61+
sleep 2
62+
63+
# Create DAX namespace
64+
if ndctl create-namespace -m dax -r region0 2>&1 | tee -a "$LOG_FILE"; then
65+
log "DAX namespace created successfully"
66+
return 0
67+
else
68+
# Try to reconfigure if it fails
69+
log "Initial namespace creation failed, trying to reconfigure..."
70+
ndctl destroy-namespace all -f 2>/dev/null || true
71+
sleep 1
72+
if ndctl create-namespace -m dax -r region0 2>&1 | tee -a "$LOG_FILE"; then
73+
log "DAX namespace created after reconfiguration"
74+
return 0
75+
else
76+
log "WARNING: Could not create DAX namespace"
77+
return 1
78+
fi
79+
fi
80+
}
81+
82+
configure_numa_node() {
83+
log "Configuring NUMA node..."
84+
85+
# Find the DAX device
86+
local dax_device=$(ls /sys/bus/dax/devices/ 2>/dev/null | head -n1)
87+
88+
if [ -z "$dax_device" ]; then
89+
log "WARNING: No DAX device found"
90+
return 1
91+
fi
92+
93+
# Online the memory as NUMA node 1
94+
if [ -f "/sys/bus/dax/devices/$dax_device/target_node" ]; then
95+
local target_node=$(cat "/sys/bus/dax/devices/$dax_device/target_node")
96+
log "Target NUMA node: $target_node"
97+
98+
# Try to online the memory
99+
if daxctl reconfigure-device --mode=system-ram "$dax_device" 2>&1 | tee -a "$LOG_FILE"; then
100+
log "Memory onlined as system RAM"
101+
else
102+
log "WARNING: Could not online memory as system RAM"
103+
fi
104+
fi
105+
106+
# Verify NUMA configuration
107+
numactl --hardware 2>&1 | tee -a "$LOG_FILE"
108+
109+
return 0
110+
}
111+
112+
main() {
113+
log "Starting CXL NUMA configuration..."
114+
115+
# Load required kernel modules
116+
modprobe cxl_core 2>/dev/null || true
117+
modprobe cxl_pci 2>/dev/null || true
118+
modprobe cxl_acpi 2>/dev/null || true
119+
modprobe cxl_port 2>/dev/null || true
120+
modprobe cxl_mem 2>/dev/null || true
121+
modprobe dax 2>/dev/null || true
122+
modprobe device_dax 2>/dev/null || true
123+
modprobe kmem 2>/dev/null || true
124+
125+
# Wait for CXL device to appear
126+
if ! wait_for_cxl_device; then
127+
log "Aborting: CXL device not available"
128+
exit 1
129+
fi
130+
131+
# Setup CXL region
132+
if ! setup_cxl_region; then
133+
log "Warning: CXL region setup failed, continuing anyway"
134+
fi
135+
136+
# Setup DAX namespace
137+
if ! setup_dax_namespace; then
138+
log "Warning: DAX namespace setup failed, continuing anyway"
139+
fi
140+
141+
# Configure NUMA node
142+
#if ! configure_numa_node; then
143+
# log "Warning: NUMA node configuration incomplete"
144+
#fi
145+
146+
log "CXL NUMA configuration completed"
147+
148+
# Display final configuration
149+
log "Final CXL configuration:"
150+
cxl list 2>&1 | tee -a "$LOG_FILE"
151+
log "Final NUMA configuration:"
152+
numactl --hardware 2>&1 | tee -a "$LOG_FILE"
153+
}
154+
155+
# Run main function
156+
main
157+
#dhcpcd
158+
ip link set enp0s2 up
159+
ip addr add 192.168.100.10/24 dev enp0s2
160+
ip route add default via 192.168.100.1

src/main_server.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,8 @@ void ThreadPerConnectionServer::handle_request(int client_fd, int thread_id, Ser
630630
read_data_str << std::hex << std::setfill('0') << std::setw(2)
631631
<< static_cast<int>(resp.data[i]) << " ";
632632
}
633-
SPDLOG_INFO("Thread {}: READ response data (first 16 bytes): {}",
634-
thread_id, read_data_str.str());
633+
// SPDLOG_INFO("Thread {}: READ response data (first 16 bytes): {}",
634+
// thread_id, read_data_str.str());
635635

636636
// Add back invalidation latency penalty if we had one
637637
if (had_back_invalidation) {
@@ -679,8 +679,8 @@ void ThreadPerConnectionServer::handle_request(int client_fd, int thread_id, Ser
679679
return;
680680
}
681681

682-
SPDLOG_INFO("Thread {}: WRITE completed successfully at addr=0x{:x}, size={}",
683-
thread_id, req.addr, req.size);
682+
// SPDLOG_INFO("Thread {}: WRITE completed successfully at addr=0x{:x}, size={}",
683+
// thread_id, req.addr, req.size);
684684

685685
// Verify write by reading back
686686
uint8_t verify_data[64];

workloads/gromacs/Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
CC = mpicc
2+
MPICC = mpicc
3+
CFLAGS = -Wall -O3 -fPIC -shared -pthread -g
4+
LDFLAGS = -ldl -lrt -pthread
5+
6+
SHIM_LIB = libmpi_cxl_shim.so
7+
SHIM_SRC = mpi_cxl_shim.c
8+
9+
TEST_PROG = test_mpi_cxl
10+
TEST_SRC = test_mpi_cxl.c
11+
12+
.PHONY: all clean test
13+
14+
all: $(SHIM_LIB) $(TEST_PROG)
15+
16+
$(SHIM_LIB): $(SHIM_SRC)
17+
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
18+
19+
$(TEST_PROG): $(TEST_SRC)
20+
$(MPICC) -o $@ $< -Wall -O2
21+
22+
test: $(SHIM_LIB) $(TEST_PROG)
23+
@echo "Running MPI CXL shim test..."
24+
@echo "Set environment variables:"
25+
@echo " export LD_PRELOAD=./$(SHIM_LIB)"
26+
@echo " export CXL_DAX_PATH=/dev/dax0.0 # or use shared memory"
27+
@echo " export CXL_SHIM_VERBOSE=1"
28+
@echo " export CXL_SHIM_ALLOC=1"
29+
@echo " export CXL_SHIM_WIN=1"
30+
@echo " export CXL_SHIM_COPY_SEND=1"
31+
@echo " export CXL_SHIM_COPY_RECV=1"
32+
@echo "Then run: mpirun -np 2 ./$(TEST_PROG)"
33+
34+
clean:
35+
rm -f $(SHIM_LIB) $(TEST_PROG) *.o
36+
37+
install: $(SHIM_LIB)
38+
@echo "Installing $(SHIM_LIB) to /usr/local/lib/"
39+
@sudo cp $(SHIM_LIB) /usr/local/lib/
40+
@sudo ldconfig
41+
@echo "Installation complete. Use LD_PRELOAD=/usr/local/lib/$(SHIM_LIB) to enable."

0 commit comments

Comments
 (0)