kernel: bump 6.1 to 6.1.39
[openwrt/staging/hauke.git] / target / linux / bcm27xx / patches-6.1 / 950-0330-staging-vchiq_arm-Usa-a-DMA-pool-for-small-bulks.patch
1 From dfbd92cb3b27855e388e17dc5035fa0e5fb70474 Mon Sep 17 00:00:00 2001
2 From: detule <ogjoneski@gmail.com>
3 Date: Tue, 2 Oct 2018 04:10:08 -0400
4 Subject: [PATCH] staging: vchiq_arm: Usa a DMA pool for small bulks
5
6 During a bulk transfer we request a DMA allocation to hold the
7 scatter-gather list. Most of the time, this allocation is small
8 (<< PAGE_SIZE), however it can be requested at a high enough frequency
9 to cause fragmentation and/or stress the CMA allocator (think time
10 spent in compaction here, or during allocations elsewhere).
11
12 Implement a pool to serve up small DMA allocations, falling back
13 to a coherent allocation if the request is greater than
14 VCHIQ_DMA_POOL_SIZE.
15
16 Signed-off-by: Oliver Gjoneski <ogjoneski@gmail.com>
17 ---
18 .../interface/vchiq_arm/vchiq_arm.c | 33 ++++++++++++++++---
19 1 file changed, 29 insertions(+), 4 deletions(-)
20
21 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
22 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
23 @@ -22,6 +22,7 @@
24 #include <linux/platform_device.h>
25 #include <linux/compat.h>
26 #include <linux/dma-mapping.h>
27 +#include <linux/dmapool.h>
28 #include <linux/rcupdate.h>
29 #include <linux/delay.h>
30 #include <linux/slab.h>
31 @@ -51,6 +52,8 @@
32
33 #define ARM_DS_ACTIVE BIT(2)
34
35 +#define VCHIQ_DMA_POOL_SIZE PAGE_SIZE
36 +
37 /* Override the default prefix, which would be vchiq_arm (from the filename) */
38 #undef MODULE_PARAM_PREFIX
39 #define MODULE_PARAM_PREFIX DEVICE_NAME "."
40 @@ -133,6 +136,7 @@ struct vchiq_pagelist_info {
41 struct pagelist *pagelist;
42 size_t pagelist_buffer_size;
43 dma_addr_t dma_addr;
44 + bool is_from_pool;
45 enum dma_data_direction dma_dir;
46 unsigned int num_pages;
47 unsigned int pages_need_release;
48 @@ -153,6 +157,7 @@ static void __iomem *g_regs;
49 * of 32.
50 */
51 static unsigned int g_cache_line_size = 32;
52 +static struct dma_pool *g_dma_pool;
53 static unsigned int g_use_36bit_addrs = 0;
54 static unsigned int g_fragments_size;
55 static char *g_fragments_base;
56 @@ -195,8 +200,13 @@ cleanup_pagelistinfo(struct vchiq_instan
57 if (pagelistinfo->pages_need_release)
58 unpin_user_pages(pagelistinfo->pages, pagelistinfo->num_pages);
59
60 - dma_free_coherent(instance->state->dev, pagelistinfo->pagelist_buffer_size,
61 - pagelistinfo->pagelist, pagelistinfo->dma_addr);
62 + if (pagelistinfo->is_from_pool) {
63 + dma_pool_free(g_dma_pool, pagelistinfo->pagelist,
64 + pagelistinfo->dma_addr);
65 + } else {
66 + dma_free_coherent(instance->state->dev, pagelistinfo->pagelist_buffer_size,
67 + pagelistinfo->pagelist, pagelistinfo->dma_addr);
68 + }
69 }
70
71 static inline bool
72 @@ -231,6 +241,7 @@ create_pagelist(struct vchiq_instance *i
73 u32 *addrs;
74 unsigned int num_pages, offset, i, k;
75 int actual_pages;
76 + bool is_from_pool;
77 size_t pagelist_size;
78 struct scatterlist *scatterlist, *sg;
79 int dma_buffers;
80 @@ -260,8 +271,14 @@ create_pagelist(struct vchiq_instance *i
81 /* Allocate enough storage to hold the page pointers and the page
82 * list
83 */
84 - pagelist = dma_alloc_coherent(instance->state->dev, pagelist_size, &dma_addr,
85 - GFP_KERNEL);
86 + if (pagelist_size > VCHIQ_DMA_POOL_SIZE) {
87 + pagelist = dma_alloc_coherent(instance->state->dev, pagelist_size, &dma_addr,
88 + GFP_KERNEL);
89 + is_from_pool = false;
90 + } else {
91 + pagelist = dma_pool_alloc(g_dma_pool, GFP_KERNEL, &dma_addr);
92 + is_from_pool = true;
93 + }
94
95 vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist);
96
97 @@ -282,6 +299,7 @@ create_pagelist(struct vchiq_instance *i
98 pagelistinfo->pagelist = pagelist;
99 pagelistinfo->pagelist_buffer_size = pagelist_size;
100 pagelistinfo->dma_addr = dma_addr;
101 + pagelistinfo->is_from_pool = is_from_pool;
102 pagelistinfo->dma_dir = (type == PAGELIST_WRITE) ?
103 DMA_TO_DEVICE : DMA_FROM_DEVICE;
104 pagelistinfo->num_pages = num_pages;
105 @@ -616,6 +634,13 @@ static int vchiq_platform_init(struct pl
106 }
107
108 g_dma_dev = dma_dev ?: dev;
109 + g_dma_pool = dmam_pool_create("vchiq_scatter_pool", dev,
110 + VCHIQ_DMA_POOL_SIZE, g_cache_line_size,
111 + 0);
112 + if (!g_dma_pool) {
113 + dev_err(dev, "failed to create dma pool");
114 + return -ENOMEM;
115 + }
116
117 vchiq_log_info(vchiq_arm_log_level, "vchiq_init - done (slots %pK, phys %pad)",
118 vchiq_slot_zero, &slot_phys);