From 8c68a24e1f04c64b19377d951625cfd604e97dee Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 12 Apr 2019 15:57:34 -0700 Subject: [PATCH] ircd::ctx::prof: Add cycle counter to ticker array. --- include/ircd/ctx/prof.h | 4 +--- ircd/ctx.cc | 22 ++++++++++++++++------ modules/console.cc | 6 +----- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/ircd/ctx/prof.h b/include/ircd/ctx/prof.h index c7f0d5ae2..63ac649f9 100644 --- a/include/ircd/ctx/prof.h +++ b/include/ircd/ctx/prof.h @@ -83,6 +83,7 @@ enum class ircd::ctx::prof::event CONTINUE, // Current context continuing INTERRUPT, // Current context detects interruption TERMINATE, // Current context detects termination + CYCLES, // monotonic counter (rdtsc) _NUM_ }; @@ -90,9 +91,6 @@ enum class ircd::ctx::prof::event /// structure aggregating any profiling related state for a ctx struct ircd::ctx::prof::ticker { - // monotonic counter (rdtsc) - ulong cycles {0}; - // monotonic counters for events std::array()> event {{0}}; }; diff --git a/ircd/ctx.cc b/ircd/ctx.cc index 60521b548..c67b61ba1 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -509,7 +509,7 @@ noexcept const ulong & ircd::ctx::cycles(const ctx &ctx) { - return ctx.profile.cycles; + return prof::get(ctx, prof::event::CYCLES); } /// Returns the yield count for `ctx` @@ -918,7 +918,7 @@ ircd::ctx::this_ctx::slice_usage_warning::slice_usage_warning(const string_view !current? prof::cycles(): ~cur().flags & context::SLICE_EXEMPT? - cur().profile.cycles + prof::cur_slice_cycles(): + prof::get(cur(), prof::event::CYCLES) + prof::cur_slice_cycles(): 0 } { @@ -941,7 +941,7 @@ noexcept const auto stop { current? - cur().profile.cycles + prof::cur_slice_cycles(): + prof::get(cur(), prof::event::CYCLES) + prof::cur_slice_cycles(): prof::cycles() }; @@ -1717,10 +1717,19 @@ ircd::ctx::prof::slice_leave() auto &c(cur()); assert(_slice_stop >= _slice_start); - const auto last_slice(_slice_stop - _slice_start); + const auto last_slice + { + _slice_stop - _slice_start + }; + + static constexpr auto pos + { + size_t(prof::event::CYCLES) + }; + + c.profile.event.at(pos) += last_slice; + _total.event.at(pos) += last_slice; c.stack.at = stack_at_here(); - c.profile.cycles += last_slice; - _total.cycles += last_slice; } #ifndef NDEBUG @@ -1903,6 +1912,7 @@ ircd::ctx::prof::reflect(const event &e) case event::CONTINUE: return "CONTINUE"; case event::INTERRUPT: return "INTERRUPT"; case event::TERMINATE: return "TERMINATE"; + case event::CYCLES: return "CYCLES"; case event::_NUM_: break; } diff --git a/modules/console.cc b/modules/console.cc index 7d6352974..6007692c7 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1486,10 +1486,6 @@ console_cmd__ctx__prof(opt &out, const string_view &line) << " " << t.event.at(uint8_t(event)) << std::endl; }); - - out << std::left << std::setw(15) << std::setfill('_') << "cycles" - << " " << t.cycles - << std::endl; }}; if(!param["id"]) @@ -1592,7 +1588,7 @@ console_cmd__ctx__list(opt &out, const string_view &line) out << " " << std::setw(15) << std::right << cycles(ctx); - const long double total_cyc(ctx::prof::get().cycles); + const long double total_cyc(ctx::prof::get(ctx, ctx::prof::event::CYCLES)); const auto tsc_pct { total_cyc > 0.0? (cycles(ctx) / total_cyc) : 0.0L