drm/ttm: move swapout logic around
Subsystems (6)
PATCH 1/3 drm/ttm: move swapout logic around
Move the iteration of the global lru into the new function ttm_global_swapout() and use that instead in drivers.
--- drivers/gpu/drm/ttm/ttm_bo.c | 57 ++++++++--------------------- drivers/gpu/drm/ttm/ttm_device.c | 29 +++++++++++++++ drivers/gpu/drm/ttm/ttm_tt.c | 2 +- drivers/gpu/drm/vmwgfx/ttm_memory.c | 3 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 2 +- include/drm/ttm/ttm_bo_api.h | 3 +- include/drm/ttm/ttm_device.h | 2 + 7 files changed, 53 insertions(+), 45 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +16 -41
@@ -1184,56 +1184,35 @@ int ttm_bo_wait(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_wait); -/* -* 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_operation_ctx *ctx,gfp_t gfp_flags) +int ttm_bo_swapout (struct ttm_buffer_object *bo,struct ttm_operation_ctx *ctx, +gfp_t gfp_flags) {struct ttm_global *glob = &ttm_glob; -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) { -if (!ttm_bo_evict_swapout_allowable (bo, ctx, &locked, -NULL )) -continue ; - -if (!ttm_bo_get_unless_zero (bo)) { -if (locked) -dma_resv_unlock (bo->base.resv); -continue ; - } +int ret; - ret =0 ; -break ; - } -if (!ret) -break ; - } +if (!ttm_bo_evict_swapout_allowable (bo, ctx, &locked,NULL )) +return -EBUSY ; -if (ret) { -spin_unlock (&glob->lru_lock); -return ret; +if (!ttm_bo_get_unless_zero (bo)) { +if (locked) +dma_resv_unlock (bo->base.resv); +return -EBUSY ; }if (bo->deleted) { - ret =ttm_bo_cleanup_refs (bo, false, false, locked); +ttm_bo_cleanup_refs (bo, false, false, locked);ttm_bo_put (bo); -return ret; +return 0 ; }ttm_bo_del_from_lru (bo); +/* TODO: Cleanup the locking */ spin_unlock (&glob->lru_lock); -/** +/* * Move to system cached */ -if (bo->mem.mem_type !=TTM_PL_SYSTEM ) {struct ttm_operation_ctx ctx = { false, false };struct ttm_resource evict_mem;
@@ -1253,29 +1232,26 @@ int ttm_bo_swapout(struct ttm_operation_ctx *ctx, gfp_t gfp_flags) } } -/** +/* * Make sure BO is idle. */ - ret =ttm_bo_wait (bo, false, false);if (unlikely (ret !=0 )) goto out;ttm_bo_unmap_virtual (bo); -/** +/* * Swap out. Buffer will be swapped in again as soon as * anyone tries to access a ttm page. */ -if (bo->bdev->funcs->swap_notify) bo->bdev->funcs->swap_notify (bo); ret =ttm_tt_swapout (bo->bdev, bo->ttm, gfp_flags); out: -/** -* +/* * Unreserve without putting on LRU to avoid swapping out an * already swapped buffer. */
@@ -1284,7 +1260,6 @@ int ttm_bo_swapout(struct ttm_operation_ctx *ctx, gfp_t gfp_flags)ttm_bo_put (bo);return ret; } -EXPORT_SYMBOL (ttm_bo_swapout);void ttm_bo_tt_destroy (struct ttm_buffer_object *bo) {
drivers/gpu/drm/ttm/ttm_device.c +29 -0
@@ -102,6 +102,35 @@ static int ttm_global_init(void)return ret; } +/** +* A buffer object shrink method that tries to swap out the first +* buffer object on the global::swap_lru list. +*/ +long ttm_global_swapout (struct ttm_operation_ctx *ctx,gfp_t gfp_flags) +{ +struct ttm_global *glob = &ttm_glob; +struct ttm_buffer_object *bo; +unsigned i; +int ret; + +spin_lock (&glob->lru_lock); +for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +list_for_each_entry (bo, &glob->swap_lru[i], swap) { +uint32_t num_pages = bo->ttm->num_pages; + + ret =ttm_bo_swapout (bo, ctx, gfp_flags); +/* ttm_bo_swapout has dropped the lru_lock */ +if (!ret) +return num_pages; +if (ret != -EBUSY ) +return ret; + } + } +spin_unlock (&glob->lru_lock); +return 0 ; +} +EXPORT_SYMBOL (ttm_global_swapout); +static void ttm_init_sysman (struct ttm_device *bdev) {struct ttm_resource_manager *man = &bdev->sysman;
drivers/gpu/drm/ttm/ttm_tt.c +1 -1
@@ -369,7 +369,7 @@ static unsigned long ttm_tt_shrinker_scan(struct shrinker *shrink, };int ret; - ret =ttm_bo_swapout (&ctx,GFP_NOFS ); + ret =ttm_global_swapout (&ctx,GFP_NOFS );return ret <0 ?SHRINK_EMPTY : ret; }
drivers/gpu/drm/vmwgfx/ttm_memory.c +2 -1
@@ -38,6 +38,7 @@#include <drm/drm_device.h> #include <drm/drm_file.h> +#include <drm/ttm/ttm_device.h> #include "ttm_memory.h"
@@ -277,7 +278,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 (ctx,GFP_KERNEL ); + ret =ttm_global_swapout (ctx,GFP_KERNEL );spin_lock (&glob->lock);if (unlikely (ret <0 ))break ;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -1
@@ -1384,7 +1384,7 @@ static int vmw_pm_freeze(struct device *kdev)vmw_execbuf_release_pinned_bo (dev_priv);vmw_resource_evict_all (dev_priv);vmw_release_device_early (dev_priv); -while (ttm_bo_swapout (&ctx,GFP_KERNEL ) >0 ); +while (ttm_global_swapout (&ctx,GFP_KERNEL ) >0 );if (dev_priv->enable_fb)vmw_fifo_resource_dec (dev_priv);if (atomic_read (&dev_priv->num_fifo_resources) !=0 ) {
include/drm/ttm/ttm_bo_api.h +2 -1
@@ -560,7 +560,8 @@ ssize_t ttm_bo_io(struct ttm_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_operation_ctx *ctx,gfp_t gfp_flags); +int ttm_bo_swapout (struct ttm_buffer_object *bo,struct ttm_operation_ctx *ctx, +gfp_t gfp_flags);/** * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
include/drm/ttm/ttm_device.h +2 -0
@@ -297,6 +297,8 @@ struct ttm_device {struct delayed_work wq; }; +long ttm_global_swapout (struct ttm_operation_ctx *ctx,gfp_t gfp_flags); +static inline struct ttm_resource_manager *ttm_manager_type (struct ttm_device *bdev,int mem_type) {
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 drm/ttm: remove swap LRU
Instead evict round robin from each devices SYSTEM and TT domain.
--- drivers/gpu/drm/ttm/ttm_bo.c | 31 ++------------- drivers/gpu/drm/ttm/ttm_bo_util.c | 1 - drivers/gpu/drm/ttm/ttm_device.c | 59 +++++++++++++++++++++-------- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 2 +- include/drm/ttm/ttm_bo_api.h | 1 - include/drm/ttm/ttm_bo_driver.h | 1 - include/drm/ttm/ttm_device.h | 7 +--- 7 files changed, 51 insertions(+), 51 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +4 -27
@@ -73,7 +73,6 @@ static void ttm_bo_del_from_lru(struct ttm_buffer_object *bo) {struct ttm_device *bdev = bo->bdev; -list_del_init (&bo->swap);list_del_init (&bo->lru);if (bdev->funcs->del_from_lru_notify)
@@ -104,14 +103,6 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, man =ttm_manager_type (bdev, mem->mem_type);list_move_tail (&bo->lru, &man->lru[bo->priority]); -if (man->use_tt && bo->ttm && - !(bo->ttm->page_flags & (TTM_PAGE_FLAG_SG | -TTM_PAGE_FLAG_SWAPPED ))) { -struct list_head *swap; - - swap = &ttm_glob.swap_lru[bo->priority]; -list_move_tail (&bo->swap, swap); - }if (bdev->funcs->del_from_lru_notify) bdev->funcs->del_from_lru_notify (bo);
@@ -126,9 +117,6 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,ttm_bo_bulk_move_set_pos (&bulk->vram[bo->priority], bo);break ; } -if (bo->ttm && !(bo->ttm->page_flags & - (TTM_PAGE_FLAG_SG |TTM_PAGE_FLAG_SWAPPED ))) -ttm_bo_bulk_move_set_pos (&bulk->swap[bo->priority], bo); } }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail);
@@ -166,20 +154,6 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)list_bulk_move_tail (&man->lru[i], &pos->first->lru, &pos->last->lru); } - -for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { -struct ttm_lru_bulk_move_pos *pos = &bulk->swap[i]; -struct list_head *lru; - -if (!pos->first) -continue ; - -dma_resv_assert_held (pos->first->base.resv); -dma_resv_assert_held (pos->last->base.resv); - - lru = &ttm_glob.swap_lru[i]; -list_bulk_move_tail (lru, &pos->first->swap, &pos->last->swap); - } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail);
@@ -1056,7 +1030,6 @@ int ttm_bo_init_reserved(struct ttm_device *bdev,kref_init (&bo->kref);INIT_LIST_HEAD (&bo->lru);INIT_LIST_HEAD (&bo->ddestroy); -INIT_LIST_HEAD (&bo->swap); bo->bdev = bdev; bo->type = type; bo->mem.mem_type =TTM_PL_SYSTEM ;
@@ -1191,6 +1164,10 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,bool locked;int ret; +if (!bo->ttm || bo->ttm->page_flags & (TTM_PAGE_FLAG_SG | +TTM_PAGE_FLAG_SWAPPED )) +return false; +if (!ttm_bo_evict_swapout_allowable (bo, ctx, &locked,NULL ))return -EBUSY ;
drivers/gpu/drm/ttm/ttm_bo_util.c +0 -1
@@ -303,7 +303,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,atomic_inc (&ttm_glob.bo_count);INIT_LIST_HEAD (&fbo->base.ddestroy);INIT_LIST_HEAD (&fbo->base.lru); -INIT_LIST_HEAD (&fbo->base.swap); fbo->base.moving =NULL ;drm_vma_node_reset (&fbo->base.base.vma_node);
drivers/gpu/drm/ttm/ttm_device.c +44 -15
86 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -1
@@ -1384,7 +1384,7 @@ static int vmw_pm_freeze(struct device *kdev)vmw_execbuf_release_pinned_bo (dev_priv);vmw_resource_evict_all (dev_priv);vmw_release_device_early (dev_priv); -while (ttm_global_swapout (&ctx,GFP_KERNEL ) >0 ); +while (ttm_device_swapout (&dev_priv->bdev, &ctx,GFP_KERNEL ) ==0 );if (dev_priv->enable_fb)vmw_fifo_resource_dec (dev_priv);if (atomic_read (&dev_priv->num_fifo_resources) !=0 ) {
include/drm/ttm/ttm_bo_api.h +0 -1
@@ -144,7 +144,6 @@ struct ttm_buffer_object {struct list_head lru;struct list_head ddestroy; -struct list_head swap;/** * Members protected by a bo reservation.
include/drm/ttm/ttm_bo_driver.h +0 -1
@@ -69,7 +69,6 @@ struct ttm_lru_bulk_move_pos {struct ttm_lru_bulk_move {struct ttm_lru_bulk_move_pos tt[TTM_MAX_BO_PRIORITY ];struct ttm_lru_bulk_move_pos vram[TTM_MAX_BO_PRIORITY ]; -struct ttm_lru_bulk_move_pos swap[TTM_MAX_BO_PRIORITY ]; };/*
include/drm/ttm/ttm_device.h +2 -5
@@ -63,11 +63,6 @@ extern struct ttm_global {*/ struct list_head device_list; -/** -* Protected by the lru_lock. -*/ -struct list_head swap_lru[TTM_MAX_BO_PRIORITY ]; -/** * Internal protection. */
@@ -298,6 +293,8 @@ struct ttm_device { };long ttm_global_swapout (struct ttm_operation_ctx *ctx,gfp_t gfp_flags); +long ttm_device_swapout (struct ttm_device *bdev,struct ttm_operation_ctx *ctx, +gfp_t gfp_flags);static inline struct ttm_resource_manager *ttm_manager_type (struct ttm_device *bdev,int mem_type)
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/3] drm/ttm: remove swap LRU
Hi "Christian,
url: https://github.com/0day-ci/linux/commits/Christian-K-nig/drm-ttm-move-swapout-logic-around/20210210-232812 base: git://anongit.freedesktop.org/drm/drm-tip drm-tip config: ia64-randconfig-m031-20210209 (attached as .config) compiler: ia64-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
New smatch warnings:drivers/gpu/drm/ttm/ttm_device.c:144 ttm_device_swapout() warn: variable dereferenced before check 'bo->ttm' (see line 142)
vim +144 drivers/gpu/drm/ttm/ttm_device.c
d37e3072dc32c7 Christian König 2021-02-10 125 long ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
d37e3072dc32c7 Christian König 2021-02-10 126 gfp_t gfp_flags)
d37e3072dc32c7 Christian König 2021-02-10 127 {
d37e3072dc32c7 Christian König 2021-02-10 128 struct ttm_global *glob = &ttm_glob;
d37e3072dc32c7 Christian König 2021-02-10 129 struct ttm_resource_manager *man;
22b09b650f7486 Christian König 2021-02-10 130 struct ttm_buffer_object *bo;
d37e3072dc32c7 Christian König 2021-02-10 131 unsigned i, j;
22b09b650f7486 Christian König 2021-02-10 132 int ret;
22b09b650f7486 Christian König 2021-02-10 133
22b09b650f7486 Christian König 2021-02-10 134 spin_lock(&glob->lru_lock);
d37e3072dc32c7 Christian König 2021-02-10 135 for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) {
d37e3072dc32c7 Christian König 2021-02-10 136 man = ttm_manager_type(bdev, i);
d37e3072dc32c7 Christian König 2021-02-10 137 if (!man || !man->use_tt)
d37e3072dc32c7 Christian König 2021-02-10 138 continue;
d37e3072dc32c7 Christian König 2021-02-10 139
d37e3072dc32c7 Christian König 2021-02-10 140 for (j = 0; j < TTM_MAX_BO_PRIORITY; ++j) {
d37e3072dc32c7 Christian König 2021-02-10 141 list_for_each_entry(bo, &man->lru[j], lru) {
d37e3072dc32c7 Christian König 2021-02-10 @142 long num_pages = bo->ttm->num_pages;
^^^^^^^^^Dereferenced
d37e3072dc32c7 Christian König 2021-02-10 143d37e3072dc32c7 Christian König 2021-02-10 @144 if (!bo->ttm ||
^^^^^^^^
Checked too late
d37e3072dc32c7 Christian König 2021-02-10 145 bo->ttm->page_flags & TTM_PAGE_FLAG_SG || d37e3072dc32c7 Christian König 2021-02-10 146 bo->ttm->page_flags & TTM_PAGE_FLAG_SWAPPED) d37e3072dc32c7 Christian König 2021-02-10 147 continue; 22b09b650f7486 Christian König 2021-02-10 148 22b09b650f7486 Christian König 2021-02-10 149 ret = ttm_bo_swapout(bo, ctx, gfp_flags); 22b09b650f7486 Christian König 2021-02-10 150 /* ttm_bo_swapout has dropped the lru_lock */ 22b09b650f7486 Christian König 2021-02-10 151 if (!ret) 22b09b650f7486 Christian König 2021-02-10 152 return num_pages; 22b09b650f7486 Christian König 2021-02-10 153 if (ret != -EBUSY) 22b09b650f7486 Christian König 2021-02-10 154 return ret; 22b09b650f7486 Christian König 2021-02-10 155 } 22b09b650f7486 Christian König 2021-02-10 156 } d37e3072dc32c7 Christian König 2021-02-10 157 } 22b09b650f7486 Christian König 2021-02-10 158 spin_unlock(&glob->lru_lock); 22b09b650f7486 Christian König 2021-02-10 159 return 0; 22b09b650f7486 Christian König 2021-02-10 160 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH 2/3] drm/ttm: remove swap LRU
In reply to Christian KönigI love your patch! Perhaps something to improve:
Hi "Christian,
I love your patch! Perhaps something to improve:
[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next tegra-drm/drm/tegra/for-next linus/master drm-exynos/exynos-drm-next drm/drm-next v5.11-rc7 next-20210125] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Christian-K-nig/drm-ttm-move-swapout-logic-around/20210210-232812 base: git://anongit.freedesktop.org/drm/drm-tip drm-tip config: x86_64-randconfig-s021-20210209 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-215-g0fb77bb6-dirty # https://github.com/0day-ci/linux/commit/d37e3072dc32c7f8466e8b9983bb3667e733fd61 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Christian-K-nig/drm-ttm-move-swapout-logic-around/20210210-232812 git checkout d37e3072dc32c7f8466e8b9983bb3667e733fd61 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
"sparse warnings: (new ones prefixed by >>)"
drivers/gpu/drm/ttm/ttm_device.c:42:1: sparse: sparse: symbol 'ttm_global_mutex' was not declared. Should it be static? drivers/gpu/drm/ttm/ttm_device.c:43:10: sparse: sparse: symbol 'ttm_glob_use_count' was not declared. Should it be static?
>> drivers/gpu/drm/ttm/ttm_device.c:125:6: sparse: sparse: context imbalance in 'ttm_device_swapout' - wrong count at exit
vim +/ttm_device_swapout +125 drivers/gpu/drm/ttm/ttm_device.c
d37e3072dc32c7 Christian König 2021-02-10 124
d37e3072dc32c7 Christian König 2021-02-10 @125 long ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
d37e3072dc32c7 Christian König 2021-02-10 126 gfp_t gfp_flags)
d37e3072dc32c7 Christian König 2021-02-10 127 {
d37e3072dc32c7 Christian König 2021-02-10 128 struct ttm_global *glob = &ttm_glob;
d37e3072dc32c7 Christian König 2021-02-10 129 struct ttm_resource_manager *man;
22b09b650f7486 Christian König 2021-02-10 130 struct ttm_buffer_object *bo;
d37e3072dc32c7 Christian König 2021-02-10 131 unsigned i, j;
22b09b650f7486 Christian König 2021-02-10 132 int ret;
22b09b650f7486 Christian König 2021-02-10 133
22b09b650f7486 Christian König 2021-02-10 134 spin_lock(&glob->lru_lock);
d37e3072dc32c7 Christian König 2021-02-10 135 for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) {
d37e3072dc32c7 Christian König 2021-02-10 136 man = ttm_manager_type(bdev, i);
d37e3072dc32c7 Christian König 2021-02-10 137 if (!man || !man->use_tt)
d37e3072dc32c7 Christian König 2021-02-10 138 continue;
d37e3072dc32c7 Christian König 2021-02-10 139
d37e3072dc32c7 Christian König 2021-02-10 140 for (j = 0; j < TTM_MAX_BO_PRIORITY; ++j) {
d37e3072dc32c7 Christian König 2021-02-10 141 list_for_each_entry(bo, &man->lru[j], lru) {
d37e3072dc32c7 Christian König 2021-02-10 142 long num_pages = bo->ttm->num_pages;
d37e3072dc32c7 Christian König 2021-02-10 143
d37e3072dc32c7 Christian König 2021-02-10 144 if (!bo->ttm ||
d37e3072dc32c7 Christian König 2021-02-10 145 bo->ttm->page_flags & TTM_PAGE_FLAG_SG ||
d37e3072dc32c7 Christian König 2021-02-10 146 bo->ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)
d37e3072dc32c7 Christian König 2021-02-10 147 continue;
22b09b650f7486 Christian König 2021-02-10 148
22b09b650f7486 Christian König 2021-02-10 149 ret = ttm_bo_swapout(bo, ctx, gfp_flags);
22b09b650f7486 Christian König 2021-02-10 150 /* ttm_bo_swapout has dropped the lru_lock */
22b09b650f7486 Christian König 2021-02-10 151 if (!ret)
22b09b650f7486 Christian König 2021-02-10 152 return num_pages;
22b09b650f7486 Christian König 2021-02-10 153 if (ret != -EBUSY)
22b09b650f7486 Christian König 2021-02-10 154 return ret;
22b09b650f7486 Christian König 2021-02-10 155 }
22b09b650f7486 Christian König 2021-02-10 156 }
d37e3072dc32c7 Christian König 2021-02-10 157 }
22b09b650f7486 Christian König 2021-02-10 158 spin_unlock(&glob->lru_lock);
22b09b650f7486 Christian König 2021-02-10 159 return 0;
22b09b650f7486 Christian König 2021-02-10 160 }
d37e3072dc32c7 Christian König 2021-02-10 161 EXPORT_SYMBOL(ttm_device_swapout);
22b09b650f7486 Christian König 2021-02-10 162 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 3/3 drm/ttm: switch to per device LRU lock
In reply to Christian KönigInstead of having a global lock.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++--- drivers/gpu/drm/qxl/qxl_release.c | 5 +-- drivers/gpu/drm/ttm/ttm_bo.c | 49 ++++++++++++-------------- drivers/gpu/drm/ttm/ttm_device.c | 12 +++---- drivers/gpu/drm/ttm/ttm_execbuf_util.c | 8 ++--- drivers/gpu/drm/ttm/ttm_resource.c | 9 +++-- include/drm/ttm/ttm_bo_driver.h | 4 +-- include/drm/ttm/ttm_device.h | 4 +-- 8 files changed, 43 insertions(+), 56 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -4
@@ -638,15 +638,15 @@ void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,struct amdgpu_vm_bo_base *bo_base;if (vm->bulk_moveable) { -spin_lock (&ttm_glob.lru_lock); +spin_lock (&adev->mman.bdev.lru_lock);ttm_bo_bulk_move_lru_tail (&vm->lru_bulk_move); -spin_unlock (&ttm_glob.lru_lock); +spin_unlock (&adev->mman.bdev.lru_lock);return ; }memset (&vm->lru_bulk_move,0 ,sizeof (vm->lru_bulk_move)); -spin_lock (&ttm_glob.lru_lock); +spin_lock (&adev->mman.bdev.lru_lock);list_for_each_entry (bo_base, &vm->idle, vm_status) {struct amdgpu_bo *bo = bo_base->bo;
@@ -660,7 +660,7 @@ void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev, &bo->shadow->tbo.mem, &vm->lru_bulk_move); } -spin_unlock (&ttm_glob.lru_lock); +spin_unlock (&adev->mman.bdev.lru_lock); vm->bulk_moveable = true; }
drivers/gpu/drm/qxl/qxl_release.c +1 -4
@@ -417,16 +417,13 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release) release->id | 0xf0000000, release->base.seqno);trace_dma_fence_emit (&release->base); -spin_lock (&ttm_glob.lru_lock); -list_for_each_entry (entry, &release->bos, head) { bo = entry->bo;dma_resv_add_shared_fence (bo->base.resv, &release->base); -ttm_bo_move_to_lru_tail (bo, &bo->mem,NULL ); +ttm_bo_move_to_lru_tail_unlocked (bo);dma_resv_unlock (bo->base.resv); } -spin_unlock (&ttm_glob.lru_lock);ww_acquire_fini (&release->ticket); }
drivers/gpu/drm/ttm/ttm_bo.c +23 -26
172 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_device.c +5 -7
@@ -81,7 +81,6 @@ static int ttm_global_init(void)ttm_pool_mgr_init (num_pages *50 /100 );ttm_tt_mgr_init (); -spin_lock_init (&glob->lru_lock); glob->dummy_read_page =alloc_page (__GFP_ZERO |GFP_DMA32 );if (unlikely (glob->dummy_read_page ==NULL )) {
@@ -125,13 +124,12 @@ EXPORT_SYMBOL(ttm_global_swapout);long ttm_device_swapout (struct ttm_device *bdev,struct ttm_operation_ctx *ctx,gfp_t gfp_flags) { -struct ttm_global *glob = &ttm_glob;struct ttm_resource_manager *man;struct ttm_buffer_object *bo;unsigned i, j;int ret; -spin_lock (&glob->lru_lock); +spin_lock (&bdev->lru_lock);for (i =TTM_PL_SYSTEM ; i <TTM_NUM_MEM_TYPES ; ++i) { man =ttm_manager_type (bdev, i);if (!man || !man->use_tt)
@@ -155,7 +153,7 @@ long ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx, } } } -spin_unlock (&glob->lru_lock); +spin_unlock (&bdev->lru_lock);return 0 ; }EXPORT_SYMBOL (ttm_device_swapout);
@@ -222,6 +220,7 @@ int ttm_device_init(struct ttm_device *bdev, struct ttm_device_funcs *funcs, bdev->vma_manager = vma_manager;INIT_DELAYED_WORK (&bdev->wq, ttm_device_delayed_workqueue); +spin_lock_init (&bdev->lru_lock);INIT_LIST_HEAD (&bdev->ddestroy); bdev->dev_mapping = mapping;mutex_lock (&ttm_global_mutex);
@@ -234,7 +233,6 @@ EXPORT_SYMBOL(ttm_device_init);void ttm_device_fini (struct ttm_device *bdev) { -struct ttm_global *glob = &ttm_glob;struct ttm_resource_manager *man;unsigned i;
@@ -251,11 +249,11 @@ void ttm_device_fini(struct ttm_device *bdev)if (ttm_bo_delayed_delete (bdev, true))pr_debug ("Delayed destroy list was clean\n" ); -spin_lock (&glob->lru_lock); +spin_lock (&bdev->lru_lock);for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i)if (list_empty (&man->lru[0 ]))pr_debug ("Swap list %d was clean\n" , i); -spin_unlock (&glob->lru_lock); +spin_unlock (&bdev->lru_lock);ttm_pool_fini (&bdev->pool);ttm_global_release ();
drivers/gpu/drm/ttm/ttm_execbuf_util.c +2 -6
@@ -51,14 +51,12 @@ void ttm_eu_backoff_reservation(struct ww_acquire_ctx *ticket,if (list_empty (list))return ; -spin_lock (&ttm_glob.lru_lock);list_for_each_entry (entry, list, head) {struct ttm_buffer_object *bo = entry->bo; -ttm_bo_move_to_lru_tail (bo, &bo->mem,NULL ); +ttm_bo_move_to_lru_tail_unlocked (bo);dma_resv_unlock (bo->base.resv); } -spin_unlock (&ttm_glob.lru_lock);if (ticket)ww_acquire_fini (ticket);
@@ -154,7 +152,6 @@ void ttm_eu_fence_buffer_objects(struct ww_acquire_ctx *ticket,if (list_empty (list))return ; -spin_lock (&ttm_glob.lru_lock);list_for_each_entry (entry, list, head) {struct ttm_buffer_object *bo = entry->bo;
@@ -162,10 +159,9 @@ void ttm_eu_fence_buffer_objects(struct ww_acquire_ctx *ticket,dma_resv_add_shared_fence (bo->base.resv, fence); else dma_resv_add_excl_fence(bo->base.resv, fence); -ttm_bo_move_to_lru_tail (bo, &bo->mem,NULL ); +ttm_bo_move_to_lru_tail_unlocked (bo);dma_resv_unlock (bo->base.resv); } -spin_unlock (&ttm_glob.lru_lock);if (ticket)ww_acquire_fini (ticket); }
drivers/gpu/drm/ttm/ttm_resource.c +4 -5
@@ -91,7 +91,6 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev, .no_wait_gpu = false, .force_alloc = true }; -struct ttm_global *glob = &ttm_glob;struct dma_fence *fence;int ret;unsigned i;
@@ -100,18 +99,18 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,* Can't use standard list traversal since we're unlocking. */ -spin_lock (&glob->lru_lock); +spin_lock (&bdev->lru_lock);for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {while (!list_empty (&man->lru[i])) { -spin_unlock (&glob->lru_lock); +spin_unlock (&bdev->lru_lock); ret =ttm_mem_evict_first (bdev, man,NULL , &ctx,NULL );if (ret)return ret; -spin_lock (&glob->lru_lock); +spin_lock (&bdev->lru_lock); } } -spin_unlock (&glob->lru_lock); +spin_unlock (&bdev->lru_lock);spin_lock (&man->move_lock); fence =dma_fence_get (man->move);
include/drm/ttm/ttm_bo_driver.h +2 -2
@@ -180,9 +180,9 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,static inline void ttm_bo_move_to_lru_tail_unlocked (struct ttm_buffer_object *bo) { -spin_lock (&ttm_glob.lru_lock); +spin_lock (&bo->bdev->lru_lock);ttm_bo_move_to_lru_tail (bo, &bo->mem,NULL ); -spin_unlock (&ttm_glob.lru_lock); +spin_unlock (&bo->bdev->lru_lock); } static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo,
include/drm/ttm/ttm_device.h +2 -2
@@ -56,7 +56,6 @@ extern struct ttm_global {*/ struct page *dummy_read_page; -spinlock_t lru_lock;/** * Protected by ttm_global_mutex.
@@ -277,8 +276,9 @@ struct ttm_device {struct ttm_pool pool;/* -* Protected by the global:lru lock. +* Protection for the per manager LRU and ddestroy lists. */ +spinlock_t lru_lock;struct list_head ddestroy;/*
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel