@@ -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 += " \n Statistics:\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 += " \n Statistics:\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
384383extern CXLController *controller;
385384#endif // CXLMEMSIM_CXLCONTROLLER_H
0 commit comments