fix: Correct logic to get valid timestamp bits

Related-To: NEO-14430

Signed-off-by: shubham kumar <shubham.kumar@intel.com>
This commit is contained in:
shubham kumar
2025-03-27 16:19:11 +00:00
committed by Compute-Runtime-Automation
parent ecc96a9ab4
commit 92a4f9df1a
9 changed files with 42 additions and 74 deletions

View File

@@ -120,6 +120,7 @@ class L0GfxCoreHelper : public NEO::ApiGfxCoreHelper {
virtual bool implicitSynchronizedDispatchForCooperativeKernelsAllowed() const = 0;
virtual std::unique_ptr<NEO::TagAllocatorBase> 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<NEO::TagAllocatorBase> 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;

View File

@@ -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<std::pair<const char *, const char *>> L0GfxCoreHelperHw<Family>::ge
return stallSamplingReportList;
}
template <typename Family>
uint64_t L0GfxCoreHelperHw<Family>::getOaTimestampValidBits() const {
constexpr uint64_t oaTimestampValidBits = 32u;
return oaTimestampValidBits;
};
} // namespace L0

View File

@@ -206,4 +206,10 @@ std::vector<std::pair<const char *, const char *>> L0GfxCoreHelperHw<Family>::ge
return stallSamplingReportList;
}
template <typename Family>
uint64_t L0GfxCoreHelperHw<Family>::getOaTimestampValidBits() const {
constexpr uint64_t oaTimestampValidBits = 56u;
return oaTimestampValidBits;
};
} // namespace L0

View File

@@ -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<L0GfxCoreHelper>();
EXPECT_EQ(56u, l0GfxCoreHelper.getOaTimestampValidBits());
}
} // namespace ult
} // namespace L0

View File

@@ -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<L0GfxCoreHelper>();
EXPECT_EQ(32u, l0GfxCoreHelper.getOaTimestampValidBits());
}
} // namespace ult
} // namespace L0

View File

@@ -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<DeviceImp *>(&getDevice());
auto &l0GfxCoreHelper = deviceImp->getNEODevice()->getRootDeviceEnvironment().getHelper<L0GfxCoreHelper>();
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<zet_metric_group_type_exp_t *>(extendedProperties);
groupType->type = ZET_METRIC_GROUP_TYPE_EXP_FLAG_OTHER;

View File

@@ -81,7 +81,7 @@ class OaMetricSourceImp : public MetricSource {
bool useCompute = false;
std::unique_ptr<MultiDomainDeferredActivationTracker> activationTracker{};
ze_result_t getTimerResolution(uint64_t &resolution);
ze_result_t getTimestampValidBits(uint64_t &validBits);
void getTimestampValidBits(uint64_t &validBits);
};
template <>

View File

@@ -134,9 +134,6 @@ class Mock<IMetricsDevice_1_13> : 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<IMetricsDevice_1_13> : 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<IMetricsDevice_1_13> : public IMetricsDevice_1_13 {
return MetricsDiscovery::CC_OK;
}
void resetMockVars() {
forceGetSymbolByNameFail = false;
forceGetGpuCpuTimestampsFail = false;
forceGetMaxTimestampFail = false;
failGetGpuTimestampFrequencyOnCall = 0;
getGpuTimestampFrequencyCallCount = 0;
}
std::vector<IConcurrentGroup_1_13 *> getConcurrentGroupResults;
};

View File

@@ -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<L0GfxCoreHelper>();
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) {