diff --git a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp index 7684fdfd22..e6b69908bb 100644 --- a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -17,6 +17,7 @@ #include "shared/source/os_interface/device_factory.h" #include "shared/source/os_interface/driver_info.h" #include "shared/source/os_interface/os_interface.h" +#include "shared/source/os_interface/os_time.h" #include "shared/source/source_level_debugger/source_level_debugger.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_device.h" @@ -126,6 +127,32 @@ TEST(RootDeviceEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCa EXPECT_STREQ(rootDeviceEnvironment->aubFileNameReceived.c_str(), "test.aub"); } +TEST(RootDeviceEnvironment, whenCreatingRootDeviceEnvironmentThenCreateOsAgnosticOsTime) { + MockExecutionEnvironment executionEnvironment; + executionEnvironment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get()); + auto profilingTimerResolution = defaultHwInfo->capabilityTable.defaultProfilingTimerResolution; + + auto rootDeviceEnvironment = static_cast(executionEnvironment.rootDeviceEnvironments[0].get()); + + EXPECT_EQ(nullptr, rootDeviceEnvironment->osTime.get()); + rootDeviceEnvironment->initOsTime(); + + uint64_t ts = 123; + EXPECT_TRUE(rootDeviceEnvironment->osTime->getCpuTime(&ts)); + EXPECT_EQ(0u, ts); + + EXPECT_EQ(0u, rootDeviceEnvironment->osTime->getHostTimerResolution()); + EXPECT_EQ(0u, rootDeviceEnvironment->osTime->getCpuRawTimestamp()); + + TimeStampData tsData{1, 2}; + EXPECT_TRUE(rootDeviceEnvironment->osTime->getCpuGpuTime(&tsData)); + EXPECT_EQ(0u, tsData.CPUTimeinNS); + EXPECT_EQ(0u, tsData.GPUTimeStamp); + + EXPECT_EQ(profilingTimerResolution, rootDeviceEnvironment->osTime->getDynamicDeviceTimerResolution(*defaultHwInfo)); + EXPECT_EQ(static_cast(1000000000.0 / OSTime::getDeviceTimerResolution(*defaultHwInfo)), rootDeviceEnvironment->osTime->getDynamicDeviceTimerClock(*defaultHwInfo)); +} + TEST(RootDeviceEnvironment, givenUseAubStreamFalseWhenGetAubManagerIsCalledThenReturnNull) { DebugManagerStateRestore dbgRestore; DebugManager.flags.UseAubStream.set(false); diff --git a/shared/source/os_interface/create_os_time_drm.cpp b/shared/source/os_interface/create_os_time_drm.cpp index 13a994427d..ac4dab8e2a 100644 --- a/shared/source/os_interface/create_os_time_drm.cpp +++ b/shared/source/os_interface/create_os_time_drm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Intel Corporation + * Copyright (C) 2021-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -12,7 +12,11 @@ namespace NEO { std::unique_ptr OSTime::create(OSInterface *osInterface) { - return OSTimeLinux::create(osInterface, std::make_unique(osInterface)); + if (osInterface) { + return OSTimeLinux::create(osInterface, std::make_unique(osInterface)); + } + + return std::make_unique(std::make_unique()); } } // namespace NEO diff --git a/shared/source/os_interface/create_os_time_drm_or_wddm.cpp b/shared/source/os_interface/create_os_time_drm_or_wddm.cpp index 2df2939dc3..88c2f4bb78 100644 --- a/shared/source/os_interface/create_os_time_drm_or_wddm.cpp +++ b/shared/source/os_interface/create_os_time_drm_or_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Intel Corporation + * Copyright (C) 2021-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,7 +14,9 @@ namespace NEO { std::unique_ptr OSTime::create(OSInterface *osInterface) { - if ((nullptr == osInterface) || (osInterface->getDriverModel()->getDriverModelType() == DriverModelType::DRM)) { + if (nullptr == osInterface) { + return std::make_unique(std::make_unique()); + } else if (osInterface->getDriverModel()->getDriverModelType() == DriverModelType::DRM) { return OSTimeLinux::create(osInterface, std::make_unique(osInterface)); } else { auto wddm = osInterface->getDriverModel()->as(); diff --git a/shared/source/os_interface/create_os_time_wddm.cpp b/shared/source/os_interface/create_os_time_wddm.cpp index 6298f93ca3..c72290d323 100644 --- a/shared/source/os_interface/create_os_time_wddm.cpp +++ b/shared/source/os_interface/create_os_time_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Intel Corporation + * Copyright (C) 2021-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,7 +11,11 @@ namespace NEO { std::unique_ptr OSTime::create(OSInterface *osInterface) { - return OSTimeWin::create(osInterface); + if (osInterface) { + return OSTimeWin::create(osInterface); + } + + return std::make_unique(std::make_unique()); } } // namespace NEO diff --git a/shared/source/os_interface/os_time.cpp b/shared/source/os_interface/os_time.cpp index 4543fae52c..6c1d980870 100644 --- a/shared/source/os_interface/os_time.cpp +++ b/shared/source/os_interface/os_time.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,4 +14,35 @@ namespace NEO { double OSTime::getDeviceTimerResolution(HardwareInfo const &hwInfo) { return hwInfo.capabilityTable.defaultProfilingTimerResolution; }; + +bool DeviceTime::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { + pGpuCpuTime->CPUTimeinNS = 0; + pGpuCpuTime->GPUTimeStamp = 0; + + return true; +} +double DeviceTime::getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const { + return OSTime::getDeviceTimerResolution(hwInfo); +} + +uint64_t DeviceTime::getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const { + return static_cast(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo)); +} + +bool OSTime::getCpuTime(uint64_t *timeStamp) { + *timeStamp = 0; + return true; +} + +double OSTime::getHostTimerResolution() const { + return 0; +} + +uint64_t OSTime::getCpuRawTimestamp() { + return 0; +} + +OSTime::OSTime(std::unique_ptr deviceTime) { + this->deviceTime = std::move(deviceTime); +} } // namespace NEO diff --git a/shared/source/os_interface/os_time.h b/shared/source/os_interface/os_time.h index 08f87d00b3..4d2856b116 100644 --- a/shared/source/os_interface/os_time.h +++ b/shared/source/os_interface/os_time.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -25,19 +25,20 @@ class OSTime; class DeviceTime { public: virtual ~DeviceTime() = default; - virtual bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) = 0; - virtual double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const = 0; - virtual uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const = 0; + virtual bool getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime); + virtual double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const; + virtual uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const; }; class OSTime { public: static std::unique_ptr create(OSInterface *osInterface); + OSTime(std::unique_ptr deviceTime); virtual ~OSTime() = default; - virtual bool getCpuTime(uint64_t *timeStamp) = 0; - virtual double getHostTimerResolution() const = 0; - virtual uint64_t getCpuRawTimestamp() = 0; + virtual bool getCpuTime(uint64_t *timeStamp); + virtual double getHostTimerResolution() const; + virtual uint64_t getCpuRawTimestamp(); OSInterface *getOSInterface() const { return osInterface; } @@ -56,7 +57,7 @@ class OSTime { } protected: - OSTime() {} + OSTime() = default; OSInterface *osInterface = nullptr; std::unique_ptr deviceTime; }; diff --git a/shared/test/unit_test/os_interface/windows/os_time_win_tests.cpp b/shared/test/unit_test/os_interface/windows/os_time_win_tests.cpp index 2ab3345503..f3e5435771 100644 --- a/shared/test/unit_test/os_interface/windows/os_time_win_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/os_time_win_tests.cpp @@ -74,14 +74,14 @@ TEST(OSTimeWinTests, givenNoOSInterfaceWhenGetCpuTimeThenReturnsSuccess) { auto osTime(OSTime::create(nullptr)); auto error = osTime->getCpuTime(&time); EXPECT_TRUE(error); - EXPECT_NE(0u, time); + EXPECT_EQ(0u, time); } -TEST(OSTimeWinTests, givenNoOSInterfaceWhenGetCpuGpuTimeThenReturnsError) { +TEST(OSTimeWinTests, givenNoOSInterfaceWhenGetCpuGpuTimeThenReturnsSuccess) { TimeStampData CPUGPUTime = {0}; auto osTime(OSTime::create(nullptr)); auto success = osTime->getCpuGpuTime(&CPUGPUTime); - EXPECT_FALSE(success); + EXPECT_TRUE(success); EXPECT_EQ(0u, CPUGPUTime.CPUTimeinNS); EXPECT_EQ(0u, CPUGPUTime.GPUTimeStamp); }