drm/i915: protect force_wake_(get|put) with the gt_lock
Subsystems (2)
PATCH 1/4 drm/i915: protect force_wake_(get|put) with the gt_lock
The problem this patch solves is that the forcewake accounting necessary for register reads is protected by dev->struct_mutex. But the hangcheck and error_capture code need to access registers without grabbing this mutex because we hold it while waiting for the gpu. So a new lock is required. Because currently the error_state capture is called from the error irq handler and the hangcheck code runs from a timer, it needs to be an irqsafe spinlock (note that the registers used by the irq handler (neglecting the error handling part) only uses registers that don't need the forcewake dance).
We could tune this down to a normal spinlock when we rework the error_state capture and hangcheck code to run from a workqueue. But we don't have any read in a fastpath that needs forcewake, so I've decided to not care much about overhead.
This prevents tests/gem_hangcheck_forcewake from i-g-t from killing my snb on recent kernels - something must have slightly changed the timings. On previous kernels it only trigger a WARN about the broken locking.
v2: Drop the previous patch for the register writes.
v3: Improve the commit message per Chris Wilson's suggestions.
--- drivers/gpu/drm/i915/i915_debugfs.c | 8 ++++++-- drivers/gpu/drm/i915/i915_dma.c | 1 + drivers/gpu/drm/i915/i915_drv.c | 18 ++++++++++++------ drivers/gpu/drm/i915/i915_drv.h | 10 +++++++--- 4 files changed, 26 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +6 -2
@@ -1321,9 +1321,13 @@ static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)struct drm_info_node *node = (struct drm_info_node *) m->private;struct drm_device *dev = node->minor->dev;struct drm_i915_private *dev_priv = dev->dev_private; +unsigned forcewake_count; -seq_printf (m,"forcewake count = %d\n" , -atomic_read (&dev_priv->forcewake_count)); +spin_lock_irq (&dev_priv->gt_lock); + forcewake_count = dev_priv->forcewake_count; +spin_unlock_irq (&dev_priv->gt_lock); + +seq_printf (m,"forcewake count = %u\n" , forcewake_count);return 0 ; }
drivers/gpu/drm/i915/i915_dma.c +1 -0
@@ -2032,6 +2032,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)if (!IS_I945G (dev) && !IS_I945GM (dev))pci_enable_msi (dev->pdev); +spin_lock_init (&dev_priv->gt_lock);spin_lock_init (&dev_priv->irq_lock);spin_lock_init (&dev_priv->error_lock);spin_lock_init (&dev_priv->rps_lock);
drivers/gpu/drm/i915/i915_drv.c +12 -6
@@ -368,11 +368,12 @@ void __gen6_gt_force_wake_mt_get(struct drm_i915_private *dev_priv)*/ void gen6_gt_force_wake_get (struct drm_i915_private *dev_priv) { -WARN_ON (!mutex_is_locked (&dev_priv->dev->struct_mutex)); +unsigned long irqflags; -/* Forcewake is atomic in case we get in here without the lock */ -if (atomic_add_return (1 , &dev_priv->forcewake_count) ==1 ) +spin_lock_irqsave (&dev_priv->gt_lock, irqflags); +if (dev_priv->forcewake_count++ ==0 ) dev_priv->display.force_wake_get (dev_priv); +spin_unlock_irqrestore (&dev_priv->gt_lock, irqflags); }void __gen6_gt_force_wake_put (struct drm_i915_private *dev_priv)
@@ -392,10 +393,12 @@ void __gen6_gt_force_wake_mt_put(struct drm_i915_private *dev_priv)*/ void gen6_gt_force_wake_put (struct drm_i915_private *dev_priv) { -WARN_ON (!mutex_is_locked (&dev_priv->dev->struct_mutex)); +unsigned long irqflags; -if (atomic_dec_and_test (&dev_priv->forcewake_count)) +spin_lock_irqsave (&dev_priv->gt_lock, irqflags); +if (--dev_priv->forcewake_count ==0 ) dev_priv->display.force_wake_put (dev_priv); +spin_unlock_irqrestore (&dev_priv->gt_lock, irqflags); }void __gen6_gt_wait_for_fifo (struct drm_i915_private *dev_priv)
@@ -626,6 +629,7 @@ int i915_reset(struct drm_device *dev, u8 flags)* need to */ bool need_display = true; +unsigned long irqflags;int ret;if (!i915_try_reset)
@@ -644,8 +648,10 @@ int i915_reset(struct drm_device *dev, u8 flags)case 6 : ret =gen6_do_reset (dev, flags);/* If reset with a user forcewake, try to restore */ -if (atomic_read (&dev_priv->forcewake_count)) +spin_lock_irqsave (&dev_priv->gt_lock, irqflags); +if (dev_priv->forcewake_count)__gen6_gt_force_wake_get (dev_priv); +spin_unlock_irqrestore (&dev_priv->gt_lock, irqflags);break ;case 5 : ret =ironlake_do_reset (dev, flags);
drivers/gpu/drm/i915/i915_drv.h +7 -3
@@ -279,7 +279,13 @@ typedef struct drm_i915_private {int relative_constants_mode;void __iomem *regs; -u32 gt_fifo_count; +/** gt_fifo_count and the subsequent register write are synchronized +* with dev->struct_mutex. */ +unsigned gt_fifo_count; +/** forcewake_count is protected by gt_lock */ +unsigned forcewake_count; +/** gt_lock is also taken in irq contexts. */ +struct spinlock gt_lock;struct intel_gmbus {struct i2c_adapter adapter;
@@ -730,8 +736,6 @@ typedef struct drm_i915_private {struct drm_property *broadcast_rgb_property;struct drm_property *force_audio_property; - -atomic_t forcewake_count; } drm_i915_private_t;enum i915_cache_level {
Signature · 1 line
1.7.7.3
PATCH 2/4 drm/i915: convert force_wake_get to func pointer in the gpu reset code
This was forgotten in the original multi-threaded forcewake conversion:
commit 8d715f0024f64ad1b1be85d8c081cf577944c847
Author: Keith Packard <[email protected]> Date: Fri Nov 18 20:39:01 2011 -0800
drm/i915: add multi-threaded forcewake support
--- drivers/gpu/drm/i915/i915_drv.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +1 -1
@@ -650,7 +650,7 @@ int i915_reset(struct drm_device *dev, u8 flags)/* If reset with a user forcewake, try to restore */ spin_lock_irqsave (&dev_priv->gt_lock, irqflags);if (dev_priv->forcewake_count) -__gen6_gt_force_wake_get (dev_priv); + dev_priv->display.force_wake_get (dev_priv);spin_unlock_irqrestore (&dev_priv->gt_lock, irqflags);break ;case 5 :
Signature · 1 line
1.7.7.3
PATCH 3/4 drm/i915: drop register special-casing in forcewake
In reply to Daniel VetterWe currently have 3 register for which we must not grab forcewake for:
FORCEWAKE, FROCEWAKE_MT and ECOBUS.
- FROCEWAKE is excluded in the NEEDS_FORCE_WAKE macro and accessed with _NOTRACE.
- FROCEWAKE_MT is just accessed with _NOTRACE.
- ECOBUS is only excluded in the macro.
In fear of an ever-growing list of special cases and to cut down the confusion, just access all of them with the _NOTRACE variants.
Also kill the duplicate definition of the macro, which is unused.
--- drivers/gpu/drm/i915/i915_drv.c | 4 +--- drivers/gpu/drm/i915/i915_drv.h | 7 ------- drivers/gpu/drm/i915/intel_display.c | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +1 -3
@@ -931,9 +931,7 @@ MODULE_LICENSE("GPL and additional rights");/* We give fast paths for the really cool registers */ #define NEEDS_FORCE_WAKE (dev_priv, reg) \ (((dev_priv)->info->gen >= 6) && \ - ((reg) < 0x40000) && \ - ((reg) != FORCEWAKE) && \ - ((reg) != ECOBUS)) + ((reg) < 0x40000)) \#define __i915_read (x, y) \ u##x i915_read##x(struct drm_i915_private *dev_priv, u32 reg) { \
drivers/gpu/drm/i915/i915_drv.h +0 -7
@@ -1356,13 +1356,6 @@ void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv);void gen6_gt_force_wake_put (struct drm_i915_private *dev_priv);void __gen6_gt_wait_for_fifo (struct drm_i915_private *dev_priv); -/* We give fast paths for the really cool registers */ -#define NEEDS_FORCE_WAKE (dev_priv, reg) \ - (((dev_priv)->info->gen >= 6) && \ - ((reg) < 0x40000) && \ - ((reg) != FORCEWAKE) && \ - ((reg) != ECOBUS)) -#define __i915_read (x, y) \ u##x i915_read##x(struct drm_i915_private *dev_priv, u32 reg);
drivers/gpu/drm/i915/intel_display.c +1 -1
@@ -8500,7 +8500,7 @@ static void intel_init_display(struct drm_device *dev)mutex_lock (&dev->struct_mutex);__gen6_gt_force_wake_mt_get (dev_priv); - ecobus =I915_READ (ECOBUS ); + ecobus =I915_READ_NOTRACE (ECOBUS );__gen6_gt_force_wake_mt_put (dev_priv);mutex_unlock (&dev->struct_mutex);
Signature · 1 line
1.7.7.3
Re: [PATCH 3/4] drm/i915: drop register special-casing in forcewake
Quoted 6 lines · Daniel Vetter
We currently have 3 register for which we must not grab forcewake for:
FORCEWAKE,FROCEWAKE_MTand ECOBUS.
- FROCEWAKE is excluded in theNEEDS_FORCE_WAKEmacro and accessed with_NOTRACE.
-FROCEWAKE_MTis just accessed with_NOTRACE.
s/FROCEWAKE/FORCEWAKE/g :)
Besides this,
for the series.
Signature · 2 lines
Eugeni Dodonov <http://eugeni.dodonov.net/>
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/4 drm/i915: introduce a vtable for gpu core functions
In reply to Daniel Vetter... like for forcewake, which protects everything _but_ display. Expect more things (like gtt abstractions, rings, inter-ring sync) to come.
--- drivers/gpu/drm/i915/i915_drv.c | 6 +++--- drivers/gpu/drm/i915/i915_drv.h | 8 ++++++-- drivers/gpu/drm/i915/intel_display.c | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +3 -3
@@ -372,7 +372,7 @@ void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)spin_lock_irqsave (&dev_priv->gt_lock, irqflags);if (dev_priv->forcewake_count++ ==0 ) - dev_priv->display.force_wake_get (dev_priv); + dev_priv->core.force_wake_get (dev_priv);spin_unlock_irqrestore (&dev_priv->gt_lock, irqflags); }
@@ -397,7 +397,7 @@ void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)spin_lock_irqsave (&dev_priv->gt_lock, irqflags);if (--dev_priv->forcewake_count ==0 ) - dev_priv->display.force_wake_put (dev_priv); + dev_priv->core.force_wake_put (dev_priv);spin_unlock_irqrestore (&dev_priv->gt_lock, irqflags); }
@@ -650,7 +650,7 @@ int i915_reset(struct drm_device *dev, u8 flags)/* If reset with a user forcewake, try to restore */ spin_lock_irqsave (&dev_priv->gt_lock, irqflags);if (dev_priv->forcewake_count) - dev_priv->display.force_wake_get (dev_priv); + dev_priv->core.force_wake_get (dev_priv);spin_unlock_irqrestore (&dev_priv->gt_lock, irqflags);break ;case 5 :
drivers/gpu/drm/i915/i915_drv.h +6 -2
@@ -215,8 +215,6 @@ struct drm_i915_display_funcs { struct drm_i915_gem_object *obj);int (*update_plane)(struct drm_crtc *crtc,struct drm_framebuffer *fb,int x,int y); -void (*force_wake_get)(struct drm_i915_private *dev_priv); -void (*force_wake_put)(struct drm_i915_private *dev_priv);/* clock updates for mode set */ /* cursor updates */ /* render clock increase/decrease */
@@ -224,6 +222,11 @@ struct drm_i915_display_funcs {/* pll clock increase/decrease */ }; +struct drm_i915_core_funcs { +void (*force_wake_get)(struct drm_i915_private *dev_priv); +void (*force_wake_put)(struct drm_i915_private *dev_priv); +}; +struct intel_device_info {u8 gen;u8 is_mobile:1 ;
@@ -296,6 +299,7 @@ typedef struct drm_i915_private {struct pci_dev *bridge_dev;struct intel_ring_buffer ring[I915_NUM_RINGS ];uint32_t next_seqno; +struct drm_i915_core_funcs core;drm_dma_handle_t *status_page_dmah;uint32_t counter;
drivers/gpu/drm/i915/intel_display.c +4 -4
@@ -8491,8 +8491,8 @@ static void intel_init_display(struct drm_device *dev)/* For FIFO watermark updates */ if (HAS_PCH_SPLIT (dev)) { - dev_priv->display.force_wake_get = __gen6_gt_force_wake_get; - dev_priv->display.force_wake_put = __gen6_gt_force_wake_put; + dev_priv->core.force_wake_get = __gen6_gt_force_wake_get; + dev_priv->core.force_wake_put = __gen6_gt_force_wake_put;/* IVB configs may use multi-threaded forcewake */ if (IS_IVYBRIDGE (dev)) {
@@ -8506,9 +8506,9 @@ static void intel_init_display(struct drm_device *dev)if (ecobus &FORCEWAKE_MT_ENABLE ) {DRM_DEBUG_KMS ("Using MT version of forcewake\n" ); - dev_priv->display.force_wake_get = + dev_priv->core.force_wake_get = __gen6_gt_force_wake_mt_get; - dev_priv->display.force_wake_put = + dev_priv->core.force_wake_put = __gen6_gt_force_wake_mt_put; } }
Signature · 1 line
1.7.7.3
PATCH 1/1 drm/i915: multithreaded forcewake is an ivb+ feature
In reply to Daniel VetterName the function accordingly. Suggested by Chris Wilson.
--- drivers/gpu/drm/i915/i915_drv.c | 4 ++-- drivers/gpu/drm/i915/i915_drv.h | 4 ++-- drivers/gpu/drm/i915/intel_display.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -2
@@ -344,7 +344,7 @@ void __gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)udelay (10 ); } -void __gen6_gt_force_wake_mt_get (struct drm_i915_private *dev_priv) +void __gen7_gt_force_wake_mt_get (struct drm_i915_private *dev_priv) {int count;
@@ -382,7 +382,7 @@ void __gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)POSTING_READ (FORCEWAKE ); } -void __gen6_gt_force_wake_mt_put (struct drm_i915_private *dev_priv) +void __gen7_gt_force_wake_mt_put (struct drm_i915_private *dev_priv) {I915_WRITE_NOTRACE (FORCEWAKE_MT , (1 <<16 ) |0 );POSTING_READ (FORCEWAKE_MT );
drivers/gpu/drm/i915/i915_drv.h +2 -2
@@ -1342,9 +1342,9 @@ extern void intel_detect_pch(struct drm_device *dev);extern int intel_trans_dp_port_sel (struct drm_crtc *crtc);extern void __gen6_gt_force_wake_get (struct drm_i915_private *dev_priv); -extern void __gen6_gt_force_wake_mt_get (struct drm_i915_private *dev_priv); +extern void __gen7_gt_force_wake_mt_get (struct drm_i915_private *dev_priv);extern void __gen6_gt_force_wake_put (struct drm_i915_private *dev_priv); -extern void __gen6_gt_force_wake_mt_put (struct drm_i915_private *dev_priv); +extern void __gen7_gt_force_wake_mt_put (struct drm_i915_private *dev_priv);/* overlay */ #ifdef CONFIG_DEBUG_FS
drivers/gpu/drm/i915/intel_display.c +4 -4
@@ -8507,17 +8507,17 @@ static void intel_init_display(struct drm_device *dev)u32 ecobus;mutex_lock (&dev->struct_mutex); -__gen6_gt_force_wake_mt_get (dev_priv); +__gen7_gt_force_wake_mt_get (dev_priv); ecobus =I915_READ_NOTRACE (ECOBUS ); -__gen6_gt_force_wake_mt_put (dev_priv); +__gen7_gt_force_wake_mt_put (dev_priv);mutex_unlock (&dev->struct_mutex);if (ecobus &FORCEWAKE_MT_ENABLE ) {DRM_DEBUG_KMS ("Using MT version of forcewake\n" ); dev_priv->core.force_wake_get = - __gen6_gt_force_wake_mt_get; + __gen7_gt_force_wake_mt_get; dev_priv->core.force_wake_put = - __gen6_gt_force_wake_mt_put; + __gen7_gt_force_wake_mt_put; } }
Signature · 1 line
1.7.7.3
Re: [PATCH] drm/i915: multithreaded forcewake is an ivb+ feature
Quoted 4 lines · Daniel Vetter
Name the function accordingly. Suggested by Chris Wilson.
Signed-off-by Daniel Vetter <[email protected]>
Such patches are so hard to review. The only ones harder than those are the white space-related ones :).
Signature · 2 lines
Eugeni Dodonov <http://eugeni.dodonov.net/>
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx