Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Pranay Samala <pranay.samala@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: kunal1.joshi@intel.com, sameer.lattannavar@intel.com,
	pranay.samala@intel.com
Subject: [PATCH i-g-t v3 6/7] lib/igt_kms: Add drm_kms_helper.poll save/restore helpers
Date: Tue, 20 Oct 2026 19:41:50 +0530	[thread overview]
Message-ID: <20261020141151.753331-7-pranay.samala@intel.com> (raw)
In-Reply-To: <20261020141151.753331-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 that,
each with its own defines and saved state. Rather than add a third copy,
add igt_kms_poll_save(), _set() and _restore(). Converting those two
callers is left to a separate patch.

Save and set stay separate, because a caller may want to restore the
original value on exit while leaving polling switched on. Save installs
the exit handler itself, and restore does nothing without a save.

Writing the parameter does not by itself start or stop polling: the poll
worker stops at its next run after it is disabled, and is only restarted
by drm_kms_helper_poll_enable(), on driver load or system resume. The
kerneldoc says so, so callers that need polling running check for it.

v3:
- Move to igt_kms and rename from igt_pm_kms_poll_*() (Kunal)
- Document that setting the parameter does not restart a stopped poll
  worker (Kunal)

Signed-off-by: Pranay Samala <pranay.samala@intel.com>
---
 lib/igt_kms.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |   3 ++
 2 files changed, 104 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index af0f7c4e5..e1adf1b6f 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -6173,6 +6173,107 @@ void igt_cleanup_uevents(struct udev_monitor *mon)
 	udev_unref(udev);
 }
 
+#define IGT_KMS_HELPER_PARAMS "/sys/module/drm_kms_helper/parameters"
+
+static struct {
+	bool saved;
+	bool orig_poll;
+} __igt_kms_poll;
+
+static void __igt_kms_poll_exit_handler(int sig)
+{
+	igt_kms_poll_restore();
+}
+
+/**
+ * igt_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_kms_poll_save(void)
+{
+	int dir;
+
+	if (__igt_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_kms_poll.orig_poll)) {
+		close(dir);
+		return false;
+	}
+	close(dir);
+
+	__igt_kms_poll.saved = true;
+	igt_install_exit_handler(__igt_kms_poll_exit_handler);
+
+	igt_debug("Saved drm_kms_helper.poll = %s\n",
+		  __igt_kms_poll.orig_poll ? "Y" : "N");
+
+	return true;
+}
+
+/**
+ * igt_kms_poll_set:
+ * @enable: whether to allow connector polling
+ *
+ * Writes the drm_kms_helper.poll module parameter. Callers are expected to have
+ * called igt_kms_poll_save() first so the original value is restored on exit.
+ *
+ * This only changes the parameter, it does not itself start or stop the poll
+ * worker. Disabling takes effect the next time the worker runs, at most one
+ * poll period later, and the worker then stops. Enabling does not restart a
+ * worker that has stopped: the kernel only does that from
+ * drm_kms_helper_poll_enable(), i.e. on driver load and, for most drivers,
+ * system resume. Callers that rely on polling actually running after enabling
+ * it must check for it.
+ */
+void igt_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_kms_poll_restore:
+ *
+ * Restores drm_kms_helper.poll to the value saved by igt_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.
+ *
+ * As with igt_kms_poll_set(), restoring the parameter to enabled does not
+ * restart a poll worker that stopped while it was disabled.
+ */
+void igt_kms_poll_restore(void)
+{
+	int dir;
+
+	if (!__igt_kms_poll.saved)
+		return;
+
+	dir = open(IGT_KMS_HELPER_PARAMS, O_RDONLY);
+	if (dir >= 0) {
+		__igt_sysfs_set_boolean(dir, "poll", __igt_kms_poll.orig_poll);
+		close(dir);
+	}
+
+	__igt_kms_poll.saved = false;
+}
+
 /**
  * kmstest_get_vbl_flag:
  * @crtc_index: CRTC index to convert into DRM_IOCTL_WAIT_VBLANK parameter
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 9b8779a62..c6081a16a 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -1239,6 +1239,9 @@ bool igt_connector_event_detected(struct udev_monitor *mon, uint32_t conn_id,
 				  uint32_t prop_id, int timeout_msecs);
 void igt_flush_uevents(struct udev_monitor *mon);
 void igt_cleanup_uevents(struct udev_monitor *mon);
+bool igt_kms_poll_save(void);
+void igt_kms_poll_set(bool enable);
+void igt_kms_poll_restore(void);
 
 bool igt_format_mods_has_format_and_modifier(const struct igt_format_mods *format_mods,
 					     uint32_t format, uint64_t modifier);
-- 
2.53.0


  parent reply	other threads:[~2026-10-20 14:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 14:11 [PATCH i-g-t v3 0/7] Validate PM_PME signalling on display hotplug Pranay Samala
2026-10-20 14:11 ` [PATCH i-g-t v3 1/7] lib/igt_pci: Add PCI Power Management capability register layout Pranay Samala
2026-10-20 14:11 ` [PATCH i-g-t v3 2/7] lib/igt_pm: Add PCI PME capability and D state accessors Pranay Samala
2026-10-20 14:11 ` [PATCH i-g-t v3 3/7] lib/igt_pm: Factor out power attribute path construction Pranay Samala
2026-10-20 14:11 ` [PATCH i-g-t v3 4/7] lib/igt_pm: Add power/wakeup accessors Pranay Samala
2026-10-20 14:11 ` [PATCH i-g-t v3 5/7] lib/igt_pm: Add power/wakeup_active_count accessor Pranay Samala
2026-10-20 14:11 ` Pranay Samala [this message]
2026-10-20 14:11 ` [PATCH i-g-t v3 7/7] tests/chamelium/kms_chamelium_hpd: Add HPD from runtime suspended D3hot Pranay Samala
2026-10-20 15:40 ` ✓ Xe.CI.BAT: success for Validate PM_PME signalling on display hotplug (rev4) Patchwork
2026-10-20 15:59 ` ✓ i915.CI.BAT: " 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=20261020141151.753331-7-pranay.samala@intel.com \
    --to=pranay.samala@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kunal1.joshi@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