Skip to content

Commit 7f2b806

Browse files
fix: Override timestamp width from KMD
Signed-off-by: Szymon Morek <[email protected]>
1 parent 8527779 commit 7f2b806

File tree

13 files changed

+97
-0
lines changed

13 files changed

+97
-0
lines changed

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, StandaloneInOrderTimestampAllocationEnabled, -1,
292292
DECLARE_DEBUG_VARIABLE(int32_t, ForceComputeWalkerPostSyncFlushWithWrite, -1, "-1: ignore. >=0: Force PostSync cache flush and override postSync immediate write address to given value")
293293
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)")
294294
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")
295+
DECLARE_DEBUG_VARIABLE(int32_t, OverrideTimestampWidth, -1, "-1: default from KMD, > 0: Override timestamp width used for profiling. Requires XeKMD kernel.")
295296

296297
/*LOGGING FLAGS*/
297298
DECLARE_DEBUG_VARIABLE(int32_t, PrintDriverDiagnostics, -1, "prints driver diagnostics messages to standard output, value corresponds to hint level")

shared/source/execution_environment/root_device_environment.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ void RootDeviceEnvironment::initOsTime() {
128128
if (!osTime) {
129129
osTime = OSTime::create(osInterface.get());
130130
osTime->setDeviceTimerResolution(*hwInfo);
131+
osTime->setDeviceTimestampWidth(gfxCoreHelper->getDeviceTimestampWidth());
131132
}
132133
}
133134

shared/source/helpers/gfx_core_helper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class GfxCoreHelper {
199199

200200
virtual bool usmCompressionSupported(const NEO::HardwareInfo &hwInfo) const = 0;
201201

202+
virtual uint32_t getDeviceTimestampWidth() const = 0;
203+
202204
virtual ~GfxCoreHelper() = default;
203205

204206
protected:
@@ -433,6 +435,8 @@ class GfxCoreHelperHw : public GfxCoreHelper {
433435

434436
bool usmCompressionSupported(const NEO::HardwareInfo &hwInfo) const override;
435437

438+
uint32_t getDeviceTimestampWidth() const override;
439+
436440
~GfxCoreHelperHw() override = default;
437441

438442
protected:

shared/source/helpers/gfx_core_helper_base.inl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,14 @@ uint32_t GfxCoreHelperHw<GfxFamily>::calculateAvailableThreadCount(const Hardwar
805805
return std::min(hwInfo.gtSystemInfo.ThreadCount, maxThreadsPerEuCount * hwInfo.gtSystemInfo.EUCount);
806806
}
807807

808+
template <typename GfxFamily>
809+
uint32_t GfxCoreHelperHw<GfxFamily>::getDeviceTimestampWidth() const {
810+
if (debugManager.flags.OverrideTimestampWidth.get() != -1) {
811+
return debugManager.flags.OverrideTimestampWidth.get();
812+
}
813+
return 0u;
814+
}
815+
808816
template <typename Family>
809817
uint32_t GfxCoreHelperHw<Family>::getInternalCopyEngineIndex(const HardwareInfo &hwInfo) const {
810818
if (debugManager.flags.ForceBCSForInternalCopyEngine.get() != -1) {

shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ bool IoctlHelperXe::setGpuCpuTimes(TimeStampData *pGpuCpuTime, OSTime *osTime) {
429429
ret = IoctlHelper::ioctl(DrmIoctl::query, &deviceQuery);
430430

431431
auto nValidBits = queryEngineCycles->width;
432+
if (osTime->getDeviceTimestampWidth() != 0) {
433+
nValidBits = osTime->getDeviceTimestampWidth();
434+
}
432435
auto gpuTimestampValidBits = maxNBitValue(nValidBits);
433436
auto gpuCycles = queryEngineCycles->engine_cycles & gpuTimestampValidBits;
434437

shared/source/os_interface/os_time.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ class OSTime {
8686
deviceTime->setDeviceTimerResolution(hwInfo);
8787
}
8888

89+
void setDeviceTimestampWidth(uint32_t timestampWidth) {
90+
this->timestampWidth = timestampWidth;
91+
}
92+
93+
uint32_t getDeviceTimestampWidth() const {
94+
return this->timestampWidth;
95+
}
96+
8997
void setRefreshTimestampsFlag() const {
9098
deviceTime->setRefreshTimestampsFlag();
9199
}
@@ -99,5 +107,6 @@ class OSTime {
99107
OSInterface *osInterface = nullptr;
100108
std::unique_ptr<DeviceTime> deviceTime;
101109
uint64_t maxGpuTimeStamp = 0;
110+
uint32_t timestampWidth = 0;
102111
};
103112
} // namespace NEO

shared/source/xe2_hpg_core/gfx_core_helper_xe2_hpg_core.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ uint32_t GfxCoreHelperHw<Family>::getMetricsLibraryGenId() const {
333333
return static_cast<uint32_t>(MetricsLibraryApi::ClientGen::Xe2HPG);
334334
}
335335

336+
template <>
337+
uint32_t GfxCoreHelperHw<Family>::getDeviceTimestampWidth() const {
338+
if (debugManager.flags.OverrideTimestampWidth.get() != -1) {
339+
return debugManager.flags.OverrideTimestampWidth.get();
340+
}
341+
return 64u;
342+
};
343+
336344
} // namespace NEO
337345

338346
namespace NEO {

shared/test/common/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,5 @@ ForceNonCoherentModeForTimestamps = 0
625625
ExperimentalUSMAllocationReuseVersion = -1
626626
ForceNonWalkerSplitMemoryCopy = -1
627627
DirectSubmissionSwitchSemaphoreMode = -1
628+
OverrideTimestampWidth = -1
628629
# Please don't edit below this line

shared/test/unit_test/helpers/gfx_core_helper_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,4 +1862,14 @@ HWTEST2_F(GfxCoreHelperTest, GivenModifiedGtSystemInfoWhenCallingCalculateAvaila
18621862
auto result = gfxCoreHelper.calculateAvailableThreadCount(hwInfo, 256);
18631863
EXPECT_EQ(expectedThreadCount, result);
18641864
}
1865+
}
1866+
1867+
HWTEST_F(GfxCoreHelperTest, givenGetDeviceTimestampWidthCalledThenReturnCorrectValue) {
1868+
DebugManagerStateRestore restore;
1869+
1870+
auto &helper = getHelper<GfxCoreHelper>();
1871+
EXPECT_EQ(0u, helper.getDeviceTimestampWidth());
1872+
1873+
debugManager.flags.OverrideTimestampWidth.set(64);
1874+
EXPECT_EQ(64u, helper.getDeviceTimestampWidth());
18651875
}

shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,35 @@ TEST(IoctlHelperXeTest, givenIoctlFailureWhenSetGpuCpuTimesIsCalledThenProperVal
17941794
EXPECT_EQ(pGpuCpuTime.cpuTimeinNS, expectedTimestamp);
17951795
}
17961796

1797+
TEST(IoctlHelperXeTest, whenDeviceTimestampWidthSetThenProperValuesAreSet) {
1798+
DebugManagerStateRestore restorer;
1799+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
1800+
auto &rootDeviceEnvironment = *executionEnvironment->rootDeviceEnvironments[0];
1801+
rootDeviceEnvironment.osInterface = std::make_unique<OSInterface>();
1802+
rootDeviceEnvironment.osInterface->setDriverModel(std::make_unique<DrmMockTime>(mockFd, rootDeviceEnvironment));
1803+
auto drm = DrmMockXe::create(rootDeviceEnvironment);
1804+
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
1805+
auto engineInfo = xeIoctlHelper->createEngineInfo(false);
1806+
ASSERT_NE(nullptr, engineInfo);
1807+
1808+
uint64_t expectedCycles = maxNBitValue(64);
1809+
auto xeQueryEngineCycles = reinterpret_cast<drm_xe_query_engine_cycles *>(drm->queryEngineCycles);
1810+
xeQueryEngineCycles->width = 32;
1811+
xeQueryEngineCycles->engine_cycles = expectedCycles;
1812+
xeQueryEngineCycles->cpu_timestamp = 100;
1813+
1814+
TimeStampData pGpuCpuTime{};
1815+
std::unique_ptr<MockOSTimeLinux> osTime = MockOSTimeLinux::create(*rootDeviceEnvironment.osInterface);
1816+
auto ret = xeIoctlHelper->setGpuCpuTimes(&pGpuCpuTime, osTime.get());
1817+
EXPECT_EQ(true, ret);
1818+
1819+
EXPECT_EQ(pGpuCpuTime.gpuTimeStamp, expectedCycles & maxNBitValue(32));
1820+
osTime->setDeviceTimestampWidth(64);
1821+
ret = xeIoctlHelper->setGpuCpuTimes(&pGpuCpuTime, osTime.get());
1822+
EXPECT_EQ(true, ret);
1823+
EXPECT_EQ(pGpuCpuTime.gpuTimeStamp, expectedCycles);
1824+
}
1825+
17971826
TEST(IoctlHelperXeTest, whenSetDefaultEngineIsCalledThenProperEngineIsSet) {
17981827
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
17991828
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>(&hwInfo);

shared/test/unit_test/xe2_hpg_core/bmg/gfx_core_helper_tests_bmg.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,14 @@ BMGTEST_F(GfxCoreHelperTestsBmg, WhenAskingForDcFlushThenReturnFalse) {
4444
setUpImpl();
4545
EXPECT_FALSE(MemorySynchronizationCommands<FamilyType>::getDcFlushEnable(true, pDevice->getRootDeviceEnvironment()));
4646
}
47+
48+
BMGTEST_F(GfxCoreHelperTestsBmg, givenGetDeviceTimestampWidthCalledThenReturnCorrectValue) {
49+
setUpImpl();
50+
DebugManagerStateRestore restore;
51+
52+
auto &helper = this->pDevice->getGfxCoreHelper();
53+
EXPECT_EQ(64u, helper.getDeviceTimestampWidth());
54+
55+
debugManager.flags.OverrideTimestampWidth.set(36);
56+
EXPECT_EQ(36u, helper.getDeviceTimestampWidth());
57+
}

shared/test/unit_test/xe2_hpg_core/excludes_xe2_hpg_core.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ HWTEST_EXCLUDE_PRODUCT(ProductHelperTest, givenBooleanUncachedWhenCallOverridePa
3737
HWTEST_EXCLUDE_PRODUCT(GfxCoreHelperTest, whenEncodeAdditionalTimestampOffsetsThenNothingEncoded, IGFX_XE2_HPG_CORE);
3838
HWTEST_EXCLUDE_PRODUCT(ProductHelperTest, givenProductHelperWhenGetThreadEuRatioForScratchThen8IsReturned, IGFX_XE2_HPG_CORE);
3939
HWTEST_EXCLUDE_PRODUCT(CompilerProductHelperFixture, WhenIsMidThreadPreemptionIsSupportedIsCalledThenCorrectResultIsReturned, IGFX_XE2_HPG_CORE);
40+
HWTEST_EXCLUDE_PRODUCT(GfxCoreHelperTest, givenGetDeviceTimestampWidthCalledThenReturnCorrectValue, IGFX_XE2_HPG_CORE);

shared/test/unit_test/xe2_hpg_core/lnl/gfx_core_helper_tests_lnl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "shared/source/os_interface/product_helper.h"
1010
#include "shared/source/xe2_hpg_core/hw_cmds_lnl.h"
1111
#include "shared/source/xe2_hpg_core/hw_info_lnl.h"
12+
#include "shared/test/common/helpers/debug_manager_state_restore.h"
1213
#include "shared/test/common/helpers/default_hw_info.h"
1314
#include "shared/test/common/helpers/gfx_core_helper_tests.h"
1415
#include "shared/test/common/mocks/mock_device.h"
@@ -31,3 +32,13 @@ LNLTEST_F(GfxCoreHelperTestsLnl, givenCommandBufferAllocationTypeWhenGetAllocati
3132
LNLTEST_F(GfxCoreHelperTestsLnl, WhenAskingForDcFlushThenReturnTrue) {
3233
EXPECT_NE(MemorySynchronizationCommands<FamilyType>::getDcFlushEnable(true, this->pDevice->getRootDeviceEnvironment()), this->pDevice->getRootDeviceEnvironment().getProductHelper().isDcFlushMitigated());
3334
}
35+
36+
LNLTEST_F(GfxCoreHelperTestsLnl, givenGetDeviceTimestampWidthCalledThenReturnCorrectValue) {
37+
DebugManagerStateRestore restore;
38+
39+
auto &helper = this->pDevice->getGfxCoreHelper();
40+
EXPECT_EQ(64u, helper.getDeviceTimestampWidth());
41+
42+
debugManager.flags.OverrideTimestampWidth.set(36);
43+
EXPECT_EQ(36u, helper.getDeviceTimestampWidth());
44+
}

0 commit comments

Comments
 (0)