Skip to contentSkip to conversation

drm/amdgpu: install ctx entities with cmpxchg

PATCH In review Christian König 3 participants 4 messages Feb 23, 2022

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

PATCH 1/1 drm/amdgpu: install ctx entities with cmpxchg

Since we removed the context lock we need to make sure that not two threads are trying to install an entity at the same time.

Fixes e68efb27647f ("drm/amdgpu: remove ctx->lock")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +7 -1
index f522b52725e4..16eb1ee600ed 100644
@@ -204,9 +204,15 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
 	if (r)
 		goto error_free_entity;
 
-	ctx->entities[hw_ip][ring] = entity;
+	/* It's not an error if we fail to install the new entity */
+	if (cmpxchg(&ctx->entities[hw_ip][ring], NULL, entity))
+		goto cleanup_entity;
+
 	return 0;
 
+cleanup_entity:
+	drm_sched_entity_fini(&entity->entity);
+
 error_free_entity:
 	kfree(entity);
 
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw

[Public]

________________________________
From: amd-gfx <[email protected]> on behalf of Christian König <[email protected]>
Sent: Wednesday, February 23, 2022 8:38 AM
To: [email protected] <[email protected]>
Cc: Koenig, Christian <[email protected]>; Xue, Ken <[email protected]>
Subject: [PATCH] drm/amdgpu: install ctx entities with cmpxchg

Since we removed the context lock we need to make sure that not two threads are trying to install an entity at the same time.

Fixes e68efb27647f ("drm/amdgpu: remove ctx->lock")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +7 -1
index f522b52725e4..16eb1ee600ed 100644
@@ -204,9 +204,15 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
         if (r)
                 goto error_free_entity;
 
-       ctx->entities[hw_ip][ring] = entity;
+       /* It's not an error if we fail to install the new entity */
+       if (cmpxchg(&ctx->entities[hw_ip][ring], NULL, entity))
+               goto cleanup_entity;
+
         return 0;
 
+cleanup_entity:
+       drm_sched_entity_fini(&entity->entity);
+
 error_free_entity:
         kfree(entity);
 

--
2.25.1

Acked-by Alex Deucher
#2 lore raw

[Public]

Shall we add a print to aware user when failing to install a new ctx entity?

Regards,
Guchun

From: amd-gfx <[email protected]> On Behalf Of Deucher, Alexander
Sent: Wednesday, February 23, 2022 11:06 PM
To: Christian König <[email protected]>; [email protected]
Cc: Koenig, Christian <[email protected]>; Xue, Ken <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: install ctx entities with cmpxchg

[Public]

[Public]

________________________________
From: amd-gfx <[email protected]<mailto:[email protected]>> on behalf of Christian König <[email protected]<mailto:[email protected]>>
Sent: Wednesday, February 23, 2022 8:38 AM
To: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Cc: Koenig, Christian <[email protected]<mailto:[email protected]>>; Xue, Ken <[email protected]<mailto:[email protected]>>
Subject: [PATCH] drm/amdgpu: install ctx entities with cmpxchg

Since we removed the context lock we need to make sure that not two threads are trying to install an entity at the same time.

Fixes e68efb27647f ("drm/amdgpu: remove ctx->lock")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +7 -1
index f522b52725e4..16eb1ee600ed 100644
@@ -204,9 +204,15 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
         if (r)
                 goto error_free_entity;
 
-       ctx->entities[hw_ip][ring] = entity;
+       /* It's not an error if we fail to install the new entity */
+       if (cmpxchg(&ctx->entities[hw_ip][ring], NULL, entity))
+               goto cleanup_entity;
+
         return 0;
 
+cleanup_entity:
+       drm_sched_entity_fini(&entity->entity);
+
 error_free_entity:
         kfree(entity);
 

--
2.25.1

#3 lore raw

No, as I wrote in the comment that is not an error and should just be ignored.

Regards,
Christian.

Am 23.02.22 um 16:18 schrieb Chen, Guchun:

Quoted 64 lines

[Public]

Shall we add a print to aware user when failing to install a new ctx entity?

Regards,

Guchun

*From:* amd-gfx <[email protected]> *On Behalf Of *Deucher, Alexander *Sent:* Wednesday, February 23, 2022 11:06 PM
*To:* Christian König <[email protected]>; [email protected] *Cc:* Koenig, Christian <[email protected]>; Xue, Ken <[email protected]> *Subject:* Re: [PATCH] drm/amdgpu: install ctx entities with cmpxchg

[Public]

[Public]

------------------------------------------------------------------------

*From:*amd-gfx <[email protected]> on behalf of Christian König <[email protected]> *Sent:* Wednesday, February 23, 2022 8:38 AM
*To:* [email protected] <[email protected]>
*Cc:* Koenig, Christian <[email protected]>; Xue, Ken <[email protected]>
*Subject:* [PATCH] drm/amdgpu: install ctx entities with cmpxchg

Since we removed the context lock we need to make sure that not two threads are trying to install an entity at the same time.

Fixes e68efb27647f ("drm/amdgpu: remove ctx->lock")

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 +++++++-

 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +7 -1
index f522b52725e4..16eb1ee600ed 100644
@@ -204,9 +204,15 @@ static int amdgpu_ctx_init_entity(struct 
 amdgpu_ctx *ctx, u32 hw_ip,
          if (r)
                  goto error_free_entity;
 
-       ctx->entities[hw_ip][ring] = entity;
+       /* It's not an error if we fail to install the new entity */
+       if (cmpxchg(&ctx->entities[hw_ip][ring], NULL, entity))
+               goto cleanup_entity;
+
          return 0;
 
+cleanup_entity:
+ drm_sched_entity_fini(&entity->entity);
+

 error_free_entity:
         kfree(entity);

Signature · 1 line
2.25.1