Skip to contentSkip to conversation

lib/igt_debugfs: Add functions/tests for controlling/testing HPD storm logic

PATCH In review Lyude 2 participants 5 messages Feb 23, 2017 Library code

lore
Share & tools
lore

Lyude

author
#0 lore raw

PATCH 1/2 lib/igt_debugfs: Add functions/tests for controlling/testing HPD storm logic

Recently we added i915_hpd_storm_ctl into i915's debugfs directory, which allows us to control the thresholds i915 uses for detecting hotplug interrupt storms from userspace, along with the ability to entirely disable them. This adds some helper functions into IGT to enable making use of this feature, along with adding some chamelium tests for it.

---
 lib/igt_debugfs.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_debugfs.h |   5 +++
 tests/chamelium.c |  61 ++++++++++++++++++++++++++++++
 3 files changed, 177 insertions(+)
lib/igt_debugfs.c +111 -0
index 982573d..e64d001 100644
@@ -463,6 +463,117 @@ void igt_require_pipe_crc(void)
 	fclose(ctl);
 }
 
+/**
+ * igt_hpd_storm_set_threshold:
+ * @threshold: How many hotplugs per second required to trigger an HPD storm,
+ * or 0 to disable storm detection.
+ *
+ * Convienence helper to configure the HPD storm detection threshold for i915
+ * through debugfs. Useful for hotplugging tests where HPD storm detection
+ * might get in the way and slow things down.
+ *
+ * If the system does not support HPD storm detection, this function does
+ * nothing.
+ *
+ * See: https://01.org/linuxgraphics/gfx-docs/drm/gpu/i915.html#hotplug
+ */
+void igt_hpd_storm_set_threshold(unsigned int threshold)
+{
+	int fd = igt_debugfs_open("i915_hpd_storm_ctl", O_WRONLY);
+	char buf[16];
+
+	if (fd < 0)
+		return;
+
+	igt_debug("Setting HPD storm threshold to %d\n", threshold);
+	snprintf(buf, sizeof(buf), "%d", threshold);
+	igt_assert_eq(write(fd, buf, strlen(buf)), strlen(buf));
+
+	close(fd);
+	igt_install_exit_handler((igt_exit_handler_t)igt_hpd_storm_reset);
+}
+
+/**
+ * igt_hpd_storm_reset:
+ *
+ * Convienence helper to reset HPD storm detection to it's default settings.
+ * If hotplug detection was disabled on any ports due to an HPD storm, it will
+ * be immediately re-enabled. Always called on exit if the HPD storm detection
+ * threshold was modified during any tests.
+ *
+ * If the system does not support HPD storm detection, this function does
+ * nothing.
+ *
+ * See: https://01.org/linuxgraphics/gfx-docs/drm/gpu/i915.html#hotplug
+ */
+void igt_hpd_storm_reset(void)
+{
+	int fd = igt_debugfs_open("i915_hpd_storm_ctl", O_WRONLY);
+	const char *buf = "reset";
+
+	if (fd < 0)
+		return;
+
+	igt_debug("Resetting HPD storm threshold\n");
+	igt_assert_eq(write(fd, buf, strlen(buf)), strlen(buf));
+
+	close(fd);
+}
+
+/**
+ * igt_hpd_storm_detected:
+ *
+ * Checks whether or not i915 has detected an HPD interrupt storm on any of the
+ * system's ports.
+ *
+ * This function always returns false on systems that do not support HPD storm
+ * detection.
+ *
+ * See: https://01.org/linuxgraphics/gfx-docs/drm/gpu/i915.html#hotplug
+ *
+ * Returns: Whether or not an HPD storm has been detected.
+ */
+bool igt_hpd_storm_detected(void)
+{
+	int fd = igt_debugfs_open("i915_hpd_storm_ctl", O_RDONLY);
+	char *start_loc;
+	char buf[32] = {0}, detected_str[4];
+	bool ret;
+
+	if (fd < 0)
+		return false;
+
+	igt_assert_lt(0, read(fd, buf, sizeof(buf)));
+	igt_assert(start_loc = strstr(buf, "Detected: "));
+	igt_assert_eq(sscanf(start_loc, "Detected: %s\n", detected_str), 1);
+
+	if (strcmp(detected_str, "yes") == 0)
+		ret = true;
+	else if (strcmp(detected_str, "no") == 0)
+		ret = false;
+	else
+		igt_fail_on_f(true, "Unknown hpd storm detection status '%s'\n",
+			      detected_str);
+
+	close(fd);
+	return ret;
+}
+
+/**
+ * igt_require_hpd_storm_ctl:
+ *
+ * Skips the current test if the system does not have HPD storm detection.
+ *
+ * See: https://01.org/linuxgraphics/gfx-docs/drm/gpu/i915.html#hotplug
+ */
+void igt_require_hpd_storm_ctl(void)
+{
+	int fd = igt_debugfs_open("i915_hpd_storm_ctl", O_RDONLY);
+
+	igt_require_f(fd > 0, "No i915_hpd_storm_ctl found in debugfs\n");
+	close(fd);
+}
+
 static igt_pipe_crc_t *
 pipe_crc_new(enum pipe pipe, enum intel_pipe_crc_source source, int flags)
 {
lib/igt_debugfs.h +5 -0
index 86c25dd..5587ad4 100644
@@ -129,6 +129,11 @@ int igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs,
 			  igt_crc_t **out_crcs);
 void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc);
 
+void igt_hpd_storm_set_threshold(unsigned int threshold);
+void igt_hpd_storm_reset(void);
+bool igt_hpd_storm_detected(void);
+void igt_require_hpd_storm_ctl(void);
+
 /*
  * Drop caches
  */
tests/chamelium.c +61 -0

85 lines not on this page · raw message

Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#1 lore raw

PATCH 2/2 tests/chamelium: Don't sleep so much in basic hpd tests

Now that we can just disable HPD storm detection, there's no need to sleep between each hotplug cycle.

---
 tests/chamelium.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tests/chamelium.c +2 -3
index 849e1ac..810c955 100644
@@ -154,6 +154,7 @@ test_basic_hotplug(data_t *data, struct chamelium_port *port)
 	int i;
 
 	reset_state(data, port);
+	igt_hpd_storm_set_threshold(0);
 
 	for (i = 0; i < 15; i++) {
 		igt_flush_hotplugs(mon);
@@ -171,12 +172,10 @@ test_basic_hotplug(data_t *data, struct chamelium_port *port)
 		igt_assert(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT));
 		igt_assert_eq(reprobe_connector(data, port),
 			      DRM_MODE_DISCONNECTED);
-
-		/* Sleep so we don't accidentally cause an hpd storm */
-		usleep(500 * 1000);
 	}
 
 	igt_cleanup_hotplug(mon);
+	igt_hpd_storm_reset();
 }
 
 static void
Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [PATCH i-g-t 2/2] tests/chamelium: Don't sleep so much in basic hpd tests

Quoted 13 lines · Lyude

Now that we can just disable HPD storm detection, there's no need to sleep between each hotplug cycle.

---
 tests/chamelium.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tests/chamelium.c +0 -0
index 849e1ac..810c955 100644

tests/chamelium.c test_basic_hotplug(data_t *data, struct chamelium_port *port) · line 157

Quoted 4 lines
tests/chamelium.c +1 -0
@@ -154,6 +154,7 @@ test_basic_hotplug(data_t *data, struct chamelium_port *port)
 	int i;
 
 	reset_state(data, port);
+	igt_hpd_storm_set_threshold(0);

You will want to check that you have the debugfs interface first and skip the test otherwise. Or was there a fallback? Or is it already checkd?
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#3 lore raw

Re: [PATCH i-g-t 2/2] tests/chamelium: Don't sleep so much in basic hpd tests

Quoted 25 lines · Chris Wilson
Quoted 18 lines · Lyude

Now that we can just disable HPD storm detection, there's no need to
sleep between each hotplug cycle.

---
 tests/chamelium.c | 5 ++---

 1 file changed, 2 insertions(+), 3 deletions(-)
tests/chamelium.c +0 -0
index 849e1ac..810c955 100644
@@ -154,6 +154,7 @@ test_basic_hotplug(data_t *data, struct
 chamelium_port *port)
  	int i;


  reset_state(data, port);

tests/chamelium.c test_basic_hotplug(data_t *data, struct chamelium_port *port) · line 157

Quoted 1 line
tests/chamelium.c +1 -0
+	igt_hpd_storm_set_threshold(0);

You will want to check that you have the debugfs interface first and skip the test otherwise. Or was there a fallback? Or is it already checkd?

Quoted 1 line

-Chris

If the debugfs interface isn't there, the function just doesn't do anything and returns immediately

Quoted 1 line
Signature · 6 lines
Cheers,
	Lyude
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Re: [PATCH i-g-t 2/2] tests/chamelium: Don't sleep so much in basic hpd tests

Quoted 26 lines · Lyude Paul
Quoted 25 lines · Chris Wilson
Quoted 18 lines · Lyude

Now that we can just disable HPD storm detection, there's no need to
sleep between each hotplug cycle.

---
 tests/chamelium.c | 5 ++---

 1 file changed, 2 insertions(+), 3 deletions(-)
tests/chamelium.c +0 -0
index 849e1ac..810c955 100644
@@ -154,6 +154,7 @@ test_basic_hotplug(data_t *data, struct
 chamelium_port *port)
  	int i;


  reset_state(data, port);

tests/chamelium.c test_basic_hotplug(data_t *data, struct chamelium_port *port) · line 157

Quoted 1 line
tests/chamelium.c +1 -0
+	igt_hpd_storm_set_threshold(0);

You will want to check that you have the debugfs interface first and skip the test otherwise. Or was there a fallback? Or is it already checkd?

Quoted 3 lines
Quoted 1 line

-Chris

If the debugfs interface isn't there, the function just doesn't do anything and returns immediately

Ok, it just sounded like you depended upon the new feature and dropped the old method.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx