Skip to contentSkip to conversation

EDITME: Update pipe joiner test to get free crtc

PATCH New Arun R Murthy 1 participant 3 messages Oct 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover EDITME: Update pipe joiner test to get free crtc

Call a new API(drmModeGetCrtcList) exported by libdrm to get the list of active crtc and then call modeset with the first freely available crtc.

The libdrm patch is still not merged and is floated for review @
https://gitlab.freedesktop.org/mesa/libdrm/-/merge_requests/490/

To: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Changes in v2:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Arun R Murthy (2):
lib/igt_kms: Add igt_get_free_pipes_mask() tests/intel/kms_joiner: Use the CRTCs reported free before a modeset

 lib/igt_kms.c            | 69 ++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h            |  1 +
 meson.build              |  7 +++++
 tests/intel/kms_joiner.c | 75 ++++++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 147 insertions(+), 5 deletions(-)

---
base-commit: 5e43e9df3a1581074f0de2bbeddd939ebd950b93
change-id: 20261007-joiner-a3b4f2d64d2a

Best regards,

Signature · 1 line
Arun R Murthy <[email protected]>
#1 lore raw

PATCH v2 1/2 lib/igt_kms: Add igt_get_free_pipes_mask()

The joiner tests derive the set of usable pipes from the pipe count alone, which assumes every pipe is free. A pipe already driven by another client is then handed to a modeset, making the commit fail.

Add igt_get_free_pipes_mask(), which gets the current CRTC usage via drmModeGetCrtcList() and translates it into a bitmask of hardware pipes.

drmModeGetCrtcList() is a recent libdrm addition, so probe for it in meson and fall back to plain CRTC enumeration when it is missing.

v2: Move the function out of Intel folder as this is not Intel specific (Jani N)

Assisted-by LLM
---
 lib/igt_kms.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  1 +
 meson.build   |  7 ++++++
 3 files changed, 77 insertions(+)
lib/igt_kms.c +69 -0
index af0f7c4e5f6fd4905b1a856f8b443492026d6b26..a0a6a6335f7548e6883f479ff67816d2793587f3 100644
@@ -7581,6 +7581,75 @@ bool igt_check_bigjoiner_support(igt_display_t *display)
 	return true;
 }
 
+/**
+ * igt_get_free_pipes_mask:
+ * @display: The display structure containing pipe information.
+ *
+ * Get the CRTCs that are currently usable and translate that into a
+ * bitmask of hardware pipes. A CRTC is reported free only when it is neither
+ * enabled through KMS nor active in hardware, so pipes claimed by another
+ * client (fbcon, a compositor, joiner) are never handed out to a modeset.
+ *
+ * The returned mask reflects the state at call time, so query it right before
+ * a modeset and after releasing the pipes a previous commit was using.
+ *
+ * Returns: bitmask of hardware pipes whose CRTC is free to be assigned. When
+ * libdrm lacks drmModeGetCrtcList() every pipe of @display is reported free.
+ */
+#ifdef HAVE_DRMMODEGETCRTCLIST
+uint32_t igt_get_free_pipes_mask(igt_display_t *display)
+{
+	uint32_t free_mask = 0;
+	drmModeCrtcListPtr list;
+	int i;
+
+	list = drmModeGetCrtcList(display->drm_fd);
+	igt_assert_f(list, "drmModeGetCrtcList() failed\n");
+
+	for (i = 0; i < list->count; i++) {
+		drmModeCrtcInfoPtr info = &list->crtcs[i];
+		igt_crtc_t *crtc = igt_crtc_for_crtc_id(display, info->crtc_id);
+
+		/* A CRTC the display never enumerated is not ours to use. */
+		if (!crtc)
+			continue;
+
+		if (info->in_use) {
+			igt_debug("CRTC %s in use: %ux%u, fb %u\n",
+				  igt_crtc_name(crtc), info->width,
+				  info->height, info->buffer_id);
+			continue;
+		}
+
+		if (info->driver_active) {
+			igt_debug("CRTC %s active in hardware, not enabled via KMS\n",
+				  igt_crtc_name(crtc));
+			continue;
+		}
+
+		free_mask |= BIT(crtc->hardware_pipe);
+	}
+
+	igt_info("%d of %d CRTCs free, free pipe mask 0x%x\n",
+		 list->count_available, list->count, free_mask);
+
+	drmModeFreeCrtcList(list);
+
+	return free_mask;
+}
+#else
+uint32_t igt_get_free_pipes_mask(igt_display_t *display)
+{
+	uint32_t free_mask = 0;
+	igt_crtc_t *crtc;
+
+	for_each_crtc(display, crtc)
+		free_mask |= BIT(crtc->hardware_pipe);
+
+	igt_debug("libdrm has no drmModeGetCrtcList(), assuming pipe mask 0x%x free\n",
+		  free_mask);
+#endif
+
 /**
  * igt_parse_mode_string:
  * @mode_string: modeline string
lib/igt_kms.h +1 -0
index 9b8779a62ca3763720609a506e1652595858487a..9cd397b2ddc343aca9397ea35a3e25c1fd0acab9 100644
@@ -1365,6 +1365,7 @@ drmModeModeInfo *igt_get_non_joiner_mode(int drm_fd, igt_output_t *output);
 bool is_joiner_mode(int drm_fd, igt_output_t *output);
 bool igt_check_force_joiner_status(int drmfd, char *connector_name);
 bool igt_check_bigjoiner_support(igt_display_t *display);
+uint32_t igt_get_free_pipes_mask(igt_display_t *display);
 bool igt_parse_mode_string(const char *mode_string, drmModeModeInfo *mode);
 bool intel_pipe_output_combo_valid(igt_display_t *display);
 bool igt_check_output_is_dp_mst(igt_output_t *output);
meson.build +7 -0
index d7bbfd9698e5616ab777ac58128192ba1e0bec23..f41588c9d73361dbfd405de5ea8f764c6768a9c9 100644
@@ -129,6 +129,13 @@ endif
 
 build_info += 'With libdrm: ' + ','.join(libdrm_info)
 
+# drmModeGetCrtcList() is a recent libdrm addition; keep building against
+# older libdrm by falling back to plain resource enumeration.
+if cc.has_function('drmModeGetCrtcList', dependencies : libdrm,
+		   prefix : '#include <xf86drmMode.h>')
+	config.set('HAVE_DRMMODEGETCRTCLIST', 1)
+endif
+
 pciaccess = dependency('pciaccess', version : '>=0.10')
 libkmod = dependency('libkmod')
 # igt_procps.c reads /proc directly; libprocps and libproc2 are not needed.
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/2 tests/intel/kms_joiner: Use the CRTCs reported free before a modeset

In reply to Arun R Murthy

Every joiner modeset here picks pipes out of BIT(n_pipes) - 1, i.e. it assumes all pipes are free, and the ultra joiner and last-pipe paths pick a pipe without checking it at all. When another client owns a pipe the commit fails for an unrelated reason and the subtest reports a bogus failure.

Query the free pipes with igt_get_free_pipes_mask() right before each modeset sequence and use only those CRTCs that are available. igt_display_reset doesnt land to KMD without committing, so the pipes were never actually released before sampling; add the missing commit.

Assisted-by LLM
---
 tests/intel/kms_joiner.c | 75 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 70 insertions(+), 5 deletions(-)
tests/intel/kms_joiner.c +70 -5
index fce24f2bd08767351c1b323cc0a7f03c6d2fa0ec..c0e358a319734b8876deffe74e0416474b7e64e5 100644
@@ -131,6 +131,21 @@ static void enable_force_joiner_on_all_non_ultra_joiner_outputs(data_t *data)
 	}
 }
 
+/*
+ * A joiner modeset needs @count consecutive free pipes starting at @pipe.
+ * @free_pipe_mask is the snapshot taken from drmModeGetCrtcList().
+ */
+static bool pipes_are_free(uint32_t free_pipe_mask, enum hardware_pipe pipe, int count)
+{
+	uint32_t needed_mask = 0;
+	int i;
+
+	for (i = 0; i < count; i++)
+		needed_mask |= BIT(pipe + i);
+
+	return (free_pipe_mask & needed_mask) == needed_mask;
+}
+
 static enum hardware_pipe get_next_master_pipe(data_t *data, uint32_t available_pipe_mask)
 {
 	if ((data->master_pipes & available_pipe_mask) == 0)
@@ -223,7 +238,8 @@ static void switch_modeset_ultra_joiner_big_joiner(data_t *data, igt_output_t *o
 	drmModeModeInfo uj_mode;
 	int status;
 	bool ultrajoiner_found;
-	enum hardware_pipe pipe;
+	/* set_joiner_mode() always drives pipe A */
+	enum hardware_pipe pipe = PIPE_A;
 	bool force_joiner_supported;
 
 	drmModeConnector *connector = output->config.connector;
@@ -246,6 +262,14 @@ static void switch_modeset_ultra_joiner_big_joiner(data_t *data, igt_output_t *o
 	}
 
 	igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) {
+		/* Release the pipes a previous output was using if any */
+		igt_display_reset(&data->display);
+		igt_display_commit2(&data->display, COMMIT_ATOMIC);
+		igt_require_f(pipes_are_free(igt_get_free_pipes_mask(&data->display),
+					     pipe, 4),
+			      "No 4 free consecutive pipes starting at %s\n",
+			      kmstest_pipe_name(pipe));
+
 		set_joiner_mode(data, output, &uj_mode);
 		/* Switch to big joiner mode */
 		if (bigjoiner_mode_found(data->drm_fd, output->config.connector,
@@ -279,7 +303,7 @@ static void test_single_joiner(data_t *data, int output_count, bool force_joiner
 {
 	int i;
 	enum hardware_pipe pipe, master_pipe;
-	uint32_t available_pipe_mask = BIT(data->n_pipes) - 1;
+	uint32_t available_pipe_mask;
 	igt_output_t *output;
 	igt_plane_t *primary;
 	igt_output_t **outputs;
@@ -290,6 +314,9 @@ static void test_single_joiner(data_t *data, int output_count, bool force_joiner
 	igt_display_reset(&data->display);
 	igt_display_commit2(&data->display, COMMIT_ATOMIC);
 
+	available_pipe_mask = igt_get_free_pipes_mask(&data->display);
+	igt_require_f(available_pipe_mask, "No free CRTC available\n");
+
 	for (i = 0; i < output_count; i++) {
 		output = outputs[i];
 		for (pipe = 0; pipe < data->n_pipes - 1; pipe++) {
@@ -320,13 +347,15 @@ static void test_multi_joiner(data_t *data, int output_count, bool force_joiner)
 	igt_fb_t fb[output_count];
 	drmModeModeInfo *mode;
 
-	available_pipe_mask = BIT(data->n_pipes) - 1;
 	outputs = force_joiner ? data->non_big_joiner_output : data->big_joiner_output;
 	cleanup = 0;
 
 	igt_display_reset(&data->display);
 	igt_display_commit2(&data->display, COMMIT_ATOMIC);
 
+	available_pipe_mask = igt_get_free_pipes_mask(&data->display);
+	igt_require_f(available_pipe_mask, "No free CRTC available\n");
+
 	for (i = 0; i < output_count; i++) {
 		output = outputs[i];
 		for (pipe = 0; pipe < data->n_pipes; pipe++) {
@@ -366,12 +395,14 @@ static void test_invalid_modeset_two_joiner(data_t *data,
 	igt_fb_t fb[INVALID_TEST_OUTPUT];
 	drmModeModeInfo mode;
 
-	available_pipe_mask = BIT(data->n_pipes) - 1;
 	outputs = force_joiner ? data->non_big_joiner_output :
 		  mixed ? data->mixed_output : data->big_joiner_output;
 	igt_display_reset(&data->display);
 	igt_display_commit2(&data->display, COMMIT_ATOMIC);
 
+	available_pipe_mask = igt_get_free_pipes_mask(&data->display);
+	igt_require_f(available_pipe_mask, "No free CRTC available\n");
+
 	for (i = 0; i < data->n_pipes - 1; i++) {
 		attempt_mask = BIT(data->pipe_seq[i]);
 		master_pipe = get_next_master_pipe(data, available_pipe_mask & attempt_mask);
@@ -447,6 +478,12 @@ static void test_joiner_on_last_pipe(data_t *data, bool force_joiner)
 		igt_display_commit2(&data->display, COMMIT_ATOMIC);
 		output = outputs[i];
 
+		if (!pipes_are_free(igt_get_free_pipes_mask(display), pipe, 1)) {
+			igt_info("Pipe %s is not free, skipping output %s\n",
+				 kmstest_pipe_name(pipe), output->name);
+			continue;
+		}
+
 		if (!force_joiner) {
 			igt_require_f(bigjoiner_mode_found(data->drm_fd, output->config.connector, max_dotclock, &mode),
 						  "No big joiner mode found on output %s\n", output->name);
@@ -478,7 +515,8 @@ static void test_joiner_on_last_pipe(data_t *data, bool force_joiner)
 static void test_ultra_joiner(data_t *data, bool invalid_pipe, bool two_display, bool force_joiner)
 {
 	igt_display_t *display = &data->display;
-	int i, j, k, ret, count;
+	int i, j, k, ret, count, needed_pipes;
+	uint32_t free_pipe_mask;
 	igt_output_t *output, *non_ultra_joiner_output;
 	igt_plane_t *primary;
 	igt_output_t **outputs;
@@ -496,6 +534,16 @@ static void test_ultra_joiner(data_t *data, bool invalid_pipe, bool two_display,
 	igt_display_reset(&data->display);
 	igt_display_commit2(&data->display, COMMIT_ATOMIC);
 
+	/*
+	 * A successful ultra joiner modeset occupies four consecutive pipes,
+	 * so all four have to be free.
+	 * The invalid_pipe is a -ve test & expects the commit to be rejected,
+	 * so dont skip the test if 4 pipes are not available, allow it to fail.
+	 */
+	needed_pipes = invalid_pipe ? 1 : 4;
+	free_pipe_mask = igt_get_free_pipes_mask(&data->display);
+	igt_require_f(free_pipe_mask, "No free CRTC available\n");
+
 	for (i = 0; i < count; i++) {
 		output = outputs[i];
 
@@ -519,6 +567,14 @@ static void test_ultra_joiner(data_t *data, bool invalid_pipe, bool two_display,
 				continue;
 
 			pipe = data->pipe_seq[j];
+
+			if (!pipes_are_free(free_pipe_mask, pipe, needed_pipes)) {
+				igt_info("No %d free consecutive pipes from %s, skipping output %s\n",
+					 needed_pipes, kmstest_pipe_name(pipe),
+					 output->name);
+				continue;
+			}
+
 			crtc = igt_crtc_for_pipe(display, pipe);
 			igt_assert_f(crtc, "There is no pipe %s\n", kmstest_pipe_name(pipe));
 
@@ -579,6 +635,7 @@ static void test_basic_max_non_joiner(data_t *data)
 {
 	igt_display_t *display = &data->display;
 	int count;
+	uint32_t free_pipe_mask;
 	enum hardware_pipe pipe;
 	igt_output_t **outputs, *output;
 	igt_fb_t fb;
@@ -588,6 +645,10 @@ static void test_basic_max_non_joiner(data_t *data)
 	count = data->non_joiner_output_count;
 	outputs = data->non_joiner_output;
 	igt_display_reset(&data->display);
+	igt_display_commit2(&data->display, COMMIT_ATOMIC);
+
+	/* A non-joiner modeset needs a single free pipe. */
+	free_pipe_mask = igt_get_free_pipes_mask(&data->display);
 
 	for (int i = 0; i < count; i++) {
 		output = outputs[i];
@@ -596,6 +657,10 @@ static void test_basic_max_non_joiner(data_t *data)
 			igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) {
 				igt_crtc_t *crtc;
 
+				igt_require_f(pipes_are_free(free_pipe_mask, pipe, 1),
+					      "Pipe %s is not free\n",
+					      kmstest_pipe_name(pipe));
+
 				crtc = igt_crtc_for_pipe(display, pipe);
 				igt_assert_f(crtc, "There is no pipe %s\n", kmstest_pipe_name(pipe));
 
Signature · 1 line
2.25.1