Skip to content

Commit

Permalink
ion: Cache the result from ion_cma_has_kernel_mapping()
Browse files Browse the repository at this point in the history
The result from ion_cma_has_kernel_mapping() will always be the same,
since it's just reading a property from the device tree. The repeated
device tree lookup adds up though, so it's helpful to cache the result.
This fixes the following irqsoff tracer report where IRQs are disabled
for over a millisecond, which happens quite often:

# tracer: irqsoff
#
# irqsoff latency trace v1.1.5 on 4.14.212-Sultan
# --------------------------------------------------------------------
# latency: 1173 us, #4/4, CPU#2 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:8)
#    -----------------
#    | task: HwBinder:682_1-696 (uid:1000 nice:0 policy:2 rt_prio:1)
#    -----------------
#  => started at: of_phandle_iterator_next
#  => ended at:   of_phandle_iterator_next
#
#
#                  _------=> CPU#
#                 / _-----=> irqs-off
#                | / _----=> need-resched
#                || / _---=> hardirq/softirq
#                ||| / _--=> preempt-depth
#                |||| /     delay
#  cmd     pid   ||||| time  |   caller
#     \   /      |||||  \    |   /
   <...>-696     2d...    0us#: of_find_node_by_phandle <-of_phandle_iterator_next
   <...>-696     2d..1 1172us : of_find_node_by_phandle <-of_phandle_iterator_next
   <...>-696     2d..1 1174us : trace_hardirqs_on <-of_phandle_iterator_next
   <...>-696     2d..1 1177us : <stack trace>
 => of_parse_phandle
 => ion_cma_allocate
 => ion_secure_cma_allocate
 => ion_alloc_dmabuf
 => ion_ioctl
 => vfs_ioctl
 => do_vfs_ioctl
 => SyS_ioctl
 => el0_svc_naked

Signed-off-by: Sultan Alsawaf <[email protected]>
Signed-off-by: Zlatan Radovanovic <[email protected]>
Signed-off-by: onettboots <[email protected]>
  • Loading branch information
kerneltoast authored and onettboots committed Apr 24, 2024
1 parent aa3657b commit f027f36
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/staging/android/ion/ion_cma_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
struct ion_cma_heap {
struct ion_heap heap;
struct cma *cma;
bool has_kernel_map;
};

struct ion_cma_buffer_info {
Expand All @@ -42,9 +43,8 @@ struct ion_cma_buffer_info {
};
#define to_cma_heap(x) container_of(x, struct ion_cma_heap, heap)

static bool ion_cma_has_kernel_mapping(struct ion_heap *heap)
static bool ion_cma_has_kernel_mapping(struct device *dev)
{
struct device *dev = heap->priv;
struct device_node *mem_region;

mem_region = of_parse_phandle(dev->of_node, "memory-region", 0);
Expand Down Expand Up @@ -88,7 +88,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
if (align > CONFIG_CMA_ALIGNMENT)
align = CONFIG_CMA_ALIGNMENT;

if (!ion_cma_has_kernel_mapping(heap)) {
if (!cma_heap->has_kernel_map) {
flags &= ~((unsigned long)ION_FLAG_CACHED);
buffer->flags = flags;

Expand Down Expand Up @@ -200,6 +200,7 @@ struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data)
if (!cma_heap)
return ERR_PTR(-ENOMEM);

cma_heap->has_kernel_map = ion_cma_has_kernel_mapping(dev);
cma_heap->heap.ops = &ion_cma_ops;
/*
* get device from private heaps data, later it will be
Expand Down

0 comments on commit f027f36

Please sign in to comment.