Skip to contentSkip to conversation

drm/amdgpu: stop trying to schedule() with a spin held

PATCH In review Christian König 4 participants 7 messages Jun 13, 2016 – Jun 14, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: stop trying to schedule() with a spin held

From: Christian König <[email protected]>

Drop the lock before calling cancel_delayed_work_sync().

---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +2 -0
index 74aa0b3..b1d49c5 100644
@@ -339,7 +339,9 @@ static void amd_sched_job_finish(struct work_struct *work)
 	if (sched->timeout != MAX_SCHEDULE_TIMEOUT) {
 		struct amd_sched_job *next;
 
+		spin_unlock_irqrestore(&sched->job_list_lock, flags);
 		cancel_delayed_work_sync(&s_job->work_tdr);
+		spin_lock_irqsave(&sched->job_list_lock, flags);
 
 		/* queue TDR for next job */
 		next = list_first_entry_or_null(&sched->ring_mirror_list,
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/2 drm/amdgpu: stop disabling irqs when it isn't neccessary

From: Christian König <[email protected]>

A regular spin_lock/unlock should do here as well.

---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +6 -8
index b1d49c5..e13b140 100644
@@ -331,17 +331,16 @@ static void amd_sched_job_finish(struct work_struct *work)
 	struct amd_sched_job *s_job = container_of(work, struct amd_sched_job,
 						   finish_work);
 	struct amd_gpu_scheduler *sched = s_job->sched;
-	unsigned long flags;
 
 	/* remove job from ring_mirror_list */
-	spin_lock_irqsave(&sched->job_list_lock, flags);
+	spin_lock(&sched->job_list_lock);
 	list_del_init(&s_job->node);
 	if (sched->timeout != MAX_SCHEDULE_TIMEOUT) {
 		struct amd_sched_job *next;
 
-		spin_unlock_irqrestore(&sched->job_list_lock, flags);
+		spin_unlock(&sched->job_list_lock);
 		cancel_delayed_work_sync(&s_job->work_tdr);
-		spin_lock_irqsave(&sched->job_list_lock, flags);
+		spin_lock(&sched->job_list_lock);
 
 		/* queue TDR for next job */
 		next = list_first_entry_or_null(&sched->ring_mirror_list,
@@ -350,7 +349,7 @@ static void amd_sched_job_finish(struct work_struct *work)
 		if (next)
 			schedule_delayed_work(&next->work_tdr, sched->timeout);
 	}
-	spin_unlock_irqrestore(&sched->job_list_lock, flags);
+	spin_unlock(&sched->job_list_lock);
 	sched->ops->free_job(s_job);
 }
 
@@ -364,15 +363,14 @@ static void amd_sched_job_finish_cb(struct fence *f, struct fence_cb *cb)
 static void amd_sched_job_begin(struct amd_sched_job *s_job)
 {
 	struct amd_gpu_scheduler *sched = s_job->sched;
-	unsigned long flags;
 
-	spin_lock_irqsave(&sched->job_list_lock, flags);
+	spin_lock(&sched->job_list_lock);
 	list_add_tail(&s_job->node, &sched->ring_mirror_list);
 	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
 	    list_first_entry_or_null(&sched->ring_mirror_list,
 				     struct amd_sched_job, node) == s_job)
 		schedule_delayed_work(&s_job->work_tdr, sched->timeout);
-	spin_unlock_irqrestore(&sched->job_list_lock, flags);
+	spin_unlock(&sched->job_list_lock);
 }
 
 static void amd_sched_job_timedout(struct work_struct *work)
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: stop disabling irqs when it isn't neccessary

Quoted 5 lines · Christian König

From: Christian König <[email protected]>

A regular spin_lock/unlock should do here as well.

Just drive-by comment, but you can't mix up irq spinlocks with normal ones. And there's places where this is still irqsave, but some of these functions can be called directly from the scheduler kthread. You can only drop the _irqsave if you know you're always called from hardirq context (softirq isn't enough), or when you know someone already disabled interrupts. And you can simplify the _irqsave to just _irq when you are in always in process context and irqs are always still enabled.

On a super-quick look seems fishy.
-Daniel

Quoted 63 lines
---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +6 -8
index b1d49c5..e13b140 100644
@@ -331,17 +331,16 @@ static void amd_sched_job_finish(struct work_struct *work)
 	struct amd_sched_job *s_job = container_of(work, struct amd_sched_job,
 						   finish_work);
 	struct amd_gpu_scheduler *sched = s_job->sched;
-	unsigned long flags;
 
 	/* remove job from ring_mirror_list */
-	spin_lock_irqsave(&sched->job_list_lock, flags);
+	spin_lock(&sched->job_list_lock);
 	list_del_init(&s_job->node);
 	if (sched->timeout != MAX_SCHEDULE_TIMEOUT) {
 		struct amd_sched_job *next;
 
-		spin_unlock_irqrestore(&sched->job_list_lock, flags);
+		spin_unlock(&sched->job_list_lock);
 		cancel_delayed_work_sync(&s_job->work_tdr);
-		spin_lock_irqsave(&sched->job_list_lock, flags);
+		spin_lock(&sched->job_list_lock);
 
 		/* queue TDR for next job */
 		next = list_first_entry_or_null(&sched->ring_mirror_list,
@@ -350,7 +349,7 @@ static void amd_sched_job_finish(struct work_struct *work)
 		if (next)
 			schedule_delayed_work(&next->work_tdr, sched->timeout);
 	}
-	spin_unlock_irqrestore(&sched->job_list_lock, flags);
+	spin_unlock(&sched->job_list_lock);
 	sched->ops->free_job(s_job);
 }
 
@@ -364,15 +363,14 @@ static void amd_sched_job_finish_cb(struct fence *f, struct fence_cb *cb)
 static void amd_sched_job_begin(struct amd_sched_job *s_job)
 {
 	struct amd_gpu_scheduler *sched = s_job->sched;
-	unsigned long flags;
 
-	spin_lock_irqsave(&sched->job_list_lock, flags);
+	spin_lock(&sched->job_list_lock);
 	list_add_tail(&s_job->node, &sched->ring_mirror_list);
 	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
 	    list_first_entry_or_null(&sched->ring_mirror_list,
 				     struct amd_sched_job, node) == s_job)
 		schedule_delayed_work(&s_job->work_tdr, sched->timeout);
-	spin_unlock_irqrestore(&sched->job_list_lock, flags);
+	spin_unlock(&sched->job_list_lock);
 }
 
 static void amd_sched_job_timedout(struct work_struct *work)
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

Re: [PATCH 2/2] drm/amdgpu: stop disabling irqs when it isn't neccessary

Am 13.06.2016 um 18:33 schrieb Daniel Vetter:

Quoted 14 lines · Christian König
Quoted 5 lines

From: Christian König <[email protected]>

A regular spin_lock/unlock should do here as well.

Just drive-by comment, but you can't mix up irq spinlocks with normal ones. And there's places where this is still irqsave, but some of these functions can be called directly from the scheduler kthread. You can only drop the _irqsave if you know you're always called from hardirq context (softirq isn't enough), or when you know someone already disabled interrupts. And you can simplify the _irqsave to just _irq when you are in always in process context and irqs are always still enabled.

Quoted 1 line

On a super-quick look seems fishy.

The point is there isn't even any IRQ involved in all of this.

The spin is either locked from a work item or the kthread, never from irq context.

Christian.

Quoted 57 lines

-Daniel

Quoted 55 lines
---
  drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 14 ++++++--------
  1 file changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +6 -8
index b1d49c5..e13b140 100644
@@ -331,17 +331,16 @@ static void amd_sched_job_finish(struct work_struct *work)
  	struct amd_sched_job *s_job = container_of(work, struct amd_sched_job,
  						   finish_work);
  	struct amd_gpu_scheduler *sched = s_job->sched;
-	unsigned long flags;
 
  	/* remove job from ring_mirror_list */
-	spin_lock_irqsave(&sched->job_list_lock, flags);
+	spin_lock(&sched->job_list_lock);
  	list_del_init(&s_job->node);
  	if (sched->timeout != MAX_SCHEDULE_TIMEOUT) {
  		struct amd_sched_job *next;
 
-		spin_unlock_irqrestore(&sched->job_list_lock, flags);
+		spin_unlock(&sched->job_list_lock);
  		cancel_delayed_work_sync(&s_job->work_tdr);
-		spin_lock_irqsave(&sched->job_list_lock, flags);
+		spin_lock(&sched->job_list_lock);
 
  		/* queue TDR for next job */
  		next = list_first_entry_or_null(&sched->ring_mirror_list,
@@ -350,7 +349,7 @@ static void amd_sched_job_finish(struct work_struct *work)
  		if (next)
  			schedule_delayed_work(&next->work_tdr, sched->timeout);
  	}
-	spin_unlock_irqrestore(&sched->job_list_lock, flags);
+	spin_unlock(&sched->job_list_lock);
  	sched->ops->free_job(s_job);
  }
 
@@ -364,15 +363,14 @@ static void amd_sched_job_finish_cb(struct fence *f, struct fence_cb *cb)
  static void amd_sched_job_begin(struct amd_sched_job *s_job)
  {
  	struct amd_gpu_scheduler *sched = s_job->sched;
-	unsigned long flags;
 
-	spin_lock_irqsave(&sched->job_list_lock, flags);
+	spin_lock(&sched->job_list_lock);
  	list_add_tail(&s_job->node, &sched->ring_mirror_list);
  	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
  	    list_first_entry_or_null(&sched->ring_mirror_list,
  				     struct amd_sched_job, node) == s_job)
  		schedule_delayed_work(&s_job->work_tdr, sched->timeout);
-	spin_unlock_irqrestore(&sched->job_list_lock, flags);
+	spin_unlock(&sched->job_list_lock);
  }
 
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +0 -0
  static void amd_sched_job_timedout(struct work_struct *work)
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: stop disabling irqs when it isn't neccessary

Quoted 18 lines · Christian König

Am 13.06.2016 um 18:33 schrieb Daniel Vetter:

Quoted 17 lines · Christian König
Quoted 6 lines

From: Christian König <[email protected]>

A regular spin_lock/unlock should do here as well.

Just drive-by comment, but you can't mix up irq spinlocks with normal ones. And there's places where this is still irqsave, but some of these functions can be called directly from the scheduler kthread. You can only drop the _irqsave if you know you're always called from hardirq context (softirq isn't enough), or when you know someone already disabled interrupts. And you can simplify the _irqsave to just _irq when you are in always in process context and irqs are always still enabled.

Quoted 7 lines
Quoted 1 line

On a super-quick look seems fishy.

The point is there isn't even any IRQ involved in all of this.

The spin is either locked from a work item or the kthread, never from irq context.

In that case git grep job_list_lock finds more of those in sched_fence.c. -Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
In reply to Christian König
Quoted 6 lines · Christian König

From: Christian König <[email protected]>

Drop the lock before calling cancel_delayed_work_sync().

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=96445

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by
#6 lore raw
Quoted 9 lines · Michel Dänzer
Quoted 6 lines · Christian König

From: Christian König <[email protected]>

Drop the lock before calling cancel_delayed_work_sync().

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=96445

Applied with the bugzilla entry added.

Thanks,

Alex

Quoted 5 lines

--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel