Skip to content

Commit

Permalink
fix: Override timestamp width from KMD
Browse files Browse the repository at this point in the history
Signed-off-by: Szymon Morek <szymon.morek@intel.com>
Source: 7f2b806
  • Loading branch information
smorek-intel authored and Compute-Runtime-Automation committed Oct 16, 2024
1 parent e7e9804 commit 625e7e0
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions shared/source/debug_settings/debug_variables_base.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void RootDeviceEnvironment::initOsTime() {
if (!osTime) {
osTime = OSTime::create(osInterface.get());
osTime->setDeviceTimerResolution(*hwInfo);
osTime->setDeviceTimestampWidth(gfxCoreHelper->getDeviceTimestampWidth());
}
}

Expand Down
4 changes: 4 additions & 0 deletions shared/source/helpers/gfx_core_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions shared/source/helpers/gfx_core_helper_base.inl
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,14 @@ bool GfxCoreHelperHw<GfxFamily>::usmCompressionSupported(const NEO::HardwareInfo
return false;
}

template <typename GfxFamily>
uint32_t GfxCoreHelperHw<GfxFamily>::getDeviceTimestampWidth() const {
if (debugManager.flags.OverrideTimestampWidth.get() != -1) {
return debugManager.flags.OverrideTimestampWidth.get();
}
return 0u;
}

template <typename Family>
uint32_t GfxCoreHelperHw<Family>::getInternalCopyEngineIndex(const HardwareInfo &hwInfo) const {
if (debugManager.flags.ForceBCSForInternalCopyEngine.get() != -1) {
Expand Down
3 changes: 3 additions & 0 deletions shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions shared/source/os_interface/os_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -99,5 +107,6 @@ class OSTime {
OSInterface *osInterface = nullptr;
std::unique_ptr<DeviceTime> deviceTime;
uint64_t maxGpuTimeStamp = 0;
uint32_t timestampWidth = 0;
};
} // namespace NEO
8 changes: 8 additions & 0 deletions shared/source/xe2_hpg_core/gfx_core_helper_xe2_hpg_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ uint32_t GfxCoreHelperHw<Family>::getMetricsLibraryGenId() const {
return static_cast<uint32_t>(MetricsLibraryApi::ClientGen::Xe2HPG);
}

template <>
uint32_t GfxCoreHelperHw<Family>::getDeviceTimestampWidth() const {
if (debugManager.flags.OverrideTimestampWidth.get() != -1) {
return debugManager.flags.OverrideTimestampWidth.get();
}
return 64u;
};

} // namespace NEO

namespace NEO {
Expand Down
1 change: 1 addition & 0 deletions shared/test/common/test_files/igdrcl.config
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,5 @@ DirectSubmissionPrintSemaphoreUsage = -1
ForceNonCoherentModeForTimestamps = 0
ExperimentalUSMAllocationReuseVersion = -1
ForceNonWalkerSplitMemoryCopy = -1
OverrideTimestampWidth = -1
# Please don't edit below this line
10 changes: 10 additions & 0 deletions shared/test/unit_test/helpers/gfx_core_helper_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1856,3 +1856,13 @@ HWTEST_F(GfxCoreHelperTest, whenEncodeAdditionalTimestampOffsetsThenNothingEncod
GenCmdList storeRegMemList = hwParser.getCommandsList<MI_STORE_REGISTER_MEM>();
EXPECT_EQ(0u, storeRegMemList.size());
}

HWTEST_F(GfxCoreHelperTest, givenGetDeviceTimestampWidthCalledThenReturnCorrectValue) {
DebugManagerStateRestore restore;

auto &helper = getHelper<GfxCoreHelper>();
EXPECT_EQ(0u, helper.getDeviceTimestampWidth());

debugManager.flags.OverrideTimestampWidth.set(64);
EXPECT_EQ(64u, helper.getDeviceTimestampWidth());
}
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,35 @@ TEST(IoctlHelperXeTest, givenIoctlFailureWhenSetGpuCpuTimesIsCalledThenProperVal
EXPECT_EQ(pGpuCpuTime.cpuTimeinNS, expectedTimestamp);
}

TEST(IoctlHelperXeTest, whenDeviceTimestampWidthSetThenProperValuesAreSet) {
DebugManagerStateRestore restorer;
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto &rootDeviceEnvironment = *executionEnvironment->rootDeviceEnvironments[0];
rootDeviceEnvironment.osInterface = std::make_unique<OSInterface>();
rootDeviceEnvironment.osInterface->setDriverModel(std::make_unique<DrmMockTime>(mockFd, rootDeviceEnvironment));
auto drm = DrmMockXe::create(rootDeviceEnvironment);
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
auto engineInfo = xeIoctlHelper->createEngineInfo(false);
ASSERT_NE(nullptr, engineInfo);

uint64_t expectedCycles = maxNBitValue(64);
auto xeQueryEngineCycles = reinterpret_cast<drm_xe_query_engine_cycles *>(drm->queryEngineCycles);
xeQueryEngineCycles->width = 32;
xeQueryEngineCycles->engine_cycles = expectedCycles;
xeQueryEngineCycles->cpu_timestamp = 100;

TimeStampData pGpuCpuTime{};
std::unique_ptr<MockOSTimeLinux> 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<MockExecutionEnvironment>(&hwInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ BMGTEST_F(GfxCoreHelperTestsBmg, WhenAskingForDcFlushThenReturnFalse) {
setUpImpl();
EXPECT_FALSE(MemorySynchronizationCommands<FamilyType>::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());
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,3 +32,13 @@ LNLTEST_F(GfxCoreHelperTestsLnl, givenCommandBufferAllocationTypeWhenGetAllocati
LNLTEST_F(GfxCoreHelperTestsLnl, WhenAskingForDcFlushThenReturnTrue) {
EXPECT_NE(MemorySynchronizationCommands<FamilyType>::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());
}

0 comments on commit 625e7e0

Please sign in to comment.