All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anshuman Gupta <anshuman.gupta@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: petri.latvala@intel.com, badal.nilawar@intel.com, rodrigo.vivi@intel.com
Subject: [igt-dev] [PATCH i-g-t v6 04/10] lib: Optional autosuspend_delay_ms configuration
Date: Mon, 16 May 2022 20:42:49 +0530	[thread overview]
Message-ID: <20220516151255.13153-5-anshuman.gupta@intel.com> (raw)
In-Reply-To: <20220516151255.13153-1-anshuman.gupta@intel.com>

Add an option to configure autosuspend_delay_ms as i915 read
autosuspend_delay_ms to all PCI devices under GFX root port.

configuring autosuspend_delay_ms as optional.

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

diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 4768deefc8..6ebbad330c 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -988,11 +988,25 @@ 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)
+igt_pm_setup_pci_dev_power_attrs(struct pci_device *pci_dev,
+				 struct igt_pm_pci_dev_pwrattr *pwrattr, int delay_ms)
 {
 	int control_fd, delay_fd, control_size, delay_size;
 	char *control, *delay;
+	char buff[64];
 
 	delay_fd = igt_pm_get_power_attr_fd(pci_dev, "autosuspend_delay_ms");
 	control_fd = igt_pm_get_power_attr_fd(pci_dev, "control");
@@ -1022,7 +1036,12 @@ igt_pm_setup_pci_dev_power_attrs(struct pci_device *pci_dev, struct igt_pm_pci_d
 
 write_power_attr:
 
-	igt_pm_write_power_attr(delay_fd, "0\n", 2);
+	if (delay_ms >= 0) {
+		int wc;
+		wc = snprintf(buff, 64, "%d\n", delay_ms);
+		igt_pm_write_power_attr(delay_fd, buff, wc);
+	}
+
 	igt_pm_write_power_attr(control_fd, "auto\n", 5);
 
 	close(delay_fd);
@@ -1030,7 +1049,7 @@ write_power_attr:
 }
 
 static void
-igt_pm_setup_pci_card_power_attrs(struct pci_device *pci_dev, bool save_attrs)
+igt_pm_setup_pci_card_power_attrs(struct pci_device *pci_dev, bool save_attrs, int delay)
 {
 	int primary, secondary, subordinate, ret;
 	struct pci_device_iterator *iter;
@@ -1052,11 +1071,15 @@ igt_pm_setup_pci_card_power_attrs(struct pci_device *pci_dev, bool save_attrs)
 	igt_assert(iter);
 
 	/* Setup power attrs for PCI root port */
-	igt_pm_setup_pci_dev_power_attrs(pci_dev, save_attrs ? &__pci_dev_pwrattr[i++] : NULL);
+	igt_pm_setup_pci_dev_power_attrs(pci_dev,
+					 save_attrs ? &__pci_dev_pwrattr[i++] : NULL,
+					 delay);
+
 	while ((dev = pci_device_next(iter)) != NULL) {
 		if (dev->bus >= secondary && dev->bus <= subordinate) {
 			igt_pm_setup_pci_dev_power_attrs(dev,
-							 save_attrs ? &__pci_dev_pwrattr[i++] : NULL);
+							 save_attrs ? &__pci_dev_pwrattr[i++] : NULL,
+							 delay);
 			if (save_attrs)
 				igt_assert(i <  MAX_PCI_DEVICES);
 		}
@@ -1067,14 +1090,21 @@ igt_pm_setup_pci_card_power_attrs(struct pci_device *pci_dev, bool save_attrs)
 
 /**
  * igt_pm_enable_pci_card_runtime_pm:
- * @pci_dev: root port pci_dev.
+ * @root: root port pci_dev.
+ * @i915: i915 pci_dev.
  * Enable runtime PM for all PCI endpoints devices for a given root port by
  * setting power/control attr to "auto" and setting autosuspend_delay_ms
  * to zero.
  */
-void igt_pm_enable_pci_card_runtime_pm(struct pci_device *pci_dev)
+void igt_pm_enable_pci_card_runtime_pm(struct pci_device *root,
+				       struct pci_device *i915)
 {
-	igt_pm_setup_pci_card_power_attrs(pci_dev, false);
+	int delay = -1;
+
+	if (i915)
+		delay = igt_pm_get_autosuspend_delay(i915);
+
+	igt_pm_setup_pci_card_power_attrs(root, false, delay);
 	pci_system_cleanup();
 }
 
@@ -1089,7 +1119,7 @@ void igt_pm_enable_pci_card_runtime_pm(struct pci_device *pci_dev)
 void igt_pm_setup_pci_card_runtime_pm(struct pci_device *pci_dev)
 {
 	memset(__pci_dev_pwrattr, 0, sizeof(__pci_dev_pwrattr));
-	igt_pm_setup_pci_card_power_attrs(pci_dev, true);
+	igt_pm_setup_pci_card_power_attrs(pci_dev, true, 0);
 }
 
 static void
diff --git a/lib/igt_pm.h b/lib/igt_pm.h
index c53dae2c31..f28b6ebfde 100644
--- a/lib/igt_pm.h
+++ b/lib/igt_pm.h
@@ -74,7 +74,8 @@ bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output);
 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);
-void igt_pm_enable_pci_card_runtime_pm(struct pci_device *pci_dev);
+void igt_pm_enable_pci_card_runtime_pm(struct pci_device *root,
+				       struct pci_device *i915);
 void igt_pm_setup_pci_card_runtime_pm(struct pci_device *pci_dev);
 void igt_pm_restore_pci_card_runtime_pm(void);
 void igt_pm_print_pci_card_runtime_status(void);
-- 
2.26.2

  parent reply	other threads:[~2022-05-16 15:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 15:12 [igt-dev] [PATCH i-g-t v6 00/10] D3Cold Tool & IGT Anshuman Gupta
2022-05-16 15:12 ` [igt-dev] [PATCH i-g-t v6 01/10] test/i915_pm_rpm: Add placement to gem-{mmap-type, execbuf} Anshuman Gupta
2022-05-16 15:12 ` [igt-dev] [PATCH i-g-t v6 02/10] lib/igt_device: Get gfx PCI card root port Anshuman Gupta
2022-05-16 15:12 ` [igt-dev] [PATCH i-g-t v6 03/10] lib/igt_pm: D3Cold runtime pm infrastructure Anshuman Gupta
2022-05-16 15:12 ` Anshuman Gupta [this message]
2022-05-17 11:38   ` [igt-dev] [PATCH i-g-t v6 04/10] lib: Optional autosuspend_delay_ms configuration Nilawar, Badal
2022-05-16 15:12 ` [igt-dev] [PATCH i-g-t v6 05/10] tools: Add intel_pm_rpm tool Anshuman Gupta
2022-05-16 15:12 ` [igt-dev] [PATCH i-g-t v6 06/10] tools/intel_pm_rpm: Add an option to setup d3cold Anshuman Gupta
2022-05-16 15:12 ` [igt-dev] [PATCH i-g-t v6 07/10] i915_pm_rpm: Add D3Cold basic subtest Anshuman Gupta
2022-05-16 15:12 ` [igt-dev] [PATCH i-g-t v6 08/10] i915_pm_rpm: Extend gem_exec_stress test with D3Cold Anshuman Gupta
2022-05-16 15:12 ` [igt-dev] [PATCH i-g-t v6 09/10] i915_pm_rpm: Extend gem_execbuf " Anshuman Gupta
2022-05-16 15:12 ` [igt-dev] [PATCH i-g-t v6 10/10] i915_pm_rpm: Extend gem-mmap-type " Anshuman Gupta
2022-05-16 18:07 ` [igt-dev] ✓ Fi.CI.BAT: success for D3Cold Tool & IGT (rev6) Patchwork
2022-05-16 21:59 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

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=20220516151255.13153-5-anshuman.gupta@intel.com \
    --to=anshuman.gupta@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=petri.latvala@intel.com \
    --cc=rodrigo.vivi@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.