Skip to content

Commit 3a1a31d

Browse files
detulepopcornmix
authored andcommitted
vchiq_2835_arm: Implement a DMA pool for small bulk transfers (#2699)
During a bulk transfer we request a DMA allocation to hold the scatter-gather list. Most of the time, this allocation is small (<< PAGE_SIZE), however it can be requested at a high enough frequency to cause fragmentation and/or stress the CMA allocator (think time spent in compaction here, or during allocations elsewhere). Implement a pool to serve up small DMA allocations, falling back to a coherent allocation if the request is greater than VCHIQ_DMA_POOL_SIZE. Signed-off-by: Oliver Gjoneski <[email protected]>
1 parent df5b90b commit 3a1a31d

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/interrupt.h>
3838
#include <linux/pagemap.h>
3939
#include <linux/dma-mapping.h>
40+
#include <linux/dmapool.h>
4041
#include <linux/io.h>
4142
#include <linux/platform_device.h>
4243
#include <linux/uaccess.h>
@@ -60,6 +61,8 @@
6061
#define BELL0 0x00
6162
#define BELL2 0x08
6263

64+
#define VCHIQ_DMA_POOL_SIZE PAGE_SIZE
65+
6366
struct vchiq_2835_state {
6467
int inited;
6568
VCHIQ_ARM_STATE_T arm_state;
@@ -69,6 +72,7 @@ struct vchiq_pagelist_info {
6972
PAGELIST_T *pagelist;
7073
size_t pagelist_buffer_size;
7174
dma_addr_t dma_addr;
75+
bool is_from_pool;
7276
enum dma_data_direction dma_dir;
7377
unsigned int num_pages;
7478
unsigned int pages_need_release;
@@ -91,6 +95,7 @@ static void __iomem *g_regs;
9195
* relevant Device Tree node.
9296
*/
9397
static unsigned int g_cache_line_size;
98+
static struct dma_pool *g_dma_pool;
9499
static unsigned int g_fragments_size;
95100
static char *g_fragments_base;
96101
static char *g_free_fragments;
@@ -206,6 +211,14 @@ int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state)
206211
}
207212

208213
g_dev = dev;
214+
g_dma_pool = dmam_pool_create("vchiq_scatter_pool", dev,
215+
VCHIQ_DMA_POOL_SIZE, g_cache_line_size,
216+
0);
217+
if (!g_dma_pool) {
218+
dev_err(dev, "failed to create dma pool");
219+
return -ENOMEM;
220+
}
221+
209222
vchiq_log_info(vchiq_arm_log_level,
210223
"vchiq_init - done (slots %pK, phys %pad)",
211224
vchiq_slot_zero, &slot_phys);
@@ -394,9 +407,14 @@ cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo)
394407
for (i = 0; i < pagelistinfo->num_pages; i++)
395408
put_page(pagelistinfo->pages[i]);
396409
}
397-
398-
dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
399-
pagelistinfo->pagelist, pagelistinfo->dma_addr);
410+
if (pagelistinfo->is_from_pool) {
411+
dma_pool_free(g_dma_pool, pagelistinfo->pagelist,
412+
pagelistinfo->dma_addr);
413+
} else {
414+
dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
415+
pagelistinfo->pagelist,
416+
pagelistinfo->dma_addr);
417+
}
400418
}
401419

402420
/* There is a potential problem with partial cache lines (pages?)
@@ -416,6 +434,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
416434
u32 *addrs;
417435
unsigned int num_pages, offset, i, k;
418436
int actual_pages;
437+
bool is_from_pool;
419438
size_t pagelist_size;
420439
struct scatterlist *scatterlist, *sg;
421440
int dma_buffers;
@@ -433,10 +452,16 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
433452
/* Allocate enough storage to hold the page pointers and the page
434453
* list
435454
*/
436-
pagelist = dma_zalloc_coherent(g_dev,
437-
pagelist_size,
438-
&dma_addr,
439-
GFP_KERNEL);
455+
if (pagelist_size > VCHIQ_DMA_POOL_SIZE) {
456+
pagelist = dma_zalloc_coherent(g_dev,
457+
pagelist_size,
458+
&dma_addr,
459+
GFP_KERNEL);
460+
is_from_pool = false;
461+
} else {
462+
pagelist = dma_pool_zalloc(g_dma_pool, GFP_KERNEL, &dma_addr);
463+
is_from_pool = true;
464+
}
440465

441466
vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist);
442467

@@ -457,6 +482,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
457482
pagelistinfo->pagelist = pagelist;
458483
pagelistinfo->pagelist_buffer_size = pagelist_size;
459484
pagelistinfo->dma_addr = dma_addr;
485+
pagelistinfo->is_from_pool = is_from_pool;
460486
pagelistinfo->dma_dir = (type == PAGELIST_WRITE) ?
461487
DMA_TO_DEVICE : DMA_FROM_DEVICE;
462488
pagelistinfo->num_pages = num_pages;

0 commit comments

Comments
 (0)