Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Karthik B S <karthik.b.s@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: pranay.samala@intel.com, Karthik B S <karthik.b.s@intel.com>,
	S Sebinraj <s.sebinraj@intel.com>,
	Krzysztof Karas <krzysztof.karas@intel.com>
Subject: [PATCH i-g-t] tests/kms_explicit_fence: Rescue pending IN_FENCE waits on test failures
Date: Mon,  4 May 2026 11:15:12 +0530	[thread overview]
Message-ID: <20260504054512.2192437-1-karthik.b.s@intel.com> (raw)

Track per-plane timeline/fence state across the in-flight NONBLOCK atomic
commit and install an exit handler to signal any still-unsignaled fences.
This prevents cleanup hangs when an assertion fires after commit
submission but before the test signals the blocking fence.

Cc: S Sebinraj <s.sebinraj@intel.com>
Cc: Krzysztof Karas <krzysztof.karas@intel.com>
Signed-off-by: Karthik B S <karthik.b.s@intel.com>
---
 tests/kms_explicit_fence.c | 58 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/tests/kms_explicit_fence.c b/tests/kms_explicit_fence.c
index 2ec9bf39d..7ffdcb285 100644
--- a/tests/kms_explicit_fence.c
+++ b/tests/kms_explicit_fence.c
@@ -68,6 +68,42 @@ typedef struct {
 	igt_pipe_crc_t *pipe_crc;
 } data_t;
 
+/*
+ * State tracked across the lifetime of an in-flight atomic commit that has
+ * IN_FENCEs attached. The exit handler uses this to unblock any pending
+ * commit if an assert hits between the commit and the point where
+ * the test would otherwise signal the unsignaled fence(s).
+ */
+static struct {
+	int timelines[NUM_PLANES];
+	bool needs_signal[NUM_PLANES];
+	bool active;
+} pending_fence_state = {
+	.timelines = { -1, -1, -1 },
+};
+
+static void signal_pending_fences(int sig)
+{
+	if (!pending_fence_state.active)
+		return;
+
+	for (int i = 0; i < NUM_PLANES; i++) {
+		if (pending_fence_state.timelines[i] < 0)
+			continue;
+
+		if (pending_fence_state.needs_signal[i]) {
+			/*
+			 * Best-effort: advance the timeline so the kernel
+			 * stops waiting on this IN_FENCE.
+			 */
+			sw_sync_timeline_inc(pending_fence_state.timelines[i], 1);
+			pending_fence_state.needs_signal[i] = false;
+		}
+	}
+
+	pending_fence_state.active = false;
+}
+
 static void setup_output(data_t *data)
 {
 	igt_display_t *display = &data->display;
@@ -242,8 +278,14 @@ static void multiplane_atomic_fence_wait(data_t *data)
 
 		/* Attach IN_FENCE_FD to plane */
 		igt_plane_set_fence_fd(planes[i], fences[i]);
+
+		pending_fence_state.timelines[i] = timelines[i];
+		pending_fence_state.needs_signal[i] = !should_signal[i];
 	}
 
+	/* Arm the exit handler before the NONBLOCK commit goes out. */
+	pending_fence_state.active = true;
+
 	/* Swap overlay colors to detect scanout changes via CRC */
 	igt_plane_set_fb(data->overlay1, &data->overlay2_fb);
 	igt_plane_set_position(data->overlay1, OVERLAY1_POS_X, OVERLAY1_POS_Y);
@@ -299,6 +341,7 @@ static void multiplane_atomic_fence_wait(data_t *data)
 	igt_assert_crc_equal(&crc_before, &crc_after);
 
 	/* Now signal the blocking fence (overlay2) */
+	pending_fence_state.needs_signal[PLANE_OVERLAY2_IDX] = false;
 	sw_sync_timeline_inc(timelines[PLANE_OVERLAY2_IDX], 1);
 
 	/* Wait for overlay2 fence to be signaled */
@@ -311,6 +354,12 @@ static void multiplane_atomic_fence_wait(data_t *data)
 	igt_assert_eq(ret, 0);
 	igt_assert_eq(sync_fence_status(out_fence), 1);
 
+	/*
+	 * The pending atomic commit has now completed, so the exit handler
+	 * no longer needs to rescue it.
+	 */
+	pending_fence_state.active = false;
+
 	/* Verify display has now updated (CRC should differ from baseline) */
 	igt_pipe_crc_get_current(data->drm_fd, data->pipe_crc, &crc_final);
 
@@ -353,6 +402,13 @@ int igt_main()
 
 		data.pipe_crc = igt_pipe_crc_new(data.drm_fd, data.crtc->crtc_index,
 						 IGT_PIPE_CRC_SOURCE_AUTO);
+
+		/*
+		 * Make sure that on any failure mid-test, any unsignaled
+		 * IN_FENCE that the kernel is still waiting on gets
+		 * signaled so cleanup can complete instead of hanging.
+		 */
+		igt_install_exit_handler(signal_pending_fences);
 	}
 
 	igt_describe("Test atomic commit with 3 planes (1 primary, 2 overlay) "
@@ -363,6 +419,8 @@ int igt_main()
 		multiplane_atomic_fence_wait(&data);
 
 	igt_fixture() {
+		signal_pending_fences(0);
+
 		reset_display_state(&data);
 		igt_pipe_crc_free(data.pipe_crc);
 		cleanup_crtc(&data);
-- 
2.43.0


             reply	other threads:[~2026-05-04  5:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-04  5:45 Karthik B S [this message]
2026-05-04  7:27 ` ✓ Xe.CI.BAT: success for tests/kms_explicit_fence: Rescue pending IN_FENCE waits on test failures Patchwork
2026-05-04  7:28 ` ✓ i915.CI.BAT: " Patchwork
2026-05-04 10:41 ` ✗ i915.CI.Full: failure " Patchwork
2026-05-05  6:34 ` [PATCH i-g-t] " Sebinraj, S
2026-05-06  8:38   ` Karthik B S
2026-05-05  7:02 ` Krzysztof Karas
2026-05-06  8:41   ` Karthik B S
2026-05-06  4:38 ` Samala, Pranay
2026-05-06  8:42   ` Karthik B S

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=20260504054512.2192437-1-karthik.b.s@intel.com \
    --to=karthik.b.s@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=krzysztof.karas@intel.com \
    --cc=pranay.samala@intel.com \
    --cc=s.sebinraj@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