Skip to content

Commit

Permalink
msm: kgsl: Avoid dynamically allocating small command buffers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kerneltoast authored and Ristovski committed Nov 18, 2023
1 parent 06a0669 commit 0a6f49e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions drivers/gpu/msm/adreno_ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 0a6f49e

Please sign in to comment.