drm/amdgpu: Move to gtt before cpu accesses dma buf.
Subsystems (2)
PATCH 3/3 drm/amdgpu: Move to gtt before cpu accesses dma buf.
To improve cpu read performance. This is implemented for APUs currently.
v2: Adapt to change https://lists.freedesktop.org/archives/amd-gfx/2017-October/015174.html
v3: Adapt to change "forward begin_cpu_access callback to drivers"
v4: Instead of v3, reuse drm_gem dmabuf_ops here. Also some minor fixes as suggested.
Change-Id: I7a583e23a9ee706e0edd2a46f4e4186a609368e3
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 67 +++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -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_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,
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +67 -0
84 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 04.01.2018 um 22:12 schrieb Samuel Li:
Quoted 55 lines
To improve cpu read performance. This is implemented for APUs currently.
v2: Adapt to change https://lists.freedesktop.org/archives/amd-gfx/2017-October/015174.html
v3: Adapt to change "forwardbegin_cpu_accesscallback to drivers"
v4: Instead of v3, reusedrm_gemdmabuf_opshere. Also some minor fixes as suggested.Change-Id: I7a583e23a9ee706e0edd2a46f4e4186a609368e3
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 67 +++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -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_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,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1
-0@@ -26,6 +26,7 @@#include <drm/drmP.h> #include "amdgpu.h" +#include "amdgpu_display.h" #include <drm/amdgpu_drm.h> #include <linux/dma-buf.h> @@ -164,6 +165,50 @@ struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)return bo->tbo.resv;
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj) · line 175
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0} +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); +struct ttm_operation_ctx ctx = { true, false }; +u32 domain =amdgpu_framebuffer_domains (adev); +int ret =0 ;
Style nit pick: Drop the initializer and make that the last variable declared.
Apart from that the patch is Reviewed-by: Christian König <[email protected]>.
Regards,
Christian.
Quoted 57 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +48
-0+bool reads = (direction ==DMA_BIDIRECTIONAL || + direction ==DMA_FROM_DEVICE ); + +if (!reads || !(domain &AMDGPU_GEM_DOMAIN_GTT )) +return 0 ; + +/* move to gtt */ + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret !=0 )) +return ret; + +if (!bo->pin_count && (bo->allowed_domains &AMDGPU_GEM_DOMAIN_GTT )) { +amdgpu_ttm_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_GTT ); + ret =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); + } + +amdgpu_bo_unreserve (bo); +return ret; +} + +static const struct dma_buf_ops amdgpu_dmabuf_ops = { + .attach = drm_gem_map_attach, + .detach = drm_gem_map_detach, + .map_dma_buf = drm_gem_map_dma_buf, + .unmap_dma_buf = drm_gem_unmap_dma_buf, + .release = drm_gem_dmabuf_release, + .begin_cpu_access = amdgpu_gem_begin_cpu_access, + .map = drm_gem_dmabuf_kmap, + .map_atomic = drm_gem_dmabuf_kmap_atomic, + .unmap = drm_gem_dmabuf_kunmap, + .unmap_atomic = drm_gem_dmabuf_kunmap_atomic, + .mmap = drm_gem_dmabuf_mmap, + .vmap = drm_gem_dmabuf_vmap, + .vunmap = drm_gem_dmabuf_vunmap, +}; +struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags)@@ -178,5 +223,27 @@ 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; + 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) { +/*
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev, · line 249
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +10
-0+* 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); +}
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Samuel,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on drm/drm-next]
[also build test WARNING on v4.15-rc7 next-20180110]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Samuel-Li/drm-amdgpu-allow-framebuffer-in-GART-memory-as-well/20180106-050432 base: git://people.freedesktop.org/~airlied/linux.git drm-next
smatch warnings:drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c:226 amdgpu_gem_prime_export() error: 'buf' dereferencing possible ERR_PTR()
# https://github.com/0day-ci/linux/commit/6aa2afecb5a3efc463d200023839399571404843
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 6aa2afecb5a3efc463d200023839399571404843
vim +/buf +226 drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
6aa2afecb5 Samuel Li 2018-01-04 211
d38ceaf99e Alex Deucher 2015-04-20 212 struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
d38ceaf99e Alex Deucher 2015-04-20 213 struct drm_gem_object *gobj,
d38ceaf99e Alex Deucher 2015-04-20 214 int flags)
d38ceaf99e Alex Deucher 2015-04-20 215 {
d38ceaf99e Alex Deucher 2015-04-20 216 struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);
4b277247b1 Christian König 2017-11-13 217 struct dma_buf *buf;
d38ceaf99e Alex Deucher 2015-04-20 218
e1eb899b45 Christian König 2017-08-25 219 if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm) ||
e1eb899b45 Christian König 2017-08-25 220 bo->flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)
d38ceaf99e Alex Deucher 2015-04-20 221 return ERR_PTR(-EPERM);
d38ceaf99e Alex Deucher 2015-04-20 222
4b277247b1 Christian König 2017-11-13 223 buf = drm_gem_prime_export(dev, gobj, flags);
4b277247b1 Christian König 2017-11-13 224 if (!IS_ERR(buf))
4b277247b1 Christian König 2017-11-13 225 buf->file->f_mapping = dev->anon_inode->i_mapping;
6aa2afecb5 Samuel Li 2018-01-04 @226 buf->ops = &amdgpu_dmabuf_ops;
6aa2afecb5 Samuel Li 2018-01-04 227
4b277247b1 Christian König 2017-11-13 228 return buf;
d38ceaf99e Alex Deucher 2015-04-20 229 }
6aa2afecb5 Samuel Li 2018-01-04 230 A good catch. I'll fix that.
Regards,
Samuel Li
Quoted 62 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Thursday, January 11, 2018 1:43 AM
To: [email protected]; Li, Samuel <[email protected]>
Cc: [email protected]; [email protected]; amd- [email protected]; Li, Samuel <[email protected]>; Dan Carpenter <[email protected]>
Subject: Re: [PATCH 3/3] drm/amdgpu: Move to gtt before cpu accesses dma buf.Hi Samuel,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on drm/drm-next] [also build test WARNING on v4.15-rc7 next-20180110] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Samuel-Li/drm-amdgpu-
allow-framebuffer-in-GART-memory-as-well/20180106-050432
base:git://people.freedesktop.org/~airlied/linux.gitdrm-nextsmatch warnings:
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c:226amdgpu_gem_prime_export()error: 'buf' dereferencing possibleERR_PTR()# https://github.com/0day-
ci/linux/commit/6aa2afecb5a3efc463d200023839399571404843
git remote add linux-review https://github.com/0day-ci/linux git remote update linux-review git checkout6aa2afecb5a3efc463d200023839399571404843
vim +/buf +226drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c6aa2afecb5 Samuel Li 2018-01-04 211 d38ceaf99e Alex Deucher 2015-04-20 212 struct dma_buf*amdgpu_gem_prime_export(struct
drm_device*dev,d38ceaf99eAlex Deucher 2015-04-20 213
structdrm_gem_object*gobj,d38ceaf99eAlex Deucher 2015-04-20 214
int flags)d38ceaf99e Alex Deucher 2015-04-20 215 { d38ceaf99e Alex Deucher 2015-04-20 216 struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj); 4b277247b1 Christian König 2017-11-13 217 struct dma_buf *buf; d38ceaf99e Alex Deucher 2015-04-20 218 e1eb899b45 Christian König 2017-08-25 219 if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm) || e1eb899b45 Christian König 2017-08-25 220 bo->flags &
AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)d38ceaf99eAlex Deucher 2015-04-20 221 return ERR_PTR(-
EPERM);d38ceaf99eAlex Deucher 2015-04-20 2224b277247b1Christian König 2017-11-13 223 buf =drm_gem_prime_export(dev, gobj, flags);4b277247b1 Christian König 2017-11-13 224 if (!IS_ERR(buf)) 4b277247b1 Christian König 2017-11-13 225 buf->file->f_mapping=
dev->anon_inode->i_mapping;6aa2afecb5Samuel Li 2018-01-04 @226buf->ops=&amdgpu_dmabuf_ops;6aa2afecb5Samuel Li 2018-01-04 2274b277247b1Christian König 2017-11-13 228 return buf;
Quoted 6 lines
d38ceaf99e Alex Deucher 2015-04-20 229 } 6aa2afecb5 Samuel Li 2018-01-04 230---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx