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.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
  • Loading branch information
kerneltoast committed Aug 21, 2019
1 parent beb620b commit 3db7951
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions drivers/gpu/msm/adreno_ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,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 @@ -846,10 +847,14 @@ int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev,
adreno_is_preemption_enabled(adreno_dev))
dwords += 8;

link = kzalloc(sizeof(unsigned int) * dwords, GFP_KERNEL);
if (!link) {
ret = -ENOMEM;
goto done;
if (dwords <= ARRAY_SIZE(link_onstack)) {
link = link_onstack;
} else {
link = kmalloc(sizeof(unsigned int) * dwords, GFP_KERNEL);
if (!link) {
ret = -ENOMEM;
goto done;
}
}

cmds = link;
Expand Down Expand Up @@ -1001,7 +1006,8 @@ int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev,
trace_kgsl_issueibcmds(device, context->id, numibs, drawobj->timestamp,
drawobj->flags, ret, drawctxt->type);

kfree(link);
if (link != link_onstack)
kfree(link);
return ret;
}

Expand Down

0 comments on commit 3db7951

Please sign in to comment.