Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/ttm: Use a struct for the common part of struct ttm_lru_walk and struct ttm_bo_lru_cursor

Let the locking functions take the new struct ttm_lru_walk_arg
as argument in order for them to be easily used from both
types of walk.

v2:
- Whitespace fix

Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://lore.kernel.org/r/20250623155313.4901-2-thomas.hellstrom@linux.intel.com

+42 -31
+14 -10
drivers/gpu/drm/ttm/ttm_bo.c
··· 526 526 return 0; 527 527 528 528 if (bo->deleted) { 529 - lret = ttm_bo_wait_ctx(bo, walk->ctx); 529 + lret = ttm_bo_wait_ctx(bo, walk->arg.ctx); 530 530 if (!lret) 531 531 ttm_bo_cleanup_memtype_use(bo); 532 532 } else { 533 - lret = ttm_bo_evict(bo, walk->ctx); 533 + lret = ttm_bo_evict(bo, walk->arg.ctx); 534 534 } 535 535 536 536 if (lret) ··· 566 566 struct ttm_bo_evict_walk evict_walk = { 567 567 .walk = { 568 568 .ops = &ttm_evict_walk_ops, 569 - .ctx = ctx, 570 - .ticket = ticket, 569 + .arg = { 570 + .ctx = ctx, 571 + .ticket = ticket, 572 + } 571 573 }, 572 574 .place = place, 573 575 .evictor = evictor, ··· 578 576 }; 579 577 s64 lret; 580 578 581 - evict_walk.walk.trylock_only = true; 579 + evict_walk.walk.arg.trylock_only = true; 582 580 lret = ttm_lru_walk_for_evict(&evict_walk.walk, bdev, man, 1); 583 581 584 582 /* One more attempt if we hit low limit? */ ··· 592 590 /* Reset low limit */ 593 591 evict_walk.try_low = evict_walk.hit_low = false; 594 592 /* If ticket-locking, repeat while making progress. */ 595 - evict_walk.walk.trylock_only = false; 593 + evict_walk.walk.arg.trylock_only = false; 596 594 597 595 retry: 598 596 do { 599 597 /* The walk may clear the evict_walk.walk.ticket field */ 600 - evict_walk.walk.ticket = ticket; 598 + evict_walk.walk.arg.ticket = ticket; 601 599 evict_walk.evicted = 0; 602 600 lret = ttm_lru_walk_for_evict(&evict_walk.walk, bdev, man, 1); 603 601 } while (!lret && evict_walk.evicted); ··· 1108 1106 struct ttm_place place = {.mem_type = bo->resource->mem_type}; 1109 1107 struct ttm_bo_swapout_walk *swapout_walk = 1110 1108 container_of(walk, typeof(*swapout_walk), walk); 1111 - struct ttm_operation_ctx *ctx = walk->ctx; 1109 + struct ttm_operation_ctx *ctx = walk->arg.ctx; 1112 1110 s64 ret; 1113 1111 1114 1112 /* ··· 1219 1217 struct ttm_bo_swapout_walk swapout_walk = { 1220 1218 .walk = { 1221 1219 .ops = &ttm_swap_ops, 1222 - .ctx = ctx, 1223 - .trylock_only = true, 1220 + .arg = { 1221 + .ctx = ctx, 1222 + .trylock_only = true, 1223 + }, 1224 1224 }, 1225 1225 .gfp_flags = gfp_flags, 1226 1226 };
+14 -12
drivers/gpu/drm/ttm/ttm_bo_util.c
··· 773 773 return ret; 774 774 } 775 775 776 - static bool ttm_lru_walk_trylock(struct ttm_operation_ctx *ctx, 776 + static bool ttm_lru_walk_trylock(struct ttm_lru_walk_arg *arg, 777 777 struct ttm_buffer_object *bo, 778 778 bool *needs_unlock) 779 779 { 780 + struct ttm_operation_ctx *ctx = arg->ctx; 781 + 780 782 *needs_unlock = false; 781 783 782 784 if (dma_resv_trylock(bo->base.resv)) { ··· 794 792 return false; 795 793 } 796 794 797 - static int ttm_lru_walk_ticketlock(struct ttm_lru_walk *walk, 795 + static int ttm_lru_walk_ticketlock(struct ttm_lru_walk_arg *arg, 798 796 struct ttm_buffer_object *bo, 799 797 bool *needs_unlock) 800 798 { 801 799 struct dma_resv *resv = bo->base.resv; 802 800 int ret; 803 801 804 - if (walk->ctx->interruptible) 805 - ret = dma_resv_lock_interruptible(resv, walk->ticket); 802 + if (arg->ctx->interruptible) 803 + ret = dma_resv_lock_interruptible(resv, arg->ticket); 806 804 else 807 - ret = dma_resv_lock(resv, walk->ticket); 805 + ret = dma_resv_lock(resv, arg->ticket); 808 806 809 807 if (!ret) { 810 808 *needs_unlock = true; ··· 814 812 * after waiting for the ticketlock, revert back to 815 813 * trylocking for this walk. 816 814 */ 817 - walk->ticket = NULL; 815 + arg->ticket = NULL; 818 816 } else if (ret == -EDEADLK) { 819 817 /* Caller needs to exit the ww transaction. */ 820 818 ret = -ENOSPC; ··· 881 879 * since if we do it the other way around, and the trylock fails, 882 880 * we need to drop the lru lock to put the bo. 883 881 */ 884 - if (ttm_lru_walk_trylock(walk->ctx, bo, &bo_needs_unlock)) 882 + if (ttm_lru_walk_trylock(&walk->arg, bo, &bo_needs_unlock)) 885 883 bo_locked = true; 886 - else if (!walk->ticket || walk->ctx->no_wait_gpu || 887 - walk->trylock_only) 884 + else if (!walk->arg.ticket || walk->arg.ctx->no_wait_gpu || 885 + walk->arg.trylock_only) 888 886 continue; 889 887 890 888 if (!ttm_bo_get_unless_zero(bo)) { ··· 897 895 898 896 lret = 0; 899 897 if (!bo_locked) 900 - lret = ttm_lru_walk_ticketlock(walk, bo, &bo_needs_unlock); 898 + lret = ttm_lru_walk_ticketlock(&walk->arg, bo, &bo_needs_unlock); 901 899 902 900 /* 903 901 * Note that in between the release of the lru lock and the ··· 974 972 { 975 973 memset(curs, 0, sizeof(*curs)); 976 974 ttm_resource_cursor_init(&curs->res_curs, man); 977 - curs->ctx = ctx; 975 + curs->arg.ctx = ctx; 978 976 979 977 return curs; 980 978 } ··· 985 983 { 986 984 struct ttm_buffer_object *bo = res->bo; 987 985 988 - if (!ttm_lru_walk_trylock(curs->ctx, bo, &curs->needs_unlock)) 986 + if (!ttm_lru_walk_trylock(&curs->arg, bo, &curs->needs_unlock)) 989 987 return NULL; 990 988 991 989 if (!ttm_bo_get_unless_zero(bo)) {
+14 -9
include/drm/ttm/ttm_bo.h
··· 207 207 }; 208 208 209 209 /** 210 - * struct ttm_lru_walk - Structure describing a LRU walk. 210 + * struct ttm_lru_walk_arg - Common part for the variants of BO LRU walk. 211 211 */ 212 - struct ttm_lru_walk { 213 - /** @ops: Pointer to the ops structure. */ 214 - const struct ttm_lru_walk_ops *ops; 212 + struct ttm_lru_walk_arg { 215 213 /** @ctx: Pointer to the struct ttm_operation_ctx. */ 216 214 struct ttm_operation_ctx *ctx; 217 215 /** @ticket: The struct ww_acquire_ctx if any. */ 218 216 struct ww_acquire_ctx *ticket; 219 217 /** @trylock_only: Only use trylock for locking. */ 220 218 bool trylock_only; 219 + }; 220 + 221 + /** 222 + * struct ttm_lru_walk - Structure describing a LRU walk. 223 + */ 224 + struct ttm_lru_walk { 225 + /** @ops: Pointer to the ops structure. */ 226 + const struct ttm_lru_walk_ops *ops; 227 + /** @arg: Common bo LRU walk arguments. */ 228 + struct ttm_lru_walk_arg arg; 221 229 }; 222 230 223 231 s64 ttm_lru_walk_for_evict(struct ttm_lru_walk *walk, struct ttm_device *bdev, ··· 475 467 /** @res_curs: Embedded struct ttm_resource_cursor. */ 476 468 struct ttm_resource_cursor res_curs; 477 469 /** 478 - * @ctx: The struct ttm_operation_ctx used while looping. 479 - * governs the locking mode. 480 - */ 481 - struct ttm_operation_ctx *ctx; 482 - /** 483 470 * @bo: Buffer object pointer if a buffer object is refcounted, 484 471 * NULL otherwise. 485 472 */ ··· 484 481 * unlock before the next iteration or after loop exit. 485 482 */ 486 483 bool needs_unlock; 484 + /** @arg: Common BO LRU walk arguments. */ 485 + struct ttm_lru_walk_arg arg; 487 486 }; 488 487 489 488 void ttm_bo_lru_cursor_fini(struct ttm_bo_lru_cursor *curs);