Skip to contentSkip to conversation

drm/amdgpu: implement amdgpu_fill_buffer()

PATCH In review Flora Cui 2 participants 3 messages Jul 22, 2016 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Flora Cui

author
#0 lore raw

PATCH 1/2 drm/amdgpu: implement amdgpu_fill_buffer()

so that bo could be set to some pattern

Change-Id Iee7b7b28801e4c696b5d217a5d2ffc224dbe0cba
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  5 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 62 +++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +5 -0
index 459e136..a1c51f6 100644
@@ -432,6 +432,11 @@ int amdgpu_copy_buffer(struct amdgpu_ring *ring,
 		       uint32_t byte_count,
 		       struct reservation_object *resv,
 		       struct fence **fence);
+int amdgpu_fill_buffer(struct amdgpu_bo *bo,
+			uint32_t src_data,
+			struct reservation_object *resv,
+			struct fence **fence);
+
 int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
 
 struct amdgpu_bo_list_entry {
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +62 -0

68 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
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): 1469153428-2203-1-git-send-email-Flora.Cui-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH 2/2 drm/amdgpu: expose AMDGPU_GEM_CREATE_VRAM_CLEARED to user space

Change-Id I256178afa18c1a433fe60d8656d1c5cc5d55cf2f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 23 +++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h              |  2 ++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +23 -0
index 6f0873c..974fd26 100644
@@ -281,6 +281,29 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 
 	trace_amdgpu_bo_create(bo);
 
+	if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+	    bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
+		struct fence *fence;
+
+		/* make sure module init routine finishes since it requires gpu_scheduler */
+		if (!adev->accel_working) {
+			DRM_INFO("amdgpu: acceleration disabled, skipping clear op\n");
+			return 0;
+		}
+
+		r = amdgpu_bo_reserve(bo, false);
+		if (unlikely(r != 0)) {
+			DRM_INFO("amdgpu: reserve bo fail, skipping clear op\n");
+			return 0;
+		}
+		amdgpu_fill_buffer(bo, 0, bo->tbo.resv, &fence);
+		amdgpu_bo_fence(bo, fence, false);
+		amdgpu_bo_unreserve(bo);
+		fence_put(bo->tbo.moving);
+		bo->tbo.moving = fence_get(fence);
+		fence_put(fence);
+	}
+
 	return 0;
 }
 
include/uapi/drm/amdgpu_drm.h +2 -0
index 946f238..8df3816 100644
@@ -75,6 +75,8 @@
 #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS		(1 << 1)
 /* Flag that USWC attributes should be used for GTT */
 #define AMDGPU_GEM_CREATE_CPU_GTT_USWC		(1 << 2)
+/* Flag that the memory should be in VRAM and cleared */
+#define AMDGPU_GEM_CREATE_VRAM_CLEARED		(1 << 3)
 
 struct drm_amdgpu_gem_create_in  {
 	/** the requested memory size */
Signature · 6 lines
1.9.1

_______________________________________________
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): 1469153428-2203-2-git-send-email-Flora.Cui-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: expose AMDGPU_GEM_CREATE_VRAM_CLEARED to user space

Am 22.07.2016 um 04:10 schrieb Flora Cui:

Quoted 13 lines
Change-Id I256178afa18c1a433fe60d8656d1c5cc5d55cf2f
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 23 +++++++++++++++++++++++
  include/uapi/drm/amdgpu_drm.h              |  2 ++
  2 files changed, 25 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 6f0873c..974fd26 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct amdgpu_device *adev, · line 282

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
@@ -281,6 +281,29 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 
  	trace_amdgpu_bo_create(bo);

I would move the trace after the clear operation.

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct amdgpu_device *adev, · line 291

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +8 -0
+	if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+	    bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
+		struct fence *fence;
+
+		/* make sure module init routine finishes since it requires gpu_scheduler */
+		if (!adev->accel_working) {
+			DRM_INFO("amdgpu: acceleration disabled, skipping clear op\n");
+			return 0;

We should return -EBUSY here when that doesn't work instead of simply ignoring the request.

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct amdgpu_device *adev, · line 297

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
+		}
+
+		r = amdgpu_bo_reserve(bo, false);
+		if (unlikely(r != 0)) {
+			DRM_INFO("amdgpu: reserve bo fail, skipping clear op\n");
+			return 0;

Same here. When something goes wrong userspace should be signaled by this and not the functionality just dropped.

Userspace can still make the request without the flag if that is a critical code path.

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct amdgpu_device *adev, · line 297

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -0
+		}

As discussed with David, you need to validate the buffer here before call amdgpu_fill_buffer() to make sure that it is actually in GPU accessible memory.

Regards,
Christian.

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +8 -0
+		amdgpu_fill_buffer(bo, 0, bo->tbo.resv, &fence);
+		amdgpu_bo_fence(bo, fence, false);
+		amdgpu_bo_unreserve(bo);
+		fence_put(bo->tbo.moving);
+		bo->tbo.moving = fence_get(fence);
+		fence_put(fence);
+	}
+
  	return 0;
  }
 
include/uapi/drm/amdgpu_drm.h +0 -0
index 946f238..8df3816 100644

include/uapi/drm/amdgpu_drm.h line 82

Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +2 -0
@@ -75,6 +75,8 @@
  #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS		(1 << 1)
  /* Flag that USWC attributes should be used for GTT */
  #define AMDGPU_GEM_CREATE_CPU_GTT_USWC		(1 << 2)
+/* Flag that the memory should be in VRAM and cleared */
+#define AMDGPU_GEM_CREATE_VRAM_CLEARED		(1 << 3)
 
  struct drm_amdgpu_gem_create_in  {
  	/** the requested memory size */

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