diff --git a/runtime/os_interface/linux/os_time_linux.cpp b/runtime/os_interface/linux/os_time_linux.cpp index bf0842bfd2..8665a082c5 100644 --- a/runtime/os_interface/linux/os_time_linux.cpp +++ b/runtime/os_interface/linux/os_time_linux.cpp @@ -125,6 +125,9 @@ bool OSTimeLinux::getGpuTimeSplitted(uint64_t *timestamp) { } bool OSTimeLinux::getCpuGpuTime(TimeStampData *pGpuCpuTime) { + if (nullptr == this->getGpuTime) { + return false; + } if (!(this->*getGpuTime)(&pGpuCpuTime->GPUTimeStamp)) { return false; } diff --git a/runtime/os_interface/linux/os_time_linux.h b/runtime/os_interface/linux/os_time_linux.h index e03ce20164..d5193e457c 100644 --- a/runtime/os_interface/linux/os_time_linux.h +++ b/runtime/os_interface/linux/os_time_linux.h @@ -38,7 +38,7 @@ class OSTimeLinux : public OSTime { bool getCpuGpuTime(TimeStampData *pGpuCpuTime) override; typedef bool (OSTimeLinux::*TimestampFunction)(uint64_t *); void timestampTypeDetect(); - TimestampFunction getGpuTime; + TimestampFunction getGpuTime = nullptr; bool getGpuTime32(uint64_t *timestamp); bool getGpuTime36(uint64_t *timestamp); bool getGpuTimeSplitted(uint64_t *timestamp); diff --git a/unit_tests/os_interface/linux/os_time_test.cpp b/unit_tests/os_interface/linux/os_time_test.cpp index 3a3c4ee65f..91f3fdebdc 100644 --- a/unit_tests/os_interface/linux/os_time_test.cpp +++ b/unit_tests/os_interface/linux/os_time_test.cpp @@ -148,6 +148,12 @@ TEST_F(DrmTimeTest, GIVENDrmWHENGetCpuGpuTimeTHENPassed) { delete pDrm; } +TEST_F(DrmTimeTest, givenGetCpuGpuTimeWhenItIsUnavailableThenReturnFalse) { + TimeStampData CPUGPUTime = {0, 0}; + auto error = osTime->getCpuGpuTime(&CPUGPUTime); + EXPECT_FALSE(error); +} + TEST_F(DrmTimeTest, GetCpuGpuTimeFails) { TimeStampData CPUGPUTime01 = {0, 0}; auto pDrm = new DrmMockFail();