@@ -310,6 +310,56 @@ int CXLMemExpander::insert(uint64_t timestamp, uint64_t tid, uint64_t phys_addr,
310310 }
311311 return 0 ;
312312}
313+
314+ int CXLMemExpander::record_access (uint64_t timestamp, uint64_t tid, uint64_t phys_addr, uint64_t virt_addr, int index,
315+ bool is_write) {
316+ if (index != this ->id ) {
317+ return 0 ;
318+ }
319+
320+ (void )virt_addr;
321+ last_timestamp = last_timestamp > timestamp ? last_timestamp : timestamp;
322+ process_queued_requests (timestamp);
323+
324+ CXLRequest req{};
325+ req.timestamp = timestamp;
326+ req.address = phys_addr;
327+ req.tid = tid;
328+ req.is_read = !is_write;
329+ req.is_write = is_write;
330+ req.issue_time = timestamp;
331+ req.complete_time = timestamp;
332+
333+ if (!can_accept_request ()) {
334+ this ->counter .inc_hit_old ();
335+ return 0 ;
336+ }
337+
338+ {
339+ std::lock_guard<std::mutex> lock (queue_mutex_);
340+ request_queue_.push_back (req);
341+ }
342+
343+ for (auto it = this ->occupation .cbegin (); it != this ->occupation .cend (); ++it) {
344+ if (it->address == phys_addr) {
345+ this ->occupation .erase (it);
346+ break ;
347+ }
348+ }
349+
350+ this ->occupation .emplace_back (timestamp, phys_addr, is_write ? 0 : 1 );
351+ this ->address_cache .insert (phys_addr);
352+ this ->invalidate_cache ();
353+
354+ if (is_write) {
355+ this ->counter .inc_store ();
356+ return 1 ;
357+ }
358+
359+ this ->counter .inc_load ();
360+ return 2 ;
361+ }
362+
313363std::vector<std::tuple<uint64_t , uint64_t >> CXLMemExpander::get_access (uint64_t timestamp) {
314364 last_counter = CXLMemExpanderEvent (counter);
315365
@@ -641,6 +691,44 @@ int CXLSwitch::insert(uint64_t timestamp, uint64_t tid, uint64_t phys_addr, uint
641691 return 0 ;
642692}
643693
694+ int CXLSwitch::record_access (uint64_t timestamp, uint64_t tid, uint64_t phys_addr, uint64_t virt_addr, int index,
695+ bool is_write) {
696+ SPDLOG_DEBUG (" CXLSwitch record_access phys_addr={}, virt_addr={}, index={}, is_write={} for switch id:{}" ,
697+ phys_addr, virt_addr, index, is_write, this ->id );
698+
699+ for (auto &expander : this ->expanders ) {
700+ if (expander == nullptr ) {
701+ continue ;
702+ }
703+ int ret = expander->record_access (timestamp, tid, phys_addr, virt_addr, index, is_write);
704+ if (ret == 1 ) {
705+ this ->counter .inc_store ();
706+ return 1 ;
707+ }
708+ if (ret == 2 ) {
709+ this ->counter .inc_load ();
710+ return 2 ;
711+ }
712+ }
713+
714+ for (auto &sw : this ->switches ) {
715+ if (sw == nullptr ) {
716+ continue ;
717+ }
718+ int ret = sw->record_access (timestamp, tid, phys_addr, virt_addr, index, is_write);
719+ if (ret == 1 ) {
720+ this ->counter .inc_store ();
721+ return 1 ;
722+ }
723+ if (ret == 2 ) {
724+ this ->counter .inc_load ();
725+ return 2 ;
726+ }
727+ }
728+
729+ return 0 ;
730+ }
731+
644732// Implementation of new CXL queue management and pipeline methods
645733bool CXLMemExpander::can_accept_request () const {
646734 std::lock_guard<std::mutex> lock (queue_mutex_);
0 commit comments