diff options
author | Finn Williams <Finn.Williams@arm.com> | 2019-12-19 17:05:18 +0000 |
---|---|---|
committer | Finn Williams <Finn.Williams@arm.com> | 2020-01-14 12:39:05 +0000 |
commit | 09ad6f909f25aef02b7f53bba320b534b9260786 (patch) | |
tree | e69f6d9d4b15b0c7e106c5f6749dd77586247a75 /src/profiling/SendCounterPacket.cpp | |
parent | f90c56d72de4848a2dc5844a97458aaf09df07c2 (diff) | |
download | armnn-09ad6f909f25aef02b7f53bba320b534b9260786.tar.gz |
IVGCVSW-4229 Fix Intermittent failures in ExternalProfiling
* Added a BufferManager.Reset() method to prevent packets being retained after a test
* Fixed a bug causing the send thread to wait needlessly before moving to active state
* Refactored SendCoundPacketTests and ProfilingTests test helper classes
* Fixed issue where WaitForPacketSent could miss a notification and timeout
Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Change-Id: I353a652260c2f7dd465baa9e979e22f50f3ca6a7
Diffstat (limited to 'src/profiling/SendCounterPacket.cpp')
-rw-r--r-- | src/profiling/SendCounterPacket.cpp | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/profiling/SendCounterPacket.cpp b/src/profiling/SendCounterPacket.cpp index 5badea9d83..5128331c46 100644 --- a/src/profiling/SendCounterPacket.cpp +++ b/src/profiling/SendCounterPacket.cpp @@ -936,6 +936,8 @@ void SendCounterPacket::Start(IProfilingConnection& profilingConnection) // no need for a mutex as the send thread can not be running at this point m_ReadyToRead = false; + m_PacketSent = false; + // Start the send thread m_SendThread = std::thread(&SendCounterPacket::Send, this, std::ref(profilingConnection)); } @@ -1016,15 +1018,20 @@ void SendCounterPacket::Send(IProfilingConnection& profilingConnection) { std::unique_lock<std::mutex> lock(m_WaitMutex); - m_WaitCondition.wait_for(lock, std::chrono::milliseconds(m_Timeout), [&]{ return m_ReadyToRead; }); - + bool timeout = m_WaitCondition.wait_for(lock, + std::chrono::milliseconds(m_Timeout), + [&]{ return m_ReadyToRead; }); + // If we get notified we need to flush the buffer again + if(timeout) + { + // Otherwise if we just timed out don't flush the buffer + continue; + } //reset condition variable predicate for next use m_ReadyToRead = false; } // Wait condition lock scope - End - - // Do not flush the buffer again - continue; + break; case ProfilingState::Active: default: // Wait condition lock scope - Begin @@ -1103,15 +1110,32 @@ void SendCounterPacket::FlushBuffer(IProfilingConnection& profilingConnection, b // Get the next available readable buffer packetBuffer = m_BufferManager.GetReadableBuffer(); } - // Check whether at least a packet has been sent if (packetsSent && notifyWatchers) { + // Wait for the parent thread to release its mutex if necessary + { + std::lock_guard<std::mutex> lck(m_PacketSentWaitMutex); + m_PacketSent = true; + } // Notify to any watcher that something has been sent m_PacketSentWaitCondition.notify_one(); } } +bool SendCounterPacket::WaitForPacketSent(uint32_t timeout = 1000) +{ + std::unique_lock<std::mutex> lock(m_PacketSentWaitMutex); + // Blocks until notified that at least a packet has been sent or until timeout expires. + bool timedOut = m_PacketSentWaitCondition.wait_for(lock, + std::chrono::milliseconds(timeout), + [&] { return m_PacketSent; }); + + m_PacketSent = false; + + return timedOut; +} + } // namespace profiling } // namespace armnn |