public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Ravi Kishore Koppuravuri <ravi.kishore.koppuravuri@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: badal.nilawar@intel.com, karthik.poosa@intel.com,
	raag.jadav@intel.com, soham.purkait@intel.com,
	mallesh.koujalagi@intel.com,
	Ravi Kishore Koppuravuri <ravi.kishore.koppuravuri@intel.com>,
	Sk Anirban <sk.anirban@intel.com>,
	Tauro Riana <riana.tauro@intel.com>,
	Gupta Anshuman <anshuman.gupta@intel.com>
Subject: [[i-g-t] 1/1] tests/intel/xe_fault_injection: Add fault-injection tests for Freq Throttle Reasons
Date: Thu, 26 Mar 2026 10:36:28 +0530	[thread overview]
Message-ID: <20260326050628.2510944-2-ravi.kishore.koppuravuri@intel.com> (raw)
In-Reply-To: <20260326050628.2510944-1-ravi.kishore.koppuravuri@intel.com>

This test validates the robustness of the throttle reason detection 
under various failure scenarios by injecting faults into 
xe_gt_throttle_get_limit_reasons() function. This test covers all 
the supported throttling reason types.

Cc: Sk Anirban <sk.anirban@intel.com>
Cc: Tauro Riana <riana.tauro@intel.com>
Cc: Gupta Anshuman <anshuman.gupta@intel.com>
Signed-off-by: Ravi Kishore Koppuravuri <ravi.kishore.koppuravuri@intel.com>
---
Verification:
This test is verified and below are the results

Test Execution:
$ ./build/tests/xe_fault_injection --run-subtest 'throttle*'
IGT-Version: 2.3-g06706ff21 (x86_64) (Linux: 7.0.0-rc2-throttle-reason-injection-test x86_64)
Using IGT_SRANDOM=1773144939 for randomisation
Opened device: /dev/dri/card0
Starting subtest: throttle-reason-fail-soc_thermal
Injecting error (-1) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : thermal
Subtest throttle-reason-fail-soc_thermal: SUCCESS (0.022s)
Starting subtest: throttle-reason-fail-mem_thermal
Injecting error (-2) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : none
Subtest throttle-reason-fail-mem_thermal: SUCCESS (0.023s)
Starting subtest: throttle-reason-fail-vr_thermal
Injecting error (-3) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : none
Subtest throttle-reason-fail-vr_thermal: SUCCESS (0.031s)
Starting subtest: throttle-reason-fail-iccmax
Injecting error (-4) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : none
Subtest throttle-reason-fail-iccmax: SUCCESS (0.034s)
Starting subtest: throttle-reason-fail-ratl
Injecting error (-5) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : ratl
Subtest throttle-reason-fail-ratl: SUCCESS (0.042s)
Starting subtest: throttle-reason-fail-soc_avg_thermal
Injecting error (-6) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : vr_thermalert
Subtest throttle-reason-fail-soc_avg_thermal: SUCCESS (0.042s)
Starting subtest: throttle-reason-fail-fastvmode
Injecting error (-7) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : vr_tdc
Subtest throttle-reason-fail-fastvmode: SUCCESS (0.030s)
Starting subtest: throttle-reason-fail-pl4_limit
Injecting error (-8) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : pl4
Subtest throttle-reason-fail-pl4_limit: SUCCESS (0.030s)
Starting subtest: throttle-reason-fail-max_vid
Injecting error (-9) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : none
Subtest throttle-reason-fail-max_vid: SUCCESS (0.018s)
Starting subtest: throttle-reason-fail-pkg_pl1
Injecting error (-10) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : pl1
Subtest throttle-reason-fail-pkg_pl1: SUCCESS (0.033s)
Starting subtest: throttle-reason-fail-pkg_pl2
Injecting error (-11) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : pl2
Subtest throttle-reason-fail-pkg_pl2: SUCCESS (0.031s)
Starting subtest: throttle-reason-fail-psys_pl1
Injecting error (-12) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : none
Subtest throttle-reason-fail-psys_pl1: SUCCESS (0.022s)
Starting subtest: throttle-reason-fail-psys_pl2
Injecting error (-13) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : none
Subtest throttle-reason-fail-psys_pl2: SUCCESS (0.035s)
Starting subtest: throttle-reason-fail-p0_freq
Injecting error (-14) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : none
Subtest throttle-reason-fail-p0_freq: SUCCESS (0.030s)
Starting subtest: throttle-reason-fail-psys_crit
Injecting error (-15) in function "xe_gt_throttle_inject_errno"
Reason for Throttling is : none
Subtest throttle-reason-fail-psys_crit: SUCCESS (0.034s)

---
 tests/intel/xe_fault_injection.c | 172 +++++++++++++++++++++++++++++++
 1 file changed, 172 insertions(+)

diff --git a/tests/intel/xe_fault_injection.c b/tests/intel/xe_fault_injection.c
index 4f4a7922c..05f5125cf 100644
--- a/tests/intel/xe_fault_injection.c
+++ b/tests/intel/xe_fault_injection.c
@@ -234,6 +234,66 @@ static void ignore_fail_dump_in_dmesg(const char function_name[], bool enable)
 	}
 }
 
+static char *prepare_reasons_path(int fd)
+{
+	char sysfs_path[PATH_MAX];
+	char device_link[PATH_MAX];
+	char pcie_path[PATH_MAX];
+	char reasons_path[PATH_MAX];
+	int ret;
+
+	igt_assert(igt_sysfs_path(fd, sysfs_path, sizeof(sysfs_path)));
+
+	ret = snprintf(device_link, sizeof(device_link), "%s/device", sysfs_path);
+	igt_assert(ret > 0 && ret < sizeof(device_link));
+	igt_assert(realpath(device_link, pcie_path));
+
+	ret = snprintf(reasons_path, sizeof(reasons_path),
+		       "%s/tile0/gt0/freq0/throttle/reasons", pcie_path);
+	igt_assert(ret > 0 && ret < sizeof(reasons_path));
+
+	return strdup(reasons_path);
+}
+
+static char *read_throttle_reasons_from_sysfs(int fd)
+{
+	char *reasons_path = NULL;
+	char *reasons = NULL;
+	int ret = -1;
+	int reason_fd = -1;
+
+	reasons_path = prepare_reasons_path(fd);
+	if (!reasons_path)
+		return NULL;
+
+	reason_fd = open(reasons_path, O_RDONLY);
+	if (reason_fd < 0) {
+		free(reasons_path);
+		return NULL;
+	}
+
+	free(reasons_path);
+	reasons = calloc(1, 256);
+	if (!reasons)
+		goto err;
+
+	ret = read(reason_fd, reasons, 255);
+	if (ret < 0)
+		goto err;
+
+	reasons[ret] = '\0';
+
+	close(reason_fd);
+	return reasons;
+
+err:
+	if (reason_fd >= 0)
+		close(reason_fd);
+	if (reasons)
+		free(reasons);
+	return NULL;
+}
+
 /**
  * SUBTEST: inject-fault-probe-function-%s
  * Description: inject an error in the injectable function %arg[1] then
@@ -529,6 +589,90 @@ oa_add_config_fail(int fd, int sysfs, int devid,
 	igt_assert_eq(intel_xe_perf_ioctl(fd, DRM_XE_OBSERVATION_OP_REMOVE_CONFIG, &config_id), 0);
 }
 
+enum cri_throttle_reason {
+	THROTTLE_REASON_SOC_THERMAL = -1,
+	THROTTLE_REASON_MEM_THERMAL = -2,
+	THROTTLE_REASON_VR_THERMAL = -3,
+	THROTTLE_REASON_ICCMAX = -4,
+	THROTTLE_REASON_RATL = -5,
+	THROTTLE_REASON_SOC_AVG_THERMAL = -6,
+	THROTTLE_REASON_FASTVMODE = -7,
+	THROTTLE_REASON_PL4_LIMIT = -8,
+	THROTTLE_REASON_MAX_VID = -9,
+	THROTTLE_REASON_PKG_PL1 = -10,
+	THROTTLE_REASON_PKG_PL2 = -11,
+	THROTTLE_REASON_PSYS_PL1 = -12,
+	THROTTLE_REASON_PSYS_PL2 = -13,
+	THROTTLE_REASON_P0_FREQ = -14,
+	THROTTLE_REASON_PSYS_CRIT = -15,
+};
+
+static int
+inject_fault_throttle_reason(int fd, const char pci_slot[], const char function_name[],
+			     enum cri_throttle_reason reason)
+{
+	int err = 0;
+	char *throttle_reasons;
+
+	igt_info("Injecting error (%d) in function \"%s\"\n",
+		 reason, function_name);
+
+	ignore_dmesg_errors_from_dut(pci_slot);
+	igt_audio_driver_unload(NULL);
+
+	injection_list_add(function_name);
+	set_retval(function_name, reason);
+
+	throttle_reasons = read_throttle_reasons_from_sysfs(fd);
+	if (throttle_reasons) {
+		igt_info("Reason for Throttling is : %s", throttle_reasons);
+		free(throttle_reasons);
+	} else {
+		igt_warn("Failed to read throttle reasons from sysfs\n");
+		err = -errno;
+	}
+
+	injection_list_remove(function_name);
+	ignore_fail_dump_in_dmesg(function_name, false);
+
+	return err;
+}
+
+/**
+ * SUBTEST: throttle-reason-fail-%s
+ * Description: inject a throttle reason in the injectable function %arg[1] then
+ * read the reasons from sysfs
+ * Functionality: fault
+ *
+ * arg[1]:
+ * @soc_thermal:     Frequency is clipped because of SOC hotspot temperature
+ * @mem_thermal:     Frequency is clipped because of memory hotspot temperature
+ * @vr_thermal:      Frequency is clipped because of VR hotspot temperature
+ * @iccmax:          Frequency is clipped because of ICCMAX limit
+ * @ratl:       Frequency is clipped because of RATL thermal algorithm
+ * @soc_avg_thermal: Frequency is clipped because of SOC average thermal limit
+ * @fastvmode:       Frequency is clipped because of Fast VMode limit
+ * @pl4_limit:       Frequency is clipped because of PL4 limit
+ * @max_vid:       Frequency is clipped because of MAX VID limit
+ * @pkg_pl1:       Frequency is clipped because of PKG PL1 limit
+ * @pkg_pl2:       Frequency is clipped because of PKG PL2 limit
+ * @psys_pl1:       Frequency is clipped because of PSYS PL1 limit
+ * @psys_pl2:       Frequency is clipped because of PSYS PL2 limit
+ * @p0_freq:       Frequency is clipped because of P0 frequency limit
+ * @psys_crit:       Frequency is clipped because of PSYS critical limit
+ */
+static void throttle_reason_fail(int fd, const char pci_slot[], const char function_name[],
+				 struct fault_injection_params *fault_params,
+				 enum cri_throttle_reason reason)
+{
+	int retval = 0;
+
+	igt_assert(fault_params);
+	setup_injection_fault(fault_params);
+	retval = inject_fault_throttle_reason(fd, pci_slot, function_name, reason);
+	igt_assert_eq(retval, 0);
+}
+
 static int opt_handler(int opt, int opt_index, void *data)
 {
 	int in_param;
@@ -625,6 +769,26 @@ int igt_main_args("I:", NULL, help_str, opt_handler, NULL)
 		{ }
 	};
 
+	const struct section throttle_reason_fail_functions[] = {
+		{ "soc_thermal", THROTTLE_REASON_SOC_THERMAL },
+		{ "mem_thermal", THROTTLE_REASON_MEM_THERMAL },
+		{ "vr_thermal", THROTTLE_REASON_VR_THERMAL },
+		{ "iccmax", THROTTLE_REASON_ICCMAX },
+		{ "ratl", THROTTLE_REASON_RATL },
+		{ "soc_avg_thermal", THROTTLE_REASON_SOC_AVG_THERMAL },
+		{ "fastvmode", THROTTLE_REASON_FASTVMODE },
+		{ "pl4_limit", THROTTLE_REASON_PL4_LIMIT },
+		{ "max_vid", THROTTLE_REASON_MAX_VID },
+		{ "pkg_pl1", THROTTLE_REASON_PKG_PL1 },
+		{ "pkg_pl2", THROTTLE_REASON_PKG_PL2 },
+		{ "psys_pl1", THROTTLE_REASON_PSYS_PL1 },
+		{ "psys_pl2", THROTTLE_REASON_PSYS_PL2 },
+		{ "p0_freq", THROTTLE_REASON_P0_FREQ },
+		{ "psys_crit", THROTTLE_REASON_PSYS_CRIT },
+		{ }
+	};
+	const char *throttle_reason_function_name = "xe_gt_throttle_inject_errno";
+
 	igt_fixture() {
 		igt_require(fail_function_injection_enabled());
 		fd = drm_open_driver(DRIVER_XE);
@@ -640,6 +804,14 @@ int igt_main_args("I:", NULL, help_str, opt_handler, NULL)
 		igt_subtest_f("vm-create-fail-%s", s->name)
 			vm_create_fail(fd, pci_slot, s->name, s->flags);
 
+	for (const struct section *s = throttle_reason_fail_functions; s->name; s++)
+		igt_subtest_f("throttle-reason-fail-%s", s->name) {
+			memcpy(&fault_params, &default_fault_params,
+			       sizeof(struct fault_injection_params));
+			throttle_reason_fail(fd, pci_slot, throttle_reason_function_name,
+					     &fault_params, s->flags);
+		}
+
 	for (const struct section *s = vm_bind_fail_functions; s->name; s++)
 		igt_subtest_f("vm-bind-fail-%s", s->name)
 			vm_bind_fail(fd, pci_slot, s->name);
-- 
2.34.1


  reply	other threads:[~2026-03-26  5:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26  5:06 [[i-g-t] 0/1] Frequency throttle reason tests using kernel's fault-injection Ravi Kishore Koppuravuri
2026-03-26  5:06 ` Ravi Kishore Koppuravuri [this message]
2026-03-26  5:57 ` ✓ Xe.CI.BAT: success for 1/1] tests/intel/xe_fault_injection: Add fault-injection tests for Freq Throttle Reasons Patchwork
2026-03-26  6:16 ` ✓ i915.CI.BAT: " Patchwork
2026-03-26 17:12 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-03-26 20:36 ` ✓ i915.CI.Full: success " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2026-03-26  5:29 [i-g-t, 0/1] " Ravi Kishore Koppuravuri
2026-03-26  5:29 ` [i-g-t, 1/1] tests/intel/xe_fault_injection: " Ravi Kishore Koppuravuri
2026-04-27  9:02   ` Anirban, Sk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260326050628.2510944-2-ravi.kishore.koppuravuri@intel.com \
    --to=ravi.kishore.koppuravuri@intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=karthik.poosa@intel.com \
    --cc=mallesh.koujalagi@intel.com \
    --cc=raag.jadav@intel.com \
    --cc=riana.tauro@intel.com \
    --cc=sk.anirban@intel.com \
    --cc=soham.purkait@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox