Skip to contentSkip to conversation

drm/amdgpu: Pin to gtt before cpu accesses dma buf.

PATCH In review Samuel Li 3 participants 8 messages Nov 29, 2017 7 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Samuel Li

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Pin to gtt before cpu accesses dma buf.

To improve cpu read performance. This is implemented for APUs currently.

Change-Id: I300a7daed8f2b0ba6be71a43196a6b8617ddc62e

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h               |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c           |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c         | 108 ++++++++++++++++++++++
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   8 +-
 5 files changed, 126 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index f8657c3..193db70 100644
@@ -417,6 +417,8 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
 struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
 					struct drm_gem_object *gobj,
 					int flags);
+struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
+					    struct dma_buf *dma_buf);
 int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
 void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
 struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +8 -2
index d704a45..b5483e4 100644
@@ -147,6 +147,7 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct amdgpu_device *adev = dev->dev_private;
 	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev->flags & AMD_IS_APU);
 	struct amdgpu_framebuffer *old_amdgpu_fb;
 	struct amdgpu_framebuffer *new_amdgpu_fb;
 	struct drm_gem_object *obj;
@@ -190,8 +191,13 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,
 
 	r = amdgpu_bo_pin(new_abo, AMDGPU_GEM_DOMAIN_VRAM, &base);
 	if (unlikely(r != 0)) {
-		DRM_ERROR("failed to pin new abo buffer before flip\n");
-		goto unreserve;
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(new_abo, AMDGPU_GEM_DOMAIN_GTT, &base);
+		if (unlikely(r != 0)) {
+			DRM_ERROR("failed to pin new abo buffer before flip\n");
+			goto unreserve;
+		}
 	}
 
 	r = reservation_object_get_fences_rcu(new_abo->tbo.resv, &work->excl,
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
index 31383e0..df30b08 100644
@@ -868,7 +868,7 @@ static struct drm_driver kms_driver = {
 	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
 	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
 	.gem_prime_export = amdgpu_gem_prime_export,
-	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_import = amdgpu_gem_prime_import,
 	.gem_prime_pin = amdgpu_gem_prime_pin,
 	.gem_prime_unpin = amdgpu_gem_prime_unpin,
 	.gem_prime_res_obj = amdgpu_gem_prime_res_obj,
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +108 -0

119 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +7 -1
index a3bf021..f25b830 100644
@@ -2987,6 +2987,8 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
 	int r;
 	struct dm_plane_state *dm_plane_state_new, *dm_plane_state_old;
 	unsigned int awidth;
+	struct amdgpu_device *adev = plane->dev->dev_private;
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev->flags & AMD_IS_APU);
 
 	dm_plane_state_old = to_dm_plane_state(plane->state);
 	dm_plane_state_new = to_dm_plane_state(new_state);
@@ -3005,7 +3007,11 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
 		return r;
 
 	r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM, &afb->address);
-
+	if (unlikely(r != 0)) {
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_GTT, &afb->address);
+	}
 
 	amdgpu_bo_unreserve(rbo);
 
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): 1511914846-25292-1-git-send-email-Samuel.Li-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Am 29.11.2017 um 01:20 schrieb Samuel Li:

Quoted 1 line

To improve cpu read performance. This is implemented for APUs currently.

And once more a NAK for this approach.

What we could do is migrate the BO to GTT during mmap, but pinning it is out of question.

Regards,
Christian.

Quoted 205 lines

Change-Id: I300a7daed8f2b0ba6be71a43196a6b8617ddc62e

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h               |   2 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       |  10 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c           |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c         | 108 ++++++++++++++++++++++
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   8 +-
  5 files changed, 126 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index f8657c3..193db70 100644
@@ -417,6 +417,8 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
  struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
  					struct drm_gem_object *gobj,
  					int flags);
+struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
+					    struct dma_buf *dma_buf);
  int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
  void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
  struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +8 -2
index d704a45..b5483e4 100644
@@ -147,6 +147,7 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,
  	struct drm_device *dev = crtc->dev;
  	struct amdgpu_device *adev = dev->dev_private;
  	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev->flags & AMD_IS_APU);
  	struct amdgpu_framebuffer *old_amdgpu_fb;
  	struct amdgpu_framebuffer *new_amdgpu_fb;
  	struct drm_gem_object *obj;
@@ -190,8 +191,13 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,
 
  	r = amdgpu_bo_pin(new_abo, AMDGPU_GEM_DOMAIN_VRAM, &base);
  	if (unlikely(r != 0)) {
-		DRM_ERROR("failed to pin new abo buffer before flip\n");
-		goto unreserve;
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(new_abo, AMDGPU_GEM_DOMAIN_GTT, &base);
+		if (unlikely(r != 0)) {
+			DRM_ERROR("failed to pin new abo buffer before flip\n");
+			goto unreserve;
+		}
  	}
 
  	r = reservation_object_get_fences_rcu(new_abo->tbo.resv, &work->excl,
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
index 31383e0..df30b08 100644
@@ -868,7 +868,7 @@ static struct drm_driver kms_driver = {
  	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  	.gem_prime_export = amdgpu_gem_prime_export,
-	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_import = amdgpu_gem_prime_import,
  	.gem_prime_pin = amdgpu_gem_prime_pin,
  	.gem_prime_unpin = amdgpu_gem_prime_unpin,
  	.gem_prime_res_obj = amdgpu_gem_prime_res_obj,
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +108 -0
index ae9c106..9e1424d 100644
@@ -164,6 +164,82 @@ struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)
  	return bo->tbo.resv;
  }
 
+static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction)
+{
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	long i, ret = 0;
+	unsigned old_count;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction == DMA_FROM_DEVICE);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev->flags & AMD_IS_APU);
+	u32 domain;
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	ret = amdgpu_bo_reserve(bo, false);
+	if (unlikely(ret != 0))
+		return ret;
+
+	/*
+	 * Wait for all shared fences to complete before we switch to future
+	 * use of exclusive fence on this prime shared bo.
+	 */
+	ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
+						  MAX_SCHEDULE_TIMEOUT);
+
+	if (unlikely(ret < 0)) {
+		DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
+		amdgpu_bo_unreserve(bo);
+		return ret;
+	}
+
+	ret = 0;
+	/* Pin to gtt */
+	domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
+	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+		old_count = bo->pin_count;
+		for (i = 0; i < old_count; i++)
+			amdgpu_bo_unpin(bo);
+		for (i = 0; i < old_count; i++) {
+			ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL);
+			if (unlikely(ret != 0))
+				break;
+		}
+	}
+	if (ret == 0)
+		ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL);
+
+	amdgpu_bo_unreserve(bo);
+	return ret;
+}
+
+static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction)
+{
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	int ret = 0;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction == DMA_FROM_DEVICE);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev->flags & AMD_IS_APU);
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	mb();
+	ret = amdgpu_bo_reserve(bo, true);
+	if (unlikely(ret != 0))
+		return ret;
+
+	amdgpu_bo_unpin(bo);
+
+	amdgpu_bo_unreserve(bo);
+
+	return 0;
+}
+
+static struct dma_buf_ops amdgpu_dmabuf_ops;
+static atomic_t aops_lock;
+
  struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
  					struct drm_gem_object *gobj,
  					int flags)
@@ -178,5 +254,37 @@ struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
  	buf = drm_gem_prime_export(dev, gobj, flags);
  	if (!IS_ERR(buf))
  		buf->file->f_mapping = dev->anon_inode->i_mapping;
+
+	while (amdgpu_dmabuf_ops.begin_cpu_access != amdgpu_gem_begin_cpu_access ||
+		amdgpu_dmabuf_ops.end_cpu_access != amdgpu_gem_end_cpu_access )
+	{
+		if (!atomic_cmpxchg(&aops_lock, 0, 1)) {
+			amdgpu_dmabuf_ops = *(buf->ops);
+			amdgpu_dmabuf_ops.begin_cpu_access = amdgpu_gem_begin_cpu_access;
+			amdgpu_dmabuf_ops.end_cpu_access = amdgpu_gem_end_cpu_access;
+		}
+	}
+	buf->ops = &amdgpu_dmabuf_ops;
+
  	return buf;
  }
+
+struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
+					    struct dma_buf *dma_buf)
+{
+	struct drm_gem_object *obj;
+
+	if (dma_buf->ops == &amdgpu_dmabuf_ops) {
+		obj = dma_buf->priv;
+		if (obj->dev == dev) {
+			/*
+			 * Importing dmabuf exported from out own gem increases
+			 * refcount on gem itself instead of f_count of dmabuf.
+			 */
+			drm_gem_object_get(obj);
+			return obj;
+		}
+	}
+
+	return drm_gem_prime_import(dev, dma_buf);
+ }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
index a3bf021..f25b830 100644
@@ -2987,6 +2987,8 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
  	int r;
  	struct dm_plane_state *dm_plane_state_new, *dm_plane_state_old;
  	unsigned int awidth;
+	struct amdgpu_device *adev = plane->dev->dev_private;
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev->flags & AMD_IS_APU);
 
  	dm_plane_state_old = to_dm_plane_state(plane->state);
  	dm_plane_state_new = to_dm_plane_state(new_state);
@@ -3005,7 +3007,11 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
  		return r;
 

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct drm_plane *plane, · line 3017

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -1
  	r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM, &afb->address);
-
+	if (unlikely(r != 0)) {
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_GTT, &afb->address);
+	}
 
  	amdgpu_bo_unreserve(rbo);
 

_______________________________________________
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): 57016c36-d7d5-d099-9bfb-e66132037b80-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

author
#4 lore raw

Actually it needs to be pinned here, since otherwise page flip will pin it into vram.

SAm

Quoted 271 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, November 29, 2017 4:39 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

Am 29.11.2017 um 01:20 schrieb Samuel Li:

Quoted 1 line

To improve cpu read performance. This is implemented for APUs currently.

And once more a NAK for this approach.

What we could do is migrate the BO to GTT during mmap, but pinning it is out of question.

Regards,
Christian.

Quoted 7 lines

Change-Id: I300a7daed8f2b0ba6be71a43196a6b8617ddc62e

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h               |   2 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       |  10 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c           |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c         | 108

++++++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct

Quoted 9 lines
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   8 +-
  5 files changed, 126 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index f8657c3..193db70 100644
@@ -417,6 +417,8 @@ amdgpu_gem_prime_import_sg_table(struct

drm_device *dev,

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct drm_device *dev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
  struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
  					struct drm_gem_object *gobj,
  					int flags);
+struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct drm_crtc

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
+					    struct dma_buf *dma_buf);
  int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
  void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
  struct reservation_object *amdgpu_gem_prime_res_obj(struct

drm_gem_object *); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index d704a45..b5483e4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -147,6 +147,7 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc

*crtc,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct drm_crtc · line 193

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -0
  	struct drm_device *dev = crtc->dev;
  	struct amdgpu_device *adev = dev->dev_private;
  	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags
+& AMD_IS_APU);
struct amdgpu_framebuffer *old_amdgpu_fb;
struct amdgpu_framebuffer *new_amdgpu_fb;
struct drm_gem_object *obj;

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -190,8 +191,13 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc
 *crtc,
 
  	r = amdgpu_bo_pin(new_abo, AMDGPU_GEM_DOMAIN_VRAM,

&base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +3 -2
  	if (unlikely(r != 0)) {
-		DRM_ERROR("failed to pin new abo buffer before flip\n");
-		goto unreserve;
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(new_abo,

AMDGPU_GEM_DOMAIN_GTT, &base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct drm_crtc · line 199

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+		if (unlikely(r != 0)) {
+			DRM_ERROR("failed to pin new abo buffer before

flip\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object

Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+			goto unreserve;
+		}
  	}
 

r = reservation_object_get_fences_rcu(new_abo->tbo.resv,
&work->excl, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 31383e0..df30b08 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
@@ -868,7 +868,7 @@ static struct drm_driver kms_driver = {
  	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  	.gem_prime_export = amdgpu_gem_prime_export,
-	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_import = amdgpu_gem_prime_import,
  	.gem_prime_pin = amdgpu_gem_prime_pin,
  	.gem_prime_unpin = amdgpu_gem_prime_unpin,
  	.gem_prime_res_obj = amdgpu_gem_prime_res_obj, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index ae9c106..9e1424d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
@@ -164,6 +164,82 @@ struct reservation_object

*amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
  	return bo->tbo.resv;
  }
 
+static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf,

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	long i, ret = 0;
+	unsigned old_count;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction ==

DMA_FROM_DEVICE);

Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +23 -0
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-
 flags & AMD_IS_APU);
+	u32 domain;
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	ret = amdgpu_bo_reserve(bo, false);
+	if (unlikely(ret != 0))
+		return ret;
+
+	/*
+	 * Wait for all shared fences to complete before we switch to future
+	 * use of exclusive fence on this prime shared bo.
+	 */
+	ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
+						  MAX_SCHEDULE_TIMEOUT);
+
+	if (unlikely(ret < 0)) {
+		DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
+		amdgpu_bo_unreserve(bo);
+		return ret;
+	}
+

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+	ret = 0;
+	/* Pin to gtt */
+	domain = amdgpu_mem_type_to_domain(bo-
 tbo.mem.mem_type);
+	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+		old_count = bo->pin_count;
+		for (i = 0; i < old_count; i++)
+			amdgpu_bo_unpin(bo);
+		for (i = 0; i < old_count; i++) {
+			ret = amdgpu_bo_pin(bo,

AMDGPU_GEM_DOMAIN_GTT, NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+			if (unlikely(ret != 0))
+				break;
+		}
+	}
+	if (ret == 0)
+		ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT,

NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+
+	amdgpu_bo_unreserve(bo);
+	return ret;
+}
+
+static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	int ret = 0;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction ==

DMA_FROM_DEVICE);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags
+& AMD_IS_APU);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +19 -0
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	mb();
+	ret = amdgpu_bo_reserve(bo, true);
+	if (unlikely(ret != 0))
+		return ret;
+
+	amdgpu_bo_unpin(bo);
+
+	amdgpu_bo_unreserve(bo);
+
+	return 0;
+}
+
+static struct dma_buf_ops amdgpu_dmabuf_ops; static atomic_t
+aops_lock;
+
  struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
  					struct drm_gem_object *gobj,
  					int flags)
@@ -178,5 +254,37 @@ struct dma_buf

*amdgpu_gem_prime_export(struct drm_device *dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
  	buf = drm_gem_prime_export(dev, gobj, flags);
  	if (!IS_ERR(buf))
  		buf->file->f_mapping = dev->anon_inode->i_mapping;
+
+	while (amdgpu_dmabuf_ops.begin_cpu_access !=

amdgpu_gem_begin_cpu_access ||

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 259

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+		amdgpu_dmabuf_ops.end_cpu_access !=

amdgpu_gem_end_cpu_access )

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+	{
+		if (!atomic_cmpxchg(&aops_lock, 0, 1)) {
+			amdgpu_dmabuf_ops = *(buf->ops);
+			amdgpu_dmabuf_ops.begin_cpu_access =

amdgpu_gem_begin_cpu_access;

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 264

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			amdgpu_dmabuf_ops.end_cpu_access =

amdgpu_gem_end_cpu_access;

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+		}
+	}
+	buf->ops = &amdgpu_dmabuf_ops;
+
  	return buf;
  }
+
+struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+					    struct dma_buf *dma_buf)
+{
+	struct drm_gem_object *obj;
+
+	if (dma_buf->ops == &amdgpu_dmabuf_ops) {
+		obj = dma_buf->priv;
+		if (obj->dev == dev) {
+			/*
+			 * Importing dmabuf exported from out own gem

increases

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 282

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			 * refcount on gem itself instead of f_count of

dmabuf.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+			 */
+			drm_gem_object_get(obj);
+			return obj;
+		}
+	}
+
+	return drm_gem_prime_import(dev, dma_buf);  }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
index a3bf021..f25b830 100644
@@ -2987,6 +2987,8 @@ static int dm_plane_helper_prepare_fb(struct

drm_plane *plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct · line 2988

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
  	int r;
  	struct dm_plane_state *dm_plane_state_new,

*dm_plane_state_old;

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
  	unsigned int awidth;
+	struct amdgpu_device *adev = plane->dev->dev_private;
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags
+& AMD_IS_APU);

  	dm_plane_state_old = to_dm_plane_state(plane->state);
  	dm_plane_state_new = to_dm_plane_state(new_state); @@ -

3005,7

Quoted 1 line

+3007,11 @@ static int dm_plane_helper_prepare_fb(struct drm_plane

*plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct drm_plane *plane,

Quoted 9 lines

return r;

r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM, &afb-
address);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -1
-
+	if (unlikely(r != 0)) {
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(rbo,

AMDGPU_GEM_DOMAIN_GTT, &afb->address);

Quoted 4 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct drm_plane *plane, · line 3016

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	}
 
  	amdgpu_bo_unreserve(rbo);

_______________________________________________
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): BY2PR12MB063022C560621FA4101DDE8CF53B0-K//h7OWB4q6KMKmDyTWPpAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#6 lore raw

And exactly that's the reason why it is a no-go.

Scanning out from GTT isn't supported at the moment.

Christian.

Am 29.11.2017 um 15:48 schrieb Li, Samuel:

Quoted 274 lines

Actually it needs to be pinned here, since otherwise page flip will pin it into vram.

SAm

Quoted 269 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, November 29, 2017 4:39 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

Am 29.11.2017 um 01:20 schrieb Samuel Li:

Quoted 1 line

To improve cpu read performance. This is implemented for APUs currently.

And once more a NAK for this approach.

What we could do is migrate the BO to GTT during mmap, but pinning it is out of question.

Regards,
Christian.

Quoted 6 lines

Change-Id: I300a7daed8f2b0ba6be71a43196a6b8617ddc62e

---
   drivers/gpu/drm/amd/amdgpu/amdgpu.h               |   2 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       |  10 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c           |   2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c         | 108

++++++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct

Quoted 9 lines
   drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   8 +-
   5 files changed, 126 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index f8657c3..193db70 100644
@@ -417,6 +417,8 @@ amdgpu_gem_prime_import_sg_table(struct

drm_device *dev,

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct drm_device *dev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
   struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
   					struct drm_gem_object *gobj,
   					int flags);
+struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct drm_crtc

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
+					    struct dma_buf *dma_buf);
   int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
   void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
   struct reservation_object *amdgpu_gem_prime_res_obj(struct

drm_gem_object *); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index d704a45..b5483e4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -147,6 +147,7 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc

*crtc,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct drm_crtc · line 193

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -0
   	struct drm_device *dev = crtc->dev;
   	struct amdgpu_device *adev = dev->dev_private;
   	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags

+& AMD_IS_APU);
   	struct amdgpu_framebuffer *old_amdgpu_fb;
   	struct amdgpu_framebuffer *new_amdgpu_fb;
   	struct drm_gem_object *obj;
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -190,8 +191,13 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc
 *crtc,
 
   	r = amdgpu_bo_pin(new_abo, AMDGPU_GEM_DOMAIN_VRAM,

&base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +3 -2
   	if (unlikely(r != 0)) {
-		DRM_ERROR("failed to pin new abo buffer before flip\n");
-		goto unreserve;
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(new_abo,

AMDGPU_GEM_DOMAIN_GTT, &base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct drm_crtc · line 199

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+		if (unlikely(r != 0)) {
+			DRM_ERROR("failed to pin new abo buffer before

flip\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object

Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+			goto unreserve;
+		}
   	}
 
   	r = reservation_object_get_fences_rcu(new_abo->tbo.resv,

&work->excl, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 31383e0..df30b08 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
@@ -868,7 +868,7 @@ static struct drm_driver kms_driver = {
   	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
   	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
   	.gem_prime_export = amdgpu_gem_prime_export,
-	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_import = amdgpu_gem_prime_import,
   	.gem_prime_pin = amdgpu_gem_prime_pin,
   	.gem_prime_unpin = amdgpu_gem_prime_unpin,
   	.gem_prime_res_obj = amdgpu_gem_prime_res_obj, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index ae9c106..9e1424d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
@@ -164,6 +164,82 @@ struct reservation_object

*amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
   	return bo->tbo.resv;
   }
 
+static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf,

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	long i, ret = 0;
+	unsigned old_count;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction ==

DMA_FROM_DEVICE);

Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +23 -0
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-
 flags & AMD_IS_APU);
+	u32 domain;
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	ret = amdgpu_bo_reserve(bo, false);
+	if (unlikely(ret != 0))
+		return ret;
+
+	/*
+	 * Wait for all shared fences to complete before we switch to future
+	 * use of exclusive fence on this prime shared bo.
+	 */
+	ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
+						  MAX_SCHEDULE_TIMEOUT);
+
+	if (unlikely(ret < 0)) {
+		DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
+		amdgpu_bo_unreserve(bo);
+		return ret;
+	}
+

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+	ret = 0;
+	/* Pin to gtt */
+	domain = amdgpu_mem_type_to_domain(bo-
 tbo.mem.mem_type);
+	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+		old_count = bo->pin_count;
+		for (i = 0; i < old_count; i++)
+			amdgpu_bo_unpin(bo);
+		for (i = 0; i < old_count; i++) {
+			ret = amdgpu_bo_pin(bo,

AMDGPU_GEM_DOMAIN_GTT, NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+			if (unlikely(ret != 0))
+				break;
+		}
+	}
+	if (ret == 0)
+		ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT,

NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+
+	amdgpu_bo_unreserve(bo);
+	return ret;
+}
+
+static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	int ret = 0;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction ==

DMA_FROM_DEVICE);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags
+& AMD_IS_APU);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +19 -0
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	mb();
+	ret = amdgpu_bo_reserve(bo, true);
+	if (unlikely(ret != 0))
+		return ret;
+
+	amdgpu_bo_unpin(bo);
+
+	amdgpu_bo_unreserve(bo);
+
+	return 0;
+}
+
+static struct dma_buf_ops amdgpu_dmabuf_ops; static atomic_t
+aops_lock;
+
   struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
   					struct drm_gem_object *gobj,
   					int flags)
@@ -178,5 +254,37 @@ struct dma_buf

*amdgpu_gem_prime_export(struct drm_device *dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
   	buf = drm_gem_prime_export(dev, gobj, flags);
   	if (!IS_ERR(buf))
   		buf->file->f_mapping = dev->anon_inode->i_mapping;
+
+	while (amdgpu_dmabuf_ops.begin_cpu_access !=

amdgpu_gem_begin_cpu_access ||

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 259

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+		amdgpu_dmabuf_ops.end_cpu_access !=

amdgpu_gem_end_cpu_access )

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+	{
+		if (!atomic_cmpxchg(&aops_lock, 0, 1)) {
+			amdgpu_dmabuf_ops = *(buf->ops);
+			amdgpu_dmabuf_ops.begin_cpu_access =

amdgpu_gem_begin_cpu_access;

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 264

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			amdgpu_dmabuf_ops.end_cpu_access =

amdgpu_gem_end_cpu_access;

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+		}
+	}
+	buf->ops = &amdgpu_dmabuf_ops;
+
   	return buf;
   }
+
+struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+					    struct dma_buf *dma_buf)
+{
+	struct drm_gem_object *obj;
+
+	if (dma_buf->ops == &amdgpu_dmabuf_ops) {
+		obj = dma_buf->priv;
+		if (obj->dev == dev) {
+			/*
+			 * Importing dmabuf exported from out own gem

increases

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 282

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			 * refcount on gem itself instead of f_count of

dmabuf.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+			 */
+			drm_gem_object_get(obj);
+			return obj;
+		}
+	}
+
+	return drm_gem_prime_import(dev, dma_buf);  }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
index a3bf021..f25b830 100644
@@ -2987,6 +2987,8 @@ static int dm_plane_helper_prepare_fb(struct

drm_plane *plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct · line 2988

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
   	int r;
   	struct dm_plane_state *dm_plane_state_new,

*dm_plane_state_old;

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
   	unsigned int awidth;
+	struct amdgpu_device *adev = plane->dev->dev_private;
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags
+& AMD_IS_APU);

   	dm_plane_state_old = to_dm_plane_state(plane->state);
   	dm_plane_state_new = to_dm_plane_state(new_state); @@ -

3005,7

Quoted 1 line

+3007,11 @@ static int dm_plane_helper_prepare_fb(struct drm_plane

*plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct drm_plane *plane,

Quoted 9 lines

return r;

r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM, &afb-
address);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -1
-
+	if (unlikely(r != 0)) {
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(rbo,

AMDGPU_GEM_DOMAIN_GTT, &afb->address);

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct drm_plane *plane, · line 3016

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	}
 
   	amdgpu_bo_unreserve(rbo);

_______________________________________________
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): 6c99af44-efbe-a737-5021-2d1c242528f5-5C7GfCeVMHo@public.gmane.org

author
#8 lore raw

One major purpose of the ChromeOS mmap_test is to avoid buffer copying. What is the concern for scanning out from GTT on APUs?

Sam

Quoted 293 lines

-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, November 29, 2017 9:54 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

And exactly that's the reason why it is a no-go.

Scanning out from GTT isn't supported at the moment.

Christian.

Am 29.11.2017 um 15:48 schrieb Li, Samuel:

Quoted 1 line

Actually it needs to be pinned here, since otherwise page flip will pin it into

vram.

Quoted 13 lines

SAm

Quoted 9 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, November 29, 2017 4:39 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

Am 29.11.2017 um 01:20 schrieb Samuel Li:

Quoted 1 line

To improve cpu read performance. This is implemented for APUs

currently.

Quoted 25 lines
Quoted 25 lines

And once more a NAK for this approach.

What we could do is migrate the BO to GTT during mmap, but pinning it is out of question.

Regards,
Christian.

Quoted 6 lines

Change-Id: I300a7daed8f2b0ba6be71a43196a6b8617ddc62e

---
   drivers/gpu/drm/amd/amdgpu/amdgpu.h               |   2 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       |  10 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c           |   2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c         | 108

++++++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct

Quoted 9 lines
   drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   8 +-
   5 files changed, 126 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index f8657c3..193db70 100644
@@ -417,6 +417,8 @@ amdgpu_gem_prime_import_sg_table(struct

drm_device *dev,

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 420

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
   struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
   					struct drm_gem_object *gobj,
   					int flags);
+struct drm_gem_object *amdgpu_gem_prime_import(struct

drm_device

Quoted 12 lines
Quoted 12 lines

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
+					    struct dma_buf *dma_buf);
   int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
   void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
   struct reservation_object *amdgpu_gem_prime_res_obj(struct

drm_gem_object *); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index d704a45..b5483e4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -147,6 +147,7 @@ int amdgpu_crtc_page_flip_target(struct

drm_crtc

Quoted 160 lines
Quoted 160 lines

*crtc,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 193

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -0
   	struct drm_device *dev = crtc->dev;
   	struct amdgpu_device *adev = dev->dev_private;
   	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags

+& AMD_IS_APU);
   	struct amdgpu_framebuffer *old_amdgpu_fb;
   	struct amdgpu_framebuffer *new_amdgpu_fb;
   	struct drm_gem_object *obj;
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -190,8 +191,13 @@ int amdgpu_crtc_page_flip_target(struct
 drm_crtc *crtc,
 
   	r = amdgpu_bo_pin(new_abo, AMDGPU_GEM_DOMAIN_VRAM,

&base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 197

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +3 -2
   	if (unlikely(r != 0)) {
-		DRM_ERROR("failed to pin new abo buffer before flip\n");
-		goto unreserve;
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(new_abo,

AMDGPU_GEM_DOMAIN_GTT, &base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 199

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+		if (unlikely(r != 0)) {
+			DRM_ERROR("failed to pin new abo buffer before

flip\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object

Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+			goto unreserve;
+		}
   	}
 
   	r = reservation_object_get_fences_rcu(new_abo->tbo.resv,

&work->excl, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 31383e0..df30b08 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
@@ -868,7 +868,7 @@ static struct drm_driver kms_driver = {
   	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
   	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
   	.gem_prime_export = amdgpu_gem_prime_export,
-	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_import = amdgpu_gem_prime_import,
   	.gem_prime_pin = amdgpu_gem_prime_pin,
   	.gem_prime_unpin = amdgpu_gem_prime_unpin,
   	.gem_prime_res_obj = amdgpu_gem_prime_res_obj, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index ae9c106..9e1424d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
@@ -164,6 +164,82 @@ struct reservation_object

*amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 167

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
   	return bo->tbo.resv;
   }
 
+static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf,

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 173

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	long i, ret = 0;
+	unsigned old_count;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction ==

DMA_FROM_DEVICE);

Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +23 -0
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-
 flags & AMD_IS_APU);
+	u32 domain;
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	ret = amdgpu_bo_reserve(bo, false);
+	if (unlikely(ret != 0))
+		return ret;
+
+	/*
+	 * Wait for all shared fences to complete before we switch to future
+	 * use of exclusive fence on this prime shared bo.
+	 */
+	ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
+						  MAX_SCHEDULE_TIMEOUT);
+
+	if (unlikely(ret < 0)) {
+		DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
+		amdgpu_bo_unreserve(bo);
+		return ret;
+	}
+

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 207

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+	ret = 0;
+	/* Pin to gtt */
+	domain = amdgpu_mem_type_to_domain(bo-
 tbo.mem.mem_type);
+	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+		old_count = bo->pin_count;
+		for (i = 0; i < old_count; i++)
+			amdgpu_bo_unpin(bo);
+		for (i = 0; i < old_count; i++) {
+			ret = amdgpu_bo_pin(bo,

AMDGPU_GEM_DOMAIN_GTT, NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 213

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+			if (unlikely(ret != 0))
+				break;
+		}
+	}
+	if (ret == 0)
+		ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT,

NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 219

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+
+	amdgpu_bo_unreserve(bo);
+	return ret;
+}
+
+static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 223

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	int ret = 0;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction ==

DMA_FROM_DEVICE);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags
+& AMD_IS_APU);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +19 -0
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	mb();
+	ret = amdgpu_bo_reserve(bo, true);
+	if (unlikely(ret != 0))
+		return ret;
+
+	amdgpu_bo_unpin(bo);
+
+	amdgpu_bo_unreserve(bo);
+
+	return 0;
+}
+
+static struct dma_buf_ops amdgpu_dmabuf_ops; static atomic_t
+aops_lock;
+
   struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
   					struct drm_gem_object *gobj,
   					int flags)
@@ -178,5 +254,37 @@ struct dma_buf

*amdgpu_gem_prime_export(struct drm_device *dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 258

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
   	buf = drm_gem_prime_export(dev, gobj, flags);
   	if (!IS_ERR(buf))
   		buf->file->f_mapping = dev->anon_inode->i_mapping;
+
+	while (amdgpu_dmabuf_ops.begin_cpu_access !=

amdgpu_gem_begin_cpu_access ||

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 259

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+		amdgpu_dmabuf_ops.end_cpu_access !=

amdgpu_gem_end_cpu_access )

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 263

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+	{
+		if (!atomic_cmpxchg(&aops_lock, 0, 1)) {
+			amdgpu_dmabuf_ops = *(buf->ops);
+			amdgpu_dmabuf_ops.begin_cpu_access =

amdgpu_gem_begin_cpu_access;

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 264

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			amdgpu_dmabuf_ops.end_cpu_access =

amdgpu_gem_end_cpu_access;

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 272

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+		}
+	}
+	buf->ops = &amdgpu_dmabuf_ops;
+
   	return buf;
   }
+
+struct drm_gem_object *amdgpu_gem_prime_import(struct

drm_device

Quoted 36 lines
Quoted 36 lines

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 281

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+					    struct dma_buf *dma_buf)
+{
+	struct drm_gem_object *obj;
+
+	if (dma_buf->ops == &amdgpu_dmabuf_ops) {
+		obj = dma_buf->priv;
+		if (obj->dev == dev) {
+			/*
+			 * Importing dmabuf exported from out own gem

increases

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 282

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			 * refcount on gem itself instead of f_count of

dmabuf.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+			 */
+			drm_gem_object_get(obj);
+			return obj;
+		}
+	}
+
+	return drm_gem_prime_import(dev, dma_buf);  }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
index a3bf021..f25b830 100644
@@ -2987,6 +2987,8 @@ static int dm_plane_helper_prepare_fb(struct

drm_plane *plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct · line 2988

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
   	int r;
   	struct dm_plane_state *dm_plane_state_new,

*dm_plane_state_old;

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
   	unsigned int awidth;
+	struct amdgpu_device *adev = plane->dev->dev_private;
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags
+& AMD_IS_APU);

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
   	dm_plane_state_old = to_dm_plane_state(plane->state);
   	dm_plane_state_new = to_dm_plane_state(new_state); @@ -

3005,7

Quoted 1 line

+3007,11 @@ static int dm_plane_helper_prepare_fb(struct drm_plane

*plane,

Quoted 3 lines

return r;

r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM, &afb-

address);

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -1
-
+	if (unlikely(r != 0)) {
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(rbo,

AMDGPU_GEM_DOMAIN_GTT, &afb->address);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	}
 
   	amdgpu_bo_unreserve(rbo);

_______________________________________________
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): BY2PR12MB06309E0735541567ECF1E3D8F53B0-K//h7OWB4q6KMKmDyTWPpAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#10 lore raw
Quoted 1 line

What is the concern for scanning out from GTT on APUs?

It's simply not implemented yet. You need quite a bunch of different setup in DC for this to work.

I've send out a WIP branch a for this a few weeks ago, but haven't worked on this in a while. BTW it is only supported on Carizzo and Raven.

But even then pinning a BO to GTT for this would still be a no-go. We could just avoid the copy on scanout when the BO is already inside GTT because of the CPU access.

In general we should rather work on this as Michel described and avoid creating the BO in VRAM in the first place if possible.

Regards,
Christian.

Am 29.11.2017 um 15:56 schrieb Li, Samuel:

Quoted 296 lines

One major purpose of the ChromeOS mmap_test is to avoid buffer copying. What is the concern for scanning out from GTT on APUs?

Sam

Quoted 292 lines

-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, November 29, 2017 9:54 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

And exactly that's the reason why it is a no-go.

Scanning out from GTT isn't supported at the moment.

Christian.

Am 29.11.2017 um 15:48 schrieb Li, Samuel:

Quoted 1 line

Actually it needs to be pinned here, since otherwise page flip will pin it into

vram.

Quoted 12 lines

SAm

Quoted 9 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, November 29, 2017 4:39 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

Am 29.11.2017 um 01:20 schrieb Samuel Li:

Quoted 1 line

To improve cpu read performance. This is implemented for APUs

currently.

Quoted 25 lines
Quoted 25 lines

And once more a NAK for this approach.

What we could do is migrate the BO to GTT during mmap, but pinning it is out of question.

Regards,
Christian.

Quoted 6 lines

Change-Id: I300a7daed8f2b0ba6be71a43196a6b8617ddc62e

---
    drivers/gpu/drm/amd/amdgpu/amdgpu.h               |   2 +
    drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       |  10 +-
    drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c           |   2 +-
    drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c         | 108

++++++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct

Quoted 9 lines
    drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   8 +-
    5 files changed, 126 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index f8657c3..193db70 100644
@@ -417,6 +417,8 @@ amdgpu_gem_prime_import_sg_table(struct

drm_device *dev,

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 420

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
    struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
    					struct drm_gem_object *gobj,
    					int flags);
+struct drm_gem_object *amdgpu_gem_prime_import(struct

drm_device

Quoted 12 lines
Quoted 12 lines

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
+					    struct dma_buf *dma_buf);
    int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
    void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
    struct reservation_object *amdgpu_gem_prime_res_obj(struct

drm_gem_object *); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index d704a45..b5483e4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -147,6 +147,7 @@ int amdgpu_crtc_page_flip_target(struct

drm_crtc

Quoted 160 lines
Quoted 160 lines

*crtc,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 193

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -0
    	struct drm_device *dev = crtc->dev;
    	struct amdgpu_device *adev = dev->dev_private;
    	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags

+& AMD_IS_APU);
    	struct amdgpu_framebuffer *old_amdgpu_fb;
    	struct amdgpu_framebuffer *new_amdgpu_fb;
    	struct drm_gem_object *obj;
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -190,8 +191,13 @@ int amdgpu_crtc_page_flip_target(struct
 drm_crtc *crtc,
 
    	r = amdgpu_bo_pin(new_abo, AMDGPU_GEM_DOMAIN_VRAM,

&base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 197

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +3 -2
    	if (unlikely(r != 0)) {
-		DRM_ERROR("failed to pin new abo buffer before flip\n");
-		goto unreserve;
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(new_abo,

AMDGPU_GEM_DOMAIN_GTT, &base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 199

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+		if (unlikely(r != 0)) {
+			DRM_ERROR("failed to pin new abo buffer before

flip\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object

Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+			goto unreserve;
+		}
    	}
 
    	r = reservation_object_get_fences_rcu(new_abo->tbo.resv,

&work->excl, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 31383e0..df30b08 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
@@ -868,7 +868,7 @@ static struct drm_driver kms_driver = {
    	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
    	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
    	.gem_prime_export = amdgpu_gem_prime_export,
-	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_import = amdgpu_gem_prime_import,
    	.gem_prime_pin = amdgpu_gem_prime_pin,
    	.gem_prime_unpin = amdgpu_gem_prime_unpin,
    	.gem_prime_res_obj = amdgpu_gem_prime_res_obj, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index ae9c106..9e1424d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
@@ -164,6 +164,82 @@ struct reservation_object

*amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 167

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
    	return bo->tbo.resv;
    }
 
+static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf,

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 173

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	long i, ret = 0;
+	unsigned old_count;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction ==

DMA_FROM_DEVICE);

Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +23 -0
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-
 flags & AMD_IS_APU);
+	u32 domain;
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	ret = amdgpu_bo_reserve(bo, false);
+	if (unlikely(ret != 0))
+		return ret;
+
+	/*
+	 * Wait for all shared fences to complete before we switch to future
+	 * use of exclusive fence on this prime shared bo.
+	 */
+	ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
+						  MAX_SCHEDULE_TIMEOUT);
+
+	if (unlikely(ret < 0)) {
+		DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
+		amdgpu_bo_unreserve(bo);
+		return ret;
+	}
+

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 207

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+	ret = 0;
+	/* Pin to gtt */
+	domain = amdgpu_mem_type_to_domain(bo-
 tbo.mem.mem_type);
+	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+		old_count = bo->pin_count;
+		for (i = 0; i < old_count; i++)
+			amdgpu_bo_unpin(bo);
+		for (i = 0; i < old_count; i++) {
+			ret = amdgpu_bo_pin(bo,

AMDGPU_GEM_DOMAIN_GTT, NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 213

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+			if (unlikely(ret != 0))
+				break;
+		}
+	}
+	if (ret == 0)
+		ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT,

NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 219

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+
+	amdgpu_bo_unreserve(bo);
+	return ret;
+}
+
+static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 223

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);
+	int ret = 0;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction ==

DMA_FROM_DEVICE);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags
+& AMD_IS_APU);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +19 -0
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	mb();
+	ret = amdgpu_bo_reserve(bo, true);
+	if (unlikely(ret != 0))
+		return ret;
+
+	amdgpu_bo_unpin(bo);
+
+	amdgpu_bo_unreserve(bo);
+
+	return 0;
+}
+
+static struct dma_buf_ops amdgpu_dmabuf_ops; static atomic_t
+aops_lock;
+
    struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
    					struct drm_gem_object *gobj,
    					int flags)
@@ -178,5 +254,37 @@ struct dma_buf

*amdgpu_gem_prime_export(struct drm_device *dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 258

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
    	buf = drm_gem_prime_export(dev, gobj, flags);
    	if (!IS_ERR(buf))
    		buf->file->f_mapping = dev->anon_inode->i_mapping;
+
+	while (amdgpu_dmabuf_ops.begin_cpu_access !=

amdgpu_gem_begin_cpu_access ||

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 259

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+		amdgpu_dmabuf_ops.end_cpu_access !=

amdgpu_gem_end_cpu_access )

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 263

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+	{
+		if (!atomic_cmpxchg(&aops_lock, 0, 1)) {
+			amdgpu_dmabuf_ops = *(buf->ops);
+			amdgpu_dmabuf_ops.begin_cpu_access =

amdgpu_gem_begin_cpu_access;

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 264

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			amdgpu_dmabuf_ops.end_cpu_access =

amdgpu_gem_end_cpu_access;

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 272

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+		}
+	}
+	buf->ops = &amdgpu_dmabuf_ops;
+
    	return buf;
    }
+
+struct drm_gem_object *amdgpu_gem_prime_import(struct

drm_device

Quoted 36 lines
Quoted 36 lines

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 281

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+					    struct dma_buf *dma_buf)
+{
+	struct drm_gem_object *obj;
+
+	if (dma_buf->ops == &amdgpu_dmabuf_ops) {
+		obj = dma_buf->priv;
+		if (obj->dev == dev) {
+			/*
+			 * Importing dmabuf exported from out own gem

increases

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 282

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			 * refcount on gem itself instead of f_count of

dmabuf.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+			 */
+			drm_gem_object_get(obj);
+			return obj;
+		}
+	}
+
+	return drm_gem_prime_import(dev, dma_buf);  }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
index a3bf021..f25b830 100644
@@ -2987,6 +2987,8 @@ static int dm_plane_helper_prepare_fb(struct

drm_plane *plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_plane_helper_prepare_fb(struct · line 2988

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
    	int r;
    	struct dm_plane_state *dm_plane_state_new,

*dm_plane_state_old;

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
    	unsigned int awidth;
+	struct amdgpu_device *adev = plane->dev->dev_private;
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO && adev-

flags
+& AMD_IS_APU);

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
    	dm_plane_state_old = to_dm_plane_state(plane->state);
    	dm_plane_state_new = to_dm_plane_state(new_state); @@ -

3005,7

Quoted 1 line

+3007,11 @@ static int dm_plane_helper_prepare_fb(struct drm_plane

*plane,

Quoted 3 lines

return r;

r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM, &afb-

address);

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -1
-
+	if (unlikely(r != 0)) {
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(rbo,

AMDGPU_GEM_DOMAIN_GTT, &afb->address);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	}
 
    	amdgpu_bo_unreserve(rbo);

_______________________________________________
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): 66363160-0778-d484-b91d-5f056b78b5c6-5C7GfCeVMHo@public.gmane.org

author
#12 lore raw

To explain the operations a little bit, the tests include repeated testing of the following sequences,
91 const int sequences[4][4] = {

92                 { STEP_MMAP, STEP_FAULT, STEP_FLIP, STEP_DRAW },
93                 { STEP_MMAP, STEP_FLIP, STEP_DRAW, STEP_SKIP },
94                 { STEP_MMAP, STEP_DRAW, STEP_FLIP, STEP_SKIP },
95                 { STEP_FLIP, STEP_MMAP, STEP_DRAW, STEP_SKIP },

96 };
Here STEP_MMAP includes prime_mmap() and begin_cpu_access(). STEP_DRAW includes repeated cpu reads/writes. It looks to me the dma_buf has to be pinned to gtt here, to prevent it being pinned back by STEP_FLIP before drawing.

Quoted 2 lines

I've send out a WIP branch a for this a few weeks ago, but haven't worked on this in a while. BTW it is only supported on Carizzo and Raven.

Can you show me the branch? Looks like we need to get if finished.

Sam

Quoted 354 lines

-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, November 29, 2017 10:01 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

Quoted 1 line

What is the concern for scanning out from GTT on APUs?

It's simply not implemented yet. You need quite a bunch of different setup in DC for this to work.

I've send out a WIP branch a for this a few weeks ago, but haven't worked on this in a while. BTW it is only supported on Carizzo and Raven.

But even then pinning a BO to GTT for this would still be a no-go. We could just avoid the copy on scanout when the BO is already inside GTT because of the CPU access.

In general we should rather work on this as Michel described and avoid creating the BO in VRAM in the first place if possible.

Regards,
Christian.

Am 29.11.2017 um 15:56 schrieb Li, Samuel:

Quoted 1 line

One major purpose of the ChromeOS mmap_test is to avoid buffer copying.

What is the concern for scanning out from GTT on APUs?

Quoted 59 lines

Sam

Quoted 56 lines

-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, November 29, 2017 9:54 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

And exactly that's the reason why it is a no-go.

Scanning out from GTT isn't supported at the moment.

Christian.

Am 29.11.2017 um 15:48 schrieb Li, Samuel:

Quoted 2 lines

Actually it needs to be pinned here, since otherwise page flip will pin it into

vram.

Quoted 12 lines

SAm

Quoted 9 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, November 29, 2017 4:39 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

Am 29.11.2017 um 01:20 schrieb Samuel Li:

Quoted 1 line

To improve cpu read performance. This is implemented for APUs

currently.

Quoted 26 lines
Quoted 26 lines

And once more a NAK for this approach.

What we could do is migrate the BO to GTT during mmap, but pinning it is out of question.

Regards,
Christian.

Quoted 6 lines

Change-Id: I300a7daed8f2b0ba6be71a43196a6b8617ddc62e

---
    drivers/gpu/drm/amd/amdgpu/amdgpu.h               |   2 +
    drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       |  10 +-
    drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c           |   2 +-
    drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c         | 108

++++++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct

Quoted 9 lines
    drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   8 +-
    5 files changed, 126 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index f8657c3..193db70 100644
@@ -417,6 +417,8 @@ amdgpu_gem_prime_import_sg_table(struct

drm_device *dev,

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
    struct dma_buf *amdgpu_gem_prime_export(struct drm_device

*dev,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 418

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
    					struct drm_gem_object

*gobj,

Quoted 16 lines
Quoted 16 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 420

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
    					int flags);
+struct drm_gem_object *amdgpu_gem_prime_import(struct

drm_device

Quoted 12 lines
Quoted 12 lines

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
+					    struct dma_buf *dma_buf);
    int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
    void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
    struct reservation_object *amdgpu_gem_prime_res_obj(struct

drm_gem_object *); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index d704a45..b5483e4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -147,6 +147,7 @@ int amdgpu_crtc_page_flip_target(struct

drm_crtc

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

*crtc,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 150

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -0
    	struct drm_device *dev = crtc->dev;
    	struct amdgpu_device *adev = dev->dev_private;
    	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO &&

adev-

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 193

Quoted 9 lines

flags

+& AMD_IS_APU);
    	struct amdgpu_framebuffer *old_amdgpu_fb;
    	struct amdgpu_framebuffer *new_amdgpu_fb;
    	struct drm_gem_object *obj;
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -190,8 +191,13 @@ int amdgpu_crtc_page_flip_target(struct
 drm_crtc *crtc,
 
    	r = amdgpu_bo_pin(new_abo,

AMDGPU_GEM_DOMAIN_VRAM,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

&base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 194

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -1
    	if (unlikely(r != 0)) {
-		DRM_ERROR("failed to pin new abo buffer before

flip\n");

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 197

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +3 -1
-		goto unreserve;
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(new_abo,

AMDGPU_GEM_DOMAIN_GTT, &base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 199

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+		if (unlikely(r != 0)) {
+			DRM_ERROR("failed to pin new abo buffer

before

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

flip\n");

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+			goto unreserve;
+		}
    	}
 
    	r = reservation_object_get_fences_rcu(new_abo->tbo.resv,

&work->excl, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 31383e0..df30b08 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -0
@@ -868,7 +868,7 @@ static struct drm_driver kms_driver = {
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = { · line 874

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
    	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
    	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
    	.gem_prime_export = amdgpu_gem_prime_export,
-	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_import = amdgpu_gem_prime_import,
    	.gem_prime_pin = amdgpu_gem_prime_pin,
    	.gem_prime_unpin = amdgpu_gem_prime_unpin,
    	.gem_prime_res_obj = amdgpu_gem_prime_res_obj, diff --

git

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object

Quoted 6 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index ae9c106..9e1424d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
@@ -164,6 +164,82 @@ struct reservation_object

*amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
    	return bo->tbo.resv;
    }
 
+static int amdgpu_gem_begin_cpu_access(struct dma_buf

*dma_buf,

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 169

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf-

priv);

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 170

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo-

tbo.bdev);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 173

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3 -0
+	long i, ret = 0;
+	unsigned old_count;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction

==

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

DMA_FROM_DEVICE);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 174

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO &&

adev-

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3 -0
 flags & AMD_IS_APU);
+	u32 domain;
+
+	if (!reads || !gtt_scannable)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 186

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8 -0
+		return 0;
+
+	ret = amdgpu_bo_reserve(bo, false);
+	if (unlikely(ret != 0))
+		return ret;
+
+	/*
+	 * Wait for all shared fences to complete before we switch to

future

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 189

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3 -0
+	 * use of exclusive fence on this prime shared bo.
+	 */
+	ret = reservation_object_wait_timeout_rcu(bo->tbo.resv,

true, false,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 190

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

MAX_SCHEDULE_TIMEOUT);

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+
+	if (unlikely(ret < 0)) {
+		DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
+		amdgpu_bo_unreserve(bo);
+		return ret;
+	}
+

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 207

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+	ret = 0;
+	/* Pin to gtt */
+	domain = amdgpu_mem_type_to_domain(bo-
 tbo.mem.mem_type);
+	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+		old_count = bo->pin_count;
+		for (i = 0; i < old_count; i++)
+			amdgpu_bo_unpin(bo);
+		for (i = 0; i < old_count; i++) {
+			ret = amdgpu_bo_pin(bo,

AMDGPU_GEM_DOMAIN_GTT, NULL);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 213

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+			if (unlikely(ret != 0))
+				break;
+		}
+	}
+	if (ret == 0)
+		ret = amdgpu_bo_pin(bo,

AMDGPU_GEM_DOMAIN_GTT,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 219

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+
+	amdgpu_bo_unreserve(bo);
+	return ret;
+}
+
+static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,

enum

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 221

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf-

priv);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 223

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+	int ret = 0;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction

==

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

DMA_FROM_DEVICE);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 224

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo-

tbo.bdev);

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 225

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO &&

adev-

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

flags
+& AMD_IS_APU);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +12 -0
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	mb();
+	ret = amdgpu_bo_reserve(bo, true);
+	if (unlikely(ret != 0))
+		return ret;
+
+	amdgpu_bo_unpin(bo);
+
+	amdgpu_bo_unreserve(bo);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+
+	return 0;
+}
+
+static struct dma_buf_ops amdgpu_dmabuf_ops; static atomic_t
+aops_lock;
+
    struct dma_buf *amdgpu_gem_prime_export(struct drm_device

*dev,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

struct drm_gem_object

*gobj,

Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf

Quoted 2 lines

int flags)

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
@@ -178,5 +254,37 @@ struct dma_buf

*amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
    	buf = drm_gem_prime_export(dev, gobj, flags);
    	if (!IS_ERR(buf))
    		buf->file->f_mapping = dev->anon_inode-

i_mapping;

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 258

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+
+	while (amdgpu_dmabuf_ops.begin_cpu_access !=

amdgpu_gem_begin_cpu_access ||

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 259

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+		amdgpu_dmabuf_ops.end_cpu_access !=

amdgpu_gem_end_cpu_access )

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 263

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+	{
+		if (!atomic_cmpxchg(&aops_lock, 0, 1)) {
+			amdgpu_dmabuf_ops = *(buf->ops);
+			amdgpu_dmabuf_ops.begin_cpu_access =

amdgpu_gem_begin_cpu_access;

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 264

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			amdgpu_dmabuf_ops.end_cpu_access =

amdgpu_gem_end_cpu_access;

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 272

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+		}
+	}
+	buf->ops = &amdgpu_dmabuf_ops;
+
    	return buf;
    }
+
+struct drm_gem_object *amdgpu_gem_prime_import(struct

drm_device

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 273

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+					    struct dma_buf *dma_buf)

{

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 280

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+	struct drm_gem_object *obj;
+
+	if (dma_buf->ops == &amdgpu_dmabuf_ops) {
+		obj = dma_buf->priv;
+		if (obj->dev == dev) {
+			/*
+			 * Importing dmabuf exported from out own

gem

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

increases

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 281

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			 * refcount on gem itself instead of f_count

of

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

dmabuf.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+			 */
+			drm_gem_object_get(obj);
+			return obj;
+		}
+	}
+
+	return drm_gem_prime_import(dev, dma_buf);  }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
index a3bf021..f25b830 100644
@@ -2987,6 +2987,8 @@ static int

dm_plane_helper_prepare_fb(struct

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drm_plane *plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int · line 2988

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
    	int r;
    	struct dm_plane_state *dm_plane_state_new,

*dm_plane_state_old;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int · line 2991

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
    	unsigned int awidth;
+	struct amdgpu_device *adev = plane->dev->dev_private;
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO &&

adev-

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

flags
+& AMD_IS_APU);

    	dm_plane_state_old = to_dm_plane_state(plane->state);
    	dm_plane_state_new = to_dm_plane_state(new_state);

@@ -

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

3005,7

Quoted 1 line

+3007,11 @@ static int dm_plane_helper_prepare_fb(struct

drm_plane

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

*plane,

Quoted 3 lines

return r;

r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM,

&afb-

Quoted 7 lines
Quoted 7 lines

address);

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -1
-
+	if (unlikely(r != 0)) {
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(rbo,

AMDGPU_GEM_DOMAIN_GTT, &afb->address);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	}
 
    	amdgpu_bo_unreserve(rbo);

_______________________________________________
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): BY2PR12MB06301C4BA16E0E00F23591F7F53B0-K//h7OWB4q6KMKmDyTWPpAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#14 lore raw

Am 29.11.2017 um 17:52 schrieb Li, Samuel:

Quoted 9 lines

To explain the operations a little bit, the tests include repeated testing of the following sequences,
91 const int sequences[4][4] = {

92                 { STEP_MMAP, STEP_FAULT, STEP_FLIP, STEP_DRAW },
93                 { STEP_MMAP, STEP_FLIP, STEP_DRAW, STEP_SKIP },
94                 { STEP_MMAP, STEP_DRAW, STEP_FLIP, STEP_SKIP },
95                 { STEP_FLIP, STEP_MMAP, STEP_DRAW, STEP_SKIP },

96 };
Here STEP_MMAP includes prime_mmap() and begin_cpu_access(). STEP_DRAW includes repeated cpu reads/writes. It looks to me the dma_buf has to be pinned to gtt here, to prevent it being pinned back by STEP_FLIP before drawing.

When STEP_FLIP needs the BO in VRAM it would fail when we pin it to GTT while it is mapped and that is not something we can do.

What we can do is migrate the BO into GTT when we mmap it and migrate it back to VRAM on demand when it is pinned.

When scanning out from GTT is implemented the flip will then automatically pin it to GTT instead of VRAM.

Quoted 3 lines
Quoted 2 lines

I've send out a WIP branch a for this a few weeks ago, but haven't worked on this in a while. BTW it is only supported on Carizzo and Raven.

Can you show me the branch? Looks like we need to get if finished.

The amdgpu part was already done and is also already committed IIRC (that was only a bunch of bugs fixes anyway).

What's missing is the DC part, they need to do some extra bandwith calculation when scanning out from GTT is enabled and that was problematic to always activate.

You need to ping Harry about the status there.

Christian.

Quoted 359 lines

Sam

Quoted 353 lines

-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, November 29, 2017 10:01 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

Quoted 1 line

What is the concern for scanning out from GTT on APUs?

It's simply not implemented yet. You need quite a bunch of different setup in DC for this to work.

I've send out a WIP branch a for this a few weeks ago, but haven't worked on this in a while. BTW it is only supported on Carizzo and Raven.

But even then pinning a BO to GTT for this would still be a no-go. We could just avoid the copy on scanout when the BO is already inside GTT because of the CPU access.

In general we should rather work on this as Michel described and avoid creating the BO in VRAM in the first place if possible.

Regards,
Christian.

Am 29.11.2017 um 15:56 schrieb Li, Samuel:

Quoted 1 line

One major purpose of the ChromeOS mmap_test is to avoid buffer copying.

What is the concern for scanning out from GTT on APUs?

Quoted 58 lines

Sam

Quoted 56 lines

-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, November 29, 2017 9:54 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

And exactly that's the reason why it is a no-go.

Scanning out from GTT isn't supported at the moment.

Christian.

Am 29.11.2017 um 15:48 schrieb Li, Samuel:

Quoted 2 lines

Actually it needs to be pinned here, since otherwise page flip will pin it into

vram.

Quoted 12 lines

SAm

Quoted 9 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, November 29, 2017 4:39 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] drm/amdgpu: Pin to gtt before cpu accesses dma buf.

Am 29.11.2017 um 01:20 schrieb Samuel Li:

Quoted 1 line

To improve cpu read performance. This is implemented for APUs

currently.

Quoted 26 lines
Quoted 26 lines

And once more a NAK for this approach.

What we could do is migrate the BO to GTT during mmap, but pinning it is out of question.

Regards,
Christian.

Quoted 6 lines

Change-Id: I300a7daed8f2b0ba6be71a43196a6b8617ddc62e

---
     drivers/gpu/drm/amd/amdgpu/amdgpu.h               |   2 +
     drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       |  10 +-
     drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c           |   2 +-
     drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c         | 108

++++++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct

Quoted 9 lines
     drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   8 +-
     5 files changed, 126 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index f8657c3..193db70 100644
@@ -417,6 +417,8 @@ amdgpu_gem_prime_import_sg_table(struct

drm_device *dev,

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
     struct dma_buf *amdgpu_gem_prime_export(struct drm_device

*dev,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 418

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
     					struct drm_gem_object

*gobj,

Quoted 16 lines
Quoted 16 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 420

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
     					int flags);
+struct drm_gem_object *amdgpu_gem_prime_import(struct

drm_device

Quoted 12 lines
Quoted 12 lines

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
+					    struct dma_buf *dma_buf);
     int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
     void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
     struct reservation_object *amdgpu_gem_prime_res_obj(struct

drm_gem_object *); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index d704a45..b5483e4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -147,6 +147,7 @@ int amdgpu_crtc_page_flip_target(struct

drm_crtc

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

*crtc,

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 150

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -0
     	struct drm_device *dev = crtc->dev;
     	struct amdgpu_device *adev = dev->dev_private;
     	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO &&

adev-

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 193

Quoted 9 lines

flags

+& AMD_IS_APU);
     	struct amdgpu_framebuffer *old_amdgpu_fb;
     	struct amdgpu_framebuffer *new_amdgpu_fb;
     	struct drm_gem_object *obj;
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -190,8 +191,13 @@ int amdgpu_crtc_page_flip_target(struct
 drm_crtc *crtc,
 
     	r = amdgpu_bo_pin(new_abo,

AMDGPU_GEM_DOMAIN_VRAM,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

&base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 194

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -1
     	if (unlikely(r != 0)) {
-		DRM_ERROR("failed to pin new abo buffer before

flip\n");

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 197

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +3 -1
-		goto unreserve;
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(new_abo,

AMDGPU_GEM_DOMAIN_GTT, &base);

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_crtc_page_flip_target(struct · line 199

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+		if (unlikely(r != 0)) {
+			DRM_ERROR("failed to pin new abo buffer

before

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

flip\n");

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+			goto unreserve;
+		}
     	}
 
     	r = reservation_object_get_fences_rcu(new_abo->tbo.resv,

&work->excl, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 31383e0..df30b08 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -0
@@ -868,7 +868,7 @@ static struct drm_driver kms_driver = {
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = { · line 874

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
     	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
     	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
     	.gem_prime_export = amdgpu_gem_prime_export,
-	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_import = amdgpu_gem_prime_import,
     	.gem_prime_pin = amdgpu_gem_prime_pin,
     	.gem_prime_unpin = amdgpu_gem_prime_unpin,
     	.gem_prime_res_obj = amdgpu_gem_prime_res_obj, diff --

git

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object

Quoted 6 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index ae9c106..9e1424d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
@@ -164,6 +164,82 @@ struct reservation_object

*amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
     	return bo->tbo.resv;
     }
 
+static int amdgpu_gem_begin_cpu_access(struct dma_buf

*dma_buf,

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

enum

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 169

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf-

priv);

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 170

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo-

tbo.bdev);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 173

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3 -0
+	long i, ret = 0;
+	unsigned old_count;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction

==

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

DMA_FROM_DEVICE);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 174

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO &&

adev-

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3 -0
 flags & AMD_IS_APU);
+	u32 domain;
+
+	if (!reads || !gtt_scannable)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 186

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8 -0
+		return 0;
+
+	ret = amdgpu_bo_reserve(bo, false);
+	if (unlikely(ret != 0))
+		return ret;
+
+	/*
+	 * Wait for all shared fences to complete before we switch to

future

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 189

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3 -0
+	 * use of exclusive fence on this prime shared bo.
+	 */
+	ret = reservation_object_wait_timeout_rcu(bo->tbo.resv,

true, false,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 190

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

MAX_SCHEDULE_TIMEOUT);

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+
+	if (unlikely(ret < 0)) {
+		DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
+		amdgpu_bo_unreserve(bo);
+		return ret;
+	}
+

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 207

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -0
+	ret = 0;
+	/* Pin to gtt */
+	domain = amdgpu_mem_type_to_domain(bo-
 tbo.mem.mem_type);
+	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+		old_count = bo->pin_count;
+		for (i = 0; i < old_count; i++)
+			amdgpu_bo_unpin(bo);
+		for (i = 0; i < old_count; i++) {
+			ret = amdgpu_bo_pin(bo,

AMDGPU_GEM_DOMAIN_GTT, NULL);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 213

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+			if (unlikely(ret != 0))
+				break;
+		}
+	}
+	if (ret == 0)
+		ret = amdgpu_bo_pin(bo,

AMDGPU_GEM_DOMAIN_GTT,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 219

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+
+	amdgpu_bo_unreserve(bo);
+	return ret;
+}
+
+static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,

enum

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 221

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+dma_data_direction direction) {
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf-

priv);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 223

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+	int ret = 0;
+	bool reads = (direction == DMA_BIDIRECTIONAL || direction

==

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

DMA_FROM_DEVICE);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 224

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo-

tbo.bdev);

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object · line 225

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO &&

adev-

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

flags
+& AMD_IS_APU);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +12 -0
+
+	if (!reads || !gtt_scannable)
+		return 0;
+
+	mb();
+	ret = amdgpu_bo_reserve(bo, true);
+	if (unlikely(ret != 0))
+		return ret;
+
+	amdgpu_bo_unpin(bo);
+
+	amdgpu_bo_unreserve(bo);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+
+	return 0;
+}
+
+static struct dma_buf_ops amdgpu_dmabuf_ops; static atomic_t
+aops_lock;
+
     struct dma_buf *amdgpu_gem_prime_export(struct drm_device

*dev,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

struct drm_gem_object

*gobj,

Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf

Quoted 2 lines

int flags)

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
@@ -178,5 +254,37 @@ struct dma_buf

*amdgpu_gem_prime_export(struct drm_device *dev,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0 -0
     	buf = drm_gem_prime_export(dev, gobj, flags);
     	if (!IS_ERR(buf))
     		buf->file->f_mapping = dev->anon_inode-

i_mapping;

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 258

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2 -0
+
+	while (amdgpu_dmabuf_ops.begin_cpu_access !=

amdgpu_gem_begin_cpu_access ||

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 259

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+		amdgpu_dmabuf_ops.end_cpu_access !=

amdgpu_gem_end_cpu_access )

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 263

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
+	{
+		if (!atomic_cmpxchg(&aops_lock, 0, 1)) {
+			amdgpu_dmabuf_ops = *(buf->ops);
+			amdgpu_dmabuf_ops.begin_cpu_access =

amdgpu_gem_begin_cpu_access;

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 264

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			amdgpu_dmabuf_ops.end_cpu_access =

amdgpu_gem_end_cpu_access;

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 272

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6 -0
+		}
+	}
+	buf->ops = &amdgpu_dmabuf_ops;
+
     	return buf;
     }
+
+struct drm_gem_object *amdgpu_gem_prime_import(struct

drm_device

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

*dev,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 273

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+					    struct dma_buf *dma_buf)

{

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 280

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+	struct drm_gem_object *obj;
+
+	if (dma_buf->ops == &amdgpu_dmabuf_ops) {
+		obj = dma_buf->priv;
+		if (obj->dev == dev) {
+			/*
+			 * Importing dmabuf exported from out own

gem

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

increases

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf · line 281

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1 -0
+			 * refcount on gem itself instead of f_count

of

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

dmabuf.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+			 */
+			drm_gem_object_get(obj);
+			return obj;
+		}
+	}
+
+	return drm_gem_prime_import(dev, dma_buf);  }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
index a3bf021..f25b830 100644
@@ -2987,6 +2987,8 @@ static int

dm_plane_helper_prepare_fb(struct

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drm_plane *plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int · line 2988

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
     	int r;
     	struct dm_plane_state *dm_plane_state_new,

*dm_plane_state_old;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int · line 2991

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
     	unsigned int awidth;
+	struct amdgpu_device *adev = plane->dev->dev_private;
+	bool gtt_scannable = (adev->asic_type >= CHIP_CARRIZO &&

adev-

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

flags
+& AMD_IS_APU);

     	dm_plane_state_old = to_dm_plane_state(plane->state);
     	dm_plane_state_new = to_dm_plane_state(new_state);

@@ -

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

3005,7

Quoted 1 line

+3007,11 @@ static int dm_plane_helper_prepare_fb(struct

drm_plane

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

*plane,

Quoted 3 lines

return r;

r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM,

&afb-

Quoted 7 lines
Quoted 7 lines

address);

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -1
-
+	if (unlikely(r != 0)) {
+		/* latest APUs support gtt scan out */
+		if (gtt_scannable)
+			r = amdgpu_bo_pin(rbo,

AMDGPU_GEM_DOMAIN_GTT, &afb->address);

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	}
 
     	amdgpu_bo_unreserve(rbo);

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

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