Skip to content

Commit dce1827

Browse files
committed
add policy
1 parent 8640ad8 commit dce1827

File tree

4 files changed

+551
-32
lines changed

4 files changed

+551
-32
lines changed

include/cxlcontroller.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,21 @@ class PagingPolicy : public Policy {
7474
class CachingPolicy : public Policy {
7575
public:
7676
CachingPolicy();
77-
// paging related
77+
78+
// 判断是否应该缓存数据
79+
virtual bool should_cache(uint64_t addr, uint64_t timestamp) {
80+
return true; // 默认行为,可以被子类覆盖
81+
}
82+
83+
// 判断是否应该进行后向失效
84+
virtual bool should_invalidate(uint64_t addr, uint64_t timestamp) {
85+
return false; // 默认行为,可以被子类覆盖
86+
}
87+
88+
// 获取需要失效的地址列表
89+
virtual std::vector<uint64_t> get_invalidation_list(CXLController* controller) {
90+
return {}; // 默认行为,可以被子类覆盖
91+
}
7892
};
7993

8094
struct LRUCacheEntry {
@@ -216,6 +230,9 @@ class CXLController : public CXLSwitch {
216230

217231
// 添加缓存更新方法
218232
void update_cache(uint64_t addr, uint64_t value, uint64_t timestamp) { lru_cache.put(addr, value, timestamp); }
233+
void perform_back_invalidation();
234+
void invalidate_in_expanders(uint64_t addr);
235+
void invalidate_in_switch(CXLSwitch* switch_, uint64_t addr);
219236
};
220237

221238
template <> struct std::formatter<CXLController> {

include/cxlcounter.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const char hitOldName[] = "hit_old";
2828
const char localName[] = "local";
2929
const char remoteName[] = "remote";
3030
const char hitmName[] = "hitm";
31+
const char backinvName[] = "backinv";
32+
3133

3234
// 基础计数器模板类
3335
template<const char* Name>
@@ -78,10 +80,8 @@ struct std::formatter<AtomicCounter<Name>> {
7880
}
7981

8082
template <typename FormatContext>
81-
constexpr auto format(const AtomicCounter<Name>& counter, FormatContext& ctx) const
82-
-> decltype(ctx.out())
83-
{
84-
// 直接使用format_to避免嵌套std::format调用
83+
auto format(const AtomicCounter<Name>& counter, FormatContext& ctx) const -> decltype(ctx.out()) {
84+
// 简化formatter实现,避免嵌套std::format调用
8585
return format_to(ctx.out(), "{}", counter.get());
8686
}
8787
};
@@ -193,6 +193,7 @@ class CXLCounter {
193193
AtomicCounter<localName> local;
194194
AtomicCounter<remoteName> remote;
195195
AtomicCounter<hitmName> hitm;
196+
AtomicCounter<backinvName> backinv;
196197

197198
constexpr CXLCounter() noexcept = default;
198199

@@ -210,6 +211,7 @@ class CXLCounter {
210211
constexpr void inc_local() noexcept { local.increment(); }
211212
constexpr void inc_remote() noexcept { remote.increment(); }
212213
constexpr void inc_hitm() noexcept { hitm.increment(); }
214+
constexpr void inc_backinv() noexcept { backinv.increment(); }
213215

214216
// 便捷方法:计算本地命中率
215217
constexpr double local_hit_ratio() const noexcept {

0 commit comments

Comments
 (0)