Skip to content

Commit 9d3c397

Browse files
committed
update
1 parent 10ec4ec commit 9d3c397

2 files changed

Lines changed: 23 additions & 25 deletions

File tree

src/cxlendpoint.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ int CXLSwitch::insert(uint64_t timestamp, uint64_t tid, uint64_t phys_addr, uint
496496
this->id);
497497

498498
for (auto &expander : this->expanders) {
499+
if (expander == nullptr) {
500+
continue;
501+
}
499502
// 在每个 expander 上尝试插入
500503
int ret = expander->insert(timestamp, tid, phys_addr, virt_addr, index);
501504
if (ret == 1) {
@@ -509,6 +512,9 @@ int CXLSwitch::insert(uint64_t timestamp, uint64_t tid, uint64_t phys_addr, uint
509512
}
510513
// 如果没有合适的 expander,就尝试下属的 switch
511514
for (auto &sw : this->switches) {
515+
if (sw == nullptr) {
516+
continue;
517+
}
512518
int ret = sw->insert(timestamp, tid, phys_addr, virt_addr, index);
513519
if (ret == 1) {
514520
this->counter.inc_store();

src/main_server.cc

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ void signal_handler(int sig) {
266266
SPDLOG_INFO("Shutting down server...");
267267
g_server->stop();
268268
}
269-
exit(0);
270269
}
271270

272271
int main(int argc, char *argv[]) {
@@ -722,9 +721,7 @@ void ThreadPerConnectionServer::run() {
722721
void ThreadPerConnectionServer::stop() {
723722
running = false;
724723

725-
if (comm_mode == CommMode::PGAS_SHM) {
726-
cleanup_pgas_shm();
727-
} else if (comm_mode == CommMode::TCP) {
724+
if (comm_mode == CommMode::TCP) {
728725
close(server_fd);
729726
}
730727

@@ -740,7 +737,7 @@ void ThreadPerConnectionServer::stop() {
740737
SPDLOG_INFO(" Back Invalidations: {}", back_invalidations.load());
741738

742739
// Print CXL controller topology statistics (switches/expanders/counters)
743-
if (controller) {
740+
if (controller && comm_mode != CommMode::PGAS_SHM) {
744741
std::cout << std::format("{}", *controller) << std::endl;
745742
}
746743
}
@@ -1678,6 +1675,8 @@ void ThreadPerConnectionServer::run_pgas_shm_mode() {
16781675
worker.join();
16791676
}
16801677
}
1678+
1679+
cleanup_pgas_shm();
16811680
}
16821681

16831682
int ThreadPerConnectionServer::poll_pgas_shm_requests() {
@@ -1703,6 +1702,7 @@ int ThreadPerConnectionServer::poll_pgas_shm_requests() {
17031702

17041703
// Calculate cacheline index from address
17051704
uint64_t addr = slot->addr;
1705+
uint64_t request_ts = slot->timestamp;
17061706
size_t cacheline_idx = addr / 64;
17071707

17081708
if (cacheline_idx >= num_cachelines) {
@@ -1719,7 +1719,7 @@ int ThreadPerConnectionServer::poll_pgas_shm_requests() {
17191719
case CXL_SHM_REQ_READ: {
17201720
// Update metadata
17211721
entry->metadata.access_count++;
1722-
entry->metadata.last_access_time = slot->timestamp;
1722+
entry->metadata.last_access_time = request_ts;
17231723

17241724
// Copy data to slot
17251725
size_t copy_size = std::min((size_t)slot->size, (size_t)64);
@@ -1732,20 +1732,16 @@ int ThreadPerConnectionServer::poll_pgas_shm_requests() {
17321732
// Store cache state in first byte of data response padding
17331733
// Client can check this for coherency information
17341734

1735-
__atomic_thread_fence(__ATOMIC_RELEASE);
1736-
slot->resp_status = CXL_SHM_RESP_OK;
17371735
total_reads++;
17381736

1739-
// Propagate stats through CXL topology
1737+
// PGAS server mode may be used with a minimal topology file whose
1738+
// switch objects are not fully materialized. Keep the authoritative
1739+
// operation counters independent from that optional topology walk.
17401740
controller->counter.inc_local();
1741-
for (auto &sw : controller->switches) {
1742-
sw->insert(slot->timestamp, 0, addr, addr, 0);
1743-
}
1744-
for (auto &ep : controller->expanders) {
1745-
ep->insert(slot->timestamp, 0, addr, addr, ep->id);
1746-
}
17471741

17481742
log_periodic_stats("PGAS_READ", total_reads.load());
1743+
__atomic_thread_fence(__ATOMIC_RELEASE);
1744+
slot->resp_status = CXL_SHM_RESP_OK;
17491745
processed++;
17501746
break;
17511747
}
@@ -1758,25 +1754,21 @@ int ThreadPerConnectionServer::poll_pgas_shm_requests() {
17581754

17591755
// Update metadata
17601756
entry->metadata.access_count++;
1761-
entry->metadata.last_access_time = slot->timestamp;
1757+
entry->metadata.last_access_time = request_ts;
17621758
entry->metadata.cache_state = 3; // MODIFIED
17631759
entry->metadata.version++;
17641760

17651761
slot->latency_ns = (uint64_t)base_latency;
1766-
__atomic_thread_fence(__ATOMIC_RELEASE);
1767-
slot->resp_status = CXL_SHM_RESP_OK;
17681762
total_writes++;
17691763

1770-
// Propagate stats through CXL topology
1764+
// PGAS server mode may be used with a minimal topology file whose
1765+
// switch objects are not fully materialized. Keep the authoritative
1766+
// operation counters independent from that optional topology walk.
17711767
controller->counter.inc_local();
1772-
for (auto &sw : controller->switches) {
1773-
sw->insert(slot->timestamp, 0, addr, addr, 0);
1774-
}
1775-
for (auto &ep : controller->expanders) {
1776-
ep->insert(slot->timestamp, 0, addr, addr, ep->id);
1777-
}
17781768

17791769
log_periodic_stats("PGAS_WRITE", total_writes.load());
1770+
__atomic_thread_fence(__ATOMIC_RELEASE);
1771+
slot->resp_status = CXL_SHM_RESP_OK;
17801772
processed++;
17811773
break;
17821774
}

0 commit comments

Comments
 (0)