Remove one stack address load.

This commit is contained in:
Bartosz Taudul 2017-10-11 01:27:22 +02:00
parent af3773dc9a
commit 77dfefb5d0
5 changed files with 32 additions and 27 deletions

View File

@ -20,11 +20,12 @@ public:
{
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::LockAnnounce;
item->lockAnnounce.id = m_id;
item->lockAnnounce.srcloc = (uint64_t)srcloc;
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
Lockable( const Lockable& ) = delete;
@ -37,12 +38,13 @@ public:
{
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::LockWait;
item->lockWait.id = m_id;
item->lockWait.thread = thread;
item->lockWait.time = Profiler::GetTime( cpu );
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
m_lockable.lock();
@ -50,12 +52,13 @@ public:
{
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::LockObtain;
item->lockObtain.id = m_id;
item->lockObtain.thread = thread;
item->lockObtain.time = Profiler::GetTime( cpu );
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
}
@ -66,12 +69,13 @@ public:
uint32_t cpu;
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::LockRelease;
item->lockRelease.id = m_id;
item->lockRelease.thread = GetThreadHandle();
item->lockRelease.time = Profiler::GetTime( cpu );
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
tracy_force_inline bool try_lock()
@ -82,12 +86,13 @@ public:
uint32_t cpu;
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::LockObtain;
item->lockObtain.id = (uint64_t)&m_lockable;
item->lockObtain.thread = GetThreadHandle();
item->lockObtain.time = Profiler::GetTime( cpu );
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
return ret;
}
@ -96,12 +101,13 @@ public:
{
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::LockMark;
item->lockMark.id = m_id;
item->lockMark.thread = GetThreadHandle();
item->lockMark.srcloc = (uint64_t)srcloc;
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
private:

View File

@ -319,20 +319,22 @@ void Profiler::CalibrateDelay()
static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 };
{
Magic magic;
auto& tail = ptoken->get_tail_index();
auto item = ptoken->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::ZoneBegin;
item->zoneBegin.thread = GetThreadHandle();
item->zoneBegin.time = GetTime( item->zoneBegin.cpu );
item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location;
ptoken->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
{
Magic magic;
auto& tail = ptoken->get_tail_index();
auto item = ptoken->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::ZoneEnd;
item->zoneEnd.thread = 0;
item->zoneEnd.time = GetTime( item->zoneEnd.cpu );
ptoken->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
}
const auto f0 = GetTime( cpu );
@ -347,20 +349,22 @@ void Profiler::CalibrateDelay()
static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 };
{
Magic magic;
auto& tail = ptoken->get_tail_index();
auto item = ptoken->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::ZoneBegin;
item->zoneBegin.thread = GetThreadHandle();
item->zoneBegin.time = GetTime( item->zoneBegin.cpu );
item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location;
ptoken->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
{
Magic magic;
auto& tail = ptoken->get_tail_index();
auto item = ptoken->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::ZoneEnd;
item->zoneEnd.thread = 0;
item->zoneEnd.time = GetTime( item->zoneEnd.cpu );
ptoken->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
}
const auto t1 = GetTime( cpu );

View File

@ -70,10 +70,11 @@ public:
uint32_t cpu;
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::FrameMarkMsg;
item->frameMark.time = GetTime( cpu );
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
static bool ShouldExit();

View File

@ -19,23 +19,25 @@ public:
m_thread = thread;
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::ZoneBegin;
item->zoneBegin.time = Profiler::GetTime( item->zoneBegin.cpu );
item->zoneBegin.thread = thread;
item->zoneBegin.srcloc = (uint64_t)srcloc;
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
tracy_force_inline ~ScopedZone()
{
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::ZoneEnd;
item->zoneEnd.time = Profiler::GetTime( item->zoneEnd.cpu );
item->zoneEnd.thread = m_thread;
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
tracy_force_inline void Text( const char* txt, size_t size )
@ -45,22 +47,24 @@ public:
memcpy( ptr, txt, size );
ptr[size] = '\0';
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::ZoneText;
item->zoneText.thread = m_thread;
item->zoneText.text = (uint64_t)ptr;
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
tracy_force_inline void Name( const char* name )
{
Magic magic;
auto& token = s_token;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::ZoneName;
item->zoneName.thread = m_thread;
item->zoneName.name = (uint64_t)name;
token->enqueue_finish( magic );
tail.store( magic + 1, std::memory_order_release );
}
private:

View File

@ -958,11 +958,6 @@ public:
return inner_enqueue_begin<CanAlloc>(token, currentTailIndex);
}
tracy_force_inline void enqueue_finish(producer_token_t const& token, index_t currentTailIndex)
{
inner_enqueue_finish(token, currentTailIndex);
}
// Enqueues several items.
// Allocates memory if required. Only fails if memory allocation fails (or
// implicit production is disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE
@ -1307,11 +1302,6 @@ private:
return static_cast<ExplicitProducer*>(token.producer)->ConcurrentQueue::ExplicitProducer::template enqueue_begin<canAlloc>(currentTailIndex);
}
tracy_force_inline void inner_enqueue_finish(producer_token_t const& token, index_t currentTailIndex)
{
return static_cast<ExplicitProducer*>(token.producer)->ConcurrentQueue::ExplicitProducer::template enqueue_finish(currentTailIndex);
}
template<AllocationMode canAlloc, typename U>
inline bool inner_enqueue(U&& element)
{
@ -1989,9 +1979,9 @@ private:
}
}
tracy_force_inline void enqueue_finish(index_t currentTailIndex)
tracy_force_inline std::atomic<index_t>& get_tail_index()
{
this->tailIndex.store(currentTailIndex + 1, std::memory_order_release);
return this->tailIndex;
}
template<typename U>