0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 15:30:52 +01:00

ircd::prof: Make scope_cycles add to result rather than overwriting it.

This commit is contained in:
Jason Volk 2020-06-24 08:41:48 -07:00
parent 200e4c55cf
commit b22d4e2eb1

View file

@ -17,13 +17,15 @@ namespace ircd::prof
} }
/// Count the reference cycles for a scope using the lifetime of this object. /// Count the reference cycles for a scope using the lifetime of this object.
/// The result is stored in `result`. Note that `result` is also used while /// The result is added to the value in `result`; note that result must be
/// this object is operating. /// initialized.
struct ircd::prof::scope_cycles struct ircd::prof::scope_cycles
{ {
uint64_t &result; uint64_t &result;
uint64_t started;
scope_cycles(uint64_t &result) noexcept; scope_cycles(uint64_t &result) noexcept;
scope_cycles(const scope_cycles &) = delete;
~scope_cycles() noexcept; ~scope_cycles() noexcept;
}; };
@ -42,7 +44,7 @@ noexcept
asm volatile ("lfence"); asm volatile ("lfence");
#endif #endif
result = cycles(); started = cycles();
#if defined(__x86_64__) || defined(__i386__) #if defined(__x86_64__) || defined(__i386__)
asm volatile ("lfence"); asm volatile ("lfence");
@ -63,7 +65,8 @@ noexcept
asm volatile ("lfence"); asm volatile ("lfence");
#endif #endif
result = cycles() - result; const uint64_t stopped(cycles());
result += stopped - started;
#if defined(__x86_64__) || defined(__i386__) #if defined(__x86_64__) || defined(__i386__)
asm volatile ("lfence"); asm volatile ("lfence");