diff mbox

[5/8] drm/i915: Inform userspace about command stream OA buf overflow

Message ID 1489644855-25562-6-git-send-email-sourab.gupta@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

sourab.gupta@intel.com March 16, 2017, 6:14 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>
---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
 drivers/gpu/drm/i915/i915_perf.c | 15 +++++++++++++++
 2 files changed, 17 insertions(+)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index d0f43e9..0f2a552 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2609,6 +2609,8 @@  struct drm_i915_private {
 		struct {
 			struct i915_vma *vma;
 			u8 *vaddr;
+#define I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW (1<<0)
+			u32 status;
 		} command_stream_buf;
 
 		struct list_head cs_samples;
diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index d1d9853..2841d0a 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -478,6 +478,8 @@  static void insert_perf_sample(struct drm_i915_private *dev_priv,
 		else {
 			u32 target_size = sample_size - first->offset;
 
+			dev_priv->perf.command_stream_buf.status |=
+				I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW;
 			release_perf_samples(dev_priv, target_size);
 			sample->offset = 0;
 		}
@@ -491,6 +493,8 @@  static void insert_perf_sample(struct drm_i915_private *dev_priv,
 				(first->offset - last->offset -
 				sample_size);
 
+			dev_priv->perf.command_stream_buf.status |=
+				I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW;
 			release_perf_samples(dev_priv, target_size);
 			sample->offset = last->offset + sample_size;
 		}
@@ -1577,6 +1581,17 @@  static int oa_rcs_append_reports(struct i915_perf_stream *stream,
 	struct i915_perf_cs_sample *entry, *next;
 	LIST_HEAD(free_list);
 	int ret = 0;
+	u32 status = dev_priv->perf.command_stream_buf.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;
+
+		dev_priv->perf.command_stream_buf.status &=
+				~I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW;
+	}
 
 	spin_lock(&dev_priv->perf.sample_lock);
 	if (list_empty(&dev_priv->perf.cs_samples)) {