]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/msm: Pre-allocate hw_fence
authorRob Clark <robdclark@chromium.org>
Mon, 20 Mar 2023 14:43:23 +0000 (07:43 -0700)
committerRob Clark <robdclark@chromium.org>
Sat, 25 Mar 2023 23:31:43 +0000 (16:31 -0700)
Avoid allocating memory in job_run() by pre-allocating the hw_fence.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Patchwork: https://patchwork.freedesktop.org/patch/527832/
Link: https://lore.kernel.org/r/20230320144356.803762-2-robdclark@gmail.com
drivers/gpu/drm/msm/msm_fence.c
drivers/gpu/drm/msm/msm_fence.h
drivers/gpu/drm/msm/msm_gem_submit.c
drivers/gpu/drm/msm/msm_ringbuffer.c

index 56641408ea742ad911f78c983db092d0cef66a89..bab3d84f1686276f9839402bae5f1aeaa282b1a1 100644 (file)
@@ -99,7 +99,7 @@ static const struct dma_fence_ops msm_fence_ops = {
 };
 
 struct dma_fence *
-msm_fence_alloc(struct msm_fence_context *fctx)
+msm_fence_alloc(void)
 {
        struct msm_fence *f;
 
@@ -107,10 +107,16 @@ msm_fence_alloc(struct msm_fence_context *fctx)
        if (!f)
                return ERR_PTR(-ENOMEM);
 
+       return &f->base;
+}
+
+void
+msm_fence_init(struct dma_fence *fence, struct msm_fence_context *fctx)
+{
+       struct msm_fence *f = to_msm_fence(fence);
+
        f->fctx = fctx;
 
        dma_fence_init(&f->base, &msm_fence_ops, &fctx->spinlock,
                       fctx->context, ++fctx->last_fence);
-
-       return &f->base;
 }
index 7f1798c54cd15195353ee5ecbadde6169ae89dd2..f913fa22d8fef144ccf25d11ee1a9cff1c29b0b7 100644 (file)
@@ -61,7 +61,8 @@ void msm_fence_context_free(struct msm_fence_context *fctx);
 bool msm_fence_completed(struct msm_fence_context *fctx, uint32_t fence);
 void msm_update_fence(struct msm_fence_context *fctx, uint32_t fence);
 
-struct dma_fence * msm_fence_alloc(struct msm_fence_context *fctx);
+struct dma_fence * msm_fence_alloc(void);
+void msm_fence_init(struct dma_fence *fence, struct msm_fence_context *fctx);
 
 static inline bool
 fence_before(uint32_t a, uint32_t b)
index ac8ed731f76d9007bdaf97df6cb163aa703dbe92..3aef47559dbe7761312260a3efa8b000c223e8cf 100644 (file)
@@ -41,8 +41,16 @@ static struct msm_gem_submit *submit_create(struct drm_device *dev,
        if (!submit)
                return ERR_PTR(-ENOMEM);
 
+       submit->hw_fence = msm_fence_alloc();
+       if (IS_ERR(submit->hw_fence)) {
+               ret = PTR_ERR(submit->hw_fence);
+               kfree(submit);
+               return ERR_PTR(ret);
+       }
+
        ret = drm_sched_job_init(&submit->base, queue->entity, queue);
        if (ret) {
+               kfree(submit->hw_fence);
                kfree(submit);
                return ERR_PTR(ret);
        }
index 57a8e9564540ee18d723d8b39bd435264df8b440..a62b45e5a8c3050b0752a124b626baa6c34da802 100644 (file)
@@ -18,7 +18,7 @@ static struct dma_fence *msm_job_run(struct drm_sched_job *job)
        struct msm_gpu *gpu = submit->gpu;
        int i;
 
-       submit->hw_fence = msm_fence_alloc(fctx);
+       msm_fence_init(submit->hw_fence, fctx);
 
        for (i = 0; i < submit->nr_bos; i++) {
                struct drm_gem_object *obj = &submit->bos[i].obj->base;