mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::ctx: Expand the reference cycle counting interface.
This commit is contained in:
parent
20d0ea70c2
commit
55241c5309
4 changed files with 54 additions and 11 deletions
|
@ -119,5 +119,5 @@ namespace ircd
|
|||
using ctx::critical_assertion;
|
||||
using ctx::critical_indicator;
|
||||
|
||||
using ctx::prof::rdtsc;
|
||||
using ctx::prof::cycles;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,11 @@ namespace ircd::ctx::prof
|
|||
struct ticker;
|
||||
|
||||
// util
|
||||
unsigned long long rdpmc();
|
||||
unsigned long long rdtsc();
|
||||
unsigned long long rdtscp();
|
||||
uint64_t cycles();
|
||||
|
||||
string_view reflect(const event &);
|
||||
|
||||
// totals
|
||||
|
@ -98,9 +102,33 @@ struct ircd::ctx::prof::ticker
|
|||
std::array<uint64_t, num_of<prof::event>()> event {{0}};
|
||||
};
|
||||
|
||||
inline uint64_t
|
||||
__attribute__((flatten, always_inline, gnu_inline, artificial))
|
||||
ircd::ctx::prof::cycles()
|
||||
{
|
||||
return rdtsc();
|
||||
}
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
inline unsigned long long
|
||||
__attribute__((flatten, always_inline, gnu_inline, artificial))
|
||||
__attribute__((always_inline, gnu_inline, artificial))
|
||||
ircd::ctx::prof::rdtscp()
|
||||
{
|
||||
uint32_t ia32_tsc_aux;
|
||||
return __builtin_ia32_rdtscp(&ia32_tsc_aux);
|
||||
}
|
||||
#else
|
||||
inline unsigned long long
|
||||
ircd::ctx::prof::rdtscp()
|
||||
{
|
||||
static_assert(false, "TODO: Implement fallback here");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
inline unsigned long long
|
||||
__attribute__((always_inline, gnu_inline, artificial))
|
||||
ircd::ctx::prof::rdtsc()
|
||||
{
|
||||
return __builtin_ia32_rdtsc();
|
||||
|
@ -113,3 +141,19 @@ ircd::ctx::prof::rdtsc()
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
inline unsigned long long
|
||||
__attribute__((always_inline, gnu_inline, artificial))
|
||||
ircd::ctx::prof::rdpmc()
|
||||
{
|
||||
return __builtin_ia32_rdpmc(0);
|
||||
}
|
||||
#else
|
||||
inline unsigned long long
|
||||
ircd::ctx::prof::rdpmc()
|
||||
{
|
||||
static_assert(false, "TODO: Implement fallback here");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
11
ircd/ctx.cc
11
ircd/ctx.cc
|
@ -8,7 +8,6 @@
|
|||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#include <RB_INC_X86INTRIN_H
|
||||
#include <cxxabi.h>
|
||||
#include <ircd/asio.h>
|
||||
#include "ctx.h"
|
||||
|
@ -874,7 +873,7 @@ ircd::ctx::this_ctx::slice_usage_warning::slice_usage_warning(const string_view
|
|||
// Set the start value to the total number of cycles accrued by this
|
||||
// context including the current time slice.
|
||||
!current?
|
||||
rdtsc():
|
||||
prof::cycles():
|
||||
~cur().flags & context::SLICE_EXEMPT?
|
||||
cur().profile.cycles + prof::cur_slice_cycles():
|
||||
0
|
||||
|
@ -900,7 +899,7 @@ noexcept
|
|||
{
|
||||
current?
|
||||
cur().profile.cycles + prof::cur_slice_cycles():
|
||||
rdtsc()
|
||||
prof::cycles()
|
||||
};
|
||||
|
||||
assert(stop >= start);
|
||||
|
@ -1665,13 +1664,13 @@ ircd::ctx::prof::handle_cur_continue()
|
|||
void
|
||||
ircd::ctx::prof::slice_enter()
|
||||
{
|
||||
_slice_start = rdtsc();
|
||||
_slice_start = cycles();
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ctx::prof::slice_leave()
|
||||
{
|
||||
_slice_stop = rdtsc();
|
||||
_slice_stop = cycles();
|
||||
|
||||
auto &c(cur());
|
||||
assert(_slice_stop >= _slice_start);
|
||||
|
@ -1813,7 +1812,7 @@ ircd::ctx::prof::slice_exceeded_warning(const ulong &cycles)
|
|||
ulong
|
||||
ircd::ctx::prof::cur_slice_cycles()
|
||||
{
|
||||
return rdtsc() - cur_slice_start();
|
||||
return cycles() - cur_slice_start();
|
||||
}
|
||||
|
||||
const ulong &
|
||||
|
|
|
@ -150,7 +150,7 @@ ircd::ios::handler::fault(handler *const &handler)
|
|||
// needs to be tied off here instead.
|
||||
if(!ret)
|
||||
{
|
||||
descriptor.slice_last = rdtsc() - handler->slice_start;
|
||||
descriptor.slice_last = cycles() - handler->slice_start;
|
||||
descriptor.slice_total += descriptor.slice_last;
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ ircd::ios::handler::leave(handler *const &handler)
|
|||
{
|
||||
assert(handler && handler->descriptor);
|
||||
auto &descriptor(*handler->descriptor);
|
||||
descriptor.slice_last = rdtsc() - handler->slice_start;
|
||||
descriptor.slice_last = cycles() - handler->slice_start;
|
||||
descriptor.slice_total += descriptor.slice_last;
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ ircd::ios::handler::enter(handler *const &handler)
|
|||
assert(handler && handler->descriptor);
|
||||
auto &descriptor(*handler->descriptor);
|
||||
++descriptor.calls;
|
||||
handler->slice_start = rdtsc();
|
||||
handler->slice_start = cycles();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue