Skip to content

Commit

Permalink
drm/i915: rework dev->first_error locking
Browse files Browse the repository at this point in the history
- 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.

Reviewed-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
  • Loading branch information
Daniel Vetter committed May 5, 2012
1 parent e5eb3d6 commit 742cbee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
13 changes: 8 additions & 5 deletions drivers/gpu/drm/i915/i915_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,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);
Expand Down Expand Up @@ -786,8 +790,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;
}
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/i915/i915_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <drm/intel-gtt.h>
#include <linux/backlight.h>
#include <linux/intel-iommu.h>
#include <linux/kref.h>

/* General customization:
*/
Expand Down Expand Up @@ -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 ier;
Expand Down Expand Up @@ -465,6 +467,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;
Expand Down Expand Up @@ -1163,6 +1166,8 @@ void i915_handle_error(struct drm_device *dev, bool wedged);

extern void intel_irq_init(struct drm_device *dev);

void i915_error_state_free(struct kref *error_ref);

void
i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);

Expand Down
12 changes: 7 additions & 5 deletions drivers/gpu/drm/i915/i915_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,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++) {
Expand Down Expand Up @@ -1102,6 +1103,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);

Expand Down Expand Up @@ -1173,7 +1175,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)
Expand All @@ -1188,7 +1190,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)
Expand Down

0 comments on commit 742cbee

Please sign in to comment.