From 625e7e0d87e3df7a0eb5dae88452092366c8f85b Mon Sep 17 00:00:00 2001 From: Szymon Morek Date: Wed, 9 Oct 2024 18:36:11 +0000 Subject: [PATCH] fix: Override timestamp width from KMD Signed-off-by: Szymon Morek Source: 7f2b806 --- .../debug_settings/debug_variables_base.inl | 1 + .../root_device_environment.cpp | 1 + shared/source/helpers/gfx_core_helper.h | 4 +++ .../source/helpers/gfx_core_helper_base.inl | 8 +++++ .../os_interface/linux/xe/ioctl_helper_xe.cpp | 3 ++ shared/source/os_interface/os_time.h | 9 ++++++ .../gfx_core_helper_xe2_hpg_core.cpp | 8 +++++ shared/test/common/test_files/igdrcl.config | 1 + .../helpers/gfx_core_helper_tests.cpp | 10 +++++++ .../linux/xe/ioctl_helper_xe_tests.cpp | 29 +++++++++++++++++++ .../bmg/gfx_core_helper_tests_bmg.cpp | 11 +++++++ .../xe2_hpg_core/excludes_xe2_hpg_core.cpp | 1 + .../lnl/gfx_core_helper_tests_lnl.cpp | 11 +++++++ 13 files changed, 97 insertions(+) diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index ce3cd48b24496..027527820ca7e 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -292,6 +292,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, StandaloneInOrderTimestampAllocationEnabled, -1, DECLARE_DEBUG_VARIABLE(int32_t, ForceComputeWalkerPostSyncFlushWithWrite, -1, "-1: ignore. >=0: Force PostSync cache flush and override postSync immediate write address to given value") DECLARE_DEBUG_VARIABLE(int32_t, DeferStateInitSubmissionToFirstRegularUsage, -1, "-1: ignore, 0: disabled, 1: enabled. If set, instead of initializing at Device creation, submit initial state during first usage (eg. kernel submission)") DECLARE_DEBUG_VARIABLE(int32_t, ForceNonWalkerSplitMemoryCopy, -1, "-1: default, 0: disabled, 1: enabled. If set, memory copy will be executed as single byte copy Walker without performance optimizations") +DECLARE_DEBUG_VARIABLE(int32_t, OverrideTimestampWidth, -1, "-1: default from KMD, > 0: Override timestamp width used for profiling. Requires XeKMD kernel.") /*LOGGING FLAGS*/ DECLARE_DEBUG_VARIABLE(int32_t, PrintDriverDiagnostics, -1, "prints driver diagnostics messages to standard output, value corresponds to hint level") diff --git a/shared/source/execution_environment/root_device_environment.cpp b/shared/source/execution_environment/root_device_environment.cpp index 28f3a80744db4..eb0b5a04eb357 100644 --- a/shared/source/execution_environment/root_device_environment.cpp +++ b/shared/source/execution_environment/root_device_environment.cpp @@ -128,6 +128,7 @@ void RootDeviceEnvironment::initOsTime() { if (!osTime) { osTime = OSTime::create(osInterface.get()); osTime->setDeviceTimerResolution(*hwInfo); + osTime->setDeviceTimestampWidth(gfxCoreHelper->getDeviceTimestampWidth()); } } diff --git a/shared/source/helpers/gfx_core_helper.h b/shared/source/helpers/gfx_core_helper.h index c669f958b0b3b..d1e41640e8b99 100644 --- a/shared/source/helpers/gfx_core_helper.h +++ b/shared/source/helpers/gfx_core_helper.h @@ -200,6 +200,8 @@ class GfxCoreHelper { virtual bool usmCompressionSupported(const NEO::HardwareInfo &hwInfo) const = 0; + virtual uint32_t getDeviceTimestampWidth() const = 0; + virtual ~GfxCoreHelper() = default; protected: @@ -436,6 +438,8 @@ class GfxCoreHelperHw : public GfxCoreHelper { bool usmCompressionSupported(const NEO::HardwareInfo &hwInfo) const override; + uint32_t getDeviceTimestampWidth() const override; + ~GfxCoreHelperHw() override = default; protected: diff --git a/shared/source/helpers/gfx_core_helper_base.inl b/shared/source/helpers/gfx_core_helper_base.inl index 9bd2b8b47238f..d0eec8bc5dada 100644 --- a/shared/source/helpers/gfx_core_helper_base.inl +++ b/shared/source/helpers/gfx_core_helper_base.inl @@ -801,6 +801,14 @@ bool GfxCoreHelperHw::usmCompressionSupported(const NEO::HardwareInfo return false; } +template +uint32_t GfxCoreHelperHw::getDeviceTimestampWidth() const { + if (debugManager.flags.OverrideTimestampWidth.get() != -1) { + return debugManager.flags.OverrideTimestampWidth.get(); + } + return 0u; +} + template uint32_t GfxCoreHelperHw::getInternalCopyEngineIndex(const HardwareInfo &hwInfo) const { if (debugManager.flags.ForceBCSForInternalCopyEngine.get() != -1) { diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index 82425dce0feb8..19bceb727c06a 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -429,6 +429,9 @@ bool IoctlHelperXe::setGpuCpuTimes(TimeStampData *pGpuCpuTime, OSTime *osTime) { ret = IoctlHelper::ioctl(DrmIoctl::query, &deviceQuery); auto nValidBits = queryEngineCycles->width; + if (osTime->getDeviceTimestampWidth() != 0) { + nValidBits = osTime->getDeviceTimestampWidth(); + } auto gpuTimestampValidBits = maxNBitValue(nValidBits); auto gpuCycles = queryEngineCycles->engine_cycles & gpuTimestampValidBits; diff --git a/shared/source/os_interface/os_time.h b/shared/source/os_interface/os_time.h index 762ce5f40cba1..69493e844d240 100644 --- a/shared/source/os_interface/os_time.h +++ b/shared/source/os_interface/os_time.h @@ -86,6 +86,14 @@ class OSTime { deviceTime->setDeviceTimerResolution(hwInfo); } + void setDeviceTimestampWidth(uint32_t timestampWidth) { + this->timestampWidth = timestampWidth; + } + + uint32_t getDeviceTimestampWidth() const { + return this->timestampWidth; + } + void setRefreshTimestampsFlag() const { deviceTime->setRefreshTimestampsFlag(); } @@ -99,5 +107,6 @@ class OSTime { OSInterface *osInterface = nullptr; std::unique_ptr deviceTime; uint64_t maxGpuTimeStamp = 0; + uint32_t timestampWidth = 0; }; } // namespace NEO diff --git a/shared/source/xe2_hpg_core/gfx_core_helper_xe2_hpg_core.cpp b/shared/source/xe2_hpg_core/gfx_core_helper_xe2_hpg_core.cpp index cd5011a688a93..7156aaccae0ec 100644 --- a/shared/source/xe2_hpg_core/gfx_core_helper_xe2_hpg_core.cpp +++ b/shared/source/xe2_hpg_core/gfx_core_helper_xe2_hpg_core.cpp @@ -332,6 +332,14 @@ uint32_t GfxCoreHelperHw::getMetricsLibraryGenId() const { return static_cast(MetricsLibraryApi::ClientGen::Xe2HPG); } +template <> +uint32_t GfxCoreHelperHw::getDeviceTimestampWidth() const { + if (debugManager.flags.OverrideTimestampWidth.get() != -1) { + return debugManager.flags.OverrideTimestampWidth.get(); + } + return 64u; +}; + } // namespace NEO namespace NEO { diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 437676f716496..40143274beea0 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -626,4 +626,5 @@ DirectSubmissionPrintSemaphoreUsage = -1 ForceNonCoherentModeForTimestamps = 0 ExperimentalUSMAllocationReuseVersion = -1 ForceNonWalkerSplitMemoryCopy = -1 +OverrideTimestampWidth = -1 # Please don't edit below this line diff --git a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp index a539aefb0bd24..25f88e9ec5131 100644 --- a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp +++ b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp @@ -1856,3 +1856,13 @@ HWTEST_F(GfxCoreHelperTest, whenEncodeAdditionalTimestampOffsetsThenNothingEncod GenCmdList storeRegMemList = hwParser.getCommandsList(); EXPECT_EQ(0u, storeRegMemList.size()); } + +HWTEST_F(GfxCoreHelperTest, givenGetDeviceTimestampWidthCalledThenReturnCorrectValue) { + DebugManagerStateRestore restore; + + auto &helper = getHelper(); + EXPECT_EQ(0u, helper.getDeviceTimestampWidth()); + + debugManager.flags.OverrideTimestampWidth.set(64); + EXPECT_EQ(64u, helper.getDeviceTimestampWidth()); +} diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp index 4a944f25603ab..f060e16d60ed7 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp @@ -1793,6 +1793,35 @@ TEST(IoctlHelperXeTest, givenIoctlFailureWhenSetGpuCpuTimesIsCalledThenProperVal EXPECT_EQ(pGpuCpuTime.cpuTimeinNS, expectedTimestamp); } +TEST(IoctlHelperXeTest, whenDeviceTimestampWidthSetThenProperValuesAreSet) { + DebugManagerStateRestore restorer; + auto executionEnvironment = std::make_unique(); + auto &rootDeviceEnvironment = *executionEnvironment->rootDeviceEnvironments[0]; + rootDeviceEnvironment.osInterface = std::make_unique(); + rootDeviceEnvironment.osInterface->setDriverModel(std::make_unique(mockFd, rootDeviceEnvironment)); + auto drm = DrmMockXe::create(rootDeviceEnvironment); + auto xeIoctlHelper = static_cast(drm->getIoctlHelper()); + auto engineInfo = xeIoctlHelper->createEngineInfo(false); + ASSERT_NE(nullptr, engineInfo); + + uint64_t expectedCycles = maxNBitValue(64); + auto xeQueryEngineCycles = reinterpret_cast(drm->queryEngineCycles); + xeQueryEngineCycles->width = 32; + xeQueryEngineCycles->engine_cycles = expectedCycles; + xeQueryEngineCycles->cpu_timestamp = 100; + + TimeStampData pGpuCpuTime{}; + std::unique_ptr osTime = MockOSTimeLinux::create(*rootDeviceEnvironment.osInterface); + auto ret = xeIoctlHelper->setGpuCpuTimes(&pGpuCpuTime, osTime.get()); + EXPECT_EQ(true, ret); + + EXPECT_EQ(pGpuCpuTime.gpuTimeStamp, expectedCycles & maxNBitValue(32)); + osTime->setDeviceTimestampWidth(64); + ret = xeIoctlHelper->setGpuCpuTimes(&pGpuCpuTime, osTime.get()); + EXPECT_EQ(true, ret); + EXPECT_EQ(pGpuCpuTime.gpuTimeStamp, expectedCycles); +} + TEST(IoctlHelperXeTest, whenSetDefaultEngineIsCalledThenProperEngineIsSet) { NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); auto executionEnvironment = std::make_unique(&hwInfo); diff --git a/shared/test/unit_test/xe2_hpg_core/bmg/gfx_core_helper_tests_bmg.cpp b/shared/test/unit_test/xe2_hpg_core/bmg/gfx_core_helper_tests_bmg.cpp index 87e3ad5732c29..0ff1060d62470 100644 --- a/shared/test/unit_test/xe2_hpg_core/bmg/gfx_core_helper_tests_bmg.cpp +++ b/shared/test/unit_test/xe2_hpg_core/bmg/gfx_core_helper_tests_bmg.cpp @@ -44,3 +44,14 @@ BMGTEST_F(GfxCoreHelperTestsBmg, WhenAskingForDcFlushThenReturnFalse) { setUpImpl(); EXPECT_FALSE(MemorySynchronizationCommands::getDcFlushEnable(true, pDevice->getRootDeviceEnvironment())); } + +BMGTEST_F(GfxCoreHelperTestsBmg, givenGetDeviceTimestampWidthCalledThenReturnCorrectValue) { + setUpImpl(); + DebugManagerStateRestore restore; + + auto &helper = this->pDevice->getGfxCoreHelper(); + EXPECT_EQ(64u, helper.getDeviceTimestampWidth()); + + debugManager.flags.OverrideTimestampWidth.set(36); + EXPECT_EQ(36u, helper.getDeviceTimestampWidth()); +} \ No newline at end of file diff --git a/shared/test/unit_test/xe2_hpg_core/excludes_xe2_hpg_core.cpp b/shared/test/unit_test/xe2_hpg_core/excludes_xe2_hpg_core.cpp index 81e8816e85bd5..0ee4cafcb6d59 100644 --- a/shared/test/unit_test/xe2_hpg_core/excludes_xe2_hpg_core.cpp +++ b/shared/test/unit_test/xe2_hpg_core/excludes_xe2_hpg_core.cpp @@ -37,3 +37,4 @@ HWTEST_EXCLUDE_PRODUCT(ProductHelperTest, givenBooleanUncachedWhenCallOverridePa HWTEST_EXCLUDE_PRODUCT(GfxCoreHelperTest, whenEncodeAdditionalTimestampOffsetsThenNothingEncoded, IGFX_XE2_HPG_CORE); HWTEST_EXCLUDE_PRODUCT(ProductHelperTest, givenProductHelperWhenGetThreadEuRatioForScratchThen8IsReturned, IGFX_XE2_HPG_CORE); HWTEST_EXCLUDE_PRODUCT(CompilerProductHelperFixture, WhenIsMidThreadPreemptionIsSupportedIsCalledThenCorrectResultIsReturned, IGFX_XE2_HPG_CORE); +HWTEST_EXCLUDE_PRODUCT(GfxCoreHelperTest, givenGetDeviceTimestampWidthCalledThenReturnCorrectValue, IGFX_XE2_HPG_CORE); \ No newline at end of file diff --git a/shared/test/unit_test/xe2_hpg_core/lnl/gfx_core_helper_tests_lnl.cpp b/shared/test/unit_test/xe2_hpg_core/lnl/gfx_core_helper_tests_lnl.cpp index 7f4c23e9bf47a..0ede715455b61 100644 --- a/shared/test/unit_test/xe2_hpg_core/lnl/gfx_core_helper_tests_lnl.cpp +++ b/shared/test/unit_test/xe2_hpg_core/lnl/gfx_core_helper_tests_lnl.cpp @@ -9,6 +9,7 @@ #include "shared/source/os_interface/product_helper.h" #include "shared/source/xe2_hpg_core/hw_cmds_lnl.h" #include "shared/source/xe2_hpg_core/hw_info_lnl.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/gfx_core_helper_tests.h" #include "shared/test/common/mocks/mock_device.h" @@ -31,3 +32,13 @@ LNLTEST_F(GfxCoreHelperTestsLnl, givenCommandBufferAllocationTypeWhenGetAllocati LNLTEST_F(GfxCoreHelperTestsLnl, WhenAskingForDcFlushThenReturnTrue) { EXPECT_NE(MemorySynchronizationCommands::getDcFlushEnable(true, this->pDevice->getRootDeviceEnvironment()), this->pDevice->getRootDeviceEnvironment().getProductHelper().isDcFlushMitigated()); } + +LNLTEST_F(GfxCoreHelperTestsLnl, givenGetDeviceTimestampWidthCalledThenReturnCorrectValue) { + DebugManagerStateRestore restore; + + auto &helper = this->pDevice->getGfxCoreHelper(); + EXPECT_EQ(64u, helper.getDeviceTimestampWidth()); + + debugManager.flags.OverrideTimestampWidth.set(36); + EXPECT_EQ(36u, helper.getDeviceTimestampWidth()); +} \ No newline at end of file