aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColm Donelan <Colm.Donelan@arm.com>2019-11-20 14:59:12 +0000
committerKeith Davis Arm <keith.davis@arm.com>2019-11-21 10:06:08 +0000
commit4cace320a75de835c08a87bb8aa3cfd0cd18ddfd (patch)
treefd07af2670e6c9829cbd4e5f519bafeb9b98aafc
parentcf7c1c695fa5ef81334b8b5664905409a71ac852 (diff)
downloadarmnn-4cace320a75de835c08a87bb8aa3cfd0cd18ddfd.tar.gz
IVGCVSW-4124 Replacing the "sleep_for" loop from FileOnlyProfilingConnection
* Replacing the "sleep_for" loop in FileOnlyProfilingConnection with a producer consumer conditional mutex. * Reducing the times sleep loop times in FileOnlyProfilingDecoratorTests. Signed-off-by: Colm Donelan <Colm.Donelan@arm.com> Change-Id: Ied2302b508b6e4e6b50809c77e3f19115449d0b6
-rw-r--r--src/profiling/FileOnlyProfilingConnection.cpp21
-rw-r--r--src/profiling/FileOnlyProfilingConnection.hpp4
-rw-r--r--src/profiling/test/FileOnlyProfilingDecoratorTests.cpp4
3 files changed, 19 insertions, 10 deletions
diff --git a/src/profiling/FileOnlyProfilingConnection.cpp b/src/profiling/FileOnlyProfilingConnection.cpp
index b32ae49911..004e27d30a 100644
--- a/src/profiling/FileOnlyProfilingConnection.cpp
+++ b/src/profiling/FileOnlyProfilingConnection.cpp
@@ -69,7 +69,11 @@ void FileOnlyProfilingConnection::SendConnectionAck()
std::cout << "Sending connection acknowledgement." << std::endl;
}
std::unique_ptr<unsigned char[]> uniqueNullPtr = nullptr;
- m_PacketQueue.push(Packet(0x10000, 0, uniqueNullPtr));
+ {
+ std::lock_guard<std::mutex> lck(m_PacketAvailableMutex);
+ m_PacketQueue.push(Packet(0x10000, 0, uniqueNullPtr));
+ }
+ m_ConditionPacketAvailable.notify_one();
}
bool FileOnlyProfilingConnection::SendCounterSelectionPacket()
@@ -94,7 +98,11 @@ bool FileOnlyProfilingConnection::SendCounterSelectionPacket()
offset += uint16_t_size;
}
- m_PacketQueue.push(Packet(0x40000, bodySize, uniqueData));
+ {
+ std::lock_guard<std::mutex> lck(m_PacketAvailableMutex);
+ m_PacketQueue.push(Packet(0x40000, bodySize, uniqueData));
+ }
+ m_ConditionPacketAvailable.notify_one();
return true;
}
@@ -155,13 +163,10 @@ bool FileOnlyProfilingConnection::WritePacket(const unsigned char* buffer, uint3
Packet FileOnlyProfilingConnection::ReadPacket(uint32_t timeout)
{
- uint16_t loopCount = 10;
- uint32_t timeoutFraction = timeout / loopCount;
- while (m_PacketQueue.empty())
+ std::unique_lock<std::mutex> lck(m_PacketAvailableMutex);
+ if (m_PacketQueue.empty())
{
- std::this_thread::sleep_for(std::chrono::milliseconds(timeoutFraction));
- --loopCount;
- if ((loopCount) == 0)
+ if(m_ConditionPacketAvailable.wait_for(lck, std::chrono::milliseconds(timeout)) == std::cv_status::timeout)
{
throw armnn::TimeoutException("Thread has timed out as per requested time limit");
}
diff --git a/src/profiling/FileOnlyProfilingConnection.hpp b/src/profiling/FileOnlyProfilingConnection.hpp
index 12a87a1535..d4477b6883 100644
--- a/src/profiling/FileOnlyProfilingConnection.hpp
+++ b/src/profiling/FileOnlyProfilingConnection.hpp
@@ -11,6 +11,7 @@
#include "ProfilingUtils.hpp"
#include "Runtime.hpp"
+#include <condition_variable>
#include <fstream>
#include <queue>
@@ -75,6 +76,9 @@ private:
std::vector<uint16_t> m_IdList;
std::queue<Packet> m_PacketQueue;
TargetEndianness m_Endianness;
+
+ std::mutex m_PacketAvailableMutex;
+ std::condition_variable m_ConditionPacketAvailable;
};
} // namespace profiling
diff --git a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp
index 5524ed4fbf..d4907b6365 100644
--- a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp
+++ b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp
@@ -45,8 +45,8 @@ BOOST_AUTO_TEST_CASE(DumpOutgoingValidFileEndToEnd)
profilingService.Update();
profilingService.Update();
- uint32_t timeout = 2000;
- uint32_t sleepTime = 50;
+ uint32_t timeout = 25; // Wait for a maximum of 25mSec
+ uint32_t sleepTime = 1; // in 1mSec intervals.
uint32_t timeSlept = 0;
// Give the profiling service sending thread time start executing and send the stream metadata.