From d98400f647cd8780781ffa32990da6850085c8fd Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Wed, 6 Nov 2019 18:57:36 -0500 Subject: [PATCH] kfdtest: Use GetSystemTickCountInMicroSec() as much as possible GetSystemTickCountInMicroSec() wraps the function gettimeofday(). Change-Id: I7b767a6efdd1db491fc8113313945b578ac69382 Signed-off-by: Yong Zhao [ROCm/ROCR-Runtime commit: 174484aac39e4eedf757860b887429ab65eaf9c3] --- .../tests/kfdtest/src/KFDQMTest.cpp | 27 +++++++++---------- .../tests/kfdtest/src/KFDTestUtil.cpp | 7 +++++ .../tests/kfdtest/src/KFDTestUtil.hpp | 2 ++ .../tests/kfdtest/src/LinuxOSWrapper.cpp | 7 ----- .../tests/kfdtest/src/OSWrapper.hpp | 2 -- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/projects/rocr-runtime/tests/kfdtest/src/KFDQMTest.cpp b/projects/rocr-runtime/tests/kfdtest/src/KFDQMTest.cpp index 13cfb96fb4..0c543e6202 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/KFDQMTest.cpp +++ b/projects/rocr-runtime/tests/kfdtest/src/KFDQMTest.cpp @@ -640,14 +640,13 @@ HSAint64 KFDQMTest::TimeConsumedwithCUMask(int node, uint32_t* mask, uint32_t ma EXPECT_SUCCESS(queue.SetCUMask(mask, mask_count)); queue.SetSkipWaitConsump(true); - struct timeval start, now; - gettimeofday(&start, NULL); + HSAuint64 startTime = GetSystemTickCountInMicroSec(); dispatch.Submit(queue); dispatch.Sync(); - gettimeofday(&now, NULL); + HSAuint64 endTime = GetSystemTickCountInMicroSec(); EXPECT_SUCCESS(queue.Destroy()); - return (now.tv_sec *1000LL + now.tv_usec/1000LL - start.tv_sec * 1000LL - start.tv_usec/1000LL); + return endTime - startTime; } /* To cover for outliers, allow us to get the Average time based on a specified number of iterations */ @@ -831,7 +830,7 @@ TEST_F(KFDQMTest, QueuePriorityOnDifferentPipe) { }; int activeTaskBitmap = 0x3; - struct timeval start, end[2]; + HSAuint64 startTime, endTime[2]; HsaEvent *pHsaEvent[2]; int numEvent = 2; PM4Queue queue[2]; @@ -850,7 +849,7 @@ TEST_F(KFDQMTest, QueuePriorityOnDifferentPipe) { dispatch[i].SetDim(1024, 16, 16); } - gettimeofday(&start, NULL); + startTime = GetSystemTickCountInMicroSec(); for (i = 0; i < 2; i++) dispatch[i].Submit(queue[i]); @@ -858,7 +857,7 @@ TEST_F(KFDQMTest, QueuePriorityOnDifferentPipe) { hsaKmtWaitOnMultipleEvents(pHsaEvent, numEvent, false, g_TestTimeOut); for (i = 0; i < 2; i++) { if ((activeTaskBitmap & (1 << i)) && (syncBuffer[i] == pHsaEvent[i]->EventId)) { - gettimeofday(&end[i], NULL); + endTime[i] = GetSystemTickCountInMicroSec(); activeTaskBitmap &= ~(1 << i); } } @@ -866,9 +865,9 @@ TEST_F(KFDQMTest, QueuePriorityOnDifferentPipe) { for (i = 0; i < 2; i++) { EXPECT_SUCCESS(queue[i].Destroy()); - int ms = end[i].tv_sec *1000LL + end[i].tv_usec/1000LL - start.tv_sec * 1000LL - start.tv_usec/1000LL; + int usecs = endTime[i] - startTime; LOG() << "Task priority: " << std::dec << priority[i] << "\t"; - LOG() << "Task duration: " << std::dec << ms << "ms" << std::endl; + LOG() << "Task duration: " << std::dec << usecs << "usecs" << std::endl; } TEST_END @@ -896,7 +895,7 @@ TEST_F(KFDQMTest, QueuePriorityOnSamePipe) { }; int activeTaskBitmap = 0x3; - struct timeval start, end[2]; + HSAuint64 startTime, endTime[2]; HsaEvent *pHsaEvent[2]; int numEvent = 2; PM4Queue queue[13]; @@ -924,7 +923,7 @@ TEST_F(KFDQMTest, QueuePriorityOnSamePipe) { dispatch[i].SetDim(1024, 16, 16); } - gettimeofday(&start, NULL); + startTime = GetSystemTickCountInMicroSec(); for (i = 0; i < 2; i++) dispatch[i].Submit(queue[i]); @@ -932,16 +931,16 @@ TEST_F(KFDQMTest, QueuePriorityOnSamePipe) { hsaKmtWaitOnMultipleEvents(pHsaEvent, numEvent, false, g_TestTimeOut); for (i = 0; i < 2; i++) { if ((activeTaskBitmap & (1 << i)) && (syncBuffer[i] == pHsaEvent[i]->EventId)) { - gettimeofday(&end[i], NULL); + endTime[i] = GetSystemTickCountInMicroSec(); activeTaskBitmap &= ~(1 << i); } } } for (i = 0; i < 2; i++) { - int ms = end[i].tv_sec *1000LL + end[i].tv_usec/1000LL - start.tv_sec * 1000LL - start.tv_usec/1000LL; + int usecs = endTime[i] - startTime; LOG() << "Task priority: " << std::dec << priority[i] << "\t"; - LOG() << "Task duration: " << std::dec << ms << "ms" << std::endl; + LOG() << "Task duration: " << std::dec << usecs << "usecs" << std::endl; } for (i = 0; i <= 12; i++) { diff --git a/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.cpp b/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.cpp index d2914a7bc2..105cc00679 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.cpp +++ b/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.cpp @@ -24,6 +24,7 @@ #include "KFDTestUtil.hpp" #include +#include #include #include #include "BaseQueue.hpp" @@ -171,6 +172,12 @@ bool isTonga(const HsaNodeProperties *props) { return false; } +HSAuint64 GetSystemTickCountInMicroSec() { + struct timeval t; + gettimeofday(&t, 0); + return t.tv_sec * 1000000ULL + t.tv_usec; +} + const HsaMemoryBuffer HsaMemoryBuffer::Null; HsaMemoryBuffer::HsaMemoryBuffer(HSAuint64 size, unsigned int node, bool zero, bool isLocal, bool isExec, diff --git a/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.hpp b/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.hpp index 7e2fe7e16d..5fefff0516 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.hpp +++ b/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.hpp @@ -56,6 +56,8 @@ void GetSdmaInfo(const HsaNodeProperties *props, unsigned int *p_num_sdma_xgmi_engines, unsigned int *p_num_sdma_queues_per_engine); +HSAuint64 GetSystemTickCountInMicroSec(); + class HsaMemoryBuffer { public: static const HsaMemoryBuffer Null; diff --git a/projects/rocr-runtime/tests/kfdtest/src/LinuxOSWrapper.cpp b/projects/rocr-runtime/tests/kfdtest/src/LinuxOSWrapper.cpp index e529c2b6dd..f5308249bf 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/LinuxOSWrapper.cpp +++ b/projects/rocr-runtime/tests/kfdtest/src/LinuxOSWrapper.cpp @@ -39,7 +39,6 @@ #include #include #include -#include static int protection_flags[8] = {PROT_NONE, PROT_READ, PROT_WRITE, PROT_READ | PROT_WRITE, PROT_EXEC, PROT_EXEC | PROT_READ, PROT_EXEC | PROT_WRITE, @@ -80,12 +79,6 @@ bool MultiProcessTest(const char *testToRun, int numOfProcesses, int runsPerProc return false; } -HSAuint64 GetSystemTickCountInMicroSec() { - struct timeval t; - gettimeofday(&t, 0); - return t.tv_sec * 1000000ULL + t.tv_usec; -} - bool SuspendAndWakeUp() { printf("Please press any key after the system suspends....\n"); diff --git a/projects/rocr-runtime/tests/kfdtest/src/OSWrapper.hpp b/projects/rocr-runtime/tests/kfdtest/src/OSWrapper.hpp index 99a7ff5829..4ded18e0e0 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/OSWrapper.hpp +++ b/projects/rocr-runtime/tests/kfdtest/src/OSWrapper.hpp @@ -95,8 +95,6 @@ void MemoryBarrier(); */ bool MultiProcessTest(const char *testToRun, int numOfProcesses, int runsPerProcess = 1); -HSAuint64 GetSystemTickCountInMicroSec(); - /* Put the system to S3/S4 power state and bring it back to S0. * @return 'true' on success, 'false' on failure. */