drm/ttm: add ttm_bo_pin()/ttm_bo_unpin() v2
Subsystems (8)
PATCH 1/11 drm/ttm: add ttm_bo_pin()/ttm_bo_unpin() v2
As an alternative to the placement flag add a
pin count to the ttm buffer object.
v2: add dma_resv_assert_help() calls
--- drivers/gpu/drm/ttm/ttm_bo.c | 9 ++++++--- drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +- include/drm/ttm/ttm_bo_api.h | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +6 -3
@@ -115,7 +115,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,struct ttm_bo_device *bdev = bo->bdev;struct ttm_resource_manager *man; -if (!list_empty (&bo->lru)) +if (!list_empty (&bo->lru) || bo->pin_count)return ;if (mem->placement &TTM_PL_FLAG_NO_EVICT )
@@ -165,7 +165,8 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,ttm_bo_del_from_lru (bo);ttm_bo_add_mem_to_lru (bo, &bo->mem); -if (bulk && !(bo->mem.placement &TTM_PL_FLAG_NO_EVICT )) { +if (bulk && !(bo->mem.placement &TTM_PL_FLAG_NO_EVICT ) && + !bo->pin_count) {switch (bo->mem.mem_type) {case TTM_PL_TT :ttm_bo_bulk_move_set_pos (&bulk->tt[bo->priority], bo);
@@ -544,8 +545,9 @@ static void ttm_bo_release(struct kref *kref)* shrinkers, now that they are queued for * destruction. */ -if (bo->mem.placement &TTM_PL_FLAG_NO_EVICT ) { +if (bo->mem.placement &TTM_PL_FLAG_NO_EVICT || bo->pin_count) { bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT ; + bo->pin_count =0 ;ttm_bo_del_from_lru (bo);ttm_bo_add_mem_to_lru (bo, &bo->mem); }
@@ -1172,6 +1174,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev, bo->moving =NULL ; bo->mem.placement =TTM_PL_FLAG_CACHED ; bo->acc_size = acc_size; + bo->pin_count =0 ; bo->sg = sg;if (resv) { bo->base.resv = resv;
drivers/gpu/drm/ttm/ttm_bo_util.c +1 -1
@@ -352,7 +352,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,return -ENOMEM ; fbo->base = *bo; - fbo->base.mem.placement |=TTM_PL_FLAG_NO_EVICT ;ttm_bo_get (bo); fbo->bo = bo;
@@ -372,6 +371,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,kref_init (&fbo->base.kref); fbo->base.destroy = &ttm_transfered_destroy; fbo->base.acc_size =0 ; + fbo->base.pin_count =1 ;if (bo->type != ttm_bo_type_sg) fbo->base.base.resv = &fbo->base.base._resv;
include/drm/ttm/ttm_bo_api.h +26 -0
@@ -157,6 +157,7 @@ struct ttm_buffer_object {struct dma_fence *moving;unsigned priority; +unsigned pin_count;/** * Special members that are protected by the reserve lock
@@ -606,6 +607,31 @@ static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)return bo->base.dev !=NULL ; } +/** +* ttm_bo_pin - Pin the buffer object. +* @bo: The buffer object to pin +* +* Make sure the buffer is not evicted any more during memory pressure. +*/ +static inline void ttm_bo_pin (struct ttm_buffer_object *bo) +{ +dma_resv_assert_held (bo->base.resv); + ++bo->pin_count; +} + +/** +* ttm_bo_unpin - Unpin the buffer object. +* @bo: The buffer object to unpin +* +* Allows the buffer object to be evicted again during memory pressure. +*/ +static inline void ttm_bo_unpin (struct ttm_buffer_object *bo) +{ +dma_resv_assert_held (bo->base.resv); +WARN_ON_ONCE (!bo->pin_count); + --bo->pin_count; +} + int ttm_mem_evict_first(struct ttm_bo_device *bdev, struct ttm_resource_manager *man, const struct ttm_place *place,
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/11 drm/vmwgfx: remove unused placement combination
Just some dead code cleanup.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 1 - drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 30 ---------------------- 2 files changed, 31 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +0 -1
@@ -1008,7 +1008,6 @@ extern struct ttm_placement vmw_vram_placement;extern struct ttm_placement vmw_vram_ne_placement;extern struct ttm_placement vmw_vram_sys_placement;extern struct ttm_placement vmw_vram_gmr_placement; -extern struct ttm_placement vmw_vram_gmr_ne_placement;extern struct ttm_placement vmw_sys_placement;extern struct ttm_placement vmw_sys_ne_placement;extern struct ttm_placement vmw_evictable_placement;
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -30
@@ -65,13 +65,6 @@ static const struct ttm_place gmr_placement_flags = { .flags = TTM_PL_FLAG_CACHED }; -static const struct ttm_place gmr_ne_placement_flags = { - .fpfn =0 , - .lpfn =0 , - .mem_type =VMW_PL_GMR , - .flags =TTM_PL_FLAG_CACHED |TTM_PL_FLAG_NO_EVICT -}; -static const struct ttm_place mob_placement_flags = { .fpfn =0 , .lpfn =0 ,
@@ -128,29 +121,6 @@ struct ttm_placement vmw_vram_gmr_placement = { .busy_placement = &gmr_placement_flags }; -static const struct ttm_place vram_gmr_ne_placement_flags[] = { - { - .fpfn =0 , - .lpfn =0 , - .mem_type =TTM_PL_VRAM , - .flags =TTM_PL_FLAG_CACHED | -TTM_PL_FLAG_NO_EVICT - }, { - .fpfn =0 , - .lpfn =0 , - .mem_type =VMW_PL_GMR , - .flags =TTM_PL_FLAG_CACHED | -TTM_PL_FLAG_NO_EVICT - } -}; - -struct ttm_placement vmw_vram_gmr_ne_placement = { - .num_placement =2 , - .placement = vram_gmr_ne_placement_flags, - .num_busy_placement =1 , - .busy_placement = &gmr_ne_placement_flags -}; -struct ttm_placement vmw_vram_sys_placement = { .num_placement =1 , .placement = &vram_placement_flags,
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/11 drm/vmwgfx: stop using ttm_bo_create
In reply to Christian KönigImplement in the driver instead since it is the only user of that function.
--- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 42 ++++++++++++++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c | 6 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 4 +++ drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 8 ++--- 4 files changed, 52 insertions(+), 8 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +42 -0
@@ -487,6 +487,48 @@ static void vmw_user_bo_destroy(struct ttm_buffer_object *bo)ttm_prime_object_kfree (vmw_user_bo, prime); } +/** +* vmw_bo_create_kernel - Create a pinned BO for internal kernel use. +* +* @dev_priv: Pointer to the device private struct +* @size: size of the BO we need +* @placement: where to put it +* @p_bo: resulting BO +* +* Creates and pin a simple BO for in kernel use. +*/ +int vmw_bo_create_kernel (struct vmw_private *dev_priv,unsigned long size, +struct ttm_placement *placement, +struct ttm_buffer_object **p_bo) +{ +unsigned npages =PAGE_ALIGN (size) >>PAGE_SHIFT ; +struct ttm_buffer_object *bo; +size_t acc_size; +int ret; + + bo =kzalloc (sizeof (*bo),GFP_KERNEL ); +if (unlikely (!bo)) +return -ENOMEM ; + + acc_size =ttm_round_pot (sizeof (*bo)); + acc_size +=ttm_round_pot (npages *sizeof (void *)); + acc_size +=ttm_round_pot (sizeof (struct ttm_tt )); + ret =ttm_bo_init_reserved (&dev_priv->bdev, bo, size, + ttm_bo_type_device, placement,0 , + false, acc_size,NULL ,NULL ,NULL ); +if (unlikely (ret)) + goto error_free; + +ttm_bo_pin (bo); +ttm_bo_unreserve (bo); + *p_bo = bo; + +return 0 ; + +error_free: +kfree (bo); +return ret; +}/** * vmw_bo_init - Initialize a vmw buffer object
drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c +3 -3
@@ -1245,9 +1245,9 @@ int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, !dev_priv->has_mob)return -ENOMEM ; - ret =ttm_bo_create (&dev_priv->bdev, size, ttm_bo_type_device, - &vmw_mob_ne_placement,0 , false, - &man->cmd_space); + ret =vmw_bo_create_kernel (dev_priv, size, + &vmw_mob_placement, + &man->cmd_space);if (ret)return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +4 -0
@@ -845,6 +845,10 @@ extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf, SVGAGuestPtr *ptr);extern void vmw_bo_pin_reserved (struct vmw_buffer_object *bo,bool pin);extern void vmw_bo_bo_free (struct ttm_buffer_object *bo); +extern int vmw_bo_create_kernel (struct vmw_private *dev_priv, +unsigned long size, +struct ttm_placement *placement, +struct ttm_buffer_object **p_bo); extern int vmw_bo_init(struct vmw_private *dev_priv, struct vmw_buffer_object *vmw_bo, size_t size, struct ttm_placement *placement,
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +3 -5
@@ -793,11 +793,9 @@ int vmw_bo_create_and_populate(struct vmw_private *dev_priv,struct ttm_buffer_object *bo;int ret; - ret =ttm_bo_create (&dev_priv->bdev, bo_size, - ttm_bo_type_device, - &vmw_sys_ne_placement, -0 , false, &bo); - + ret =vmw_bo_create_kernel (dev_priv, bo_size, + &vmw_sys_placement, + &bo);if (unlikely (ret !=0 ))return ret;
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/11 drm/vmwgfx: switch over to the new pin interface v2
In reply to Christian KönigStop using TTM_PL_FLAG_NO_EVICT.
v2: fix unconditional pinning
--- drivers/gpu/drm/vmwgfx/vmwgfx_blit.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 49 +++++++++++----------- drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 7 +--- drivers/gpu/drm/vmwgfx/vmwgfx_fb.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 42 ------------------- drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 2 +- 11 files changed, 39 insertions(+), 85 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_blit.c +2 -2
@@ -459,9 +459,9 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,int ret =0 ;/* Buffer objects need to be either pinned or reserved: */ -if (!(dst->mem.placement &TTM_PL_FLAG_NO_EVICT )) +if (!(dst->pin_count))dma_resv_assert_held (dst->base.resv); -if (!(src->mem.placement &TTM_PL_FLAG_NO_EVICT )) +if (!(src->pin_count))dma_resv_assert_held (src->base.resv);if (!ttm_tt_is_populated (dst->ttm)) {
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +25 -24
115 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +2 -2
@@ -410,8 +410,8 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)if (!buf)return -ENOMEM ; - ret =vmw_bo_init (dev_priv, buf, new_size, &vmw_mob_ne_placement, - true, vmw_bo_bo_free); + ret =vmw_bo_init (dev_priv, buf, new_size, &vmw_mob_placement, + true, true, vmw_bo_bo_free);if (ret) {DRM_ERROR ("Failed initializing new cotable MOB.\n" );return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -1
@@ -372,7 +372,7 @@ static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)return -ENOMEM ; ret =vmw_bo_init (dev_priv, vbo,PAGE_SIZE , - &vmw_sys_ne_placement, false, + &vmw_sys_placement, false, true, &vmw_bo_bo_free);if (unlikely (ret !=0 ))return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +1 -6
@@ -99,7 +99,6 @@ struct vmw_fpriv {* struct vmw_buffer_object - TTM buffer object with vmwgfx additions * @base: The TTM buffer object * @res_tree: RB tree of resources using this buffer object as a backing MOB -* @pin_count: pin depth * @cpu_writers: Number of synccpu write grabs. Protected by reservation when * increased. May be decreased without reservation. * @dx_query_ctx: DX context if this buffer object is used as a DX query MOB
@@ -110,7 +109,6 @@ struct vmw_fpriv {struct vmw_buffer_object {struct ttm_buffer_object base;struct rb_root res_tree; -s32 pin_count;atomic_t cpu_writers;/* Not ref-counted. Protected by binding_mutex */ struct vmw_resource *dx_query_ctx;
@@ -852,7 +850,7 @@ extern int vmw_bo_create_kernel(struct vmw_private *dev_priv,extern int vmw_bo_init (struct vmw_private *dev_priv,struct vmw_buffer_object *vmw_bo,size_t size,struct ttm_placement *placement, -bool interruptible, +bool interruptible,bool pin,void (*bo_free)(struct ttm_buffer_object *bo));extern int vmw_user_bo_verify_access (struct ttm_buffer_object *bo,struct ttm_object_file *tfile);
@@ -1009,15 +1007,12 @@ extern void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv,extern const size_t vmw_tt_size;extern struct ttm_placement vmw_vram_placement; -extern struct ttm_placement vmw_vram_ne_placement;extern struct ttm_placement vmw_vram_sys_placement;extern struct ttm_placement vmw_vram_gmr_placement;extern struct ttm_placement vmw_sys_placement; -extern struct ttm_placement vmw_sys_ne_placement;extern struct ttm_placement vmw_evictable_placement;extern struct ttm_placement vmw_srf_placement;extern struct ttm_placement vmw_mob_placement; -extern struct ttm_placement vmw_mob_ne_placement;extern struct ttm_placement vmw_nonfixed_placement;extern struct ttm_bo_driver vmw_bo_driver; extern const struct vmw_sg_table *
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c +1 -1
@@ -406,7 +406,7 @@ static int vmw_fb_create_bo(struct vmw_private *vmw_priv, ret =vmw_bo_init (vmw_priv, vmw_bo, size, &vmw_sys_placement, - false, + false, false, &vmw_bo_bo_free);if (unlikely (ret !=0 )) goto err_unlock;/* init frees the buffer on failure */
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +2 -2
@@ -370,7 +370,7 @@ static int vmw_resource_buf_alloc(struct vmw_resource *res, ret =vmw_bo_init (res->dev_priv, backup, res->backup_size, res->func->backup_placement, - interruptible, + interruptible, false, &vmw_bo_bo_free);if (unlikely (ret !=0 )) goto out_no_bo;
@@ -1002,7 +1002,7 @@ int vmw_resource_pin(struct vmw_resource *res, bool interruptible) vbo = res->backup;ttm_bo_reserve (&vbo->base, interruptible, false,NULL ); -if (!vbo->pin_count) { +if (!vbo->base.pin_count) { ret = ttm_bo_validate (&vbo->base, res->func->backup_placement,
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c +2 -2
@@ -451,8 +451,8 @@ vmw_sou_primary_plane_prepare_fb(struct drm_plane *plane,*/ vmw_overlay_pause_all (dev_priv); ret =vmw_bo_init (dev_priv, vps->bo, size, - &vmw_vram_ne_placement, - false, &vmw_bo_bo_free); + &vmw_vram_placement, + false, true, &vmw_bo_bo_free);vmw_overlay_resume_all (dev_priv);if (ret) { vps->bo =NULL ;/* vmw_bo_init frees on error */
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +2 -2
@@ -978,8 +978,8 @@ int vmw_compat_shader_add(struct vmw_private *dev_priv,if (unlikely (!buf))return -ENOMEM ; - ret =vmw_bo_init (dev_priv, buf, size, &vmw_sys_ne_placement, - true, vmw_bo_bo_free); + ret =vmw_bo_init (dev_priv, buf, size, &vmw_sys_placement, + true, true, vmw_bo_bo_free);if (unlikely (ret !=0 )) goto out;
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -42
78 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +1 -1
@@ -540,7 +540,7 @@ int vmw_validation_bo_validate_single(struct ttm_buffer_object *bo,if (atomic_read (&vbo->cpu_writers))return -EBUSY ; -if (vbo->pin_count >0 ) +if (vbo->base.pin_count >0 )return 0 ;if (validate_as_mob)
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/11 drm/nouveau: switch over to the new pin interface
In reply to Christian KönigStop using TTM_PL_FLAG_NO_EVICT.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 48 +++++++------------------- drivers/gpu/drm/nouveau/nouveau_bo.h | 3 -- drivers/gpu/drm/nouveau/nouveau_chan.c | 2 +- 3 files changed, 13 insertions(+), 40 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +12 -36
@@ -139,7 +139,7 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo)struct drm_device *dev = drm->dev;struct nouveau_bo *nvbo =nouveau_bo (bo); -WARN_ON (nvbo->pin_refcnt >0 ); +WARN_ON (nvbo->bo.pin_count >0 );nouveau_bo_del_io_reserve_lru (bo);nv10_bo_put_tile_region (dev, nvbo->tile,NULL );
@@ -417,9 +417,8 @@ nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain, {struct nouveau_drm *drm =nouveau_bdev (nvbo->bo.bdev);struct ttm_placement *pl = &nvbo->placement; -uint32_t flags = (nvbo->force_coherent ?TTM_PL_FLAG_UNCACHED : -TTM_PL_MASK_CACHING ) | - (nvbo->pin_refcnt ?TTM_PL_FLAG_NO_EVICT :0 ); +uint32_t flags = nvbo->force_coherent ?TTM_PL_FLAG_UNCACHED : +TTM_PL_MASK_CACHING ; pl->placement = nvbo->placements; set_placement_list(drm, nvbo->placements, &pl->num_placement,
@@ -453,7 +452,7 @@ nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t domain, bool contig) } } -if (nvbo->pin_refcnt) { +if (nvbo->bo.pin_count) {bool error = evict;switch (bo->mem.mem_type) {
@@ -472,7 +471,7 @@ nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t domain, bool contig) bo->mem.mem_type, domain); ret = -EBUSY ; } - nvbo->pin_refcnt++; +ttm_bo_pin (&nvbo->bo); goto out; }
@@ -483,18 +482,12 @@ nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t domain, bool contig) goto out; } - nvbo->pin_refcnt++;nouveau_bo_placement_set (nvbo, domain,0 ); - -/* drop pin_refcnt temporarily, so we don't trip the assertion -* in nouveau_bo_move() that makes sure we're not trying to -* move a pinned buffer -*/ - nvbo->pin_refcnt--; ret =nouveau_bo_validate (nvbo, false, false);if (ret) goto out; - nvbo->pin_refcnt++; + +ttm_bo_pin (&nvbo->bo);switch (bo->mem.mem_type) {case TTM_PL_VRAM :
@@ -519,30 +512,14 @@ nouveau_bo_unpin(struct nouveau_bo *nvbo) {struct nouveau_drm *drm =nouveau_bdev (nvbo->bo.bdev);struct ttm_buffer_object *bo = &nvbo->bo; -int ret, ref; +int ret; ret =ttm_bo_reserve (bo, false, false,NULL );if (ret)return ret; - ref = --nvbo->pin_refcnt; -WARN_ON_ONCE (ref <0 ); -if (ref) - goto out; - -switch (bo->mem.mem_type) { -case TTM_PL_VRAM : -nouveau_bo_placement_set (nvbo,NOUVEAU_GEM_DOMAIN_VRAM ,0 ); -break ; -case TTM_PL_TT : -nouveau_bo_placement_set (nvbo,NOUVEAU_GEM_DOMAIN_GART ,0 ); -break ; -default : -break ; - } - - ret =nouveau_bo_validate (nvbo, false, false); -if (ret ==0 ) { +ttm_bo_unpin (&nvbo->bo); +if (!nvbo->bo.pin_count) {switch (bo->mem.mem_type) {case TTM_PL_VRAM : drm->gem.vram_available += bo->mem.size;
@@ -555,9 +532,8 @@ nouveau_bo_unpin(struct nouveau_bo *nvbo) } } -out:ttm_bo_unreserve (bo); -return ret; +return 0 ; }int
@@ -1065,7 +1041,7 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,if (ret)return ret; -if (nvbo->pin_refcnt) +if (nvbo->bo.pin_count)NV_WARN (drm,"Moving pinned object %p!\n" , nvbo);if (drm->client.device.info.family <NV_DEVICE_INFO_V0_TESLA ) {
drivers/gpu/drm/nouveau/nouveau_bo.h +0 -3
@@ -40,9 +40,6 @@ struct nouveau_bo {struct nouveau_drm_tile *tile; -/* protect by the ttm reservation lock */ -int pin_refcnt; -struct ttm_bo_kmap_obj dma_buf_vmap; };
drivers/gpu/drm/nouveau/nouveau_chan.c +1 -1
@@ -107,7 +107,7 @@ nouveau_channel_del(struct nouveau_channel **pchan)nvif_object_dtor (&chan->push.ctxdma);nouveau_vma_del (&chan->push.vma);nouveau_bo_unmap (chan->push.buffer); -if (chan->push.buffer && chan->push.buffer->pin_refcnt) +if (chan->push.buffer && chan->push.buffer->bo.pin_count)nouveau_bo_unpin (chan->push.buffer);nouveau_bo_ref (NULL , &chan->push.buffer);kfree (chan);
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/11 drm/vram-helper: switch over to the new pin interface
In reply to Christian KönigStop using TTM_PL_FLAG_NO_EVICT.
--- drivers/gpu/drm/drm_gem_vram_helper.c | 37 +++++++-------------------- include/drm/drm_gem_vram_helper.h | 3 --- 2 files changed, 9 insertions(+), 31 deletions(-)
drivers/gpu/drm/drm_gem_vram_helper.c +9 -28
@@ -301,7 +301,7 @@ static u64 drm_gem_vram_pg_offset(struct drm_gem_vram_object *gbo)*/ s64 drm_gem_vram_offset (struct drm_gem_vram_object *gbo) { -if (WARN_ON_ONCE (!gbo->pin_count)) +if (WARN_ON_ONCE (!gbo->bo.pin_count))return (s64)-ENODEV ;return drm_gem_vram_pg_offset (gbo) <<PAGE_SHIFT ; }
@@ -310,24 +310,21 @@ EXPORT_SYMBOL(drm_gem_vram_offset);static int drm_gem_vram_pin_locked (struct drm_gem_vram_object *gbo,unsigned long pl_flag) { -int i, ret;struct ttm_operation_ctx ctx = { false, false }; +int ret; -if (gbo->pin_count) +if (gbo->bo.pin_count) goto out;if (pl_flag)drm_gem_vram_placement (gbo, pl_flag); -for (i =0 ; i < gbo->placement.num_placement; ++i) - gbo->placements[i].flags |=TTM_PL_FLAG_NO_EVICT ; - ret =ttm_bo_validate (&gbo->bo, &gbo->placement, &ctx);if (ret <0 )return ret; out: - ++gbo->pin_count; +ttm_bo_pin (&gbo->bo);return 0 ; }
@@ -369,26 +366,9 @@ int drm_gem_vram_pin(struct drm_gem_vram_object *gbo, unsigned long pl_flag) }EXPORT_SYMBOL (drm_gem_vram_pin); -static int drm_gem_vram_unpin_locked (struct drm_gem_vram_object *gbo) +static void drm_gem_vram_unpin_locked (struct drm_gem_vram_object *gbo) { -int i, ret; -struct ttm_operation_ctx ctx = { false, false }; - -if (WARN_ON_ONCE (!gbo->pin_count)) -return 0 ; - - --gbo->pin_count; -if (gbo->pin_count) -return 0 ; - -for (i =0 ; i < gbo->placement.num_placement ; ++i) - gbo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT ; - - ret =ttm_bo_validate (&gbo->bo, &gbo->placement, &ctx); -if (ret <0 ) -return ret; - -return 0 ; +ttm_bo_unpin (&gbo->bo); }/**
@@ -406,10 +386,11 @@ int drm_gem_vram_unpin(struct drm_gem_vram_object *gbo) ret =ttm_bo_reserve (&gbo->bo, true, false,NULL );if (ret)return ret; - ret =drm_gem_vram_unpin_locked (gbo); + +drm_gem_vram_unpin_locked (gbo);ttm_bo_unreserve (&gbo->bo); -return ret; +return 0 ; }EXPORT_SYMBOL (drm_gem_vram_unpin);
include/drm/drm_gem_vram_helper.h +0 -3
@@ -35,7 +35,6 @@ struct vm_area_struct; * @placement: TTM placement information. Supported placements are \ %TTM_PL_VRAM and %TTM_PL_SYSTEM * @placements: TTM placement information. - * @pin_count: Pin counter * * The type struct drm_gem_vram_object represents a GEM object that is * backed by VRAM. It can be used for simple framebuffer devices with
@@ -64,8 +63,6 @@ struct drm_gem_vram_object {/* Supported placements are %TTM_PL_VRAM and %TTM_PL_SYSTEM */ struct ttm_placement placement;struct ttm_place placements[2 ]; - -int pin_count; };/**
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 7/11 drm/qxl: switch over to the new pin interface
In reply to Christian KönigStop using TTM_PL_FLAG_NO_EVICT.
--- drivers/gpu/drm/qxl/qxl_debugfs.c | 2 +- drivers/gpu/drm/qxl/qxl_drv.h | 1 - drivers/gpu/drm/qxl/qxl_ioctl.c | 4 +-- drivers/gpu/drm/qxl/qxl_object.c | 44 +++++++++---------------------- drivers/gpu/drm/qxl/qxl_object.h | 2 +- drivers/gpu/drm/qxl/qxl_release.c | 4 +-- drivers/gpu/drm/qxl/qxl_ttm.c | 2 +- 7 files changed, 20 insertions(+), 39 deletions(-)
drivers/gpu/drm/qxl/qxl_debugfs.c +1 -1
@@ -67,7 +67,7 @@ qxl_debugfs_buffers_info(struct seq_file *m, void *data)seq_printf (m,"size %ld, pc %d, num releases %d\n" , (unsigned long )bo->tbo.base.size, - bo->pin_count, rel); + bo->tbo.pin_count, rel); }return 0 ; }
drivers/gpu/drm/qxl/qxl_drv.h +0 -1
@@ -80,7 +80,6 @@ struct qxl_bo {struct ttm_place placements[3 ];struct ttm_placement placement;struct ttm_bo_kmap_obj kmap; -unsigned int pin_count;void *kptr;unsigned int map_count;int type;
drivers/gpu/drm/qxl/qxl_ioctl.c +2 -2
@@ -326,8 +326,8 @@ static int qxl_update_area_ioctl(struct drm_device *dev, void *data,if (ret) goto out; -if (!qobj->pin_count) { -qxl_ttm_placement_from_domain (qobj, qobj->type, false); +if (!qobj->tbo.pin_count) { +qxl_ttm_placement_from_domain (qobj, qobj->type); ret =ttm_bo_validate (&qobj->tbo, &qobj->placement, &ctx);if (unlikely (ret)) goto out;
drivers/gpu/drm/qxl/qxl_object.c +13 -31
95 lines not on this page · raw message
drivers/gpu/drm/qxl/qxl_object.h +1 -1
@@ -94,7 +94,7 @@ extern struct qxl_bo *qxl_bo_ref(struct qxl_bo *bo);extern void qxl_bo_unref (struct qxl_bo **bo);extern int qxl_bo_pin (struct qxl_bo *bo);extern int qxl_bo_unpin (struct qxl_bo *bo); -extern void qxl_ttm_placement_from_domain (struct qxl_bo *qbo,u32 domain,bool pinned); +extern void qxl_ttm_placement_from_domain (struct qxl_bo *qbo,u32 domain);extern bool qxl_ttm_bo_is_qxl_bo (struct ttm_buffer_object *bo);#endif
drivers/gpu/drm/qxl/qxl_release.c +2 -2
@@ -231,8 +231,8 @@ static int qxl_release_validate_bo(struct qxl_bo *bo)struct ttm_operation_ctx ctx = { true, false };int ret; -if (!bo->pin_count) { -qxl_ttm_placement_from_domain (bo, bo->type, false); +if (!bo->tbo.pin_count) { +qxl_ttm_placement_from_domain (bo, bo->type); ret =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);if (ret)return ret;
drivers/gpu/drm/qxl/qxl_ttm.c +1 -1
@@ -67,7 +67,7 @@ static void qxl_evict_flags(struct ttm_buffer_object *bo,return ; } qbo =to_qxl_bo (bo); -qxl_ttm_placement_from_domain (qbo,QXL_GEM_DOMAIN_CPU , false); +qxl_ttm_placement_from_domain (qbo,QXL_GEM_DOMAIN_CPU ); *placement = qbo->placement; }
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 8/11 drm/radeon: switch over to the new pin interface
In reply to Christian KönigStop using TTM_PL_FLAG_NO_EVICT.
--- drivers/gpu/drm/radeon/radeon.h | 1 - drivers/gpu/drm/radeon/radeon_display.c | 9 ++---- drivers/gpu/drm/radeon/radeon_object.c | 37 ++++++------------------- drivers/gpu/drm/radeon/radeon_object.h | 2 +- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- 5 files changed, 13 insertions(+), 38 deletions(-)
drivers/gpu/drm/radeon/radeon.h +0 -1
@@ -497,7 +497,6 @@ struct radeon_bo {struct ttm_buffer_object tbo;struct ttm_bo_kmap_obj kmap;u32 flags; -unsigned pin_count;void *kptr;u32 tiling_flags;u32 pitch;
drivers/gpu/drm/radeon/radeon_display.c +2 -7
@@ -273,10 +273,7 @@ static void radeon_unpin_work_func(struct work_struct *__work)/* unpin of the old buffer */ r =radeon_bo_reserve (work->old_rbo, false);if (likely (r ==0 )) { - r =radeon_bo_unpin (work->old_rbo); -if (unlikely (r !=0 )) { -DRM_ERROR ("failed to unpin buffer after flip\n" ); - } +radeon_bo_unpin (work->old_rbo);radeon_bo_unreserve (work->old_rbo); }else DRM_ERROR ("failed to reserve buffer after flip\n" );
@@ -607,9 +604,7 @@ static int radeon_crtc_page_flip_target(struct drm_crtc *crtc,DRM_ERROR ("failed to reserve new rbo in error path\n" ); goto cleanup; } -if (unlikely (radeon_bo_unpin (new_rbo) !=0 )) { -DRM_ERROR ("failed to unpin new rbo in error path\n" ); - } +radeon_bo_unpin (new_rbo);radeon_bo_unreserve (new_rbo); cleanup:
drivers/gpu/drm/radeon/radeon_object.c +9 -28
@@ -334,8 +334,8 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,if (radeon_ttm_tt_has_userptr (bo->rdev, bo->tbo.ttm))return -EPERM ; -if (bo->pin_count) { - bo->pin_count++; +if (bo->tbo.pin_count) { +ttm_bo_pin (&bo->tbo);if (gpu_addr) *gpu_addr =radeon_bo_gpu_offset (bo);
@@ -367,13 +367,11 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset, bo->rdev->mc.visible_vram_size >>PAGE_SHIFT ; else bo->placements[i].lpfn = max_offset >> PAGE_SHIFT; - - bo->placements[i].flags |=TTM_PL_FLAG_NO_EVICT ; } r =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);if (likely (r ==0 )) { - bo->pin_count =1 ; +ttm_bo_pin (&bo->tbo);if (gpu_addr !=NULL ) *gpu_addr =radeon_bo_gpu_offset (bo);if (domain ==RADEON_GEM_DOMAIN_VRAM )
@@ -391,32 +389,15 @@ int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr)return radeon_bo_pin_restricted (bo, domain,0 , gpu_addr); } -int radeon_bo_unpin (struct radeon_bo *bo) +void radeon_bo_unpin (struct radeon_bo *bo) { -struct ttm_operation_ctx ctx = { false, false }; -int r, i; - -if (!bo->pin_count) { -dev_warn (bo->rdev->dev,"%p unpin not necessary\n" , bo); -return 0 ; - } - bo->pin_count--; -if (bo->pin_count) -return 0 ; -for (i =0 ; i < bo->placement.num_placement; i++) { - bo->placements[i].lpfn =0 ; - bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT ; - } - r =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); -if (likely (r ==0 )) { +ttm_bo_unpin (&bo->tbo); +if (!bo->tbo.pin_count) {if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) bo->rdev->vram_pin_size -=radeon_bo_size (bo);else bo->rdev->gart_pin_size -=radeon_bo_size (bo); - }else { -dev_err (bo->rdev->dev,"%p validate failed for unpin\n" , bo); } -return r; }int radeon_bo_evict_vram (struct radeon_device *rdev)
@@ -549,7 +530,7 @@ int radeon_bo_list_validate(struct radeon_device *rdev,list_for_each_entry (lobj, head, tv.head) {struct radeon_bo *bo = lobj->robj; -if (!bo->pin_count) { +if (!bo->tbo.pin_count) {u32 domain = lobj->preferred_domains;u32 allowed = lobj->allowed_domains; u32 current_domain =
@@ -629,7 +610,7 @@ int radeon_bo_get_surface_reg(struct radeon_bo *bo)break ; old_object = reg->bo; -if (old_object->pin_count ==0 ) +if (old_object->tbo.pin_count ==0 ) steal = i; }
@@ -816,7 +797,7 @@ int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo)return 0 ;/* Can't move a pinned BO to visible VRAM */ -if (rbo->pin_count >0 ) +if (rbo->tbo.pin_count >0 )return -EINVAL ;/* hurrah the memory is not visible ! */
drivers/gpu/drm/radeon/radeon_object.h +1 -1
@@ -149,7 +149,7 @@ extern void radeon_bo_unref(struct radeon_bo **bo);extern int radeon_bo_pin (struct radeon_bo *bo,u32 domain,u64 *gpu_addr);extern int radeon_bo_pin_restricted (struct radeon_bo *bo,u32 domain,u64 max_offset,u64 *gpu_addr); -extern int radeon_bo_unpin (struct radeon_bo *bo); +extern void radeon_bo_unpin (struct radeon_bo *bo);extern int radeon_bo_evict_vram (struct radeon_device *rdev);extern void radeon_bo_force_delete (struct radeon_device *rdev);extern int radeon_bo_init (struct radeon_device *rdev);
drivers/gpu/drm/radeon/radeon_ttm.c +1 -1
@@ -310,7 +310,7 @@ static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,/* Can't move a pinned BO */ rbo = container_of(bo, struct radeon_bo, tbo); -if (WARN_ON_ONCE (rbo->pin_count >0 )) +if (WARN_ON_ONCE (rbo->tbo.pin_count >0 ))return -EINVAL ; rdev =radeon_get_rdev (bo->bdev);
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 9/11 drm/amdgpu: switch over to the new pin interface
In reply to Christian KönigStop using TTM_PL_FLAG_NO_EVICT.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 8 +--- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 41 +++++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 9 files changed, 24 insertions(+), 46 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3 -2
@@ -1479,7 +1479,7 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( } } -if (!amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) && !bo->pin_count) +if (!amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) && !bo->tbo.pin_count)amdgpu_bo_fence (bo, &avm->process_info->eviction_fence->base, true);
@@ -1558,7 +1558,8 @@ int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(* required. */ if (mem->mapped_to_gpu_memory ==0 && - !amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && !mem->bo->pin_count) + !amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && + !mem->bo->tbo.pin_count)amdgpu_amdkfd_remove_eviction_fence (mem->bo, process_info->eviction_fence);
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -410,7 +410,7 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,uint32_t domain;int r; -if (bo->pin_count) +if (bo->tbo.pin_count)return 0 ;/* Don't move this buffer if we have depleted our allowance
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -6
@@ -132,10 +132,7 @@ static void amdgpu_display_unpin_work_func(struct work_struct *__work)/* unpin of the old buffer */ r =amdgpu_bo_reserve (work->old_abo, true);if (likely (r ==0 )) { - r =amdgpu_bo_unpin (work->old_abo); -if (unlikely (r !=0 )) { -DRM_ERROR ("failed to unpin buffer after flip\n" ); - } +amdgpu_bo_unpin (work->old_abo);amdgpu_bo_unreserve (work->old_abo); }else DRM_ERROR ("failed to reserve buffer after flip\n" );
@@ -249,8 +246,7 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc, } unpin:if (!adev->enable_virtual_display) -if (unlikely (amdgpu_bo_unpin (new_abo) !=0 )) -DRM_ERROR ("failed to unpin new abo in error path\n" ); +amdgpu_bo_unpin (new_abo); unreserve:amdgpu_bo_unreserve (new_abo);
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +3 -2
@@ -281,7 +281,7 @@ static struct sg_table *amdgpu_dma_buf_map(struct dma_buf_attachment *attach,struct sg_table *sgt;long r; -if (!bo->pin_count) { +if (!bo->tbo.pin_count) {/* move buffer into GTT or VRAM */ struct ttm_operation_ctx ctx = { false, false };unsigned domains =AMDGPU_GEM_DOMAIN_GTT ;
@@ -390,7 +390,8 @@ static int amdgpu_dma_buf_begin_cpu_access(struct dma_buf *dma_buf,if (unlikely (ret !=0 ))return ret; -if (!bo->pin_count && (bo->allowed_domains &AMDGPU_GEM_DOMAIN_GTT )) { +if (!bo->tbo.pin_count && + (bo->allowed_domains &AMDGPU_GEM_DOMAIN_GTT )) {amdgpu_bo_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_GTT ); ret =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); }
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -1
@@ -860,7 +860,7 @@ static int amdgpu_debugfs_gem_bo_info(int id, void *ptr, void *data)seq_printf (m,"\t0x%08x: %12ld byte %s" , id,amdgpu_bo_size (bo), placement); - pin_count =READ_ONCE (bo->pin_count); + pin_count =READ_ONCE (bo->tbo.pin_count);if (pin_count)seq_printf (m," pin count %d" , pin_count);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +11 -30
100 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -2
@@ -89,7 +89,6 @@ struct amdgpu_bo {struct ttm_buffer_object tbo;struct ttm_bo_kmap_obj kmap;u64 flags; -unsigned pin_count;u64 tiling_flags;u64 metadata_flags;void *metadata;
@@ -267,7 +266,7 @@ void amdgpu_bo_unref(struct amdgpu_bo **bo);int amdgpu_bo_pin (struct amdgpu_bo *bo,u32 domain);int amdgpu_bo_pin_restricted (struct amdgpu_bo *bo,u32 domain,u64 min_offset,u64 max_offset); -int amdgpu_bo_unpin (struct amdgpu_bo *bo); +void amdgpu_bo_unpin (struct amdgpu_bo *bo);int amdgpu_bo_evict_vram (struct amdgpu_device *adev);int amdgpu_bo_init (struct amdgpu_device *adev);int amdgpu_bo_late_init (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
@@ -662,7 +662,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,/* Can't move a pinned BO */ abo =ttm_to_amdgpu_bo (bo); -if (WARN_ON_ONCE (abo->pin_count >0 )) +if (WARN_ON_ONCE (abo->tbo.pin_count >0 ))return -EINVAL ; adev =amdgpu_ttm_adev (bo->bdev);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -609,7 +609,7 @@ void amdgpu_vm_del_from_lru_notify(struct ttm_buffer_object *bo)if (!amdgpu_bo_is_amdgpu_bo (bo))return ; -if (bo->mem.placement &TTM_PL_FLAG_NO_EVICT ) +if (bo->pin_count)return ; abo =ttm_to_amdgpu_bo (bo);
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 09/11] drm/amdgpu: switch over to the new pin interface
Quoted 264 lines · Christian König
Stop using
TTM_PL_FLAG_NO_EVICT.Signed-off-by Christian König <[email protected]>--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 8 +--- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 41 +++++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 9 files changed, 24 insertions(+), 46 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-2@@ -1479,7 +1479,7 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( } } -if (!amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) && !bo->pin_count) +if (!amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) && !bo->tbo.pin_count)amdgpu_bo_fence (bo, &avm->process_info->eviction_fence->base, true);@@ -1558,7 +1558,8 @@ int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(* required. */ if (mem->mapped_to_gpu_memory ==0 && - !amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && !mem->bo->pin_count) + !amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && + !mem->bo->tbo.pin_count)amdgpu_amdkfd_remove_eviction_fence (mem->bo, process_info->eviction_fence);drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1@@ -410,7 +410,7 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,uint32_t domain;int r; -if (bo->pin_count) +if (bo->tbo.pin_count)return 0 ;/* Don't move this buffer if we have depleted our allowance drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2
-6@@ -132,10 +132,7 @@ static void amdgpu_display_unpin_work_func(struct work_struct *__work)/* unpin of the old buffer */ r =amdgpu_bo_reserve (work->old_abo, true);if (likely (r ==0 )) { - r =amdgpu_bo_unpin (work->old_abo); -if (unlikely (r !=0 )) { -DRM_ERROR ("failed to unpin buffer after flip\n" ); - } +amdgpu_bo_unpin (work->old_abo);amdgpu_bo_unreserve (work->old_abo); }else DRM_ERROR ("failed to reserve buffer after flip\n" );@@ -249,8 +246,7 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc, } unpin:if (!adev->enable_virtual_display) -if (unlikely (amdgpu_bo_unpin (new_abo) !=0 )) -DRM_ERROR ("failed to unpin new abo in error path\n" ); +amdgpu_bo_unpin (new_abo); unreserve:amdgpu_bo_unreserve (new_abo);drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +3
-2@@ -281,7 +281,7 @@ static struct sg_table *amdgpu_dma_buf_map(struct dma_buf_attachment *attach,struct sg_table *sgt;long r; -if (!bo->pin_count) { +if (!bo->tbo.pin_count) {/* move buffer into GTT or VRAM */ struct ttm_operation_ctx ctx = { false, false };unsigned domains =AMDGPU_GEM_DOMAIN_GTT ;@@ -390,7 +390,8 @@ static int amdgpu_dma_buf_begin_cpu_access(struct dma_buf *dma_buf,if (unlikely (ret !=0 ))return ret; -if (!bo->pin_count && (bo->allowed_domains &AMDGPU_GEM_DOMAIN_GTT )) { +if (!bo->tbo.pin_count && + (bo->allowed_domains &AMDGPU_GEM_DOMAIN_GTT )) {amdgpu_bo_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_GTT ); ret =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -860,7 +860,7 @@ static int amdgpu_debugfs_gem_bo_info(int id, void *ptr, void *data)seq_printf (m,"\t0x%08x: %12ld byte %s" , id,amdgpu_bo_size (bo), placement); - pin_count =READ_ONCE (bo->pin_count); + pin_count =READ_ONCE (bo->tbo.pin_count);if (pin_count)seq_printf (m," pin count %d" , pin_count);drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +11
-30@@ -78,7 +78,7 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)struct amdgpu_device *adev =amdgpu_ttm_adev (tbo->bdev);struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); -if (bo->pin_count >0 ) +if (bo->tbo.pin_count >0 )amdgpu_bo_subtract_pin_size (bo);amdgpu_bo_kunmap (bo);@@ -721,7 +721,7 @@ int amdgpu_bo_validate(struct amdgpu_bo *bo)uint32_t domain;int r; -if (bo->pin_count) +if (bo->tbo.pin_count)return 0 ; domain = bo->preferred_domains;@@ -918,13 +918,13 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,*/ domain =amdgpu_bo_get_preferred_pin_domain (adev, domain); -if (bo->pin_count) { +if (bo->tbo.pin_count) {uint32_t mem_type = bo->tbo.mem.mem_type;if (!(domain &amdgpu_mem_type_to_domain (mem_type)))return -EINVAL ; - bo->pin_count++; +ttm_bo_pin (&bo->tbo);if (max_offset !=0 ) { u64 domain_start = amdgpu_ttm_domain_start(adev,@@ -955,7 +955,6 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,if (!bo->placements[i].lpfn || (lpfn && lpfn < bo->placements[i].lpfn)) bo->placements[i].lpfn = lpfn; - bo->placements[i].flags |=TTM_PL_FLAG_NO_EVICT ; } r =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);@@ -964,7 +963,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, goto error; } - bo->pin_count =1 ; +ttm_bo_pin (&bo->tbo); domain =amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type);if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) {@@ -1006,34 +1005,16 @@ int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain)* Returns: * 0 for success or a negative error code on failure. */ -int amdgpu_bo_unpin (struct amdgpu_bo *bo) +void amdgpu_bo_unpin (struct amdgpu_bo *bo) { -struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); -struct ttm_operation_ctx ctx = { false, false }; -int r, i; - -if (WARN_ON_ONCE (!bo->pin_count)) { -dev_warn (adev->dev,"%p unpin not necessary\n" , bo); -return 0 ; - } - bo->pin_count--; -if (bo->pin_count) -return 0 ; +ttm_bo_unpin (&bo->tbo); +if (bo->tbo.pin_count) +return ;amdgpu_bo_subtract_pin_size (bo);if (bo->tbo.base.import_attach)dma_buf_unpin (bo->tbo.base.import_attach); - -for (i =0 ; i < bo->placement.num_placement; i++) { - bo->placements[i].lpfn =0 ; - bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT ; - } - r =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); -if (unlikely (r)) -dev_err (adev->dev,"%p validate failed for unpin\n" , bo); - -return r; }/** @@ -1385,7 +1366,7 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)return 0 ;/* Can't move a pinned BO to visible VRAM */ -if (abo->pin_count >0 ) +if (abo->tbo.pin_count >0 )return -EINVAL ;/* hurrah the memory is not visible ! */ @@ -1489,7 +1470,7 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) {WARN_ON_ONCE (bo->tbo.mem.mem_type ==TTM_PL_SYSTEM );WARN_ON_ONCE (!dma_resv_is_locked (bo->tbo.base.resv) && - !bo->pin_count && bo->tbo.type != ttm_bo_type_kernel); + !bo->tbo.pin_count && bo->tbo.type != ttm_bo_type_kernel);WARN_ON_ONCE (bo->tbo.mem.start ==AMDGPU_BO_INVALID_OFFSET );WARN_ON_ONCE (bo->tbo.mem.mem_type ==TTM_PL_VRAM && !(bo->flags &AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS ));drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1
-2@@ -89,7 +89,6 @@ struct amdgpu_bo {struct ttm_buffer_object tbo;struct ttm_bo_kmap_obj kmap;u64 flags; -unsigned pin_count;u64 tiling_flags;u64 metadata_flags;void *metadata;@@ -267,7 +266,7 @@ void amdgpu_bo_unref(struct amdgpu_bo **bo);int amdgpu_bo_pin (struct amdgpu_bo *bo,u32 domain);int amdgpu_bo_pin_restricted (struct amdgpu_bo *bo,u32 domain,u64 min_offset,u64 max_offset); -int amdgpu_bo_unpin (struct amdgpu_bo *bo); +void amdgpu_bo_unpin (struct amdgpu_bo *bo);int amdgpu_bo_evict_vram (struct amdgpu_device *adev);int amdgpu_bo_init (struct amdgpu_device *adev);int amdgpu_bo_late_init (struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -662,7 +662,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,/* Can't move a pinned BO */ abo =ttm_to_amdgpu_bo (bo); -if (WARN_ON_ONCE (abo->pin_count >0 )) +if (WARN_ON_ONCE (abo->tbo.pin_count >0 ))return -EINVAL ; adev =amdgpu_ttm_adev (bo->bdev);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_del_from_lru_notify(struct ttm_buffer_object *bo) · line 615
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -609,7 +609,7 @@ void amdgpu_vm_del_from_lru_notify(struct ttm_buffer_object *bo)if (!amdgpu_bo_is_amdgpu_bo (bo))return ; -if (bo->mem.placement &TTM_PL_FLAG_NO_EVICT ) +if (bo->pin_count)return ; abo =ttm_to_amdgpu_bo (bo);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 09/11] drm/amdgpu: switch over to the new pin interface
In reply to Christian KönigQuoted 264 lines · Christian König
Stop using
TTM_PL_FLAG_NO_EVICT.Signed-off-by Christian König <[email protected]>--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 8 +--- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 41 +++++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 9 files changed, 24 insertions(+), 46 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-2@@ -1479,7 +1479,7 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( } } -if (!amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) && !bo->pin_count) +if (!amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) && !bo->tbo.pin_count)amdgpu_bo_fence (bo, &avm->process_info->eviction_fence->base, true);@@ -1558,7 +1558,8 @@ int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(* required. */ if (mem->mapped_to_gpu_memory ==0 && - !amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && !mem->bo->pin_count) + !amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && + !mem->bo->tbo.pin_count)amdgpu_amdkfd_remove_eviction_fence (mem->bo, process_info->eviction_fence);drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1@@ -410,7 +410,7 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,uint32_t domain;int r; -if (bo->pin_count) +if (bo->tbo.pin_count)return 0 ;/* Don't move this buffer if we have depleted our allowance drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2
-6@@ -132,10 +132,7 @@ static void amdgpu_display_unpin_work_func(struct work_struct *__work)/* unpin of the old buffer */ r =amdgpu_bo_reserve (work->old_abo, true);if (likely (r ==0 )) { - r =amdgpu_bo_unpin (work->old_abo); -if (unlikely (r !=0 )) { -DRM_ERROR ("failed to unpin buffer after flip\n" ); - } +amdgpu_bo_unpin (work->old_abo);amdgpu_bo_unreserve (work->old_abo); }else DRM_ERROR ("failed to reserve buffer after flip\n" );@@ -249,8 +246,7 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc, } unpin:if (!adev->enable_virtual_display) -if (unlikely (amdgpu_bo_unpin (new_abo) !=0 )) -DRM_ERROR ("failed to unpin new abo in error path\n" ); +amdgpu_bo_unpin (new_abo); unreserve:amdgpu_bo_unreserve (new_abo);drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +3
-2@@ -281,7 +281,7 @@ static struct sg_table *amdgpu_dma_buf_map(struct dma_buf_attachment *attach,struct sg_table *sgt;long r; -if (!bo->pin_count) { +if (!bo->tbo.pin_count) {/* move buffer into GTT or VRAM */ struct ttm_operation_ctx ctx = { false, false };unsigned domains =AMDGPU_GEM_DOMAIN_GTT ;@@ -390,7 +390,8 @@ static int amdgpu_dma_buf_begin_cpu_access(struct dma_buf *dma_buf,if (unlikely (ret !=0 ))return ret; -if (!bo->pin_count && (bo->allowed_domains &AMDGPU_GEM_DOMAIN_GTT )) { +if (!bo->tbo.pin_count && + (bo->allowed_domains &AMDGPU_GEM_DOMAIN_GTT )) {amdgpu_bo_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_GTT ); ret =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -860,7 +860,7 @@ static int amdgpu_debugfs_gem_bo_info(int id, void *ptr, void *data)seq_printf (m,"\t0x%08x: %12ld byte %s" , id,amdgpu_bo_size (bo), placement); - pin_count =READ_ONCE (bo->pin_count); + pin_count =READ_ONCE (bo->tbo.pin_count);if (pin_count)seq_printf (m," pin count %d" , pin_count);drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +11
-30@@ -78,7 +78,7 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)struct amdgpu_device *adev =amdgpu_ttm_adev (tbo->bdev);struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); -if (bo->pin_count >0 ) +if (bo->tbo.pin_count >0 )amdgpu_bo_subtract_pin_size (bo);amdgpu_bo_kunmap (bo);@@ -721,7 +721,7 @@ int amdgpu_bo_validate(struct amdgpu_bo *bo)uint32_t domain;int r; -if (bo->pin_count) +if (bo->tbo.pin_count)return 0 ; domain = bo->preferred_domains;@@ -918,13 +918,13 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,*/ domain =amdgpu_bo_get_preferred_pin_domain (adev, domain); -if (bo->pin_count) { +if (bo->tbo.pin_count) {uint32_t mem_type = bo->tbo.mem.mem_type;if (!(domain &amdgpu_mem_type_to_domain (mem_type)))return -EINVAL ; - bo->pin_count++; +ttm_bo_pin (&bo->tbo);if (max_offset !=0 ) { u64 domain_start = amdgpu_ttm_domain_start(adev,@@ -955,7 +955,6 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,if (!bo->placements[i].lpfn || (lpfn && lpfn < bo->placements[i].lpfn)) bo->placements[i].lpfn = lpfn; - bo->placements[i].flags |=TTM_PL_FLAG_NO_EVICT ; } r =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);@@ -964,7 +963,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, goto error; } - bo->pin_count =1 ; +ttm_bo_pin (&bo->tbo); domain =amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type);if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) {@@ -1006,34 +1005,16 @@ int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain)* Returns: * 0 for success or a negative error code on failure. */ -int amdgpu_bo_unpin (struct amdgpu_bo *bo) +void amdgpu_bo_unpin (struct amdgpu_bo *bo) { -struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); -struct ttm_operation_ctx ctx = { false, false }; -int r, i; - -if (WARN_ON_ONCE (!bo->pin_count)) { -dev_warn (adev->dev,"%p unpin not necessary\n" , bo); -return 0 ; - } - bo->pin_count--; -if (bo->pin_count) -return 0 ; +ttm_bo_unpin (&bo->tbo); +if (bo->tbo.pin_count) +return ;amdgpu_bo_subtract_pin_size (bo);if (bo->tbo.base.import_attach)dma_buf_unpin (bo->tbo.base.import_attach); - -for (i =0 ; i < bo->placement.num_placement; i++) { - bo->placements[i].lpfn =0 ; - bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT ; - } - r =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); -if (unlikely (r)) -dev_err (adev->dev,"%p validate failed for unpin\n" , bo); - -return r; }/** @@ -1385,7 +1366,7 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)return 0 ;/* Can't move a pinned BO to visible VRAM */ -if (abo->pin_count >0 ) +if (abo->tbo.pin_count >0 )return -EINVAL ;/* hurrah the memory is not visible ! */ @@ -1489,7 +1470,7 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) {WARN_ON_ONCE (bo->tbo.mem.mem_type ==TTM_PL_SYSTEM );WARN_ON_ONCE (!dma_resv_is_locked (bo->tbo.base.resv) && - !bo->pin_count && bo->tbo.type != ttm_bo_type_kernel); + !bo->tbo.pin_count && bo->tbo.type != ttm_bo_type_kernel);WARN_ON_ONCE (bo->tbo.mem.start ==AMDGPU_BO_INVALID_OFFSET );WARN_ON_ONCE (bo->tbo.mem.mem_type ==TTM_PL_VRAM && !(bo->flags &AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS ));drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1
-2@@ -89,7 +89,6 @@ struct amdgpu_bo {struct ttm_buffer_object tbo;struct ttm_bo_kmap_obj kmap;u64 flags; -unsigned pin_count;u64 tiling_flags;u64 metadata_flags;void *metadata;@@ -267,7 +266,7 @@ void amdgpu_bo_unref(struct amdgpu_bo **bo);int amdgpu_bo_pin (struct amdgpu_bo *bo,u32 domain);int amdgpu_bo_pin_restricted (struct amdgpu_bo *bo,u32 domain,u64 min_offset,u64 max_offset); -int amdgpu_bo_unpin (struct amdgpu_bo *bo); +void amdgpu_bo_unpin (struct amdgpu_bo *bo);int amdgpu_bo_evict_vram (struct amdgpu_device *adev);int amdgpu_bo_init (struct amdgpu_device *adev);int amdgpu_bo_late_init (struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -662,7 +662,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,/* Can't move a pinned BO */ abo =ttm_to_amdgpu_bo (bo); -if (WARN_ON_ONCE (abo->pin_count >0 )) +if (WARN_ON_ONCE (abo->tbo.pin_count >0 ))return -EINVAL ; adev =amdgpu_ttm_adev (bo->bdev);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_del_from_lru_notify(struct ttm_buffer_object *bo) · line 615
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -609,7 +609,7 @@ void amdgpu_vm_del_from_lru_notify(struct ttm_buffer_object *bo)if (!amdgpu_bo_is_amdgpu_bo (bo))return ; -if (bo->mem.placement &TTM_PL_FLAG_NO_EVICT ) +if (bo->pin_count)return ; abo =ttm_to_amdgpu_bo (bo);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 10/11 drm/ttm: remove ttm_bo_create
In reply to Christian KönigNot used any more.
--- drivers/gpu/drm/ttm/ttm_bo.c | 40 ------------------------------------ include/drm/ttm/ttm_bo_api.h | 24 ---------------------- 2 files changed, 64 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -40
@@ -1254,19 +1254,6 @@ int ttm_bo_init(struct ttm_bo_device *bdev, }EXPORT_SYMBOL (ttm_bo_init); -static size_t ttm_bo_acc_size (struct ttm_bo_device *bdev, -unsigned long bo_size, -unsigned struct_size) -{ -unsigned npages = (PAGE_ALIGN (bo_size)) >>PAGE_SHIFT ; -size_t size =0 ; - - size +=ttm_round_pot (struct_size); - size +=ttm_round_pot (npages *sizeof (void *)); - size +=ttm_round_pot (sizeof (struct ttm_tt )); -return size; -} -size_t ttm_bo_dma_acc_size (struct ttm_bo_device *bdev,unsigned long bo_size,unsigned struct_size)
@@ -1281,33 +1268,6 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, }EXPORT_SYMBOL (ttm_bo_dma_acc_size); -int ttm_bo_create (struct ttm_bo_device *bdev, -unsigned long size, -enum ttm_bo_type type, -struct ttm_placement *placement, -uint32_t page_alignment, -bool interruptible, -struct ttm_buffer_object **p_bo) -{ -struct ttm_buffer_object *bo; -size_t acc_size; -int ret; - - bo =kzalloc (sizeof (*bo),GFP_KERNEL ); -if (unlikely (bo ==NULL )) -return -ENOMEM ; - - acc_size =ttm_bo_acc_size (bdev, size,sizeof (struct ttm_buffer_object )); - ret =ttm_bo_init (bdev, bo, size, type, placement, page_alignment, - interruptible, acc_size, -NULL ,NULL ,NULL ); -if (likely (ret ==0 )) - *p_bo = bo; - -return ret; -} -EXPORT_SYMBOL (ttm_bo_create); -int ttm_bo_evict_mm (struct ttm_bo_device *bdev,unsigned mem_type) {struct ttm_resource_manager *man =ttm_manager_type (bdev, mem_type);
include/drm/ttm/ttm_bo_api.h +0 -24
@@ -447,30 +447,6 @@ int ttm_bo_init(struct ttm_bo_device *bdev, struct ttm_buffer_object *bo, struct sg_table *sg, struct dma_resv *resv, void (*destroy) (struct ttm_buffer_object *)); -/** -* ttm_bo_create -* -* @bdev: Pointer to a ttm_bo_device struct. -* @size: Requested size of buffer object. -* @type: Requested type of buffer object. -* @placement: Initial placement. -* @page_alignment: Data alignment in pages. -* @interruptible: If needing to sleep while waiting for GPU resources, -* sleep interruptible. -* @p_bo: On successful completion *p_bo points to the created object. -* -* This function allocates a ttm_buffer_object, and then calls ttm_bo_init -* on that object. The destroy function is set to kfree(). -* Returns -* -ENOMEM: Out of memory. -* -EINVAL: Invalid placement flags. -* -ERESTARTSYS: Interrupted by signal while waiting for resources. -*/ -int ttm_bo_create (struct ttm_bo_device *bdev,unsigned long size, -enum ttm_bo_type type,struct ttm_placement *placement, -uint32_t page_alignment,bool interruptible, -struct ttm_buffer_object **p_bo); -/** * ttm_bo_evict_mm *
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 11/11 drm/ttm: remove TTM_PL_FLAG_NO_EVICT
In reply to Christian KönigNot used any more.
--- drivers/gpu/drm/ttm/ttm_bo.c | 11 +++-------- include/drm/ttm/ttm_placement.h | 1 - 2 files changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +3 -8
@@ -118,9 +118,6 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,if (!list_empty (&bo->lru) || bo->pin_count)return ; -if (mem->placement &TTM_PL_FLAG_NO_EVICT ) -return ; - man =ttm_manager_type (bdev, mem->mem_type);list_add_tail (&bo->lru, &man->lru[bo->priority]);
@@ -165,8 +162,7 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,ttm_bo_del_from_lru (bo);ttm_bo_add_mem_to_lru (bo, &bo->mem); -if (bulk && !(bo->mem.placement &TTM_PL_FLAG_NO_EVICT ) && - !bo->pin_count) { +if (bulk && !bo->pin_count) {switch (bo->mem.mem_type) {case TTM_PL_TT :ttm_bo_bulk_move_set_pos (&bulk->tt[bo->priority], bo);
@@ -541,12 +537,11 @@ static void ttm_bo_release(struct kref *kref)spin_lock (&ttm_bo_glob.lru_lock);/* -* Make NO_EVICT bos immediately available to +* Make pinned bos immediately available to * shrinkers, now that they are queued for * destruction. */ -if (bo->mem.placement &TTM_PL_FLAG_NO_EVICT || bo->pin_count) { - bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT ; +if (bo->pin_count) { bo->pin_count =0 ;ttm_bo_del_from_lru (bo);ttm_bo_add_mem_to_lru (bo, &bo->mem);
include/drm/ttm/ttm_placement.h +0 -1
@@ -58,7 +58,6 @@#define TTM_PL_FLAG_UNCACHED (1 << 17)#define TTM_PL_FLAG_WC (1 << 18)#define TTM_PL_FLAG_CONTIGUOUS (1 << 19) -#define TTM_PL_FLAG_NO_EVICT (1 << 21)#define TTM_PL_FLAG_TOPDOWN (1 << 22)#define TTM_PL_MASK_CACHING (TTM_PL_FLAG_CACHED | \
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 3 lines · Christian König
As an alternative to the placement flag add a
pin count to the ttm buffer object.
These all look good to me, nice cleanup.
For the series:
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 10 lines · Dave Airlie
Quoted 3 lines · Christian König
As an alternative to the placement flag add a
pin count to the ttm buffer object.These all look good to me, nice cleanup.
For the series:
Reviewed-by Dave Airlie <[email protected]>
Yeah I like, but plenty of review already so I wont bother.
I do wonder whether we should/could lift this one more level to drm_gem_object, since cma/shmem gem helpers have this too.
But they have hand-rolled locking for it of dubious quality, and don't use dma_resv_lock for any of this unfortunately. And I guess that would need to be fixed first.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 6 lines · Christian König
As an alternative to the placement flag add a
pin count to the ttm buffer object.v2: add
dma_resv_assert_help()callsSigned-off-by Christian König <[email protected]>
Series look good for me as well.
Only one comment:
We can modify the TOPDOWN offset as 21 since the NO_EVICT is removed.
#define TTM_PL_FLAG_UNCACHED (1 << 17) #define TTM_PL_FLAG_WC (1 << 18) #define TTM_PL_FLAG_CONTIGUOUS (1 << 19) -#define TTM_PL_FLAG_NO_EVICT (1 << 21) #define TTM_PL_FLAG_TOPDOWN (1 << 22)
Thanks,
Ray
Quoted 115 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 9 ++++++--- drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +- include/drm/ttm/ttm_bo_api.h | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +6
-3@@ -115,7 +115,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,struct ttm_bo_device *bdev = bo->bdev;struct ttm_resource_manager *man; -if (!list_empty (&bo->lru)) +if (!list_empty (&bo->lru) || bo->pin_count)return ;if (mem->placement &TTM_PL_FLAG_NO_EVICT )@@ -165,7 +165,8 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,ttm_bo_del_from_lru (bo);ttm_bo_add_mem_to_lru (bo, &bo->mem); -if (bulk && !(bo->mem.placement &TTM_PL_FLAG_NO_EVICT )) { +if (bulk && !(bo->mem.placement &TTM_PL_FLAG_NO_EVICT ) && + !bo->pin_count) {switch (bo->mem.mem_type) {case TTM_PL_TT :ttm_bo_bulk_move_set_pos (&bulk->tt[bo->priority], bo);@@ -544,8 +545,9 @@ static void ttm_bo_release(struct kref *kref)* shrinkers, now that they are queued for * destruction. */ -if (bo->mem.placement &TTM_PL_FLAG_NO_EVICT ) { +if (bo->mem.placement &TTM_PL_FLAG_NO_EVICT || bo->pin_count) { bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT ; + bo->pin_count =0 ;ttm_bo_del_from_lru (bo);ttm_bo_add_mem_to_lru (bo, &bo->mem); }@@ -1172,6 +1174,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev, bo->moving =NULL ; bo->mem.placement =TTM_PL_FLAG_CACHED ; bo->acc_size = acc_size; + bo->pin_count =0 ; bo->sg = sg;if (resv) { bo->base.resv = resv;drivers/gpu/drm/ttm/ttm_bo_util.c +1
-1@@ -352,7 +352,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,return -ENOMEM ; fbo->base = *bo; - fbo->base.mem.placement |=TTM_PL_FLAG_NO_EVICT ;ttm_bo_get (bo); fbo->bo = bo;@@ -372,6 +371,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,kref_init (&fbo->base.kref); fbo->base.destroy = &ttm_transfered_destroy; fbo->base.acc_size =0 ; + fbo->base.pin_count =1 ;if (bo->type != ttm_bo_type_sg) fbo->base.base.resv = &fbo->base.base._resv;include/drm/ttm/ttm_bo_api.h +26
-0@@ -157,6 +157,7 @@ struct ttm_buffer_object {struct dma_fence *moving;unsigned priority; +unsigned pin_count;/** * Special members that are protected by the reserve lock @@ -606,6 +607,31 @@ static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)return bo->base.dev !=NULL ; } +/** +* ttm_bo_pin - Pin the buffer object. +* @bo: The buffer object to pin +* +* Make sure the buffer is not evicted any more during memory pressure. +*/ +static inline void ttm_bo_pin (struct ttm_buffer_object *bo) +{ +dma_resv_assert_held (bo->base.resv); + ++bo->pin_count; +} + +/** +* ttm_bo_unpin - Unpin the buffer object. +* @bo: The buffer object to unpin +* +* Allows the buffer object to be evicted again during memory pressure. +*/ +static inline void ttm_bo_unpin (struct ttm_buffer_object *bo) +{ +dma_resv_assert_held (bo->base.resv); +WARN_ON_ONCE (!bo->pin_count); + --bo->pin_count; +} + int ttm_mem_evict_first(struct ttm_bo_device *bdev, struct ttm_resource_manager *man, const struct ttm_place *place,Signature · 1 line
2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel