Skip to content

Commit c7d92d8

Browse files
detulepelwell
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 489e30e commit c7d92d8

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/interrupt.h>
88
#include <linux/pagemap.h>
99
#include <linux/dma-mapping.h>
10+
#include <linux/dmapool.h>
1011
#include <linux/io.h>
1112
#include <linux/platform_device.h>
1213
#include <linux/uaccess.h>
@@ -31,6 +32,8 @@
3132

3233
#define ARM_DS_ACTIVE BIT(2)
3334

35+
#define VCHIQ_DMA_POOL_SIZE PAGE_SIZE
36+
3437
struct vchiq_2835_state {
3538
int inited;
3639
struct vchiq_arm_state arm_state;
@@ -40,6 +43,7 @@ struct vchiq_pagelist_info {
4043
struct pagelist *pagelist;
4144
size_t pagelist_buffer_size;
4245
dma_addr_t dma_addr;
46+
bool is_from_pool;
4347
enum dma_data_direction dma_dir;
4448
unsigned int num_pages;
4549
unsigned int pages_need_release;
@@ -60,6 +64,7 @@ static void __iomem *g_regs;
6064
* of 32.
6165
*/
6266
static unsigned int g_cache_line_size = 32;
67+
static struct dma_pool *g_dma_pool;
6368
static unsigned int g_use_36bit_addrs = 0;
6469
static unsigned int g_fragments_size;
6570
static char *g_fragments_base;
@@ -185,6 +190,13 @@ int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state *state)
185190

186191
g_dev = dev;
187192
g_dma_dev = dma_dev ?: dev;
193+
g_dma_pool = dmam_pool_create("vchiq_scatter_pool", dev,
194+
VCHIQ_DMA_POOL_SIZE, g_cache_line_size,
195+
0);
196+
if (!g_dma_pool) {
197+
dev_err(dev, "failed to create dma pool");
198+
return -ENOMEM;
199+
}
188200

189201
vchiq_log_info(vchiq_arm_log_level,
190202
"vchiq_init - done (slots %pK, phys %pad)",
@@ -313,8 +325,14 @@ cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo)
313325
if (pagelistinfo->pages_need_release)
314326
unpin_user_pages(pagelistinfo->pages, pagelistinfo->num_pages);
315327

316-
dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
317-
pagelistinfo->pagelist, pagelistinfo->dma_addr);
328+
if (pagelistinfo->is_from_pool) {
329+
dma_pool_free(g_dma_pool, pagelistinfo->pagelist,
330+
pagelistinfo->dma_addr);
331+
} else {
332+
dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
333+
pagelistinfo->pagelist,
334+
pagelistinfo->dma_addr);
335+
}
318336
}
319337

320338
/* There is a potential problem with partial cache lines (pages?)
@@ -335,6 +353,7 @@ create_pagelist(char *buf, char __user *ubuf,
335353
u32 *addrs;
336354
unsigned int num_pages, offset, i, k;
337355
int actual_pages;
356+
bool is_from_pool;
338357
size_t pagelist_size;
339358
struct scatterlist *scatterlist, *sg;
340359
int dma_buffers;
@@ -364,8 +383,16 @@ create_pagelist(char *buf, char __user *ubuf,
364383
/* Allocate enough storage to hold the page pointers and the page
365384
* list
366385
*/
367-
pagelist = dma_alloc_coherent(g_dev, pagelist_size, &dma_addr,
368-
GFP_KERNEL);
386+
if (pagelist_size > VCHIQ_DMA_POOL_SIZE) {
387+
pagelist = dma_alloc_coherent(g_dev,
388+
pagelist_size,
389+
&dma_addr,
390+
GFP_KERNEL);
391+
is_from_pool = false;
392+
} else {
393+
pagelist = dma_pool_alloc(g_dma_pool, GFP_KERNEL, &dma_addr);
394+
is_from_pool = true;
395+
}
369396

370397
vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist);
371398

@@ -386,6 +413,7 @@ create_pagelist(char *buf, char __user *ubuf,
386413
pagelistinfo->pagelist = pagelist;
387414
pagelistinfo->pagelist_buffer_size = pagelist_size;
388415
pagelistinfo->dma_addr = dma_addr;
416+
pagelistinfo->is_from_pool = is_from_pool;
389417
pagelistinfo->dma_dir = (type == PAGELIST_WRITE) ?
390418
DMA_TO_DEVICE : DMA_FROM_DEVICE;
391419
pagelistinfo->num_pages = num_pages;

0 commit comments

Comments
 (0)