From 92a4f9df1aa062ae1b24a5b45a355ea73955bdaa Mon Sep 17 00:00:00 2001 From: shubham kumar Date: Thu, 27 Mar 2025 16:19:11 +0000 Subject: [PATCH] fix: Correct logic to get valid timestamp bits Related-To: NEO-14430 Signed-off-by: shubham kumar --- .../gfx_core_helpers/l0_gfx_core_helper.h | 2 ++ .../l0_gfx_core_helper_skl_to_pvc.inl | 8 ++++- .../l0_gfx_core_helper_xe2_hpg_and_later.inl | 6 ++++ .../test_l0_gfx_core_helper_xe2_hpg_core.cpp | 7 +++- .../test_l0_gfx_core_helper_xe_hpc_core.cpp | 7 +++- .../tools/source/metrics/metric_oa_source.cpp | 35 +++++-------------- .../tools/source/metrics/metric_oa_source.h | 2 +- .../metrics/mock_metric_oa_enumeration.h | 18 ---------- .../metrics/test_metric_oa_enumeration_1.cpp | 31 ++++------------ 9 files changed, 42 insertions(+), 74 deletions(-) diff --git a/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h b/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h index 983c10db4d..76826c43ae 100644 --- a/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h +++ b/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h @@ -120,6 +120,7 @@ class L0GfxCoreHelper : public NEO::ApiGfxCoreHelper { virtual bool implicitSynchronizedDispatchForCooperativeKernelsAllowed() const = 0; virtual std::unique_ptr getInOrderTimestampAllocator(const RootDeviceIndicesContainer &rootDeviceIndices, NEO::MemoryManager *memoryManager, size_t initialTagCount, size_t packetsCountPerElement, size_t tagAlignment, NEO::DeviceBitfield deviceBitfield) const = 0; + virtual uint64_t getOaTimestampValidBits() const = 0; protected: L0GfxCoreHelper() = default; @@ -174,6 +175,7 @@ class L0GfxCoreHelperHw : public L0GfxCoreHelper { bool implicitSynchronizedDispatchForCooperativeKernelsAllowed() const override; std::unique_ptr getInOrderTimestampAllocator(const RootDeviceIndicesContainer &rootDeviceIndices, NEO::MemoryManager *memoryManager, size_t initialTagCount, size_t packetsCountPerElement, size_t tagAlignment, NEO::DeviceBitfield deviceBitfield) const override; + uint64_t getOaTimestampValidBits() const override; protected: L0GfxCoreHelperHw() = default; diff --git a/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper_skl_to_pvc.inl b/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper_skl_to_pvc.inl index 7182b34f9e..45500f7d15 100644 --- a/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper_skl_to_pvc.inl +++ b/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper_skl_to_pvc.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -209,4 +209,10 @@ std::vector> L0GfxCoreHelperHw::ge return stallSamplingReportList; } +template +uint64_t L0GfxCoreHelperHw::getOaTimestampValidBits() const { + constexpr uint64_t oaTimestampValidBits = 32u; + return oaTimestampValidBits; +}; + } // namespace L0 diff --git a/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper_xe2_hpg_and_later.inl b/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper_xe2_hpg_and_later.inl index 8504e39f94..7a0f88a2f0 100644 --- a/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper_xe2_hpg_and_later.inl +++ b/level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper_xe2_hpg_and_later.inl @@ -206,4 +206,10 @@ std::vector> L0GfxCoreHelperHw::ge return stallSamplingReportList; } +template +uint64_t L0GfxCoreHelperHw::getOaTimestampValidBits() const { + constexpr uint64_t oaTimestampValidBits = 56u; + return oaTimestampValidBits; +}; + } // namespace L0 diff --git a/level_zero/core/test/unit_tests/xe2_hpg_core/test_l0_gfx_core_helper_xe2_hpg_core.cpp b/level_zero/core/test/unit_tests/xe2_hpg_core/test_l0_gfx_core_helper_xe2_hpg_core.cpp index 4fc610c767..12b8fea512 100644 --- a/level_zero/core/test/unit_tests/xe2_hpg_core/test_l0_gfx_core_helper_xe2_hpg_core.cpp +++ b/level_zero/core/test/unit_tests/xe2_hpg_core/test_l0_gfx_core_helper_xe2_hpg_core.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -139,5 +139,10 @@ XE2_HPG_CORETEST_F(L0GfxCoreHelperTestXe2Hpg, GivenXe2HpgWhenCheckingL0HelperFor EXPECT_NE(0u, stallSumIpDataMap.size()); } +XE2_HPG_CORETEST_F(L0GfxCoreHelperTestXe2Hpg, GivenXe2HpgWhenCheckingL0HelperForGetOaTimestampValidBitsThenCorrectValueIsReturned) { + auto &l0GfxCoreHelper = getHelper(); + EXPECT_EQ(56u, l0GfxCoreHelper.getOaTimestampValidBits()); +} + } // namespace ult } // namespace L0 diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/test_l0_gfx_core_helper_xe_hpc_core.cpp b/level_zero/core/test/unit_tests/xe_hpc_core/test_l0_gfx_core_helper_xe_hpc_core.cpp index 136e583182..4d4ac50f3f 100644 --- a/level_zero/core/test/unit_tests/xe_hpc_core/test_l0_gfx_core_helper_xe_hpc_core.cpp +++ b/level_zero/core/test/unit_tests/xe_hpc_core/test_l0_gfx_core_helper_xe_hpc_core.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -86,5 +86,10 @@ XE_HPC_CORETEST_F(L0GfxCoreHelperTestXeHpc, GivenXeHpcWhenCheckingL0HelperForDel EXPECT_NE(0u, stallSumIpDataMap.size()); } +XE_HPC_CORETEST_F(L0GfxCoreHelperTestXeHpc, GivenXeHpcWhenCheckingL0HelperForGetOaTimestampValidBitsThenCorrectValueIsReturned) { + auto &l0GfxCoreHelper = getHelper(); + EXPECT_EQ(32u, l0GfxCoreHelper.getOaTimestampValidBits()); +} + } // namespace ult } // namespace L0 diff --git a/level_zero/tools/source/metrics/metric_oa_source.cpp b/level_zero/tools/source/metrics/metric_oa_source.cpp index 3505c0b726..ae35d4b5f9 100644 --- a/level_zero/tools/source/metrics/metric_oa_source.cpp +++ b/level_zero/tools/source/metrics/metric_oa_source.cpp @@ -7,10 +7,12 @@ #include "level_zero/tools/source/metrics/metric_oa_source.h" +#include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/os_interface/os_library.h" #include "level_zero/core/source/cmdlist/cmdlist.h" #include "level_zero/core/source/device/device_imp.h" +#include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" #include "level_zero/tools/source/metrics/metric.h" #include "level_zero/tools/source/metrics/metric_multidevice_programmable.h" #include "level_zero/tools/source/metrics/metric_multidevice_programmable.inl" @@ -47,27 +49,10 @@ ze_result_t OaMetricSourceImp::getTimerResolution(uint64_t &resolution) { return ZE_RESULT_SUCCESS; } -ze_result_t OaMetricSourceImp::getTimestampValidBits(uint64_t &validBits) { - ze_result_t retVal = ZE_RESULT_SUCCESS; - - uint64_t maxNanoSeconds = 0; - if (!metricEnumeration->readGlobalSymbol(globalSymbolOaMaxTimestamp.data(), maxNanoSeconds)) { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - - uint64_t timerFreqquency; - retVal = getTimerResolution(timerFreqquency); - if (retVal != ZE_RESULT_SUCCESS) { - validBits = 0; - return retVal; - } - - uint64_t maxTimeStamp = maxNanoSeconds * timerFreqquency / CommonConstants::nsecPerSec; - - auto bits = std::bitset<64>(maxTimeStamp); - validBits = bits.count(); - - return retVal; +void OaMetricSourceImp::getTimestampValidBits(uint64_t &validBits) { + DeviceImp *deviceImp = static_cast(&getDevice()); + auto &l0GfxCoreHelper = deviceImp->getNEODevice()->getRootDeviceEnvironment().getHelper(); + validBits = l0GfxCoreHelper.getOaTimestampValidBits(); } bool OaMetricSourceImp::isAvailable() { @@ -220,12 +205,8 @@ ze_result_t OaMetricSourceImp::handleMetricGroupExtendedProperties(zet_metric_gr return retVal; } - retVal = getTimestampValidBits(metricsTimestampProperties->timestampValidBits); - if (retVal != ZE_RESULT_SUCCESS) { - metricsTimestampProperties->timerResolution = 0; - metricsTimestampProperties->timestampValidBits = 0; - return retVal; - } + getTimestampValidBits(metricsTimestampProperties->timestampValidBits); + } else if (extendedProperties->stype == ZET_STRUCTURE_TYPE_METRIC_GROUP_TYPE_EXP) { zet_metric_group_type_exp_t *groupType = reinterpret_cast(extendedProperties); groupType->type = ZET_METRIC_GROUP_TYPE_EXP_FLAG_OTHER; diff --git a/level_zero/tools/source/metrics/metric_oa_source.h b/level_zero/tools/source/metrics/metric_oa_source.h index 02244e7aba..26ca8dbd75 100644 --- a/level_zero/tools/source/metrics/metric_oa_source.h +++ b/level_zero/tools/source/metrics/metric_oa_source.h @@ -81,7 +81,7 @@ class OaMetricSourceImp : public MetricSource { bool useCompute = false; std::unique_ptr activationTracker{}; ze_result_t getTimerResolution(uint64_t &resolution); - ze_result_t getTimestampValidBits(uint64_t &validBits); + void getTimestampValidBits(uint64_t &validBits); }; template <> diff --git a/level_zero/tools/test/unit_tests/sources/metrics/mock_metric_oa_enumeration.h b/level_zero/tools/test/unit_tests/sources/metrics/mock_metric_oa_enumeration.h index 3062cb468d..64b0fbebc7 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/mock_metric_oa_enumeration.h +++ b/level_zero/tools/test/unit_tests/sources/metrics/mock_metric_oa_enumeration.h @@ -134,9 +134,6 @@ class Mock : public IMetricsDevice_1_13 { MetricsDiscovery::TTypedValue_1_0 symbolValue = {}; bool forceGetSymbolByNameFail = false; bool forceGetGpuCpuTimestampsFail = false; - bool forceGetMaxTimestampFail = false; - uint32_t failGetGpuTimestampFrequencyOnCall = 0; - uint32_t getGpuTimestampFrequencyCallCount = 0; TTypedValue_1_0 *GetGlobalSymbolValueByName(const char *name) override { bool found = false; if (forceGetSymbolByNameFail) { @@ -146,17 +143,10 @@ class Mock : public IMetricsDevice_1_13 { symbolValue.ValueUInt32 = 1024; found = true; } else if (std::strcmp(name, "MaxTimestamp") == 0) { - if (forceGetMaxTimestampFail) { - return nullptr; - } symbolValue.ValueType = MetricsDiscovery::TValueType::VALUE_TYPE_UINT64; symbolValue.ValueUInt64 = 171798691800UL; // PVC as reference found = true; } else if (std::strcmp(name, "GpuTimestampFrequency") == 0) { - getGpuTimestampFrequencyCallCount++; - if (failGetGpuTimestampFrequencyOnCall && (getGpuTimestampFrequencyCallCount >= failGetGpuTimestampFrequencyOnCall)) { - return nullptr; - } symbolValue.ValueType = MetricsDiscovery::TValueType::VALUE_TYPE_UINT64; symbolValue.ValueUInt64 = 25000000UL; // PVC as reference found = true; @@ -182,14 +172,6 @@ class Mock : public IMetricsDevice_1_13 { return MetricsDiscovery::CC_OK; } - void resetMockVars() { - forceGetSymbolByNameFail = false; - forceGetGpuCpuTimestampsFail = false; - forceGetMaxTimestampFail = false; - failGetGpuTimestampFrequencyOnCall = 0; - getGpuTimestampFrequencyCallCount = 0; - } - std::vector getConcurrentGroupResults; }; diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_oa_enumeration_1.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_oa_enumeration_1.cpp index c30c34152e..8af35ca8bd 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_oa_enumeration_1.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_oa_enumeration_1.cpp @@ -10,6 +10,7 @@ #include "shared/test/common/test_macros/test_base.h" #include "level_zero/core/source/device/device_imp.h" +#include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" #include "level_zero/core/test/unit_tests/mocks/mock_driver.h" #include "level_zero/tools/source/metrics/metric_oa_source.h" @@ -548,7 +549,10 @@ TEST_F(MetricEnumerationTest, GivenEnumerationIsSuccessfulWhenReadingMetricsFreq EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0); EXPECT_EQ(metricTimestampProperties.timerResolution, 25000000UL); - EXPECT_EQ(metricTimestampProperties.timestampValidBits, 32UL); + + auto &l0GfxCoreHelper = neoDevice->getRootDeviceEnvironment().getHelper(); + uint64_t expectedValidBits = l0GfxCoreHelper.getOaTimestampValidBits(); + EXPECT_EQ(metricTimestampProperties.timestampValidBits, expectedValidBits); } TEST_F(MetricEnumerationTest, whenReadingMetricCroupCalculateParametersThenExpectedValuesAreReturned) { @@ -767,7 +771,7 @@ TEST_F(MetricEnumerationTest, GivenValidMetricGroupWhenReadingFrequencyAndIntern EXPECT_NE(metricTimestampProperties.timerResolution, 0UL); EXPECT_NE(metricTimestampProperties.timestampValidBits, 0UL); - metricsDevice.failGetGpuTimestampFrequencyOnCall = true; + metricsDevice.forceGetSymbolByNameFail = true; EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_ERROR_NOT_AVAILABLE); EXPECT_EQ(metricGroupProperties.domain, 0u); @@ -778,29 +782,6 @@ TEST_F(MetricEnumerationTest, GivenValidMetricGroupWhenReadingFrequencyAndIntern EXPECT_EQ(metricTimestampProperties.timerResolution, 0UL); EXPECT_EQ(metricTimestampProperties.timestampValidBits, 0UL); - - metricsDevice.resetMockVars(); - metricsDevice.forceGetMaxTimestampFail = true; - - EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_ERROR_NOT_AVAILABLE); - EXPECT_EQ(metricGroupProperties.domain, 0u); - EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED); - EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount); - EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0); - EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0); - - EXPECT_EQ(metricTimestampProperties.timerResolution, 0UL); - EXPECT_EQ(metricTimestampProperties.timestampValidBits, 0UL); - - metricsDevice.resetMockVars(); - metricsDevice.failGetGpuTimestampFrequencyOnCall = 2; - - EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_ERROR_NOT_AVAILABLE); - EXPECT_EQ(metricGroupProperties.domain, 0u); - EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED); - EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount); - EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0); - EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0); } TEST_F(MetricEnumerationTest, GivenEnumerationIsSuccessfulWhenReadingMetricsFrequencyThenValuesAreUpdated) {