From 0f866e24e692eda7b54f3900eb02e1a7d864720f Mon Sep 17 00:00:00 2001 From: Katarzyna Cencelewska Date: Thu, 2 Oct 2025 15:16:00 +0000 Subject: [PATCH] fix: enable setting timestamp via submission on tbx mode Resolves: NEO-16293 Signed-off-by: Katarzyna Cencelewska --- level_zero/core/source/device/device_imp.cpp | 11 ++-- .../sources/device/test_l0_device.cpp | 59 +++++++++++++++++++ .../debug_settings/debug_variables_base.inl | 2 +- shared/test/common/test_files/igdrcl.config | 2 +- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index ad154ff3f2..f02cd16c1a 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -1198,12 +1198,15 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties) ze_result_t DeviceImp::getGlobalTimestamps(uint64_t *hostTimestamp, uint64_t *deviceTimestamp) { - bool method = 0; - if (NEO::debugManager.flags.EnableGlobalTimestampViaSubmission.get() != -1) { - method = NEO::debugManager.flags.EnableGlobalTimestampViaSubmission.get(); + bool useTimestampViaSubmission = false; + auto csrType = obtainCsrTypeFromIntegerValue(NEO::debugManager.flags.SetCommandStreamReceiver.get(), NEO::CommandStreamReceiverType::hardware); + if (csrType == NEO::CommandStreamReceiverType::tbx || + csrType == NEO::CommandStreamReceiverType::tbxWithAub || + NEO::debugManager.flags.EnableGlobalTimestampViaSubmission.get() == 1) { + useTimestampViaSubmission = true; } - if (method == 0) { + if (useTimestampViaSubmission == false) { auto ret = getGlobalTimestampsUsingOsInterface(hostTimestamp, deviceTimestamp); if (ret != ZE_RESULT_ERROR_UNSUPPORTED_FEATURE) { return ret; diff --git a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp index 56d9b8743f..435da90618 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp @@ -1739,6 +1739,65 @@ TEST_F(DeviceTest, givenInvalidPciBusInfoWhenPciPropertiesIsCalledThenUninitiali EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, res); } } +struct GetGlobalTimestampTest : public DeviceTest { + struct MockCommandListAppendWriteGlobalTimestamp : public MockCommandList { + ze_result_t appendWriteGlobalTimestamp(uint64_t *dstptr, ze_event_handle_t hEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) override { + isAppendWriteGlobalTimestampCalled = true; + *dstptr = 123456u; // dummy value + return ZE_RESULT_SUCCESS; + } + bool isAppendWriteGlobalTimestampCalled = false; + }; + void SetUp() override { + DeviceTest::SetUp(); + mockCommandList = std::make_unique(); + uint64_t hostTs = 0u; + uint64_t deviceTs = 0u; + // initialize globalTimestampAllocation + debugManager.flags.EnableGlobalTimestampViaSubmission.set(1); + device->getGlobalTimestamps(&hostTs, &deviceTs); + debugManager.flags.EnableGlobalTimestampViaSubmission.set(0); + + deviceImp = static_cast(device); + actualGlobalTimestampCommandList = deviceImp->globalTimestampCommandList; + // Swap the command list with the mock command list. + deviceImp->globalTimestampCommandList = static_cast(mockCommandList.get()); + } + + void TearDown() override { + // Swap back the command list. + deviceImp->globalTimestampCommandList = actualGlobalTimestampCommandList; + DeviceTest::TearDown(); + } + + std::unique_ptr mockCommandList = nullptr; + ze_command_list_handle_t actualGlobalTimestampCommandList = nullptr; + DeviceImp *deviceImp = nullptr; +}; + +TEST_F(GetGlobalTimestampTest, whenTbxModeThenSetGlobalTimestampViaSubmission) { + uint64_t hostTs = 0u; + uint64_t deviceTs = 0u; + + debugManager.flags.SetCommandStreamReceiver.set(static_cast(NEO::CommandStreamReceiverType::tbx)); + + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + EXPECT_NE(0u, hostTs); + EXPECT_NE(0u, deviceTs); + EXPECT_TRUE(mockCommandList->isAppendWriteGlobalTimestampCalled); + + debugManager.flags.SetCommandStreamReceiver.set(static_cast(NEO::CommandStreamReceiverType::tbxWithAub)); + mockCommandList->isAppendWriteGlobalTimestampCalled = false; + + result = device->getGlobalTimestamps(&hostTs, &deviceTs); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + EXPECT_NE(0u, hostTs); + EXPECT_NE(0u, deviceTs); + EXPECT_TRUE(mockCommandList->isAppendWriteGlobalTimestampCalled); +} TEST_F(DeviceTest, whenGetGlobalTimestampIsCalledWithOsInterfaceThenSuccessIsReturnedAndValuesSetCorrectly) { uint64_t hostTs = 0u; diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 9dcc99f180..660281949f 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -680,7 +680,7 @@ DECLARE_DEBUG_VARIABLE(std::string, FinalizerInputType, std::string("unk"), "unk DECLARE_DEBUG_VARIABLE(std::string, FinalizerLibraryName, std::string("unk"), "Library name for finalizer") DECLARE_DEBUG_VARIABLE(std::string, IgcLibraryName, std::string("unk"), "Library name for igc") DECLARE_DEBUG_SCOPED_V(int32_t, UseIgcAsFcl, 0, S_RT | S_OCLOC, "0: platform default, 1: force use IGC, 2: force use FCL") -DECLARE_DEBUG_VARIABLE(int32_t, EnableGlobalTimestampViaSubmission, -1, "-1: OS Interface, 0: OS Interface, 1: Submission. This flag sets the type of method to get timestamp for getGlobalTimestamps"); +DECLARE_DEBUG_VARIABLE(bool, EnableGlobalTimestampViaSubmission, 0, "0: OS Interface, 1: Submission. This flag sets the type of method to get timestamp for getGlobalTimestamps"); /* Binary Cache */ DECLARE_DEBUG_VARIABLE(bool, BinaryCacheTrace, false, "enable cl_cache to produce .trace files with information about hash computation") diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index a663e93f27..f58fd2cc49 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -618,7 +618,7 @@ SetAssumeNotInUse = 1 ForceNonWalkerSplitMemoryCopy = -1 FinalizerInputType = unk FinalizerLibraryName = unk -EnableGlobalTimestampViaSubmission = -1 +EnableGlobalTimestampViaSubmission = 0 DirectSubmissionSwitchSemaphoreMode = -1 DisableProgrammableMetricsSupport = 0 IgnoreZebinUnknownAttributes = 0