drm/ttm: call ttm_bo_swapout directly when ttm shrink
Subsystems (9)
PATCH 1/7 drm/ttm: call ttm_bo_swapout directly when ttm shrink
then remove superfluous functions
--- drivers/gpu/drm/ttm/ttm_bo.c | 21 +++--------- drivers/gpu/drm/ttm/ttm_memory.c | 12 ++----- include/drm/ttm/ttm_bo_api.h | 1 + include/drm/ttm/ttm_bo_driver.h | 1 - include/drm/ttm/ttm_memory.h | 69 +--------------------------------------- 5 files changed, 9 insertions(+), 95 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +4 -17
@@ -42,7 +42,6 @@#include <linux/atomic.h> #include <linux/reservation.h> -static int ttm_bo_swapout (struct ttm_mem_shrink *shrink);static void ttm_bo_global_kobj_release (struct kobject *kobj);static struct attribute ttm_bo_count = {
@@ -1454,7 +1453,6 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj)struct ttm_bo_global *glob = container_of(kobj, struct ttm_bo_global, kobj); -ttm_mem_unregister_shrink (glob->mem_glob, &glob->shrink);__free_page (glob->dummy_read_page);kfree (glob); }
@@ -1479,6 +1477,7 @@ int ttm_bo_global_init(struct drm_global_reference *ref)mutex_init (&glob->device_list_mutex);spin_lock_init (&glob->lru_lock); glob->mem_glob = bo_ref->mem_glob; + glob->mem_glob->bo_glob = glob; glob->dummy_read_page =alloc_page (__GFP_ZERO |GFP_DMA32 );if (unlikely (glob->dummy_read_page ==NULL )) {
@@ -1489,14 +1488,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i)INIT_LIST_HEAD (&glob->swap_lru[i]);INIT_LIST_HEAD (&glob->device_list); - -ttm_mem_init_shrink (&glob->shrink, ttm_bo_swapout); - ret =ttm_mem_register_shrink (glob->mem_glob, &glob->shrink); -if (unlikely (ret !=0 )) { -pr_err ("Could not register buffer object swapout\n" ); - goto out_no_shrink; - } -atomic_set (&glob->bo_count,0 ); ret = kobject_init_and_add(
@@ -1504,8 +1495,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)if (unlikely (ret !=0 ))kobject_put (&glob->kobj);return ret; -out_no_shrink: -__free_page (glob->dummy_read_page); out_no_drp:kfree (glob);return ret;
@@ -1688,11 +1677,8 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);* A buffer object shrink method that tries to swap out the first * buffer object on the bo_global::swap_lru list. */ - -static int ttm_bo_swapout (struct ttm_mem_shrink *shrink) +int ttm_bo_swapout (struct ttm_bo_global *glob) { -struct ttm_bo_global *glob = - container_of(shrink, struct ttm_bo_global, shrink);struct ttm_buffer_object *bo;int ret = -EBUSY ;unsigned i;
@@ -1774,10 +1760,11 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)kref_put (&bo->list_kref, ttm_bo_release_list);return ret; } +EXPORT_SYMBOL (ttm_bo_swapout);void ttm_bo_swapout_all (struct ttm_bo_device *bdev) { -while (ttm_bo_swapout (&bdev->glob->shrink) ==0 ) +while (ttm_bo_swapout (bdev->glob) ==0 ) ; }EXPORT_SYMBOL (ttm_bo_swapout_all);
drivers/gpu/drm/ttm/ttm_memory.c +3 -9
@@ -214,26 +214,20 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, uint64_t extra) {int ret; -struct ttm_mem_shrink *shrink;spin_lock (&glob->lock); -if (glob->shrink ==NULL ) - goto out;while (ttm_zones_above_swap_target (glob, from_wq, extra)) { - shrink = glob->shrink;spin_unlock (&glob->lock); - ret = shrink->do_shrink (shrink); + ret =ttm_bo_swapout (glob->bo_glob);spin_lock (&glob->lock);if (unlikely (ret !=0 )) - goto out; +break ; } -out: +spin_unlock (&glob->lock); } - -static void ttm_shrink_work (struct work_struct *work) { struct ttm_mem_global *glob =
include/drm/ttm/ttm_bo_api.h +1 -0
@@ -752,6 +752,7 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, const char __user *wbuf, char __user *rbuf, size_t count, loff_t *f_pos, bool write); +int ttm_bo_swapout (struct ttm_bo_global *glob);void ttm_bo_swapout_all (struct ttm_bo_device *bdev);int ttm_bo_wait_unreserved (struct ttm_buffer_object *bo);#endif
include/drm/ttm/ttm_bo_driver.h +0 -1
@@ -522,7 +522,6 @@ struct ttm_bo_global {struct kobject kobj;struct ttm_mem_global *mem_glob;struct page *dummy_read_page; -struct ttm_mem_shrink shrink;struct mutex device_list_mutex;spinlock_t lru_lock;
include/drm/ttm/ttm_memory.h +1 -68
87 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): 1513766101-15993-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org
PATCH 2/7 drm/ttm: use an operation ctx for ttm_mem_global_alloc
--- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_memory.c | 15 +++++++++------ drivers/gpu/drm/ttm/ttm_object.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_binding.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 18 +++++++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 12 ++++++++++-- include/drm/ttm/ttm_memory.h | 3 ++- 13 files changed, 87 insertions(+), 25 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -1133,7 +1133,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;bool locked; - ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false); + ret =ttm_mem_global_alloc (mem_glob, acc_size, ctx);if (ret) {pr_err ("Out of kernel memory\n" );if (destroy)
drivers/gpu/drm/ttm/ttm_memory.c +9 -6
@@ -508,7 +508,7 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,static int ttm_mem_global_alloc_zone (struct ttm_mem_global *glob,struct ttm_mem_zone *single_zone,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {int count =TTM_MEMORY_ALLOC_RETRIES ;
@@ -516,7 +516,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, single_zone, memory, true) != 0)) { -if (no_wait) +if (ctx->no_wait_gpu)return -ENOMEM ;if (unlikely (count-- ==0 ))return -ENOMEM ;
@@ -527,15 +527,14 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, }int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {/** * Normal allocations of kernel memory are registered in * all zones. */ -return ttm_mem_global_alloc_zone (glob,NULL , memory, no_wait, - interruptible); +return ttm_mem_global_alloc_zone (glob,NULL , memory, ctx); }EXPORT_SYMBOL (ttm_mem_global_alloc);
@@ -544,6 +543,10 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, {struct ttm_mem_zone *zone =NULL ; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };/** * Page allocations may be registed in a single zone
@@ -557,7 +560,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone, size, false, false); +return ttm_mem_global_alloc_zone (glob, zone, size, &ctx); } void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,
drivers/gpu/drm/ttm/ttm_object.c +10 -3
@@ -325,6 +325,10 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,struct ttm_ref_object *ref;struct drm_hash_item *hash;struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret = -EINVAL ;if (base->tfile != tfile && !base->shareable)
@@ -350,7 +354,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,return -EPERM ; ret =ttm_mem_global_alloc (mem_glob,sizeof (*ref), - false, false); + &ctx);if (unlikely (ret !=0 ))return ret; ref =kmalloc (sizeof (*ref),GFP_KERNEL );
@@ -686,7 +690,10 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, dma_buf = prime->dma_buf;if (!dma_buf || !get_dma_buf_unless_doomed (dma_buf)) {DEFINE_DMA_BUF_EXPORT_INFO (exp_info); - +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + }; exp_info.ops = &tdev->ops; exp_info.size = prime->size; exp_info.flags = flags;
@@ -696,7 +703,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,* Need to create a new dma_buf, with memory accounting. */ ret =ttm_mem_global_alloc (tdev->mem_glob, tdev->dma_buf_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {mutex_unlock (&prime->mutex); goto out_unref;
drivers/gpu/drm/vmwgfx/vmwgfx_binding.c +5 -1
@@ -1202,10 +1202,14 @@ struct vmw_ctx_binding_state * vmw_binding_state_alloc(struct vmw_private *dev_priv) {struct vmw_ctx_binding_state *cbs; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv),sizeof (*cbs), - false, false); + &ctx);if (ret)return ERR_PTR (ret);
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +10 -3
@@ -394,6 +394,10 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv);struct vmw_sg_table *vsgt = &vmw_tt->vsgt; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_piter iter;dma_addr_t old;int ret =0 ;
@@ -417,8 +421,7 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt) sgt_size =ttm_round_pot (sizeof (struct sg_table )); } vmw_tt->sg_alloc_size = sgt_size + sgl_size * vsgt->num_pages; - ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, false, - true); + ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, &ctx);if (unlikely (ret !=0 ))return ret;
@@ -638,6 +641,10 @@ static int vmw_ttm_populate(struct ttm_tt *ttm) container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (ttm->state != tt_unpopulated)
@@ -646,7 +653,7 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)if (dev_priv->map_mode == vmw_dma_alloc_coherent) {size_t size =ttm_round_pot (ttm->num_pages *sizeof (dma_addr_t)); - ret =ttm_mem_global_alloc (glob, size, false, true); + ret =ttm_mem_global_alloc (glob, size, &ctx);if (unlikely (ret !=0 ))return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +5 -1
@@ -746,6 +746,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,struct vmw_resource *tmp;struct drm_vmw_context_arg *arg = (struct drm_vmw_context_arg *)data;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!dev_priv->has_dx && dx) {
@@ -768,7 +772,7 @@ static int vmw_context_define(struct drm_device *dev, void *data, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_context_size, - false, true); + &ttm_opt_ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for context"
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +5 -1
@@ -573,6 +573,10 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, u32 type) {struct vmw_cotable *vcotbl; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;u32 num_entries;
@@ -580,7 +584,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, cotable_acc_size =ttm_round_pot (sizeof (struct vmw_cotable )); ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - cotable_acc_size, false, true); + cotable_acc_size, &ttm_opt_ctx);if (unlikely (ret))return ERR_PTR (ret);
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +5 -1
@@ -588,6 +588,10 @@ int vmw_user_fence_create(struct drm_file *file_priv,struct vmw_user_fence *ufence;struct vmw_fence_obj *tmp;struct ttm_mem_global *mem_glob =vmw_mem_glob (fman->dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret;/*
@@ -596,7 +600,7 @@ int vmw_user_fence_create(struct drm_file *file_priv,*/ ret =ttm_mem_global_alloc (mem_glob, fman->user_fence_size, - false, false); + &ctx);if (unlikely (ret !=0 ))return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +15 -3
@@ -607,6 +607,10 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,struct vmw_dx_shader *shader;struct vmw_resource *res;struct vmw_private *dev_priv = ctx->dev_priv; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!vmw_shader_dx_size)
@@ -616,7 +620,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,return -EINVAL ; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_dx_size, - false, true); + &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "
@@ -730,6 +734,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, {struct vmw_user_shader *ushader;struct vmw_resource *res, *tmp; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/*
@@ -742,7 +750,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "
@@ -800,6 +808,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, {struct vmw_shader *shader;struct vmw_resource *res; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/*
@@ -812,7 +824,7 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "
drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c +5 -1
@@ -149,6 +149,10 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,struct vmw_resource *res;struct vmw_resource *tmp;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t alloc_size;size_t account_size;int ret;
@@ -162,7 +166,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), account_size, - false, true); + &ctx);ttm_read_unlock (&dev_priv->reservation_sem);if (ret) {if (ret != -ERESTARTSYS )
drivers/gpu/drm/vmwgfx/vmwgfx_so.c +5 -1
@@ -329,6 +329,10 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,struct vmw_private *dev_priv = ctx->dev_priv;struct vmw_resource *res;struct vmw_view *view; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t size;int ret;
@@ -345,7 +349,7 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man, size = offsetof(struct vmw_view , cmd) + cmd_size; - ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, false, true); + ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for view"
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +10 -2
@@ -700,6 +700,10 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,struct drm_vmw_surface_create_req *req = &arg->req;struct drm_vmw_surface_arg *rep = &arg->rep;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;int i, j;uint32_t cur_bo_offset;
@@ -741,7 +745,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - size, false, true); + size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"
@@ -1479,6 +1483,10 @@ int vmw_surface_gb_priv_define(struct drm_device *dev, {struct vmw_private *dev_priv =vmw_priv (dev);struct vmw_user_surface *user_srf; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_surface *srf;int ret;u32 num_layers;
@@ -1525,7 +1533,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - user_accounting_size, false, true); + user_accounting_size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"
include/drm/ttm/ttm_memory.h +2 -1
@@ -35,6 +35,7 @@#include <linux/errno.h> #include <linux/kobject.h> #include <linux/mm.h> +#include "ttm_bo_api.h" /** * struct ttm_mem_global - Global memory accounting structure.
@@ -79,7 +80,7 @@ struct ttm_mem_global {extern int ttm_mem_global_init (struct ttm_mem_global *glob);extern void ttm_mem_global_release (struct ttm_mem_global *glob);extern int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible); +struct ttm_operation_ctx *ctx);extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount); extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
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): 1513766101-15993-2-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc
Commit message needed! Something like:
Forward the operation context to ttm_mem_global_alloc as well.
Am 20.12.2017 um 11:34 schrieb Roger He:
Quoted 2 lines
Change-Id I5279b5cd3560c4082b00f822219575a5f9c3808aSigned-off-by Roger He <[email protected]>
With the commit message fixed, patch is Reviewed-by: Christian König <[email protected]>.
I would like to get an rb or ab from Thomas and/or Sinclair as well, since this is touching a lot of vmwgfx code.
Regards,
Christian.
Quoted 440 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_memory.c | 15 +++++++++------ drivers/gpu/drm/ttm/ttm_object.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_binding.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 18 +++++++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 12 ++++++++++-- include/drm/ttm/ttm_memory.h | 3 ++- 13 files changed, 87 insertions(+), 25 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -1133,7 +1133,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;bool locked; - ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false); + ret =ttm_mem_global_alloc (mem_glob, acc_size, ctx);if (ret) {pr_err ("Out of kernel memory\n" );if (destroy)drivers/gpu/drm/ttm/ttm_memory.c +9
-6@@ -508,7 +508,7 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,static int ttm_mem_global_alloc_zone (struct ttm_mem_global *glob,struct ttm_mem_zone *single_zone,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {int count =TTM_MEMORY_ALLOC_RETRIES ;@@ -516,7 +516,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, single_zone, memory, true) != 0)) { -if (no_wait) +if (ctx->no_wait_gpu)return -ENOMEM ;if (unlikely (count-- ==0 ))return -ENOMEM ;@@ -527,15 +527,14 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, }int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {/** * Normal allocations of kernel memory are registered in * all zones. */ -return ttm_mem_global_alloc_zone (glob,NULL , memory, no_wait, - interruptible); +return ttm_mem_global_alloc_zone (glob,NULL , memory, ctx); }EXPORT_SYMBOL (ttm_mem_global_alloc);@@ -544,6 +543,10 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, {struct ttm_mem_zone *zone =NULL ; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };/** * Page allocations may be registed in a single zone @@ -557,7 +560,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone, size, false, false); +return ttm_mem_global_alloc_zone (glob, zone, size, &ctx); } void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,drivers/gpu/drm/ttm/ttm_object.c +10
-3@@ -325,6 +325,10 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,struct ttm_ref_object *ref;struct drm_hash_item *hash;struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret = -EINVAL ;if (base->tfile != tfile && !base->shareable)@@ -350,7 +354,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,return -EPERM ; ret =ttm_mem_global_alloc (mem_glob,sizeof (*ref), - false, false); + &ctx);if (unlikely (ret !=0 ))return ret; ref =kmalloc (sizeof (*ref),GFP_KERNEL );@@ -686,7 +690,10 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, dma_buf = prime->dma_buf;if (!dma_buf || !get_dma_buf_unless_doomed (dma_buf)) {DEFINE_DMA_BUF_EXPORT_INFO (exp_info); - +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + }; exp_info.ops = &tdev->ops; exp_info.size = prime->size; exp_info.flags = flags;@@ -696,7 +703,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,* Need to create a new dma_buf, with memory accounting. */ ret =ttm_mem_global_alloc (tdev->mem_glob, tdev->dma_buf_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {mutex_unlock (&prime->mutex); goto out_unref;drivers/gpu/drm/vmwgfx/vmwgfx_binding.c +5
-1@@ -1202,10 +1202,14 @@ struct vmw_ctx_binding_state * vmw_binding_state_alloc(struct vmw_private *dev_priv) {struct vmw_ctx_binding_state *cbs; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv),sizeof (*cbs), - false, false); + &ctx);if (ret)return ERR_PTR (ret);drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +10
-3@@ -394,6 +394,10 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv);struct vmw_sg_table *vsgt = &vmw_tt->vsgt; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_piter iter;dma_addr_t old;int ret =0 ;@@ -417,8 +421,7 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt) sgt_size =ttm_round_pot (sizeof (struct sg_table )); } vmw_tt->sg_alloc_size = sgt_size + sgl_size * vsgt->num_pages; - ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, false, - true); + ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, &ctx);if (unlikely (ret !=0 ))return ret;@@ -638,6 +641,10 @@ static int vmw_ttm_populate(struct ttm_tt *ttm) container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (ttm->state != tt_unpopulated)@@ -646,7 +653,7 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)if (dev_priv->map_mode == vmw_dma_alloc_coherent) {size_t size =ttm_round_pot (ttm->num_pages *sizeof (dma_addr_t)); - ret =ttm_mem_global_alloc (glob, size, false, true); + ret =ttm_mem_global_alloc (glob, size, &ctx);if (unlikely (ret !=0 ))return ret;drivers/gpu/drm/vmwgfx/vmwgfx_context.c +5
-1@@ -746,6 +746,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,struct vmw_resource *tmp;struct drm_vmw_context_arg *arg = (struct drm_vmw_context_arg *)data;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!dev_priv->has_dx && dx) {@@ -768,7 +772,7 @@ static int vmw_context_define(struct drm_device *dev, void *data, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_context_size, - false, true); + &ttm_opt_ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for context"drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +5
-1@@ -573,6 +573,10 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, u32 type) {struct vmw_cotable *vcotbl; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;u32 num_entries;@@ -580,7 +584,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, cotable_acc_size =ttm_round_pot (sizeof (struct vmw_cotable )); ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - cotable_acc_size, false, true); + cotable_acc_size, &ttm_opt_ctx);if (unlikely (ret))return ERR_PTR (ret);drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +5
-1@@ -588,6 +588,10 @@ int vmw_user_fence_create(struct drm_file *file_priv,struct vmw_user_fence *ufence;struct vmw_fence_obj *tmp;struct ttm_mem_global *mem_glob =vmw_mem_glob (fman->dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret;/* @@ -596,7 +600,7 @@ int vmw_user_fence_create(struct drm_file *file_priv,*/ ret =ttm_mem_global_alloc (mem_glob, fman->user_fence_size, - false, false); + &ctx);if (unlikely (ret !=0 ))return ret;drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +15
-3@@ -607,6 +607,10 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,struct vmw_dx_shader *shader;struct vmw_resource *res;struct vmw_private *dev_priv = ctx->dev_priv; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!vmw_shader_dx_size)@@ -616,7 +620,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,return -EINVAL ; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_dx_size, - false, true); + &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "@@ -730,6 +734,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, {struct vmw_user_shader *ushader;struct vmw_resource *res, *tmp; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/* @@ -742,7 +750,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "@@ -800,6 +808,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, {struct vmw_shader *shader;struct vmw_resource *res; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/* @@ -812,7 +824,7 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c +5
-1@@ -149,6 +149,10 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,struct vmw_resource *res;struct vmw_resource *tmp;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t alloc_size;size_t account_size;int ret;@@ -162,7 +166,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), account_size, - false, true); + &ctx);ttm_read_unlock (&dev_priv->reservation_sem);if (ret) {if (ret != -ERESTARTSYS )drivers/gpu/drm/vmwgfx/vmwgfx_so.c +5
-1@@ -329,6 +329,10 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,struct vmw_private *dev_priv = ctx->dev_priv;struct vmw_resource *res;struct vmw_view *view; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t size;int ret;@@ -345,7 +349,7 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man, size = offsetof(struct vmw_view , cmd) + cmd_size; - ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, false, true); + ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for view"drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +10
-2@@ -700,6 +700,10 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,struct drm_vmw_surface_create_req *req = &arg->req;struct drm_vmw_surface_arg *rep = &arg->rep;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;int i, j;uint32_t cur_bo_offset;@@ -741,7 +745,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - size, false, true); + size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"@@ -1479,6 +1483,10 @@ int vmw_surface_gb_priv_define(struct drm_device *dev, {struct vmw_private *dev_priv =vmw_priv (dev);struct vmw_user_surface *user_srf; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_surface *srf;int ret;u32 num_layers;@@ -1525,7 +1533,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - user_accounting_size, false, true); + user_accounting_size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"include/drm/ttm/ttm_memory.h +1
-0@@ -35,6 +35,7 @@#include <linux/errno.h> #include <linux/kobject.h> #include <linux/mm.h> +#include "ttm_bo_api.h" /** * struct ttm_mem_global - Global memory accounting structure.
include/drm/ttm/ttm_memory.h struct ttm_mem_global { · line 86
Quoted 8 lines
include/drm/ttm/ttm_memory.h +1
-1@@ -79,7 +80,7 @@ struct ttm_mem_global {extern int ttm_mem_global_init (struct ttm_mem_global *glob);extern void ttm_mem_global_release (struct ttm_mem_global *glob);extern int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible); +struct ttm_operation_ctx *ctx);extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount); extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
_______________________________________________
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): 15e3b956-8777-8fb1-2709-5409a756f0be-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc
Hi,
Sorry, I've been on a leave. Catching up on emails.
In case this is still not yet merged, my comment is be consist with the new variable name. In some cases it's "ttm_opt_ctx", in others it's "ctx".
I prefer ttm_opt_ctx because it's more descriptive.
And yes, some description on why this change is necessary in the commit message is nice, too.
Sinclair
Quoted 421 lines · Christian König
Commit message needed! Something like:
Forward the operation context to
ttm_mem_global_allocas well.Am 20.12.2017 um 11:34 schrieb Roger He:
Quoted 2 lines
Change-Id I5279b5cd3560c4082b00f822219575a5f9c3808aSigned-off-by Roger He <[email protected]>With the commit message fixed, patch is Reviewed-by: Christian König <[email protected]>.
I would like to get an rb or ab from Thomas and/or Sinclair as well, since this is touching a lot of vmwgfx code.
Regards,
Christian.Quoted 404 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_memory.c | 15 +++++++++------ drivers/gpu/drm/ttm/ttm_object.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_binding.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 18 +++++++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 12 ++++++++++-- include/drm/ttm/ttm_memory.h | 3 ++- 13 files changed, 87 insertions(+), 25 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -1133,7 +1133,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;bool locked; - ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false); + ret =ttm_mem_global_alloc (mem_glob, acc_size, ctx);if (ret) {pr_err ("Out of kernel memory\n" );if (destroy)drivers/gpu/drm/ttm/ttm_memory.c +9
-6@@ -508,7 +508,7 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,static int ttm_mem_global_alloc_zone (struct ttm_mem_global *glob,struct ttm_mem_zone *single_zone,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {int count =TTM_MEMORY_ALLOC_RETRIES ;@@ -516,7 +516,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, single_zone, memory, true) != 0)) { -if (no_wait) +if (ctx->no_wait_gpu)return -ENOMEM ;if (unlikely (count-- ==0 ))return -ENOMEM ;@@ -527,15 +527,14 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, }int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {/** * Normal allocations of kernel memory are registered in * all zones. */ -return ttm_mem_global_alloc_zone (glob,NULL , memory, no_wait, - interruptible); +return ttm_mem_global_alloc_zone (glob,NULL , memory, ctx); }EXPORT_SYMBOL (ttm_mem_global_alloc);@@ -544,6 +543,10 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, {struct ttm_mem_zone *zone =NULL ; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };/** * Page allocations may be registed in a single zone @@ -557,7 +560,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone, size, false, false); +return ttm_mem_global_alloc_zone (glob, zone, size, &ctx); } void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,drivers/gpu/drm/ttm/ttm_object.c +10
-3@@ -325,6 +325,10 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,struct ttm_ref_object *ref;struct drm_hash_item *hash;struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret = -EINVAL ;if (base->tfile != tfile && !base->shareable)@@ -350,7 +354,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,return -EPERM ; ret =ttm_mem_global_alloc (mem_glob,sizeof (*ref), - false, false); + &ctx);if (unlikely (ret !=0 ))return ret; ref =kmalloc (sizeof (*ref),GFP_KERNEL );@@ -686,7 +690,10 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, dma_buf = prime->dma_buf;if (!dma_buf || !get_dma_buf_unless_doomed (dma_buf)) {DEFINE_DMA_BUF_EXPORT_INFO (exp_info); - +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + }; exp_info.ops = &tdev->ops; exp_info.size = prime->size; exp_info.flags = flags;@@ -696,7 +703,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,* Need to create a new dma_buf, with memory accounting. */ ret =ttm_mem_global_alloc (tdev->mem_glob, tdev->dma_buf_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {mutex_unlock (&prime->mutex); goto out_unref;drivers/gpu/drm/vmwgfx/vmwgfx_binding.c +5
-1@@ -1202,10 +1202,14 @@ struct vmw_ctx_binding_state * vmw_binding_state_alloc(struct vmw_private *dev_priv) {struct vmw_ctx_binding_state *cbs; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv),sizeof (*cbs), - false, false); + &ctx);if (ret)return ERR_PTR (ret);drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +10
-3@@ -394,6 +394,10 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv);struct vmw_sg_table *vsgt = &vmw_tt->vsgt; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_piter iter;dma_addr_t old;int ret =0 ;@@ -417,8 +421,7 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt) sgt_size =ttm_round_pot (sizeof (struct sg_table )); } vmw_tt->sg_alloc_size = sgt_size + sgl_size * vsgt->num_pages; - ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, false, - true); + ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, &ctx);if (unlikely (ret !=0 ))return ret;@@ -638,6 +641,10 @@ static int vmw_ttm_populate(struct ttm_tt *ttm) container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (ttm->state != tt_unpopulated)@@ -646,7 +653,7 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)if (dev_priv->map_mode == vmw_dma_alloc_coherent) {size_t size =ttm_round_pot (ttm->num_pages *sizeof (dma_addr_t)); - ret =ttm_mem_global_alloc (glob, size, false, true); + ret =ttm_mem_global_alloc (glob, size, &ctx);if (unlikely (ret !=0 ))return ret;drivers/gpu/drm/vmwgfx/vmwgfx_context.c +5
-1@@ -746,6 +746,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,struct vmw_resource *tmp;struct drm_vmw_context_arg *arg = (struct drm_vmw_context_arg *)data;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!dev_priv->has_dx && dx) {@@ -768,7 +772,7 @@ static int vmw_context_define(struct drm_device *dev, void *data, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_context_size, - false, true); + &ttm_opt_ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for context"drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +5
-1@@ -573,6 +573,10 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, u32 type) {struct vmw_cotable *vcotbl; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;u32 num_entries;@@ -580,7 +584,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, cotable_acc_size =ttm_round_pot (sizeof (struct vmw_cotable )); ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - cotable_acc_size, false, true); + cotable_acc_size, &ttm_opt_ctx);if (unlikely (ret))return ERR_PTR (ret);drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +5
-1@@ -588,6 +588,10 @@ int vmw_user_fence_create(struct drm_file *file_priv,struct vmw_user_fence *ufence;struct vmw_fence_obj *tmp;struct ttm_mem_global *mem_glob =vmw_mem_glob (fman->dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret;/* @@ -596,7 +600,7 @@ int vmw_user_fence_create(struct drm_file *file_priv,*/ ret =ttm_mem_global_alloc (mem_glob, fman->user_fence_size, - false, false); + &ctx);if (unlikely (ret !=0 ))return ret;drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +15
-3@@ -607,6 +607,10 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,struct vmw_dx_shader *shader;struct vmw_resource *res;struct vmw_private *dev_priv = ctx->dev_priv; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!vmw_shader_dx_size)@@ -616,7 +620,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,return -EINVAL ; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_dx_size, - false, true); + &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "@@ -730,6 +734,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, {struct vmw_user_shader *ushader;struct vmw_resource *res, *tmp; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/* @@ -742,7 +750,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "@@ -800,6 +808,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, {struct vmw_shader *shader;struct vmw_resource *res; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/* @@ -812,7 +824,7 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c +5
-1@@ -149,6 +149,10 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,struct vmw_resource *res;struct vmw_resource *tmp;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t alloc_size;size_t account_size;int ret;@@ -162,7 +166,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), account_size, - false, true); + &ctx);ttm_read_unlock (&dev_priv->reservation_sem);if (ret) {if (ret != -ERESTARTSYS )drivers/gpu/drm/vmwgfx/vmwgfx_so.c +5
-1@@ -329,6 +329,10 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,struct vmw_private *dev_priv = ctx->dev_priv;struct vmw_resource *res;struct vmw_view *view; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t size;int ret;@@ -345,7 +349,7 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man, size = offsetof(struct vmw_view , cmd) + cmd_size; - ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, false, true); + ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for view"drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +10
-2@@ -700,6 +700,10 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,struct drm_vmw_surface_create_req *req = &arg->req;struct drm_vmw_surface_arg *rep = &arg->rep;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;int i, j;uint32_t cur_bo_offset;@@ -741,7 +745,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - size, false, true); + size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"@@ -1479,6 +1483,10 @@ int vmw_surface_gb_priv_define(struct drm_device *dev, {struct vmw_private *dev_priv =vmw_priv (dev);struct vmw_user_surface *user_srf; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_surface *srf;int ret;u32 num_layers;@@ -1525,7 +1533,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - user_accounting_size, false, true); + user_accounting_size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"include/drm/ttm/ttm_memory.h +1
-0@@ -35,6 +35,7 @@#include <linux/errno.h> #include <linux/kobject.h> #include <linux/mm.h> +#include "ttm_bo_api.h" /** * struct ttm_mem_global - Global memory accounting structure. @@ -79,7 +80,7 @@ struct ttm_mem_global {
Quoted 9 lines
include/drm/ttm/ttm_memory.h struct ttm_mem_global { · line 86
Quoted 8 lines
include/drm/ttm/ttm_memory.h +1
-1extern int ttm_mem_global_init (struct ttm_mem_global *glob);extern void ttm_mem_global_release (struct ttm_mem_global *glob);extern int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible); +struct ttm_operation_ctx *ctx);extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount); extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
_______________________________________________
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): [email protected]
Re: [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc
Unfortunately the patches are already comitted (with a better commit message IIRC).
But the variable name sounds just like a style nit pick to me we can fix in a separate patch as well.
Thanks,
Christian.
Am 25.01.2018 um 00:24 schrieb Sinclair Yeh:
Quoted 436 lines
Hi,
Sorry, I've been on a leave. Catching up on emails.
In case this is still not yet merged, my comment is be consist with the new variable name. In some cases it's "
ttm_opt_ctx", in others it's "ctx".I prefer
ttm_opt_ctxbecause it's more descriptive.And yes, some description on why this change is necessary in the commit message is nice, too.
Sinclair
Quoted 420 lines · Christian König
Commit message needed! Something like:
Forward the operation context to
ttm_mem_global_allocas well.Am 20.12.2017 um 11:34 schrieb Roger He:
Quoted 2 lines
Change-Id I5279b5cd3560c4082b00f822219575a5f9c3808aSigned-off-by Roger He <[email protected]>With the commit message fixed, patch is Reviewed-by: Christian König <[email protected]>.
I would like to get an rb or ab from Thomas and/or Sinclair as well, since this is touching a lot of vmwgfx code.
Regards,
Christian.Quoted 404 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_memory.c | 15 +++++++++------ drivers/gpu/drm/ttm/ttm_object.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_binding.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 18 +++++++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 12 ++++++++++-- include/drm/ttm/ttm_memory.h | 3 ++- 13 files changed, 87 insertions(+), 25 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -1133,7 +1133,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;bool locked; - ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false); + ret =ttm_mem_global_alloc (mem_glob, acc_size, ctx);if (ret) {pr_err ("Out of kernel memory\n" );if (destroy)drivers/gpu/drm/ttm/ttm_memory.c +9
-6@@ -508,7 +508,7 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,static int ttm_mem_global_alloc_zone (struct ttm_mem_global *glob,struct ttm_mem_zone *single_zone,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {int count =TTM_MEMORY_ALLOC_RETRIES ;@@ -516,7 +516,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, single_zone, memory, true) != 0)) { -if (no_wait) +if (ctx->no_wait_gpu)return -ENOMEM ;if (unlikely (count-- ==0 ))return -ENOMEM ;@@ -527,15 +527,14 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, }int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {/** * Normal allocations of kernel memory are registered in * all zones. */ -return ttm_mem_global_alloc_zone (glob,NULL , memory, no_wait, - interruptible); +return ttm_mem_global_alloc_zone (glob,NULL , memory, ctx); }EXPORT_SYMBOL (ttm_mem_global_alloc);@@ -544,6 +543,10 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, {struct ttm_mem_zone *zone =NULL ; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };/** * Page allocations may be registed in a single zone @@ -557,7 +560,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone, size, false, false); +return ttm_mem_global_alloc_zone (glob, zone, size, &ctx); } void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,drivers/gpu/drm/ttm/ttm_object.c +10
-3@@ -325,6 +325,10 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,struct ttm_ref_object *ref;struct drm_hash_item *hash;struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret = -EINVAL ;if (base->tfile != tfile && !base->shareable)@@ -350,7 +354,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,return -EPERM ; ret =ttm_mem_global_alloc (mem_glob,sizeof (*ref), - false, false); + &ctx);if (unlikely (ret !=0 ))return ret; ref =kmalloc (sizeof (*ref),GFP_KERNEL );@@ -686,7 +690,10 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, dma_buf = prime->dma_buf;if (!dma_buf || !get_dma_buf_unless_doomed (dma_buf)) {DEFINE_DMA_BUF_EXPORT_INFO (exp_info); - +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + }; exp_info.ops = &tdev->ops; exp_info.size = prime->size; exp_info.flags = flags;@@ -696,7 +703,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,* Need to create a new dma_buf, with memory accounting. */ ret =ttm_mem_global_alloc (tdev->mem_glob, tdev->dma_buf_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {mutex_unlock (&prime->mutex); goto out_unref;drivers/gpu/drm/vmwgfx/vmwgfx_binding.c +5
-1@@ -1202,10 +1202,14 @@ struct vmw_ctx_binding_state * vmw_binding_state_alloc(struct vmw_private *dev_priv) {struct vmw_ctx_binding_state *cbs; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv),sizeof (*cbs), - false, false); + &ctx);if (ret)return ERR_PTR (ret);drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +10
-3@@ -394,6 +394,10 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv);struct vmw_sg_table *vsgt = &vmw_tt->vsgt; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_piter iter;dma_addr_t old;int ret =0 ;@@ -417,8 +421,7 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt) sgt_size =ttm_round_pot (sizeof (struct sg_table )); } vmw_tt->sg_alloc_size = sgt_size + sgl_size * vsgt->num_pages; - ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, false, - true); + ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, &ctx);if (unlikely (ret !=0 ))return ret;@@ -638,6 +641,10 @@ static int vmw_ttm_populate(struct ttm_tt *ttm) container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (ttm->state != tt_unpopulated)@@ -646,7 +653,7 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)if (dev_priv->map_mode == vmw_dma_alloc_coherent) {size_t size =ttm_round_pot (ttm->num_pages *sizeof (dma_addr_t)); - ret =ttm_mem_global_alloc (glob, size, false, true); + ret =ttm_mem_global_alloc (glob, size, &ctx);if (unlikely (ret !=0 ))return ret;drivers/gpu/drm/vmwgfx/vmwgfx_context.c +5
-1@@ -746,6 +746,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,struct vmw_resource *tmp;struct drm_vmw_context_arg *arg = (struct drm_vmw_context_arg *)data;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!dev_priv->has_dx && dx) {@@ -768,7 +772,7 @@ static int vmw_context_define(struct drm_device *dev, void *data, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_context_size, - false, true); + &ttm_opt_ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for context"drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +5
-1@@ -573,6 +573,10 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, u32 type) {struct vmw_cotable *vcotbl; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;u32 num_entries;@@ -580,7 +584,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, cotable_acc_size =ttm_round_pot (sizeof (struct vmw_cotable )); ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - cotable_acc_size, false, true); + cotable_acc_size, &ttm_opt_ctx);if (unlikely (ret))return ERR_PTR (ret);drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +5
-1@@ -588,6 +588,10 @@ int vmw_user_fence_create(struct drm_file *file_priv,struct vmw_user_fence *ufence;struct vmw_fence_obj *tmp;struct ttm_mem_global *mem_glob =vmw_mem_glob (fman->dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret;/* @@ -596,7 +600,7 @@ int vmw_user_fence_create(struct drm_file *file_priv,*/ ret =ttm_mem_global_alloc (mem_glob, fman->user_fence_size, - false, false); + &ctx);if (unlikely (ret !=0 ))return ret;drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +15
-3@@ -607,6 +607,10 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,struct vmw_dx_shader *shader;struct vmw_resource *res;struct vmw_private *dev_priv = ctx->dev_priv; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!vmw_shader_dx_size)@@ -616,7 +620,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,return -EINVAL ; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_dx_size, - false, true); + &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "@@ -730,6 +734,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, {struct vmw_user_shader *ushader;struct vmw_resource *res, *tmp; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/* @@ -742,7 +750,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "@@ -800,6 +808,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, {struct vmw_shader *shader;struct vmw_resource *res; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/* @@ -812,7 +824,7 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c +5
-1@@ -149,6 +149,10 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,struct vmw_resource *res;struct vmw_resource *tmp;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t alloc_size;size_t account_size;int ret;@@ -162,7 +166,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), account_size, - false, true); + &ctx);ttm_read_unlock (&dev_priv->reservation_sem);if (ret) {if (ret != -ERESTARTSYS )drivers/gpu/drm/vmwgfx/vmwgfx_so.c +5
-1@@ -329,6 +329,10 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,struct vmw_private *dev_priv = ctx->dev_priv;struct vmw_resource *res;struct vmw_view *view; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t size;int ret;@@ -345,7 +349,7 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man, size = offsetof(struct vmw_view , cmd) + cmd_size; - ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, false, true); + ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for view"drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +10
-2@@ -700,6 +700,10 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,struct drm_vmw_surface_create_req *req = &arg->req;struct drm_vmw_surface_arg *rep = &arg->rep;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;int i, j;uint32_t cur_bo_offset;@@ -741,7 +745,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - size, false, true); + size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"@@ -1479,6 +1483,10 @@ int vmw_surface_gb_priv_define(struct drm_device *dev, {struct vmw_private *dev_priv =vmw_priv (dev);struct vmw_user_surface *user_srf; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_surface *srf;int ret;u32 num_layers;@@ -1525,7 +1533,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - user_accounting_size, false, true); + user_accounting_size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"include/drm/ttm/ttm_memory.h +1
-0@@ -35,6 +35,7 @@#include <linux/errno.h> #include <linux/kobject.h> #include <linux/mm.h> +#include "ttm_bo_api.h" /** * struct ttm_mem_global - Global memory accounting structure. @@ -79,7 +80,7 @@ struct ttm_mem_global {
Quoted 8 lines
Quoted 8 lines
include/drm/ttm/ttm_memory.h struct ttm_mem_global { · line 86
Quoted 8 lines
include/drm/ttm/ttm_memory.h +1
-1extern int ttm_mem_global_init (struct ttm_mem_global *glob);extern void ttm_mem_global_release (struct ttm_mem_global *glob);extern int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible); +struct ttm_operation_ctx *ctx);extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount); extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc
In reply to Roger HeWith a suitable commit log, LGTM.
Quoted 442 lines · Roger He
Change-Id I5279b5cd3560c4082b00f822219575a5f9c3808aSigned-off-by Roger He <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_memory.c | 15 +++++++++------ drivers/gpu/drm/ttm/ttm_object.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_binding.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 ++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 18 +++++++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++++- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 12 ++++++++++-- include/drm/ttm/ttm_memory.h | 3 ++- 13 files changed, 87 insertions(+), 25 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -1133,7 +1133,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;bool locked; - ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false); + ret =ttm_mem_global_alloc (mem_glob, acc_size, ctx);if (ret) {pr_err ("Out of kernel memory\n" );if (destroy)drivers/gpu/drm/ttm/ttm_memory.c +9
-6@@ -508,7 +508,7 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,static int ttm_mem_global_alloc_zone (struct ttm_mem_global *glob,struct ttm_mem_zone *single_zone,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {int count =TTM_MEMORY_ALLOC_RETRIES ;@@ -516,7 +516,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, single_zone, memory, true) != 0)) { -if (no_wait) +if (ctx->no_wait_gpu)return -ENOMEM ;if (unlikely (count-- ==0 ))return -ENOMEM ;@@ -527,15 +527,14 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, }int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible) +struct ttm_operation_ctx *ctx) {/** * Normal allocations of kernel memory are registered in * all zones. */ -return ttm_mem_global_alloc_zone (glob,NULL , memory, no_wait, - interruptible); +return ttm_mem_global_alloc_zone (glob,NULL , memory, ctx); }EXPORT_SYMBOL (ttm_mem_global_alloc);@@ -544,6 +543,10 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, {struct ttm_mem_zone *zone =NULL ; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };/** * Page allocations may be registed in a single zone @@ -557,7 +560,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone, size, false, false); +return ttm_mem_global_alloc_zone (glob, zone, size, &ctx); } void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,drivers/gpu/drm/ttm/ttm_object.c +10
-3@@ -325,6 +325,10 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,struct ttm_ref_object *ref;struct drm_hash_item *hash;struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret = -EINVAL ;if (base->tfile != tfile && !base->shareable)@@ -350,7 +354,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,return -EPERM ; ret =ttm_mem_global_alloc (mem_glob,sizeof (*ref), - false, false); + &ctx);if (unlikely (ret !=0 ))return ret; ref =kmalloc (sizeof (*ref),GFP_KERNEL );@@ -686,7 +690,10 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, dma_buf = prime->dma_buf;if (!dma_buf || !get_dma_buf_unless_doomed (dma_buf)) {DEFINE_DMA_BUF_EXPORT_INFO (exp_info); - +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + }; exp_info.ops = &tdev->ops; exp_info.size = prime->size; exp_info.flags = flags;@@ -696,7 +703,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,* Need to create a new dma_buf, with memory accounting. */ ret =ttm_mem_global_alloc (tdev->mem_glob, tdev->dma_buf_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {mutex_unlock (&prime->mutex); goto out_unref;drivers/gpu/drm/vmwgfx/vmwgfx_binding.c +5
-1@@ -1202,10 +1202,14 @@ struct vmw_ctx_binding_state * vmw_binding_state_alloc(struct vmw_private *dev_priv) {struct vmw_ctx_binding_state *cbs; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv),sizeof (*cbs), - false, false); + &ctx);if (ret)return ERR_PTR (ret);drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +10
-3@@ -394,6 +394,10 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv);struct vmw_sg_table *vsgt = &vmw_tt->vsgt; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_piter iter;dma_addr_t old;int ret =0 ;@@ -417,8 +421,7 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt) sgt_size =ttm_round_pot (sizeof (struct sg_table )); } vmw_tt->sg_alloc_size = sgt_size + sgl_size * vsgt->num_pages; - ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, false, - true); + ret =ttm_mem_global_alloc (glob, vmw_tt->sg_alloc_size, &ctx);if (unlikely (ret !=0 ))return ret;@@ -638,6 +641,10 @@ static int vmw_ttm_populate(struct ttm_tt *ttm) container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (ttm->state != tt_unpopulated)@@ -646,7 +653,7 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)if (dev_priv->map_mode == vmw_dma_alloc_coherent) {size_t size =ttm_round_pot (ttm->num_pages *sizeof (dma_addr_t)); - ret =ttm_mem_global_alloc (glob, size, false, true); + ret =ttm_mem_global_alloc (glob, size, &ctx);if (unlikely (ret !=0 ))return ret;drivers/gpu/drm/vmwgfx/vmwgfx_context.c +5
-1@@ -746,6 +746,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,struct vmw_resource *tmp;struct drm_vmw_context_arg *arg = (struct drm_vmw_context_arg *)data;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!dev_priv->has_dx && dx) {@@ -768,7 +772,7 @@ static int vmw_context_define(struct drm_device *dev, void *data, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_context_size, - false, true); + &ttm_opt_ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for context"drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +5
-1@@ -573,6 +573,10 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, u32 type) {struct vmw_cotable *vcotbl; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;u32 num_entries;@@ -580,7 +584,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, cotable_acc_size =ttm_round_pot (sizeof (struct vmw_cotable )); ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - cotable_acc_size, false, true); + cotable_acc_size, &ttm_opt_ctx);if (unlikely (ret))return ERR_PTR (ret);drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +5
-1@@ -588,6 +588,10 @@ int vmw_user_fence_create(struct drm_file *file_priv,struct vmw_user_fence *ufence;struct vmw_fence_obj *tmp;struct ttm_mem_global *mem_glob =vmw_mem_glob (fman->dev_priv); +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret;/* @@ -596,7 +600,7 @@ int vmw_user_fence_create(struct drm_file *file_priv,*/ ret =ttm_mem_global_alloc (mem_glob, fman->user_fence_size, - false, false); + &ctx);if (unlikely (ret !=0 ))return ret;drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +15
-3@@ -607,6 +607,10 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,struct vmw_dx_shader *shader;struct vmw_resource *res;struct vmw_private *dev_priv = ctx->dev_priv; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;if (!vmw_shader_dx_size)@@ -616,7 +620,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,return -EINVAL ; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_dx_size, - false, true); + &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "@@ -730,6 +734,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, {struct vmw_user_shader *ushader;struct vmw_resource *res, *tmp; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/* @@ -742,7 +750,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_user_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "@@ -800,6 +808,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, {struct vmw_shader *shader;struct vmw_resource *res; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;/* @@ -812,7 +824,7 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), vmw_shader_size, - false, true); + &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for shader "drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c +5
-1@@ -149,6 +149,10 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,struct vmw_resource *res;struct vmw_resource *tmp;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t alloc_size;size_t account_size;int ret;@@ -162,7 +166,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), account_size, - false, true); + &ctx);ttm_read_unlock (&dev_priv->reservation_sem);if (ret) {if (ret != -ERESTARTSYS )drivers/gpu/drm/vmwgfx/vmwgfx_so.c +5
-1@@ -329,6 +329,10 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,struct vmw_private *dev_priv = ctx->dev_priv;struct vmw_resource *res;struct vmw_view *view; +struct ttm_operation_ctx ttm_opt_ctx = { + .interruptible = true, + .no_wait_gpu = false + };size_t size;int ret;@@ -345,7 +349,7 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man, size = offsetof(struct vmw_view , cmd) + cmd_size; - ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, false, true); + ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), size, &ttm_opt_ctx);if (ret) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for view"drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +10
-2@@ -700,6 +700,10 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,struct drm_vmw_surface_create_req *req = &arg->req;struct drm_vmw_surface_arg *rep = &arg->rep;struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };int ret;int i, j;uint32_t cur_bo_offset;@@ -741,7 +745,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - size, false, true); + size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"@@ -1479,6 +1483,10 @@ int vmw_surface_gb_priv_define(struct drm_device *dev, {struct vmw_private *dev_priv =vmw_priv (dev);struct vmw_user_surface *user_srf; +struct ttm_operation_ctx ctx = { + .interruptible = true, + .no_wait_gpu = false + };struct vmw_surface *srf;int ret;u32 num_layers;@@ -1525,7 +1533,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,return ret; ret =ttm_mem_global_alloc (vmw_mem_glob (dev_priv), - user_accounting_size, false, true); + user_accounting_size, &ctx);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS ) DRM_ERROR("Out of graphics memory for surface"include/drm/ttm/ttm_memory.h +1
-0@@ -35,6 +35,7 @@#include <linux/errno.h> #include <linux/kobject.h> #include <linux/mm.h> +#include "ttm_bo_api.h" /** * struct ttm_mem_global - Global memory accounting structure.
include/drm/ttm/ttm_memory.h struct ttm_mem_global { · line 86
Quoted 8 lines
include/drm/ttm/ttm_memory.h +1
-1@@ -79,7 +80,7 @@ struct ttm_mem_global {extern int ttm_mem_global_init (struct ttm_mem_global *glob);extern void ttm_mem_global_release (struct ttm_mem_global *glob);extern int ttm_mem_global_alloc (struct ttm_mem_global *glob,uint64_t memory, -bool no_wait,bool interruptible); +struct ttm_operation_ctx *ctx);extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount); extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/7 drm/ttm: use an operation ctx for ttm_tt_populate in ttm_bo_driver
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++--- drivers/gpu/drm/ast/ast_ttm.c | 5 +++-- drivers/gpu/drm/cirrus/cirrus_ttm.c | 5 +++-- drivers/gpu/drm/nouveau/nouveau_bo.c | 8 ++++---- drivers/gpu/drm/qxl/qxl_ttm.c | 5 +++-- drivers/gpu/drm/radeon/radeon_ttm.c | 9 +++++---- drivers/gpu/drm/ttm/ttm_agp_backend.c | 4 ++-- drivers/gpu/drm/ttm/ttm_bo_util.c | 11 ++++++++--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 7 ++++++- drivers/gpu/drm/ttm/ttm_page_alloc.c | 13 +++++-------- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 11 ++++------- drivers/gpu/drm/ttm/ttm_tt.c | 6 +++++- drivers/gpu/drm/virtio/virtgpu_object.c | 6 +++++- drivers/gpu/drm/virtio/virtgpu_ttm.c | 5 +++-- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 +++++-------- drivers/gpu/drm/vmwgfx/vmwgfx_mob.c | 13 +++++++++++-- include/drm/ttm/ttm_bo_driver.h | 5 +++-- include/drm/ttm/ttm_page_alloc.h | 11 +++++++---- 18 files changed, 86 insertions(+), 58 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +4 -3
@@ -990,7 +990,8 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_bo_device *bdev,return >t->ttm.ttm; } -static int amdgpu_ttm_tt_populate (struct ttm_tt *ttm) +static int amdgpu_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) {struct amdgpu_device *adev =amdgpu_ttm_adev (ttm->bdev);struct amdgpu_ttm_tt *gtt = (void *)ttm;
@@ -1018,11 +1019,11 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm)#ifdef CONFIG_SWIOTLB if (swiotlb_nr_tbl ()) { -return ttm_dma_populate (>t->ttm, adev->dev); +return ttm_dma_populate (>t->ttm, adev->dev, ctx); }#endif -return ttm_populate_and_map_pages (adev->dev, >t->ttm); +return ttm_populate_and_map_pages (adev->dev, >t->ttm, ctx); }static void amdgpu_ttm_tt_unpopulate (struct ttm_tt *ttm)
drivers/gpu/drm/ast/ast_ttm.c +3 -2
@@ -216,9 +216,10 @@ static struct ttm_tt *ast_ttm_tt_create(struct ttm_bo_device *bdev,return tt; } -static int ast_ttm_tt_populate (struct ttm_tt *ttm) +static int ast_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) { -return ttm_pool_populate (ttm); +return ttm_pool_populate (ttm, ctx); }static void ast_ttm_tt_unpopulate (struct ttm_tt *ttm)
drivers/gpu/drm/cirrus/cirrus_ttm.c +3 -2
@@ -216,9 +216,10 @@ static struct ttm_tt *cirrus_ttm_tt_create(struct ttm_bo_device *bdev,return tt; } -static int cirrus_ttm_tt_populate (struct ttm_tt *ttm) +static int cirrus_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) { -return ttm_pool_populate (ttm); +return ttm_pool_populate (ttm, ctx); }static void cirrus_ttm_tt_unpopulate (struct ttm_tt *ttm)
drivers/gpu/drm/nouveau/nouveau_bo.c +4 -4
@@ -1547,7 +1547,7 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) }static int -nouveau_ttm_tt_populate (struct ttm_tt *ttm) +nouveau_ttm_tt_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx) {struct ttm_dma_tt *ttm_dma = (void *)ttm;struct nouveau_drm *drm;
@@ -1572,17 +1572,17 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)#if IS_ENABLED (CONFIG_AGP )if (drm->agp.bridge) { -return ttm_agp_tt_populate (ttm); +return ttm_agp_tt_populate (ttm, ctx); }#endif #if IS_ENABLED (CONFIG_SWIOTLB ) &&IS_ENABLED (CONFIG_X86 )if (swiotlb_nr_tbl ()) { -return ttm_dma_populate ((void *)ttm, dev); +return ttm_dma_populate ((void *)ttm, dev, ctx); }#endif - r =ttm_pool_populate (ttm); + r =ttm_pool_populate (ttm, ctx);if (r) {return r; }
drivers/gpu/drm/qxl/qxl_ttm.c +3 -2
@@ -291,14 +291,15 @@ static struct ttm_backend_func qxl_backend_func = { .destroy = &qxl_ttm_backend_destroy, }; -static int qxl_ttm_tt_populate (struct ttm_tt *ttm) +static int qxl_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) {int r;if (ttm->state != tt_unpopulated)return 0 ; - r =ttm_pool_populate (ttm); + r =ttm_pool_populate (ttm, ctx);if (r)return r;
drivers/gpu/drm/radeon/radeon_ttm.c +5 -4
@@ -721,7 +721,8 @@ static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm)return (struct radeon_ttm_tt *)ttm; } -static int radeon_ttm_tt_populate (struct ttm_tt *ttm) +static int radeon_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) {struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);struct radeon_device *rdev;
@@ -750,17 +751,17 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm) rdev =radeon_get_rdev (ttm->bdev);#if IS_ENABLED (CONFIG_AGP )if (rdev->flags &RADEON_IS_AGP ) { -return ttm_agp_tt_populate (ttm); +return ttm_agp_tt_populate (ttm, ctx); }#endif #ifdef CONFIG_SWIOTLB if (swiotlb_nr_tbl ()) { -return ttm_dma_populate (>t->ttm, rdev->dev); +return ttm_dma_populate (>t->ttm, rdev->dev, ctx); }#endif -return ttm_populate_and_map_pages (rdev->dev, >t->ttm); +return ttm_populate_and_map_pages (rdev->dev, >t->ttm, ctx); }static void radeon_ttm_tt_unpopulate (struct ttm_tt *ttm)
drivers/gpu/drm/ttm/ttm_agp_backend.c +2 -2
@@ -133,12 +133,12 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev, }EXPORT_SYMBOL (ttm_agp_tt_create); -int ttm_agp_tt_populate (struct ttm_tt *ttm) +int ttm_agp_tt_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx) {if (ttm->state != tt_unpopulated)return 0 ; -return ttm_pool_populate (ttm); +return ttm_pool_populate (ttm, ctx); }EXPORT_SYMBOL (ttm_agp_tt_populate);
drivers/gpu/drm/ttm/ttm_bo_util.c +8 -3
@@ -376,7 +376,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,* TTM might be null for moves within the same region. */ if (ttm && ttm->state == tt_unpopulated) { - ret = ttm->bdev->driver->ttm_tt_populate (ttm); + ret = ttm->bdev->driver->ttm_tt_populate (ttm, ctx);if (ret) goto out1; }
@@ -545,14 +545,19 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,unsigned long num_pages, struct ttm_bo_kmap_obj *map) { - struct ttm_mem_reg *mem = &bo->mem; pgprot_t prot; + struct ttm_mem_reg *mem = &bo->mem; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };struct ttm_tt *ttm = bo->ttm; +pgprot_t prot;int ret;BUG_ON (!ttm);if (ttm->state == tt_unpopulated) { - ret = ttm->bdev->driver->ttm_tt_populate (ttm); + ret = ttm->bdev->driver->ttm_tt_populate (ttm, &ctx);if (ret)return ret; }
drivers/gpu/drm/ttm/ttm_bo_vm.c +6 -1
@@ -215,12 +215,17 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf) cvma.vm_page_prot =ttm_io_prot (bo->mem.placement, cvma.vm_page_prot); }else { +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + }; + ttm = bo->ttm; cvma.vm_page_prot =ttm_io_prot (bo->mem.placement, cvma.vm_page_prot);/* Allocate all page at once, most common usage */ -if (ttm->bdev->driver->ttm_tt_populate (ttm)) { +if (ttm->bdev->driver->ttm_tt_populate (ttm, &ctx)) { retval =VM_FAULT_OOM ; goto out_io_unlock; }
drivers/gpu/drm/ttm/ttm_page_alloc.c +5 -8
@@ -1058,13 +1058,9 @@ void ttm_page_alloc_fini(void) _manager =NULL ; } -int ttm_pool_populate (struct ttm_tt *ttm) +int ttm_pool_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx) {struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - };unsigned i;int ret;
@@ -1080,7 +1076,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)for (i =0 ; i < ttm->num_pages; ++i) { ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], -PAGE_SIZE , &ctx); +PAGE_SIZE , ctx);if (unlikely (ret !=0 )) {ttm_pool_unpopulate (ttm);return -ENOMEM ;
@@ -1117,12 +1113,13 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm) }EXPORT_SYMBOL (ttm_pool_unpopulate); -int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt) +int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt, +struct ttm_operation_ctx *ctx) {unsigned i, j;int r; - r =ttm_pool_populate (&tt->ttm); + r =ttm_pool_populate (&tt->ttm, ctx);if (r)return r;
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +4 -7
@@ -923,14 +923,11 @@ static gfp_t ttm_dma_pool_gfp_flags(struct ttm_dma_tt *ttm_dma, bool huge)* On success pages list will hold count number of correctly * cached pages. On failure will hold the negative return value (-ENOMEM, etc). */ -int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev) +int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev, +struct ttm_operation_ctx *ctx) {struct ttm_tt *ttm = &ttm_dma->ttm;struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - };unsigned long num_pages = ttm->num_pages;struct dma_pool *pool;enum pool_type type;
@@ -966,7 +963,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)break ; ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size, &ctx); + pool->size, ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;
@@ -1002,7 +999,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev) } ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size, &ctx); + pool->size, ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;
drivers/gpu/drm/ttm/ttm_tt.c +5 -1
@@ -263,6 +263,10 @@ void ttm_tt_unbind(struct ttm_tt *ttm)int ttm_tt_bind (struct ttm_tt *ttm,struct ttm_mem_reg *bo_mem) { +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret =0 ;if (!ttm)
@@ -271,7 +275,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)if (ttm->state == tt_bound)return 0 ; - ret = ttm->bdev->driver->ttm_tt_populate (ttm); + ret = ttm->bdev->driver->ttm_tt_populate (ttm, &ctx);if (ret)return ret;
drivers/gpu/drm/virtio/virtgpu_object.c +5 -1
@@ -124,13 +124,17 @@ int virtio_gpu_object_get_sg_table(struct virtio_gpu_device *qdev,int ret;struct page **pages = bo->tbo.ttm->pages;int nr_pages = bo->tbo.num_pages; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };/* wtf swapping */ if (bo->pages)return 0 ;if (bo->tbo.ttm->state == tt_unpopulated) - bo->tbo.ttm->bdev->driver->ttm_tt_populate (bo->tbo.ttm); + bo->tbo.ttm->bdev->driver->ttm_tt_populate (bo->tbo.ttm, &ctx); bo->pages =kmalloc (sizeof (struct sg_table ),GFP_KERNEL );if (!bo->pages) goto out;
drivers/gpu/drm/virtio/virtgpu_ttm.c +3 -2
@@ -324,12 +324,13 @@ static struct ttm_backend_func virtio_gpu_backend_func = { .destroy = &virtio_gpu_ttm_backend_destroy, }; -static int virtio_gpu_ttm_tt_populate (struct ttm_tt *ttm) +static int virtio_gpu_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) {if (ttm->state != tt_unpopulated)return 0 ; -return ttm_pool_populate (ttm); +return ttm_pool_populate (ttm, ctx); }static void virtio_gpu_ttm_tt_unpopulate (struct ttm_tt *ttm)
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +5 -8
@@ -635,16 +635,12 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm) } -static int vmw_ttm_populate (struct ttm_tt *ttm) +static int vmw_ttm_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx) {struct vmw_ttm_tt *vmw_tt = container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv); -struct ttm_operation_ctx ctx = { - .interruptible = true, - .no_wait_gpu = false - };int ret;if (ttm->state != tt_unpopulated)
@@ -653,15 +649,16 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)if (dev_priv->map_mode == vmw_dma_alloc_coherent) {size_t size =ttm_round_pot (ttm->num_pages *sizeof (dma_addr_t)); - ret =ttm_mem_global_alloc (glob, size, &ctx); + ret =ttm_mem_global_alloc (glob, size, ctx);if (unlikely (ret !=0 ))return ret; - ret =ttm_dma_populate (&vmw_tt->dma_ttm, dev_priv->dev->dev); + ret =ttm_dma_populate (&vmw_tt->dma_ttm, dev_priv->dev->dev, + ctx);if (unlikely (ret !=0 ))ttm_mem_global_free (glob, size); }else - ret =ttm_pool_populate (ttm); + ret =ttm_pool_populate (ttm, ctx);return ret; }
drivers/gpu/drm/vmwgfx/vmwgfx_mob.c +11 -2
@@ -240,6 +240,10 @@ static int vmw_otable_batch_setup(struct vmw_private *dev_priv,unsigned long offset;unsigned long bo_size;struct vmw_otable *otables = batch->otables; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };SVGAOTableType i;int ret;
@@ -264,7 +268,7 @@ static int vmw_otable_batch_setup(struct vmw_private *dev_priv, ret =ttm_bo_reserve (batch->otable_bo, false, true,NULL );BUG_ON (ret !=0 ); - ret = vmw_bo_driver.ttm_tt_populate (batch->otable_bo->ttm); + ret = vmw_bo_driver.ttm_tt_populate (batch->otable_bo->ttm, &ctx);if (unlikely (ret !=0 )) goto out_unreserve; ret =vmw_bo_map_dma (batch->otable_bo);
@@ -430,6 +434,11 @@ static int vmw_mob_pt_populate(struct vmw_private *dev_priv, struct vmw_mob *mob) {int ret; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + }; +BUG_ON (mob->pt_bo !=NULL ); ret = ttm_bo_create(&dev_priv->bdev, mob->num_pages * PAGE_SIZE,
@@ -442,7 +451,7 @@ static int vmw_mob_pt_populate(struct vmw_private *dev_priv, ret =ttm_bo_reserve (mob->pt_bo, false, true,NULL );BUG_ON (ret !=0 ); - ret = vmw_bo_driver.ttm_tt_populate (mob->pt_bo->ttm); + ret = vmw_bo_driver.ttm_tt_populate (mob->pt_bo->ttm, &ctx);if (unlikely (ret !=0 )) goto out_unreserve; ret =vmw_bo_map_dma (mob->pt_bo);
include/drm/ttm/ttm_bo_driver.h +3 -2
@@ -352,7 +352,8 @@ struct ttm_bo_driver {* Returns: * -ENOMEM: Out of memory. */ -int (*ttm_tt_populate)(struct ttm_tt *ttm); +int (*ttm_tt_populate)(struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx);/** * ttm_tt_unpopulate
@@ -1077,7 +1078,7 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,struct agp_bridge_data *bridge, unsigned long size, uint32_t page_flags, struct page *dummy_read_page); -int ttm_agp_tt_populate (struct ttm_tt *ttm); +int ttm_agp_tt_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx);void ttm_agp_tt_unpopulate (struct ttm_tt *ttm);#endif
include/drm/ttm/ttm_page_alloc.h +7 -4
@@ -47,7 +47,7 @@ void ttm_page_alloc_fini(void);* * Add backing pages to all of @ttm */ -int ttm_pool_populate (struct ttm_tt *ttm); +int ttm_pool_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx);/** * ttm_pool_unpopulate:
@@ -61,7 +61,8 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm);/** * Populates and DMA maps pages to fullfil a ttm_dma_populate() request */ -int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt); +int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt, +struct ttm_operation_ctx *ctx);/** * Unpopulates and DMA unmaps pages as part of a
@@ -89,7 +90,8 @@ void ttm_dma_page_alloc_fini(void);*/ int ttm_dma_page_alloc_debugfs (struct seq_file *m,void *data); -int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev); +int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev, +struct ttm_operation_ctx *ctx);void ttm_dma_unpopulate (struct ttm_dma_tt *ttm_dma,struct device *dev);#else
@@ -106,7 +108,8 @@ static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)return 0 ; }static inline int ttm_dma_populate (struct ttm_dma_tt *ttm_dma, -struct device *dev) +struct device *dev, +struct ttm_operation_ctx *ctx) {return -ENOMEM ; }
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 4/7] drm/ttm: use an operation ctx for ttm_tt_populate in ttm_bo_driver
Am 20.12.2017 um 11:34 schrieb Roger He:
Quoted 2 lines
Change-Id I803ea52d11e5c06add0dffab836c3aecc00b56ddSigned-off-by Roger He <[email protected]>
Commit message! And please double check the coding style of ast_ttm_tt_populate.
With that fixed that patch is Reviewed-by: Christian König <[email protected]>.
Regards,
Christian.
Quoted 545 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++--- drivers/gpu/drm/ast/ast_ttm.c | 5 +++-- drivers/gpu/drm/cirrus/cirrus_ttm.c | 5 +++-- drivers/gpu/drm/nouveau/nouveau_bo.c | 8 ++++---- drivers/gpu/drm/qxl/qxl_ttm.c | 5 +++-- drivers/gpu/drm/radeon/radeon_ttm.c | 9 +++++---- drivers/gpu/drm/ttm/ttm_agp_backend.c | 4 ++-- drivers/gpu/drm/ttm/ttm_bo_util.c | 11 ++++++++--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 7 ++++++- drivers/gpu/drm/ttm/ttm_page_alloc.c | 13 +++++-------- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 11 ++++------- drivers/gpu/drm/ttm/ttm_tt.c | 6 +++++- drivers/gpu/drm/virtio/virtgpu_object.c | 6 +++++- drivers/gpu/drm/virtio/virtgpu_ttm.c | 5 +++-- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 +++++-------- drivers/gpu/drm/vmwgfx/vmwgfx_mob.c | 13 +++++++++++-- include/drm/ttm/ttm_bo_driver.h | 5 +++-- include/drm/ttm/ttm_page_alloc.h | 11 +++++++---- 18 files changed, 86 insertions(+), 58 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +4
-3@@ -990,7 +990,8 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_bo_device *bdev,return >t->ttm.ttm; } -static int amdgpu_ttm_tt_populate (struct ttm_tt *ttm) +static int amdgpu_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) {struct amdgpu_device *adev =amdgpu_ttm_adev (ttm->bdev);struct amdgpu_ttm_tt *gtt = (void *)ttm;@@ -1018,11 +1019,11 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm)#ifdef CONFIG_SWIOTLB if (swiotlb_nr_tbl ()) { -return ttm_dma_populate (>t->ttm, adev->dev); +return ttm_dma_populate (>t->ttm, adev->dev, ctx); }#endif -return ttm_populate_and_map_pages (adev->dev, >t->ttm); +return ttm_populate_and_map_pages (adev->dev, >t->ttm, ctx); }static void amdgpu_ttm_tt_unpopulate (struct ttm_tt *ttm)drivers/gpu/drm/ast/ast_ttm.c +3
-2@@ -216,9 +216,10 @@ static struct ttm_tt *ast_ttm_tt_create(struct ttm_bo_device *bdev,return tt; } -static int ast_ttm_tt_populate (struct ttm_tt *ttm) +static int ast_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) { -return ttm_pool_populate (ttm); +return ttm_pool_populate (ttm, ctx); }static void ast_ttm_tt_unpopulate (struct ttm_tt *ttm)drivers/gpu/drm/cirrus/cirrus_ttm.c +3
-2@@ -216,9 +216,10 @@ static struct ttm_tt *cirrus_ttm_tt_create(struct ttm_bo_device *bdev,return tt; } -static int cirrus_ttm_tt_populate (struct ttm_tt *ttm) +static int cirrus_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) { -return ttm_pool_populate (ttm); +return ttm_pool_populate (ttm, ctx); }static void cirrus_ttm_tt_unpopulate (struct ttm_tt *ttm)drivers/gpu/drm/nouveau/nouveau_bo.c +4
-4@@ -1547,7 +1547,7 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) }static int -nouveau_ttm_tt_populate (struct ttm_tt *ttm) +nouveau_ttm_tt_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx) {struct ttm_dma_tt *ttm_dma = (void *)ttm;struct nouveau_drm *drm;@@ -1572,17 +1572,17 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)#if IS_ENABLED (CONFIG_AGP )if (drm->agp.bridge) { -return ttm_agp_tt_populate (ttm); +return ttm_agp_tt_populate (ttm, ctx); }#endif #if IS_ENABLED (CONFIG_SWIOTLB ) &&IS_ENABLED (CONFIG_X86 )if (swiotlb_nr_tbl ()) { -return ttm_dma_populate ((void *)ttm, dev); +return ttm_dma_populate ((void *)ttm, dev, ctx); }#endif - r =ttm_pool_populate (ttm); + r =ttm_pool_populate (ttm, ctx);if (r) {return r; }drivers/gpu/drm/qxl/qxl_ttm.c +3
-2@@ -291,14 +291,15 @@ static struct ttm_backend_func qxl_backend_func = { .destroy = &qxl_ttm_backend_destroy, }; -static int qxl_ttm_tt_populate (struct ttm_tt *ttm) +static int qxl_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) {int r;if (ttm->state != tt_unpopulated)return 0 ; - r =ttm_pool_populate (ttm); + r =ttm_pool_populate (ttm, ctx);if (r)return r;drivers/gpu/drm/radeon/radeon_ttm.c +5
-4@@ -721,7 +721,8 @@ static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm)return (struct radeon_ttm_tt *)ttm; } -static int radeon_ttm_tt_populate (struct ttm_tt *ttm) +static int radeon_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) {struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);struct radeon_device *rdev;@@ -750,17 +751,17 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm) rdev =radeon_get_rdev (ttm->bdev);#if IS_ENABLED (CONFIG_AGP )if (rdev->flags &RADEON_IS_AGP ) { -return ttm_agp_tt_populate (ttm); +return ttm_agp_tt_populate (ttm, ctx); }#endif #ifdef CONFIG_SWIOTLB if (swiotlb_nr_tbl ()) { -return ttm_dma_populate (>t->ttm, rdev->dev); +return ttm_dma_populate (>t->ttm, rdev->dev, ctx); }#endif -return ttm_populate_and_map_pages (rdev->dev, >t->ttm); +return ttm_populate_and_map_pages (rdev->dev, >t->ttm, ctx); }static void radeon_ttm_tt_unpopulate (struct ttm_tt *ttm)drivers/gpu/drm/ttm/ttm_agp_backend.c +2
-2@@ -133,12 +133,12 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev, }EXPORT_SYMBOL (ttm_agp_tt_create); -int ttm_agp_tt_populate (struct ttm_tt *ttm) +int ttm_agp_tt_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx) {if (ttm->state != tt_unpopulated)return 0 ; -return ttm_pool_populate (ttm); +return ttm_pool_populate (ttm, ctx); }EXPORT_SYMBOL (ttm_agp_tt_populate);drivers/gpu/drm/ttm/ttm_bo_util.c +8
-3@@ -376,7 +376,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,* TTM might be null for moves within the same region. */ if (ttm && ttm->state == tt_unpopulated) { - ret = ttm->bdev->driver->ttm_tt_populate (ttm); + ret = ttm->bdev->driver->ttm_tt_populate (ttm, ctx);if (ret) goto out1; }@@ -545,14 +545,19 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,unsigned long num_pages, struct ttm_bo_kmap_obj *map) { - struct ttm_mem_reg *mem = &bo->mem; pgprot_t prot; + struct ttm_mem_reg *mem = &bo->mem; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };struct ttm_tt *ttm = bo->ttm; +pgprot_t prot;int ret;BUG_ON (!ttm);if (ttm->state == tt_unpopulated) { - ret = ttm->bdev->driver->ttm_tt_populate (ttm); + ret = ttm->bdev->driver->ttm_tt_populate (ttm, &ctx);if (ret)return ret; }drivers/gpu/drm/ttm/ttm_bo_vm.c +6
-1@@ -215,12 +215,17 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf) cvma.vm_page_prot =ttm_io_prot (bo->mem.placement, cvma.vm_page_prot); }else { +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + }; + ttm = bo->ttm; cvma.vm_page_prot =ttm_io_prot (bo->mem.placement, cvma.vm_page_prot);/* Allocate all page at once, most common usage */ -if (ttm->bdev->driver->ttm_tt_populate (ttm)) { +if (ttm->bdev->driver->ttm_tt_populate (ttm, &ctx)) { retval =VM_FAULT_OOM ; goto out_io_unlock; }drivers/gpu/drm/ttm/ttm_page_alloc.c +5
-8@@ -1058,13 +1058,9 @@ void ttm_page_alloc_fini(void) _manager =NULL ; } -int ttm_pool_populate (struct ttm_tt *ttm) +int ttm_pool_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx) {struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - };unsigned i;int ret;@@ -1080,7 +1076,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)for (i =0 ; i < ttm->num_pages; ++i) { ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], -PAGE_SIZE , &ctx); +PAGE_SIZE , ctx);if (unlikely (ret !=0 )) {ttm_pool_unpopulate (ttm);return -ENOMEM ;@@ -1117,12 +1113,13 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm) }EXPORT_SYMBOL (ttm_pool_unpopulate); -int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt) +int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt, +struct ttm_operation_ctx *ctx) {unsigned i, j;int r; - r =ttm_pool_populate (&tt->ttm); + r =ttm_pool_populate (&tt->ttm, ctx);if (r)return r;drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +4
-7@@ -923,14 +923,11 @@ static gfp_t ttm_dma_pool_gfp_flags(struct ttm_dma_tt *ttm_dma, bool huge)* On success pages list will hold count number of correctly * cached pages. On failure will hold the negative return value (-ENOMEM, etc). */ -int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev) +int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev, +struct ttm_operation_ctx *ctx) {struct ttm_tt *ttm = &ttm_dma->ttm;struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - };unsigned long num_pages = ttm->num_pages;struct dma_pool *pool;enum pool_type type;@@ -966,7 +963,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)break ; ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size, &ctx); + pool->size, ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;@@ -1002,7 +999,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev) } ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size, &ctx); + pool->size, ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;drivers/gpu/drm/ttm/ttm_tt.c +5
-1@@ -263,6 +263,10 @@ void ttm_tt_unbind(struct ttm_tt *ttm)int ttm_tt_bind (struct ttm_tt *ttm,struct ttm_mem_reg *bo_mem) { +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };int ret =0 ;if (!ttm)@@ -271,7 +275,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)if (ttm->state == tt_bound)return 0 ; - ret = ttm->bdev->driver->ttm_tt_populate (ttm); + ret = ttm->bdev->driver->ttm_tt_populate (ttm, &ctx);if (ret)return ret;drivers/gpu/drm/virtio/virtgpu_object.c +5
-1@@ -124,13 +124,17 @@ int virtio_gpu_object_get_sg_table(struct virtio_gpu_device *qdev,int ret;struct page **pages = bo->tbo.ttm->pages;int nr_pages = bo->tbo.num_pages; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };/* wtf swapping */ if (bo->pages)return 0 ;if (bo->tbo.ttm->state == tt_unpopulated) - bo->tbo.ttm->bdev->driver->ttm_tt_populate (bo->tbo.ttm); + bo->tbo.ttm->bdev->driver->ttm_tt_populate (bo->tbo.ttm, &ctx); bo->pages =kmalloc (sizeof (struct sg_table ),GFP_KERNEL );if (!bo->pages) goto out;drivers/gpu/drm/virtio/virtgpu_ttm.c +3
-2@@ -324,12 +324,13 @@ static struct ttm_backend_func virtio_gpu_backend_func = { .destroy = &virtio_gpu_ttm_backend_destroy, }; -static int virtio_gpu_ttm_tt_populate (struct ttm_tt *ttm) +static int virtio_gpu_ttm_tt_populate (struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx) {if (ttm->state != tt_unpopulated)return 0 ; -return ttm_pool_populate (ttm); +return ttm_pool_populate (ttm, ctx); }static void virtio_gpu_ttm_tt_unpopulate (struct ttm_tt *ttm)drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +5
-8@@ -635,16 +635,12 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm) } -static int vmw_ttm_populate (struct ttm_tt *ttm) +static int vmw_ttm_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx) {struct vmw_ttm_tt *vmw_tt = container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv); -struct ttm_operation_ctx ctx = { - .interruptible = true, - .no_wait_gpu = false - };int ret;if (ttm->state != tt_unpopulated)@@ -653,15 +649,16 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)if (dev_priv->map_mode == vmw_dma_alloc_coherent) {size_t size =ttm_round_pot (ttm->num_pages *sizeof (dma_addr_t)); - ret =ttm_mem_global_alloc (glob, size, &ctx); + ret =ttm_mem_global_alloc (glob, size, ctx);if (unlikely (ret !=0 ))return ret; - ret =ttm_dma_populate (&vmw_tt->dma_ttm, dev_priv->dev->dev); + ret =ttm_dma_populate (&vmw_tt->dma_ttm, dev_priv->dev->dev, + ctx);if (unlikely (ret !=0 ))ttm_mem_global_free (glob, size); }else - ret =ttm_pool_populate (ttm); + ret =ttm_pool_populate (ttm, ctx);return ret; }drivers/gpu/drm/vmwgfx/vmwgfx_mob.c +11
-2@@ -240,6 +240,10 @@ static int vmw_otable_batch_setup(struct vmw_private *dev_priv,unsigned long offset;unsigned long bo_size;struct vmw_otable *otables = batch->otables; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };SVGAOTableType i;int ret;@@ -264,7 +268,7 @@ static int vmw_otable_batch_setup(struct vmw_private *dev_priv, ret =ttm_bo_reserve (batch->otable_bo, false, true,NULL );BUG_ON (ret !=0 ); - ret = vmw_bo_driver.ttm_tt_populate (batch->otable_bo->ttm); + ret = vmw_bo_driver.ttm_tt_populate (batch->otable_bo->ttm, &ctx);if (unlikely (ret !=0 )) goto out_unreserve; ret =vmw_bo_map_dma (batch->otable_bo);@@ -430,6 +434,11 @@ static int vmw_mob_pt_populate(struct vmw_private *dev_priv, struct vmw_mob *mob) {int ret; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + }; +BUG_ON (mob->pt_bo !=NULL ); ret = ttm_bo_create(&dev_priv->bdev, mob->num_pages * PAGE_SIZE,@@ -442,7 +451,7 @@ static int vmw_mob_pt_populate(struct vmw_private *dev_priv, ret =ttm_bo_reserve (mob->pt_bo, false, true,NULL );BUG_ON (ret !=0 ); - ret = vmw_bo_driver.ttm_tt_populate (mob->pt_bo->ttm); + ret = vmw_bo_driver.ttm_tt_populate (mob->pt_bo->ttm, &ctx);if (unlikely (ret !=0 )) goto out_unreserve; ret =vmw_bo_map_dma (mob->pt_bo);include/drm/ttm/ttm_bo_driver.h +3
-2@@ -352,7 +352,8 @@ struct ttm_bo_driver {* Returns: * -ENOMEM: Out of memory. */ -int (*ttm_tt_populate)(struct ttm_tt *ttm); +int (*ttm_tt_populate)(struct ttm_tt *ttm, +struct ttm_operation_ctx *ctx);/** * ttm_tt_unpopulate @@ -1077,7 +1078,7 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,struct agp_bridge_data *bridge, unsigned long size, uint32_t page_flags, struct page *dummy_read_page); -int ttm_agp_tt_populate (struct ttm_tt *ttm); +int ttm_agp_tt_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx);void ttm_agp_tt_unpopulate (struct ttm_tt *ttm);#endif include/drm/ttm/ttm_page_alloc.h +5
-3@@ -47,7 +47,7 @@ void ttm_page_alloc_fini(void);* * Add backing pages to all of @ttm */ -int ttm_pool_populate (struct ttm_tt *ttm); +int ttm_pool_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx);/** * ttm_pool_unpopulate: @@ -61,7 +61,8 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm);/** * Populates and DMA maps pages to fullfil a ttm_dma_populate() request */ -int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt); +int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt, +struct ttm_operation_ctx *ctx);/** * Unpopulates and DMA unmaps pages as part of a @@ -89,7 +90,8 @@ void ttm_dma_page_alloc_fini(void);*/ int ttm_dma_page_alloc_debugfs (struct seq_file *m,void *data); -int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev); +int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev, +struct ttm_operation_ctx *ctx);void ttm_dma_unpopulate (struct ttm_dma_tt *ttm_dma,struct device *dev);#else
include/drm/ttm/ttm_page_alloc.h static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data) · line 115
Quoted 9 lines
include/drm/ttm/ttm_page_alloc.h +2
-1@@ -106,7 +108,8 @@ static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)return 0 ; }static inline int ttm_dma_populate (struct ttm_dma_tt *ttm_dma, -struct device *dev) +struct device *dev, +struct ttm_operation_ctx *ctx) {return -ENOMEM ; }
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/7 drm/ttm: use an operation ctx for ttm_tt_bind
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/nouveau/nouveau_bo.c | 2 +- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +- drivers/gpu/drm/ttm/ttm_tt.c | 9 +++------ include/drm/ttm/ttm_bo_driver.h | 3 ++- 7 files changed, 10 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
@@ -497,7 +497,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict, goto out_cleanup; } - r =ttm_tt_bind (bo->ttm, &tmp_mem); + r =ttm_tt_bind (bo->ttm, &tmp_mem, ctx);if (unlikely (r)) { goto out_cleanup; }
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -1
@@ -1218,7 +1218,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,if (ret)return ret; - ret =ttm_tt_bind (bo->ttm, &tmp_reg); + ret =ttm_tt_bind (bo->ttm, &tmp_reg, &ctx);if (ret) goto out;
drivers/gpu/drm/radeon/radeon_ttm.c +1 -1
@@ -339,7 +339,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo, goto out_cleanup; } - r =ttm_tt_bind (bo->ttm, &tmp_mem); + r =ttm_tt_bind (bo->ttm, &tmp_mem, &ctx);if (unlikely (r)) { goto out_cleanup; }
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -300,7 +300,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, goto out_err;if (mem->mem_type !=TTM_PL_SYSTEM ) { - ret =ttm_tt_bind (bo->ttm, mem); + ret =ttm_tt_bind (bo->ttm, mem, ctx);if (ret) goto out_err; }
drivers/gpu/drm/ttm/ttm_bo_util.c +1 -1
@@ -73,7 +73,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,return ret;if (new_mem->mem_type !=TTM_PL_SYSTEM ) { - ret =ttm_tt_bind (ttm, new_mem); + ret =ttm_tt_bind (ttm, new_mem, ctx);if (unlikely (ret !=0 ))return ret; }
drivers/gpu/drm/ttm/ttm_tt.c +3 -6
@@ -261,12 +261,9 @@ void ttm_tt_unbind(struct ttm_tt *ttm) } } -int ttm_tt_bind (struct ttm_tt *ttm,struct ttm_mem_reg *bo_mem) +int ttm_tt_bind (struct ttm_tt *ttm,struct ttm_mem_reg *bo_mem, +struct ttm_operation_ctx *ctx) { -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - };int ret =0 ;if (!ttm)
@@ -275,7 +272,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)if (ttm->state == tt_bound)return 0 ; - ret = ttm->bdev->driver->ttm_tt_populate (ttm, &ctx); + ret = ttm->bdev->driver->ttm_tt_populate (ttm, ctx);if (ret)return ret;
include/drm/ttm/ttm_bo_driver.h +2 -1
@@ -650,7 +650,8 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);* * Bind the pages of @ttm to an aperture location identified by @bo_mem */ -int ttm_tt_bind (struct ttm_tt *ttm,struct ttm_mem_reg *bo_mem); +int ttm_tt_bind (struct ttm_tt *ttm,struct ttm_mem_reg *bo_mem, +struct ttm_operation_ctx *ctx);/** * ttm_ttm_destroy:
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 7/7 drm/ttm: enable swapout of per VM BOs during allocation and allows reaping of deleted BOs
In reply to a message not in the archive--- drivers/gpu/drm/ttm/ttm_bo.c | 15 +++++++++++---- drivers/gpu/drm/ttm/ttm_memory.c | 12 ++++++++---- include/drm/ttm/ttm_bo_api.h | 3 ++- 3 files changed, 21 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +11 -4
@@ -1686,18 +1686,20 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);* A buffer object shrink method that tries to swap out the first * buffer object on the bo_global::swap_lru list. */ -int ttm_bo_swapout (struct ttm_bo_global *glob) +int ttm_bo_swapout (struct ttm_bo_global *glob,struct ttm_operation_ctx *ctx) {struct ttm_buffer_object *bo;int ret = -EBUSY ; +bool locked;unsigned i;spin_lock (&glob->lru_lock);for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {list_for_each_entry (bo, &glob->swap_lru[i], swap) { - ret =reservation_object_trylock (bo->resv) ?0 : -EBUSY ; -if (!ret) +if (ttm_bo_evict_swapout_allowable (bo, ctx, &locked)) { + ret =0 ;break ; + } }if (!ret)break ;
@@ -1773,7 +1775,12 @@ EXPORT_SYMBOL(ttm_bo_swapout);void ttm_bo_swapout_all (struct ttm_bo_device *bdev) { -while (ttm_bo_swapout (bdev->glob) ==0 ) +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + }; + +while (ttm_bo_swapout (bdev->glob, &ctx) ==0 ) ; }EXPORT_SYMBOL (ttm_bo_swapout_all);
drivers/gpu/drm/ttm/ttm_memory.c +8 -4
@@ -211,7 +211,7 @@ static bool ttm_zones_above_swap_target(struct ttm_mem_global *glob,*/ static void ttm_shrink (struct ttm_mem_global *glob,bool from_wq, -uint64_t extra) +uint64_t extra,struct ttm_operation_ctx *ctx) {int ret;
@@ -219,7 +219,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,while (ttm_zones_above_swap_target (glob, from_wq, extra)) {spin_unlock (&glob->lock); - ret =ttm_bo_swapout (glob->bo_glob); + ret =ttm_bo_swapout (glob->bo_glob, ctx);spin_lock (&glob->lock);if (unlikely (ret !=0 ))break ;
@@ -230,10 +230,14 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,static void ttm_shrink_work (struct work_struct *work) { +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };struct ttm_mem_global *glob = container_of(work, struct ttm_mem_global, work); -ttm_shrink (glob, true,0ULL ); +ttm_shrink (glob, true,0ULL , &ctx); } static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
@@ -520,7 +524,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,return -ENOMEM ;if (unlikely (count-- ==0 ))return -ENOMEM ; -ttm_shrink (glob, false, memory + (memory >>2 ) +16 ); +ttm_shrink (glob, false, memory + (memory >>2 ) +16 , ctx); }return 0 ;
include/drm/ttm/ttm_bo_api.h +2 -1
@@ -752,7 +752,8 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, const char __user *wbuf, char __user *rbuf, size_t count, loff_t *f_pos, bool write); -int ttm_bo_swapout (struct ttm_bo_global *glob); +int ttm_bo_swapout (struct ttm_bo_global *glob, +struct ttm_operation_ctx *ctx);void ttm_bo_swapout_all (struct ttm_bo_device *bdev);int ttm_bo_wait_unreserved (struct ttm_buffer_object *bo);#endif
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): 1513766101-15993-7-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 7/7] drm/ttm: enable swapout of per VM BOs during allocation and allows reaping of deleted BOs
What about
"Enable recursive locking at swapout time to make it possible to swap out BOs that share the same reservation object."
Is "per VM BOs" an AMD specific name? In that case, I'd avoid using it in the TTM code since most people have no idea what they are and why the need specific treatment in TTM.
/Thomas
Quoted 102 lines · Roger He
Change-Id I1e87954564f38ad298bf6e4ff88c9f26f291a62dSigned-off-by Roger He <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 15 +++++++++++---- drivers/gpu/drm/ttm/ttm_memory.c | 12 ++++++++---- include/drm/ttm/ttm_bo_api.h | 3 ++- 3 files changed, 21 insertions(+), 9 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +11
-4@@ -1686,18 +1686,20 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);* A buffer object shrink method that tries to swap out the first * buffer object on the bo_global::swap_lru list. */ -int ttm_bo_swapout (struct ttm_bo_global *glob) +int ttm_bo_swapout (struct ttm_bo_global *glob,struct ttm_operation_ctx *ctx) {struct ttm_buffer_object *bo;int ret = -EBUSY ; +bool locked;unsigned i;spin_lock (&glob->lru_lock);for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {list_for_each_entry (bo, &glob->swap_lru[i], swap) { - ret =reservation_object_trylock (bo->resv) ?0 : -EBUSY ; -if (!ret) +if (ttm_bo_evict_swapout_allowable (bo, ctx, &locked)) { + ret =0 ;break ; + } }if (!ret)break ;@@ -1773,7 +1775,12 @@ EXPORT_SYMBOL(ttm_bo_swapout);void ttm_bo_swapout_all (struct ttm_bo_device *bdev) { -while (ttm_bo_swapout (bdev->glob) ==0 ) +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + }; + +while (ttm_bo_swapout (bdev->glob, &ctx) ==0 ) ; }EXPORT_SYMBOL (ttm_bo_swapout_all);drivers/gpu/drm/ttm/ttm_memory.c +8
-4@@ -211,7 +211,7 @@ static bool ttm_zones_above_swap_target(struct ttm_mem_global *glob,*/ static void ttm_shrink (struct ttm_mem_global *glob,bool from_wq, -uint64_t extra) +uint64_t extra,struct ttm_operation_ctx *ctx) {int ret;@@ -219,7 +219,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,while (ttm_zones_above_swap_target (glob, from_wq, extra)) {spin_unlock (&glob->lock); - ret =ttm_bo_swapout (glob->bo_glob); + ret =ttm_bo_swapout (glob->bo_glob, ctx);spin_lock (&glob->lock);if (unlikely (ret !=0 ))break ;@@ -230,10 +230,14 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,static void ttm_shrink_work (struct work_struct *work) { +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };struct ttm_mem_global *glob = container_of(work, struct ttm_mem_global, work); -ttm_shrink (glob, true,0ULL ); +ttm_shrink (glob, true,0ULL , &ctx); } static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,@@ -520,7 +524,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,return -ENOMEM ;if (unlikely (count-- ==0 ))return -ENOMEM ; -ttm_shrink (glob, false, memory + (memory >>2 ) +16 ); +ttm_shrink (glob, false, memory + (memory >>2 ) +16 , ctx); }return 0 ;include/drm/ttm/ttm_bo_api.h +0
-0
include/drm/ttm/ttm_bo_api.h ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, · line 759
Quoted 9 lines
include/drm/ttm/ttm_bo_api.h +2
-1@@ -752,7 +752,8 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, const char __user *wbuf, char __user *rbuf, size_t count, loff_t *f_pos, bool write); -int ttm_bo_swapout (struct ttm_bo_global *glob); +int ttm_bo_swapout (struct ttm_bo_global *glob, +struct ttm_operation_ctx *ctx);void ttm_bo_swapout_all (struct ttm_bo_device *bdev);int ttm_bo_wait_unreserved (struct ttm_buffer_object *bo);#endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 7/7] drm/ttm: enable swapout of per VM BOs during allocation and allows reaping of deleted BOs
Am 21.12.2017 um 08:58 schrieb Thomas Hellstrom:
Quoted 5 lines
What about
"Enable recursive locking at swapout time to make it possible to swap out BOs that share the same reservation object."
Is "per VM BOs" an AMD specific name?
Yes, absolutely. It's even amdgpu specific, radeon uses the same functionality but a bit different and not for user mode allocations.
Quoted 1 line
In that case, I'd avoid using it in the TTM code since most people have no idea what they are and why the need specific treatment in TTM.
Good point, going to keep that in mind when reviewing the patch set.
Christian.
Quoted 109 lines
/Thomas
Quoted 104 lines · Roger He
Change-Id I1e87954564f38ad298bf6e4ff88c9f26f291a62dSigned-off-by Roger He <[email protected]>---
drivers/gpu/drm/ttm/ttm_bo.c | 15 +++++++++++----drivers/gpu/drm/ttm/ttm_memory.c| 12 ++++++++---- include/drm/ttm/ttm_bo_api.h | 3 ++-3 files changed, 21 insertions(+), 9 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +11
-4@@ -1686,18 +1686,20 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);* A buffer object shrink method that tries to swap out the first * buffer object on the bo_global::swap_lru list. */ -int ttm_bo_swapout (struct ttm_bo_global *glob) +int ttm_bo_swapout (struct ttm_bo_global *glob,struct ttm_operation_ctx *ctx) { struct ttm_buffer_object *bo; int ret = -EBUSY; + bool locked; unsigned i; spin_lock(&glob->lru_lock); for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { list_for_each_entry(bo, &glob->swap_lru[i], swap) { - ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY; - if (!ret) + if (ttm_bo_evict_swapout_allowable(bo, ctx, &locked)) { + ret = 0; break; + } } if (!ret) break;@@ -1773,7 +1775,12 @@ EXPORT_SYMBOL(ttm_bo_swapout); void ttm_bo_swapout_all(struct ttm_bo_device *bdev) { - while (ttm_bo_swapout(bdev->glob) == 0) + struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + }; + + while (ttm_bo_swapout(bdev->glob, &ctx) == 0) ; } EXPORT_SYMBOL(ttm_bo_swapout_all);drivers/gpu/drm/ttm/ttm_memory.c +1
-1@@ -211,7 +211,7 @@ static bool ttm_zones_above_swap_target(structttm_mem_global *glob, */ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, - uint64_t extra) + uint64_t extra, struct ttm_operation_ctx *ctx) { int ret; @@ -219,7 +219,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,while (
ttm_zones_above_swap_target(glob, from_wq, extra)) {spin_unlock(&glob->lock);
- ret =ttm_bo_swapout(glob->bo_glob);
+ ret =ttm_bo_swapout(glob->bo_glob, ctx);spin_lock(&glob->lock);
if (unlikely(ret != 0))
break;drivers/gpu/drm/ttm/ttm_memory.c +4
-0@@ -230,10 +230,14 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, static void ttm_shrink_work(struct work_struct *work) { + struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };struct
ttm_mem_global*glob =
container_of(work, struct ttm_mem_global, work); -ttm_shrink(glob, true, 0ULL);
+ttm_shrink(glob, true, 0ULL, &ctx);
}
static int ttm_mem_init_kernel_zone(structttm_mem_global*glob,drivers/gpu/drm/ttm/ttm_memory.c +1
-1@@ -520,7 +524,7 @@ static int ttm_mem_global_alloc_zone(structttm_mem_global *glob, return -ENOMEM; if (unlikely(count-- == 0)) return -ENOMEM; - ttm_shrink(glob, false, memory + (memory >> 2) + 16); + ttm_shrink(glob, false, memory + (memory >> 2) + 16, ctx); } return 0;include/drm/ttm/ttm_bo_api.h +2
-0@@ -752,7 +752,8 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev,struct file *filp, const char __user *wbuf, char __user *rbuf, size_t count, loff_t *f_pos, bool write); -int ttm_bo_swapout(struct ttm_bo_global *glob); +int ttm_bo_swapout (struct ttm_bo_global *glob, + struct ttm_operation_ctx *ctx); void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
Quoted 8 lines
Quoted 2 lines
include/drm/ttm/ttm_bo_api.h +0
-0int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);#endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 20.12.2017 um 11:34 schrieb Roger He:
Quoted 1 line
then remove superfluous functions
We need a better commit message. Something like:
Remove the extra indirection, cause we have only one implementation anyway.
Quoted 3 lines
Change-Id Iea020f0e30a239e0265e7a1500168c7d7f819bd9Signed-off-by Roger He <[email protected]>
With the commit message fixed Reviewed-by: Christian König <[email protected]>.
Regards,
Christian.
Quoted 228 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 21 +++--------- drivers/gpu/drm/ttm/ttm_memory.c | 12 ++----- include/drm/ttm/ttm_bo_api.h | 1 + include/drm/ttm/ttm_bo_driver.h | 1 - include/drm/ttm/ttm_memory.h | 69 +--------------------------------------- 5 files changed, 9 insertions(+), 95 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +4
-17@@ -42,7 +42,6 @@#include <linux/atomic.h> #include <linux/reservation.h> -static int ttm_bo_swapout (struct ttm_mem_shrink *shrink);static void ttm_bo_global_kobj_release (struct kobject *kobj);static struct attribute ttm_bo_count = {@@ -1454,7 +1453,6 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj)struct ttm_bo_global *glob = container_of(kobj, struct ttm_bo_global, kobj); -ttm_mem_unregister_shrink (glob->mem_glob, &glob->shrink);__free_page (glob->dummy_read_page);kfree (glob); }@@ -1479,6 +1477,7 @@ int ttm_bo_global_init(struct drm_global_reference *ref)mutex_init (&glob->device_list_mutex);spin_lock_init (&glob->lru_lock); glob->mem_glob = bo_ref->mem_glob; + glob->mem_glob->bo_glob = glob; glob->dummy_read_page =alloc_page (__GFP_ZERO |GFP_DMA32 );if (unlikely (glob->dummy_read_page ==NULL )) {@@ -1489,14 +1488,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i)INIT_LIST_HEAD (&glob->swap_lru[i]);INIT_LIST_HEAD (&glob->device_list); - -ttm_mem_init_shrink (&glob->shrink, ttm_bo_swapout); - ret =ttm_mem_register_shrink (glob->mem_glob, &glob->shrink); -if (unlikely (ret !=0 )) { -pr_err ("Could not register buffer object swapout\n" ); - goto out_no_shrink; - } -atomic_set (&glob->bo_count,0 ); ret = kobject_init_and_add(@@ -1504,8 +1495,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)if (unlikely (ret !=0 ))kobject_put (&glob->kobj);return ret; -out_no_shrink: -__free_page (glob->dummy_read_page); out_no_drp:kfree (glob);return ret;@@ -1688,11 +1677,8 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);* A buffer object shrink method that tries to swap out the first * buffer object on the bo_global::swap_lru list. */ - -static int ttm_bo_swapout (struct ttm_mem_shrink *shrink) +int ttm_bo_swapout (struct ttm_bo_global *glob) { -struct ttm_bo_global *glob = - container_of(shrink, struct ttm_bo_global, shrink);struct ttm_buffer_object *bo;int ret = -EBUSY ;unsigned i;@@ -1774,10 +1760,11 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)kref_put (&bo->list_kref, ttm_bo_release_list);return ret; } +EXPORT_SYMBOL (ttm_bo_swapout);void ttm_bo_swapout_all (struct ttm_bo_device *bdev) { -while (ttm_bo_swapout (&bdev->glob->shrink) ==0 ) +while (ttm_bo_swapout (bdev->glob) ==0 ) ; }EXPORT_SYMBOL (ttm_bo_swapout_all);drivers/gpu/drm/ttm/ttm_memory.c +3
-9@@ -214,26 +214,20 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, uint64_t extra) {int ret; -struct ttm_mem_shrink *shrink;spin_lock (&glob->lock); -if (glob->shrink ==NULL ) - goto out;while (ttm_zones_above_swap_target (glob, from_wq, extra)) { - shrink = glob->shrink;spin_unlock (&glob->lock); - ret = shrink->do_shrink (shrink); + ret =ttm_bo_swapout (glob->bo_glob);spin_lock (&glob->lock);if (unlikely (ret !=0 )) - goto out; +break ; } -out: +spin_unlock (&glob->lock); } - -static void ttm_shrink_work (struct work_struct *work) { struct ttm_mem_global *glob =include/drm/ttm/ttm_bo_api.h +1
-0@@ -752,6 +752,7 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, const char __user *wbuf, char __user *rbuf, size_t count, loff_t *f_pos, bool write); +int ttm_bo_swapout (struct ttm_bo_global *glob);void ttm_bo_swapout_all (struct ttm_bo_device *bdev);int ttm_bo_wait_unreserved (struct ttm_buffer_object *bo);#endif include/drm/ttm/ttm_bo_driver.h +0
-1@@ -522,7 +522,6 @@ struct ttm_bo_global {struct kobject kobj;struct ttm_mem_global *mem_glob;struct page *dummy_read_page; -struct ttm_mem_shrink shrink;struct mutex device_list_mutex;spinlock_t lru_lock;include/drm/ttm/ttm_memory.h +1
-61@@ -37,20 +37,6 @@#include <linux/mm.h> /** -* struct ttm_mem_shrink - callback to shrink TTM memory usage. -* -* @do_shrink: The callback function. -* -* Arguments to the do_shrink functions are intended to be passed using -* inheritance. That is, the argument class derives from struct ttm_mem_shrink, -* and can be accessed using container_of(). -*/ - -struct ttm_mem_shrink { -int (*do_shrink) (struct ttm_mem_shrink *); -}; - -/** * struct ttm_mem_global - Global memory accounting structure. * * @shrink: A single callback to shrink TTM memory usage. Extend this @@ -76,7 +62,7 @@ struct ttm_mem_shrink {struct ttm_mem_zone ;struct ttm_mem_global {struct kobject kobj; -struct ttm_mem_shrink *shrink; +struct ttm_bo_global *bo_glob;struct workqueue_struct *swap_queue;struct work_struct work;spinlock_t lock;@@ -90,59 +76,6 @@ struct ttm_mem_global {#endif }; -/** -* ttm_mem_init_shrink - initialize a struct ttm_mem_shrink object -* -* @shrink: The object to initialize. -* @func: The callback function. -*/ - -static inline void ttm_mem_init_shrink (struct ttm_mem_shrink *shrink, -int (*func) (struct ttm_mem_shrink *)) -{ - shrink->do_shrink = func; -} - -/** -* ttm_mem_register_shrink - register a struct ttm_mem_shrink object. -* -* @glob: The struct ttm_mem_global object to register with. -* @shrink: An initialized struct ttm_mem_shrink object to register. -* -* Returns: -* -EBUSY: There's already a callback registered. (May change). -*/ - -static inline int ttm_mem_register_shrink (struct ttm_mem_global *glob, -struct ttm_mem_shrink *shrink) -{ -spin_lock (&glob->lock); -if (glob->shrink !=NULL ) { -spin_unlock (&glob->lock); -return -EBUSY ; - } - glob->shrink = shrink; -spin_unlock (&glob->lock); -return 0 ; -} - -/** -* ttm_mem_unregister_shrink - unregister a struct ttm_mem_shrink object. -* -* @glob: The struct ttm_mem_global object to unregister from. -* @shrink: A previously registert struct ttm_mem_shrink object. -* -*/ - -static inline void ttm_mem_unregister_shrink (struct ttm_mem_global *glob, -struct ttm_mem_shrink *shrink)
include/drm/ttm/ttm_memory.h struct ttm_mem_global { · line 81
Quoted 10 lines
include/drm/ttm/ttm_memory.h +0
-7-{ -spin_lock (&glob->lock); -BUG_ON (glob->shrink != shrink); - glob->shrink =NULL ; -spin_unlock (&glob->lock); -} -extern int ttm_mem_global_init (struct ttm_mem_global *glob);extern void ttm_mem_global_release (struct ttm_mem_global *glob); extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Roger,
5 out of 7 patches in this series are completely lacking a commit log message, and thats not OK. Really.
https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#describe-your-changes
I'll review these, but IIRC the no_wait in the memory accounting code is different in that it doesn't allow sleeping,
whereas in the bo code we had originally had no_wait_gpu and also no_wait. (IIRC Maarten or Jerome removed the latter due to lack of users.) Seems like these patches confuse the to. At the very least that requires some form of motivation.
Also I wonder what testing is being performed on these changes prior to submission? We have pretty high number of critical deployments out there, that we need to support.
/Thomas
Quoted 232 lines · Roger He
then remove superfluous functions
Change-Id Iea020f0e30a239e0265e7a1500168c7d7f819bd9Signed-off-by Roger He <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 21 +++--------- drivers/gpu/drm/ttm/ttm_memory.c | 12 ++----- include/drm/ttm/ttm_bo_api.h | 1 + include/drm/ttm/ttm_bo_driver.h | 1 - include/drm/ttm/ttm_memory.h | 69 +--------------------------------------- 5 files changed, 9 insertions(+), 95 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +4
-17@@ -42,7 +42,6 @@#include <linux/atomic.h> #include <linux/reservation.h> -static int ttm_bo_swapout (struct ttm_mem_shrink *shrink);static void ttm_bo_global_kobj_release (struct kobject *kobj);static struct attribute ttm_bo_count = {@@ -1454,7 +1453,6 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj)struct ttm_bo_global *glob = container_of(kobj, struct ttm_bo_global, kobj); -ttm_mem_unregister_shrink (glob->mem_glob, &glob->shrink);__free_page (glob->dummy_read_page);kfree (glob); }@@ -1479,6 +1477,7 @@ int ttm_bo_global_init(struct drm_global_reference *ref)mutex_init (&glob->device_list_mutex);spin_lock_init (&glob->lru_lock); glob->mem_glob = bo_ref->mem_glob; + glob->mem_glob->bo_glob = glob; glob->dummy_read_page =alloc_page (__GFP_ZERO |GFP_DMA32 );if (unlikely (glob->dummy_read_page ==NULL )) {@@ -1489,14 +1488,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i)INIT_LIST_HEAD (&glob->swap_lru[i]);INIT_LIST_HEAD (&glob->device_list); - -ttm_mem_init_shrink (&glob->shrink, ttm_bo_swapout); - ret =ttm_mem_register_shrink (glob->mem_glob, &glob->shrink); -if (unlikely (ret !=0 )) { -pr_err ("Could not register buffer object swapout\n" ); - goto out_no_shrink; - } -atomic_set (&glob->bo_count,0 ); ret = kobject_init_and_add(@@ -1504,8 +1495,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)if (unlikely (ret !=0 ))kobject_put (&glob->kobj);return ret; -out_no_shrink: -__free_page (glob->dummy_read_page); out_no_drp:kfree (glob);return ret;@@ -1688,11 +1677,8 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);* A buffer object shrink method that tries to swap out the first * buffer object on the bo_global::swap_lru list. */ - -static int ttm_bo_swapout (struct ttm_mem_shrink *shrink) +int ttm_bo_swapout (struct ttm_bo_global *glob) { -struct ttm_bo_global *glob = - container_of(shrink, struct ttm_bo_global, shrink);struct ttm_buffer_object *bo;int ret = -EBUSY ;unsigned i;@@ -1774,10 +1760,11 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)kref_put (&bo->list_kref, ttm_bo_release_list);return ret; } +EXPORT_SYMBOL (ttm_bo_swapout);void ttm_bo_swapout_all (struct ttm_bo_device *bdev) { -while (ttm_bo_swapout (&bdev->glob->shrink) ==0 ) +while (ttm_bo_swapout (bdev->glob) ==0 ) ; }EXPORT_SYMBOL (ttm_bo_swapout_all);drivers/gpu/drm/ttm/ttm_memory.c +3
-9@@ -214,26 +214,20 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, uint64_t extra) {int ret; -struct ttm_mem_shrink *shrink;spin_lock (&glob->lock); -if (glob->shrink ==NULL ) - goto out;while (ttm_zones_above_swap_target (glob, from_wq, extra)) { - shrink = glob->shrink;spin_unlock (&glob->lock); - ret = shrink->do_shrink (shrink); + ret =ttm_bo_swapout (glob->bo_glob);spin_lock (&glob->lock);if (unlikely (ret !=0 )) - goto out; +break ; } -out: +spin_unlock (&glob->lock); } - -static void ttm_shrink_work (struct work_struct *work) { struct ttm_mem_global *glob =include/drm/ttm/ttm_bo_api.h +1
-0@@ -752,6 +752,7 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, const char __user *wbuf, char __user *rbuf, size_t count, loff_t *f_pos, bool write); +int ttm_bo_swapout (struct ttm_bo_global *glob);void ttm_bo_swapout_all (struct ttm_bo_device *bdev);int ttm_bo_wait_unreserved (struct ttm_buffer_object *bo);#endif include/drm/ttm/ttm_bo_driver.h +0
-1@@ -522,7 +522,6 @@ struct ttm_bo_global {struct kobject kobj;struct ttm_mem_global *mem_glob;struct page *dummy_read_page; -struct ttm_mem_shrink shrink;struct mutex device_list_mutex;spinlock_t lru_lock;include/drm/ttm/ttm_memory.h +1
-61@@ -37,20 +37,6 @@#include <linux/mm.h> /** -* struct ttm_mem_shrink - callback to shrink TTM memory usage. -* -* @do_shrink: The callback function. -* -* Arguments to the do_shrink functions are intended to be passed using -* inheritance. That is, the argument class derives from struct ttm_mem_shrink, -* and can be accessed using container_of(). -*/ - -struct ttm_mem_shrink { -int (*do_shrink) (struct ttm_mem_shrink *); -}; - -/** * struct ttm_mem_global - Global memory accounting structure. * * @shrink: A single callback to shrink TTM memory usage. Extend this @@ -76,7 +62,7 @@ struct ttm_mem_shrink {struct ttm_mem_zone ;struct ttm_mem_global {struct kobject kobj; -struct ttm_mem_shrink *shrink; +struct ttm_bo_global *bo_glob;struct workqueue_struct *swap_queue;struct work_struct work;spinlock_t lock;@@ -90,59 +76,6 @@ struct ttm_mem_global {#endif }; -/** -* ttm_mem_init_shrink - initialize a struct ttm_mem_shrink object -* -* @shrink: The object to initialize. -* @func: The callback function. -*/ - -static inline void ttm_mem_init_shrink (struct ttm_mem_shrink *shrink, -int (*func) (struct ttm_mem_shrink *)) -{ - shrink->do_shrink = func; -} - -/** -* ttm_mem_register_shrink - register a struct ttm_mem_shrink object. -* -* @glob: The struct ttm_mem_global object to register with. -* @shrink: An initialized struct ttm_mem_shrink object to register. -* -* Returns: -* -EBUSY: There's already a callback registered. (May change). -*/ - -static inline int ttm_mem_register_shrink (struct ttm_mem_global *glob, -struct ttm_mem_shrink *shrink) -{ -spin_lock (&glob->lock); -if (glob->shrink !=NULL ) { -spin_unlock (&glob->lock); -return -EBUSY ; - } - glob->shrink = shrink; -spin_unlock (&glob->lock); -return 0 ; -} - -/** -* ttm_mem_unregister_shrink - unregister a struct ttm_mem_shrink object. -* -* @glob: The struct ttm_mem_global object to unregister from. -* @shrink: A previously registert struct ttm_mem_shrink object. -* -*/ - -static inline void ttm_mem_unregister_shrink (struct ttm_mem_global *glob, -struct ttm_mem_shrink *shrink)
include/drm/ttm/ttm_memory.h struct ttm_mem_global { · line 81
Quoted 10 lines
include/drm/ttm/ttm_memory.h +0
-7-{ -spin_lock (&glob->lock); -BUG_ON (glob->shrink != shrink); - glob->shrink =NULL ; -spin_unlock (&glob->lock); -} -extern int ttm_mem_global_init (struct ttm_mem_global *glob);extern void ttm_mem_global_release (struct ttm_mem_global *glob); extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
_______________________________________________
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): b0f51ff0-950e-bbe0-0032-e0e714d94350-4+hqylr40dJg9hUCZPvPmw@public.gmane.org
Hi Thomas:
Also I wonder what testing is being performed on these changes prior to submission?
Vulkan CTS test with Per VM BO enabled.
After that, Command submit will not need to provide BO list it will use. It is helpful for performance to CPU bound games.
The reason why we enable eviction and swapout here is the test always overalloction.
Thanks
Roger(Hongbo.He)
-----Original Message-----
From: Thomas Hellstrom [mailto:[email protected]]
Sent: Thursday, December 21, 2017 3:34 PM
To: He, Roger <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH 1/7] drm/ttm: call ttm_bo_swapout directly when ttm shrink
Roger,
5 out of 7 patches in this series are completely lacking a commit log message, and thats not OK. Really.
https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#describe-your-changes
I'll review these, but IIRC the no_wait in the memory accounting code is different in that it doesn't allow sleeping, whereas in the bo code we had originally had no_wait_gpu and also no_wait. (IIRC Maarten or Jerome removed the latter due to lack of users.) Seems like these patches confuse the to. At the very least that requires some form of motivation.
Also I wonder what testing is being performed on these changes prior to submission? We have pretty high number of critical deployments out there, that we need to support.
/Thomas
Quoted 245 lines · Roger He
then remove superfluous functions
Change-Id Iea020f0e30a239e0265e7a1500168c7d7f819bd9Signed-off-by Roger He <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 21 +++--------- drivers/gpu/drm/ttm/ttm_memory.c | 12 ++----- include/drm/ttm/ttm_bo_api.h | 1 + include/drm/ttm/ttm_bo_driver.h | 1 - include/drm/ttm/ttm_memory.h | 69 +--------------------------------------- 5 files changed, 9 insertions(+), 95 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/ttm/ttm_bo.cindex 60bb5c1..fa57aa8 100644drivers/gpu/drm/ttm/ttm_bo.c +0
-1@@ -42,7 +42,6 @@#include <linux/atomic.h> #include <linux/reservation.h> -static int ttm_bo_swapout (struct ttm_mem_shrink *shrink);static void ttm_bo_global_kobj_release (struct kobject *kobj); static struct attribute ttm_bo_count = { @@ -1454,7 +1453,6 @@static void
ttm_bo_global_kobj_release(struct kobject *kobj)
structttm_bo_global*glob =
container_of(kobj, struct ttm_bo_global, kobj);drivers/gpu/drm/ttm/ttm_bo.c +1
-1-ttm_mem_unregister_shrink (glob->mem_glob, &glob->shrink);__free_page (glob->dummy_read_page);kfree (glob); }@@ -1479,6 +1477,7 @@ int ttm_bo_global_init(struct drm_global_reference *ref)mutex_init (&glob->device_list_mutex);spin_lock_init (&glob->lru_lock); glob->mem_glob = bo_ref->mem_glob; + glob->mem_glob->bo_glob = glob; glob->dummy_read_page =alloc_page (__GFP_ZERO |GFP_DMA32 ); if (unlikely(glob->dummy_read_page == NULL)) { @@ -1489,14 +1488,6@@ int
ttm_bo_global_init(struct drm_global_reference *ref)
for (i = 0; i <TTM_MAX_BO_PRIORITY; ++i)
INIT_LIST_HEAD(&glob->swap_lru[i]);
INIT_LIST_HEAD(&glob->device_list);drivers/gpu/drm/ttm/ttm_bo.c +3
-15- -ttm_mem_init_shrink (&glob->shrink, ttm_bo_swapout); - ret =ttm_mem_register_shrink (glob->mem_glob, &glob->shrink); -if (unlikely (ret !=0 )) { -pr_err ("Could not register buffer object swapout\n" ); - goto out_no_shrink; - } -atomic_set (&glob->bo_count,0 ); ret = kobject_init_and_add(@@ -1504,8 +1495,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)if (unlikely (ret !=0 ))kobject_put (&glob->kobj);return ret; -out_no_shrink: -__free_page (glob->dummy_read_page); out_no_drp:kfree (glob);return ret;@@ -1688,11 +1677,8 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);* A buffer object shrink method that tries to swap out the first * buffer object on the bo_global::swap_lru list. */ - -static int ttm_bo_swapout (struct ttm_mem_shrink *shrink) +int ttm_bo_swapout (struct ttm_bo_global *glob) { -struct ttm_bo_global *glob = - container_of(shrink, struct ttm_bo_global, shrink);struct ttm_buffer_object *bo;int ret = -EBUSY ;unsigned i;@@ -1774,10 +1760,11 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)kref_put (&bo->list_kref, ttm_bo_release_list);return ret; } +EXPORT_SYMBOL (ttm_bo_swapout);void ttm_bo_swapout_all (struct ttm_bo_device *bdev) { -while (ttm_bo_swapout (&bdev->glob->shrink) ==0 ) +while (ttm_bo_swapout (bdev->glob) ==0 ) ; }EXPORT_SYMBOL (ttm_bo_swapout_all);drivers/gpu/drm/ttm/ttm_memory.c +3
-9@@ -214,26 +214,20 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, uint64_t extra) {int ret; -struct ttm_mem_shrink *shrink;spin_lock (&glob->lock); -if (glob->shrink ==NULL ) - goto out;while (ttm_zones_above_swap_target (glob, from_wq, extra)) { - shrink = glob->shrink;spin_unlock (&glob->lock); - ret = shrink->do_shrink (shrink); + ret =ttm_bo_swapout (glob->bo_glob);spin_lock (&glob->lock);if (unlikely (ret !=0 )) - goto out; +break ; } -out: +spin_unlock (&glob->lock); } - -static void ttm_shrink_work (struct work_struct *work) { struct ttm_mem_global *glob =(quoted diff) +0
-0
b/include/drm/ttm/ttm_bo_api.hindex c126330..24a8db7 100644include/drm/ttm/ttm_bo_api.h +1
-0@@ -752,6 +752,7 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, const char __user *wbuf, char __user *rbuf, size_t count, loff_t *f_pos, bool write); +int ttm_bo_swapout (struct ttm_bo_global *glob);void ttm_bo_swapout_all (struct ttm_bo_device *bdev);int ttm_bo_wait_unreserved (struct ttm_buffer_object *bo);#endif (quoted diff) +0
-0
b/include/drm/ttm/ttm_bo_driver.hindex 5115718..934fecf 100644include/drm/ttm/ttm_bo_driver.h +0
-1@@ -522,7 +522,6 @@ struct ttm_bo_global {struct kobject kobj;struct ttm_mem_global *mem_glob;struct page *dummy_read_page; -struct ttm_mem_shrink shrink;struct mutex device_list_mutex;spinlock_t lru_lock;(quoted diff) +0
-0
b/include/drm/ttm/ttm_memory.hindex 2c1e359..85f3ad6 100644include/drm/ttm/ttm_memory.h +0
-5@@ -37,20 +37,6 @@#include <linux/mm.h> /** -* struct ttm_mem_shrink - callback to shrink TTM memory usage. -* -* @do_shrink: The callback function. -* -* Arguments to the do_shrink functions are intended to be passed using
- * inheritance. That is, the argument class derives from structttm_mem_shrink,
- * and can be accessed usingcontainer_of().
- */include/drm/ttm/ttm_memory.h +0
-6- -struct ttm_mem_shrink { -int (*do_shrink) (struct ttm_mem_shrink *); -}; - -/** * struct ttm_mem_global - Global memory accounting structure. * * @shrink: A single callback to shrink TTM memory usage. Extend this @@ -76,7 +62,7 @@ struct
ttm_mem_shrink{
structttm_mem_zone;
structttm_mem_global{
struct kobject kobj;include/drm/ttm/ttm_memory.h +1
-54-struct ttm_mem_shrink *shrink; +struct ttm_bo_global *bo_glob;struct workqueue_struct *swap_queue;struct work_struct work;spinlock_t lock;@@ -90,59 +76,6 @@ struct ttm_mem_global {#endif }; -/** -* ttm_mem_init_shrink - initialize a struct ttm_mem_shrink object -* -* @shrink: The object to initialize. -* @func: The callback function. -*/ - -static inline void ttm_mem_init_shrink (struct ttm_mem_shrink *shrink, -int (*func) (struct ttm_mem_shrink *)) -{ - shrink->do_shrink = func; -} - -/** -* ttm_mem_register_shrink - register a struct ttm_mem_shrink object. -* -* @glob: The struct ttm_mem_global object to register with. -* @shrink: An initialized struct ttm_mem_shrink object to register. -* -* Returns: -* -EBUSY: There's already a callback registered. (May change). -*/ - -static inline int ttm_mem_register_shrink (struct ttm_mem_global *glob, -struct ttm_mem_shrink *shrink) -{ -spin_lock (&glob->lock); -if (glob->shrink !=NULL ) { -spin_unlock (&glob->lock); -return -EBUSY ; - } - glob->shrink = shrink; -spin_unlock (&glob->lock); -return 0 ; -} - -/** -* ttm_mem_unregister_shrink - unregister a struct ttm_mem_shrink object. -* -* @glob: The struct ttm_mem_global object to unregister from. -* @shrink: A previously registert struct ttm_mem_shrink object. -* -*/ - -static inline void ttm_mem_unregister_shrink (struct ttm_mem_global *glob, -struct ttm_mem_shrink *shrink) -{ -spin_lock (&glob->lock); -BUG_ON (glob->shrink != shrink); - glob->shrink =NULL ; -spin_unlock (&glob->lock); -} -extern int ttm_mem_global_init (struct ttm_mem_global *glob);extern void ttm_mem_global_release (struct ttm_mem_global *glob); extern int ttm_mem_global_alloc(struct ttm_mem_global *glob,
Quoted 1 line
uint64_tmemory,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/7 drm/ttm: use an operation ctx for ttm_mem_global_alloc_page
In reply to Roger He--- drivers/gpu/drm/ttm/ttm_memory.c | 15 ++++++++------- drivers/gpu/drm/ttm/ttm_page_alloc.c | 6 +++++- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 8 ++++++-- include/drm/ttm/ttm_memory.h | 3 ++- 4 files changed, 21 insertions(+), 11 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +8 -7
@@ -539,15 +539,14 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,EXPORT_SYMBOL (ttm_mem_global_alloc);int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page,uint64_t size) +struct page *page,uint64_t size, +struct ttm_operation_ctx *ctx) { - +int ret;struct ttm_mem_zone *zone =NULL ; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - }; +bool tmp_no_wait_gpu = ctx->no_wait_gpu; + ctx->no_wait_gpu = false;/** * Page allocations may be registed in a single zone * only if highmem or !dma32.
@@ -560,7 +559,9 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone, size, &ctx); + ret =ttm_mem_global_alloc_zone (glob, zone, size, ctx); + ctx->no_wait_gpu = tmp_no_wait_gpu; +return ret; } void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,
drivers/gpu/drm/ttm/ttm_page_alloc.c +5 -1
@@ -1061,6 +1061,10 @@ void ttm_page_alloc_fini(void)int ttm_pool_populate (struct ttm_tt *ttm) {struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };unsigned i;int ret;
@@ -1076,7 +1080,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)for (i =0 ; i < ttm->num_pages; ++i) { ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], -PAGE_SIZE ); +PAGE_SIZE , &ctx);if (unlikely (ret !=0 )) {ttm_pool_unpopulate (ttm);return -ENOMEM ;
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +6 -2
@@ -927,6 +927,10 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev) {struct ttm_tt *ttm = &ttm_dma->ttm;struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };unsigned long num_pages = ttm->num_pages;struct dma_pool *pool;enum pool_type type;
@@ -962,7 +966,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)break ; ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size); + pool->size, &ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;
@@ -998,7 +1002,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev) } ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size); + pool->size, &ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;
include/drm/ttm/ttm_memory.h +2 -1
@@ -84,7 +84,8 @@ extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount);extern int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page,uint64_t size); +struct page *page,uint64_t size, +struct ttm_operation_ctx *ctx);extern void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page,uint64_t size);extern size_t ttm_round_pot (size_t size);
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): 1513766101-15993-3-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 3/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc_page
Commit message!
Am 20.12.2017 um 11:34 schrieb Roger He:
Quoted 19 lines
Change-Id I4104a12e09a374b6477a0dd5a8fce26dce27a746Signed-off-by Roger He <[email protected]>--- drivers/gpu/drm/ttm/ttm_memory.c | 15 ++++++++------- drivers/gpu/drm/ttm/ttm_page_alloc.c | 6 +++++- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 8 ++++++-- include/drm/ttm/ttm_memory.h | 3 ++- 4 files changed, 21 insertions(+), 11 deletions(-)drivers/gpu/drm/ttm/ttm_memory.c +1
-1@@ -539,15 +539,14 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,EXPORT_SYMBOL (ttm_mem_global_alloc); int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, -struct page *page,uint64_t size) + struct page *page, uint64_t size,
drivers/gpu/drm/ttm/ttm_memory.c int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, · line 547
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_memory.c +3
-5+ struct ttm_operation_ctx *ctx) { - +int ret;struct ttm_mem_zone *zone =NULL ; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - }; +bool tmp_no_wait_gpu = ctx->no_wait_gpu;
Mhm, please drop that. That the function might wait for the GPU even when the caller requested not to do so sounds like a bug to me.
Christian.
Quoted 78 lines
drivers/gpu/drm/ttm/ttm_memory.c +4
-1+ ctx->no_wait_gpu = false;/** * Page allocations may be registed in a single zone * only if highmem or !dma32. @@ -560,7 +559,9 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone, size, &ctx); + ret =ttm_mem_global_alloc_zone (glob, zone, size, ctx); + ctx->no_wait_gpu = tmp_no_wait_gpu; +return ret; } void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,drivers/gpu/drm/ttm/ttm_page_alloc.c +5
-1@@ -1061,6 +1061,10 @@ void ttm_page_alloc_fini(void)int ttm_pool_populate (struct ttm_tt *ttm) {struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };unsigned i;int ret;@@ -1076,7 +1080,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)for (i =0 ; i < ttm->num_pages; ++i) { ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], -PAGE_SIZE ); +PAGE_SIZE , &ctx);if (unlikely (ret !=0 )) {ttm_pool_unpopulate (ttm);return -ENOMEM ;drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +6
-2@@ -927,6 +927,10 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev) {struct ttm_tt *ttm = &ttm_dma->ttm;struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };unsigned long num_pages = ttm->num_pages;struct dma_pool *pool;enum pool_type type;@@ -962,7 +966,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)break ; ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size); + pool->size, &ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;@@ -998,7 +1002,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev) } ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size); + pool->size, &ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;include/drm/ttm/ttm_memory.h +0
-0
include/drm/ttm/ttm_memory.h extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, · line 91
Quoted 9 lines
include/drm/ttm/ttm_memory.h +2
-1@@ -84,7 +84,8 @@ extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount);extern int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page,uint64_t size); +struct page *page,uint64_t size, +struct ttm_operation_ctx *ctx);extern void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page,uint64_t size);extern size_t ttm_round_pot (size_t size);
_______________________________________________
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): edd81ee9-bb23-84c4-4065-2b424c95724e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
RE: [PATCH 3/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc_page
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, December 20, 2017 9:36 PM
To: He, Roger <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH 3/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc_page
Commit message!
Am 20.12.2017 um 11:34 schrieb Roger He:
Quoted 20 lines
Change-Id I4104a12e09a374b6477a0dd5a8fce26dce27a746Signed-off-by Roger He <[email protected]>--- drivers/gpu/drm/ttm/ttm_memory.c | 15 ++++++++------- drivers/gpu/drm/ttm/ttm_page_alloc.c | 6 +++++- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 8 ++++++-- include/drm/ttm/ttm_memory.h | 3 ++- 4 files changed, 21 insertions(+), 11 deletions(-)drivers/gpu/drm/ttm/ttm_memory.c +1
-1@@ -539,15 +539,14 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,EXPORT_SYMBOL (ttm_mem_global_alloc); int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, -struct page *page,uint64_t size) + struct page *page, uint64_t size,
drivers/gpu/drm/ttm/ttm_memory.c int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, · line 547
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_memory.c +3
-5+ struct ttm_operation_ctx *ctx) { - +int ret;struct ttm_mem_zone *zone =NULL ; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - }; +bool tmp_no_wait_gpu = ctx->no_wait_gpu;
Mhm, please drop that. That the function might wait for the GPU even when the caller requested not to do so sounds like a bug to me.
Yes. I will remove this. Later I will send new patches. Will appreciate If Thomas can help to verify that.
Thanks
Roger(Hongbo.He)
Quoted 80 lines
drivers/gpu/drm/ttm/ttm_memory.c +4
-1+ ctx->no_wait_gpu = false;/** * Page allocations may be registed in a single zone * only if highmem or !dma32. @@ -560,7 +559,9 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone, size, &ctx); + ret =ttm_mem_global_alloc_zone (glob, zone, size, ctx); + ctx->no_wait_gpu = tmp_no_wait_gpu; +return ret; } void ttm_mem_global_free_page(struct ttm_mem_global *glob, structpage *page, diff --git
a/drivers/gpu/drm/ttm/ttm_page_alloc.cb/drivers/gpu/drm/ttm/ttm_page_alloc.c
index b5ba644..8f93ff3 100644drivers/gpu/drm/ttm/ttm_page_alloc.c +5
-1@@ -1061,6 +1061,10 @@ void ttm_page_alloc_fini(void)int ttm_pool_populate (struct ttm_tt *ttm) {struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };unsigned i;int ret;@@ -1076,7 +1080,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)for (i =0 ; i < ttm->num_pages; ++i) { ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], -PAGE_SIZE ); +PAGE_SIZE , &ctx);if (unlikely (ret !=0 )) {ttm_pool_unpopulate (ttm);return -ENOMEM ;drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +6
-2@@ -927,6 +927,10 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev) {struct ttm_tt *ttm = &ttm_dma->ttm;struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; +struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + };unsigned long num_pages = ttm->num_pages;struct dma_pool *pool;enum pool_type type;@@ -962,7 +966,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)break ; ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size); + pool->size, &ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;@@ -998,7 +1002,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev) } ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - pool->size); + pool->size, &ctx);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;(quoted diff) +0
-0
b/include/drm/ttm/ttm_memory.hindex 755c107..8936285 100644
include/drm/ttm/ttm_memory.h extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, · line 91
Quoted 9 lines
include/drm/ttm/ttm_memory.h +2
-1@@ -84,7 +84,8 @@ extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount);extern int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page,uint64_t size); +struct page *page,uint64_t size, +struct ttm_operation_ctx *ctx);extern void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page,uint64_t size);extern size_t ttm_round_pot (size_t size);
_______________________________________________
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): BN6PR1201MB0114CD1510459BE13D0BF292FD0D0-6iU6OBHu2P8MH+E/uqw63WrFom/aUZj6nBOFsp37pqbUKgpGm//BTAC/[email protected]
Re: [PATCH 3/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc_page
Quoted 27 lines · Roger
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, December 20, 2017 9:36 PM
To: He, Roger <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH 3/7] drm/ttm: use an operation ctx forttm_mem_global_alloc_pageCommit message!
Am 20.12.2017 um 11:34 schrieb Roger He:
Quoted 17 lines
Change-Id I4104a12e09a374b6477a0dd5a8fce26dce27a746Signed-off-by Roger He <[email protected]>--- drivers/gpu/drm/ttm/ttm_memory.c | 15 ++++++++------- drivers/gpu/drm/ttm/ttm_page_alloc.c | 6 +++++- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 8 ++++++-- include/drm/ttm/ttm_memory.h | 3 ++- 4 files changed, 21 insertions(+), 11 deletions(-)drivers/gpu/drm/ttm/ttm_memory.c +0
-0@@ -539,15 +539,14 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,EXPORT_SYMBOL (ttm_mem_global_alloc);
Quoted 14 lines
drivers/gpu/drm/ttm/ttm_memory.c int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, · line 547
Quoted 13 lines
drivers/gpu/drm/ttm/ttm_memory.c +4
-6int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page,uint64_t size) +struct page *page,uint64_t size, +struct ttm_operation_ctx *ctx) { - +int ret;struct ttm_mem_zone *zone =NULL ; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - }; +bool tmp_no_wait_gpu = ctx->no_wait_gpu;Mhm, please drop that. That the function might wait for the GPU even when the caller requested not to do so sounds like a bug to
Yes, I agree.
/Thomas
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/7 drm/ttm: add ttm_bo_evict_swapout_allowable to check bo is allowable to evict or swapout
In reply to Roger Heextract this function since eviction and swapout share same logic
--- drivers/gpu/drm/ttm/ttm_bo.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +19 -10
@@ -706,6 +706,23 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_eviction_valuable); +static bool ttm_bo_evict_swapout_allowable (struct ttm_buffer_object *bo, +struct ttm_operation_ctx *ctx,bool *locked) +{ +bool ret = false; + + *locked = false; +if (bo->resv == ctx->resv) { +if (ctx->allow_reserved_eviction || !list_empty (&bo->ddestroy)) + ret = true; + }else { + *locked =reservation_object_trylock (bo->resv); + ret = *locked; + } + +return ret; +} + static int ttm_mem_evict_first(struct ttm_bo_device *bdev, uint32_t mem_type, const struct ttm_place *place,
@@ -721,21 +738,13 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,spin_lock (&glob->lru_lock);for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {list_for_each_entry (bo, &man->lru[i], lru) { -if (bo->resv == ctx->resv) { -if (!ctx->allow_reserved_eviction && -list_empty (&bo->ddestroy)) -continue ; - }else { - locked =reservation_object_trylock (bo->resv); -if (!locked) -continue ; - } +if (!ttm_bo_evict_swapout_allowable (bo, ctx, &locked)) +continue ;if (place && !bdev->driver->eviction_valuable (bo, place)) {if (locked)reservation_object_unlock (bo->resv); - locked = false;continue ; }break ;
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 6/7] drm/ttm: add ttm_bo_evict_swapout_allowable to check bo is allowable to evict or swapout
Quoted 1 line · Roger He
extract this function since eviction and swapout share same logic
But it's only used in eviction?
Quoted 12 lines
Change-Id I80a475a93fceed8d66d74a1832c815a0756341acSigned-off-by Roger He <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +0
-0
drivers/gpu/drm/ttm/ttm_bo.c bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, · line 710
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c +2
-0@@ -706,6 +706,23 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_eviction_valuable); +static bool ttm_bo_evict_swapout_allowable (struct ttm_buffer_object *bo, +struct ttm_operation_ctx *ctx,bool *locked)
Could we have a description in the code what this function actually does? admittedly it checks whether a swapout or eviction is allowable, but it aso performs a recursive tryreserve(), and that is of value to any future code reader.?
/Thomas
Quoted 32 lines
drivers/gpu/drm/ttm/ttm_bo.c +16
-9+{ +bool ret = false; + + *locked = false; +if (bo->resv == ctx->resv) { +if (ctx->allow_reserved_eviction || !list_empty (&bo->ddestroy)) + ret = true; + }else { + *locked =reservation_object_trylock (bo->resv); + ret = *locked; + } + +return ret; +} + static int ttm_mem_evict_first(struct ttm_bo_device *bdev, uint32_t mem_type, const struct ttm_place *place,@@ -721,21 +738,13 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,spin_lock (&glob->lru_lock);for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {list_for_each_entry (bo, &man->lru[i], lru) { -if (bo->resv == ctx->resv) { -if (!ctx->allow_reserved_eviction && -list_empty (&bo->ddestroy)) -continue ; - }else { - locked =reservation_object_trylock (bo->resv); -if (!locked) -continue ; - } +if (!ttm_bo_evict_swapout_allowable (bo, ctx, &locked))
drivers/gpu/drm/ttm/ttm_bo.c static int ttm_mem_evict_first(struct ttm_bo_device *bdev, · line 750
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +1
-1+continue ;if (place && !bdev->driver->eviction_valuable (bo, place)) {if (locked)reservation_object_unlock (bo->resv); - locked = false;continue ; }break ;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RE: [PATCH 6/7] drm/ttm: add ttm_bo_evict_swapout_allowable to check bo is allowable to evict or swapout
-----Original Message-----
From: dri-devel [mailto:[email protected]] On Behalf Of Thomas Hellstrom
Sent: Thursday, December 21, 2017 3:51 PM
To: [email protected]
Subject: Re: [PATCH 6/7] drm/ttm: add ttm_bo_evict_swapout_allowable to check bo is allowable to evict or swapout
Quoted 1 line · Roger He
extract this function since eviction and swapout share same logic
But it's only used in eviction?
Yes, currently it only used in eviction. And will be used in Swapout.
Quoted 12 lines
Change-Id I80a475a93fceed8d66d74a1832c815a0756341acSigned-off-by Roger He <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/ttm/ttm_bo.cindex e7595b4..313925c 100644
drivers/gpu/drm/ttm/ttm_bo.c bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, · line 710
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c +2
-0@@ -706,6 +706,23 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_eviction_valuable); +static bool ttm_bo_evict_swapout_allowable (struct ttm_buffer_object *bo, +struct ttm_operation_ctx *ctx,bool *locked)
Could we have a description in the code what this function actually does? admittedly it checks whether a swapout or eviction is allowable, but it aso performs a recursive tryreserve(), and that is of value to any future code reader.?
Ok.
Thanks
Roger(Hongbo.He)
/Thomas
Quoted 32 lines
drivers/gpu/drm/ttm/ttm_bo.c +15
-0+{ +bool ret = false; + + *locked = false; +if (bo->resv == ctx->resv) { +if (ctx->allow_reserved_eviction || !list_empty (&bo->ddestroy)) + ret = true; + }else { + *locked =reservation_object_trylock (bo->resv); + ret = *locked; + } + +return ret; +} + static int ttm_mem_evict_first(struct ttm_bo_device *bdev, uint32_t mem_type, const struct ttm_place *place, @@ -721,21 +738,13 @@static int ttm_mem_evict_first(struct
ttm_bo_device*bdev,
spin_lock(&glob->lru_lock);
for (i = 0; i <TTM_MAX_BO_PRIORITY; ++i) {
list_for_each_entry(bo, &man->lru[i], lru){drivers/gpu/drm/ttm/ttm_bo.c +1
-9-if (bo->resv == ctx->resv) { -if (!ctx->allow_reserved_eviction && -list_empty (&bo->ddestroy)) -continue ; - }else { - locked =reservation_object_trylock (bo->resv); -if (!locked) -continue ; - } +if (!ttm_bo_evict_swapout_allowable (bo, ctx, &locked))
drivers/gpu/drm/ttm/ttm_bo.c static int ttm_mem_evict_first(struct ttm_bo_device *bdev, · line 750
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +1
-1+continue ;if (place && !bdev->driver->eviction_valuable (bo, place)) {if (locked)reservation_object_unlock (bo->resv); - locked = false;continue ; }break ;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel