Skip to content

Commit d1ef967

Browse files
mbrost05lucasdemarchi
authored andcommitted
drm/xe: Convert to USM lock to rwsem
Remove contention from GPU fault path for ASID->VM lookup. Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Matthew Auld <[email protected]> Reviewed-by: Himal Prasad Ghimiray <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 1378c63) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent cb58977 commit d1ef967

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

drivers/gpu/drm/xe/xe_device.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,7 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
339339

340340
init_waitqueue_head(&xe->ufence_wq);
341341

342-
err = drmm_mutex_init(&xe->drm, &xe->usm.lock);
343-
if (err)
344-
goto err;
342+
init_rwsem(&xe->usm.lock);
345343

346344
xa_init_flags(&xe->usm.asid_to_vm, XA_FLAGS_ALLOC);
347345

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ struct xe_device {
369369
/** @usm.next_asid: next ASID, used to cyclical alloc asids */
370370
u32 next_asid;
371371
/** @usm.lock: protects UM state */
372-
struct mutex lock;
372+
struct rw_semaphore lock;
373373
} usm;
374374

375375
/** @pinned: pinned BO state */

drivers/gpu/drm/xe/xe_gt_pagefault.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
198198
return -EFAULT;
199199

200200
/* ASID to VM */
201-
mutex_lock(&xe->usm.lock);
201+
down_read(&xe->usm.lock);
202202
vm = xa_load(&xe->usm.asid_to_vm, pf->asid);
203203
if (vm && xe_vm_in_fault_mode(vm))
204204
xe_vm_get(vm);
205205
else
206206
vm = NULL;
207-
mutex_unlock(&xe->usm.lock);
207+
up_read(&xe->usm.lock);
208208
if (!vm)
209209
return -EINVAL;
210210

@@ -549,11 +549,11 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
549549
return -EINVAL;
550550

551551
/* ASID to VM */
552-
mutex_lock(&xe->usm.lock);
552+
down_read(&xe->usm.lock);
553553
vm = xa_load(&xe->usm.asid_to_vm, acc->asid);
554554
if (vm)
555555
xe_vm_get(vm);
556-
mutex_unlock(&xe->usm.lock);
556+
up_read(&xe->usm.lock);
557557
if (!vm || !xe_vm_in_fault_mode(vm))
558558
return -EINVAL;
559559

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
16131613

16141614
up_write(&vm->lock);
16151615

1616-
mutex_lock(&xe->usm.lock);
1616+
down_write(&xe->usm.lock);
16171617
if (vm->usm.asid) {
16181618
void *lookup;
16191619

@@ -1623,7 +1623,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
16231623
lookup = xa_erase(&xe->usm.asid_to_vm, vm->usm.asid);
16241624
xe_assert(xe, lookup == vm);
16251625
}
1626-
mutex_unlock(&xe->usm.lock);
1626+
up_write(&xe->usm.lock);
16271627

16281628
for_each_tile(tile, xe, id)
16291629
xe_range_fence_tree_fini(&vm->rftree[id]);
@@ -1772,11 +1772,11 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
17721772
goto err_close_and_put;
17731773

17741774
if (xe->info.has_asid) {
1775-
mutex_lock(&xe->usm.lock);
1775+
down_write(&xe->usm.lock);
17761776
err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
17771777
XA_LIMIT(1, XE_MAX_ASID - 1),
17781778
&xe->usm.next_asid, GFP_KERNEL);
1779-
mutex_unlock(&xe->usm.lock);
1779+
up_write(&xe->usm.lock);
17801780
if (err < 0)
17811781
goto err_free_id;
17821782

0 commit comments

Comments
 (0)