Skip to contentSkip to conversation

drm/scheduler: use job count instead of peek

PATCH In review Christian König 3 participants 3 messages Aug 9, 2019 – Aug 13, 2019

Subsystems (3)
lore
Share & tools
lore

Christian König

author reviewer
#0 lore raw

PATCH 1/1 drm/scheduler: use job count instead of peek

The spsc_queue_peek function is accessing queue->head which belongs to the consumer thread and shouldn't be accessed by the producer

This is fixing a rare race condition when destroying entities.

---
 drivers/gpu/drm/scheduler/sched_entity.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +2 -2
index 35ddbec1375a..671c90f34ede 100644
@@ -95,7 +95,7 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity)
 	rmb(); /* for list_empty to work without lock */
 
 	if (list_empty(&entity->list) ||
-	    spsc_queue_peek(&entity->job_queue) == NULL)
+	    spsc_queue_count(&entity->job_queue) == 0)
 		return true;
 
 	return false;
@@ -281,7 +281,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity)
 	/* Consumption of existing IBs wasn't completed. Forcefully
 	 * remove them here.
 	 */
-	if (spsc_queue_peek(&entity->job_queue)) {
+	if (spsc_queue_count(&entity->job_queue)) {
 		if (sched) {
 			/* Park the kernel for a moment to make sure it isn't processing
 			 * our enity.
Signature · 6 lines
2.17.1

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

Andrey

Quoted 24 lines · Christian König

The spsc_queue_peek function is accessing queue->head which belongs to the consumer thread and shouldn't be accessed by the producer

This is fixing a rare race condition when destroying entities.

---
  drivers/gpu/drm/scheduler/sched_entity.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +1 -1
index 35ddbec1375a..671c90f34ede 100644
@@ -95,7 +95,7 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity)
  	rmb(); /* for list_empty to work without lock */
 
  	if (list_empty(&entity->list) ||
-	    spsc_queue_peek(&entity->job_queue) == NULL)
+	    spsc_queue_count(&entity->job_queue) == 0)
  		return true;
 
  	return false;

drivers/gpu/drm/scheduler/sched_entity.c void drm_sched_entity_fini(struct drm_sched_entity *entity) · line 287

Quoted 8 lines
drivers/gpu/drm/scheduler/sched_entity.c +1 -1
@@ -281,7 +281,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity)
  	/* Consumption of existing IBs wasn't completed. Forcefully
  	 * remove them here.
  	 */
-	if (spsc_queue_peek(&entity->job_queue)) {
+	if (spsc_queue_count(&entity->job_queue)) {
  		if (sched) {
  			/* Park the kernel for a moment to make sure it isn't processing
  			 * our enity.

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

Reviewed-by on v1 1/1
#2 lore raw
In reply to Christian König
Reviewed-by [email protected]

_____________________________________
Monk Liu|GPU Virtualization Team |AMD

-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, August 9, 2019 11:31 PM
To: Grodzovsky, Andrey <[email protected]>; [email protected]; Liu, Monk <[email protected]>; Deng, Emily <[email protected]>
Subject: [PATCH] drm/scheduler: use job count instead of peek

The spsc_queue_peek function is accessing queue->head which belongs to the consumer thread and shouldn't be accessed by the producer

This is fixing a rare race condition when destroying entities.

---
 drivers/gpu/drm/scheduler/sched_entity.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +2 -2
index 35ddbec1375a..671c90f34ede 100644
@@ -95,7 +95,7 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity)
 	rmb(); /* for list_empty to work without lock */
 
 	if (list_empty(&entity->list) ||
-	    spsc_queue_peek(&entity->job_queue) == NULL)
+	    spsc_queue_count(&entity->job_queue) == 0)
 		return true;
 
 	return false;
@@ -281,7 +281,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity)
 	/* Consumption of existing IBs wasn't completed. Forcefully
 	 * remove them here.
 	 */
-	if (spsc_queue_peek(&entity->job_queue)) {
+	if (spsc_queue_count(&entity->job_queue)) {
 		if (sched) {
 			/* Park the kernel for a moment to make sure it isn't processing
 			 * our enity.

--
2.17.1

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