dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Don't disable interrupts independently of the lock
@ 2019-04-10 14:24 Sebastian Andrzej Siewior
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-04-10 14:24 UTC (permalink / raw)
  To: dri-devel
  Cc: David Airlie, intel-gfx, Steven Rostedt, tglx, Sebastian Andrzej Siewior

The locks (timeline->lock and rq->lock) need to be taken with disabled
interrupts. This is done in __retire_engine_request() by disabling the
interrupts independently of the locks itself.
While local_irq_disable()+spin_lock() equals spin_lock_irq() on vanilla
it does not on RT. Also, it is not obvious if there is a special reason
to why the interrupts are disabled independently of the lock.

Enable/disable interrupts as part of the locking instruction.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/gpu/drm/i915/i915_request.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c
index ca95ab2f4cfa3..8744d20ac1681 100644
--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -278,9 +278,7 @@ static void __retire_engine_request(struct intel_engine_cs *engine,
 
 	GEM_BUG_ON(!i915_request_completed(rq));
 
-	local_irq_disable();
-
-	spin_lock(&engine->timeline.lock);
+	spin_lock_irq(&engine->timeline.lock);
 	GEM_BUG_ON(!list_is_first(&rq->link, &engine->timeline.requests));
 	list_del_init(&rq->link);
 	spin_unlock(&engine->timeline.lock);
@@ -294,9 +292,7 @@ static void __retire_engine_request(struct intel_engine_cs *engine,
 		GEM_BUG_ON(!atomic_read(&rq->i915->gt_pm.rps.num_waiters));
 		atomic_dec(&rq->i915->gt_pm.rps.num_waiters);
 	}
-	spin_unlock(&rq->lock);
-
-	local_irq_enable();
+	spin_unlock_irq(&rq->lock);
 
 	/*
 	 * The backing object for the context is done after switching to the
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915: Don't disable interrupts independently of the lock
  2019-10-10 20:30     ` [Intel-gfx] " Chris Wilson
@ 2019-10-14 16:10       ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-10-14 16:10 UTC (permalink / raw)
  To: Chris Wilson; +Cc: David Airlie, intel-gfx, tglx, dri-devel

On 2019-10-10 21:30:35 [+0100], Chris Wilson wrote:
> > |         spin_lock_irq(&rq->engine->active.lock);
> > |         list_del(&rq->sched.link);
> > |         spin_unlock_irq(&rq->engine->active.lock);
> > | 
> > |         spin_lock_irq(&rq->lock);
> > |         i915_request_mark_complete(rq);
> > …
> > |         spin_unlock_irq(&rq->lock);
> > 
> > has been avoided because an interrupt here could change something or if
> > this is just an optimisation.
> 
> Just avoiding the back-to-back enable/disable.

as I assumed. Is the patch okay?

> -Chris

Sebastian
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915: Don't disable interrupts independently of the lock
  2019-10-10 18:11 ` [Intel-gfx] " Chris Wilson
@ 2019-10-10 18:26   ` Sebastian Andrzej Siewior
  2019-10-10 20:30     ` [Intel-gfx] " Chris Wilson
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-10-10 18:26 UTC (permalink / raw)
  To: Chris Wilson; +Cc: David Airlie, intel-gfx, tglx, dri-devel

On 2019-10-10 19:11:27 [+0100], Chris Wilson wrote:
> > --- a/drivers/gpu/drm/i915/i915_request.c
> > +++ b/drivers/gpu/drm/i915/i915_request.c
> > @@ -251,15 +251,13 @@ static bool i915_request_retire(struct i
> >                 active->retire(active, rq);
> >         }
> >  
> > -       local_irq_disable();
> > -
> >         /*
> >          * We only loosely track inflight requests across preemption,
> >          * and so we may find ourselves attempting to retire a _completed_
> >          * request that we have removed from the HW and put back on a run
> >          * queue.
> >          */
> > -       spin_lock(&rq->engine->active.lock);
> > +       spin_lock_irq(&rq->engine->active.lock);
> >         list_del(&rq->sched.link);
> >         spin_unlock(&rq->engine->active.lock);
> >  
> > @@ -278,9 +276,7 @@ static bool i915_request_retire(struct i
> >                 __notify_execute_cb(rq);
> >         }
> >         GEM_BUG_ON(!list_empty(&rq->execute_cb));
> > -       spin_unlock(&rq->lock);
> > -
> > -       local_irq_enable();
> > +       spin_unlock_irq(&rq->lock);
> 
> Nothing screams about the imbalance? irq off from one lock to the other?

There is no imbalance, is there? Interrupts are disabled as part of
acquiring the first lock and enabled again as part of releasing the
second lock.
It may not look beautiful. 

I'm just not sure if this

|         spin_lock_irq(&rq->engine->active.lock);
|         list_del(&rq->sched.link);
|         spin_unlock_irq(&rq->engine->active.lock);
| 
|         spin_lock_irq(&rq->lock);
|         i915_request_mark_complete(rq);
…
|         spin_unlock_irq(&rq->lock);

has been avoided because an interrupt here could change something or if
this is just an optimisation.

> -Chris

Sebastian
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] drm/i915: Don't disable interrupts independently of the lock
@ 2019-10-10 16:06 Sebastian Andrzej Siewior
  2019-10-10 18:11 ` [Intel-gfx] " Chris Wilson
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-10-10 16:06 UTC (permalink / raw)
  To: dri-devel, intel-gfx; +Cc: David Airlie, Sebastian Andrzej Siewior, tglx

The locks (active.lock and rq->lock) need to be taken with disabled
interrupts. This is done in i915_request_retire() by disabling the
interrupts independently of the locks itself.
While local_irq_disable()+spin_lock() equals spin_lock_irq() on vanilla
it does not on PREEMPT_RT. Also, it is not obvious if there is a special reason
to why the interrupts are disabled independently of the lock.

Enable/disable interrupts as part of the locking instruction.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/gpu/drm/i915/i915_request.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -251,15 +251,13 @@ static bool i915_request_retire(struct i
 		active->retire(active, rq);
 	}
 
-	local_irq_disable();
-
 	/*
 	 * We only loosely track inflight requests across preemption,
 	 * and so we may find ourselves attempting to retire a _completed_
 	 * request that we have removed from the HW and put back on a run
 	 * queue.
 	 */
-	spin_lock(&rq->engine->active.lock);
+	spin_lock_irq(&rq->engine->active.lock);
 	list_del(&rq->sched.link);
 	spin_unlock(&rq->engine->active.lock);
 
@@ -278,9 +276,7 @@ static bool i915_request_retire(struct i
 		__notify_execute_cb(rq);
 	}
 	GEM_BUG_ON(!list_empty(&rq->execute_cb));
-	spin_unlock(&rq->lock);
-
-	local_irq_enable();
+	spin_unlock_irq(&rq->lock);
 
 	remove_from_client(rq);
 	list_del(&rq->link);
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-14 16:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-10 14:24 [PATCH] drm/i915: Don't disable interrupts independently of the lock Sebastian Andrzej Siewior
2019-10-10 16:06 Sebastian Andrzej Siewior
2019-10-10 18:11 ` [Intel-gfx] " Chris Wilson
2019-10-10 18:26   ` Sebastian Andrzej Siewior
2019-10-10 20:30     ` [Intel-gfx] " Chris Wilson
2019-10-14 16:10       ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).