diff --git a/include/ircd/ctx/ctx.h b/include/ircd/ctx/ctx.h index ee4d05853..6f8d57b1b 100644 --- a/include/ircd/ctx/ctx.h +++ b/include/ircd/ctx/ctx.h @@ -45,8 +45,6 @@ namespace ircd::ctx const uint64_t &id(const ctx &) noexcept; // Unique ID for context string_view name(const ctx &) noexcept; // User's optional label for context - const size_t &stack_max(const ctx &) noexcept; // Returns stack size allocated for ctx - const size_t &stack_at(const ctx &) noexcept; // Stack at last sleep (also see this_ctx.h) const int32_t ¬es(const ctx &) noexcept; // Peeks at internal semaphore count const uint64_t &epoch(const ctx &) noexcept; // Context switching counter const ulong &cycles(const ctx &) noexcept; // Accumulated tsc (not counting cur slice) @@ -81,6 +79,7 @@ namespace ircd::ctx #include "this_ctx.h" #include "wait.h" #include "sleep.h" +#include "stack.h" #include "stack_usage_assertion.h" #include "slice_usage_warning.h" #include "critical_assertion.h" diff --git a/include/ircd/ctx/stack.h b/include/ircd/ctx/stack.h new file mode 100644 index 000000000..77d929778 --- /dev/null +++ b/include/ircd/ctx/stack.h @@ -0,0 +1,26 @@ +// The Construct +// +// Copyright (C) The Construct Developers, Authors & Contributors +// Copyright (C) 2016-2020 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +namespace ircd::ctx +{ + struct stack; +} + +struct ircd::ctx::stack +{ + uintptr_t base {0}; // assigned when spawned + size_t max {0}; // User given stack size + size_t at {0}; // Updated for profiling at sleep + + stack(const size_t &max); + + static const stack &get(const ctx &) noexcept; + static stack &get(ctx &) noexcept; +}; diff --git a/ircd/ctx.cc b/ircd/ctx.cc index 3fbd2b55d..6e212bc1e 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -654,24 +654,6 @@ noexcept return ctx.notes; } -/// Returns the notification count for `ctx` -[[gnu::hot]] -const size_t & -ircd::ctx::stack_at(const ctx &ctx) -noexcept -{ - return ctx.stack.at; -} - -/// Returns the notification count for `ctx` -[[gnu::hot]] -const size_t & -ircd::ctx::stack_max(const ctx &ctx) -noexcept -{ - return ctx.stack.max; -} - /// Returns the developer's optional name literal for `ctx` [[gnu::hot]] ircd::string_view @@ -998,6 +980,36 @@ noexcept } #endif +////////////////////////////////////////////////////////////////////////////// +// +// ctx/stack.h +// + +[[gnu::hot]] +ircd::ctx::stack & +ircd::ctx::stack::get(ctx &ctx) +noexcept +{ + return ctx.stack; +} + +[[gnu::hot]] +const ircd::ctx::stack & +ircd::ctx::stack::get(const ctx &ctx) +noexcept +{ + return ctx.stack; +} + +// +// stack::stack +// + +ircd::ctx::stack::stack(const size_t &max) +:max{max} +{ +} + /////////////////////////////////////////////////////////////////////////////// // // ctx/continuation.h diff --git a/ircd/ctx.h b/ircd/ctx.h index aba63e264..e5b7ec67c 100644 --- a/ircd/ctx.h +++ b/ircd/ctx.h @@ -18,29 +18,11 @@ #define IRCD_CTX_STACK_PROTECT #endif -namespace ircd::ctx -{ - struct stack; - struct profile; -} - namespace ircd::ctx::prof { void mark(const event &); } -/// Internal structure aggregating any stack related state for the ctx -struct ircd::ctx::stack -{ - uintptr_t base {0}; // assigned when spawned - size_t max {0}; // User given stack size - size_t at {0}; // Updated for profiling at sleep - - stack(const size_t &max = 0) - :max{max} - {} -}; - /// Internal context implementation /// struct ircd::ctx::ctx diff --git a/modules/console.cc b/modules/console.cc index cc07df6d2..8a671fe13 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -2459,14 +2459,14 @@ console_cmd__ctx__list(opt &out, const string_view &line) thread_local char pbuf[32]; out << " " - << std::setw(25) << std::right << pretty(pbuf, iec(stack_at(ctx))); + << std::setw(25) << std::right << pretty(pbuf, iec(ctx::stack::get(ctx).at)); out << " " - << std::setw(25) << std::right << pretty(pbuf, iec(stack_max(ctx))); + << std::setw(25) << std::right << pretty(pbuf, iec(ctx::stack::get(ctx).max)); const auto stack_pct { - stack_at(ctx) / (long double)stack_max(ctx) + ctx::stack::get(ctx).at / (long double)(ctx::stack::get(ctx).max) }; out << " "