* [Intel-xe] [PATCH] drm/i915: handle uncore spinlock when not available
@ 2023-10-18 12:45 Luca Coelho
2023-10-19 14:28 ` Rodrigo Vivi
0 siblings, 1 reply; 3+ messages in thread
From: Luca Coelho @ 2023-10-18 12:45 UTC (permalink / raw)
To: intel-xe; +Cc: rodrigo.vivi
The uncore code may not always be available (e.g. when we build the
display code with Xe), so we can't always rely on having the uncore's
spinlock.
To handle this, split the spin_lock/unlock_irqsave/restore() into
spin_lock/unlock() followed by a call to local_irq_save/restore() and
create wrapper functions for locking and unlocking the uncore's
spinlock. In these functions, we have a condition check and only
actually try to lock/unlock the spinlock when I915 is defined, and
thus uncore is available.
This keeps the ifdefs contained in these new functions and all such
logic inside the display code.
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
---
drivers/gpu/drm/i915/display/intel_display.h | 20 ++++++++++++++++++++
drivers/gpu/drm/i915/display/intel_vblank.c | 18 +++++++++++-------
2 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/i915/display/intel_display.h b/drivers/gpu/drm/i915/display/intel_display.h
index 0e5dffe8f018..07acf5d414f6 100644
--- a/drivers/gpu/drm/i915/display/intel_display.h
+++ b/drivers/gpu/drm/i915/display/intel_display.h
@@ -559,4 +559,24 @@ bool assert_port_valid(struct drm_i915_private *i915, enum port port);
bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915);
+/*
+ * The uncore version of the spin lock functions is used to decide
+ * whether we need to lock the uncore lock or not. This is only
+ * needed in i915, not in Xe. Keep the decision-making centralized
+ * here.
+ */
+static inline void uncore_spin_lock(spinlock_t *lock)
+{
+#ifdef I915
+ spin_lock(lock);
+#endif
+}
+
+static inline void uncore_spin_unlock(spinlock_t *lock)
+{
+#ifdef I915
+ spin_unlock(lock);
+#endif
+}
+
#endif
diff --git a/drivers/gpu/drm/i915/display/intel_vblank.c b/drivers/gpu/drm/i915/display/intel_vblank.c
index 2cec2abf9746..0e8b71063353 100644
--- a/drivers/gpu/drm/i915/display/intel_vblank.c
+++ b/drivers/gpu/drm/i915/display/intel_vblank.c
@@ -306,7 +306,8 @@ static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
* register reads, potentially with preemption disabled, so the
* following code must not block on uncore.lock.
*/
- spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
+ uncore_spin_lock(&dev_priv->uncore.lock);
+ local_irq_save(irqflags);
/* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
@@ -374,7 +375,8 @@ static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
/* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
- spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
+ uncore_spin_unlock(&dev_priv->uncore.lock);
+ local_irq_restore(irqflags);
/*
* While in vblank, position will be negative
@@ -412,9 +414,12 @@ int intel_get_crtc_scanline(struct intel_crtc *crtc)
unsigned long irqflags;
int position;
- spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
+ uncore_spin_lock(&dev_priv->uncore.lock);
+ local_irq_save(irqflags);
position = __intel_get_crtc_scanline(crtc);
- spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
+ local_irq_restore(irqflags);
+
+ uncore_spin_unlock(&dev_priv->uncore.lock);
return position;
}
@@ -537,7 +542,7 @@ void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state,
* Need to audit everything to make sure it's safe.
*/
spin_lock_irqsave(&i915->drm.vblank_time_lock, irqflags);
- spin_lock(&i915->uncore.lock);
+ uncore_spin_lock(&i915->uncore.lock);
drm_calc_timestamping_constants(&crtc->base, &adjusted_mode);
@@ -546,7 +551,6 @@ void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state,
crtc->mode_flags = mode_flags;
crtc->scanline_offset = intel_crtc_scanline_offset(crtc_state);
-
- spin_unlock(&i915->uncore.lock);
+ uncore_spin_unlock(&i915->uncore.lock);
spin_unlock_irqrestore(&i915->drm.vblank_time_lock, irqflags);
}
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [Intel-xe] [PATCH] drm/i915: handle uncore spinlock when not available
2023-10-18 12:45 [Intel-xe] [PATCH] drm/i915: handle uncore spinlock when not available Luca Coelho
@ 2023-10-19 14:28 ` Rodrigo Vivi
2023-10-23 8:04 ` Luca Coelho
0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo Vivi @ 2023-10-19 14:28 UTC (permalink / raw)
To: Luca Coelho; +Cc: intel-xe
On Wed, Oct 18, 2023 at 03:45:00PM +0300, Luca Coelho wrote:
> The uncore code may not always be available (e.g. when we build the
> display code with Xe), so we can't always rely on having the uncore's
> spinlock.
>
> To handle this, split the spin_lock/unlock_irqsave/restore() into
> spin_lock/unlock() followed by a call to local_irq_save/restore() and
> create wrapper functions for locking and unlocking the uncore's
> spinlock. In these functions, we have a condition check and only
> actually try to lock/unlock the spinlock when I915 is defined, and
> thus uncore is available.
>
> This keeps the ifdefs contained in these new functions and all such
> logic inside the display code.
>
> Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> ---
> drivers/gpu/drm/i915/display/intel_display.h | 20 ++++++++++++++++++++
> drivers/gpu/drm/i915/display/intel_vblank.c | 18 +++++++++++-------
> 2 files changed, 31 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_display.h b/drivers/gpu/drm/i915/display/intel_display.h
> index 0e5dffe8f018..07acf5d414f6 100644
> --- a/drivers/gpu/drm/i915/display/intel_display.h
> +++ b/drivers/gpu/drm/i915/display/intel_display.h
> @@ -559,4 +559,24 @@ bool assert_port_valid(struct drm_i915_private *i915, enum port port);
>
> bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915);
>
> +/*
> + * The uncore version of the spin lock functions is used to decide
> + * whether we need to lock the uncore lock or not. This is only
> + * needed in i915, not in Xe. Keep the decision-making centralized
> + * here.
> + */
> +static inline void uncore_spin_lock(spinlock_t *lock)
> +{
> +#ifdef I915
> + spin_lock(lock);
> +#endif
okay, I understand that your goal here is not to fix xe in case the
flow is totally broken there because of the lack of the locks to
serialize the display here. Nor also remove this serialization in
i915, if not needed. And that's the safest option I agree.
I just wonder if we could do in some more generic way like avoiding
the term 'uncore' and using 'dev_priv' as argument instead of the
lock directly. But not hard feelings...
> +}
> +
> +static inline void uncore_spin_unlock(spinlock_t *lock)
> +{
> +#ifdef I915
> + spin_unlock(lock);
> +#endif
> +}
> +
> #endif
> diff --git a/drivers/gpu/drm/i915/display/intel_vblank.c b/drivers/gpu/drm/i915/display/intel_vblank.c
> index 2cec2abf9746..0e8b71063353 100644
> --- a/drivers/gpu/drm/i915/display/intel_vblank.c
> +++ b/drivers/gpu/drm/i915/display/intel_vblank.c
> @@ -306,7 +306,8 @@ static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
> * register reads, potentially with preemption disabled, so the
> * following code must not block on uncore.lock.
> */
> - spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
> + uncore_spin_lock(&dev_priv->uncore.lock);
> + local_irq_save(irqflags);
shouldn't we save before lock or restore before unlock?
or to be on the safe side also create other helpers for these?
>
> /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
>
> @@ -374,7 +375,8 @@ static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
>
> /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
>
> - spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
> + uncore_spin_unlock(&dev_priv->uncore.lock);
> + local_irq_restore(irqflags);
>
> /*
> * While in vblank, position will be negative
> @@ -412,9 +414,12 @@ int intel_get_crtc_scanline(struct intel_crtc *crtc)
> unsigned long irqflags;
> int position;
>
> - spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
> + uncore_spin_lock(&dev_priv->uncore.lock);
> + local_irq_save(irqflags);
> position = __intel_get_crtc_scanline(crtc);
> - spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
> + local_irq_restore(irqflags);
> +
> + uncore_spin_unlock(&dev_priv->uncore.lock);
>
> return position;
> }
> @@ -537,7 +542,7 @@ void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state,
> * Need to audit everything to make sure it's safe.
> */
> spin_lock_irqsave(&i915->drm.vblank_time_lock, irqflags);
> - spin_lock(&i915->uncore.lock);
> + uncore_spin_lock(&i915->uncore.lock);
>
> drm_calc_timestamping_constants(&crtc->base, &adjusted_mode);
>
> @@ -546,7 +551,6 @@ void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state,
> crtc->mode_flags = mode_flags;
>
> crtc->scanline_offset = intel_crtc_scanline_offset(crtc_state);
> -
> - spin_unlock(&i915->uncore.lock);
> + uncore_spin_unlock(&i915->uncore.lock);
> spin_unlock_irqrestore(&i915->drm.vblank_time_lock, irqflags);
> }
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [Intel-xe] [PATCH] drm/i915: handle uncore spinlock when not available
2023-10-19 14:28 ` Rodrigo Vivi
@ 2023-10-23 8:04 ` Luca Coelho
0 siblings, 0 replies; 3+ messages in thread
From: Luca Coelho @ 2023-10-23 8:04 UTC (permalink / raw)
To: Rodrigo Vivi; +Cc: intel-xe
On Thu, 2023-10-19 at 10:28 -0400, Rodrigo Vivi wrote:
> On Wed, Oct 18, 2023 at 03:45:00PM +0300, Luca Coelho wrote:
> > The uncore code may not always be available (e.g. when we build the
> > display code with Xe), so we can't always rely on having the uncore's
> > spinlock.
> >
> > To handle this, split the spin_lock/unlock_irqsave/restore() into
> > spin_lock/unlock() followed by a call to local_irq_save/restore() and
> > create wrapper functions for locking and unlocking the uncore's
> > spinlock. In these functions, we have a condition check and only
> > actually try to lock/unlock the spinlock when I915 is defined, and
> > thus uncore is available.
> >
> > This keeps the ifdefs contained in these new functions and all such
> > logic inside the display code.
> >
> > Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> > ---
> > drivers/gpu/drm/i915/display/intel_display.h | 20 ++++++++++++++++++++
> > drivers/gpu/drm/i915/display/intel_vblank.c | 18 +++++++++++-------
> > 2 files changed, 31 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_display.h b/drivers/gpu/drm/i915/display/intel_display.h
> > index 0e5dffe8f018..07acf5d414f6 100644
> > --- a/drivers/gpu/drm/i915/display/intel_display.h
> > +++ b/drivers/gpu/drm/i915/display/intel_display.h
> > @@ -559,4 +559,24 @@ bool assert_port_valid(struct drm_i915_private *i915, enum port port);
> >
> > bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915);
> >
> > +/*
> > + * The uncore version of the spin lock functions is used to decide
> > + * whether we need to lock the uncore lock or not. This is only
> > + * needed in i915, not in Xe. Keep the decision-making centralized
> > + * here.
> > + */
> > +static inline void uncore_spin_lock(spinlock_t *lock)
> > +{
> > +#ifdef I915
> > + spin_lock(lock);
> > +#endif
>
> okay, I understand that your goal here is not to fix xe in case the
> flow is totally broken there because of the lack of the locks to
> serialize the display here. Nor also remove this serialization in
> i915, if not needed. And that's the safest option I agree.
>
> I just wonder if we could do in some more generic way like avoiding
> the term 'uncore' and using 'dev_priv' as argument instead of the
> lock directly. But not hard feelings...
Makes sense. I'll change it.
> > +}
> > +
> > +static inline void uncore_spin_unlock(spinlock_t *lock)
> > +{
> > +#ifdef I915
> > + spin_unlock(lock);
> > +#endif
> > +}
> > +
> > #endif
> > diff --git a/drivers/gpu/drm/i915/display/intel_vblank.c b/drivers/gpu/drm/i915/display/intel_vblank.c
> > index 2cec2abf9746..0e8b71063353 100644
> > --- a/drivers/gpu/drm/i915/display/intel_vblank.c
> > +++ b/drivers/gpu/drm/i915/display/intel_vblank.c
> > @@ -306,7 +306,8 @@ static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
> > * register reads, potentially with preemption disabled, so the
> > * following code must not block on uncore.lock.
> > */
> > - spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
> > + uncore_spin_lock(&dev_priv->uncore.lock);
> > + local_irq_save(irqflags);
>
> shouldn't we save before lock or restore before unlock?
> or to be on the safe side also create other helpers for these?
Oh, nice catch. I did go into spin_lock_irqsave() to check the order,
but for some reason didn't do it right here. This is the correct
order:
irq_save->lock->unlock->irq_restore
I'll fix it.
Thanks for the review! I accidentally sent this to intel-xe again,
though my intention was to send it to intel-gfx. I'll send v2 to both.
--
Cheers,
Luca.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-23 8:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-18 12:45 [Intel-xe] [PATCH] drm/i915: handle uncore spinlock when not available Luca Coelho
2023-10-19 14:28 ` Rodrigo Vivi
2023-10-23 8:04 ` Luca Coelho
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox