Skip to contentSkip to conversation

Cold Reset IGT Test

PATCH Superseded Anshuman Gupta 2 participants 6 messages Nov 14, 2022 – Nov 15, 2022 Library code

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Cold Reset IGT Test

Cold Reset IGT Test.

v2:
Address some review comments from Kamil and Badal.

Anshuman Gupta (3):
lib/igt_pm: Refactor get firmware_node fd test/device_reset: Refactor initiate_device_reset tests/device_reset: Add cold reset IGT test

 lib/igt_pm.c         |  76 ++++++++++++++++++++----
 lib/igt_pm.h         |   1 +
 tests/device_reset.c | 138 +++++++++++++++++++++++++++++++++++++++----
 3 files changed, 191 insertions(+), 24 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/3 lib/igt_pm: Refactor get firmware_node fd

Created igt_pm_open_pci_firmware_node() to refactor the retrieving the firmware_node fd code.

igt_pm_open_pci_firmware_node() will be used by other firmware_node consumers.

While doing that fixed the leaked fd as well.

v2:
- return false instead of igt_require on no firmware_node_fd. [Kamil]
- use igt_assert() when failed to open 'real_power_state' on error other then ENONET.

---
 lib/igt_pm.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)
lib/igt_pm.c +25 -11
index 1e6e9ed3f..4f0cfbdd1 100644
@@ -863,6 +863,20 @@ bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output)
 	return strstr(buf, "LPSP: capable");
 }
 
+static int igt_pm_open_pci_firmware_node(struct pci_device *pci_dev)
+{
+	char name[PATH_MAX];
+	int dir;
+
+	snprintf(name, PATH_MAX,
+		 "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/firmware_node",
+		 pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func);
+
+	dir = open(name, O_RDONLY);
+
+	return dir;
+}
+
 /**
  * igt_pm_acpi_d3cold_supported:
  * @pci_dev: root port pci_dev.
@@ -873,23 +887,23 @@ bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output)
  */
 bool igt_pm_acpi_d3cold_supported(struct pci_device *pci_dev)
 {
-	char name[PATH_MAX];
-	int dir, fd;
-
-	snprintf(name, PATH_MAX,
-		 "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/firmware_node",
-		 pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func);
+	int firmware_node_fd, fd;
 
-	dir = open(name, O_RDONLY);
-	igt_require(dir > 0);
+	firmware_node_fd = igt_pm_open_pci_firmware_node(pci_dev);
+	if (firmware_node_fd < 0)
+		return false;
 
 	/* BIOS need to enable ACPI D3Cold Support.*/
-	fd = openat(dir, "real_power_state", O_RDONLY);
-	if (fd < 0 && errno == ENOENT)
+	fd = openat(firmware_node_fd, "real_power_state", O_RDONLY);
+	if (fd < 0 && errno == ENOENT) {
+		close(firmware_node_fd);
 		return false;
+	}
 
-	igt_require(fd > 0);
+	igt_assert(errno > 0);
 
+	close(firmware_node_fd);
+	close(fd);
 	return true;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v2 1/3
#2 lore raw

Re: [Intel-gfx] [PATCH i-g-t v2 1/3] lib/igt_pm: Refactor get firmware_node fd

Quoted 8 lines · Anshuman Gupta

Created igt_pm_open_pci_firmware_node() to refactor the retrieving the firmware_node fd code.

igt_pm_open_pci_firmware_node() will be used by other firmware_node consumers.

While doing that fixed the leaked fd as well.

Quoted 8 lines

v2:
- return false instead of igt_require on no firmware_node_fd. [Kamil]
- use igt_assert() when failed to open 'real_power_state' on error other then ENONET.

---
 lib/igt_pm.c | 36 +++++++++++++++++++++++++-----------

I believe we need a massive refactor in this lib... we have 2 different ways of using stuff, plus that ugly global restore...

but anyway, this one here looks a good change regardless of the current mess in the lib.

Quoted 65 lines
 1 file changed, 25 insertions(+), 11 deletions(-)
lib/igt_pm.c +25 -11
index 1e6e9ed3f..4f0cfbdd1 100644
@@ -863,6 +863,20 @@ bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output)
 	return strstr(buf, "LPSP: capable");
 }
 
+static int igt_pm_open_pci_firmware_node(struct pci_device *pci_dev)
+{
+	char name[PATH_MAX];
+	int dir;
+
+	snprintf(name, PATH_MAX,
+		 "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/firmware_node",
+		 pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func);
+
+	dir = open(name, O_RDONLY);
+
+	return dir;
+}
+
 /**
  * igt_pm_acpi_d3cold_supported:
  * @pci_dev: root port pci_dev.
@@ -873,23 +887,23 @@ bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output)
  */
 bool igt_pm_acpi_d3cold_supported(struct pci_device *pci_dev)
 {
-	char name[PATH_MAX];
-	int dir, fd;
-
-	snprintf(name, PATH_MAX,
-		 "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/firmware_node",
-		 pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func);
+	int firmware_node_fd, fd;
 
-	dir = open(name, O_RDONLY);
-	igt_require(dir > 0);
+	firmware_node_fd = igt_pm_open_pci_firmware_node(pci_dev);
+	if (firmware_node_fd < 0)
+		return false;
 
 	/* BIOS need to enable ACPI D3Cold Support.*/
-	fd = openat(dir, "real_power_state", O_RDONLY);
-	if (fd < 0 && errno == ENOENT)
+	fd = openat(firmware_node_fd, "real_power_state", O_RDONLY);
+	if (fd < 0 && errno == ENOENT) {
+		close(firmware_node_fd);
 		return false;
+	}
 
-	igt_require(fd > 0);
+	igt_assert(errno > 0);
 
+	close(firmware_node_fd);
+	close(fd);
 	return true;
 }
 
Signature · 1 line
2.25.1
#3 lore raw

Re: [Intel-gfx] [PATCH i-g-t v2 1/3] lib/igt_pm: Refactor get firmware_node fd

Quoted 29 lines

-----Original Message-----
From: Vivi, Rodrigo <[email protected]>
Sent: Tuesday, November 15, 2022 1:27 AM
To: Gupta, Anshuman <[email protected]>
Cc: [email protected]; [email protected]; Tangudu, Tilak <[email protected]>; Nilawar, Badal <[email protected]>
Subject: Re: [PATCH i-g-t v2 1/3] lib/igt_pm: Refactor get firmware_node fd

Quoted 8 lines · Anshuman Gupta

Created igt_pm_open_pci_firmware_node() to refactor the retrieving the firmware_node fd code.

igt_pm_open_pci_firmware_node() will be used by other firmware_node consumers.

While doing that fixed the leaked fd as well.

Quoted 8 lines

v2:
- return false instead of igt_require on no firmware_node_fd. [Kamil]
- use igt_assert() when failed to open 'real_power_state' on error other then ENONET.

---
 lib/igt_pm.c | 36 +++++++++++++++++++++++++-----------
Quoted 8 lines

I believe we need a massive refactor in this lib... we have 2 different ways of using stuff, plus that ugly global restore...

but anyway, this one here looks a good change regardless of the current mess in the lib.

Thanks Rodrigo for RB,
my bad I sent these patches on kernel mailing list instead of igt-dev. I will keep your RB and re-float the patches to igt-dev. Thanks,
Anshuman Gupta.

Quoted 71 lines

lib/igt_pm.c bool i915_output_is_lpsp_capable(int drm_fd,

Quoted 9 lines

 1 file changed, 25 insertions(+), 11 deletions(-)
lib/igt_pm.c index 1e6e9ed3f..4f0cfbdd1 renamed from lib/igt_pm.c +0 -0

100644

lib/igt_pm.c +0 -0
@@ -863,6 +863,20 @@ bool i915_output_is_lpsp_capable(int drm_fd,

igt_output_t *output)

lib/igt_pm.c bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output) · line 874

Quoted 9 lines
lib/igt_pm.c +7 -0
 	return strstr(buf, "LPSP: capable");  }
 
+static int igt_pm_open_pci_firmware_node(struct pci_device *pci_dev)
+{
+	char name[PATH_MAX];
+	int dir;
+
+	snprintf(name, PATH_MAX,
+

"/sys/bus/pci/devices/%04x:%02x:%02x.%01x/firmware_node",

lib/igt_pm.c bool i915_output_is_lpsp_capable(int drm_fd,

Quoted 12 lines
lib/igt_pm.c +7 -0
+		 pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev-
 func);
+
+	dir = open(name, O_RDONLY);
+
+	return dir;
+}
+
 /**
  * igt_pm_acpi_d3cold_supported:
  * @pci_dev: root port pci_dev.
@@ -873,23 +887,23 @@ bool i915_output_is_lpsp_capable(int drm_fd,

igt_output_t *output)

lib/igt_pm.c bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output)

Quoted 7 lines
lib/igt_pm.c +0 -5
  */
 bool igt_pm_acpi_d3cold_supported(struct pci_device *pci_dev)  {
-	char name[PATH_MAX];
-	int dir, fd;
-
-	snprintf(name, PATH_MAX,
-

"/sys/bus/pci/devices/%04x:%02x:%02x.%01x/firmware_node",

Quoted 30 lines
lib/igt_pm.c +11 -7
-		 pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev-
 func);
+	int firmware_node_fd, fd;
 
-	dir = open(name, O_RDONLY);
-	igt_require(dir > 0);
+	firmware_node_fd = igt_pm_open_pci_firmware_node(pci_dev);
+	if (firmware_node_fd < 0)
+		return false;
 
 	/* BIOS need to enable ACPI D3Cold Support.*/
-	fd = openat(dir, "real_power_state", O_RDONLY);
-	if (fd < 0 && errno == ENOENT)
+	fd = openat(firmware_node_fd, "real_power_state", O_RDONLY);
+	if (fd < 0 && errno == ENOENT) {
+		close(firmware_node_fd);
 		return false;
+	}
 
-	igt_require(fd > 0);
+	igt_assert(errno > 0);
 
+	close(firmware_node_fd);
+	close(fd);
 	return true;
 }
 
--

2.25.1

#4 lore raw

PATCH v2 2/3 test/device_reset: Refactor initiate_device_reset

In reply to Anshuman Gupta

Added a reset type enum to support multiple types
of reset like WARM, COLD and FLR reset.

No functional change.

v2:
- Removed WARM_RESET enum as not used yet. [Badal]

---
 tests/device_reset.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
tests/device_reset.c +14 -6
index e60d4c7fd..0c477a02c 100644
@@ -19,6 +19,11 @@ IGT_TEST_DESCRIPTION("Examine behavior of a driver on device sysfs reset");
 #define DEV_PATH_LEN 80
 #define DEV_BUS_ADDR_LEN 13 /* addr has form 0000:00:00.0 */
 
+enum reset {
+	COLD_RESET,
+	FLR_RESET
+};
+
 /**
  * Helper structure containing file descriptors
  * and bus address related to tested device
@@ -222,10 +227,13 @@ static void driver_bind(struct device_fds *dev)
 }
 
 /* Initiate device reset */
-static void initiate_device_reset(struct device_fds *dev)
+static void initiate_device_reset(struct device_fds *dev, enum reset type)
 {
 	igt_debug("reset device\n");
-	igt_assert(igt_sysfs_set(dev->fds.dev_dir, "reset", "1"));
+
+	if (type == FLR_RESET)
+		igt_assert(igt_sysfs_set(dev->fds.dev_dir, "reset", "1"));
+
 }
 
 static bool is_i915_wedged(int i915)
@@ -274,14 +282,14 @@ static void set_device_filter(const char* dev_path)
 	igt_assert_eq(igt_device_filter_add(filter), 1);
 }
 
-static void unbind_reset_rebind(struct device_fds *dev)
+static void unbind_reset_rebind(struct device_fds *dev, enum reset type)
 {
 	igt_debug("close the device\n");
 	close_if_opened(&dev->fds.dev);
 
 	driver_unbind(dev);
 
-	initiate_device_reset(dev);
+	initiate_device_reset(dev, type);
 
 	driver_bind(dev);
 }
@@ -306,13 +314,13 @@ igt_main
 	igt_describe("Unbinds driver from device, initiates reset"
 		     " then rebinds driver to device");
 	igt_subtest("unbind-reset-rebind") {
-		unbind_reset_rebind(&dev);
+		unbind_reset_rebind(&dev, FLR_RESET);
 		healthcheck(&dev);
 	}
 
 	igt_describe("Resets device with bound driver");
 	igt_subtest("reset-bound") {
-		initiate_device_reset(&dev);
+		initiate_device_reset(&dev, FLR_RESET);
 		healthcheck(&dev);
 	}
 
Signature · 1 line
2.25.1
#5 lore raw

PATCH v2 3/3 tests/device_reset: Add cold reset IGT test

In reply to Anshuman Gupta

Add cold-reset IGT subtest, IGT subtest will use /sys/bus/pci/slots/$SUN/power sysfs in order to initiate a cold reset sequence. $SUN value will be retrieved from PCIe device ACPI firmware node.

v2:
- %s/igt_require(fd > 0)/igt_assert(errno >0)

---
 lib/igt_pm.c         |  40 ++++++++++++++
 lib/igt_pm.h         |   1 +
 tests/device_reset.c | 124 +++++++++++++++++++++++++++++++++++++++----
 3 files changed, 155 insertions(+), 10 deletions(-)
lib/igt_pm.c +40 -0
index 4f0cfbdd1..9b7ed4be6 100644
@@ -877,6 +877,46 @@ static int igt_pm_open_pci_firmware_node(struct pci_device *pci_dev)
 	return dir;
 }
 
+/**
+ * igt_pm_get_pcie_acpihp_slot:
+ * @pci_dev: pci bridge device.
+ * Get pci bridge acpi hotplug slot number, if bridge's ACPI firmware_node
+ * handle supports _SUN method.
+ *
+ * Returns:
+ * PCIe bridge Slot number.
+ * Returns -ENOENT number in case firmware_node/sun is not supported by the
+ * bridge.
+ */
+int igt_pm_get_pcie_acpihp_slot(struct pci_device *pci_dev)
+{
+	int firmware_node_fd, fd, n_read;
+	char sun[8];
+
+	firmware_node_fd = igt_pm_open_pci_firmware_node(pci_dev);
+
+	if (firmware_node_fd < 0 && errno == ENOENT)
+		return -ENOENT;
+
+	igt_require(firmware_node_fd > 0);
+
+	fd = openat(firmware_node_fd, "sun", O_RDONLY);
+	if (fd < 0 && errno == ENOENT) {
+		close(firmware_node_fd);
+		return -ENOENT;
+	}
+
+	igt_assert(errno > 0);
+
+	n_read = read(fd, sun, sizeof(sun));
+	igt_assert(n_read > 0);
+
+	close(firmware_node_fd);
+	close(fd);
+
+	return strtol(sun, NULL, 10);
+}
+
 /**
  * igt_pm_acpi_d3cold_supported:
  * @pci_dev: root port pci_dev.
lib/igt_pm.h +1 -0
index e81fceb89..f65b960c3 100644
@@ -73,6 +73,7 @@ bool igt_wait_for_pm_status(enum igt_runtime_pm_status status);
 bool igt_pm_dmc_loaded(int debugfs);
 bool igt_pm_pc8_plus_residencies_enabled(int msr_fd);
 bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output);
+int igt_pm_get_pcie_acpihp_slot(struct pci_device *pci_dev);
 bool igt_pm_acpi_d3cold_supported(struct pci_device *pci_dev);
 enum igt_acpi_d_state
 igt_pm_get_acpi_real_d_state(struct pci_device *pci_dev);
tests/device_reset.c +114 -10

175 lines not on this page · raw message

Signature · 1 line
2.25.1