From 2b0b2231a7cf9c48c20c62886889ea3c2628a045 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 1 Feb 2021 18:37:13 +0000 Subject: [PATCH] Windows: Use timestamp frequency from adapter info Related-To: NEO-5435 Signed-off-by: Mateusz Jablonski --- opencl/test/unit_test/device/device_win_timers_tests.cpp | 6 ++++-- opencl/test/unit_test/mocks/mock_wddm.h | 3 ++- shared/source/os_interface/windows/os_time_win.cpp | 8 +++----- shared/source/os_interface/windows/wddm/wddm.cpp | 1 + shared/source/os_interface/windows/wddm/wddm.h | 3 +++ shared/test/unit_test/mock_gdi/mock_gdi.cpp | 1 + shared/test/unit_test/os_interface/windows/wddm_tests.cpp | 8 +++++++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/opencl/test/unit_test/device/device_win_timers_tests.cpp b/opencl/test/unit_test/device/device_win_timers_tests.cpp index bc4c0f9fa4..c9b6b71ffc 100644 --- a/opencl/test/unit_test/device/device_win_timers_tests.cpp +++ b/opencl/test/unit_test/device/device_win_timers_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -30,11 +30,13 @@ TEST_F(MockOSTimeWinTest, WhenCreatingTimerThenResolutionIsSetCorrectly) { wddmMock->init(); + wddmMock->timestampFrequency = 1000; + std::unique_ptr timeWin(new MockOSTimeWin(wddmMock)); double res = 0.0; res = timeWin->getDynamicDeviceTimerResolution(device->getHardwareInfo()); - EXPECT_EQ(res, 1e+09); + EXPECT_EQ(res, 1e+06); } } // namespace ULT diff --git a/opencl/test/unit_test/mocks/mock_wddm.h b/opencl/test/unit_test/mocks/mock_wddm.h index 98fc3cebe5..9de18f715c 100644 --- a/opencl/test/unit_test/mocks/mock_wddm.h +++ b/opencl/test/unit_test/mocks/mock_wddm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -44,6 +44,7 @@ class WddmMock : public Wddm { using Wddm::residencyLogger; using Wddm::rootDeviceEnvironment; using Wddm::temporaryResources; + using Wddm::timestampFrequency; using Wddm::wddmInterface; WddmMock(std::unique_ptr hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::move(hwDeviceId), rootDeviceEnvironment) {} diff --git a/shared/source/os_interface/windows/os_time_win.cpp b/shared/source/os_interface/windows/os_time_win.cpp index 6b8e355527..fc1f524f57 100644 --- a/shared/source/os_interface/windows/os_time_win.cpp +++ b/shared/source/os_interface/windows/os_time_win.cpp @@ -99,11 +99,9 @@ double OSTimeWin::getHostTimerResolution() const { } double OSTimeWin::getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const { - double retVal = 0; - TimeStampDataHeader escapeInfo = {0}; - - if (runEscape(wddm, escapeInfo)) { - retVal = 1000000000.0 / (double)escapeInfo.m_Data.m_Out.gpuPerfFreq; + double retVal = 0u; + if (wddm) { + retVal = 1000000000.0 / static_cast(wddm->getTimestampFrequency()); } return retVal; diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index 2e8854080a..62159f0649 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -150,6 +150,7 @@ bool Wddm::queryAdapterInfo() { systemSharedMemory = adapterInfo.SystemSharedMemory; dedicatedVideoMemory = adapterInfo.DedicatedVideoMemory; maxRenderFrequency = adapterInfo.MaxRenderFreq; + timestampFrequency = adapterInfo.GfxTimeStampFreq; instrumentationEnabled = adapterInfo.Caps.InstrumentationIsEnabled != 0; } diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 7d48fb3f47..05bc27397d 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -161,6 +161,8 @@ class Wddm { const RootDeviceEnvironment &getRootDeviceEnvironment() const { return rootDeviceEnvironment; } + const uint32_t getTimestampFrequency() const { return timestampFrequency; } + protected: std::unique_ptr hwDeviceId; D3DKMT_HANDLE device = 0; @@ -180,6 +182,7 @@ class Wddm { uint64_t systemSharedMemory = 0; uint64_t dedicatedVideoMemory = 0; uint32_t maxRenderFrequency = 0; + uint32_t timestampFrequency = 0u; bool instrumentationEnabled = false; std::string deviceRegistryPath; RootDeviceEnvironment &rootDeviceEnvironment; diff --git a/shared/test/unit_test/mock_gdi/mock_gdi.cpp b/shared/test/unit_test/mock_gdi/mock_gdi.cpp index ad9c4d75a8..fbb9916dc8 100644 --- a/shared/test/unit_test/mock_gdi/mock_gdi.cpp +++ b/shared/test/unit_test/mock_gdi/mock_gdi.cpp @@ -291,6 +291,7 @@ NTSTATUS __stdcall D3DKMTQueryAdapterInfo(IN CONST D3DKMT_QUERYADAPTERINFO *quer adapterInfo->GfxMemorySize = 2181038080; adapterInfo->SystemSharedMemory = 4249540608; adapterInfo->SystemVideoMemory = 0; + adapterInfo->GfxTimeStampFreq = 1; adapterInfo->GfxPartition.Standard.Base = gAdapterInfo.GfxPartition.Standard.Base; adapterInfo->GfxPartition.Standard.Limit = gAdapterInfo.GfxPartition.Standard.Limit; diff --git a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp index fce4894944..4d030004a4 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -39,6 +39,12 @@ TEST_F(WddmTests, whenInitializingWddmThenSetMinAddressToCorrectValue) { ASSERT_EQ(expectedMinAddress, wddm->getWddmMinAddress()); } +TEST_F(WddmTests, whenInitializingWddmThenSetTimestampFrequencyToCorrectValue) { + EXPECT_EQ(0u, wddm->timestampFrequency); + init(); + EXPECT_EQ(1u, wddm->timestampFrequency); +} + TEST_F(WddmTests, givenWddmWhenPassesCorrectHandleToVerifySharedHandleThenReturnTrue) { init(); D3DKMT_HANDLE handle = 1u;