From ba263efb92ffba13212cf4ee6fd15b4339349fb3 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Fri, 23 Sep 2022 09:02:59 -0700 Subject: Basic IPC stats support --- backend/regfile.h | 4 ++++ infra/stat.h | 35 +++++++++++++++++++++++++++++++++++ pt | 8 ++++++++ 3 files changed, 47 insertions(+) create mode 100644 infra/stat.h diff --git a/backend/regfile.h b/backend/regfile.h index 4cf328a..4ea2f31 100644 --- a/backend/regfile.h +++ b/backend/regfile.h @@ -4,6 +4,7 @@ #include "frontend/decode.h" #include "infra/port.h" +#include "infra/stat.h" #include "inst.h" #include "memory/dram.h" @@ -16,6 +17,8 @@ namespace backend { infra::port writebackp; infra::port *storep = nullptr; + infra::stat ipc{"ipc"}; + unsigned int generation_up = 0; unsigned int generation_down = 0; @@ -33,6 +36,7 @@ namespace backend { auto i = writebackp.read(); if (i.generation == generation_down) { pte(i.transaction, "W", fmt::format("writeback gen={} pc={:x}", generation_down, pc)); + ++ipc; assert(pc == i.init_pc); auto old_pc = pc; pc = i.linear_next_pc; diff --git a/infra/stat.h b/infra/stat.h new file mode 100644 index 0000000..f1ca75a --- /dev/null +++ b/infra/stat.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#include "infra/sim.h" + +namespace infra { + struct stat : public sim { + std::string name; + std::uint64_t numerator = 0; + std::uint64_t denominator = 0; + + stat(std::string name) + : name(std::move(name)) + { } + + ~stat() { + fmt::print("# {} {}\n", name, (double)numerator/(double)denominator); + } + + void unclock() { + ++denominator; + } + + stat & operator++() { + ++numerator; + return *this; + } + + stat & operator++(int) { + return operator++(); + } + }; +} diff --git a/pt b/pt index 489a13a..206795f 100755 --- a/pt +++ b/pt @@ -9,6 +9,8 @@ $data = {} $horiz = {} $maxtime = -1 +$stats = false + $stdin.each_line do | line | case line @@ -38,11 +40,17 @@ $stdin.each_line do | line | end $maxtime = [$maxtime, time+1].max + when /^#\s*(.*)$/ + $stats = true + $stdout.write("#{$1}\n") + else raise "Unexpected line: #{line}" end end +$stdout.write("\n") if $stats + $hier = {} $hier_direct = {} -- cgit v1.2.3