[Intel-gfx] [PATCH 05/12] drm/i915: Inform userspace about command stream OA buf overflow

Sagar Arun Kamble sagar.a.kamble at intel.com
Mon Jul 31 07:59:38 UTC 2017


From: Sourab Gupta <sourab.gupta at intel.com>

Considering how we don't currently give userspace control over the
OA buffer size and always configure a large 16MB buffer,
then a buffer overflow does anyway likely indicate that something
has gone quite badly wrong.

Here we set a status flag to detect overflow and inform userspace
of the report_lost condition accordingly. This is in line with the
behavior of the periodic OA buffer.

Signed-off-by: Sourab Gupta <sourab.gupta at intel.com>
Signed-off-by: Sagar Arun Kamble <sagar.a.kamble at intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
 drivers/gpu/drm/i915/i915_perf.c | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 886fc5e..fb81315 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2068,6 +2068,8 @@ struct i915_perf_stream {
 	struct {
 		struct i915_vma *vma;
 		u8 *vaddr;
+#define I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW (1<<0)
+		u32 status;
 	} cs_buffer;
 
 	struct list_head cs_samples;
diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 462d180..905c5bb 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -501,6 +501,8 @@ static void insert_perf_sample(struct i915_perf_stream *stream,
 		else {
 			u32 target_size = sample_size - first->offset;
 
+			stream->cs_buffer.status |=
+				I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW;
 			release_perf_samples(stream, target_size);
 			sample->offset = 0;
 		}
@@ -514,6 +516,8 @@ static void insert_perf_sample(struct i915_perf_stream *stream,
 				(first->offset - last->offset -
 				sample_size);
 
+			stream->cs_buffer.status |=
+				I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW;
 			release_perf_samples(stream, target_size);
 			sample->offset = last->offset + sample_size;
 		}
@@ -1552,6 +1556,17 @@ static int append_cs_buffer_samples(struct i915_perf_stream *stream,
 	LIST_HEAD(free_list);
 	int ret = 0;
 	unsigned long flags;
+	u32 status = stream->cs_buffer.status;
+
+	if (unlikely(status & I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW)) {
+		ret = append_oa_status(stream, buf, count, offset,
+				       DRM_I915_PERF_RECORD_OA_BUFFER_LOST);
+		if (ret)
+			return ret;
+
+		stream->cs_buffer.status &=
+				~I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW;
+	}
 
 	spin_lock_irqsave(&stream->cs_samples_lock, flags);
 	if (list_empty(&stream->cs_samples)) {
-- 
1.9.1



More information about the Intel-gfx mailing list