Skip to content

Commit

Permalink
test: Add CTS for Sysman Freq & Power telemetry collection Overhead
Browse files Browse the repository at this point in the history
Related-To: VLCLJ-2294

Signed-off-by: B, Vishnu Khanth <[email protected]>
  • Loading branch information
vishnu-khanth committed Jan 7, 2025
1 parent 38ae470 commit 38115d2
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand All @@ -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

Expand Down Expand Up @@ -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<double, std::micro> elapsed_initial = end - start;

uint32_t iterations = 20;
std::chrono::duration<double, std::micro> 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<double, std::micro> 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand All @@ -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

Expand Down Expand Up @@ -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<double, std::micro> elapsed_initial = end - start;

uint32_t iterations = 20;
std::chrono::duration<double, std::micro> 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<double, std::micro> 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ uint32_t get_freq_handle_count(zes_device_handle_t device);
std::vector<zes_freq_handle_t> 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<zes_freq_state_t>
get_freq_state(std::vector<zes_freq_handle_t> &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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<zes_power_energy_counter_t>
get_power_energy_counter(std::vector<zes_pwr_handle_t> &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,
Expand Down
11 changes: 11 additions & 0 deletions utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ zes_freq_state_t get_freq_state(zes_freq_handle_t pFreqHandle) {
return pState;
}

std::vector<zes_freq_state_t>
get_freq_state(std::vector<zes_freq_handle_t> &freq_handles) {
std::vector<zes_freq_state_t> 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));
Expand Down
11 changes: 11 additions & 0 deletions utils/test_harness/sysman/src/test_harness_sysman_power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<zes_power_energy_counter_t>
get_power_energy_counter(std::vector<zes_pwr_handle_t> &power_handles) {
std::vector<zes_power_energy_counter_t> 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);
Expand Down

0 comments on commit 38115d2

Please sign in to comment.