SWDEV-197284 - drm/amdgpu: Only use the peek function in productor side is not correct
Subsystems (3)
PATCH 1/1 SWDEV-197284 - drm/amdgpu: Only use the peek function in productor side is not correct
For spsc queue, use peek function would cause error in productor side.
As for the last element, when the push job is occurring during pop job, the peek function will not be updated in time, and it will return NULL.
So use queue count for double confirming the job queue is empty.
--- drivers/gpu/drm/scheduler/sched_entity.c | 4 ++-- include/drm/spsc_queue.h | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +2 -2
@@ -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_peek (&entity->job_queue) ==NULL ) && !spsc_queue_count (&entity->job_queue)))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_peek (&entity->job_queue) ==NULL ) && !spsc_queue_count (&entity->job_queue)) {if (sched) {/* Park the kernel for a moment to make sure it isn't processing * our enity.
include/drm/spsc_queue.h +3 -4
@@ -54,9 +54,8 @@ static inline void spsc_queue_init(struct spsc_queue *queue)static inline struct spsc_node *spsc_queue_peek (struct spsc_queue *queue) { -return queue->head; +return READ_ONCE (queue->head); } -static inline int spsc_queue_count (struct spsc_queue *queue) {return atomic_read (&queue->job_count);
@@ -70,9 +69,9 @@ static inline bool spsc_queue_push(struct spsc_queue *queue, struct spsc_node *npreempt_disable (); +atomic_inc (&queue->job_count); tail = (struct spsc_node **)atomic_long_xchg (&queue->tail, (long )&node->next);WRITE_ONCE (*tail, node); -atomic_inc (&queue->job_count);/* * In case of first element verify new node will be visible to the consumer
@@ -93,6 +92,7 @@ static inline struct spsc_node *spsc_queue_pop(struct spsc_queue *queue)/* Verify reading from memory and not the cache */ smp_rmb (); +atomic_dec (&queue->job_count); node =READ_ONCE (queue->head);if (!node)
@@ -113,7 +113,6 @@ static inline struct spsc_node *spsc_queue_pop(struct spsc_queue *queue) } } -atomic_dec (&queue->job_count);return node; }
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1565595762-8141-1-git-send-email-Emily.Deng-5C7GfCeVMHo@public.gmane.org
Am 12.08.19 um 09:42 schrieb Emily Deng:
Quoted 5 lines
For spsc queue, use peek function would cause error in productor side.
As for the last element, when the push job is occurring during pop job, the peek function will not be updated in time, and it will return NULL.So use queue count for double confirming the job queue is empty.
For the upstream branch I'm going to push my patch which is not as invasive as this one.
Christian.
Quoted 64 lines
Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 4 ++-- include/drm/spsc_queue.h | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +2
-2@@ -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_peek (&entity->job_queue) ==NULL ) && !spsc_queue_count (&entity->job_queue)))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_peek (&entity->job_queue) ==NULL ) && !spsc_queue_count (&entity->job_queue)) {if (sched) {/* Park the kernel for a moment to make sure it isn't processing * our enity. include/drm/spsc_queue.h +3
-3@@ -54,9 +54,8 @@ static inline void spsc_queue_init(struct spsc_queue *queue)static inline struct spsc_node *spsc_queue_peek (struct spsc_queue *queue) { -return queue->head; +return READ_ONCE (queue->head); } -static inline int spsc_queue_count (struct spsc_queue *queue) {return atomic_read (&queue->job_count);@@ -70,9 +69,9 @@ static inline bool spsc_queue_push(struct spsc_queue *queue, struct spsc_node *npreempt_disable (); +atomic_inc (&queue->job_count); tail = (struct spsc_node **)atomic_long_xchg (&queue->tail, (long )&node->next);WRITE_ONCE (*tail, node); -atomic_inc (&queue->job_count);/* * In case of first element verify new node will be visible to the consumer @@ -93,6 +92,7 @@ static inline struct spsc_node *spsc_queue_pop(struct spsc_queue *queue)/* Verify reading from memory and not the cache */ smp_rmb (); +atomic_dec (&queue->job_count); node =READ_ONCE (queue->head);if (!node)
include/drm/spsc_queue.h static inline struct spsc_node *spsc_queue_pop(struct spsc_queue *queue) · line 118
Quoted 7 lines
include/drm/spsc_queue.h +0
-1@@ -113,7 +113,6 @@ static inline struct spsc_node *spsc_queue_pop(struct spsc_queue *queue) } } -atomic_dec (&queue->job_count);return node; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): d05d8b60-ab08-67ec-b57b-6de6b2e40d3e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Ok, please ignore this patch.
Best wishes
Emily Deng
Quoted 94 lines
-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, August 13, 2019 1:00 AM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] SWDEV-197284 - drm/amdgpu: Only use the peek function in productor side is not correctAm 12.08.19 um 09:42 schrieb Emily Deng:
Quoted 5 lines
For spsc queue, use peek function would cause error in productor side. As for the last element, when the push job is occurring during pop job, the peek function will not be updated in time, and it will return NULL.
So use queue count for double confirming the job queue is empty.
For the upstream branch I'm going to push my patch which is not as invasive as this one.
Christian.
drivers/gpu/drm/scheduler/sched_entity.c static bool drm_sched_entity_is_idle(struct
Quoted 13 lines
Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 4 ++-- include/drm/spsc_queue.h | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -95,7 +95,7 @@ static bool drm_sched_entity_is_idle(struct
drm_sched_entity*entity)drivers/gpu/drm/scheduler/sched_entity.c void drm_sched_entity_fini(struct drm_sched_entity
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_entity.c +2
-1rmb ();/* for list_empty to work without lock */ if (list_empty (&entity->list) || -spsc_queue_peek (&entity->job_queue) ==NULL ) + ((spsc_queue_peek (&entity->job_queue) ==NULL ) && +!spsc_queue_count (&entity->job_queue)))return true;return false;@@ -281,7 +281,7 @@ void drm_sched_entity_fini(struct drm_sched_entity*entity)
drivers/gpu/drm/scheduler/sched_entity.c void drm_sched_entity_fini(struct drm_sched_entity *entity)
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_entity.c +2
-1/* Consumption of existing IBs wasn't completed. Forcefully * remove them here. */ -if (spsc_queue_peek (&entity->job_queue)) { +if ((spsc_queue_peek (&entity->job_queue) ==NULL ) && +!spsc_queue_count (&entity->job_queue)) {if (sched) {/* Park the kernel for a moment to make sure it isn't processing
Quoted 22 lines
drivers/gpu/drm/scheduler/sched_entity.c +0
-0* our enity. include/drm/spsc_queue.h index renamed from include/drm/spsc_queue.h +0
-0125f096..78092b9 100644
include/drm/spsc_queue.h +1
-2@@ -54,9 +54,8 @@ static inline void spsc_queue_init(struct spsc_queue *queue)static inline struct spsc_node *spsc_queue_peek (struct spsc_queue *queue) { -return queue->head; +return READ_ONCE (queue->head); } -static inline int spsc_queue_count (struct spsc_queue *queue) {return
atomic_read(&queue->job_count); @@ -70,9 +69,9 @@ static
inline bool spsc_queue_push(structspsc_queue*queue, structspsc_node*npreempt_disable();include/drm/spsc_queue.h
Quoted 2 lines
include/drm/spsc_queue.h +1
-0+atomic_inc (&queue->job_count); tail = (struct spsc_node **)atomic_long_xchg(&queue->tail,(long)&node->next);
Quoted 6 lines
WRITE_ONCE(*tail, node);include/drm/spsc_queue.h +0
-1-atomic_inc (&queue->job_count);/* * In case of first element verify new node will be visible to the consumer @@ -93,6 +92,7 @@ static inline struct
spsc_node*spsc_queue_pop(struct
spsc_queue*queue)include/drm/spsc_queue.h static inline struct spsc_node
Quoted 8 lines
/* Verify reading from memory and not the cache */
smp_rmb();include/drm/spsc_queue.h +1
-0+atomic_dec (&queue->job_count); node =READ_ONCE (queue->head);if (!node)@@ -113,7 +113,6 @@ static inline struct spsc_node*spsc_queue_pop(struct
spsc_queue*queue)
Quoted 7 lines
include/drm/spsc_queue.h static inline struct spsc_node *spsc_queue_pop(struct spsc_queue *queue) · line 118
Quoted 7 lines
include/drm/spsc_queue.h +0
-1} } -atomic_dec (&queue->job_count);return node; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx