From 0a6f49e1ab6b009892fd373a32956e4c59a73e0d Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Sat, 18 Nov 2023 19:38:52 +0100 Subject: [PATCH] msm: kgsl: Avoid dynamically allocating small command buffers Most command buffers here are rather small (fewer than 256 words); it's a waste of time to dynamically allocate memory for such a small buffer when it could easily fit on the stack. Conditionally using an on-stack command buffer when the size is small enough eliminates the need for using a dynamically-allocated buffer most of the time, reducing GPU command submission latency. --- drivers/gpu/msm/adreno_ringbuffer.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/msm/adreno_ringbuffer.c b/drivers/gpu/msm/adreno_ringbuffer.c index 1aa6777f8..c707e28be 100644 --- a/drivers/gpu/msm/adreno_ringbuffer.c +++ b/drivers/gpu/msm/adreno_ringbuffer.c @@ -869,6 +869,7 @@ int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev, struct kgsl_memobj_node *ib; unsigned int numibs = 0; unsigned int *link; + unsigned int link_onstack[SZ_256] __aligned(sizeof(long)); unsigned int *cmds; struct kgsl_context *context; struct adreno_context *drawctxt; @@ -996,10 +997,14 @@ int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev, if (gpudev->ccu_invalidate) dwords += 4; - link = kvcalloc(dwords, sizeof(unsigned int), GFP_KERNEL); - if (!link) { - ret = -ENOMEM; - goto done; + if (dwords <= ARRAY_SIZE(link_onstack)) { + link = link_onstack; + } else { + link = kvcalloc(dwords, sizeof(unsigned int), GFP_KERNEL); + if (!link) { + ret = -ENOMEM; + goto done; + } } cmds = link; @@ -1129,7 +1134,9 @@ int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev, trace_kgsl_issueibcmds(device, context->id, numibs, drawobj->timestamp, drawobj->flags, ret, drawctxt->type); - kvfree(link); + if (link != link_onstack) + kvfree(link); + return ret; }