[Intel-gfx] [PATCH 4/4] drm/i915: Rename drm_i915_error_state_buf to intel_strbuf

Mika Kuoppala mika.kuoppala at linux.intel.com
Tue Dec 9 08:04:34 PST 2014


Emphasize the more general applicability of the seekable
string buffer by decoupling it from error handling.

Signed-off-by: Mika Kuoppala <mika.kuoppala at intel.com>
---
 drivers/gpu/drm/i915/i915_debugfs.c   |  2 +-
 drivers/gpu/drm/i915/i915_drv.h       | 14 +++----
 drivers/gpu/drm/i915/i915_gpu_error.c | 74 ++++++++++++++++++++---------------
 drivers/gpu/drm/i915/i915_sysfs.c     |  2 +-
 drivers/gpu/drm/i915/intel_display.c  |  4 +-
 drivers/gpu/drm/i915/intel_overlay.c  |  8 ++--
 6 files changed, 58 insertions(+), 46 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 5480cf5..f9e3449 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -925,7 +925,7 @@ static ssize_t i915_gpu_state_read(struct file *file, char __user *userbuf,
 				   size_t count, loff_t *pos)
 {
 	struct i915_error_state_file_priv *error_priv = file->private_data;
-	struct drm_i915_error_state_buf error_str;
+	struct intel_strbuf error_str;
 	loff_t tmp_pos = 0;
 	ssize_t ret_count = 0;
 	int ret;
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 452f93f..7ac3c71 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1201,7 +1201,7 @@ struct i915_gem_mm {
 	u32 object_count;
 };
 
-struct drm_i915_error_state_buf {
+struct intel_strbuf {
 	struct drm_i915_private *i915;
 	unsigned bytes;
 	unsigned size;
@@ -2859,14 +2859,14 @@ static inline void intel_display_crc_init(struct drm_device *dev) {}
 
 /* i915_gpu_error.c */
 __printf(2, 3)
-void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
-int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
+void intel_strbuf_printf(struct intel_strbuf *e, const char *f, ...);
+int i915_error_state_to_str(struct intel_strbuf *estr,
 			    const struct i915_error_state_file_priv *error);
-int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
+int i915_error_state_buf_init(struct intel_strbuf *eb,
 			      struct drm_i915_private *i915,
 			      size_t count, loff_t pos);
 static inline void i915_error_state_buf_release(
-	struct drm_i915_error_state_buf *eb)
+	struct intel_strbuf *eb)
 {
 	kfree(eb->buf);
 }
@@ -2995,11 +2995,11 @@ void intel_notify_mmio_flip(struct intel_engine_cs *ring);
 
 /* overlay */
 extern struct intel_overlay_error_state *intel_overlay_capture_error_state(struct drm_device *dev);
-extern void intel_overlay_print_error_state(struct drm_i915_error_state_buf *e,
+extern void intel_overlay_print_error_state(struct intel_strbuf *e,
 					    struct intel_overlay_error_state *error);
 
 extern struct intel_display_error_state *intel_display_capture_error_state(struct drm_device *dev);
-extern void intel_display_print_error_state(struct drm_i915_error_state_buf *e,
+extern void intel_display_print_error_state(struct intel_strbuf *e,
 					    struct drm_device *dev,
 					    struct intel_display_error_state *error);
 
diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
index 0cefeebc..78c6d87 100644
--- a/drivers/gpu/drm/i915/i915_gpu_error.c
+++ b/drivers/gpu/drm/i915/i915_gpu_error.c
@@ -77,7 +77,7 @@ static const char *purgeable_flag(int purgeable)
 	return purgeable ? " purgeable" : "";
 }
 
-static bool __i915_error_ok(struct drm_i915_error_state_buf *e)
+static bool __intel_strbuf_ok(struct intel_strbuf *e)
 {
 
 	if (!e->err && WARN(e->bytes > (e->size - 1), "overflow")) {
@@ -91,8 +91,8 @@ static bool __i915_error_ok(struct drm_i915_error_state_buf *e)
 	return true;
 }
 
-static bool __i915_error_seek(struct drm_i915_error_state_buf *e,
-			      unsigned len)
+static bool __intel_strbuf_seek(struct intel_strbuf *e,
+				unsigned len)
 {
 	if (e->pos + len <= e->start) {
 		e->pos += len;
@@ -108,8 +108,8 @@ static bool __i915_error_seek(struct drm_i915_error_state_buf *e,
 	return true;
 }
 
-static void __i915_error_advance(struct drm_i915_error_state_buf *e,
-				 unsigned len)
+static void __intel_strbuf_advance(struct intel_strbuf *e,
+				   unsigned len)
 {
 	/* If this is first printf in this window, adjust it so that
 	 * start position matches start of the buffer
@@ -134,12 +134,12 @@ static void __i915_error_advance(struct drm_i915_error_state_buf *e,
 	e->pos += len;
 }
 
-static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
-			       const char *f, va_list args)
+static void intel_strbuf_vprintf(struct intel_strbuf *e,
+				 const char *f, va_list args)
 {
 	unsigned len;
 
-	if (!__i915_error_ok(e))
+	if (!__intel_strbuf_ok(e))
 		return;
 
 	/* Seek the first printf which is hits start position */
@@ -150,7 +150,7 @@ static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
 		len = vsnprintf(NULL, 0, f, tmp);
 		va_end(tmp);
 
-		if (!__i915_error_seek(e, len))
+		if (!__intel_strbuf_seek(e, len))
 			return;
 	}
 
@@ -158,22 +158,22 @@ static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
 	if (len >= e->size - e->bytes)
 		len = e->size - e->bytes - 1;
 
-	__i915_error_advance(e, len);
+	__intel_strbuf_advance(e, len);
 }
 
-static void i915_error_puts(struct drm_i915_error_state_buf *e,
-			    const char *str)
+static void intel_strbuf_puts(struct intel_strbuf *e,
+			      const char *str)
 {
 	unsigned len;
 
-	if (!__i915_error_ok(e))
+	if (!__intel_strbuf_ok(e))
 		return;
 
 	len = strlen(str);
 
 	/* Seek the first printf which is hits start position */
 	if (e->pos < e->start) {
-		if (!__i915_error_seek(e, len))
+		if (!__intel_strbuf_seek(e, len))
 			return;
 	}
 
@@ -181,13 +181,34 @@ static void i915_error_puts(struct drm_i915_error_state_buf *e,
 		len = e->size - e->bytes - 1;
 	memcpy(e->buf + e->bytes, str, len);
 
-	__i915_error_advance(e, len);
+	__intel_strbuf_advance(e, len);
 }
 
-#define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
-#define err_puts(e, s) i915_error_puts(e, s)
+/**
+ * intel_strbuf_printf - print formatted string into intel_strbuf
+ * @strbuf: destination string buffer
+ * @format: format string
+ * @...: variable arguments for each format specifier in @format.
+ *
+ * Print formatted string into intel_strbuf. struct intel_strbuf is
+ * a seekable string buffer. It is used to seek into a potentially
+ * very big string without the need to allocate the whole string
+ * beforehand. Only the seekable 'window' is allocated at a time.
+ * __intel_strbuf_ok() can be used to check for errors after this call.
+ */
+void intel_strbuf_printf(struct intel_strbuf *strbuf, const char *format, ...)
+{
+	va_list args;
+
+	va_start(args, format);
+	intel_strbuf_vprintf(strbuf, format, args);
+	va_end(args);
+}
 
-static void print_error_buffers(struct drm_i915_error_state_buf *m,
+#define err_printf(e, ...) intel_strbuf_printf(e, __VA_ARGS__)
+#define err_puts(e, s) intel_strbuf_puts(e, s)
+
+static void print_error_buffers(struct intel_strbuf *m,
 				const char *name,
 				struct drm_i915_error_buffer *err,
 				int count)
@@ -240,7 +261,7 @@ static const char *hangcheck_action_to_str(enum intel_ring_hangcheck_action a)
 	return "unknown";
 }
 
-static void i915_ring_error_state(struct drm_i915_error_state_buf *m,
+static void i915_ring_error_state(struct intel_strbuf *m,
 				  struct drm_device *dev,
 				  struct drm_i915_error_state *error,
 				  int ring_idx)
@@ -304,16 +325,7 @@ static void i915_ring_error_state(struct drm_i915_error_state_buf *m,
 		   ring->hangcheck_score);
 }
 
-void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...)
-{
-	va_list args;
-
-	va_start(args, f);
-	i915_error_vprintf(e, f, args);
-	va_end(args);
-}
-
-static void print_error_obj(struct drm_i915_error_state_buf *m,
+static void print_error_obj(struct intel_strbuf *m,
 			    struct drm_i915_error_object *obj)
 {
 	int page, offset, elt;
@@ -327,7 +339,7 @@ static void print_error_obj(struct drm_i915_error_state_buf *m,
 	}
 }
 
-int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
+int i915_error_state_to_str(struct intel_strbuf *m,
 			    const struct i915_error_state_file_priv *error_priv)
 {
 	struct drm_device *dev = error_priv->dev;
@@ -495,7 +507,7 @@ out:
 	return 0;
 }
 
-int i915_error_state_buf_init(struct drm_i915_error_state_buf *ebuf,
+int i915_error_state_buf_init(struct intel_strbuf *ebuf,
 			      struct drm_i915_private *i915,
 			      size_t count, loff_t pos)
 {
diff --git a/drivers/gpu/drm/i915/i915_sysfs.c b/drivers/gpu/drm/i915/i915_sysfs.c
index 4a5af69..68d40ab 100644
--- a/drivers/gpu/drm/i915/i915_sysfs.c
+++ b/drivers/gpu/drm/i915/i915_sysfs.c
@@ -543,7 +543,7 @@ static ssize_t error_state_read(struct file *filp, struct kobject *kobj,
 	struct drm_minor *minor = dev_to_drm_minor(kdev);
 	struct drm_device *dev = minor->dev;
 	struct i915_error_state_file_priv error_priv;
-	struct drm_i915_error_state_buf error_str;
+	struct intel_strbuf error_str;
 	ssize_t ret_count = 0;
 	int ret;
 
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index a9bdc12..2414277 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -13762,10 +13762,10 @@ intel_display_capture_error_state(struct drm_device *dev)
 	return error;
 }
 
-#define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
+#define err_printf(e, ...) intel_strbuf_printf(e, __VA_ARGS__)
 
 void
-intel_display_print_error_state(struct drm_i915_error_state_buf *m,
+intel_display_print_error_state(struct intel_strbuf *m,
 				struct drm_device *dev,
 				struct intel_display_error_state *error)
 {
diff --git a/drivers/gpu/drm/i915/intel_overlay.c b/drivers/gpu/drm/i915/intel_overlay.c
index 973c9de..b4fdcc7 100644
--- a/drivers/gpu/drm/i915/intel_overlay.c
+++ b/drivers/gpu/drm/i915/intel_overlay.c
@@ -1509,15 +1509,15 @@ err:
 }
 
 void
-intel_overlay_print_error_state(struct drm_i915_error_state_buf *m,
+intel_overlay_print_error_state(struct intel_strbuf *m,
 				struct intel_overlay_error_state *error)
 {
-	i915_error_printf(m, "Overlay, status: 0x%08x, interrupt: 0x%08x\n",
+	intel_strbuf_printf(m, "Overlay, status: 0x%08x, interrupt: 0x%08x\n",
 			  error->dovsta, error->isr);
-	i915_error_printf(m, "  Register file at 0x%08lx:\n",
+	intel_strbuf_printf(m, "  Register file at 0x%08lx:\n",
 			  error->base);
 
-#define P(x) i915_error_printf(m, "    " #x ":	0x%08x\n", error->regs.x)
+#define P(x) intel_strbuf_printf(m, "    " #x ":	0x%08x\n", error->regs.x)
 	P(OBUF_0Y);
 	P(OBUF_1Y);
 	P(OBUF_0U);
-- 
1.9.1



More information about the Intel-gfx mailing list