diff --git a/shared/source/os_interface/windows/CMakeLists.txt b/shared/source/os_interface/windows/CMakeLists.txt index db4bd5b17d..fbe4f2d995 100644 --- a/shared/source/os_interface/windows/CMakeLists.txt +++ b/shared/source/os_interface/windows/CMakeLists.txt @@ -49,6 +49,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM ${CMAKE_CURRENT_SOURCE_DIR}/dxgi_wrapper.h ${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion_win.h + ${CMAKE_CURRENT_SOURCE_DIR}/device_time_gpu_cpu_${DRIVER_MODEL}.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_time_wddm.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_time_wddm.h ${CMAKE_CURRENT_SOURCE_DIR}/driver_info_windows.h diff --git a/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp b/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp new file mode 100644 index 0000000000..64dbde68dc --- /dev/null +++ b/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2017-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/os_interface/hw_info_config.h" +#include "shared/source/os_interface/os_time.h" +#include "shared/source/os_interface/windows/device_time_wddm.h" +#include "shared/source/os_interface/windows/wddm/wddm.h" + +namespace NEO { +bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { + bool retVal = false; + + pGpuCpuTime->CPUTimeinNS = 0; + pGpuCpuTime->GPUTimeStamp = 0; + + TimeStampDataHeader escapeInfo = {}; + + if (runEscape(wddm, escapeInfo)) { + auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily; + auto *hwInfoConfig = HwInfoConfig::get(productFamily); + hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks); + + osTime->getCpuTime(&pGpuCpuTime->CPUTimeinNS); + pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks; + retVal = true; + } + + return retVal; +} +} // namespace NEO \ No newline at end of file diff --git a/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp b/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp new file mode 100644 index 0000000000..6cd14fea10 --- /dev/null +++ b/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2017-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/os_interface/hw_info_config.h" +#include "shared/source/os_interface/os_time.h" +#include "shared/source/os_interface/windows/device_time_wddm.h" +#include "shared/source/os_interface/windows/wddm/wddm.h" + +namespace NEO { +bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { + bool retVal = false; + + pGpuCpuTime->CPUTimeinNS = 0; + pGpuCpuTime->GPUTimeStamp = 0; + + TimeStampDataHeader escapeInfo = {}; + + if (runEscape(wddm, escapeInfo)) { + auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily; + auto *hwInfoConfig = HwInfoConfig::get(productFamily); + hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks); + double cpuNanoseconds = escapeInfo.m_Data.m_Out.cpuPerfTicks * + (1000000000.0 / escapeInfo.m_Data.m_Out.cpuPerfFreq); + + pGpuCpuTime->CPUTimeinNS = (unsigned long long)cpuNanoseconds; + pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks; + retVal = true; + } + + return retVal; +} +} // namespace NEO \ No newline at end of file diff --git a/shared/source/os_interface/windows/device_time_wddm.cpp b/shared/source/os_interface/windows/device_time_wddm.cpp index 07d02744ed..7027e2c5d4 100644 --- a/shared/source/os_interface/windows/device_time_wddm.cpp +++ b/shared/source/os_interface/windows/device_time_wddm.cpp @@ -19,7 +19,7 @@ namespace NEO { -bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) { +bool DeviceTimeWddm::runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) { if (wddm) { D3DKMT_ESCAPE escapeCommand = {0}; @@ -48,29 +48,6 @@ bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) { return false; } -bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { - bool retVal = false; - - pGpuCpuTime->CPUTimeinNS = 0; - pGpuCpuTime->GPUTimeStamp = 0; - - TimeStampDataHeader escapeInfo = {}; - - if (runEscape(wddm, escapeInfo)) { - auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily; - auto *hwInfoConfig = HwInfoConfig::get(productFamily); - hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks); - double cpuNanoseconds = escapeInfo.m_Data.m_Out.cpuPerfTicks * - (1000000000.0 / escapeInfo.m_Data.m_Out.cpuPerfFreq); - - pGpuCpuTime->CPUTimeinNS = (unsigned long long)cpuNanoseconds; - pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks; - retVal = true; - } - - return retVal; -} - DeviceTimeWddm::DeviceTimeWddm(Wddm *wddm) { this->wddm = wddm; } diff --git a/shared/source/os_interface/windows/device_time_wddm.h b/shared/source/os_interface/windows/device_time_wddm.h index 33ca111f88..f2a7952a52 100644 --- a/shared/source/os_interface/windows/device_time_wddm.h +++ b/shared/source/os_interface/windows/device_time_wddm.h @@ -13,6 +13,7 @@ namespace NEO { class Wddm; +struct TimeStampDataHeader; class DeviceTimeWddm : public DeviceTime { public: @@ -22,6 +23,7 @@ class DeviceTimeWddm : public DeviceTime { uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override; protected: + MOCKABLE_VIRTUAL bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo); Wddm *wddm = nullptr; }; diff --git a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp index ffbe26521d..3247ee87b8 100644 --- a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp +++ b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp @@ -6,6 +6,10 @@ */ #include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/os_interface/linux/os_time_linux.h" +#include "shared/source/os_interface/os_interface.h" +#include "shared/source/os_interface/os_time.h" +#include "shared/source/os_interface/windows/device_time_wddm.h" #include "shared/source/os_interface/windows/gdi_interface.h" #include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/wddm/wddm.h" @@ -203,3 +207,46 @@ TEST(WddmLinux, givenRequestFor32bitAllocationWithoutPreexistingHostPtrWhenAlloc EXPECT_EQ(0U, receivedMapGpuVirtualAddressArgs.BaseAddress); EXPECT_EQ(mockAllocationHandle, receivedLock2Args.hAllocation); } +class MockOsTimeLinux : public NEO::OSTimeLinux { + public: + MockOsTimeLinux(NEO::OSInterface *osInterface, std::unique_ptr deviceTime) : NEO::OSTimeLinux(osInterface, std::move(deviceTime)) {} + bool getCpuTime(uint64_t *timeStamp) override { + osTimeGetCpuTimeWasCalled = true; + *timeStamp = 0x1234; + return true; + } + bool osTimeGetCpuTimeWasCalled = false; +}; + +class MockDeviceTimeWddm : public NEO::DeviceTimeWddm { + public: + MockDeviceTimeWddm(NEO::Wddm *wddm) : NEO::DeviceTimeWddm(wddm) {} + bool runEscape(NEO::Wddm *wddm, NEO::TimeStampDataHeader &escapeInfo) override { + return true; + } +}; + +TEST(OSTimeWinLinuxTests, givenOSInterfaceWhenGetCpuGpuTimeThenGetCpuTimeFromOsTimeWasCalled) { + + NEO::TimeStampData CPUGPUTime01 = {0}; + + std::unique_ptr hwDeviceIdIn; + auto osEnvironment = std::make_unique(); + osEnvironment->gdi->closeAdapter = closeAdapterMock; + osEnvironment->gdi->reserveGpuVirtualAddress = reserveDeviceAddressSpaceMock; + NEO::MockExecutionEnvironment mockExecEnv; + NEO::MockRootDeviceEnvironment mockRootDeviceEnvironment{mockExecEnv}; + hwDeviceIdIn.reset(new NEO::HwDeviceIdWddm(NULL_HANDLE, LUID{}, osEnvironment.get(), std::make_unique())); + + std::unique_ptr osInterface(new NEO::OSInterface()); + + std::unique_ptr wddm = std::make_unique(std::move(hwDeviceIdIn), mockRootDeviceEnvironment); + *wddm->gfxPlatform = NEO::defaultHwInfo->platform; + mockRootDeviceEnvironment.setHwInfo(NEO::defaultHwInfo.get()); + auto mockDeviceTimeWddm = std::make_unique(wddm.get()); + osInterface->setDriverModel(std::move(wddm)); + std::unique_ptr deviceTime = std::unique_ptr(mockDeviceTimeWddm.release()); + auto osTime = std::unique_ptr(new MockOsTimeLinux(osInterface.get(), std::move(deviceTime))); + osTime->getCpuGpuTime(&CPUGPUTime01); + EXPECT_TRUE(osTime->osTimeGetCpuTimeWasCalled); +}