Skip to content

Commit 4d55148

Browse files
detuleTiejunChina
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 d273af7 commit 4d55148

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);
@@ -397,9 +410,14 @@ cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo)
397410
for (i = 0; i < pagelistinfo->num_pages; i++)
398411
put_page(pagelistinfo->pages[i]);
399412
}
400-
401-
dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
402-
pagelistinfo->pagelist, pagelistinfo->dma_addr);
413+
if (pagelistinfo->is_from_pool) {
414+
dma_pool_free(g_dma_pool, pagelistinfo->pagelist,
415+
pagelistinfo->dma_addr);
416+
} else {
417+
dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
418+
pagelistinfo->pagelist,
419+
pagelistinfo->dma_addr);
420+
}
403421
}
404422

405423
/* There is a potential problem with partial cache lines (pages?)
@@ -419,6 +437,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
419437
u32 *addrs;
420438
unsigned int num_pages, offset, i, k;
421439
int actual_pages;
440+
bool is_from_pool;
422441
size_t pagelist_size;
423442
struct scatterlist *scatterlist, *sg;
424443
int dma_buffers;
@@ -445,10 +464,16 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
445464
/* Allocate enough storage to hold the page pointers and the page
446465
* list
447466
*/
448-
pagelist = dma_zalloc_coherent(g_dev,
449-
pagelist_size,
450-
&dma_addr,
451-
GFP_KERNEL);
467+
if (pagelist_size > VCHIQ_DMA_POOL_SIZE) {
468+
pagelist = dma_zalloc_coherent(g_dev,
469+
pagelist_size,
470+
&dma_addr,
471+
GFP_KERNEL);
472+
is_from_pool = false;
473+
} else {
474+
pagelist = dma_pool_zalloc(g_dma_pool, GFP_KERNEL, &dma_addr);
475+
is_from_pool = true;
476+
}
452477

453478
vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist);
454479

@@ -469,6 +494,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
469494
pagelistinfo->pagelist = pagelist;
470495
pagelistinfo->pagelist_buffer_size = pagelist_size;
471496
pagelistinfo->dma_addr = dma_addr;
497+
pagelistinfo->is_from_pool = is_from_pool;
472498
pagelistinfo->dma_dir = (type == PAGELIST_WRITE) ?
473499
DMA_TO_DEVICE : DMA_FROM_DEVICE;
474500
pagelistinfo->num_pages = num_pages;

0 commit comments

Comments
 (0)