diff mbox

[06/14] drm/i915: Inform userspace about command stream OA buf overflow

Message ID 1504778774-18117-7-git-send-email-sagar.a.kamble@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

sagar.a.kamble@intel.com Sept. 7, 2017, 10:06 a.m. UTC
From: Sourab Gupta <sourab.gupta@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@intel.com>
Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
 drivers/gpu/drm/i915/i915_perf.c | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index cd0920d..db2505f 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2120,6 +2120,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 0b1aa78..7664c5b 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -613,8 +613,11 @@  static void i915_perf_stream_patch_request(struct i915_perf_stream *stream,
 
 	while (sample_id < MAX_REQUEST_SAMPLE_ID) {
 		spin_lock_irqsave(&stream->samples_lock, flags);
-		if (list_empty(&stream->free_samples))
+		if (list_empty(&stream->free_samples)) {
+			stream->cs_buffer.status |=
+				I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW;
 			release_perf_sample(stream);
+		}
 		sample = list_first_entry_or_null(&stream->free_samples,
 				struct i915_perf_cs_sample, link);
 		WARN_ON(sample == NULL);
@@ -1572,6 +1575,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->samples_lock, flags);
 	if (list_empty(&stream->cs_samples)) {