From: Pranay Samala <pranay.samala@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: karthik.b.s@intel.com, sameer.lattannavar@intel.com,
pranay.samala@intel.com
Subject: [PATCH i-g-t 6/7] lib/igt_pm: Add drm_kms_helper.poll save/restore helpers
Date: Mon, 7 Sep 2026 19:52:58 +0530 [thread overview]
Message-ID: <20260907142259.750528-7-pranay.samala@intel.com> (raw)
In-Reply-To: <20260907142259.750528-1-pranay.samala@intel.com>
The new PME hotplug subtest needs to save the drm_kms_helper.poll module
parameter and put it back on exit, so that an earlier test cannot leave
polling disabled and make the measurement pass for the wrong reason.
tests/intel/kms_pm_dc.c and tests/kms_prime.c already open code exactly
that, each with its own copy of the KMS_HELPER and KMS_POLL_DISABLE
defines and its own file scope kms_poll_saved_state global. Rather than
add a third copy, add igt_pm_kms_poll_save(), _set() and _restore().
Converting those two existing callers is left to a separate patch.
Save and set stay separate rather than becoming one "save and disable"
helper, because a caller may want to record the original value and put it
back on exit while leaving polling switched on.
igt_pm_kms_poll_save() installs the exit handler itself, and
igt_pm_kms_poll_restore() does nothing unless a save actually happened, so
a restore can never run without a matching save.
Assisted-by: GitHub_Copilot:claude-opus-5
Signed-off-by: Pranay Samala <pranay.samala@intel.com>
---
lib/igt_pm.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_pm.h | 3 ++
2 files changed, 93 insertions(+)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index a9fd9610a..f6a99d233 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -1679,6 +1679,96 @@ uint64_t igt_pm_get_wakeup_active_count(struct pci_device *pci_dev)
return igt_pm_read_power_attr_u64(pci_dev, "wakeup_active_count");
}
+#define IGT_KMS_HELPER_PARAMS "/sys/module/drm_kms_helper/parameters"
+
+static struct {
+ bool saved;
+ bool orig_poll;
+} __igt_pm_kms_poll;
+
+static void __igt_pm_kms_poll_exit_handler(int sig)
+{
+ igt_pm_kms_poll_restore();
+}
+
+/**
+ * igt_pm_kms_poll_save:
+ *
+ * Saves the current drm_kms_helper.poll value and installs an exit handler to
+ * restore it. Safe to call more than once, only the first value is kept.
+ *
+ * Returns: false if the module parameter is not available, in which case
+ * nothing was saved.
+ */
+bool igt_pm_kms_poll_save(void)
+{
+ int dir;
+
+ if (__igt_pm_kms_poll.saved)
+ return true;
+
+ dir = open(IGT_KMS_HELPER_PARAMS, O_RDONLY);
+ if (dir < 0)
+ return false;
+
+ if (!__igt_sysfs_get_boolean(dir, "poll", &__igt_pm_kms_poll.orig_poll)) {
+ close(dir);
+ return false;
+ }
+ close(dir);
+
+ __igt_pm_kms_poll.saved = true;
+ igt_install_exit_handler(__igt_pm_kms_poll_exit_handler);
+
+ igt_debug("Saved drm_kms_helper.poll = %s\n",
+ __igt_pm_kms_poll.orig_poll ? "Y" : "N");
+
+ return true;
+}
+
+/**
+ * igt_pm_kms_poll_set:
+ * @enable: whether to enable connector polling
+ *
+ * Writes the drm_kms_helper.poll module parameter. Callers are expected to have
+ * called igt_pm_kms_poll_save() first so the original value is restored on exit.
+ */
+void igt_pm_kms_poll_set(bool enable)
+{
+ int dir;
+
+ dir = open(IGT_KMS_HELPER_PARAMS, O_RDONLY);
+ igt_assert_f(dir >= 0, "Can't open %s\n", IGT_KMS_HELPER_PARAMS);
+
+ igt_sysfs_set_boolean(dir, "poll", enable);
+ close(dir);
+
+ igt_debug("drm_kms_helper.poll = %s\n", enable ? "Y" : "N");
+}
+
+/**
+ * igt_pm_kms_poll_restore:
+ *
+ * Restores drm_kms_helper.poll to the value saved by
+ * igt_pm_kms_poll_save(). Does nothing if it was never saved, so it is safe to
+ * use as an exit handler that may run before any save happened.
+ */
+void igt_pm_kms_poll_restore(void)
+{
+ int dir;
+
+ if (!__igt_pm_kms_poll.saved)
+ return;
+
+ dir = open(IGT_KMS_HELPER_PARAMS, O_RDONLY);
+ if (dir >= 0) {
+ __igt_sysfs_set_boolean(dir, "poll", __igt_pm_kms_poll.orig_poll);
+ close(dir);
+ }
+
+ __igt_pm_kms_poll.saved = false;
+}
+
/**
* igt_pm_ignore_slpc_efficient_freq:
* @i915: open i915 drm file descriptor
diff --git a/lib/igt_pm.h b/lib/igt_pm.h
index eba54efa2..307fd9e34 100644
--- a/lib/igt_pm.h
+++ b/lib/igt_pm.h
@@ -107,6 +107,9 @@ bool igt_pm_has_wakeup_support(struct pci_device *pci_dev);
void igt_pm_set_wakeup_enabled(struct pci_device *pci_dev, bool enable);
void igt_pm_restore_wakeup(void);
uint64_t igt_pm_get_wakeup_active_count(struct pci_device *pci_dev);
+bool igt_pm_kms_poll_save(void);
+void igt_pm_kms_poll_set(bool enable);
+void igt_pm_kms_poll_restore(void);
void igt_pm_ignore_slpc_efficient_freq(int i915, int gtfd, bool val);
bool igt_has_pci_pm_capability(struct pci_device *pci_dev);
bool igt_pm_pci_pme_supported(struct pci_device *pci_dev,
--
2.53.0
next prev parent reply other threads:[~2026-09-07 14:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 14:22 [PATCH i-g-t 0/7] Validate PM_PME signalling on display hotplug Pranay Samala
2026-09-07 14:22 ` [PATCH i-g-t 1/7] lib/igt_pci: Add PCI Power Management capability register layout Pranay Samala
2026-09-07 14:22 ` [PATCH i-g-t 2/7] lib/igt_pm: Add PCI PME capability and D state accessors Pranay Samala
2026-09-07 14:22 ` [PATCH i-g-t 3/7] lib/igt_pm: Factor out power attribute path construction Pranay Samala
2026-09-07 14:22 ` [PATCH i-g-t 4/7] lib/igt_pm: Add power/wakeup accessors Pranay Samala
2026-09-07 14:22 ` [PATCH i-g-t 5/7] lib/igt_pm: Add power/wakeup_active_count accessor Pranay Samala
2026-09-07 14:22 ` Pranay Samala [this message]
2026-09-07 14:22 ` [PATCH i-g-t 7/7] tests/chamelium/kms_chamelium_hpd: Add HPD from runtime suspended D3hot Pranay Samala
2026-09-16 15:40 ` Govindapillai, Vinod
2026-09-07 19:49 ` ✓ Xe.CI.BAT: success for Validate PM_PME signalling on display hotplug (rev2) Patchwork
2026-09-07 20:02 ` ✓ i915.CI.BAT: " Patchwork
2026-09-08 0:17 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-09-08 6:28 ` ✗ i915.CI.Full: " 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=20260907142259.750528-7-pranay.samala@intel.com \
--to=pranay.samala@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=karthik.b.s@intel.com \
--cc=sameer.lattannavar@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