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

drm/ttm: Hide the implementation details of reservation

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>

+47 -36
+1 -1
drivers/gpu/drm/qxl/qxl_release.c
··· 349 349 qxl_fence_add_release_locked(&qbo->fence, release->id); 350 350 351 351 ttm_bo_add_to_lru(bo); 352 - ww_mutex_unlock(&bo->resv->lock); 352 + __ttm_bo_unreserve(bo); 353 353 entry->reserved = false; 354 354 } 355 355 spin_unlock(&bdev->fence_lock);
+13 -13
drivers/gpu/drm/ttm/ttm_bo.c
··· 412 412 int ret; 413 413 414 414 spin_lock(&glob->lru_lock); 415 - ret = ttm_bo_reserve_nolru(bo, false, true, false, 0); 415 + ret = __ttm_bo_reserve(bo, false, true, false, 0); 416 416 417 417 spin_lock(&bdev->fence_lock); 418 418 (void) ttm_bo_wait(bo, false, false, true); ··· 443 443 ttm_bo_add_to_lru(bo); 444 444 } 445 445 446 - ww_mutex_unlock(&bo->resv->lock); 446 + __ttm_bo_unreserve(bo); 447 447 } 448 448 449 449 kref_get(&bo->list_kref); ··· 494 494 sync_obj = driver->sync_obj_ref(bo->sync_obj); 495 495 spin_unlock(&bdev->fence_lock); 496 496 497 - ww_mutex_unlock(&bo->resv->lock); 497 + __ttm_bo_unreserve(bo); 498 498 spin_unlock(&glob->lru_lock); 499 499 500 500 ret = driver->sync_obj_wait(sync_obj, false, interruptible); ··· 514 514 return ret; 515 515 516 516 spin_lock(&glob->lru_lock); 517 - ret = ttm_bo_reserve_nolru(bo, false, true, false, 0); 517 + ret = __ttm_bo_reserve(bo, false, true, false, 0); 518 518 519 519 /* 520 520 * We raced, and lost, someone else holds the reservation now, ··· 532 532 spin_unlock(&bdev->fence_lock); 533 533 534 534 if (ret || unlikely(list_empty(&bo->ddestroy))) { 535 - ww_mutex_unlock(&bo->resv->lock); 535 + __ttm_bo_unreserve(bo); 536 536 spin_unlock(&glob->lru_lock); 537 537 return ret; 538 538 } ··· 577 577 kref_get(&nentry->list_kref); 578 578 } 579 579 580 - ret = ttm_bo_reserve_nolru(entry, false, true, false, 0); 580 + ret = __ttm_bo_reserve(entry, false, true, false, 0); 581 581 if (remove_all && ret) { 582 582 spin_unlock(&glob->lru_lock); 583 - ret = ttm_bo_reserve_nolru(entry, false, false, 584 - false, 0); 583 + ret = __ttm_bo_reserve(entry, false, false, 584 + false, 0); 585 585 spin_lock(&glob->lru_lock); 586 586 } 587 587 ··· 726 726 727 727 spin_lock(&glob->lru_lock); 728 728 list_for_each_entry(bo, &man->lru, lru) { 729 - ret = ttm_bo_reserve_nolru(bo, false, true, false, 0); 729 + ret = __ttm_bo_reserve(bo, false, true, false, 0); 730 730 if (!ret) 731 731 break; 732 732 } ··· 1630 1630 1631 1631 spin_lock(&glob->lru_lock); 1632 1632 list_for_each_entry(bo, &glob->swap_lru, swap) { 1633 - ret = ttm_bo_reserve_nolru(bo, false, true, false, 0); 1633 + ret = __ttm_bo_reserve(bo, false, true, false, 0); 1634 1634 if (!ret) 1635 1635 break; 1636 1636 } ··· 1697 1697 * already swapped buffer. 1698 1698 */ 1699 1699 1700 - ww_mutex_unlock(&bo->resv->lock); 1700 + __ttm_bo_unreserve(bo); 1701 1701 kref_put(&bo->list_kref, ttm_bo_release_list); 1702 1702 return ret; 1703 1703 } ··· 1731 1731 return -ERESTARTSYS; 1732 1732 if (!ww_mutex_is_locked(&bo->resv->lock)) 1733 1733 goto out_unlock; 1734 - ret = ttm_bo_reserve_nolru(bo, true, false, false, NULL); 1734 + ret = __ttm_bo_reserve(bo, true, false, false, NULL); 1735 1735 if (unlikely(ret != 0)) 1736 1736 goto out_unlock; 1737 - ww_mutex_unlock(&bo->resv->lock); 1737 + __ttm_bo_unreserve(bo); 1738 1738 1739 1739 out_unlock: 1740 1740 mutex_unlock(&bo->wu_mutex);
+4 -4
drivers/gpu/drm/ttm/ttm_execbuf_util.c
··· 46 46 ttm_bo_add_to_lru(bo); 47 47 entry->removed = false; 48 48 } 49 - ww_mutex_unlock(&bo->resv->lock); 49 + __ttm_bo_unreserve(bo); 50 50 } 51 51 } 52 52 ··· 140 140 if (entry->reserved) 141 141 continue; 142 142 143 - ret = ttm_bo_reserve_nolru(bo, true, (ticket == NULL), true, 144 - ticket); 143 + ret = __ttm_bo_reserve(bo, true, (ticket == NULL), true, 144 + ticket); 145 145 146 146 if (ret == -EDEADLK) { 147 147 /* uh oh, we lost out, drop every reservation and try ··· 224 224 entry->old_sync_obj = bo->sync_obj; 225 225 bo->sync_obj = driver->sync_obj_ref(sync_obj); 226 226 ttm_bo_add_to_lru(bo); 227 - ww_mutex_unlock(&bo->resv->lock); 227 + __ttm_bo_unreserve(bo); 228 228 entry->reserved = false; 229 229 } 230 230 spin_unlock(&bdev->fence_lock);
+29 -18
include/drm/ttm/ttm_bo_driver.h
··· 788 788 extern void ttm_bo_add_to_lru(struct ttm_buffer_object *bo); 789 789 790 790 /** 791 - * ttm_bo_reserve_nolru: 791 + * __ttm_bo_reserve: 792 792 * 793 793 * @bo: A pointer to a struct ttm_buffer_object. 794 794 * @interruptible: Sleep interruptible if waiting. ··· 809 809 * -EALREADY: Bo already reserved using @ticket. This error code will only 810 810 * be returned if @use_ticket is set to true. 811 811 */ 812 - static inline int ttm_bo_reserve_nolru(struct ttm_buffer_object *bo, 813 - bool interruptible, 814 - bool no_wait, bool use_ticket, 815 - struct ww_acquire_ctx *ticket) 812 + static inline int __ttm_bo_reserve(struct ttm_buffer_object *bo, 813 + bool interruptible, 814 + bool no_wait, bool use_ticket, 815 + struct ww_acquire_ctx *ticket) 816 816 { 817 817 int ret = 0; 818 818 ··· 888 888 889 889 WARN_ON(!atomic_read(&bo->kref.refcount)); 890 890 891 - ret = ttm_bo_reserve_nolru(bo, interruptible, no_wait, use_ticket, 892 - ticket); 891 + ret = __ttm_bo_reserve(bo, interruptible, no_wait, use_ticket, ticket); 893 892 if (likely(ret == 0)) 894 893 ttm_bo_del_sub_from_lru(bo); 895 894 ··· 928 929 } 929 930 930 931 /** 931 - * ttm_bo_unreserve_ticket 932 + * __ttm_bo_unreserve 932 933 * @bo: A pointer to a struct ttm_buffer_object. 933 - * @ticket: ww_acquire_ctx used for reserving 934 934 * 935 - * Unreserve a previous reservation of @bo made with @ticket. 935 + * Unreserve a previous reservation of @bo where the buffer object is 936 + * already on lru lists. 936 937 */ 937 - static inline void ttm_bo_unreserve_ticket(struct ttm_buffer_object *bo, 938 - struct ww_acquire_ctx *t) 938 + static inline void __ttm_bo_unreserve(struct ttm_buffer_object *bo) 939 939 { 940 - if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) { 941 - spin_lock(&bo->glob->lru_lock); 942 - ttm_bo_add_to_lru(bo); 943 - spin_unlock(&bo->glob->lru_lock); 944 - } 945 940 ww_mutex_unlock(&bo->resv->lock); 946 941 } 947 942 ··· 948 955 */ 949 956 static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo) 950 957 { 951 - ttm_bo_unreserve_ticket(bo, NULL); 958 + if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) { 959 + spin_lock(&bo->glob->lru_lock); 960 + ttm_bo_add_to_lru(bo); 961 + spin_unlock(&bo->glob->lru_lock); 962 + } 963 + __ttm_bo_unreserve(bo); 964 + } 965 + 966 + /** 967 + * ttm_bo_unreserve_ticket 968 + * @bo: A pointer to a struct ttm_buffer_object. 969 + * @ticket: ww_acquire_ctx used for reserving 970 + * 971 + * Unreserve a previous reservation of @bo made with @ticket. 972 + */ 973 + static inline void ttm_bo_unreserve_ticket(struct ttm_buffer_object *bo, 974 + struct ww_acquire_ctx *t) 975 + { 976 + ttm_bo_unreserve(bo); 952 977 } 953 978 954 979 /*