Seeing random issues where this test starts with invalid values. Ensure that we restore the frequencies in case test exits early due to some system issues. Link: https://gitlab.freedesktop.org/drm/intel/-/issues/9432 Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@xxxxxxxxx> --- tests/intel/perf_pmu.c | 53 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/tests/intel/perf_pmu.c b/tests/intel/perf_pmu.c index c6e6a8b77..ceacc1d3d 100644 --- a/tests/intel/perf_pmu.c +++ b/tests/intel/perf_pmu.c @@ -2454,12 +2454,59 @@ static void pmu_read(int i915) for_each_if((e)->class == I915_ENGINE_CLASS_RENDER) \ igt_dynamic_f("%s", e->name) +int fd = -1; +uint32_t *stash_min, *stash_max, *stash_boost; + +static void save_sysfs_freq(int i915) +{ + int gt, num_gts, sysfs, tmp; + + num_gts = igt_sysfs_get_num_gt(i915); + + stash_min = (uint32_t *)malloc(sizeof(uint32_t) * num_gts); + stash_max = (uint32_t *)malloc(sizeof(uint32_t) * num_gts); + stash_boost = (uint32_t *)malloc(sizeof(uint32_t) * num_gts); + + /* Save boost, min and max across GTs */ + i915_for_each_gt(i915, tmp, gt) { + sysfs = igt_sysfs_gt_open(i915, gt); + igt_require(sysfs >= 0); + + stash_min[gt] = igt_sysfs_get_u32(sysfs, "rps_min_freq_mhz"); + stash_max[gt] = igt_sysfs_get_u32(sysfs, "rps_max_freq_mhz"); + stash_boost[gt] = igt_sysfs_get_u32(sysfs, "rps_boost_freq_mhz"); + igt_debug("GT: %d, min: %d, max: %d, boost:%d\n", + gt, stash_min[gt], stash_max[gt], stash_boost[gt]); + + close(sysfs); + } +} + +static void restore_sysfs_freq(int sig) +{ + int sysfs, gt, tmp; + + /* Restore frequencies */ + i915_for_each_gt(fd, tmp, gt) { + sysfs = igt_sysfs_gt_open(fd, gt); + igt_require(sysfs >= 0); + + igt_require(__igt_sysfs_set_u32(sysfs, "rps_max_freq_mhz", stash_max[gt])); + igt_require(__igt_sysfs_set_u32(sysfs, "rps_min_freq_mhz", stash_min[gt])); + igt_require(__igt_sysfs_set_u32(sysfs, "rps_boost_freq_mhz", stash_boost[gt])); + + close(sysfs); + } + free(stash_min); + free(stash_max); +} + igt_main { const struct intel_execution_engine2 *e; unsigned int num_engines = 0; const intel_ctx_t *ctx = NULL; - int gt, tmp, fd = -1; + int gt, tmp; int num_gt = 0; /** @@ -2482,6 +2529,7 @@ igt_main i915_for_each_gt(fd, tmp, gt) num_gt++; + } igt_describe("Verify i915 pmu dir exists and read all events"); @@ -2664,6 +2712,9 @@ igt_main * Test GPU frequency. */ igt_subtest_with_dynamic("frequency") { + save_sysfs_freq(fd); + igt_install_exit_handler(restore_sysfs_freq); + i915_for_each_gt(fd, tmp, gt) { igt_dynamic_f("gt%u", gt) test_frequency(fd, gt); -- 2.38.1