From b5f8a38f1986476d8ebf4c6e3c43c07388e31f3e Mon Sep 17 00:00:00 2001 From: "Neil R. Spruit" Date: Sat, 9 Mar 2024 01:22:47 +0000 Subject: [PATCH] feature: Enable Per IP euStall Functionality Related-To: NEO-10220 Signed-off-by: Neil R. Spruit --- .../gfx_core_helpers/l0_gfx_core_helper.h | 10 ++ .../l0_gfx_core_helper_skl_to_pvc.inl | 153 +++++++++++++++++- .../test_l0_gfx_core_helper_xe_hpc_core.cpp | 8 + .../linux/os_metric_ip_sampling_imp_linux.cpp | 34 +--- .../metrics/metric_ip_sampling_source.cpp | 138 ++-------------- .../metrics/metric_ip_sampling_source.h | 16 -- .../linux/test_metric_ip_sampling_linux.cpp | 6 +- .../test_metric_ip_sampling_enumeration.cpp | 119 ++++++++------ .../source/os_interface/linux/drm_wrappers.h | 3 + .../source/os_interface/linux/i915_prelim.h | 1 + .../os_interface/linux/ioctl_helper.cpp | 7 +- .../source/os_interface/linux/ioctl_helper.h | 8 +- .../os_interface/linux/ioctl_helper_i915.cpp | 14 +- .../linux/ioctl_helper_prelim.cpp | 32 ++++ .../linux/ioctl_helper_upstream.cpp | 8 + .../os_interface/linux/xe/CMakeLists.txt | 1 + .../os_interface/linux/xe/ioctl_helper_xe.cpp | 9 +- .../os_interface/linux/xe/ioctl_helper_xe.h | 2 + .../linux/xe/ioctl_helper_xe_perf.cpp | 24 +++ shared/test/common/libult/linux/drm_mock.cpp | 12 +- shared/test/common/libult/linux/drm_mock.h | 1 + .../linux/device_command_stream_fixture.h | 3 + .../linux/ioctl_helper_tests_prelim.cpp | 87 ++++++++++ .../linux/ioctl_helper_tests_upstream.cpp | 31 ++++ .../os_interface/linux/xe/CMakeLists.txt | 1 + .../linux/xe/ioctl_helper_xe_perf_tests.cpp | 38 +++++ 26 files changed, 538 insertions(+), 228 deletions(-) create mode 100644 shared/source/os_interface/linux/xe/ioctl_helper_xe_perf.cpp create mode 100644 shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_perf_tests.cpp 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 bffda7c5e7..a1099f4bd7 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 @@ -13,9 +13,11 @@ #include "level_zero/include/zet_intel_gpu_debug.h" #include "level_zero/tools/source/debug/eu_thread.h" #include +#include #include "igfxfmid.h" +#include #include #include @@ -90,6 +92,10 @@ class L0GfxCoreHelper : public NEO::ApiGfxCoreHelper { virtual uint32_t getImmediateWritePostSyncOffset() const = 0; virtual ze_mutable_command_exp_flags_t getCmdListUpdateCapabilities() const = 0; virtual void appendPlatformSpecificExtensions(std::vector> &extensions, const NEO::ProductHelper &productHelper) const = 0; + virtual std::vector> getStallSamplingReportMetrics() const = 0; + virtual void stallSumIpDataToTypedValues(uint64_t ip, void *sumIpData, std::vector &ipDataValues) = 0; + virtual bool stallIpDataMapUpdate(std::map &stallSumIpDataMap, const uint8_t *pRawIpData) = 0; + virtual void stallIpDataMapDelete(std::map &stallSumIpDataMap) = 0; protected: L0GfxCoreHelper() = default; @@ -132,6 +138,10 @@ class L0GfxCoreHelperHw : public L0GfxCoreHelper { uint32_t getImmediateWritePostSyncOffset() const override; ze_mutable_command_exp_flags_t getCmdListUpdateCapabilities() const override; void appendPlatformSpecificExtensions(std::vector> &extensions, const NEO::ProductHelper &productHelper) const override; + std::vector> getStallSamplingReportMetrics() const override; + void stallSumIpDataToTypedValues(uint64_t ip, void *sumIpData, std::vector &ipDataValues) override; + bool stallIpDataMapUpdate(std::map &stallSumIpDataMap, const uint8_t *pRawIpData) override; + void stallIpDataMapDelete(std::map &stallSumIpDataMap) 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 8bb447c9fc..c6fc7c3c8e 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 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,6 +10,8 @@ #include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" +#include + namespace L0 { template @@ -35,4 +37,153 @@ bool L0GfxCoreHelperHw::forceDefaultUsmCompressionSupport() const { return false; } +/* + * stall sample data item format: + * + * Bits Field + * 0 to 28 IP (addr) + * 29 to 36 active count + * 37 to 44 other count + * 45 to 52 control count + * 53 to 60 pipestall count + * 61 to 68 send count + * 69 to 76 dist_acc count + * 77 to 84 sbid count + * 85 to 92 sync count + * 93 to 100 inst_fetch count + * + * bytes 49 and 50, subSlice + * bytes 51 and 52, flags + * + * total size 64 bytes + */ +typedef struct StallSumIpData { + uint64_t activeCount; + uint64_t otherCount; + uint64_t controlCount; + uint64_t pipeStallCount; + uint64_t sendCount; + uint64_t distAccCount; + uint64_t sbidCount; + uint64_t syncCount; + uint64_t instFetchCount; +} StallSumIpData_t; + +template +void L0GfxCoreHelperHw::stallIpDataMapDelete(std::map &stallSumIpDataMap) { + for (auto i = stallSumIpDataMap.begin(); i != stallSumIpDataMap.end(); i++) { + StallSumIpData_t *stallSumData = reinterpret_cast(i->second); + if (stallSumData) { + delete stallSumData; + } + } +} + +template +bool L0GfxCoreHelperHw::stallIpDataMapUpdate(std::map &stallSumIpDataMap, const uint8_t *pRawIpData) { + const uint8_t *tempAddr = pRawIpData; + uint64_t ip = 0ULL; + memcpy_s(reinterpret_cast(&ip), sizeof(ip), tempAddr, sizeof(ip)); + ip &= 0x1fffffff; + StallSumIpData_t *stallSumData = nullptr; + if (stallSumIpDataMap.count(ip) == 0) { + stallSumData = new StallSumIpData_t{}; + stallSumIpDataMap[ip] = stallSumData; + } else { + stallSumData = reinterpret_cast(stallSumIpDataMap[ip]); + } + tempAddr += 3; + + auto getCount = [&tempAddr]() { + uint16_t tempCount = 0; + memcpy_s(reinterpret_cast(&tempCount), sizeof(tempCount), tempAddr, sizeof(tempCount)); + tempCount = (tempCount >> 5) & 0xff; + tempAddr += 1; + return static_cast(tempCount); + }; + + stallSumData->activeCount += getCount(); + stallSumData->otherCount += getCount(); + stallSumData->controlCount += getCount(); + stallSumData->pipeStallCount += getCount(); + stallSumData->sendCount += getCount(); + stallSumData->distAccCount += getCount(); + stallSumData->sbidCount += getCount(); + stallSumData->syncCount += getCount(); + stallSumData->instFetchCount += getCount(); + + struct StallCntrInfo { + uint16_t subslice; + uint16_t flags; + } stallCntrInfo = {}; + + tempAddr = pRawIpData + 48; + memcpy_s(reinterpret_cast(&stallCntrInfo), sizeof(stallCntrInfo), tempAddr, sizeof(stallCntrInfo)); + + constexpr int overflowDropFlag = (1 << 8); + return stallCntrInfo.flags & overflowDropFlag; +} + +// The order of push_back calls must match the order of stallSamplingReportList. +template +void L0GfxCoreHelperHw::stallSumIpDataToTypedValues(uint64_t ip, void *sumIpData, std::vector &ipDataValues) { + StallSumIpData_t *stallSumData = reinterpret_cast(sumIpData); + zet_typed_value_t tmpValueData; + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = ip; + ipDataValues.push_back(tmpValueData); + + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = stallSumData->activeCount; + ipDataValues.push_back(tmpValueData); + + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = stallSumData->controlCount; + ipDataValues.push_back(tmpValueData); + + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = stallSumData->pipeStallCount; + ipDataValues.push_back(tmpValueData); + + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = stallSumData->sendCount; + ipDataValues.push_back(tmpValueData); + + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = stallSumData->distAccCount; + ipDataValues.push_back(tmpValueData); + + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = stallSumData->sbidCount; + ipDataValues.push_back(tmpValueData); + + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = stallSumData->syncCount; + ipDataValues.push_back(tmpValueData); + + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = stallSumData->instFetchCount; + ipDataValues.push_back(tmpValueData); + + tmpValueData.type = ZET_VALUE_TYPE_UINT64; + tmpValueData.value.ui64 = stallSumData->otherCount; + ipDataValues.push_back(tmpValueData); +} + +template +std::vector> L0GfxCoreHelperHw::getStallSamplingReportMetrics() const { + std::vector> stallSamplingReportList = { + {"Active", "Active cycles"}, + {"ControlStall", "Stall on control"}, + {"PipeStall", "Stall on pipe"}, + {"SendStall", "Stall on send"}, + {"DistStall", "Stall on distance"}, + {"SbidStall", "Stall on scoreboard"}, + {"SyncStall", "Stall on sync"}, + {"InstrFetchStall", "Stall on instruction fetch"}, + {"OtherStall", "Stall on other condition"}, + }; + return stallSamplingReportList; +} + } // 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 f886e91ccf..4809ffc9a6 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 @@ -83,5 +83,13 @@ XE_HPC_CORETEST_F(L0GfxCoreHelperTestXeHpc, GivenXeHpcWhenGettingCmdlistUpdateCa EXPECT_EQ(49u, l0GfxCoreHelper.getCmdListUpdateCapabilities()); } +XE_HPC_CORETEST_F(L0GfxCoreHelperTestXeHpc, GivenXeHpcWhenCheckingL0HelperForDeletingIpSamplingEntryWithNullValuesThenMapRemainstheSameSize) { + auto &l0GfxCoreHelper = getHelper(); + std::map stallSumIpDataMap; + stallSumIpDataMap.emplace(std::pair(0ull, nullptr)); + l0GfxCoreHelper.stallIpDataMapDelete(stallSumIpDataMap); + EXPECT_NE(0u, stallSumIpDataMap.size()); +} + } // namespace ult } // namespace L0 diff --git a/level_zero/tools/source/metrics/linux/os_metric_ip_sampling_imp_linux.cpp b/level_zero/tools/source/metrics/linux/os_metric_ip_sampling_imp_linux.cpp index 305682d2ab..bd727ecd23 100644 --- a/level_zero/tools/source/metrics/linux/os_metric_ip_sampling_imp_linux.cpp +++ b/level_zero/tools/source/metrics/linux/os_metric_ip_sampling_imp_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,7 +10,6 @@ #include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/linux/engine_info.h" -#include "shared/source/os_interface/linux/i915.h" #include "shared/source/os_interface/linux/ioctl_helper.h" #include "shared/source/os_interface/linux/sys_calls.h" #include "shared/source/os_interface/os_interface.h" @@ -101,38 +100,19 @@ ze_result_t MetricIpSamplingLinuxImp::startMeasurement(uint32_t ¬ifyEveryNRep return ZE_RESULT_ERROR_UNKNOWN; } - struct drm_i915_perf_open_param param = { - .flags = I915_PERF_FLAG_FD_CLOEXEC | - euStallFdParameter | - I915_PERF_FLAG_FD_NONBLOCK, - .num_properties = sizeof(properties) / 16, - .properties_ptr = reinterpret_cast(properties.data()), - }; - - stream = NEO::SysCalls::ioctl(drm->getFileDescriptor(), DRM_IOCTL_I915_PERF_OPEN, ¶m); - if (stream < 0) { + if (!ioctlHelper->perfOpenEuStallStream(euStallFdParameter, properties, &stream)) { return ZE_RESULT_ERROR_UNKNOWN; } - auto ret = NEO::SysCalls::ioctl(stream, I915_PERF_IOCTL_ENABLE, 0); - PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get() && (ret < 0), stderr, - "PRELIM_I915_PERF_IOCTL_ENABLE failed errno = %d | ret = %d \n", errno, ret); - - return (ret == 0) ? ZE_RESULT_SUCCESS : ZE_RESULT_ERROR_UNKNOWN; + return ZE_RESULT_SUCCESS; } ze_result_t MetricIpSamplingLinuxImp::stopMeasurement() { + const auto drm = device.getOsInterface().getDriverModel()->as(); + auto ioctlHelper = drm->getIoctlHelper(); + bool result = ioctlHelper->perfDisableEuStallStream(&stream); - int disableStatus = NEO::SysCalls::ioctl(stream, I915_PERF_IOCTL_DISABLE, 0); - PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get() && (disableStatus < 0), stderr, - "I915_PERF_IOCTL_DISABLE failed errno = %d | ret = %d \n", errno, disableStatus); - - int closeStatus = NEO::SysCalls::close(stream); - PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get() && (closeStatus < 0), stderr, - "close() failed errno = %d | ret = %d \n", errno, closeStatus); - stream = -1; - - return ((closeStatus == 0) && (disableStatus == 0)) ? ZE_RESULT_SUCCESS : ZE_RESULT_ERROR_UNKNOWN; + return result ? ZE_RESULT_SUCCESS : ZE_RESULT_ERROR_UNKNOWN; } ze_result_t MetricIpSamplingLinuxImp::readData(uint8_t *pRawData, size_t *pRawDataSize) { diff --git a/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp b/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp index 692288cf50..85a2c5ef0c 100644 --- a/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp +++ b/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp @@ -8,11 +8,13 @@ #include "level_zero/tools/source/metrics/metric_ip_sampling_source.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/string.h" #include "level_zero/core/source/device/device.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/include/zet_intel_gpu_metric.h" #include "level_zero/tools/source/metrics/metric.h" #include "level_zero/tools/source/metrics/metric_ip_sampling_streamer.h" @@ -55,8 +57,8 @@ bool IpSamplingMetricSourceImp::isAvailable() { void IpSamplingMetricSourceImp::cacheMetricGroup() { + const auto deviceImp = static_cast(&metricDeviceContext.getDevice()); if (metricDeviceContext.isImplicitScalingCapable()) { - const auto deviceImp = static_cast(&metricDeviceContext.getDevice()); std::vector subDeviceMetricGroup = {}; subDeviceMetricGroup.reserve(deviceImp->subDevices.size()); @@ -95,23 +97,14 @@ void IpSamplingMetricSourceImp::cacheMetricGroup() { strcpy_s(metricProperties.resultUnits, ZET_MAX_METRIC_RESULT_UNITS, "Address"); metrics.push_back(IpSamplingMetricImp(*this, metricProperties)); - std::vector> metricPropertiesList = { - {"Active", "Active cycles"}, - {"ControlStall", "Stall on control"}, - {"PipeStall", "Stall on pipe"}, - {"SendStall", "Stall on send"}, - {"DistStall", "Stall on distance"}, - {"SbidStall", "Stall on scoreboard"}, - {"SyncStall", "Stall on sync"}, - {"InstrFetchStall", "Stall on instruction fetch"}, - {"OtherStall", "Stall on other condition"}, - }; + auto &l0GfxCoreHelper = deviceImp->getNEODevice()->getRootDeviceEnvironment().getHelper(); + std::vector> stallSamplingReportList = l0GfxCoreHelper.getStallSamplingReportMetrics(); // Preparing properties for others because of common values metricProperties.metricType = ZET_METRIC_TYPE_EVENT; strcpy_s(metricProperties.resultUnits, ZET_MAX_METRIC_RESULT_UNITS, "Events"); - for (auto &property : metricPropertiesList) { + for (auto &property : stallSamplingReportList) { strcpy_s(metricProperties.name, ZET_MAX_METRIC_NAME, property.first); strcpy_s(metricProperties.description, ZET_MAX_METRIC_DESCRIPTION, property.second); metrics.push_back(IpSamplingMetricImp(*this, metricProperties)); @@ -419,7 +412,7 @@ ze_result_t IpSamplingMetricGroupImp::getCalculatedMetricValues(const zet_metric uint32_t &metricValueCount, zet_typed_value_t *pCalculatedData) { bool dataOverflow = false; - StallSumIpDataMap_t stallSumIpDataMap; + std::map stallReportDataMap; // MAX_METRIC_VALUES is not supported yet. if (type != ZET_METRIC_GROUP_CALCULATION_TYPE_METRIC_VALUES) { @@ -436,129 +429,28 @@ ze_result_t IpSamplingMetricGroupImp::getCalculatedMetricValues(const zet_metric const uint32_t rawReportCount = static_cast(rawDataSize) / rawReportSize; + DeviceImp *deviceImp = static_cast(&this->getMetricSource().getMetricDeviceContext().getDevice()); + auto &l0GfxCoreHelper = deviceImp->getNEODevice()->getRootDeviceEnvironment().getHelper(); + for (const uint8_t *pRawIpData = pRawData; pRawIpData < pRawData + (rawReportCount * rawReportSize); pRawIpData += rawReportSize) { - dataOverflow |= stallIpDataMapUpdate(stallSumIpDataMap, pRawIpData); + dataOverflow |= l0GfxCoreHelper.stallIpDataMapUpdate(stallReportDataMap, pRawIpData); } - metricValueCount = std::min(metricValueCount, static_cast(stallSumIpDataMap.size()) * properties.metricCount); + metricValueCount = std::min(metricValueCount, static_cast(stallReportDataMap.size()) * properties.metricCount); std::vector ipDataValues; uint32_t i = 0; - for (auto it = stallSumIpDataMap.begin(); it != stallSumIpDataMap.end(); ++it) { - stallSumIpDataToTypedValues(it->first, it->second, ipDataValues); + for (auto it = stallReportDataMap.begin(); it != stallReportDataMap.end(); ++it) { + l0GfxCoreHelper.stallSumIpDataToTypedValues(it->first, it->second, ipDataValues); for (auto jt = ipDataValues.begin(); (jt != ipDataValues.end()) && (i < metricValueCount); jt++, i++) { *(pCalculatedData + i) = *jt; } ipDataValues.clear(); } + l0GfxCoreHelper.stallIpDataMapDelete(stallReportDataMap); return dataOverflow ? ZE_RESULT_WARNING_DROPPED_DATA : ZE_RESULT_SUCCESS; } -/* - * stall sample data item format: - * - * Bits Field - * 0 to 28 IP (addr) - * 29 to 36 active count - * 37 to 44 other count - * 45 to 52 control count - * 53 to 60 pipestall count - * 61 to 68 send count - * 69 to 76 dist_acc count - * 77 to 84 sbid count - * 85 to 92 sync count - * 93 to 100 inst_fetch count - * - * bytes 49 and 50, subSlice - * bytes 51 and 52, flags - * - * total size 64 bytes - */ -bool IpSamplingMetricGroupImp::stallIpDataMapUpdate(StallSumIpDataMap_t &stallSumIpDataMap, const uint8_t *pRawIpData) { - - const uint8_t *tempAddr = pRawIpData; - uint64_t ip = 0ULL; - memcpy_s(reinterpret_cast(&ip), sizeof(ip), tempAddr, sizeof(ip)); - ip &= 0x1fffffff; - StallSumIpData_t &stallSumData = stallSumIpDataMap[ip]; - tempAddr += 3; - - auto getCount = [&tempAddr]() { - uint16_t tempCount = 0; - memcpy_s(reinterpret_cast(&tempCount), sizeof(tempCount), tempAddr, sizeof(tempCount)); - tempCount = (tempCount >> 5) & 0xff; - tempAddr += 1; - return static_cast(tempCount); - }; - - stallSumData.activeCount += getCount(); - stallSumData.otherCount += getCount(); - stallSumData.controlCount += getCount(); - stallSumData.pipeStallCount += getCount(); - stallSumData.sendCount += getCount(); - stallSumData.distAccCount += getCount(); - stallSumData.sbidCount += getCount(); - stallSumData.syncCount += getCount(); - stallSumData.instFetchCount += getCount(); - - struct StallCntrInfo { - uint16_t subslice; - uint16_t flags; - } stallCntrInfo = {}; - - tempAddr = pRawIpData + 48; - memcpy_s(reinterpret_cast(&stallCntrInfo), sizeof(stallCntrInfo), tempAddr, sizeof(stallCntrInfo)); - - constexpr int overflowDropFlag = (1 << 8); - return stallCntrInfo.flags & overflowDropFlag; -} - -// The order of push_back calls must match the order of metricPropertiesList. -void IpSamplingMetricGroupImp::stallSumIpDataToTypedValues(uint64_t ip, - StallSumIpData_t &sumIpData, - std::vector &ipDataValues) { - zet_typed_value_t tmpValueData; - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = ip; - ipDataValues.push_back(tmpValueData); - - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = sumIpData.activeCount; - ipDataValues.push_back(tmpValueData); - - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = sumIpData.controlCount; - ipDataValues.push_back(tmpValueData); - - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = sumIpData.pipeStallCount; - ipDataValues.push_back(tmpValueData); - - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = sumIpData.sendCount; - ipDataValues.push_back(tmpValueData); - - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = sumIpData.distAccCount; - ipDataValues.push_back(tmpValueData); - - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = sumIpData.sbidCount; - ipDataValues.push_back(tmpValueData); - - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = sumIpData.syncCount; - ipDataValues.push_back(tmpValueData); - - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = sumIpData.instFetchCount; - ipDataValues.push_back(tmpValueData); - - tmpValueData.type = ZET_VALUE_TYPE_UINT64; - tmpValueData.value.ui64 = sumIpData.otherCount; - ipDataValues.push_back(tmpValueData); -} - zet_metric_group_handle_t IpSamplingMetricGroupImp::getMetricGroupForSubDevice(const uint32_t subDeviceIndex) { return toHandle(); } diff --git a/level_zero/tools/source/metrics/metric_ip_sampling_source.h b/level_zero/tools/source/metrics/metric_ip_sampling_source.h index 723473817b..ddf333b57b 100644 --- a/level_zero/tools/source/metrics/metric_ip_sampling_source.h +++ b/level_zero/tools/source/metrics/metric_ip_sampling_source.h @@ -53,20 +53,6 @@ class IpSamplingMetricSourceImp : public MetricSource { std::unique_ptr activationTracker{}; }; -typedef struct StallSumIpData { - uint64_t activeCount; - uint64_t otherCount; - uint64_t controlCount; - uint64_t pipeStallCount; - uint64_t sendCount; - uint64_t distAccCount; - uint64_t sbidCount; - uint64_t syncCount; - uint64_t instFetchCount; -} StallSumIpData_t; - -typedef std::map StallSumIpDataMap_t; - struct IpSamplingMetricGroupBase : public MetricGroupImp { IpSamplingMetricGroupBase(MetricSource &metricSource) : MetricGroupImp(metricSource) {} static constexpr uint32_t rawReportSize = 64u; @@ -130,8 +116,6 @@ struct IpSamplingMetricGroupImp : public IpSamplingMetricGroupBase { ze_result_t getCalculatedMetricValues(const zet_metric_group_calculation_type_t type, const size_t rawDataSize, const uint8_t *pRawData, uint32_t &metricValueCount, zet_typed_value_t *pCalculatedData); - bool stallIpDataMapUpdate(StallSumIpDataMap_t &, const uint8_t *pRawIpData); - void stallSumIpDataToTypedValues(uint64_t ip, StallSumIpData_t &sumIpData, std::vector &ipDataValues); bool isMultiDeviceCaptureData(const size_t rawDataSize, const uint8_t *pRawData); }; diff --git a/level_zero/tools/test/unit_tests/sources/metrics/linux/test_metric_ip_sampling_linux.cpp b/level_zero/tools/test/unit_tests/sources/metrics/linux/test_metric_ip_sampling_linux.cpp index 70ee57998b..fcc6b93b63 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/linux/test_metric_ip_sampling_linux.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/linux/test_metric_ip_sampling_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -27,7 +27,9 @@ class MetricIpSamplingLinuxTest : public DeviceFixture, std::unique_ptr metricIpSamplingOsInterface = nullptr; }; -HWTEST2_F(MetricIpSamplingLinuxTest, GivenUnsupportedProductFamilyIsUsedWhenIsDependencyAvailableIsCalledThenReturnFailure, IsNotXeHpcCore) { +using IsNotGen9ThruPVC = IsNotWithinProducts; + +HWTEST2_F(MetricIpSamplingLinuxTest, GivenUnsupportedProductFamilyIsUsedWhenIsDependencyAvailableIsCalledThenReturnFailure, IsNotGen9ThruPVC) { EXPECT_FALSE(metricIpSamplingOsInterface->isDependencyAvailable()); } diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp index 0ccca84907..f1de07094c 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp @@ -6,6 +6,7 @@ */ #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/test_macros/test_base.h" #include "level_zero/core/source/cmdlist/cmdlist.h" @@ -23,9 +24,11 @@ extern _ze_driver_handle_t *globalDriverHandle; namespace ult { +using IsGen9ThruPVC = IsWithinProducts; + using MetricIpSamplingEnumerationTest = MetricIpSamplingFixture; -TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenInititializingThenSuccessIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenInititializingThenSuccessIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -34,13 +37,13 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenInititiali } } -TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesUnAvailableForRootDeviceWhenInititializingThenFailureIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesUnAvailableForRootDeviceWhenInititializingThenFailureIsReturned, IsGen9ThruPVC) { osInterfaceVector[0]->isDependencyAvailableReturn = false; EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, testDevices[0]->getMetricDeviceContext().enableMetricApi()); } -TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesUnAvailableForSubDeviceWhenInititializingThenFailureIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesUnAvailableForSubDeviceWhenInititializingThenFailureIsReturned, IsGen9ThruPVC) { osInterfaceVector[1]->isDependencyAvailableReturn = false; EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -55,7 +58,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesUnAvailableForSubDevice EXPECT_TRUE(metricSource1.isAvailable()); } -TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGroupGetIsCalledThenValidMetricGroupIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGroupGetIsCalledThenValidMetricGroupIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -72,7 +75,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGrou } } -TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGroupGetIsCalledMultipleTimesThenValidMetricGroupIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGroupGetIsCalledMultipleTimesThenValidMetricGroupIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -91,7 +94,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGrou } } -TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGroupGetIsCalledThenMetricGroupWithCorrectPropertiesIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGroupGetIsCalledThenMetricGroupWithCorrectPropertiesIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -116,19 +119,19 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGrou } } -TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGroupGetIsCalledThenCorrectMetricsAreReturned) { +struct TestMetricProperties { + const char *name; + const char *description; + const char *component; + uint32_t tierNumber; + zet_metric_type_t metricType; + zet_value_type_t resultType; + const char *resultUnits; +}; - struct MetricProperties { - const char *name; - const char *description; - const char *component; - uint32_t tierNumber; - zet_metric_type_t metricType; - zet_value_type_t resultType; - const char *resultUnits; - }; +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGroupGetIsCalledThenCorrectMetricsAreReturned, IsGen9ThruPVC) { - std::vector expectedProperties = { + std::vector expectedProperties = { {"IP", "IP address", "XVE", 4, ZET_METRIC_TYPE_IP, ZET_VALUE_TYPE_UINT64, "Address"}, {"Active", "Active cycles", "XVE", 4, ZET_METRIC_TYPE_EVENT, ZET_VALUE_TYPE_UINT64, "Events"}, {"ControlStall", "Stall on control", "XVE", 4, ZET_METRIC_TYPE_EVENT, ZET_VALUE_TYPE_UINT64, "Events"}, @@ -162,7 +165,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGrou EXPECT_EQ(metricCount, metricGroupProperties.metricCount); EXPECT_EQ(zetMetricGet(metricGroups[0], &metricCount, metricHandles.data()), ZE_RESULT_SUCCESS); - std::vector::iterator propertiesIter = expectedProperties.begin(); + std::vector::iterator propertiesIter = expectedProperties.begin(); zet_metric_properties_t ipSamplingMetricProperties = {}; for (auto &metricHandle : metricHandles) { @@ -179,8 +182,28 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGrou } } } +using IsNotGen9ThruPVC = IsNotWithinProducts; +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnableMetricAPIOnUnsupportedPlatformsThenFailureIsReturned, IsNotGen9ThruPVC) { + EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); -TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulThenDummyActivationAndDeActivationHappens) { + for (auto device : testDevices) { + + uint32_t metricGroupCount = 0; + zetMetricGroupGet(device->toHandle(), &metricGroupCount, nullptr); + std::vector metricGroups; + metricGroups.resize(metricGroupCount); + ASSERT_EQ(zetMetricGroupGet(device->toHandle(), &metricGroupCount, metricGroups.data()), ZE_RESULT_SUCCESS); + ASSERT_NE(metricGroups[0], nullptr); + zet_metric_group_properties_t metricGroupProperties = {ZET_STRUCTURE_TYPE_METRIC_GROUP_PROPERTIES, nullptr}; + EXPECT_EQ(zetMetricGroupGetProperties(metricGroups[0], &metricGroupProperties), ZE_RESULT_SUCCESS); + + EXPECT_EQ(zetContextActivateMetricGroups(context->toHandle(), device->toHandle(), 1, &metricGroups[0]), ZE_RESULT_SUCCESS); + static_cast(device)->activateMetricGroups(); + EXPECT_EQ(zetContextActivateMetricGroups(context->toHandle(), device->toHandle(), 0, nullptr), ZE_RESULT_SUCCESS); + } +} + +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulThenDummyActivationAndDeActivationHappens, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -201,7 +224,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulThenDummyAct } } -TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulThenUnsupportedApisForMetricGroupReturnsFailure) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulThenUnsupportedApisForMetricGroupReturnsFailure, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -229,7 +252,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulThenUnsuppor } } -TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenReadingMetricsFrequencyAndValidBitsThenConfirmAreTheSameAsDevice) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenReadingMetricsFrequencyAndValidBitsThenConfirmAreTheSameAsDevice, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -259,7 +282,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenReadingM } } -TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulOnMulitDeviceWhenReadingMetricsTimestampThenResultIsSuccess) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulOnMulitDeviceWhenReadingMetricsTimestampThenResultIsSuccess, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -287,7 +310,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulOnMulitDevic using MetricIpSamplingTimestampTest = MetricIpSamplingTimestampFixture; -TEST_F(MetricIpSamplingTimestampTest, GivenEnumerationIsSuccessfulWhenReadingMetricsFrequencyThenValuesAreUpdated) { +HWTEST2_F(MetricIpSamplingTimestampTest, GivenEnumerationIsSuccessfulWhenReadingMetricsFrequencyThenValuesAreUpdated, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, device->getMetricDeviceContext().enableMetricApi()); @@ -329,7 +352,7 @@ TEST_F(MetricIpSamplingTimestampTest, GivenEnumerationIsSuccessfulWhenReadingMet EXPECT_NE(metricTimestamp, 0UL); } -TEST_F(MetricIpSamplingTimestampTest, GivenGetGpuCpuTimeIsFalseWhenReadingMetricsFrequencyThenValuesAreZero) { +HWTEST2_F(MetricIpSamplingTimestampTest, GivenGetGpuCpuTimeIsFalseWhenReadingMetricsFrequencyThenValuesAreZero, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, device->getMetricDeviceContext().enableMetricApi()); @@ -359,7 +382,7 @@ TEST_F(MetricIpSamplingTimestampTest, GivenGetGpuCpuTimeIsFalseWhenReadingMetric using MetricIpSamplingCalculateMetricsTest = MetricIpSamplingCalculateMetricsFixture; -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledThenValidDataIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledThenValidDataIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); std::vector metricValues(30); @@ -411,7 +434,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithInvalidHeaderThenErrorIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithInvalidHeaderThenErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); std::vector metricValues(30); @@ -450,7 +473,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithDataFromSingleDeviceThenValidDataIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithDataFromSingleDeviceThenValidDataIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); std::vector metricValues(30); @@ -499,7 +522,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithDataFromSingleDeviceAndInvalidRawDataThenErrorIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithDataFromSingleDeviceAndInvalidRawDataThenErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); std::vector metricValues(30); @@ -530,7 +553,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithLessThanRequiredMetricCountThenValidDataIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithLessThanRequiredMetricCountThenValidDataIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); std::vector metricValues(30); @@ -588,7 +611,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithInvalidRawDataSizeThenErrorIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpIsCalledWithInvalidRawDataSizeThenErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -617,7 +640,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, WhenCalculateMultipleMetricValuesExpIsCalledWithInvalidRawDataSizeDuringValueCalculationPhaseThenErrorIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, WhenCalculateMultipleMetricValuesExpIsCalledWithInvalidRawDataSizeDuringValueCalculationPhaseThenErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); std::vector metricValues(30); @@ -654,7 +677,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, WhenCalculateMultipleMetricValuesEx } } -TEST_F(MetricIpSamplingCalculateMetricsTest, WhenCalculateMultipleMetricValuesExpCalculateSizeIsCalledWithInvalidRawDataSizeInHeaderDuringSizeCalculationThenErrorIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, WhenCalculateMultipleMetricValuesExpCalculateSizeIsCalledWithInvalidRawDataSizeInHeaderDuringSizeCalculationThenErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -683,7 +706,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, WhenCalculateMultipleMetricValuesEx } } -TEST_F(MetricIpSamplingCalculateMetricsTest, WhenCalculateMultipleMetricValuesExpCalculateSizeIsCalledWithInvalidRawDataSizeInHeaderThenErrorIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, WhenCalculateMultipleMetricValuesExpCalculateSizeIsCalledWithInvalidRawDataSizeInHeaderThenErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -713,7 +736,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, WhenCalculateMultipleMetricValuesEx } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpCalculateDataWithBadRawDataSizeIsCalledThenErrorUnknownIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMultipleMetricValuesExpCalculateDataWithBadRawDataSizeIsCalledThenErrorUnknownIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -758,7 +781,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMetricValuesIsCalledThenValidDataIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMetricValuesIsCalledThenValidDataIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -792,7 +815,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMetricValuesIsCalledWithDataFromMultipleSubdevicesThenReturnError) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMetricValuesIsCalledWithDataFromMultipleSubdevicesThenReturnError, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -820,7 +843,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMetricValuesIsCalledWithSmallValueCountThenValidDataIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMetricValuesIsCalledWithSmallValueCountThenValidDataIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -855,7 +878,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWithBadRawDataSizeWhenCalculateMetricValuesCalculateSizeIsCalledThenErrorUnknownIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWithBadRawDataSizeWhenCalculateMetricValuesCalculateSizeIsCalledThenErrorUnknownIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -878,7 +901,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWithBad } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMetricValuesWithBadRawDataSizeCalculateDataIsCalledThenUnsupportedFeatureIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCalculateMetricValuesWithBadRawDataSizeCalculateDataIsCalledThenUnsupportedFeatureIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -907,7 +930,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWhenCal } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenDataOverflowOccurredWhenStreamerReadDataIscalledThenCalculateMultipleMetricsValulesExpReturnsOverflowWarning) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenDataOverflowOccurredWhenStreamerReadDataIscalledThenCalculateMultipleMetricsValulesExpReturnsOverflowWarning, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); std::vector metricValues(30); @@ -957,7 +980,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenDataOverflowOccurredWhenStream } } -TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWithCALCULATIONTYPEMAXWhenCalculateMetricValuesIsCalledThenErrorUnknownIsReturned) { +HWTEST2_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWithCALCULATIONTYPEMAXWhenCalculateMetricValuesIsCalledThenErrorUnknownIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); @@ -986,7 +1009,7 @@ TEST_F(MetricIpSamplingCalculateMetricsTest, GivenEnumerationIsSuccessfulWithCAL } } -TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenQueryPoolCreateIsCalledThenUnsupportedFeatureIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenQueryPoolCreateIsCalledThenUnsupportedFeatureIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -1009,7 +1032,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenQueryPoo } } -TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenAppendMetricMemoryBarrierIsCalledThenUnsupportedFeatureIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenAppendMetricMemoryBarrierIsCalledThenUnsupportedFeatureIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); auto &device = testDevices[0]; @@ -1021,7 +1044,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenAppendMe using MetricExportDataIpSamplingTest = MetricIpSamplingEnumerationTest; -TEST_F(MetricExportDataIpSamplingTest, WhenMetricGroupGetExportDataIsCalledThenReturnSuccess) { +HWTEST2_F(MetricExportDataIpSamplingTest, WhenMetricGroupGetExportDataIsCalledThenReturnSuccess, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -1053,7 +1076,7 @@ TEST_F(MetricExportDataIpSamplingTest, WhenMetricGroupGetExportDataIsCalledThenR } } -TEST_F(MetricExportDataIpSamplingTest, GivenIncorrectExportDataSizeWhenMetricGroupGetExportDataIsCalledThenErrorIsReturned) { +HWTEST2_F(MetricExportDataIpSamplingTest, GivenIncorrectExportDataSizeWhenMetricGroupGetExportDataIsCalledThenErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -1094,7 +1117,7 @@ class MockMultiDomainDeferredActivationTracker : public MultiDomainDeferredActiv } }; -TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulAndActivationFailsThenErrorIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulAndActivationFailsThenErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -1116,7 +1139,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulAndActivatio } } -TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenUnsupportedFunctionsAreCalledErrorIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenUnsupportedFunctionsAreCalledErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { @@ -1134,7 +1157,7 @@ TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenUnsuppor } } -TEST_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenUnsupportedFunctionsForDeviceContextAreCalledErrorIsReturned) { +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenUnsupportedFunctionsForDeviceContextAreCalledErrorIsReturned, IsGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); for (auto device : testDevices) { diff --git a/shared/source/os_interface/linux/drm_wrappers.h b/shared/source/os_interface/linux/drm_wrappers.h index ea354d0d52..a83eeafbde 100644 --- a/shared/source/os_interface/linux/drm_wrappers.h +++ b/shared/source/os_interface/linux/drm_wrappers.h @@ -265,6 +265,9 @@ enum class DrmIoctl { vmExport, metadataCreate, metadataDestroy, + perfOpen, + perfEnable, + perfDisable }; enum class DrmParam { diff --git a/shared/source/os_interface/linux/i915_prelim.h b/shared/source/os_interface/linux/i915_prelim.h index cb1e55ca48..a72f6ce24e 100644 --- a/shared/source/os_interface/linux/i915_prelim.h +++ b/shared/source/os_interface/linux/i915_prelim.h @@ -32,6 +32,7 @@ using NEO::PrelimI915::drm_i915_gem_vm_control; using NEO::PrelimI915::drm_i915_gem_wait; using NEO::PrelimI915::drm_i915_getparam_t; using NEO::PrelimI915::drm_i915_memory_region_info; +using NEO::PrelimI915::drm_i915_perf_open_param; using NEO::PrelimI915::drm_i915_query; using NEO::PrelimI915::drm_i915_query_engine_info; using NEO::PrelimI915::drm_i915_query_memory_regions; diff --git a/shared/source/os_interface/linux/ioctl_helper.cpp b/shared/source/os_interface/linux/ioctl_helper.cpp index 1697b4a086..c53ea33ffb 100644 --- a/shared/source/os_interface/linux/ioctl_helper.cpp +++ b/shared/source/os_interface/linux/ioctl_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,6 +13,7 @@ #include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/linux/drm_wrappers.h" +#include "shared/source/os_interface/linux/sys_calls.h" #include "drm/drm.h" @@ -25,6 +26,10 @@ int IoctlHelper::ioctl(DrmIoctl request, void *arg) { return drm.ioctl(request, arg); } +int IoctlHelper::ioctl(int fd, DrmIoctl request, void *arg) { + return NEO::SysCalls::ioctl(fd, getIoctlRequestValue(request), arg); +} + void IoctlHelper::setupIpVersion() { auto &rootDeviceEnvironment = drm.getRootDeviceEnvironment(); auto &hwInfo = *rootDeviceEnvironment.getMutableHardwareInfo(); diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index 8b45b79c99..e40ca5bbd9 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -90,6 +90,7 @@ class IoctlHelper { virtual ~IoctlHelper() {} static std::unique_ptr getI915Helper(const PRODUCT_FAMILY productFamily, const std::string &prelimVersion, Drm &drm); virtual int ioctl(DrmIoctl request, void *arg); + virtual int ioctl(int fd, DrmIoctl request, void *arg); virtual bool initialize() = 0; virtual bool isSetPairAvailable() = 0; @@ -135,6 +136,8 @@ class IoctlHelper { virtual bool getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) = 0; virtual uint32_t getEuStallFdParameter() = 0; + virtual bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array &properties, int32_t *stream) = 0; + virtual bool perfDisableEuStallStream(int32_t *stream) = 0; virtual UuidRegisterResult registerUuid(const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) = 0; virtual UuidRegisterResult registerStringClassUuid(const std::string &uuid, uint64_t ptr, uint64_t size) = 0; virtual int unregisterUuid(uint32_t handle) = 0; @@ -272,6 +275,8 @@ class IoctlHelperUpstream : public IoctlHelperI915 { bool getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) override; uint32_t getEuStallFdParameter() override; + bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array &properties, int32_t *stream) override; + bool perfDisableEuStallStream(int32_t *stream) override; UuidRegisterResult registerUuid(const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) override; UuidRegisterResult registerStringClassUuid(const std::string &uuid, uint64_t ptr, uint64_t size) override; int unregisterUuid(uint32_t handle) override; @@ -306,7 +311,6 @@ class IoctlHelperImpl : public IoctlHelperUpstream { class IoctlHelperPrelim20 : public IoctlHelperI915 { public: IoctlHelperPrelim20(Drm &drmArg); - bool initialize() override; bool isSetPairAvailable() override; bool isChunkingAvailable() override; @@ -347,6 +351,8 @@ class IoctlHelperPrelim20 : public IoctlHelperI915 { int getResetStats(ResetStats &resetStats, uint32_t *status, ResetStatsFault *resetStatsFault) override; bool getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) override; + bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array &properties, int32_t *stream) override; + bool perfDisableEuStallStream(int32_t *stream) override; uint32_t getEuStallFdParameter() override; UuidRegisterResult registerUuid(const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) override; UuidRegisterResult registerStringClassUuid(const std::string &uuid, uint64_t ptr, uint64_t size) override; diff --git a/shared/source/os_interface/linux/ioctl_helper_i915.cpp b/shared/source/os_interface/linux/ioctl_helper_i915.cpp index f8e9f7ba10..2e454f29b6 100644 --- a/shared/source/os_interface/linux/ioctl_helper_i915.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_i915.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -312,6 +312,12 @@ unsigned int IoctlHelperI915::getIoctlRequestValue(DrmIoctl ioctlRequest) const return DRM_IOCTL_I915_GEM_VM_CREATE; case DrmIoctl::gemVmDestroy: return DRM_IOCTL_I915_GEM_VM_DESTROY; + case DrmIoctl::perfOpen: + return DRM_IOCTL_I915_PERF_OPEN; + case DrmIoctl::perfEnable: + return I915_PERF_IOCTL_ENABLE; + case DrmIoctl::perfDisable: + return I915_PERF_IOCTL_DISABLE; default: return getIoctlRequestValueBase(ioctlRequest); } @@ -393,6 +399,12 @@ std::string IoctlHelperI915::getIoctlString(DrmIoctl ioctlRequest) const { return "DRM_IOCTL_I915_GEM_VM_CREATE"; case DrmIoctl::gemVmDestroy: return "DRM_IOCTL_I915_GEM_VM_DESTROY"; + case DrmIoctl::perfOpen: + return "DRM_IOCTL_I915_PERF_OPEN"; + case DrmIoctl::perfEnable: + return "I915_PERF_IOCTL_ENABLE"; + case DrmIoctl::perfDisable: + return "I915_PERF_IOCTL_DISABLE"; default: return getIoctlStringBase(ioctlRequest); } diff --git a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp index 06c7eee3a4..e87b6ca8f7 100644 --- a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp @@ -575,6 +575,38 @@ uint32_t IoctlHelperPrelim20::getEuStallFdParameter() { return PRELIM_I915_PERF_FLAG_FD_EU_STALL; } +bool IoctlHelperPrelim20::perfOpenEuStallStream(uint32_t euStallFdParameter, std::array &properties, int32_t *stream) { + NEO::PrelimI915::drm_i915_perf_open_param param = { + .flags = I915_PERF_FLAG_FD_CLOEXEC | + euStallFdParameter | + I915_PERF_FLAG_FD_NONBLOCK, + .num_properties = sizeof(properties) / 16, + .properties_ptr = reinterpret_cast(properties.data()), + }; + *stream = ioctl(DrmIoctl::perfOpen, ¶m); + if (*stream < 0) { + PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get() && (*stream < 0), stderr, + "%s failed errno = %d | ret = %d \n", "DRM_IOCTL_I915_PERF_OPEN", errno, *stream); + return false; + } + auto ret = ioctl(*stream, DrmIoctl::perfEnable, 0); + PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get() && (ret < 0), stderr, + "%s failed errno = %d | ret = %d \n", "I915_PERF_IOCTL_ENABLE", errno, ret); + return (ret == 0) ? true : false; +} + +bool IoctlHelperPrelim20::perfDisableEuStallStream(int32_t *stream) { + int disableStatus = ioctl(*stream, DrmIoctl::perfDisable, 0); + PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get() && (disableStatus < 0), stderr, + "I915_PERF_IOCTL_DISABLE failed errno = %d | ret = %d \n", errno, disableStatus); + + int closeStatus = NEO::SysCalls::close(*stream); + PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get() && (closeStatus < 0), stderr, + "close() failed errno = %d | ret = %d \n", errno, closeStatus); + *stream = -1; + return ((closeStatus == 0) && (disableStatus == 0)) ? true : false; +} + std::unique_ptr IoctlHelperPrelim20::createVmControlExtRegion(const std::optional ®ionInstanceClass) { if (regionInstanceClass) { diff --git a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp index 56ae71bf3b..839d483526 100644 --- a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp @@ -205,6 +205,14 @@ uint32_t IoctlHelperUpstream::getEuStallFdParameter() { return 0u; } +bool IoctlHelperUpstream::perfOpenEuStallStream(uint32_t euStallFdParameter, std::array &properties, int32_t *stream) { + return false; +} + +bool IoctlHelperUpstream::perfDisableEuStallStream(int32_t *stream) { + return false; +} + std::unique_ptr IoctlHelperUpstream::createVmControlExtRegion(const std::optional ®ionInstanceClass) { return {}; } diff --git a/shared/source/os_interface/linux/xe/CMakeLists.txt b/shared/source/os_interface/linux/xe/CMakeLists.txt index 3049459b49..f95e38f77f 100644 --- a/shared/source/os_interface/linux/xe/CMakeLists.txt +++ b/shared/source/os_interface/linux/xe/CMakeLists.txt @@ -11,6 +11,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX_XE ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_debugger.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_xe_string_value_getter.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_xe_vm_export.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_xe_perf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe.h ) diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index 7429f45568..5d3392f9d2 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -26,6 +26,7 @@ #include "shared/source/os_interface/linux/engine_info.h" #include "shared/source/os_interface/linux/memory_info.h" #include "shared/source/os_interface/linux/os_context_linux.h" +#include "shared/source/os_interface/linux/sys_calls.h" #include "shared/source/os_interface/os_time.h" #include "drm/xe_drm.h" @@ -769,15 +770,9 @@ std::optional IoctlHelperXe::getHasPageFaultParamId() { return {}; }; -bool IoctlHelperXe::getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, - uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) { - xeLog(" -> IoctlHelperXe::%s\n", __FUNCTION__); - return false; -} - uint32_t IoctlHelperXe::getEuStallFdParameter() { xeLog(" -> IoctlHelperXe::%s\n", __FUNCTION__); - return 0; + return 0u; } std::unique_ptr IoctlHelperXe::createVmControlExtRegion(const std::optional ®ionInstanceClass) { diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h index 828f69cd1b..4a60b013fd 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -98,6 +98,8 @@ class IoctlHelperXe : public IoctlHelper { bool getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) override; uint32_t getEuStallFdParameter() override; + bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array &properties, int32_t *stream) override; + bool perfDisableEuStallStream(int32_t *stream) override; UuidRegisterResult registerUuid(const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) override; UuidRegisterResult registerStringClassUuid(const std::string &uuid, uint64_t ptr, uint64_t size) override; int unregisterUuid(uint32_t handle) override; diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe_perf.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe_perf.cpp new file mode 100644 index 0000000000..11c29d1697 --- /dev/null +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe_perf.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" + +#include "drm/xe_drm.h" + +namespace NEO { +bool IoctlHelperXe::perfOpenEuStallStream(uint32_t euStallFdParameter, std::array &properties, int32_t *stream) { + return false; +} + +bool IoctlHelperXe::perfDisableEuStallStream(int32_t *stream) { + return false; +} +bool IoctlHelperXe::getEuStallProperties(std::array &properties, uint64_t dssBufferSize, uint64_t samplingRate, + uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) { + return false; +} +} // namespace NEO \ No newline at end of file diff --git a/shared/test/common/libult/linux/drm_mock.cpp b/shared/test/common/libult/linux/drm_mock.cpp index 6e38b008e7..2adaced3cc 100644 --- a/shared/test/common/libult/linux/drm_mock.cpp +++ b/shared/test/common/libult/linux/drm_mock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,6 +11,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/linux/i915.h" +#include "shared/source/os_interface/linux/sys_calls.h" #include "gtest/gtest.h" @@ -127,6 +128,15 @@ int DrmMock::ioctl(DrmIoctl request, void *arg) { } } + if ((request == DrmIoctl::perfOpen) && (arg != nullptr)) { + ioctlCount.perfOpen++; + if (failPerfOpen) { + return -1; + } else { + return NEO::SysCalls::ioctl(mockFd, DRM_IOCTL_I915_PERF_OPEN, arg); + } + } + if ((request == DrmIoctl::gemVmCreate) && (arg != nullptr)) { ioctlCount.gemVmCreate++; auto gemVmControl = static_cast(arg); diff --git a/shared/test/common/libult/linux/drm_mock.h b/shared/test/common/libult/linux/drm_mock.h index 5914caf1cb..6d6a4a401f 100644 --- a/shared/test/common/libult/linux/drm_mock.h +++ b/shared/test/common/libult/linux/drm_mock.h @@ -222,6 +222,7 @@ class DrmMock : public Drm { bool unrecoverableContextSet = false; bool failRetHwIpVersion = false; bool returnInvalidHwIpVersionLength = false; + bool failPerfOpen = false; bool capturedCooperativeContextRequest = false; bool incrementVmId = false; diff --git a/shared/test/common/os_interface/linux/device_command_stream_fixture.h b/shared/test/common/os_interface/linux/device_command_stream_fixture.h index 379e59e197..1b162d6d9c 100644 --- a/shared/test/common/os_interface/linux/device_command_stream_fixture.h +++ b/shared/test/common/os_interface/linux/device_command_stream_fixture.h @@ -52,6 +52,9 @@ class Ioctls { std::atomic contextSetParam; std::atomic contextCreate; std::atomic contextDestroy; + std::atomic perfOpen; + std::atomic perfEnable; + std::atomic perfDisable; }; class DrmMockSuccess : public Drm { diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp index 3a786a2882..000b5f3aec 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp @@ -10,6 +10,7 @@ #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/linux/i915_prelim.h" #include "shared/source/os_interface/linux/ioctl_helper.h" +#include "shared/source/os_interface/linux/sys_calls.h" #include "shared/source/os_interface/product_helper.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/variable_backup.h" @@ -85,6 +86,9 @@ TEST_F(IoctlPrelimHelperTests, whenGettingIoctlRequestValueThenPropertValueIsRet EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::gemMmapOffset), static_cast(DRM_IOCTL_I915_GEM_MMAP_OFFSET)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::gemVmCreate), static_cast(DRM_IOCTL_I915_GEM_VM_CREATE)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::gemVmDestroy), static_cast(DRM_IOCTL_I915_GEM_VM_DESTROY)); + EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::perfOpen), static_cast(DRM_IOCTL_I915_PERF_OPEN)); + EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::perfEnable), static_cast(I915_PERF_IOCTL_ENABLE)); + EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::perfDisable), static_cast(I915_PERF_IOCTL_DISABLE)); EXPECT_THROW(ioctlHelper.getIoctlRequestValue(DrmIoctl::dg1GemCreateExt), std::runtime_error); } @@ -138,6 +142,9 @@ TEST_F(IoctlPrelimHelperTests, whenGettingIoctlRequestStringThenProperStringIsRe EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::gemMmapOffset).c_str(), "DRM_IOCTL_I915_GEM_MMAP_OFFSET"); EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::gemVmCreate).c_str(), "DRM_IOCTL_I915_GEM_VM_CREATE"); EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::gemVmDestroy).c_str(), "DRM_IOCTL_I915_GEM_VM_DESTROY"); + EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::perfOpen).c_str(), "DRM_IOCTL_I915_PERF_OPEN"); + EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::perfEnable).c_str(), "I915_PERF_IOCTL_ENABLE"); + EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::perfDisable).c_str(), "I915_PERF_IOCTL_DISABLE"); EXPECT_THROW(ioctlHelper.getIoctlString(DrmIoctl::dg1GemCreateExt), std::runtime_error); } @@ -376,6 +383,14 @@ TEST_F(IoctlPrelimHelperTests, givenPrelimWhenGettingEuStallPropertiesThenCorrec EXPECT_EQ(properties[11], 20u); } +TEST_F(IoctlPrelimHelperTests, givenPrelimWhenCallingPerfOpenEuStallStreamWithInvalidArgumentsThenFailureReturned) { + std::array properties = {}; + int32_t invalid_stream = -1; + DrmMock *mockDrm = reinterpret_cast(drm.get()); + mockDrm->failPerfOpen = true; + EXPECT_FALSE(ioctlHelper.perfOpenEuStallStream(0u, properties, &invalid_stream)); +} + TEST_F(IoctlPrelimHelperTests, givenPrelimWhenGettingEuStallFdParameterThenCorrectIoctlValueIsReturned) { EXPECT_EQ(static_cast(PRELIM_I915_PERF_FLAG_FD_EU_STALL), ioctlHelper.getEuStallFdParameter()); } @@ -414,6 +429,19 @@ struct MockIoctlHelperPrelim20 : IoctlHelperPrelim20 { return IoctlHelperPrelim20::ioctl(request, arg); } + int ioctl(int fd, DrmIoctl request, void *arg) override { + if (request == DrmIoctl::perfDisable) { + if (failPerfDisable) { + return -1; + } + } + if (request == DrmIoctl::perfEnable) { + if (failPerfEnable) { + return -1; + } + } + return IoctlHelperPrelim20::ioctl(fd, request, arg); + } bool checkWhetherGemCreateExtContainsMemPolicy(void *arg) { auto &gemCreateExt = *reinterpret_cast(arg); auto pExtensionBase = reinterpret_cast(gemCreateExt.extensions); @@ -435,6 +463,8 @@ struct MockIoctlHelperPrelim20 : IoctlHelperPrelim20 { } size_t ioctlCallCount = 0; bool lastGemCreateContainedMemPolicy = false; + bool failPerfDisable = false; + bool failPerfEnable = false; std::optional overrideGemCreateExtReturnValue{}; uint32_t lastPolicyMode = 0; uint32_t lastPolicyFlags = 0; @@ -499,6 +529,63 @@ TEST(IoctlPrelimHelperCreateGemExtTests, givenPrelimWhenCreateGemExtWithMemPolic EXPECT_EQ(memPolicy, mockIoctlHelper.lastPolicyNodeMask); } +TEST(IoctlPrelimHelperPerfTests, givenCalltoPerfDisableEuStallStreamWithValidStreamButCloseFailsThenFailureReturned) { + VariableBackup mockClose(&NEO::SysCalls::sysCallsClose, [](int fileDescriptor) -> int { + return -1; + }); + + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + MockIoctlHelperPrelim20 mockIoctlHelper{*drm}; + + mockIoctlHelper.initialize(); + NEO::SysCalls::closeFuncCalled = 0; + NEO::SysCalls::closeFuncRetVal = -1; + int32_t invalidFd = 10; + EXPECT_FALSE(mockIoctlHelper.perfDisableEuStallStream(&invalidFd)); + EXPECT_EQ(1u, NEO::SysCalls::closeFuncCalled); + EXPECT_EQ(10, NEO::SysCalls::closeFuncArgPassed); + NEO::SysCalls::closeFuncCalled = 0; + NEO::SysCalls::closeFuncArgPassed = 0; + NEO::SysCalls::closeFuncRetVal = 0; +} + +TEST(IoctlPrelimHelperPerfTests, givenCalltoPerfDisableEuStallStreamWithInvalidStreamThenFailureIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + MockIoctlHelperPrelim20 mockIoctlHelper{*drm}; + + mockIoctlHelper.initialize(); + int32_t invalidFd = -1; + mockIoctlHelper.failPerfDisable = true; + EXPECT_FALSE(mockIoctlHelper.perfDisableEuStallStream(&invalidFd)); +} + +TEST(IoctlPrelimHelperPerfTests, givenCalltoPerfOpenEuStallStreamWithInvalidStreamWithEnableSetToFailThenFailureReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + MockIoctlHelperPrelim20 mockIoctlHelper{*drm}; + + mockIoctlHelper.initialize(); + int32_t invalidFd = -1; + mockIoctlHelper.failPerfEnable = true; + std::array properties = {}; + EXPECT_FALSE(mockIoctlHelper.perfOpenEuStallStream(0u, properties, &invalidFd)); +} + +TEST(IoctlPrelimHelperPerfTests, givenCalltoPerfDisableEuStallStreamWithValidStreamThenSuccessIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + MockIoctlHelperPrelim20 mockIoctlHelper{*drm}; + + mockIoctlHelper.initialize(); + int32_t valid_fd = -1; + std::array properties = {}; + EXPECT_TRUE(mockIoctlHelper.getEuStallProperties(properties, 0x101, 0x102, 0x103, 1, 20u)); + EXPECT_TRUE(mockIoctlHelper.perfOpenEuStallStream(0u, properties, &valid_fd)); + EXPECT_TRUE(mockIoctlHelper.perfDisableEuStallStream(&valid_fd)); +} + class DrmMockIoctl : public DrmMock { public: DrmMockIoctl(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(rootDeviceEnvironment) { diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp index 0894783516..074678e00d 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp @@ -182,6 +182,9 @@ TEST(IoctlHelperUpstreamTest, whenGettingIoctlRequestStringThenProperStringIsRet EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::gemMmapOffset).c_str(), "DRM_IOCTL_I915_GEM_MMAP_OFFSET"); EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::gemVmCreate).c_str(), "DRM_IOCTL_I915_GEM_VM_CREATE"); EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::gemVmDestroy).c_str(), "DRM_IOCTL_I915_GEM_VM_DESTROY"); + EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::perfOpen).c_str(), "DRM_IOCTL_I915_PERF_OPEN"); + EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::perfEnable).c_str(), "I915_PERF_IOCTL_ENABLE"); + EXPECT_STREQ(ioctlHelper.getIoctlString(DrmIoctl::perfDisable).c_str(), "I915_PERF_IOCTL_DISABLE"); EXPECT_THROW(ioctlHelper.getIoctlString(DrmIoctl::dg1GemCreateExt), std::runtime_error); } @@ -212,6 +215,9 @@ TEST(IoctlHelperUpstreamTest, whenGettingIoctlRequestValueThenProperValueIsRetur EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::gemMmapOffset), static_cast(DRM_IOCTL_I915_GEM_MMAP_OFFSET)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::gemVmCreate), static_cast(DRM_IOCTL_I915_GEM_VM_CREATE)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::gemVmDestroy), static_cast(DRM_IOCTL_I915_GEM_VM_DESTROY)); + EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::perfOpen), static_cast(DRM_IOCTL_I915_PERF_OPEN)); + EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::perfEnable), static_cast(I915_PERF_IOCTL_ENABLE)); + EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::perfDisable), static_cast(I915_PERF_IOCTL_DISABLE)); EXPECT_THROW(ioctlHelper.getIoctlRequestValue(DrmIoctl::dg1GemCreateExt), std::runtime_error); } @@ -515,6 +521,31 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenSetVmPrefetchThenReturnTrue) { EXPECT_TRUE(ioctlHelper->setVmPrefetch(0, 0, 0, 0)); } +TEST(IoctlHelperTestsUpstream, whenCallingGetEuStallPropertiesThenFailueIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + auto ioctlHelper = drm->getIoctlHelper(); + std::array properties = {}; + EXPECT_FALSE(ioctlHelper->getEuStallProperties(properties, 0x101, 0x102, 0x103, 1, 20u)); +} + +TEST(IoctlHelperTestsUpstream, whenCallingPerfOpenEuStallStreamThenFailueIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + auto ioctlHelper = drm->getIoctlHelper(); + int32_t invalidFd = -1; + std::array properties = {}; + EXPECT_FALSE(ioctlHelper->perfOpenEuStallStream(0u, properties, &invalidFd)); +} + +TEST(IoctlHelperTestsUpstream, whenCallingPerfDisableEuStallStreamThenFailueIsReturned) { + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + auto ioctlHelper = drm->getIoctlHelper(); + int32_t invalidFd = -1; + EXPECT_FALSE(ioctlHelper->perfDisableEuStallStream(&invalidFd)); +} + TEST(IoctlHelperTestsUpstream, givenUpstreamWhenDirectSubmissionEnabledThenNoFlagsAdded) { DebugManagerStateRestore stateRestore; debugManager.flags.DirectSubmissionDrmContext.set(1); diff --git a/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt b/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt index 8edaba54d1..45e3368c84 100644 --- a/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt +++ b/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt @@ -9,6 +9,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX_XE ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_debugger_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_vm_export_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_perf_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_tests.h ) set_property(GLOBAL APPEND PROPERTY NEO_CORE_OS_INTERFACE_TESTS_LINUX ${NEO_CORE_OS_INTERFACE_TESTS_LINUX_XE}) diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_perf_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_perf_tests.cpp new file mode 100644 index 0000000000..7a9149d279 --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_perf_tests.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h" + +using namespace NEO; + +TEST(IoctlHelperXeTest, whenCallingGetEuStallPropertiesThenFailueIsReturned) { + auto executionEnvironment = std::make_unique(); + DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; + auto xeIoctlHelper = std::make_unique(drm); + EXPECT_NE(nullptr, xeIoctlHelper); + std::array properties = {}; + EXPECT_FALSE(xeIoctlHelper.get()->getEuStallProperties(properties, 0x101, 0x102, 0x103, 1, 20u)); +} + +TEST(IoctlHelperXeTest, whenCallingPerfOpenEuStallStreamThenFailueIsReturned) { + auto executionEnvironment = std::make_unique(); + DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; + auto xeIoctlHelper = std::make_unique(drm); + EXPECT_NE(nullptr, xeIoctlHelper); + int32_t invalidFd = -1; + std::array properties = {}; + EXPECT_FALSE(xeIoctlHelper.get()->perfOpenEuStallStream(0u, properties, &invalidFd)); +} + +TEST(IoctlHelperXeTest, whenCallingPerfDisableEuStallStreamThenFailueIsReturned) { + auto executionEnvironment = std::make_unique(); + DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; + auto xeIoctlHelper = std::make_unique(drm); + EXPECT_NE(nullptr, xeIoctlHelper); + int32_t invalidFd = -1; + EXPECT_FALSE(xeIoctlHelper.get()->perfDisableEuStallStream(&invalidFd)); +}