Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t v4 0/4] Add d3 mmap test
@ 2023-12-21 16:33 Anshuman Gupta
  2023-12-21 16:33 ` [PATCH i-g-t v4 1/4] test/xe_pm: Add exit handler to close fw handle Anshuman Gupta
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Anshuman Gupta @ 2023-12-21 16:33 UTC (permalink / raw)
  To: igt-dev; +Cc: kamil.konieczny, rodrigo.vivi

Add d3 mmap test.

Anshuman Gupta (4):
  test/xe_pm: Add exit handler to close fw handle
  lib/igt_pm: Add helper to get/set auto_suspenddelay_ms
  tests/xe_pm: Add d3-mmap IGT test
  HAX: Add d3-mmap to xe-fast-feedback

 lib/igt_pm.c                             |  53 ++++++---
 lib/igt_pm.h                             |   2 +
 tests/intel-ci/xe-fast-feedback.testlist |   1 +
 tests/intel/xe_pm.c                      | 131 +++++++++++++++++++++--
 4 files changed, 166 insertions(+), 21 deletions(-)

-- 
2.25.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH i-g-t v4 1/4] test/xe_pm: Add exit handler to close fw handle
  2023-12-21 16:33 [PATCH i-g-t v4 0/4] Add d3 mmap test Anshuman Gupta
@ 2023-12-21 16:33 ` Anshuman Gupta
  2023-12-21 16:33 ` [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set auto_suspenddelay_ms Anshuman Gupta
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Anshuman Gupta @ 2023-12-21 16:33 UTC (permalink / raw)
  To: igt-dev; +Cc: kamil.konieczny, rodrigo.vivi

Adding an exit handler to close the fw handle to make sure we don't
leak the fw in CI environment. Adding a IGT subtest group for the
test using the fw handle to runtime wake the device.
Scaling forcewake close exit handler for vram-d3cold-threshold
subtest, while doing so add the missing subtest Functionality
as well.

Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
---
 tests/intel/xe_pm.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/tests/intel/xe_pm.c b/tests/intel/xe_pm.c
index 602729daf..c4ec38ae3 100644
--- a/tests/intel/xe_pm.c
+++ b/tests/intel/xe_pm.c
@@ -39,6 +39,7 @@ typedef struct {
 } device_t;
 
 uint64_t orig_threshold;
+int fw_handle = -1;
 
 /* runtime_usage is only available if kernel build CONFIG_PM_ADVANCED_DEBUG */
 static bool runtime_usage_available(struct pci_device *pci)
@@ -166,6 +167,14 @@ static bool out_of_d3(device_t device, enum igt_acpi_d_state state)
 	return true;
 }
 
+static void close_fw_handle(int sig)
+{
+	if (fw_handle < 0)
+		return;
+
+	close(fw_handle);
+}
+
 /**
  * SUBTEST: %s-basic
  * Description: set GPU state to %arg[1] and test suspend/autoresume
@@ -382,9 +391,9 @@ static void test_vram_d3cold_threshold(device_t device, int sysfs_fd)
 	};
 	uint64_t vram_used_mb = 0, vram_total_mb = 0, threshold;
 	uint32_t bo, placement;
-	int handle, i;
 	bool active;
 	void *map;
+	int i;
 
 	igt_require(xe_has_vram(device.fd_xe));
 
@@ -428,10 +437,10 @@ static void test_vram_d3cold_threshold(device_t device, int sysfs_fd)
 	 * the device from runtime suspend.
 	 * Therefore open and close fw handle to wake the device.
 	 */
-	handle = igt_debugfs_open(device.fd_xe, "forcewake_all", O_RDONLY);
-	igt_assert(handle >= 0);
+	fw_handle = igt_debugfs_open(device.fd_xe, "forcewake_all", O_RDONLY);
+	igt_assert(fw_handle >= 0);
 	active = igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE;
-	close(handle);
+	close(fw_handle);
 	igt_assert(active);
 
 	/* Test D3Cold again after freeing up the Xe BO */
@@ -536,11 +545,18 @@ igt_main
 		}
 	}
 
-	igt_describe("Validate whether card is limited to d3hot, if vram used > vram threshold");
-	igt_subtest("vram-d3cold-threshold") {
-		orig_threshold = get_vram_d3cold_threshold(sysfs_fd);
-		igt_install_exit_handler(vram_d3cold_threshold_restore);
-		test_vram_d3cold_threshold(device, sysfs_fd);
+	igt_subtest_group {
+		igt_fixture {
+			igt_install_exit_handler(close_fw_handle);
+		}
+
+		igt_describe("Validate whether card is limited to d3hot,"
+			     "if vram used > vram threshold");
+		igt_subtest("vram-d3cold-threshold") {
+			orig_threshold = get_vram_d3cold_threshold(sysfs_fd);
+			igt_install_exit_handler(vram_d3cold_threshold_restore);
+			test_vram_d3cold_threshold(device, sysfs_fd);
+		}
 	}
 
 	igt_fixture {
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set auto_suspenddelay_ms
  2023-12-21 16:33 [PATCH i-g-t v4 0/4] Add d3 mmap test Anshuman Gupta
  2023-12-21 16:33 ` [PATCH i-g-t v4 1/4] test/xe_pm: Add exit handler to close fw handle Anshuman Gupta
@ 2023-12-21 16:33 ` Anshuman Gupta
  2023-12-28  0:40   ` Rodrigo Vivi
  2023-12-21 16:33 ` [PATCH i-g-t v4 3/4] tests/xe_pm: Add d3-mmap IGT test Anshuman Gupta
  2023-12-21 16:33 ` [PATCH i-g-t v4 4/4] HAX: Add d3-mmap to xe-fast-feedback Anshuman Gupta
  3 siblings, 1 reply; 10+ messages in thread
From: Anshuman Gupta @ 2023-12-21 16:33 UTC (permalink / raw)
  To: igt-dev; +Cc: kamil.konieczny, rodrigo.vivi

Sometimes we want to test pm igt test with an explicit auto
suspend delay, therefore adding helpers to get/set the pci_dev
auto_suspenddelay_ms.

Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
---
 lib/igt_pm.c | 53 ++++++++++++++++++++++++++++++++++++++++------------
 lib/igt_pm.h |  2 ++
 2 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index c2d98fceb..d436c2c50 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -1068,18 +1068,6 @@ static void igt_pm_write_power_attr(int fd, const char *val, int len)
 	igt_assert(strncmp(buf, val, len) == 0);
 }
 
-static int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev)
-{
-	char delay_str[64];
-	int delay, delay_fd;
-
-	delay_fd = igt_pm_get_power_attr_fd(pci_dev, "autosuspend_delay_ms");
-	if (igt_pm_read_power_attr(delay_fd, delay_str, 64, true))
-		igt_assert(sscanf(delay_str, "%d", &delay) > 0);
-
-	return delay;
-}
-
 static void
 igt_pm_setup_pci_dev_power_attrs(struct pci_device *pci_dev,
 				 struct igt_pm_pci_dev_pwrattr *pwrattr, int delay_ms)
@@ -1165,6 +1153,47 @@ igt_pm_setup_pci_card_power_attrs(struct pci_device *pci_dev, bool save_attrs, i
 	pci_iterator_destroy(iter);
 }
 
+/**
+ * igt_pm_get_autosuspend_delay:
+ * @pci_dev: pci_dev.
+ * Get pci_dev autosuspend delay value from pci sysfs "autosuspend_delay_ms".
+ *
+ * Returns:
+ * autosuspend_delay_ms.
+ */
+int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev)
+{
+	char delay_str[64];
+	int delay, delay_fd;
+
+	delay_fd = igt_pm_get_power_attr_fd(pci_dev, "autosuspend_delay_ms");
+	if (igt_pm_read_power_attr(delay_fd, delay_str, 64, true))
+		igt_assert(sscanf(delay_str, "%d", &delay) > 0);
+
+	return delay;
+}
+
+/**
+ * igt_pm_set_autosuspend_delay:
+ * @pci_dev: pci_dev.
+ * @delay_ms: autosuspend delay in ms.
+ * Set pci_dev autosuspend delay value through pci sysfs "autosuspend_delay_ms".
+ */
+void igt_pm_set_autosuspend_delay(struct pci_device *pci_dev, int delay_ms)
+{
+	char delay_str[64];
+	int delay_fd;
+
+	delay_fd = igt_pm_get_power_attr_fd(pci_dev, "autosuspend_delay_ms");
+
+	if (delay_ms >= 0) {
+		int wc;
+
+		wc = snprintf(delay_str, 64, "%d\n", delay_ms);
+		igt_pm_write_power_attr(delay_fd, delay_str, wc);
+	}
+}
+
 /**
  * igt_pm_enable_pci_card_runtime_pm:
  * @root: root port pci_dev.
diff --git a/lib/igt_pm.h b/lib/igt_pm.h
index 306a9eb46..8394315c6 100644
--- a/lib/igt_pm.h
+++ b/lib/igt_pm.h
@@ -77,6 +77,8 @@ 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);
+int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev);
+void igt_pm_set_autosuspend_delay(struct pci_device *pci_dev, int delay_ms);
 void igt_pm_enable_pci_card_runtime_pm(struct pci_device *root,
 				       struct pci_device *i915);
 void igt_pm_get_d3cold_allowed(const char *pci_slot_name, uint32_t *value);
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH i-g-t v4 3/4] tests/xe_pm: Add d3-mmap IGT test
  2023-12-21 16:33 [PATCH i-g-t v4 0/4] Add d3 mmap test Anshuman Gupta
  2023-12-21 16:33 ` [PATCH i-g-t v4 1/4] test/xe_pm: Add exit handler to close fw handle Anshuman Gupta
  2023-12-21 16:33 ` [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set auto_suspenddelay_ms Anshuman Gupta
@ 2023-12-21 16:33 ` Anshuman Gupta
  2023-12-22  7:48   ` Nilawar, Badal
  2023-12-21 16:33 ` [PATCH i-g-t v4 4/4] HAX: Add d3-mmap to xe-fast-feedback Anshuman Gupta
  3 siblings, 1 reply; 10+ messages in thread
From: Anshuman Gupta @ 2023-12-21 16:33 UTC (permalink / raw)
  To: igt-dev; +Cc: kamil.konieczny, rodrigo.vivi

Adding a test to validate mmap memory mappings along with runtime
suspend and resume for both xe device and it's pci parent bridge
in device hierarchy.

v2:
- Use 0xc00fee pattern. [Rodrigo]
- Test the pagefault case on read and write the mapping. [Rodrigo]

v3:
- Cosmetic comment. [Kamil]
- Use MAGIC macro for 0xc0ffe and 0xdeadbeef. [Kamil]
- Fix xe_bo_create() with respect to Xe uapi.
- Set auto_suspend delay to 1000ms and restore it.

Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
---
 tests/intel/xe_pm.c | 97 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/tests/intel/xe_pm.c b/tests/intel/xe_pm.c
index c4ec38ae3..9e7c523eb 100644
--- a/tests/intel/xe_pm.c
+++ b/tests/intel/xe_pm.c
@@ -30,6 +30,8 @@
 #define NO_RPM -1
 
 #define SIZE (4096 * 1024)
+#define MAGIC_1 0xc0ffee
+#define MAGIC_2 0xdeadbeef
 
 typedef struct {
 	int fd_xe;
@@ -447,6 +449,84 @@ static void test_vram_d3cold_threshold(device_t device, int sysfs_fd)
 	igt_assert(in_d3(device, IGT_ACPI_D3Cold));
 }
 
+/**
+ * SUBTEST: d3-mmap-%s
+ * Description:
+ *	Validate mmap memory mapping with d3 state, for %arg[1] region,
+ *	if supported by device.
+ * arg[1]:
+ *
+ * @vram:	vram region
+ * @system:	system region
+ *
+ * Functionality: pm-d3
+ * Run type: FULL
+ */
+static void test_mmap(device_t device, uint32_t placement, uint32_t flags)
+{
+	size_t bo_size = 8192;
+	uint32_t *map = NULL;
+	uint32_t bo;
+	int i, delay_ms;
+
+	igt_require_f(placement, "Device doesn't support such memory region\n");
+
+	bo_size = ALIGN(bo_size, xe_get_default_alignment(device.fd_xe));
+
+	bo = xe_bo_create(device.fd_xe, 0, bo_size, placement, flags);
+	map = xe_bo_map(device.fd_xe, bo, bo_size);
+	igt_assert(map);
+	memset(map, 0, bo_size);
+
+	fw_handle = igt_debugfs_open(device.fd_xe, "forcewake_all", O_RDONLY);
+
+	igt_assert(fw_handle >= 0);
+	igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
+
+	for (i = 0; i < bo_size / sizeof(*map); i++)
+		map[i] = MAGIC_1;
+
+	for (i = 0; i < bo_size / sizeof(*map); i++)
+		igt_assert(map[i] == MAGIC_1);
+
+	/* Runtime suspend and validate the pattern and changed the pattern */
+	close(fw_handle);
+	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
+
+	for (i = 0; i < bo_size / sizeof(*map); i++)
+		igt_assert(map[i] == MAGIC_1);
+
+	/* dgfx page-fault on mmaping should wake the gpu */
+	if (xe_has_vram(device.fd_xe)) {
+		/* Give some auto suspend delay to validate rpm active */
+		delay_ms = igt_pm_get_autosuspend_delay(device.pci_xe);
+		igt_pm_set_autosuspend_delay(device.pci_xe, 1000);
+		igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
+		igt_pm_set_autosuspend_delay(device.pci_xe, delay_ms);
+	}
+
+	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
+
+	for (i = 0; i < bo_size / sizeof(*map); i++)
+		map[i] = MAGIC_2;
+
+	if (xe_has_vram(device.fd_xe))
+		igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
+
+	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
+
+	/* Runtime resume and check the pattern */
+	fw_handle = igt_debugfs_open(device.fd_xe, "forcewake_all", O_RDONLY);
+	igt_assert(fw_handle >= 0);
+	igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
+	for (i = 0; i < bo_size / sizeof(*map); i++)
+		igt_assert(map[i] == MAGIC_2);
+
+	igt_assert(munmap(map, bo_size) == 0);
+	gem_close(device.fd_xe, bo);
+	close(fw_handle);
+}
+
 igt_main
 {
 	struct drm_xe_engine_class_instance *hwe;
@@ -557,6 +637,23 @@ igt_main
 			igt_install_exit_handler(vram_d3cold_threshold_restore);
 			test_vram_d3cold_threshold(device, sysfs_fd);
 		}
+
+		igt_describe("Validate mmap memory mappings with system region,"
+			     "when device along with parent bridge in d3");
+		igt_subtest("d3-mmap-system") {
+			test_mmap(device, system_memory(device.fd_xe), 0);
+		}
+
+		igt_describe("Validate mmap memory mappings with vram region,"
+			     "when device along with parent bridge in d3");
+		igt_subtest("d3-mmap-vram") {
+			if (device.pci_root != device.pci_xe) {
+				igt_pm_enable_pci_card_runtime_pm(device.pci_root, NULL);
+				igt_pm_set_d3cold_allowed(device.pci_slot_name, 1);
+			}
+
+			test_mmap(device, vram_memory(device.fd_xe, 0), DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM);
+		}
 	}
 
 	igt_fixture {
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH i-g-t v4 4/4] HAX: Add d3-mmap to xe-fast-feedback
  2023-12-21 16:33 [PATCH i-g-t v4 0/4] Add d3 mmap test Anshuman Gupta
                   ` (2 preceding siblings ...)
  2023-12-21 16:33 ` [PATCH i-g-t v4 3/4] tests/xe_pm: Add d3-mmap IGT test Anshuman Gupta
@ 2023-12-21 16:33 ` Anshuman Gupta
  3 siblings, 0 replies; 10+ messages in thread
From: Anshuman Gupta @ 2023-12-21 16:33 UTC (permalink / raw)
  To: igt-dev; +Cc: kamil.konieczny, rodrigo.vivi

Adding d3-mmap to xe-fast-feedback.

Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
---
 tests/intel-ci/xe-fast-feedback.testlist | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/intel-ci/xe-fast-feedback.testlist b/tests/intel-ci/xe-fast-feedback.testlist
index bef5b0b8a..eafeb83a8 100644
--- a/tests/intel-ci/xe-fast-feedback.testlist
+++ b/tests/intel-ci/xe-fast-feedback.testlist
@@ -113,6 +113,7 @@ igt@xe_mmap@system
 igt@xe_mmap@vram
 igt@xe_mmap@vram-system
 igt@xe_pm_residency@gt-c6-on-idle
+igt@xe_pm@d3-mmap
 igt@xe_prime_self_import@basic-with_one_bo
 igt@xe_prime_self_import@basic-with_fd_dup
 #igt@xe_prime_self_import@basic-llseek-size
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH i-g-t v4 3/4] tests/xe_pm: Add d3-mmap IGT test
  2023-12-21 16:33 ` [PATCH i-g-t v4 3/4] tests/xe_pm: Add d3-mmap IGT test Anshuman Gupta
@ 2023-12-22  7:48   ` Nilawar, Badal
  2023-12-22  7:48     ` Nilawar, Badal
  0 siblings, 1 reply; 10+ messages in thread
From: Nilawar, Badal @ 2023-12-22  7:48 UTC (permalink / raw)
  To: Anshuman Gupta, igt-dev; +Cc: kamil.konieczny, rodrigo.vivi



On 21-12-2023 22:03, Anshuman Gupta wrote:
> Adding a test to validate mmap memory mappings along with runtime
> suspend and resume for both xe device and it's pci parent bridge
> in device hierarchy.
> 
> v2:
> - Use 0xc00fee pattern. [Rodrigo]
> - Test the pagefault case on read and write the mapping. [Rodrigo]
> 
> v3:
> - Cosmetic comment. [Kamil]
> - Use MAGIC macro for 0xc0ffe and 0xdeadbeef. [Kamil]
> - Fix xe_bo_create() with respect to Xe uapi.
> - Set auto_suspend delay to 1000ms and restore it.
> 
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> ---
>   tests/intel/xe_pm.c | 97 +++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 97 insertions(+)
> 
> diff --git a/tests/intel/xe_pm.c b/tests/intel/xe_pm.c
> index c4ec38ae3..9e7c523eb 100644
> --- a/tests/intel/xe_pm.c
> +++ b/tests/intel/xe_pm.c
> @@ -30,6 +30,8 @@
>   #define NO_RPM -1
>   
>   #define SIZE (4096 * 1024)
> +#define MAGIC_1 0xc0ffee
> +#define MAGIC_2 0xdeadbeef
>   
>   typedef struct {
>   	int fd_xe;
> @@ -447,6 +449,84 @@ static void test_vram_d3cold_threshold(device_t device, int sysfs_fd)
>   	igt_assert(in_d3(device, IGT_ACPI_D3Cold));
>   }
>   
> +/**
> + * SUBTEST: d3-mmap-%s
> + * Description:
> + *	Validate mmap memory mapping with d3 state, for %arg[1] region,
> + *	if supported by device.
> + * arg[1]:
> + *
> + * @vram:	vram region
> + * @system:	system region
> + *
> + * Functionality: pm-d3
> + * Run type: FULL
> + */
> +static void test_mmap(device_t device, uint32_t placement, uint32_t flags)
> +{
> +	size_t bo_size = 8192;
> +	uint32_t *map = NULL;
> +	uint32_t bo;
> +	int i, delay_ms;
> +
> +	igt_require_f(placement, "Device doesn't support such memory region\n");
> +
> +	bo_size = ALIGN(bo_size, xe_get_default_alignment(device.fd_xe));
> +
> +	bo = xe_bo_create(device.fd_xe, 0, bo_size, placement, flags);
> +	map = xe_bo_map(device.fd_xe, bo, bo_size);
> +	igt_assert(map);
> +	memset(map, 0, bo_size);
> +
> +	fw_handle = igt_debugfs_open(device.fd_xe, "forcewake_all", O_RDONLY);
> +
> +	igt_assert(fw_handle >= 0);
> +	igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
> +
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		map[i] = MAGIC_1;
> +
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		igt_assert(map[i] == MAGIC_1);
> +
> +	/* Runtime suspend and validate the pattern and changed the pattern */
> +	close(fw_handle);
> +	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
> +
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		igt_assert(map[i] == MAGIC_1);
> +
> +	/* dgfx page-fault on mmaping should wake the gpu */
> +	if (xe_has_vram(device.fd_xe)) {
> +		/* Give some auto suspend delay to validate rpm active */
> +		delay_ms = igt_pm_get_autosuspend_delay(device.pci_xe);
> +		igt_pm_set_autosuspend_delay(device.pci_xe, 1000);
> +		igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
> +		igt_pm_set_autosuspend_delay(device.pci_xe, delay_ms);
> +	}
> +
> +	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
> +
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		map[i] = MAGIC_2;
> +
> +	if (xe_has_vram(device.fd_xe))
> +		igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
Need to increase auto suspend delay at this place as well. I think 
better to change it at the beginning of test and restore back at the end 
of test.

Regards,
Badal
> +
> +	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
> +
> +	/* Runtime resume and check the pattern */
> +	fw_handle = igt_debugfs_open(device.fd_xe, "forcewake_all", O_RDONLY);
> +	igt_assert(fw_handle >= 0);
> +	igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		igt_assert(map[i] == MAGIC_2);
> +
> +	igt_assert(munmap(map, bo_size) == 0);
> +	gem_close(device.fd_xe, bo);
> +	close(fw_handle);
> +}
> +
>   igt_main
>   {
>   	struct drm_xe_engine_class_instance *hwe;
> @@ -557,6 +637,23 @@ igt_main
>   			igt_install_exit_handler(vram_d3cold_threshold_restore);
>   			test_vram_d3cold_threshold(device, sysfs_fd);
>   		}
> +
> +		igt_describe("Validate mmap memory mappings with system region,"
> +			     "when device along with parent bridge in d3");
> +		igt_subtest("d3-mmap-system") {
> +			test_mmap(device, system_memory(device.fd_xe), 0);
> +		}
> +
> +		igt_describe("Validate mmap memory mappings with vram region,"
> +			     "when device along with parent bridge in d3");
> +		igt_subtest("d3-mmap-vram") {
> +			if (device.pci_root != device.pci_xe) {
> +				igt_pm_enable_pci_card_runtime_pm(device.pci_root, NULL);
> +				igt_pm_set_d3cold_allowed(device.pci_slot_name, 1);
> +			}
> +
> +			test_mmap(device, vram_memory(device.fd_xe, 0), DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM);
> +		}
>   	}
>   
>   	igt_fixture {

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH i-g-t v4 3/4] tests/xe_pm: Add d3-mmap IGT test
  2023-12-22  7:48   ` Nilawar, Badal
@ 2023-12-22  7:48     ` Nilawar, Badal
  0 siblings, 0 replies; 10+ messages in thread
From: Nilawar, Badal @ 2023-12-22  7:48 UTC (permalink / raw)
  To: Anshuman Gupta, igt-dev; +Cc: kamil.konieczny, rodrigo.vivi



On 21-12-2023 22:03, Anshuman Gupta wrote:
> Adding a test to validate mmap memory mappings along with runtime
> suspend and resume for both xe device and it's pci parent bridge
> in device hierarchy.
> 
> v2:
> - Use 0xc00fee pattern. [Rodrigo]
> - Test the pagefault case on read and write the mapping. [Rodrigo]
> 
> v3:
> - Cosmetic comment. [Kamil]
> - Use MAGIC macro for 0xc0ffe and 0xdeadbeef. [Kamil]
> - Fix xe_bo_create() with respect to Xe uapi.
> - Set auto_suspend delay to 1000ms and restore it.
> 
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> ---
>   tests/intel/xe_pm.c | 97 +++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 97 insertions(+)
> 
> diff --git a/tests/intel/xe_pm.c b/tests/intel/xe_pm.c
> index c4ec38ae3..9e7c523eb 100644
> --- a/tests/intel/xe_pm.c
> +++ b/tests/intel/xe_pm.c
> @@ -30,6 +30,8 @@
>   #define NO_RPM -1
>   
>   #define SIZE (4096 * 1024)
> +#define MAGIC_1 0xc0ffee
> +#define MAGIC_2 0xdeadbeef
>   
>   typedef struct {
>   	int fd_xe;
> @@ -447,6 +449,84 @@ static void test_vram_d3cold_threshold(device_t device, int sysfs_fd)
>   	igt_assert(in_d3(device, IGT_ACPI_D3Cold));
>   }
>   
> +/**
> + * SUBTEST: d3-mmap-%s
> + * Description:
> + *	Validate mmap memory mapping with d3 state, for %arg[1] region,
> + *	if supported by device.
> + * arg[1]:
> + *
> + * @vram:	vram region
> + * @system:	system region
> + *
> + * Functionality: pm-d3
> + * Run type: FULL
> + */
> +static void test_mmap(device_t device, uint32_t placement, uint32_t flags)
> +{
> +	size_t bo_size = 8192;
> +	uint32_t *map = NULL;
> +	uint32_t bo;
> +	int i, delay_ms;
> +
> +	igt_require_f(placement, "Device doesn't support such memory region\n");
> +
> +	bo_size = ALIGN(bo_size, xe_get_default_alignment(device.fd_xe));
> +
> +	bo = xe_bo_create(device.fd_xe, 0, bo_size, placement, flags);
> +	map = xe_bo_map(device.fd_xe, bo, bo_size);
> +	igt_assert(map);
> +	memset(map, 0, bo_size);
> +
> +	fw_handle = igt_debugfs_open(device.fd_xe, "forcewake_all", O_RDONLY);
> +
> +	igt_assert(fw_handle >= 0);
> +	igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
> +
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		map[i] = MAGIC_1;
> +
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		igt_assert(map[i] == MAGIC_1);
> +
> +	/* Runtime suspend and validate the pattern and changed the pattern */
> +	close(fw_handle);
> +	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
> +
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		igt_assert(map[i] == MAGIC_1);
> +
> +	/* dgfx page-fault on mmaping should wake the gpu */
> +	if (xe_has_vram(device.fd_xe)) {
> +		/* Give some auto suspend delay to validate rpm active */
> +		delay_ms = igt_pm_get_autosuspend_delay(device.pci_xe);
> +		igt_pm_set_autosuspend_delay(device.pci_xe, 1000);
> +		igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
> +		igt_pm_set_autosuspend_delay(device.pci_xe, delay_ms);
> +	}
> +
> +	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
> +
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		map[i] = MAGIC_2;
> +
> +	if (xe_has_vram(device.fd_xe))
> +		igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
Need to increase auto suspend delay at this place as well. I think 
better to change it at the beginning of test and restore back at the end 
of test.

Regards,
Badal
> +
> +	igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
> +
> +	/* Runtime resume and check the pattern */
> +	fw_handle = igt_debugfs_open(device.fd_xe, "forcewake_all", O_RDONLY);
> +	igt_assert(fw_handle >= 0);
> +	igt_assert(igt_get_runtime_pm_status() == IGT_RUNTIME_PM_STATUS_ACTIVE);
> +	for (i = 0; i < bo_size / sizeof(*map); i++)
> +		igt_assert(map[i] == MAGIC_2);
> +
> +	igt_assert(munmap(map, bo_size) == 0);
> +	gem_close(device.fd_xe, bo);
> +	close(fw_handle);
> +}
> +
>   igt_main
>   {
>   	struct drm_xe_engine_class_instance *hwe;
> @@ -557,6 +637,23 @@ igt_main
>   			igt_install_exit_handler(vram_d3cold_threshold_restore);
>   			test_vram_d3cold_threshold(device, sysfs_fd);
>   		}
> +
> +		igt_describe("Validate mmap memory mappings with system region,"
> +			     "when device along with parent bridge in d3");
> +		igt_subtest("d3-mmap-system") {
> +			test_mmap(device, system_memory(device.fd_xe), 0);
> +		}
> +
> +		igt_describe("Validate mmap memory mappings with vram region,"
> +			     "when device along with parent bridge in d3");
> +		igt_subtest("d3-mmap-vram") {
> +			if (device.pci_root != device.pci_xe) {
> +				igt_pm_enable_pci_card_runtime_pm(device.pci_root, NULL);
> +				igt_pm_set_d3cold_allowed(device.pci_slot_name, 1);
> +			}
> +
> +			test_mmap(device, vram_memory(device.fd_xe, 0), DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM);
> +		}
>   	}
>   
>   	igt_fixture {

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set auto_suspenddelay_ms
  2023-12-21 16:33 ` [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set auto_suspenddelay_ms Anshuman Gupta
@ 2023-12-28  0:40   ` Rodrigo Vivi
  2024-01-19 14:12     ` Gupta, Anshuman
  0 siblings, 1 reply; 10+ messages in thread
From: Rodrigo Vivi @ 2023-12-28  0:40 UTC (permalink / raw)
  To: Anshuman Gupta; +Cc: igt-dev, kamil.konieczny

On Thu, Dec 21, 2023 at 10:03:36PM +0530, Anshuman Gupta wrote:
> Sometimes we want to test pm igt test with an explicit auto
> suspend delay, therefore adding helpers to get/set the pci_dev
> auto_suspenddelay_ms.
> 
> Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

we also need to change the default value from 0 to 1 at least,
and then see how much more time machine we use. But 0 is unrealistic.

> ---
>  lib/igt_pm.c | 53 ++++++++++++++++++++++++++++++++++++++++------------
>  lib/igt_pm.h |  2 ++
>  2 files changed, 43 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/igt_pm.c b/lib/igt_pm.c
> index c2d98fceb..d436c2c50 100644
> --- a/lib/igt_pm.c
> +++ b/lib/igt_pm.c
> @@ -1068,18 +1068,6 @@ static void igt_pm_write_power_attr(int fd, const char *val, int len)
>  	igt_assert(strncmp(buf, val, len) == 0);
>  }
>  
> -static int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev)
> -{
> -	char delay_str[64];
> -	int delay, delay_fd;
> -
> -	delay_fd = igt_pm_get_power_attr_fd(pci_dev, "autosuspend_delay_ms");
> -	if (igt_pm_read_power_attr(delay_fd, delay_str, 64, true))
> -		igt_assert(sscanf(delay_str, "%d", &delay) > 0);
> -
> -	return delay;
> -}
> -
>  static void
>  igt_pm_setup_pci_dev_power_attrs(struct pci_device *pci_dev,
>  				 struct igt_pm_pci_dev_pwrattr *pwrattr, int delay_ms)
> @@ -1165,6 +1153,47 @@ igt_pm_setup_pci_card_power_attrs(struct pci_device *pci_dev, bool save_attrs, i
>  	pci_iterator_destroy(iter);
>  }
>  
> +/**
> + * igt_pm_get_autosuspend_delay:
> + * @pci_dev: pci_dev.
> + * Get pci_dev autosuspend delay value from pci sysfs "autosuspend_delay_ms".
> + *
> + * Returns:
> + * autosuspend_delay_ms.
> + */
> +int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev)
> +{
> +	char delay_str[64];
> +	int delay, delay_fd;
> +
> +	delay_fd = igt_pm_get_power_attr_fd(pci_dev, "autosuspend_delay_ms");
> +	if (igt_pm_read_power_attr(delay_fd, delay_str, 64, true))
> +		igt_assert(sscanf(delay_str, "%d", &delay) > 0);
> +
> +	return delay;
> +}
> +
> +/**
> + * igt_pm_set_autosuspend_delay:
> + * @pci_dev: pci_dev.
> + * @delay_ms: autosuspend delay in ms.
> + * Set pci_dev autosuspend delay value through pci sysfs "autosuspend_delay_ms".
> + */
> +void igt_pm_set_autosuspend_delay(struct pci_device *pci_dev, int delay_ms)
> +{
> +	char delay_str[64];
> +	int delay_fd;
> +
> +	delay_fd = igt_pm_get_power_attr_fd(pci_dev, "autosuspend_delay_ms");
> +
> +	if (delay_ms >= 0) {
> +		int wc;
> +
> +		wc = snprintf(delay_str, 64, "%d\n", delay_ms);
> +		igt_pm_write_power_attr(delay_fd, delay_str, wc);
> +	}
> +}
> +
>  /**
>   * igt_pm_enable_pci_card_runtime_pm:
>   * @root: root port pci_dev.
> diff --git a/lib/igt_pm.h b/lib/igt_pm.h
> index 306a9eb46..8394315c6 100644
> --- a/lib/igt_pm.h
> +++ b/lib/igt_pm.h
> @@ -77,6 +77,8 @@ 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);
> +int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev);
> +void igt_pm_set_autosuspend_delay(struct pci_device *pci_dev, int delay_ms);
>  void igt_pm_enable_pci_card_runtime_pm(struct pci_device *root,
>  				       struct pci_device *i915);
>  void igt_pm_get_d3cold_allowed(const char *pci_slot_name, uint32_t *value);
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set auto_suspenddelay_ms
  2023-12-28  0:40   ` Rodrigo Vivi
@ 2024-01-19 14:12     ` Gupta, Anshuman
  2024-01-19 14:47       ` Vivi, Rodrigo
  0 siblings, 1 reply; 10+ messages in thread
From: Gupta, Anshuman @ 2024-01-19 14:12 UTC (permalink / raw)
  To: Vivi, Rodrigo; +Cc: igt-dev@lists.freedesktop.org, Konieczny, Kamil



> -----Original Message-----
> From: Vivi, Rodrigo <rodrigo.vivi@intel.com>
> Sent: Thursday, December 28, 2023 6:11 AM
> To: Gupta, Anshuman <anshuman.gupta@intel.com>
> Cc: igt-dev@lists.freedesktop.org; Tauro, Riana <riana.tauro@intel.com>;
> Nilawar, Badal <badal.nilawar@intel.com>; Konieczny, Kamil
> <kamil.konieczny@intel.com>
> Subject: Re: [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set
> auto_suspenddelay_ms
> 
> On Thu, Dec 21, 2023 at 10:03:36PM +0530, Anshuman Gupta wrote:
> > Sometimes we want to test pm igt test with an explicit auto suspend
> > delay, therefore adding helpers to get/set the pci_dev
> > auto_suspenddelay_ms.
> >
> > Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
> 
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> 
> we also need to change the default value from 0 to 1 at least, and then see
> how much more time machine we use. But 0 is unrealistic.
Thanks Rodrigo for RB.
You mean 1ms or 1 second ?
Thanks,
Anshuman Gupta.
> 
> > ---
> >  lib/igt_pm.c | 53
> > ++++++++++++++++++++++++++++++++++++++++------------
> >  lib/igt_pm.h |  2 ++
> >  2 files changed, 43 insertions(+), 12 deletions(-)
> >
> > diff --git a/lib/igt_pm.c b/lib/igt_pm.c index c2d98fceb..d436c2c50
> > 100644
> > --- a/lib/igt_pm.c
> > +++ b/lib/igt_pm.c
> > @@ -1068,18 +1068,6 @@ static void igt_pm_write_power_attr(int fd,
> const char *val, int len)
> >  	igt_assert(strncmp(buf, val, len) == 0);  }
> >
> > -static int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev)
> > -{
> > -	char delay_str[64];
> > -	int delay, delay_fd;
> > -
> > -	delay_fd = igt_pm_get_power_attr_fd(pci_dev,
> "autosuspend_delay_ms");
> > -	if (igt_pm_read_power_attr(delay_fd, delay_str, 64, true))
> > -		igt_assert(sscanf(delay_str, "%d", &delay) > 0);
> > -
> > -	return delay;
> > -}
> > -
> >  static void
> >  igt_pm_setup_pci_dev_power_attrs(struct pci_device *pci_dev,
> >  				 struct igt_pm_pci_dev_pwrattr *pwrattr, int
> delay_ms) @@ -1165,6
> > +1153,47 @@ igt_pm_setup_pci_card_power_attrs(struct pci_device
> *pci_dev, bool save_attrs, i
> >  	pci_iterator_destroy(iter);
> >  }
> >
> > +/**
> > + * igt_pm_get_autosuspend_delay:
> > + * @pci_dev: pci_dev.
> > + * Get pci_dev autosuspend delay value from pci sysfs
> "autosuspend_delay_ms".
> > + *
> > + * Returns:
> > + * autosuspend_delay_ms.
> > + */
> > +int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev) {
> > +	char delay_str[64];
> > +	int delay, delay_fd;
> > +
> > +	delay_fd = igt_pm_get_power_attr_fd(pci_dev,
> "autosuspend_delay_ms");
> > +	if (igt_pm_read_power_attr(delay_fd, delay_str, 64, true))
> > +		igt_assert(sscanf(delay_str, "%d", &delay) > 0);
> > +
> > +	return delay;
> > +}
> > +
> > +/**
> > + * igt_pm_set_autosuspend_delay:
> > + * @pci_dev: pci_dev.
> > + * @delay_ms: autosuspend delay in ms.
> > + * Set pci_dev autosuspend delay value through pci sysfs
> "autosuspend_delay_ms".
> > + */
> > +void igt_pm_set_autosuspend_delay(struct pci_device *pci_dev, int
> > +delay_ms) {
> > +	char delay_str[64];
> > +	int delay_fd;
> > +
> > +	delay_fd = igt_pm_get_power_attr_fd(pci_dev,
> > +"autosuspend_delay_ms");
> > +
> > +	if (delay_ms >= 0) {
> > +		int wc;
> > +
> > +		wc = snprintf(delay_str, 64, "%d\n", delay_ms);
> > +		igt_pm_write_power_attr(delay_fd, delay_str, wc);
> > +	}
> > +}
> > +
> >  /**
> >   * igt_pm_enable_pci_card_runtime_pm:
> >   * @root: root port pci_dev.
> > diff --git a/lib/igt_pm.h b/lib/igt_pm.h index 306a9eb46..8394315c6
> > 100644
> > --- a/lib/igt_pm.h
> > +++ b/lib/igt_pm.h
> > @@ -77,6 +77,8 @@ 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);
> > +int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev); void
> > +igt_pm_set_autosuspend_delay(struct pci_device *pci_dev, int
> > +delay_ms);
> >  void igt_pm_enable_pci_card_runtime_pm(struct pci_device *root,
> >  				       struct pci_device *i915);
> >  void igt_pm_get_d3cold_allowed(const char *pci_slot_name, uint32_t
> > *value);
> > --
> > 2.25.1
> >

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set auto_suspenddelay_ms
  2024-01-19 14:12     ` Gupta, Anshuman
@ 2024-01-19 14:47       ` Vivi, Rodrigo
  0 siblings, 0 replies; 10+ messages in thread
From: Vivi, Rodrigo @ 2024-01-19 14:47 UTC (permalink / raw)
  To: Gupta, Anshuman; +Cc: igt-dev@lists.freedesktop.org, Konieczny, Kamil

On Fri, 2024-01-19 at 14:12 +0000, Gupta, Anshuman wrote:
> 
> 
> > -----Original Message-----
> > From: Vivi, Rodrigo <rodrigo.vivi@intel.com>
> > Sent: Thursday, December 28, 2023 6:11 AM
> > To: Gupta, Anshuman <anshuman.gupta@intel.com>
> > Cc: igt-dev@lists.freedesktop.org; Tauro, Riana
> > <riana.tauro@intel.com>;
> > Nilawar, Badal <badal.nilawar@intel.com>; Konieczny, Kamil
> > <kamil.konieczny@intel.com>
> > Subject: Re: [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set
> > auto_suspenddelay_ms
> > 
> > On Thu, Dec 21, 2023 at 10:03:36PM +0530, Anshuman Gupta wrote:
> > > Sometimes we want to test pm igt test with an explicit auto
> > > suspend
> > > delay, therefore adding helpers to get/set the pci_dev
> > > auto_suspenddelay_ms.
> > > 
> > > Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
> > 
> > Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> > 
> > we also need to change the default value from 0 to 1 at least, and
> > then see
> > how much more time machine we use. But 0 is unrealistic.
> Thanks Rodrigo for RB.
> You mean 1ms or 1 second ?

ops, yeap, I mentioned 1second. But we might attempt some smaller
ones like 500ms?! 200ms?

> Thanks,
> Anshuman Gupta.
> > 
> > > ---
> > >  lib/igt_pm.c | 53
> > > ++++++++++++++++++++++++++++++++++++++++------------
> > >  lib/igt_pm.h |  2 ++
> > >  2 files changed, 43 insertions(+), 12 deletions(-)
> > > 
> > > diff --git a/lib/igt_pm.c b/lib/igt_pm.c index
> > > c2d98fceb..d436c2c50
> > > 100644
> > > --- a/lib/igt_pm.c
> > > +++ b/lib/igt_pm.c
> > > @@ -1068,18 +1068,6 @@ static void igt_pm_write_power_attr(int
> > > fd,
> > const char *val, int len)
> > >         igt_assert(strncmp(buf, val, len) == 0);  }
> > > 
> > > -static int igt_pm_get_autosuspend_delay(struct pci_device
> > > *pci_dev)
> > > -{
> > > -       char delay_str[64];
> > > -       int delay, delay_fd;
> > > -
> > > -       delay_fd = igt_pm_get_power_attr_fd(pci_dev,
> > "autosuspend_delay_ms");
> > > -       if (igt_pm_read_power_attr(delay_fd, delay_str, 64,
> > > true))
> > > -               igt_assert(sscanf(delay_str, "%d", &delay) > 0);
> > > -
> > > -       return delay;
> > > -}
> > > -
> > >  static void
> > >  igt_pm_setup_pci_dev_power_attrs(struct pci_device *pci_dev,
> > >                                  struct igt_pm_pci_dev_pwrattr
> > > *pwrattr, int
> > delay_ms) @@ -1165,6
> > > +1153,47 @@ igt_pm_setup_pci_card_power_attrs(struct pci_device
> > *pci_dev, bool save_attrs, i
> > >         pci_iterator_destroy(iter);
> > >  }
> > > 
> > > +/**
> > > + * igt_pm_get_autosuspend_delay:
> > > + * @pci_dev: pci_dev.
> > > + * Get pci_dev autosuspend delay value from pci sysfs
> > "autosuspend_delay_ms".
> > > + *
> > > + * Returns:
> > > + * autosuspend_delay_ms.
> > > + */
> > > +int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev) {
> > > +       char delay_str[64];
> > > +       int delay, delay_fd;
> > > +
> > > +       delay_fd = igt_pm_get_power_attr_fd(pci_dev,
> > "autosuspend_delay_ms");
> > > +       if (igt_pm_read_power_attr(delay_fd, delay_str, 64,
> > > true))
> > > +               igt_assert(sscanf(delay_str, "%d", &delay) > 0);
> > > +
> > > +       return delay;
> > > +}
> > > +
> > > +/**
> > > + * igt_pm_set_autosuspend_delay:
> > > + * @pci_dev: pci_dev.
> > > + * @delay_ms: autosuspend delay in ms.
> > > + * Set pci_dev autosuspend delay value through pci sysfs
> > "autosuspend_delay_ms".
> > > + */
> > > +void igt_pm_set_autosuspend_delay(struct pci_device *pci_dev,
> > > int
> > > +delay_ms) {
> > > +       char delay_str[64];
> > > +       int delay_fd;
> > > +
> > > +       delay_fd = igt_pm_get_power_attr_fd(pci_dev,
> > > +"autosuspend_delay_ms");
> > > +
> > > +       if (delay_ms >= 0) {
> > > +               int wc;
> > > +
> > > +               wc = snprintf(delay_str, 64, "%d\n", delay_ms);
> > > +               igt_pm_write_power_attr(delay_fd, delay_str, wc);
> > > +       }
> > > +}
> > > +
> > >  /**
> > >   * igt_pm_enable_pci_card_runtime_pm:
> > >   * @root: root port pci_dev.
> > > diff --git a/lib/igt_pm.h b/lib/igt_pm.h index
> > > 306a9eb46..8394315c6
> > > 100644
> > > --- a/lib/igt_pm.h
> > > +++ b/lib/igt_pm.h
> > > @@ -77,6 +77,8 @@ 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);
> > > +int igt_pm_get_autosuspend_delay(struct pci_device *pci_dev);
> > > void
> > > +igt_pm_set_autosuspend_delay(struct pci_device *pci_dev, int
> > > +delay_ms);
> > >  void igt_pm_enable_pci_card_runtime_pm(struct pci_device *root,
> > >                                        struct pci_device *i915);
> > >  void igt_pm_get_d3cold_allowed(const char *pci_slot_name,
> > > uint32_t
> > > *value);
> > > --
> > > 2.25.1
> > > 


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-01-19 14:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-21 16:33 [PATCH i-g-t v4 0/4] Add d3 mmap test Anshuman Gupta
2023-12-21 16:33 ` [PATCH i-g-t v4 1/4] test/xe_pm: Add exit handler to close fw handle Anshuman Gupta
2023-12-21 16:33 ` [PATCH i-g-t v4 2/4] lib/igt_pm: Add helper to get/set auto_suspenddelay_ms Anshuman Gupta
2023-12-28  0:40   ` Rodrigo Vivi
2024-01-19 14:12     ` Gupta, Anshuman
2024-01-19 14:47       ` Vivi, Rodrigo
2023-12-21 16:33 ` [PATCH i-g-t v4 3/4] tests/xe_pm: Add d3-mmap IGT test Anshuman Gupta
2023-12-22  7:48   ` Nilawar, Badal
2023-12-22  7:48     ` Nilawar, Badal
2023-12-21 16:33 ` [PATCH i-g-t v4 4/4] HAX: Add d3-mmap to xe-fast-feedback Anshuman Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox