@@ -46,7 +46,7 @@ CXLController::CXLController(std::array<Policy *, 4> p, int capacity, page_type
4646 double dramlatency)
4747 : CXLSwitch(0 ), capacity(capacity), allocation_policy(dynamic_cast <AllocationPolicy *>(p[0 ])),
4848 migration_policy(dynamic_cast <MigrationPolicy *>(p[1 ])), paging_policy(dynamic_cast <PagingPolicy *>(p[2 ])),
49- caching_policy(dynamic_cast <CachingPolicy *>(p[3 ])), page_type_(page_type_), dramlatency(dramlatency) {
49+ caching_policy(dynamic_cast <CachingPolicy *>(p[3 ])), page_type_(page_type_), dramlatency(dramlatency), lru_cache( 32 * 1024 * 1024 / 64 ) {
5050 for (auto switch_ : this ->switches ) {
5151 switch_->set_epoch (epoch);
5252 }
@@ -56,7 +56,6 @@ CXLController::CXLController(std::array<Policy *, 4> p, int capacity, page_type
5656 // TODO get LRU wb
5757 // TODO BW type series
5858 // TODO cache
59- // TODO back invalidation
6059 // deferentiate R/W for multi reader multi writer
6160}
6261
@@ -130,9 +129,7 @@ void CXLController::insert_one(thread_info &t_info, lbr &lbr) {
130129 ring_buffer.pop ();
131130 }
132131}
133-
134132int CXLController::insert (uint64_t timestamp, uint64_t tid, uint64_t phys_addr, uint64_t virt_addr, int index) {
135- auto res = true ;
136133 auto &t_info = thread_map[tid];
137134
138135 // 计算时间步长,使timestamp均匀分布
@@ -142,31 +139,54 @@ int CXLController::insert(uint64_t timestamp, uint64_t tid, uint64_t phys_addr,
142139 }
143140 uint64_t current_timestamp = last_timestamp;
144141
142+ bool res = true ;
145143 for (int i = last_index; i < index; i++) {
146144 // 更新当前时间戳
147145 current_timestamp += time_step;
148146
147+ // 首先检查LRU缓存
148+ auto cache_result = access_cache (phys_addr, current_timestamp);
149+
150+ if (cache_result.has_value ()) {
151+ // 缓存命中
152+ this ->counter .inc_local ();
153+ t_info.llcm_type .push (0 ); // 本地访问类型
154+ continue ;
155+ }
156+
157+ // 缓存未命中,决定分配策略
149158 auto numa_policy = allocation_policy->compute_once (this );
159+
150160 if (numa_policy == -1 ) {
161+ // 本地访问
151162 this ->occupation .emplace (current_timestamp, phys_addr);
152163 this ->counter .inc_local ();
153164 t_info.llcm_type .push (0 );
154- continue ;
155- }
156- this ->counter .inc_remote ();
157- for (auto switch_ : this ->switches ) {
158- res &= switch_->insert (current_timestamp, tid, phys_addr, virt_addr, numa_policy);
159- }
160- for (auto expander_ : this ->expanders ) {
161- res &= expander_->insert (current_timestamp, tid, phys_addr, virt_addr, numa_policy);
165+
166+ // 更新缓存
167+ update_cache (phys_addr, phys_addr, current_timestamp); // 使用物理地址作为值
168+ } else {
169+ // 远程访问
170+ this ->counter .inc_remote ();
171+ for (auto switch_ : this ->switches ) {
172+ res &= switch_->insert (current_timestamp, tid, phys_addr, virt_addr, numa_policy);
173+ }
174+ for (auto expander_ : this ->expanders ) {
175+ res &= expander_->insert (current_timestamp, tid, phys_addr, virt_addr, numa_policy);
176+ }
177+ t_info.llcm_type .push (1 ); // 远程访问类型
178+ // 可以选择是否缓存远程访问的数据
179+ if (caching_policy->compute_once (this )) {
180+ counter.inc_hitm ();
181+ update_cache (phys_addr, phys_addr, current_timestamp);
182+ }
162183 }
163- t_info.llcm_type .push (1 );
164184 }
165185
166186 // 更新最后的索引和时间戳
167187 last_index = index;
168188 last_timestamp = timestamp;
169- return res; // 返回实际的结果而不是固定的true
189+ return res;
170190}
171191int CXLController::insert (uint64_t timestamp, uint64_t tid, lbr lbrs[32 ], cntr counters[32 ]) {
172192 // 处理LBR记录
0 commit comments