0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-27 11:18:51 +02:00

ircd::ctx: Unify access to ctx::stack, expose structure; remove cruft.

This commit is contained in:
Jason Volk 2020-04-23 05:05:57 -07:00
parent dd1e016ec5
commit 5a27958fa0
5 changed files with 60 additions and 41 deletions

View file

@ -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 &notes(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"

26
include/ircd/ctx/stack.h Normal file
View file

@ -0,0 +1,26 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
//
// 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;
};

View file

@ -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

View file

@ -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

View file

@ -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 << " "