Skip to contentSkip to conversation

drm/amdkfd: Use the correct wptr size

PATCH In review Lijo Lazar 3 participants 7 messages Nov 18, 2024 – Nov 28, 2024

Subsystems (3)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH 1/1 drm/amdkfd: Use the correct wptr size

Write pointer could be 32-bit or 64-bit. Use the correct size during initialization.

---
 drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +1 -1
index 4843dcb9a5f7..d6037577c532 100644
@@ -125,7 +125,7 @@ static bool kq_initialize(struct kernel_queue *kq, struct kfd_node *dev,
 
 	memset(kq->pq_kernel_addr, 0, queue_size);
 	memset(kq->rptr_kernel, 0, sizeof(*kq->rptr_kernel));
-	memset(kq->wptr_kernel, 0, sizeof(*kq->wptr_kernel));
+	memset(kq->wptr_kernel, 0, dev->kfd->device_info.doorbell_size);
 
 	prop.queue_size = queue_size;
 	prop.is_interop = false;
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Lijo Lazar

Write pointer could be 32-bit or 64-bit. Use the correct size during initialization.

Quoted 20 lines
---
 drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +1 -2
index 4843dcb9a5f7..d6037577c532 100644
@@ -125,7 +125,7 @@ static bool kq_initialize(struct kernel_queue *kq, struct kfd_node *dev,
 
        memset(kq->pq_kernel_addr, 0, queue_size);
        memset(kq->rptr_kernel, 0, sizeof(*kq->rptr_kernel));
-       memset(kq->wptr_kernel, 0, sizeof(*kq->wptr_kernel));
+       memset(kq->wptr_kernel, 0, dev->kfd->device_info.doorbell_size);
 
        prop.queue_size = queue_size;
        prop.is_interop = false;
--

2.25.1

maintainer
#2 lore raw
In reply to Lijo Lazar
Quoted 13 lines · Lijo Lazar

Write pointer could be 32-bit or 64-bit. Use the correct size during initialization.

---
  drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0
index 4843dcb9a5f7..d6037577c532 100644

drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c static bool kq_initialize(struct kernel_queue *kq, struct kfd_node *dev, · line 128

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +1 -1
@@ -125,7 +125,7 @@ static bool kq_initialize(struct kernel_queue *kq, struct kfd_node *dev,
 
  	memset(kq->pq_kernel_addr, 0, queue_size);
  	memset(kq->rptr_kernel, 0, sizeof(*kq->rptr_kernel));
-	memset(kq->wptr_kernel, 0, sizeof(*kq->wptr_kernel));
+	memset(kq->wptr_kernel, 0, dev->kfd->device_info.doorbell_size);

It would be safer and cleaner to just initialize kq->wptr64_kernel, which is always 64 bit and aliases kq->wptr_kernel.

Regards,
  Felix

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0
  	prop.queue_size = queue_size;
  	prop.is_interop = false;
#3 lore raw
Quoted 10 lines · Felix Kuehling
Quoted 8 lines · Lijo Lazar

Write pointer could be 32-bit or 64-bit. Use the correct size during initialization.

---
  drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c static bool kq_initialize(struct kernel_queue *kq, · line 128

Quoted 11 lines
drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0

gpu/drm/amd/amdkfd/kfd_kernel_queue.c
index 4843dcb9a5f7..d6037577c532 100644

drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +1 -1
@@ -125,7 +125,7 @@ static bool kq_initialize(struct kernel_queue *kq,
 struct kfd_node *dev,
         memset(kq->pq_kernel_addr, 0, queue_size);
       memset(kq->rptr_kernel, 0, sizeof(*kq->rptr_kernel));
-    memset(kq->wptr_kernel, 0, sizeof(*kq->wptr_kernel));
+    memset(kq->wptr_kernel, 0, dev->kfd->device_info.doorbell_size);

It would be safer and cleaner to just initialize kq->wptr64_kernel, which is always 64 bit and aliases kq->wptr_kernel.

It's done this way because of aliasing. The size requested is doorbell_size which could be 4 or 8 bytes.

By safer, do you mean to have an if..else check in case the aliasing is taken out?

Thanks,
Lijo

Quoted 7 lines

Regards,
  Felix

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0
         prop.queue_size = queue_size;
       prop.is_interop = false;
maintainer
#4 lore raw
Quoted 29 lines · Lijo
Quoted 10 lines · Felix Kuehling
Quoted 8 lines · Lijo Lazar

Write pointer could be 32-bit or 64-bit. Use the correct size during initialization.

---
  drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c static bool kq_initialize(struct kernel_queue *kq, · line 128

Quoted 11 lines
drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0

gpu/drm/amd/amdkfd/kfd_kernel_queue.c
index 4843dcb9a5f7..d6037577c532 100644

drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +1 -1
@@ -125,7 +125,7 @@ static bool kq_initialize(struct kernel_queue *kq,
 struct kfd_node *dev,
         memset(kq->pq_kernel_addr, 0, queue_size);
       memset(kq->rptr_kernel, 0, sizeof(*kq->rptr_kernel));
-    memset(kq->wptr_kernel, 0, sizeof(*kq->wptr_kernel));
+    memset(kq->wptr_kernel, 0, dev->kfd->device_info.doorbell_size);

It would be safer and cleaner to just initialize kq->wptr64_kernel, which is always 64 bit and aliases kq->wptr_kernel.

Quoted 5 lines

It's done this way because of aliasing. The size requested is doorbell_size which could be 4 or 8 bytes.

By safer, do you mean to have an if..else check in case the aliasing is taken out?

Cleaner because the size of the memset would match the size of the variable. And safer because it clears the entire wptr, regardless of the doorbell size.

That said, it doesn't really matter because the whole kq structure is allocated with kzalloc just before calling kq_initialize. So maybe we should just remove all those redundant memset(kq->field, 0, size) calls.

Regards,
Felix

Quoted 12 lines

Thanks,
Lijo

Quoted 7 lines

Regards,
  Felix

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0
         prop.queue_size = queue_size;
       prop.is_interop = false;
#5 lore raw
Quoted 35 lines · Felix Kuehling
Quoted 32 lines · Lijo
Quoted 10 lines · Felix Kuehling
Quoted 8 lines · Lijo Lazar

Write pointer could be 32-bit or 64-bit. Use the correct size during initialization.

---
  drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c static bool kq_initialize(struct kernel_queue *kq, · line 128

Quoted 11 lines
drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0

gpu/drm/amd/amdkfd/kfd_kernel_queue.c
index 4843dcb9a5f7..d6037577c532 100644

drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +1 -1
@@ -125,7 +125,7 @@ static bool kq_initialize(struct kernel_queue *kq,
 struct kfd_node *dev,
         memset(kq->pq_kernel_addr, 0, queue_size);
       memset(kq->rptr_kernel, 0, sizeof(*kq->rptr_kernel));
-    memset(kq->wptr_kernel, 0, sizeof(*kq->wptr_kernel));
+    memset(kq->wptr_kernel, 0, dev->kfd->device_info.doorbell_size);

It would be safer and cleaner to just initialize kq->wptr64_kernel, which is always 64 bit and aliases kq->wptr_kernel.

It's done this way because of aliasing. The size requested is doorbell_size which could be 4 or 8 bytes.

Quoted 7 lines
Quoted 2 lines

By safer, do you mean to have an if..else check in case the aliasing is taken out?

Cleaner because the size of the memset would match the size of the variable. And safer because it clears the entire wptr, regardless of the doorbell size.

That said, it doesn't really matter because the whole kq structure is allocated with kzalloc just before calling kq_initialize. So maybe we should just remove all those redundant memset(kq->field, 0, size) calls.

This is not related to kzalloc of kq structure. This is actually initializing write pointer value to 0.

The sequence is -
Allocate memory for write pointer (kfd_gtt_sa_allocate) Assign kq wptr to the allocated pointer
Set wptr to 0 (Initial write pointer value).

The last step should actually be based on 4 byte or 8byte, this patch is for that. If gtt_sa_allocate is already getting a cleared memory, then this can be skipped as well.

Thanks,
Lijo

Quoted 16 lines

Regards,
Felix

Quoted 12 lines

Thanks,
Lijo

Quoted 7 lines

Regards,
  Felix

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0
         prop.queue_size = queue_size;
       prop.is_interop = false;
maintainer Reviewed-by
#6 lore raw
Quoted 49 lines · Lijo
Quoted 35 lines · Felix Kuehling
Quoted 32 lines · Lijo
Quoted 10 lines · Felix Kuehling
Quoted 8 lines · Lijo Lazar

Write pointer could be 32-bit or 64-bit. Use the correct size during initialization.

---
  drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c static bool kq_initialize(struct kernel_queue *kq, · line 128

Quoted 11 lines
drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0

gpu/drm/amd/amdkfd/kfd_kernel_queue.c
index 4843dcb9a5f7..d6037577c532 100644

drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +1 -1
@@ -125,7 +125,7 @@ static bool kq_initialize(struct kernel_queue *kq,
 struct kfd_node *dev,
         memset(kq->pq_kernel_addr, 0, queue_size);
       memset(kq->rptr_kernel, 0, sizeof(*kq->rptr_kernel));
-    memset(kq->wptr_kernel, 0, sizeof(*kq->wptr_kernel));
+    memset(kq->wptr_kernel, 0, dev->kfd->device_info.doorbell_size);

It would be safer and cleaner to just initialize kq->wptr64_kernel, which is always 64 bit and aliases kq->wptr_kernel.

It's done this way because of aliasing. The size requested is doorbell_size which could be 4 or 8 bytes.

Quoted 7 lines
Quoted 2 lines

By safer, do you mean to have an if..else check in case the aliasing is taken out?

Cleaner because the size of the memset would match the size of the variable. And safer because it clears the entire wptr, regardless of the doorbell size.

That said, it doesn't really matter because the whole kq structure is allocated with kzalloc just before calling kq_initialize. So maybe we should just remove all those redundant memset(kq->field, 0, size) calls.

This is not related to kzalloc of kq structure. This is actually initializing write pointer value to 0.

Quoted 8 lines

The sequence is -
Allocate memory for write pointer (kfd_gtt_sa_allocate) Assign kq wptr to the allocated pointer
Set wptr to 0 (Initial write pointer value).

The last step should actually be based on 4 byte or 8byte, this patch is for that. If gtt_sa_allocate is already getting a cleared memory, then this can be skipped as well.

OK, sorry, I was reading that wrong. You're right. kfd_gtt_sa_allocate does not clear memory. And clearing it with the same size as the allocation is the right thing to do. The patch is

Quoted 21 lines

Thanks,
Lijo

Quoted 16 lines

Regards,
Felix

Quoted 12 lines

Thanks,
Lijo

Quoted 7 lines

Regards,
  Felix

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -0
         prop.queue_size = queue_size;
       prop.is_interop = false;