From 2271ce2b7f57eff745298c2ebff8d6f540938b4c Mon Sep 17 00:00:00 2001 From: Anvesh Bakwad Date: Tue, 10 Jun 2025 11:00:02 +0000 Subject: [PATCH] fix(sysman): change KMD config macro for group all engine handles Related-To: NEO-15172 Signed-off-by: Anvesh Bakwad --- .../sysman_kmd_interface_i915_prelim.cpp | 14 ++++++++++---- .../sysman/engine/linux/os_engine_imp_prelim.cpp | 16 +++++++++++++--- .../sysman/engine/linux/mock_engine_prelim.h | 9 +++++++-- .../engine/linux/test_zes_engine_prelim.cpp | 4 +++- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_i915_prelim.cpp b/level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_i915_prelim.cpp index 97d08cbbbb..d37805b716 100644 --- a/level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_i915_prelim.cpp +++ b/level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_i915_prelim.cpp @@ -126,14 +126,20 @@ ze_result_t SysmanKmdInterfaceI915Prelim::getEngineActivityFdListAndConfigPair(z config = __PRELIM_I915_PMU_MEDIA_GROUP_BUSY_TICKS(gtId); break; default: - auto engineClass = engineGroupToEngineClass.find(engineGroup); - config = PRELIM_I915_PMU_ENGINE_BUSY_TICKS(engineClass->second, engineInstance); + auto i915EngineClass = engineGroupToEngineClass.find(engineGroup); + config = PRELIM_I915_PMU_ENGINE_BUSY_TICKS(i915EngineClass->second, engineInstance); break; } int64_t fd[2]; - auto i915EngineClass = engineGroupToEngineClass.find(engineGroup); - configPair = std::make_pair(config, PRELIM_I915_PMU_ENGINE_TOTAL_TICKS(i915EngineClass->second, engineInstance)); + + if (isGroupEngineHandle(engineGroup)) { + configPair = std::make_pair(config, __PRELIM_I915_PMU_TOTAL_ACTIVE_TICKS(gtId)); + } else { + auto i915EngineClass = engineGroupToEngineClass.find(engineGroup); + configPair = std::make_pair(config, PRELIM_I915_PMU_ENGINE_TOTAL_TICKS(i915EngineClass->second, engineInstance)); + } + fd[0] = pPmuInterface->pmuInterfaceOpen(configPair.first, -1, PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_GROUP); if (fd[0] < 0) { NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Could not open Busy Ticks Handle \n", __FUNCTION__); diff --git a/level_zero/tools/source/sysman/engine/linux/os_engine_imp_prelim.cpp b/level_zero/tools/source/sysman/engine/linux/os_engine_imp_prelim.cpp index a455fc70ed..de9db2ef83 100644 --- a/level_zero/tools/source/sysman/engine/linux/os_engine_imp_prelim.cpp +++ b/level_zero/tools/source/sysman/engine/linux/os_engine_imp_prelim.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -227,8 +227,17 @@ void LinuxEngineImpPrelim::init() { checkErrorNumberAndUpdateStatus(); return; } - auto i915EngineClass = engineToI915MapPrelim.find(engineGroup); - fd[1] = pPmuInterface->pmuInterfaceOpen(PRELIM_I915_PMU_ENGINE_TOTAL_TICKS(i915EngineClass->second, engineInstance), static_cast(fd[0]), PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_GROUP); + + uint64_t totalTickConfig = 0u; + bool isGroupEngineHandle = (engineGroup == ZES_ENGINE_GROUP_ALL || engineGroup == ZES_ENGINE_GROUP_MEDIA_ALL || engineGroup == ZES_ENGINE_GROUP_COMPUTE_ALL || engineGroup == ZES_ENGINE_GROUP_RENDER_ALL || engineGroup == ZES_ENGINE_GROUP_COPY_ALL); + if (isGroupEngineHandle) { + totalTickConfig = __PRELIM_I915_PMU_TOTAL_ACTIVE_TICKS(subDeviceId); + } else { + auto i915EngineClass = engineToI915MapPrelim.find(engineGroup); + totalTickConfig = PRELIM_I915_PMU_ENGINE_TOTAL_TICKS(i915EngineClass->second, engineInstance); + } + + fd[1] = pPmuInterface->pmuInterfaceOpen(totalTickConfig, static_cast(fd[0]), PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_GROUP); if (fd[1] < 0) { NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Could not open Total Active Ticks Handle \n", __FUNCTION__); @@ -249,6 +258,7 @@ void LinuxEngineImpPrelim::init() { // Delay fd opening till actually needed for (uint64_t i = 0; i < numberOfVfs + 1; i++) { const uint64_t busyConfig = ___PRELIM_I915_PMU_FN_EVENT(config, i); + auto i915EngineClass = engineToI915MapPrelim.find(engineGroup); const uint64_t totalConfig = ___PRELIM_I915_PMU_FN_EVENT(PRELIM_I915_PMU_ENGINE_TOTAL_TICKS(i915EngineClass->second, engineInstance), i); vfConfigs.push_back(std::make_pair(busyConfig, totalConfig)); } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/mock_engine_prelim.h b/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/mock_engine_prelim.h index 8b4699cd5a..5feffcd15d 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/mock_engine_prelim.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/mock_engine_prelim.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -116,6 +116,11 @@ struct MockEnginePmuInterfaceImpPrelim : public PmuInterfaceImp { int32_t mockErrorNumber = -ENOSPC; int32_t mockPerfEventOpenFailAtCount = 1; uint64_t mockTimestamp = 87654321; + static uint32_t engineConfigIndex; + std::vector mockSingleEngineConfigs = { + __PRELIM_I915_PMU_TOTAL_ACTIVE_TICKS(0), + PRELIM_I915_PMU_ENGINE_TOTAL_TICKS(drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER, 0), + __PRELIM_I915_PMU_TOTAL_ACTIVE_TICKS(0)}; int64_t perfEventOpen(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags) override { @@ -157,7 +162,7 @@ struct MockEnginePmuInterfaceImpPrelim : public PmuInterfaceImp { int64_t pmuInterfaceOpen(uint64_t config, int group, uint32_t format) override { if (group > -1 && MockEngineNeoDrmPrelim::mockQuerySingleEngineInstance == true) { - uint64_t testConfig = PRELIM_I915_PMU_ENGINE_TOTAL_TICKS(drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER, 0); + auto testConfig = mockSingleEngineConfigs[engineConfigIndex++]; EXPECT_EQ(config, testConfig); } return PmuInterfaceImp::pmuInterfaceOpen(config, group, format); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine_prelim.cpp b/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine_prelim.cpp index 1e4a156afe..549b599d14 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine_prelim.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine_prelim.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,6 +20,7 @@ constexpr uint32_t handleComponentCount = 13u; constexpr uint32_t handleCountForMultiDeviceFixture = 7u; bool MockEngineNeoDrmPrelim::mockQuerySingleEngineInstance = false; +uint32_t MockEnginePmuInterfaceImpPrelim::engineConfigIndex = 0u; class ZesEngineFixturePrelim : public SysmanDeviceFixture { protected: @@ -104,6 +105,7 @@ TEST_F(ZesEngineFixturePrelim, GivenDeviceHandleAndSingleEngineInstanceIsQueried EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEnumEngineGroups(device->toHandle(), &count, NULL)); EXPECT_EQ(count, numHandles); MockEngineNeoDrmPrelim::mockQuerySingleEngineInstance = false; + MockEnginePmuInterfaceImpPrelim::engineConfigIndex = 0u; } TEST_F(ZesEngineFixturePrelim, GivenComponentCountZeroWhenCallingzesDeviceEnumEngineGroupsThenNonZeroCountIsReturnedAndVerifyCallSucceeds) {