All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [PATCH 02/10] drm/i915: rework dev->first_error locking
Date: Fri, 27 Apr 2012 15:17:39 +0200	[thread overview]
Message-ID: <1335532667-10597-2-git-send-email-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <1335532667-10597-1-git-send-email-daniel.vetter@ffwll.ch>

- reduce the irq disabled section, even for a debugfs file this was
  way too long.
- always disable irqs when taking the lock.

v2: Thou shalt not mistake locking for reference counting, so:
- reference count the error_state to protect from concurent freeeing.
  This will be only really used in the next patch.

Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_debugfs.c |   13 ++++++++-----
 drivers/gpu/drm/i915/i915_drv.h     |    4 ++++
 drivers/gpu/drm/i915/i915_irq.c     |   12 +++++++-----
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 3f6e28e..b46c198 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -701,12 +701,16 @@ static int i915_error_state(struct seq_file *m, void *unused)
 	int i, j, page, offset, elt;
 
 	spin_lock_irqsave(&dev_priv->error_lock, flags);
-	if (!dev_priv->first_error) {
+	error = dev_priv->first_error;
+	if (error)
+		kref_get(&error->ref);
+	spin_unlock_irqrestore(&dev_priv->error_lock, flags);
+
+	if (!error) {
 		seq_printf(m, "no error state collected\n");
-		goto out;
+		return 0;
 	}
 
-	error = dev_priv->first_error;
 
 	seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
 		   error->time.tv_usec);
@@ -788,8 +792,7 @@ static int i915_error_state(struct seq_file *m, void *unused)
 	if (error->display)
 		intel_display_print_error_state(m, dev, error->display);
 
-out:
-	spin_unlock_irqrestore(&dev_priv->error_lock, flags);
+	kref_put(&error->ref, i915_error_state_free);
 
 	return 0;
 }
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 5e62b35..2aaa594 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -39,6 +39,7 @@
 #include <drm/intel-gtt.h>
 #include <linux/backlight.h>
 #include <linux/intel-iommu.h>
+#include <linux/kref.h>
 
 /* General customization:
  */
@@ -171,6 +172,7 @@ struct sdvo_device_mapping {
 struct intel_display_error_state;
 
 struct drm_i915_error_state {
+	struct kref ref;
 	u32 eir;
 	u32 pgtbl_er;
 	u32 pipestat[I915_MAX_PIPES];
@@ -466,6 +468,7 @@ typedef struct drm_i915_private {
 	unsigned int fsb_freq, mem_freq, is_ddr3;
 
 	spinlock_t error_lock;
+	/* Protected by dev->error_lock. */
 	struct drm_i915_error_state *first_error;
 	struct work_struct error_work;
 	struct completion error_completion;
@@ -1163,6 +1166,7 @@ extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
 				struct drm_file *file_priv);
 extern int i915_vblank_swap(struct drm_device *dev, void *data,
 			    struct drm_file *file_priv);
+void i915_error_state_free(struct kref *error_ref);
 
 void
 i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 5c360ee..b6c02eb 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -869,10 +869,11 @@ i915_error_object_free(struct drm_i915_error_object *obj)
 	kfree(obj);
 }
 
-static void
-i915_error_state_free(struct drm_device *dev,
-		      struct drm_i915_error_state *error)
+void
+i915_error_state_free(struct kref *error_ref)
 {
+	struct drm_i915_error_state *error = container_of(error_ref,
+							  typeof(*error), ref);
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
@@ -1120,6 +1121,7 @@ static void i915_capture_error_state(struct drm_device *dev)
 	DRM_INFO("capturing error event; look for more information in /debug/dri/%d/i915_error_state\n",
 		 dev->primary->index);
 
+	kref_init(&error->ref);
 	error->eir = I915_READ(EIR);
 	error->pgtbl_er = I915_READ(PGTBL_ER);
 	for_each_pipe(pipe)
@@ -1181,7 +1183,7 @@ static void i915_capture_error_state(struct drm_device *dev)
 	spin_unlock_irqrestore(&dev_priv->error_lock, flags);
 
 	if (error)
-		i915_error_state_free(dev, error);
+		i915_error_state_free(&error->ref);
 }
 
 void i915_destroy_error_state(struct drm_device *dev)
@@ -1196,7 +1198,7 @@ void i915_destroy_error_state(struct drm_device *dev)
 	spin_unlock_irqrestore(&dev_priv->error_lock, flags);
 
 	if (error)
-		i915_error_state_free(dev, error);
+		kref_put(&error->ref, i915_error_state_free);
 }
 #else
 #define i915_capture_error_state(x)
-- 
1.7.9

  reply	other threads:[~2012-04-27 13:17 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-27 13:17 [PATCH 01/10] drm/i915: add interface to simulate gpu hangs Daniel Vetter
2012-04-27 13:17 ` Daniel Vetter [this message]
2012-05-04 17:04   ` [PATCH 02/10] drm/i915: rework dev->first_error locking Eugeni Dodonov
2012-04-27 13:17 ` [PATCH 03/10] drm/i915: allow the existing error_state to be destroyed Daniel Vetter
2012-05-04 11:56   ` Daniel Vetter
2012-05-04 17:15     ` Eugeni Dodonov
2012-05-04 19:58       ` Daniel Vetter
2012-04-27 13:17 ` [PATCH 04/10] drm/i915: simplify i915_reset a bit Daniel Vetter
2012-05-04 16:47   ` Eugeni Dodonov
2012-04-27 13:17 ` [PATCH 05/10] drm/i915: extract intel_gpu_reset Daniel Vetter
2012-04-30  1:03   ` Ben Widawsky
2012-05-04 16:51   ` Eugeni Dodonov
2012-04-27 13:17 ` [PATCH 06/10] drm/i915: make gpu hangman more resilient Daniel Vetter
2012-05-04 16:47   ` Eugeni Dodonov
2012-04-27 13:17 ` [PATCH 07/10] drm/i915: kill flags parameter for reset functions Daniel Vetter
2012-05-04 16:47   ` Eugeni Dodonov
2012-04-27 13:17 ` [PATCH 08/10] drm/i915: also reset the media engine on gen4/5 Daniel Vetter
2012-04-27 13:17 ` [PATCH 09/10] drm/i915: remove modeset reset from i915_reset Daniel Vetter
2012-04-27 13:17 ` [PATCH 10/10] drm/i915: kill gen4 gpu reset code Daniel Vetter
2012-04-27 18:49   ` Eric Anholt
2012-04-27 19:17     ` Daniel Vetter
2012-04-27 23:26       ` Eric Anholt
2012-05-02 19:33         ` [PATCH] drm/i915: fix gen4 gpu reset Daniel Vetter
2012-05-02 19:54           ` Kenneth Graunke
2012-05-04 12:07             ` Daniel Vetter
2012-05-04 17:06           ` Eugeni Dodonov
2012-04-28  4:56 ` [PATCH 01/10] drm/i915: add interface to simulate gpu hangs Ben Widawsky
2012-05-02 15:23   ` Daniel Vetter
2012-05-03 12:48 ` [PATCH] " Daniel Vetter
2012-05-03 19:00   ` Eugeni Dodonov
2012-05-05 19:13     ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1335532667-10597-2-git-send-email-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.