Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t v3] tools/xe-perf-recorder: Wait for mmio-trigger-report
@ 2026-10-07  5:44 Shekhar Chauhan
  2026-10-07  6:43 ` ✓ Xe.CI.BAT: success for tools/xe-perf-recorder: Wait for mmio-trigger-report (rev3) Patchwork
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Shekhar Chauhan @ 2026-10-07  5:44 UTC (permalink / raw)
  To: igt-dev; +Cc: shekhar.chauhan, umesh.nerlige.ramappa

From: Ashutosh Dixit <ashutosh.dixit@intel.com>

After mmio trigger is issued, we should wait till we receive a report with
the context id issued in the mmio trigger.

While waiting, propagate write_perf_data() failures back to main(). A
failed write can drop an already-read trigger report before it is checked,
which would otherwise leave the recorder waiting indefinitely.

v3: Propagate write_perf_data() failures out of the trigger wait (Shekhar)

Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Co-developed-by: Shekhar Chauhan <shekhar.chauhan@intel.com>
Signed-off-by: Shekhar Chauhan <shekhar.chauhan@intel.com>
---
 tools/xe-perf/xe_perf_recorder.c | 57 ++++++++++++++++++++++++++------
 1 file changed, 47 insertions(+), 10 deletions(-)

diff --git a/tools/xe-perf/xe_perf_recorder.c b/tools/xe-perf/xe_perf_recorder.c
index e13eef519..6ec29558d 100644
--- a/tools/xe-perf/xe_perf_recorder.c
+++ b/tools/xe-perf/xe_perf_recorder.c
@@ -370,6 +370,7 @@ struct recording_context {
 	uint32_t vm;
 	uint32_t exec_queue;
 	struct intel_bb *ibb;
+	uint32_t mmio_trg_val;
 };
 
 static uint32_t oa_unit_mmio_trigger_reg(struct recording_context *ctx)
@@ -642,13 +643,15 @@ check_mmio_trigger_report(struct recording_context *ctx, const void *report)
 	const uint32_t *report_32 = report;
 	uint64_t value;
 
-	if (report_reason(report_32))
+	if (!ctx->mmio_trg_val || report_reason(report_32))
 		return;
 
 	value = (fmt->header == HDR_64_BIT) ? ((const uint64_t *)report)[2] : report_32[2];
 
-	if (value == 0xc0ffee01 || value == 0xc0ffee02)
+	if (value == ctx->mmio_trg_val) {
 		fprintf(stdout, "Received trigger report with value 0x%" PRIx64 "\n", value);
+		ctx->mmio_trg_val = 0;
+	}
 }
 
 static bool write_stream_data(struct recording_context *ctx,
@@ -712,6 +715,21 @@ static bool write_perf_data(FILE *output, struct recording_context *ctx)
 	return false;
 }
 
+static bool write_mmio_trigger_data(struct recording_context *ctx)
+{
+	struct pollfd pollfd = { .fd = ctx->perf_fd, .events = POLLIN };
+
+	while (ctx->mmio_trg_val) {
+		poll(&pollfd, 1, -1);
+		assert(pollfd.revents & POLLIN);
+
+		if (!write_perf_data(ctx->output_stream, ctx))
+			return false;
+	}
+
+	return true;
+}
+
 static clock_t correlation_clock_id = CLOCK_MONOTONIC;
 
 static const char *
@@ -790,23 +808,27 @@ static void emit_mmio_triggered_report(struct intel_bb *ibb, uint32_t reg, uint3
 	intel_bb_out(ibb, value);
 }
 
-static void emit_oa_trigger(struct recording_context *ctx, uint32_t value)
+static bool emit_oa_trigger(struct recording_context *ctx, uint32_t value)
 {
 	emit_mmio_triggered_report(ctx->ibb, oa_unit_mmio_trigger_reg(ctx), value);
 
 	intel_bb_flush_render(ctx->ibb);
 	intel_bb_sync(ctx->ibb);
 	intel_bb_reset(ctx->ibb, false);
+
+	ctx->mmio_trg_val = value;
+
+	return write_mmio_trigger_data(ctx);
 }
 
-static void
+static bool
 read_command_file(struct recording_context *ctx)
 {
 	struct recorder_command_base header;
 	ssize_t ret = read(ctx->command_fifo_fd, &header, sizeof(header));
 
 	if (ret < 0)
-		return;
+		return true;
 
 	switch (header.command) {
 	case RECORDER_COMMAND_DUMP: {
@@ -814,8 +836,10 @@ read_command_file(struct recording_context *ctx)
 		uint8_t *dump = malloc(len);
 		FILE *file;
 
-		emit_oa_trigger(ctx, 0xc0ffee02);
-		write_perf_data(ctx->output_stream, ctx);
+		if (!emit_oa_trigger(ctx, 0xc0ffee02)) {
+			free(dump);
+			return false;
+		}
 
 		while (offset < len &&
 		       ((ret = read(ctx->command_fifo_fd,
@@ -859,6 +883,8 @@ read_command_file(struct recording_context *ctx)
 		fprintf(stderr, "Unknown command 0x%x\n", header.command);
 		break;
 	}
+
+	return true;
 }
 
 static void
@@ -1320,7 +1346,11 @@ main(int argc, char *argv[])
 	}
 
 	init_mmio_trigger_ctx(&ctx);
-	emit_oa_trigger(&ctx, 0xc0ffee01);
+	if (!emit_oa_trigger(&ctx, 0xc0ffee01)) {
+		fprintf(stderr, "Failed to write xe-oa data: %s\n",
+			strerror(errno));
+		goto fail;
+	}
 
 	corr_period_ns = corr_period * 1000000000ul;
 	poll_time_ns = corr_period_ns;
@@ -1351,7 +1381,11 @@ main(int argc, char *argv[])
 			}
 
 			if (pollfd[1].revents & POLLIN) {
-				read_command_file(&ctx);
+				if (!read_command_file(&ctx)) {
+					fprintf(stderr, "Failed to write xe-oa data: %s\n",
+						strerror(errno));
+					break;
+				}
 			}
 		}
 
@@ -1370,7 +1404,10 @@ main(int argc, char *argv[])
 	}
 
 	/* Emit second OA trigger for the case where circular buffer is not used */
-	emit_oa_trigger(&ctx, 0xc0ffee02);
+	if (!emit_oa_trigger(&ctx, 0xc0ffee02))
+		fprintf(stderr, "Failed to write xe-oa data: %s\n",
+			strerror(errno));
+
 	fprintf(stdout, "Exiting...\n");
 
 	if (!write_perf_data(ctx.output_stream, &ctx)) {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-15 10:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-07  5:44 [PATCH i-g-t v3] tools/xe-perf-recorder: Wait for mmio-trigger-report Shekhar Chauhan
2026-10-07  6:43 ` ✓ Xe.CI.BAT: success for tools/xe-perf-recorder: Wait for mmio-trigger-report (rev3) Patchwork
2026-10-07  6:56 ` ✓ i915.CI.BAT: " Patchwork
2026-10-07  8:15 ` ✓ Xe.CI.FULL: " Patchwork
2026-10-07  9:43 ` ✗ i915.CI.Full: failure " Patchwork
2026-10-15 10:46   ` Shekhar Chauhan
2026-10-08 18:56 ` [PATCH i-g-t v3] tools/xe-perf-recorder: Wait for mmio-trigger-report Umesh Nerlige Ramappa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox