From 1dc4afe8ab71bc6b8ddf806a5246a1bf6cef742b Mon Sep 17 00:00:00 2001 From: Kamil Kopryk Date: Sun, 1 Jan 2023 18:02:40 +0000 Subject: [PATCH] Refactor: pass gfxCoreHelper to convertTimestampsFromOaToCsDomain Related-To: NEO-6853 Signed-off-by: Kamil Kopryk --- .../device_time_gpu_cpu_drm_or_wddm.cpp | 6 +++--- .../windows/device_time_gpu_cpu_wddm.cpp | 6 +++--- .../os_interface/windows/device_time_wddm.cpp | 6 +++--- .../os_interface/windows/device_time_wddm.h | 5 +++-- shared/test/common/mocks/mock_ostime_win.h | 6 +++--- .../windows/neo_device_windows_tests.cpp | 19 ++++++++++--------- 6 files changed, 25 insertions(+), 23 deletions(-) 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 index 00380c4875..349a65df51 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { TimeStampDataHeader escapeInfo = {}; if (runEscape(wddm, escapeInfo)) { - auto hwInfo = wddm->getRootDeviceEnvironment().getHardwareInfo(); - convertTimestampsFromOaToCsDomain(*hwInfo, escapeInfo.m_Data.m_Out.gpuPerfTicks, escapeInfo.m_Data.m_Out.gpuPerfFreq, static_cast(wddm->getTimestampFrequency())); + auto &gfxCoreHelper = wddm->getRootDeviceEnvironment().getHelper(); + convertTimestampsFromOaToCsDomain(gfxCoreHelper, escapeInfo.m_Data.m_Out.gpuPerfTicks, escapeInfo.m_Data.m_Out.gpuPerfFreq, static_cast(wddm->getTimestampFrequency())); osTime->getCpuTime(&pGpuCpuTime->CPUTimeinNS); pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks; 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 index 2924a1d7c5..74253ec521 100644 --- a/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp +++ b/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { TimeStampDataHeader escapeInfo = {}; if (runEscape(wddm, escapeInfo)) { - auto hwInfo = wddm->getRootDeviceEnvironment().getHardwareInfo(); - convertTimestampsFromOaToCsDomain(*hwInfo, escapeInfo.m_Data.m_Out.gpuPerfTicks, escapeInfo.m_Data.m_Out.gpuPerfFreq, static_cast(wddm->getTimestampFrequency())); + auto &gfxCoreHelper = wddm->getRootDeviceEnvironment().getHelper(); + convertTimestampsFromOaToCsDomain(gfxCoreHelper, escapeInfo.m_Data.m_Out.gpuPerfTicks, escapeInfo.m_Data.m_Out.gpuPerfFreq, static_cast(wddm->getTimestampFrequency())); double cpuNanoseconds = escapeInfo.m_Data.m_Out.cpuPerfTicks * (1000000000.0 / escapeInfo.m_Data.m_Out.cpuPerfFreq); diff --git a/shared/source/os_interface/windows/device_time_wddm.cpp b/shared/source/os_interface/windows/device_time_wddm.cpp index 89a373316c..fd3a4cff24 100644 --- a/shared/source/os_interface/windows/device_time_wddm.cpp +++ b/shared/source/os_interface/windows/device_time_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -71,8 +71,8 @@ uint64_t DeviceTimeWddm::getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) return retVal; } -void DeviceTimeWddm::convertTimestampsFromOaToCsDomain(HardwareInfo const &hwInfo, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS) { - auto &gfxCoreHelper = GfxCoreHelper::get(hwInfo.platform.eRenderCoreFamily); +void DeviceTimeWddm::convertTimestampsFromOaToCsDomain(const GfxCoreHelper &gfxCoreHelper, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS) { + if (gfxCoreHelper.isTimestampShiftRequired() && freqCS > 0 && freqOA > 0) { auto freqRatio = static_cast(freqOA) / static_cast(freqCS); timestampData = static_cast(timestampData / freqRatio); diff --git a/shared/source/os_interface/windows/device_time_wddm.h b/shared/source/os_interface/windows/device_time_wddm.h index af916c9ae2..d685b2e284 100644 --- a/shared/source/os_interface/windows/device_time_wddm.h +++ b/shared/source/os_interface/windows/device_time_wddm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,6 +13,7 @@ namespace NEO { class Wddm; +class GfxCoreHelper; struct TimeStampDataHeader; class DeviceTimeWddm : public DeviceTime { @@ -24,7 +25,7 @@ class DeviceTimeWddm : public DeviceTime { protected: MOCKABLE_VIRTUAL bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo); - void convertTimestampsFromOaToCsDomain(HardwareInfo const &hwInfo, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS); + void convertTimestampsFromOaToCsDomain(const GfxCoreHelper &gfxCoreHelper, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS); Wddm *wddm = nullptr; }; diff --git a/shared/test/common/mocks/mock_ostime_win.h b/shared/test/common/mocks/mock_ostime_win.h index 916bcb6242..54996b7268 100644 --- a/shared/test/common/mocks/mock_ostime_win.h +++ b/shared/test/common/mocks/mock_ostime_win.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,8 +18,8 @@ class MockOSTimeWin : public OSTimeWin { MockOSTimeWin(Wddm *wddm) { this->deviceTime = std::make_unique(wddm); } - void convertTimestampsFromOaToCsDomain(HardwareInfo const &hwInfo, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS) { - static_cast(this->deviceTime.get())->convertTimestampsFromOaToCsDomain(hwInfo, timestampData, freqOA, freqCS); + void convertTimestampsFromOaToCsDomain(const GfxCoreHelper &gfxCoreHelper, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS) { + static_cast(this->deviceTime.get())->convertTimestampsFromOaToCsDomain(gfxCoreHelper, timestampData, freqOA, freqCS); } }; } // namespace NEO diff --git a/shared/test/unit_test/device/windows/neo_device_windows_tests.cpp b/shared/test/unit_test/device/windows/neo_device_windows_tests.cpp index 5dad8ec21b..8af421d860 100644 --- a/shared/test/unit_test/device/windows/neo_device_windows_tests.cpp +++ b/shared/test/unit_test/device/windows/neo_device_windows_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -95,47 +95,48 @@ HWTEST_F(MockOSTimeWinTest, whenConvertingTimestampsToCsDomainThenTimestampDataA wddmMock->init(); auto hwInfo = wddmMock->getRootDeviceEnvironment().getHardwareInfo(); RAIIGfxCoreHelperFactory> gfxCoreHelperBackup{hwInfo->platform.eRenderCoreFamily}; + auto &gfxCoreHelper = gfxCoreHelperBackup.mockGfxCoreHelper; std::unique_ptr timeWin(new MockOSTimeWin(wddmMock)); uint64_t timestampData = 0x1234; uint64_t freqOA = 5; uint64_t freqCS = 2; double ratio = static_cast(freqOA) / static_cast(freqCS); auto expectedGpuTicksWhenOAfreqBiggerThanCSfreq = static_cast(timestampData / ratio); - timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + timeWin->convertTimestampsFromOaToCsDomain(gfxCoreHelper, timestampData, freqOA, freqCS); EXPECT_EQ(expectedGpuTicksWhenOAfreqBiggerThanCSfreq, timestampData); freqOA = 2; freqCS = 5; ratio = static_cast(freqCS) / static_cast(freqOA); auto expectedGpuTicksWhenCSfreqBiggerThanOAfreq = static_cast(timestampData * ratio); - timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + timeWin->convertTimestampsFromOaToCsDomain(gfxCoreHelper, timestampData, freqOA, freqCS); EXPECT_EQ(expectedGpuTicksWhenCSfreqBiggerThanOAfreq, timestampData); freqOA = 1; freqCS = 0; auto expectedGpuTicksWhenNotChange = timestampData; - timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + timeWin->convertTimestampsFromOaToCsDomain(gfxCoreHelper, timestampData, freqOA, freqCS); EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); freqOA = 1; freqCS = 1; - timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + timeWin->convertTimestampsFromOaToCsDomain(gfxCoreHelper, timestampData, freqOA, freqCS); EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); freqOA = 0; freqCS = 1; - timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + timeWin->convertTimestampsFromOaToCsDomain(gfxCoreHelper, timestampData, freqOA, freqCS); EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); gfxCoreHelperBackup.mockGfxCoreHelper.shiftRequired = false; freqOA = 1; freqCS = 0; expectedGpuTicksWhenNotChange = timestampData; - timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + timeWin->convertTimestampsFromOaToCsDomain(gfxCoreHelper, timestampData, freqOA, freqCS); EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); freqOA = 0; freqCS = 1; - timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + timeWin->convertTimestampsFromOaToCsDomain(gfxCoreHelper, timestampData, freqOA, freqCS); EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); freqOA = 2; freqCS = 1; - timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + timeWin->convertTimestampsFromOaToCsDomain(gfxCoreHelper, timestampData, freqOA, freqCS); EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); }