Skip to content

Commit 5de92b8

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 eaca4a5 commit 5de92b8

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>
@@ -59,6 +60,8 @@
5960
#define BELL0 0x00
6061
#define BELL2 0x08
6162

63+
#define VCHIQ_DMA_POOL_SIZE PAGE_SIZE
64+
6265
struct vchiq_2835_state {
6366
int inited;
6467
VCHIQ_ARM_STATE_T arm_state;
@@ -68,6 +71,7 @@ struct vchiq_pagelist_info {
6871
PAGELIST_T *pagelist;
6972
size_t pagelist_buffer_size;
7073
dma_addr_t dma_addr;
74+
bool is_from_pool;
7175
enum dma_data_direction dma_dir;
7276
unsigned int num_pages;
7377
unsigned int pages_need_release;
@@ -88,6 +92,7 @@ static void __iomem *g_regs;
8892
* of 32.
8993
*/
9094
static unsigned int g_cache_line_size = 32;
95+
static struct dma_pool *g_dma_pool;
9196
static unsigned int g_fragments_size;
9297
static char *g_fragments_base;
9398
static char *g_free_fragments;
@@ -194,6 +199,14 @@ int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state)
194199
}
195200

196201
g_dev = dev;
202+
g_dma_pool = dmam_pool_create("vchiq_scatter_pool", dev,
203+
VCHIQ_DMA_POOL_SIZE, g_cache_line_size,
204+
0);
205+
if (!g_dma_pool) {
206+
dev_err(dev, "failed to create dma pool");
207+
return -ENOMEM;
208+
}
209+
197210
vchiq_log_info(vchiq_arm_log_level,
198211
"vchiq_init - done (slots %pK, phys %pad)",
199212
vchiq_slot_zero, &slot_phys);
@@ -382,9 +395,14 @@ cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo)
382395
for (i = 0; i < pagelistinfo->num_pages; i++)
383396
put_page(pagelistinfo->pages[i]);
384397
}
385-
386-
dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
387-
pagelistinfo->pagelist, pagelistinfo->dma_addr);
398+
if (pagelistinfo->is_from_pool) {
399+
dma_pool_free(g_dma_pool, pagelistinfo->pagelist,
400+
pagelistinfo->dma_addr);
401+
} else {
402+
dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
403+
pagelistinfo->pagelist,
404+
pagelistinfo->dma_addr);
405+
}
388406
}
389407

390408
/* There is a potential problem with partial cache lines (pages?)
@@ -404,6 +422,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
404422
u32 *addrs;
405423
unsigned int num_pages, offset, i, k;
406424
int actual_pages;
425+
bool is_from_pool;
407426
size_t pagelist_size;
408427
struct scatterlist *scatterlist, *sg;
409428
int dma_buffers;
@@ -421,10 +440,16 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
421440
/* Allocate enough storage to hold the page pointers and the page
422441
* list
423442
*/
424-
pagelist = dma_zalloc_coherent(g_dev,
425-
pagelist_size,
426-
&dma_addr,
427-
GFP_KERNEL);
443+
if (pagelist_size > VCHIQ_DMA_POOL_SIZE) {
444+
pagelist = dma_zalloc_coherent(g_dev,
445+
pagelist_size,
446+
&dma_addr,
447+
GFP_KERNEL);
448+
is_from_pool = false;
449+
} else {
450+
pagelist = dma_pool_zalloc(g_dma_pool, GFP_KERNEL, &dma_addr);
451+
is_from_pool = true;
452+
}
428453

429454
vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist);
430455

@@ -445,6 +470,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
445470
pagelistinfo->pagelist = pagelist;
446471
pagelistinfo->pagelist_buffer_size = pagelist_size;
447472
pagelistinfo->dma_addr = dma_addr;
473+
pagelistinfo->is_from_pool = is_from_pool;
448474
pagelistinfo->dma_dir = (type == PAGELIST_WRITE) ?
449475
DMA_TO_DEVICE : DMA_FROM_DEVICE;
450476
pagelistinfo->num_pages = num_pages;

0 commit comments

Comments
 (0)