Skip to content

Commit 764be12

Browse files
committed
drm/etnaviv: convert user fence tracking to XArray
This simplifies the driver code a bit, as XArray already provides internal locking. IDRs are implemented using XArrays anyways, so this drops one level of unneeded abstraction. Signed-off-by: Lucas Stach <[email protected]> Reviewed-by: Philipp Zabel <[email protected]>
1 parent 2cd5bd9 commit 764be12

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

drivers/gpu/drm/etnaviv/etnaviv_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/sizes.h>
1313
#include <linux/time64.h>
1414
#include <linux/types.h>
15+
#include <linux/xarray.h>
1516

1617
#include <drm/drm_drv.h>
1718
#include <drm/drm_gem.h>

drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,11 @@ static void submit_cleanup(struct kref *kref)
393393
wake_up_all(&submit->gpu->fence_event);
394394

395395
if (submit->out_fence) {
396-
/* first remove from IDR, so fence can not be found anymore */
397-
mutex_lock(&submit->gpu->idr_lock);
398-
idr_remove(&submit->gpu->fence_idr, submit->out_fence_id);
399-
mutex_unlock(&submit->gpu->idr_lock);
396+
/*
397+
* Remove from user fence array before dropping the reference,
398+
* so fence can not be found in lookup anymore.
399+
*/
400+
xa_erase(&submit->gpu->user_fences, submit->out_fence_id);
400401
dma_fence_put(submit->out_fence);
401402
}
402403

drivers/gpu/drm/etnaviv/etnaviv_gpu.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
12441244
* pretends we didn't find a fence in that case.
12451245
*/
12461246
rcu_read_lock();
1247-
fence = idr_find(&gpu->fence_idr, id);
1247+
fence = xa_load(&gpu->user_fences, id);
12481248
if (fence)
12491249
fence = dma_fence_get_rcu(fence);
12501250
rcu_read_unlock();
@@ -1744,7 +1744,7 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master,
17441744

17451745
gpu->drm = drm;
17461746
gpu->fence_context = dma_fence_context_alloc(1);
1747-
idr_init(&gpu->fence_idr);
1747+
xa_init_flags(&gpu->user_fences, XA_FLAGS_ALLOC);
17481748
spin_lock_init(&gpu->fence_spinlock);
17491749

17501750
INIT_WORK(&gpu->sync_point_work, sync_point_worker);
@@ -1798,7 +1798,7 @@ static void etnaviv_gpu_unbind(struct device *dev, struct device *master,
17981798
}
17991799

18001800
gpu->drm = NULL;
1801-
idr_destroy(&gpu->fence_idr);
1801+
xa_destroy(&gpu->user_fences);
18021802

18031803
if (IS_ENABLED(CONFIG_DRM_ETNAVIV_THERMAL))
18041804
thermal_cooling_device_unregister(gpu->cooling);
@@ -1831,7 +1831,6 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
18311831
gpu->dev = &pdev->dev;
18321832
mutex_init(&gpu->lock);
18331833
mutex_init(&gpu->sched_lock);
1834-
mutex_init(&gpu->idr_lock);
18351834

18361835
/* Map registers: */
18371836
gpu->mmio = devm_platform_ioremap_resource(pdev, 0);

drivers/gpu/drm/etnaviv/etnaviv_gpu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ struct etnaviv_gpu {
121121
u32 idle_mask;
122122

123123
/* Fencing support */
124-
struct mutex idr_lock;
125-
struct idr fence_idr;
124+
struct xarray user_fences;
125+
u32 next_user_fence;
126126
u32 next_fence;
127127
u32 completed_fence;
128128
wait_queue_head_t fence_event;

drivers/gpu/drm/etnaviv/etnaviv_sched.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static const struct drm_sched_backend_ops etnaviv_sched_ops = {
9898
int etnaviv_sched_push_job(struct etnaviv_gem_submit *submit)
9999
{
100100
struct etnaviv_gpu *gpu = submit->gpu;
101-
int ret = 0;
101+
int ret;
102102

103103
/*
104104
* Hold the sched lock across the whole operation to avoid jobs being
@@ -110,14 +110,11 @@ int etnaviv_sched_push_job(struct etnaviv_gem_submit *submit)
110110
drm_sched_job_arm(&submit->sched_job);
111111

112112
submit->out_fence = dma_fence_get(&submit->sched_job.s_fence->finished);
113-
mutex_lock(&gpu->idr_lock);
114-
submit->out_fence_id = idr_alloc_cyclic(&gpu->fence_idr,
115-
submit->out_fence, 0,
116-
INT_MAX, GFP_KERNEL);
117-
mutex_unlock(&gpu->idr_lock);
118-
if (submit->out_fence_id < 0) {
113+
ret = xa_alloc_cyclic(&gpu->user_fences, &submit->out_fence_id,
114+
submit->out_fence, xa_limit_32b,
115+
&gpu->next_user_fence, GFP_KERNEL);
116+
if (ret < 0) {
119117
drm_sched_job_cleanup(&submit->sched_job);
120-
ret = -ENOMEM;
121118
goto out_unlock;
122119
}
123120

0 commit comments

Comments
 (0)