Skip to content

Commit 16ed6b5

Browse files
author
Your Name
committed
fall back to Ubuntu20
1 parent 6a88f50 commit 16ed6b5

File tree

9 files changed

+146
-146
lines changed

9 files changed

+146
-146
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ endif ()
99
execute_process(COMMAND uname -r OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE)
1010
set(LINUX_SOURCE /lib/modules/${arch}/build/)
1111

12-
set(CMAKE_CXX_STANDARD 26)
12+
set(CMAKE_CXX_STANDARD 20)
1313

1414
# Add option for server mode (disables bpftime dependencies)
1515
option(SERVER_MODE "Build in server mode without bpftime dependencies" OFF)

include/cxlcontroller.h

Lines changed: 94 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -275,111 +275,110 @@ class CXLController : public CXLSwitch {
275275
void invalidate_in_switch(CXLSwitch *switch_, uint64_t addr);
276276
};
277277

278-
template <> struct std::formatter<CXLController> {
279-
// Parse function to handle any format specifiers (if needed)
280-
constexpr auto parse(std::format_parse_context &ctx) -> decltype(ctx.begin()) {
281-
// If you have specific format specifiers, parse them here
282-
// For simplicity, we'll ignore them and return the end iterator
283-
return ctx.end();
284-
}
285-
286-
// Format function to output the Monitors data
278+
// C++20 doesn't have std::formatter - using fmt::formatter instead
279+
// We'll use a helper function instead
280+
namespace fmt {
281+
template <> struct formatter<CXLController> {
282+
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
283+
return ctx.end();
284+
}
287285

288-
template <typename FormatContext>
289-
auto format(const CXLController &controller, FormatContext &ctx) const -> decltype(ctx.out()) {
290-
std::string result;
286+
template <typename FormatContext>
287+
auto format(const CXLController &controller, FormatContext &ctx) const -> decltype(ctx.out()) {
288+
std::string result;
291289

292-
// 首先打印控制器自身的计数器信息
293-
result += std::format("CXLController:\n");
294-
// iterate through the topology map
295-
uint64_t total_capacity = 0;
290+
// 首先打印控制器自身的计数器信息
291+
result += "CXLController:\n";
292+
// iterate through the topology map
293+
uint64_t total_capacity = 0;
296294

297-
std::function<void(const CXLSwitch *)> dfs_capacity = [&](const CXLSwitch *node) {
298-
if (!node)
299-
return;
295+
std::function<void(const CXLSwitch *)> dfs_capacity = [&](const CXLSwitch *node) {
296+
if (!node)
297+
return;
300298

301-
// Traverse expanders and sum their capacity
302-
for (const auto *expander : node->expanders) {
303-
if (expander) {
304-
total_capacity += expander->capacity;
299+
// Traverse expanders and sum their capacity
300+
for (const auto *expander : node->expanders) {
301+
if (expander) {
302+
total_capacity += expander->capacity;
303+
}
305304
}
306-
}
307305

308-
// Recur for all connected switches
309-
for (const auto *sw : node->switches) {
310-
dfs_capacity(sw); // Proper recursive call
311-
}
312-
};
313-
dfs_capacity(&controller);
314-
315-
result += std::format("Total system memory capacity: {}GB\n", total_capacity);
316-
317-
result += std::format(" Page Type: {}\n", [](page_type pt) {
318-
switch (pt) {
319-
case CACHELINE:
320-
return "CACHELINE";
321-
case PAGE:
322-
return "PAGE";
323-
case HUGEPAGE_2M:
324-
return "HUGEPAGE_2M";
325-
case HUGEPAGE_1G:
326-
return "HUGEPAGE_1G";
327-
default:
328-
return "UNKNOWN";
329-
}
330-
}(controller.page_type_));
331-
332-
// 打印全局计数器
333-
result += std::format(" Global Counter:\n");
334-
result += std::format(" Local: {}\n", controller.counter.local.get());
335-
result += std::format(" Remote: {}\n", controller.counter.remote.get());
336-
result += std::format(" HITM: {}\n", controller.counter.hitm.get());
337-
338-
// 打印拓扑结构(交换机和端点)
339-
result += "Topology:\n";
340-
341-
// 递归打印每个交换机
342-
std::function<void(const CXLSwitch *, int)> print_switch = [&result, &print_switch](const CXLSwitch *sw,
343-
int depth) {
344-
std::string indent(depth * 2, ' ');
345-
346-
// 打印交换机事件计数
347-
result += std::format("{}Switch:\n", indent);
348-
result += std::format("{} Events:\n", indent);
349-
result += std::format("{} Load: {}\n", indent, sw->counter.load.get());
350-
result += std::format("{} Store: {}\n", indent, sw->counter.store.get());
351-
result += std::format("{} Conflict: {}\n", indent, sw->counter.conflict.get());
352-
353-
// 递归打印子交换机
354-
for (const auto &child : sw->switches) {
355-
print_switch(child, depth + 1);
356-
}
306+
// Recur for all connected switches
307+
for (const auto *sw : node->switches) {
308+
dfs_capacity(sw); // Proper recursive call
309+
}
310+
};
311+
dfs_capacity(&controller);
312+
313+
result += fmt::format("Total system memory capacity: {}GB\n", total_capacity);
314+
315+
result += fmt::format(" Page Type: {}\n", [](page_type pt) {
316+
switch (pt) {
317+
case CACHELINE:
318+
return "CACHELINE";
319+
case PAGE:
320+
return "PAGE";
321+
case HUGEPAGE_2M:
322+
return "HUGEPAGE_2M";
323+
case HUGEPAGE_1G:
324+
return "HUGEPAGE_1G";
325+
default:
326+
return "UNKNOWN";
327+
}
328+
}(controller.page_type_));
329+
330+
// 打印全局计数器
331+
result += fmt::format(" Global Counter:\n");
332+
result += fmt::format(" Local: {}\n", controller.counter.local.get());
333+
result += fmt::format(" Remote: {}\n", controller.counter.remote.get());
334+
result += fmt::format(" HITM: {}\n", controller.counter.hitm.get());
335+
336+
// 打印拓扑结构(交换机和端点)
337+
result += "Topology:\n";
338+
339+
// 递归打印每个交换机
340+
std::function<void(const CXLSwitch *, int)> print_switch = [&result, &print_switch](const CXLSwitch *sw,
341+
int depth) {
342+
std::string indent(depth * 2, ' ');
343+
344+
// 打印交换机事件计数
345+
result += fmt::format("{}Switch:\n", indent);
346+
result += fmt::format("{} Events:\n", indent);
347+
result += fmt::format("{} Load: {}\n", indent, sw->counter.load.get());
348+
result += fmt::format("{} Store: {}\n", indent, sw->counter.store.get());
349+
result += fmt::format("{} Conflict: {}\n", indent, sw->counter.conflict.get());
350+
351+
// 递归打印子交换机
352+
for (const auto &child : sw->switches) {
353+
print_switch(child, depth + 1);
354+
}
357355

358-
// 打印端点
359-
for (const auto &endpoint : sw->expanders) {
360-
result += std::format("{}Expander:\n", indent + " ");
361-
result += std::format("{} Events:\n", indent + " ");
362-
result += std::format("{} Load: {}\n", indent + " ", endpoint->counter.load.get());
363-
result += std::format("{} Store: {}\n", indent + " ", endpoint->counter.store.get());
364-
result += std::format("{} Migrate in: {}\n", indent + " ", endpoint->counter.migrate_in.get());
365-
result += std::format("{} Migrate out: {}\n", indent + " ", endpoint->counter.migrate_out.get());
366-
result += std::format("{} Hit Old: {}\n", indent + " ", endpoint->counter.hit_old.get());
367-
}
368-
};
356+
// 打印端点
357+
for (const auto &endpoint : sw->expanders) {
358+
result += fmt::format("{}Expander:\n", indent + " ");
359+
result += fmt::format("{} Events:\n", indent + " ");
360+
result += fmt::format("{} Load: {}\n", indent + " ", endpoint->counter.load.get());
361+
result += fmt::format("{} Store: {}\n", indent + " ", endpoint->counter.store.get());
362+
result += fmt::format("{} Migrate in: {}\n", indent + " ", endpoint->counter.migrate_in.get());
363+
result += fmt::format("{} Migrate out: {}\n", indent + " ", endpoint->counter.migrate_out.get());
364+
result += fmt::format("{} Hit Old: {}\n", indent + " ", endpoint->counter.hit_old.get());
365+
}
366+
};
369367

370-
// 从控制器开始递归打印
371-
print_switch(&controller, 0);
368+
// 从控制器开始递归打印
369+
print_switch(&controller, 0);
372370

373-
// 打印额外的统计信息
374-
result += "\nStatistics:\n";
375-
result += std::format(" Number of Switches: {}\n", controller.num_switches);
376-
result += std::format(" Number of Endpoints: {}\n", controller.num_end_points);
377-
result += std::format(" Number of Threads created: {}\n", controller.thread_map.size());
378-
result += std::format(" Memory Freed: {} bytes\n", controller.freed);
371+
// 打印额外的统计信息
372+
result += "\nStatistics:\n";
373+
result += fmt::format(" Number of Switches: {}\n", controller.num_switches);
374+
result += fmt::format(" Number of Endpoints: {}\n", controller.num_end_points);
375+
result += fmt::format(" Number of Threads created: {}\n", controller.thread_map.size());
376+
result += fmt::format(" Memory Freed: {} bytes\n", controller.freed);
379377

380-
return format_to(ctx.out(), "{}", result);
381-
}
382-
};
378+
return format_to(ctx.out(), "{}", result);
379+
}
380+
};
381+
}
383382

384383
extern CXLController *controller;
385384
#endif // CXLMEMSIM_CXLCONTROLLER_H

include/cxlcounter.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <concepts>
1616
#include <cstdint>
1717
#include <optional>
18-
#include <format>
19-
#include <source_location>
2018
#include <string>
2119
/** TODO: Whether to using the pebs to record the state. add back invalidation migrate huge/ page and prefetch*/
2220
const char loadName[] = "load";
@@ -64,9 +62,10 @@ template <const char *Name> class AtomicCounter {
6462
constexpr operator uint64_t() const noexcept { return get(); }
6563

6664
// 用于可能需要记录的事件日志 (For event logs that may need to be recorded)
67-
void log_increment(std::source_location loc = std::source_location::current()) const {
68-
// 未来可以实现日志记录 (Logging can be implemented in the future)
69-
}
65+
// Note: std::source_location is C++20, but not all compilers support it yet
66+
// void log_increment(std::source_location loc = std::source_location::current()) const {
67+
// // 未来可以实现日志记录 (Logging can be implemented in the future)
68+
// }
7069
};
7170
// 确保AtomicCounter满足Counter概念 (Ensure AtomicCounter meets the Counter concept)
7271
template <const char *Name>
@@ -75,16 +74,17 @@ inline constexpr bool implements_counter_concept = requires(AtomicCounter<Name>
7574
{ t.increment() } -> std::same_as<void>;
7675
};
7776

78-
template <const char *Name> struct std::formatter<AtomicCounter<Name>> {
79-
constexpr auto parse(std::format_parse_context &ctx) -> decltype(ctx.begin()) { return ctx.end(); }
80-
81-
template <typename FormatContext>
82-
auto format(const AtomicCounter<Name> &counter, FormatContext &ctx) const -> decltype(ctx.out()) {
83-
// 简化formatter实现,避免嵌套std::format调用 (Simplify formatter implementation, avoid nested std::format
84-
// calls)
85-
return format_to(ctx.out(), "{}", counter.get());
86-
}
87-
};
77+
// C++20 doesn't have std::formatter - this requires C++20 with fmt library
78+
// template <const char *Name> struct std::formatter<AtomicCounter<Name>> {
79+
// constexpr auto parse(std::format_parse_context &ctx) -> decltype(ctx.begin()) { return ctx.end(); }
80+
//
81+
// template <typename FormatContext>
82+
// auto format(const AtomicCounter<Name> &counter, FormatContext &ctx) const -> decltype(ctx.out()) {
83+
// // 简化formatter实现,避免嵌套std::format调用 (Simplify formatter implementation, avoid nested std::format
84+
// // calls)
85+
// return format_to(ctx.out(), "{}", counter.get());
86+
// }
87+
// };
8888

8989
// 使用C++20的enum class和强类型枚举 (Use C++20 enum class and strong-typed enumerations)
9090
enum class EventType { Load, Store, Conflict, MigrateIn, MigrateOut, HitOld, Local, Remote, Hitm };

include/rdma_communication.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class RDMATransport {
136136
if (std::string(mode) == "rdma") return MODE_RDMA;
137137
if (std::string(mode) == "shm") return MODE_SHM;
138138
}
139-
return MODE_RDMA
139+
return MODE_RDMA;
140140
}
141141

142142
static bool is_rdma_available() {

src/incore.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ void pcm_cpuid(const unsigned leaf, CPUID_INFO *info) {
1919
}
2020

2121
int Incore::start() {
22-
int i, r = -1;
22+
int r = -1;
2323

24-
for (i = 0; i < this->perf.size(); i++) {
24+
for (size_t i = 0; i < this->perf.size(); i++) {
2525
r = this->perf[i]->start();
2626
if (r < 0) {
2727
SPDLOG_ERROR("perf_start failed. i:{}\n", i);
@@ -31,9 +31,9 @@ int Incore::start() {
3131
return r;
3232
}
3333
int Incore::stop() {
34-
int i, r = -1;
34+
int r = -1;
3535

36-
for (i = 0; i < this->perf.size(); i++) {
36+
for (size_t i = 0; i < this->perf.size(); i++) {
3737
r = this->perf[i]->stop();
3838
if (r < 0) {
3939
SPDLOG_ERROR("perf_stop failed. i:{}\n", i);
@@ -45,8 +45,8 @@ int Incore::stop() {
4545

4646
ssize_t Incore::read_cpu_elems(struct CPUElem *elem) {
4747
ssize_t r;
48-
for (auto const &[idx, value] : this->perf | std::views::enumerate) {
49-
r = value->read_pmu(&elem->cpu[idx]);
48+
for (size_t idx = 0; idx < this->perf.size(); idx++) {
49+
r = this->perf[idx]->read_pmu(&elem->cpu[idx]);
5050
if (r < 0) {
5151
SPDLOG_ERROR("read cpu_elems[{}] failed.\n", std::get<0>(helper.perf_conf.cpu[idx]));
5252
}
@@ -58,7 +58,7 @@ ssize_t Incore::read_cpu_elems(struct CPUElem *elem) {
5858

5959
Incore::Incore(const pid_t pid, const int cpu, struct PerfConfig *perf_config) : perf_config(perf_config) {
6060
/* reset all pmc values */
61-
for (int i = 0; i < perf_config->cpu.size(); i++) {
61+
for (size_t i = 0; i < perf_config->cpu.size(); i++) {
6262
this->perf[i] = init_incore_perf(pid, cpu, std::get<1>(perf_config->cpu[i]), std::get<2>(perf_config->cpu[i]));
6363
}
6464
}

src/main.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ int main(int argc, char *argv[]) {
180180
auto ncpu = helper.num_of_cpu();
181181
auto ncha = helper.num_of_cha();
182182
SPDLOG_DEBUG("tnum:{}", tnum);
183-
for (auto const &[idx, value] : weight | std::views::enumerate) {
184-
SPDLOG_DEBUG("weight[{}]:{}", weight_vec[idx], value);
183+
for (size_t idx = 0; idx < weight.size(); idx++) {
184+
SPDLOG_DEBUG("weight[{}]:{}", weight_vec[idx], weight[idx]);
185185
}
186186

187-
for (auto const &[idx, value] : capacity | std::views::enumerate) {
187+
for (size_t idx = 0; idx < capacity.size(); idx++) {
188188
if (idx == 0) {
189-
SPDLOG_DEBUG("local_memory_region capacity:{}", value);
189+
SPDLOG_DEBUG("local_memory_region capacity:{}", capacity[idx]);
190190
controller = new CXLController({policy1, policy2, policy3, policy4}, capacity[0], mode, 100, dramlatency);
191191
} else {
192192
SPDLOG_DEBUG("memory_region:{}", (idx - 1) + 1);
@@ -284,10 +284,10 @@ int main(int argc, char *argv[]) {
284284

285285
/* read CHA params */
286286
for (const auto &mon : monitors->mon) {
287-
for (auto const &[idx, value] : pmu.chas | std::views::enumerate) {
287+
for (size_t idx = 0; idx < pmu.chas.size(); idx++) {
288288
pmu.chas[idx].read_cha_elems(&mon.before->chas[idx]);
289289
}
290-
for (auto const &[idx, value] : pmu.cpus | std::views::enumerate) {
290+
for (size_t idx = 0; idx < pmu.cpus.size(); idx++) {
291291
pmu.cpus[idx].read_cpu_elems(&mon.before->cpus[idx]);
292292
}
293293
}
@@ -303,7 +303,8 @@ int main(int argc, char *argv[]) {
303303

304304
while (true) {
305305
uint64_t calibrated_delay;
306-
for (auto const &[i, mon] : monitors->mon | std::views::enumerate) {
306+
for (size_t i = 0; i < monitors->mon.size(); i++) {
307+
const auto &mon = monitors->mon[i];
307308
// check other process
308309
auto m_status = mon.status.load();
309310
if (m_status == MONITOR_DISABLE) {
@@ -336,13 +337,13 @@ int main(int argc, char *argv[]) {
336337
}
337338
target_llcmiss = mon.after->pebs.total - mon.before->pebs.total;
338339

339-
for (auto const &[idx, value] : pmu.cpus | std::views::enumerate) {
340-
value.read_cpu_elems(&mon.after->cpus[i]);
340+
for (size_t idx = 0; idx < pmu.cpus.size(); idx++) {
341+
pmu.cpus[idx].read_cpu_elems(&mon.after->cpus[i]);
341342
cpu_vec[idx] = mon.after->cpus[i].cpu[idx] - mon.before->cpus[i].cpu[idx];
342343
}
343344

344-
for (auto const &[idx, value] : pmu.chas | std::views::enumerate) {
345-
value.read_cha_elems(&mon.after->chas[cha_mapping[i]]);
345+
for (size_t idx = 0; idx < pmu.chas.size(); idx++) {
346+
pmu.chas[idx].read_cha_elems(&mon.after->chas[cha_mapping[i]]);
346347
cha_vec[idx] = mon.after->chas[cha_mapping[i]].cha[idx] - mon.before->chas[cha_mapping[i]].cha[idx];
347348
}
348349
target_llchits = cpu_vec[0];

0 commit comments

Comments
 (0)