Skip to content

Commit 8a56c60

Browse files
author
Your Name
committed
update
1 parent 434020d commit 8a56c60

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

qemu_integration/launch_qemu_cxl.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ exec $QEMU_BINARY \
2828
-device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=0 \
2929
-device cxl-rp,port=1,bus=cxl.1,id=root_port14,chassis=0,slot=1 \
3030
-device cxl-type3,bus=root_port13,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem0,sn=0x1 \
31-
-device cxl-type1,bus=root_port14,size=256M,cache-size=64M \
31+
-device cxl-type1,bus=root_port14,size=2G,cache-size=64M \
3232
-device virtio-cxl-accel-pci,bus=pcie.0 \
33-
-object memory-backend-file,id=cxl-mem1,share=on,mem-path=/dev/shm/cxlmemsim_shared,size=256M \
34-
-object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/tmp/lsa0.raw,size=256M \
33+
-object memory-backend-file,id=cxl-mem1,share=on,mem-path=/dev/shm/cxlmemsim_shared,size=2G \
34+
-object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/dev/shm/lsa0.raw,size=2G \
3535
-M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G \
3636
-nographic

qemu_integration/launch_qemu_cxl1.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ exec $QEMU_BINARY \
2828
-device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=0 \
2929
-device cxl-rp,port=1,bus=cxl.1,id=root_port14,chassis=0,slot=1 \
3030
-device cxl-type3,bus=root_port13,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem0,sn=0x1 \
31-
-device cxl-type1,bus=root_port14,size=256M,cache-size=64M \
31+
-device cxl-type1,bus=root_port14,size=2G,cache-size=64M \
3232
-device virtio-cxl-accel-pci,bus=pcie.0 \
33-
-object memory-backend-file,id=cxl-mem1,share=on,mem-path=/dev/shm/cxlmemsim_shared,size=256M \
34-
-object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/tmp/lsa1.raw,size=256M \
33+
-object memory-backend-file,id=cxl-mem1,share=on,mem-path=/dev/shm/cxlmemsim_shared,size=2G \
34+
-object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/dev/shm/lsa1.raw,size=2G \
3535
-M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G \
3636
-nographic

src/main_server.cc

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <fstream>
4242
#include <iterator>
4343
#include <queue>
44+
#include <sys/mman.h> // For msync
4445

4546
#ifndef MSG_WAITALL
4647
#define MSG_WAITALL 0x100
@@ -543,7 +544,11 @@ uint64_t ThreadPerConnectionServer::calculate_total_latency(uint64_t base_latenc
543544
void ThreadPerConnectionServer::handle_request(int client_fd, int thread_id, ServerRequest& req, ServerResponse& resp) {
544545
uint64_t cacheline_addr = req.addr & ~(63ULL); // 64-byte aligned
545546
bool had_coherency_miss = false;
546-
547+
548+
// CRITICAL: Memory barrier before reading from shared memory
549+
// This ensures we see all updates from other guests
550+
std::atomic_thread_fence(std::memory_order_seq_cst);
551+
547552
// Log CXL Type3 operation with detailed information
548553
const char* op_name = (req.op_type == 0) ? "CXL_TYPE3_READ" : "CXL_TYPE3_WRITE";
549554

@@ -617,7 +622,12 @@ void ThreadPerConnectionServer::handle_request(int client_fd, int thread_id, Ser
617622

618623
// Read data from shared memory
619624
if (!shm_manager->read_cacheline(req.addr, resp.data, req.size)) {
620-
SPDLOG_ERROR("Thread {}: Failed to read from shared memory at 0x{:x}",
625+
// Force sync before reporting failure
626+
auto* metadata_ptr = shm_manager->get_cacheline_metadata(cacheline_addr);
627+
if (metadata_ptr) {
628+
msync(metadata_ptr, sizeof(CachelineMetadata), MS_INVALIDATE | MS_SYNC);
629+
}
630+
SPDLOG_ERROR("Thread {}: Failed to read from shared memory at 0x{:x}",
621631
thread_id, req.addr);
622632
resp.status = 1;
623633
congestion_info.active_requests--;
@@ -672,14 +682,26 @@ void ThreadPerConnectionServer::handle_request(int client_fd, int thread_id, Ser
672682

673683
// Write data to shared memory
674684
if (!shm_manager->write_cacheline(req.addr, req.data, req.size)) {
675-
SPDLOG_ERROR("Thread {}: Failed to write to shared memory at 0x{:x}",
685+
SPDLOG_ERROR("Thread {}: Failed to write to shared memory at 0x{:x}",
676686
thread_id, req.addr);
677687
resp.status = 1;
678688
congestion_info.active_requests--;
679689
return;
680690
}
681-
682-
// SPDLOG_INFO("Thread {}: WRITE completed successfully at addr=0x{:x}, size={}",
691+
692+
// CRITICAL: Force sync to physical memory so other guests can see it
693+
auto* metadata_ptr = shm_manager->get_cacheline_metadata(cacheline_addr);
694+
if (metadata_ptr) {
695+
msync(metadata_ptr, sizeof(CachelineMetadata), MS_SYNC);
696+
}
697+
// Force sync the data as well
698+
void* data_ptr = shm_manager->get_data_area();
699+
if (data_ptr) {
700+
msync((uint8_t*)data_ptr + (cacheline_addr & ~CACHELINE_MASK), CACHELINE_SIZE, MS_SYNC);
701+
}
702+
std::atomic_thread_fence(std::memory_order_release);
703+
704+
// SPDLOG_INFO("Thread {}: WRITE completed successfully at addr=0x{:x}, size={}",
683705
// thread_id, req.addr, req.size);
684706

685707
// Verify write by reading back

src/shared_memory_manager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ class SharedMemoryManager {
110110
uint8_t* get_cacheline_data(uint64_t cacheline_addr);
111111
bool read_cacheline(uint64_t addr, uint8_t* buffer, size_t size);
112112
bool write_cacheline(uint64_t addr, const uint8_t* data, size_t size);
113-
113+
114+
// Direct access to data area (for msync)
115+
void* get_data_area() { return data_area; }
116+
114117
// Metadata access (uses local cache)
115118
CachelineMetadata* get_cacheline_metadata(uint64_t cacheline_addr);
116119

0 commit comments

Comments
 (0)