diff --git a/conformance_tests/sysman/test_sysman_frequency/src/test_sysman_frequency.cpp b/conformance_tests/sysman/test_sysman_frequency/src/test_sysman_frequency.cpp index 16accb5e..d557db6f 100644 --- a/conformance_tests/sysman/test_sysman_frequency/src/test_sysman_frequency.cpp +++ b/conformance_tests/sysman/test_sysman_frequency/src/test_sysman_frequency.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,10 +20,16 @@ namespace lzt = level_zero_tests; namespace { #ifdef USE_ZESINIT -class FrequencyModuleZesTest : public lzt::ZesSysmanCtsClass {}; +class FrequencyModuleZesTest : public lzt::ZesSysmanCtsClass { +public: + bool freq_handles_available = false; +}; #define FREQUENCY_TEST FrequencyModuleZesTest #else // USE_ZESINIT -class FrequencyModuleTest : public lzt::SysmanCtsClass {}; +class FrequencyModuleTest : public lzt::SysmanCtsClass { +public: + bool freq_handles_available = false; +}; #define FREQUENCY_TEST FrequencyModuleTest #endif // USE_ZESINIT @@ -763,4 +769,50 @@ TEST_F( } } +#ifdef __linux__ +TEST_F( + FREQUENCY_TEST, + GivenValidDeviceWhenCallingFrequencyGetStateMultipleTimesThenExpectFirstCallIsSlowerThanSubsequentCalls) { + for (auto device : devices) { + uint32_t count = 0; + auto freq_handles = lzt::get_freq_handles(device, count); + + if (count > 0) { + freq_handles_available = true; + auto start = std::chrono::steady_clock::now(); + auto states = lzt::get_freq_state(freq_handles); + auto end = std::chrono::steady_clock::now(); + std::chrono::duration elapsed_initial = end - start; + + uint32_t iterations = 20; + std::chrono::duration total_time(0); + + for (uint32_t i = 0; i < iterations; i++) { + auto start = std::chrono::steady_clock::now(); + auto states = lzt::get_freq_state(freq_handles); + auto end = std::chrono::steady_clock::now(); + std::chrono::duration elapsed = end - start; + total_time += elapsed; + } + + auto avg_time = total_time / iterations; + LOG_INFO << "Initial Telemetry collection time (micro sec): " + << elapsed_initial.count(); + LOG_INFO << "Average Telemetry collection time (micro sec) for " + << iterations << " iterations : " << avg_time.count(); + + EXPECT_GT(elapsed_initial.count(), 0); + EXPECT_GT(avg_time.count(), 0); + EXPECT_GT(elapsed_initial.count(), avg_time.count()); + } else { + LOG_WARNING << "No handles found on this device!"; + } + } + + if (!freq_handles_available) { + FAIL() << "No handles found in any of the devices!"; + } +} +#endif + } // namespace diff --git a/conformance_tests/sysman/test_sysman_power/src/test_sysman_power.cpp b/conformance_tests/sysman/test_sysman_power/src/test_sysman_power.cpp index 4bbcc910..d8b7d36b 100644 --- a/conformance_tests/sysman/test_sysman_power/src/test_sysman_power.cpp +++ b/conformance_tests/sysman/test_sysman_power/src/test_sysman_power.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,10 +18,16 @@ namespace lzt = level_zero_tests; namespace { #ifdef USE_ZESINIT -class PowerModuleZesTest : public lzt::ZesSysmanCtsClass {}; +class PowerModuleZesTest : public lzt::ZesSysmanCtsClass { +public: + bool power_handles_available = false; +}; #define POWER_TEST PowerModuleZesTest #else // USE_ZESINIT -class PowerModuleTest : public lzt::SysmanCtsClass {}; +class PowerModuleTest : public lzt::SysmanCtsClass { +public: + bool power_handles_available = false; +}; #define POWER_TEST PowerModuleTest #endif // USE_ZESINIT @@ -1265,4 +1271,50 @@ TEST_F( } } +#ifdef __linux__ +TEST_F( + POWER_TEST, + GivenValidDeviceWhenCallingPowerGetEnergyCountersMultipleTimesThenExpectFirstCallIsSlowerThanSubsequentCalls) { + for (auto device : devices) { + uint32_t count = 0; + auto power_handles = lzt::get_power_handles(device, count); + + if (count > 0) { + power_handles_available = true; + auto start = std::chrono::steady_clock::now(); + auto energy_counters = lzt::get_power_energy_counter(power_handles); + auto end = std::chrono::steady_clock::now(); + std::chrono::duration elapsed_initial = end - start; + + uint32_t iterations = 20; + std::chrono::duration total_time(0); + + for (uint32_t i = 0; i < iterations; i++) { + auto start = std::chrono::steady_clock::now(); + auto energy_counters = lzt::get_power_energy_counter(power_handles); + auto end = std::chrono::steady_clock::now(); + std::chrono::duration elapsed = end - start; + total_time += elapsed; + } + + auto avg_time = total_time / iterations; + LOG_INFO << "Initial Telemetry collection time (micro sec): " + << elapsed_initial.count(); + LOG_INFO << "Average Telemetry collection time (micro sec) for " + << iterations << " iterations : " << avg_time.count(); + + EXPECT_GT(elapsed_initial.count(), 0); + EXPECT_GT(avg_time.count(), 0); + EXPECT_GT(elapsed_initial.count(), avg_time.count()); + } else { + LOG_WARNING << "No handles found on this device!"; + } + } + + if (!power_handles_available) { + FAIL() << "No handles found in any of the devices!"; + } +} +#endif + } // namespace diff --git a/utils/test_harness/sysman/include/test_harness_sysman_frequency.hpp b/utils/test_harness/sysman/include/test_harness_sysman_frequency.hpp index 118f2fa9..61f6dfe3 100644 --- a/utils/test_harness/sysman/include/test_harness_sysman_frequency.hpp +++ b/utils/test_harness/sysman/include/test_harness_sysman_frequency.hpp @@ -23,6 +23,8 @@ uint32_t get_freq_handle_count(zes_device_handle_t device); std::vector get_freq_handles(zes_device_handle_t device, uint32_t &count); zes_freq_state_t get_freq_state(zes_freq_handle_t pFreqHandle); +std::vector +get_freq_state(std::vector &freq_handles); zes_freq_range_t get_freq_range(zes_freq_handle_t pFreqHandle); void set_freq_range(zes_freq_handle_t pFreqHandle, zes_freq_range_t &pLimits); void set_freq_range(zes_freq_handle_t pFreqHandle, zes_freq_range_t &pLimits, diff --git a/utils/test_harness/sysman/include/test_harness_sysman_power.hpp b/utils/test_harness/sysman/include/test_harness_sysman_power.hpp index 1c434a30..3b4b3b69 100644 --- a/utils/test_harness/sysman/include/test_harness_sysman_power.hpp +++ b/utils/test_harness/sysman/include/test_harness_sysman_power.hpp @@ -27,6 +27,8 @@ ze_result_t set_power_limits(zes_pwr_handle_t pPowerHandle, zes_power_peak_limit_t *pPeak); void get_power_energy_counter(zes_pwr_handle_t pPowerHandle, zes_power_energy_counter_t *pEnergy); +std::vector +get_power_energy_counter(std::vector &power_handles); ze_result_t get_power_energy_threshold(zes_pwr_handle_t pPowerHandle, zes_energy_threshold_t *pThreshold); void set_power_energy_threshold(zes_pwr_handle_t pPowerHandle, diff --git a/utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp b/utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp index 501f5270..d081aa44 100644 --- a/utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp +++ b/utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp @@ -42,6 +42,17 @@ zes_freq_state_t get_freq_state(zes_freq_handle_t pFreqHandle) { return pState; } +std::vector +get_freq_state(std::vector &freq_handles) { + std::vector states{}; + for (auto &freq_handle : freq_handles) { + EXPECT_NE(nullptr, freq_handle); + zes_freq_state_t state = get_freq_state(freq_handle); + states.push_back(state); + } + return states; +} + zes_freq_range_t get_freq_range(zes_freq_handle_t pFreqHandle) { zes_freq_range_t pLimits = {}; EXPECT_EQ(ZE_RESULT_SUCCESS, zesFrequencyGetRange(pFreqHandle, &pLimits)); diff --git a/utils/test_harness/sysman/src/test_harness_sysman_power.cpp b/utils/test_harness/sysman/src/test_harness_sysman_power.cpp index 6a24bb9e..d1f44e93 100644 --- a/utils/test_harness/sysman/src/test_harness_sysman_power.cpp +++ b/utils/test_harness/sysman/src/test_harness_sysman_power.cpp @@ -108,6 +108,17 @@ void get_power_energy_counter(zes_pwr_handle_t pPowerHandle, zes_power_energy_counter_t *pEnergy) { EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(pPowerHandle, pEnergy)); } +std::vector +get_power_energy_counter(std::vector &power_handles) { + std::vector energy_counters{}; + for (auto &power_handle : power_handles) { + EXPECT_NE(nullptr, power_handle); + zes_power_energy_counter_t energy_counter = {}; + get_power_energy_counter(power_handle, &energy_counter); + energy_counters.push_back(energy_counter); + } + return energy_counters; +} ze_result_t get_power_energy_threshold(zes_pwr_handle_t pPowerHandle, zes_energy_threshold_t *pThreshold) { ze_result_t status = zesPowerGetEnergyThreshold(pPowerHandle, pThreshold);