Skip to content

Commit dd7cfd6

Browse files
author
Maarten Lankhorst
committed
drm/ttm: kill fence_lock
No users are left, kill it off! :D Conversion to the reservation api is next on the list, after that the functionality can be restored with rcu. Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
1 parent 7040138 commit dd7cfd6

17 files changed

Lines changed: 37 additions & 142 deletions

‎drivers/gpu/drm/nouveau/nouveau_bo.c‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,9 +1212,7 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict, bool intr,
12121212
}
12131213

12141214
/* Fallback to software copy. */
1215-
spin_lock(&bo->bdev->fence_lock);
12161215
ret = ttm_bo_wait(bo, true, intr, no_wait_gpu);
1217-
spin_unlock(&bo->bdev->fence_lock);
12181216
if (ret == 0)
12191217
ret = ttm_bo_move_memcpy(bo, evict, no_wait_gpu, new_mem);
12201218

@@ -1457,26 +1455,19 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
14571455
ttm_pool_unpopulate(ttm);
14581456
}
14591457

1458+
static void
1459+
nouveau_bo_fence_unref(void **sync_obj)
1460+
{
1461+
nouveau_fence_unref((struct nouveau_fence **)sync_obj);
1462+
}
1463+
14601464
void
14611465
nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)
14621466
{
1463-
struct nouveau_fence *new_fence = nouveau_fence_ref(fence);
1464-
struct nouveau_fence *old_fence = NULL;
1465-
14661467
lockdep_assert_held(&nvbo->bo.resv->lock.base);
14671468

1468-
spin_lock(&nvbo->bo.bdev->fence_lock);
1469-
old_fence = nvbo->bo.sync_obj;
1470-
nvbo->bo.sync_obj = new_fence;
1471-
spin_unlock(&nvbo->bo.bdev->fence_lock);
1472-
1473-
nouveau_fence_unref(&old_fence);
1474-
}
1475-
1476-
static void
1477-
nouveau_bo_fence_unref(void **sync_obj)
1478-
{
1479-
nouveau_fence_unref((struct nouveau_fence **)sync_obj);
1469+
nouveau_bo_fence_unref(&nvbo->bo.sync_obj);
1470+
nvbo->bo.sync_obj = nouveau_fence_ref(fence);
14801471
}
14811472

14821473
static void *

‎drivers/gpu/drm/nouveau/nouveau_display.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,7 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
722722
goto fail_unpin;
723723

724724
/* synchronise rendering channel with the kernel's channel */
725-
spin_lock(&new_bo->bo.bdev->fence_lock);
726-
fence = nouveau_fence_ref(new_bo->bo.sync_obj);
727-
spin_unlock(&new_bo->bo.bdev->fence_lock);
728-
ret = nouveau_fence_sync(fence, chan);
729-
nouveau_fence_unref(&fence);
725+
ret = nouveau_fence_sync(new_bo->bo.sync_obj, chan);
730726
if (ret) {
731727
ttm_bo_unreserve(&new_bo->bo);
732728
goto fail_unpin;

‎drivers/gpu/drm/nouveau/nouveau_gem.c‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ nouveau_gem_object_unmap(struct nouveau_bo *nvbo, struct nouveau_vma *vma)
103103
list_del(&vma->head);
104104

105105
if (mapped) {
106-
spin_lock(&nvbo->bo.bdev->fence_lock);
107106
fence = nouveau_fence_ref(nvbo->bo.sync_obj);
108-
spin_unlock(&nvbo->bo.bdev->fence_lock);
109107
}
110108

111109
if (fence) {
@@ -430,17 +428,11 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
430428
static int
431429
validate_sync(struct nouveau_channel *chan, struct nouveau_bo *nvbo)
432430
{
433-
struct nouveau_fence *fence = NULL;
431+
struct nouveau_fence *fence = nvbo->bo.sync_obj;
434432
int ret = 0;
435433

436-
spin_lock(&nvbo->bo.bdev->fence_lock);
437-
fence = nouveau_fence_ref(nvbo->bo.sync_obj);
438-
spin_unlock(&nvbo->bo.bdev->fence_lock);
439-
440-
if (fence) {
434+
if (fence)
441435
ret = nouveau_fence_sync(fence, chan);
442-
nouveau_fence_unref(&fence);
443-
}
444436

445437
return ret;
446438
}
@@ -659,9 +651,7 @@ nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
659651
data |= r->vor;
660652
}
661653

662-
spin_lock(&nvbo->bo.bdev->fence_lock);
663654
ret = ttm_bo_wait(&nvbo->bo, false, false, false);
664-
spin_unlock(&nvbo->bo.bdev->fence_lock);
665655
if (ret) {
666656
NV_PRINTK(error, cli, "reloc wait_idle failed: %d\n", ret);
667657
break;
@@ -894,11 +884,9 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
894884

895885
ret = ttm_bo_reserve(&nvbo->bo, true, false, false, NULL);
896886
if (!ret) {
897-
spin_lock(&nvbo->bo.bdev->fence_lock);
898887
ret = ttm_bo_wait(&nvbo->bo, true, true, true);
899888
if (!no_wait && ret)
900889
fence = nouveau_fence_ref(nvbo->bo.sync_obj);
901-
spin_unlock(&nvbo->bo.bdev->fence_lock);
902890

903891
ttm_bo_unreserve(&nvbo->bo);
904892
}

‎drivers/gpu/drm/qxl/qxl_cmd.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,7 @@ static int qxl_reap_surf(struct qxl_device *qdev, struct qxl_bo *surf, bool stal
628628
if (stall)
629629
mutex_unlock(&qdev->surf_evict_mutex);
630630

631-
spin_lock(&surf->tbo.bdev->fence_lock);
632631
ret = ttm_bo_wait(&surf->tbo, true, true, !stall);
633-
spin_unlock(&surf->tbo.bdev->fence_lock);
634632

635633
if (stall)
636634
mutex_lock(&qdev->surf_evict_mutex);

‎drivers/gpu/drm/qxl/qxl_fence.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ int qxl_fence_remove_release(struct qxl_fence *qfence, uint32_t rel_id)
6060
{
6161
void *ret;
6262
int retval = 0;
63-
struct qxl_bo *bo = container_of(qfence, struct qxl_bo, fence);
64-
65-
spin_lock(&bo->tbo.bdev->fence_lock);
6663

6764
ret = radix_tree_delete(&qfence->tree, rel_id);
6865
if (ret == qfence)
@@ -71,7 +68,6 @@ int qxl_fence_remove_release(struct qxl_fence *qfence, uint32_t rel_id)
7168
DRM_DEBUG("didn't find fence in radix tree for %d\n", rel_id);
7269
retval = -ENOENT;
7370
}
74-
spin_unlock(&bo->tbo.bdev->fence_lock);
7571
return retval;
7672
}
7773

‎drivers/gpu/drm/qxl/qxl_object.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ static inline int qxl_bo_wait(struct qxl_bo *bo, u32 *mem_type,
7676
}
7777
return r;
7878
}
79-
spin_lock(&bo->tbo.bdev->fence_lock);
8079
if (mem_type)
8180
*mem_type = bo->tbo.mem.mem_type;
8281
if (bo->tbo.sync_obj)
8382
r = ttm_bo_wait(&bo->tbo, true, true, no_wait);
84-
spin_unlock(&bo->tbo.bdev->fence_lock);
8583
ttm_bo_unreserve(&bo->tbo);
8684
return r;
8785
}

‎drivers/gpu/drm/qxl/qxl_release.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)
337337
glob = bo->glob;
338338

339339
spin_lock(&glob->lru_lock);
340-
spin_lock(&bdev->fence_lock);
341340

342341
list_for_each_entry(entry, &release->bos, head) {
343342
bo = entry->bo;
@@ -352,7 +351,6 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)
352351
__ttm_bo_unreserve(bo);
353352
entry->reserved = false;
354353
}
355-
spin_unlock(&bdev->fence_lock);
356354
spin_unlock(&glob->lru_lock);
357355
ww_acquire_fini(&release->ticket);
358356
}

‎drivers/gpu/drm/radeon/radeon_display.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,6 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc,
476476
obj = new_radeon_fb->obj;
477477
new_rbo = gem_to_radeon_bo(obj);
478478

479-
spin_lock(&new_rbo->tbo.bdev->fence_lock);
480-
if (new_rbo->tbo.sync_obj)
481-
work->fence = radeon_fence_ref(new_rbo->tbo.sync_obj);
482-
spin_unlock(&new_rbo->tbo.bdev->fence_lock);
483-
484479
/* pin the new buffer */
485480
DRM_DEBUG_DRIVER("flip-ioctl() cur_rbo = %p, new_rbo = %p\n",
486481
work->old_rbo, new_rbo);
@@ -499,6 +494,7 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc,
499494
DRM_ERROR("failed to pin new rbo buffer before flip\n");
500495
goto cleanup;
501496
}
497+
work->fence = radeon_fence_ref(new_rbo->tbo.sync_obj);
502498
radeon_bo_get_tiling_flags(new_rbo, &tiling_flags, NULL);
503499
radeon_bo_unreserve(new_rbo);
504500

@@ -582,7 +578,6 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc,
582578
drm_gem_object_unreference_unlocked(&work->old_rbo->gem_base);
583579
radeon_fence_unref(&work->fence);
584580
kfree(work);
585-
586581
return r;
587582
}
588583

‎drivers/gpu/drm/radeon/radeon_object.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,10 @@ int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type, bool no_wait)
779779
r = ttm_bo_reserve(&bo->tbo, true, no_wait, false, NULL);
780780
if (unlikely(r != 0))
781781
return r;
782-
spin_lock(&bo->tbo.bdev->fence_lock);
783782
if (mem_type)
784783
*mem_type = bo->tbo.mem.mem_type;
785784
if (bo->tbo.sync_obj)
786785
r = ttm_bo_wait(&bo->tbo, true, true, no_wait);
787-
spin_unlock(&bo->tbo.bdev->fence_lock);
788786
ttm_bo_unreserve(&bo->tbo);
789787
return r;
790788
}

‎drivers/gpu/drm/ttm/ttm_bo.c‎

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -415,24 +415,20 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
415415
spin_lock(&glob->lru_lock);
416416
ret = __ttm_bo_reserve(bo, false, true, false, NULL);
417417

418-
spin_lock(&bdev->fence_lock);
419-
(void) ttm_bo_wait(bo, false, false, true);
420-
if (!ret && !bo->sync_obj) {
421-
spin_unlock(&bdev->fence_lock);
422-
put_count = ttm_bo_del_from_lru(bo);
418+
if (!ret) {
419+
(void) ttm_bo_wait(bo, false, false, true);
423420

424-
spin_unlock(&glob->lru_lock);
425-
ttm_bo_cleanup_memtype_use(bo);
421+
if (!bo->sync_obj) {
422+
put_count = ttm_bo_del_from_lru(bo);
426423

427-
ttm_bo_list_ref_sub(bo, put_count, true);
424+
spin_unlock(&glob->lru_lock);
425+
ttm_bo_cleanup_memtype_use(bo);
428426

429-
return;
430-
}
431-
if (bo->sync_obj)
432-
sync_obj = driver->sync_obj_ref(bo->sync_obj);
433-
spin_unlock(&bdev->fence_lock);
427+
ttm_bo_list_ref_sub(bo, put_count, true);
434428

435-
if (!ret) {
429+
return;
430+
}
431+
sync_obj = driver->sync_obj_ref(bo->sync_obj);
436432

437433
/*
438434
* Make NO_EVICT bos immediately available to
@@ -481,7 +477,6 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
481477
int put_count;
482478
int ret;
483479

484-
spin_lock(&bdev->fence_lock);
485480
ret = ttm_bo_wait(bo, false, false, true);
486481

487482
if (ret && !no_wait_gpu) {
@@ -493,7 +488,6 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
493488
* no new sync objects can be attached.
494489
*/
495490
sync_obj = driver->sync_obj_ref(bo->sync_obj);
496-
spin_unlock(&bdev->fence_lock);
497491

498492
__ttm_bo_unreserve(bo);
499493
spin_unlock(&glob->lru_lock);
@@ -523,11 +517,9 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
523517
* remove sync_obj with ttm_bo_wait, the wait should be
524518
* finished, and no new wait object should have been added.
525519
*/
526-
spin_lock(&bdev->fence_lock);
527520
ret = ttm_bo_wait(bo, false, false, true);
528521
WARN_ON(ret);
529522
}
530-
spin_unlock(&bdev->fence_lock);
531523

532524
if (ret || unlikely(list_empty(&bo->ddestroy))) {
533525
__ttm_bo_unreserve(bo);
@@ -665,9 +657,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible,
665657
struct ttm_placement placement;
666658
int ret = 0;
667659

668-
spin_lock(&bdev->fence_lock);
669660
ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu);
670-
spin_unlock(&bdev->fence_lock);
671661

672662
if (unlikely(ret != 0)) {
673663
if (ret != -ERESTARTSYS) {
@@ -958,7 +948,6 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
958948
{
959949
int ret = 0;
960950
struct ttm_mem_reg mem;
961-
struct ttm_bo_device *bdev = bo->bdev;
962951

963952
lockdep_assert_held(&bo->resv->lock.base);
964953

@@ -967,9 +956,7 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
967956
* Have the driver move function wait for idle when necessary,
968957
* instead of doing it here.
969958
*/
970-
spin_lock(&bdev->fence_lock);
971959
ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu);
972-
spin_unlock(&bdev->fence_lock);
973960
if (ret)
974961
return ret;
975962
mem.num_pages = bo->num_pages;
@@ -1459,7 +1446,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
14591446
bdev->glob = glob;
14601447
bdev->need_dma32 = need_dma32;
14611448
bdev->val_seq = 0;
1462-
spin_lock_init(&bdev->fence_lock);
14631449
mutex_lock(&glob->device_list_mutex);
14641450
list_add_tail(&bdev->device_list, &glob->device_list);
14651451
mutex_unlock(&glob->device_list_mutex);
@@ -1517,7 +1503,6 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,
15171503
bool lazy, bool interruptible, bool no_wait)
15181504
{
15191505
struct ttm_bo_driver *driver = bo->bdev->driver;
1520-
struct ttm_bo_device *bdev = bo->bdev;
15211506
void *sync_obj;
15221507
int ret = 0;
15231508

@@ -1526,53 +1511,33 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,
15261511
if (likely(bo->sync_obj == NULL))
15271512
return 0;
15281513

1529-
while (bo->sync_obj) {
1530-
1514+
if (bo->sync_obj) {
15311515
if (driver->sync_obj_signaled(bo->sync_obj)) {
1532-
void *tmp_obj = bo->sync_obj;
1533-
bo->sync_obj = NULL;
1516+
driver->sync_obj_unref(&bo->sync_obj);
15341517
clear_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
1535-
spin_unlock(&bdev->fence_lock);
1536-
driver->sync_obj_unref(&tmp_obj);
1537-
spin_lock(&bdev->fence_lock);
1538-
continue;
1518+
return 0;
15391519
}
15401520

15411521
if (no_wait)
15421522
return -EBUSY;
15431523

15441524
sync_obj = driver->sync_obj_ref(bo->sync_obj);
1545-
spin_unlock(&bdev->fence_lock);
15461525
ret = driver->sync_obj_wait(sync_obj,
15471526
lazy, interruptible);
1548-
if (unlikely(ret != 0)) {
1549-
driver->sync_obj_unref(&sync_obj);
1550-
spin_lock(&bdev->fence_lock);
1551-
return ret;
1552-
}
1553-
spin_lock(&bdev->fence_lock);
1554-
if (likely(bo->sync_obj == sync_obj)) {
1555-
void *tmp_obj = bo->sync_obj;
1556-
bo->sync_obj = NULL;
1527+
1528+
if (likely(ret == 0)) {
15571529
clear_bit(TTM_BO_PRIV_FLAG_MOVING,
15581530
&bo->priv_flags);
1559-
spin_unlock(&bdev->fence_lock);
1560-
driver->sync_obj_unref(&sync_obj);
1561-
driver->sync_obj_unref(&tmp_obj);
1562-
spin_lock(&bdev->fence_lock);
1563-
} else {
1564-
spin_unlock(&bdev->fence_lock);
1565-
driver->sync_obj_unref(&sync_obj);
1566-
spin_lock(&bdev->fence_lock);
1531+
driver->sync_obj_unref(&bo->sync_obj);
15671532
}
1533+
driver->sync_obj_unref(&sync_obj);
15681534
}
1569-
return 0;
1535+
return ret;
15701536
}
15711537
EXPORT_SYMBOL(ttm_bo_wait);
15721538

15731539
int ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait)
15741540
{
1575-
struct ttm_bo_device *bdev = bo->bdev;
15761541
int ret = 0;
15771542

15781543
/*
@@ -1582,9 +1547,7 @@ int ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait)
15821547
ret = ttm_bo_reserve(bo, true, no_wait, false, NULL);
15831548
if (unlikely(ret != 0))
15841549
return ret;
1585-
spin_lock(&bdev->fence_lock);
15861550
ret = ttm_bo_wait(bo, false, true, no_wait);
1587-
spin_unlock(&bdev->fence_lock);
15881551
if (likely(ret == 0))
15891552
atomic_inc(&bo->cpu_writers);
15901553
ttm_bo_unreserve(bo);
@@ -1641,9 +1604,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
16411604
* Wait for GPU, then move to system cached.
16421605
*/
16431606

1644-
spin_lock(&bo->bdev->fence_lock);
16451607
ret = ttm_bo_wait(bo, false, false, false);
1646-
spin_unlock(&bo->bdev->fence_lock);
16471608

16481609
if (unlikely(ret != 0))
16491610
goto out;

0 commit comments

Comments
 (0)