From: Maarten Vanraes <maarten@rmail.be>
To: Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>,
linux-media@vger.kernel.org
Cc: Kieran Bingham <kbingham@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Umang Jain <umang.jain@ideasonboard.com>,
detule <ogjoneski@gmail.com>, Maarten Vanraes <maarten@rmail.be>
Subject: [RFC PATCH 06/13] staging: vchiq_arm: Usa a DMA pool for small bulks
Date: Sun, 3 Mar 2024 16:10:01 +0100 [thread overview]
Message-ID: <20240303152635.2762696-7-maarten@rmail.be> (raw)
In-Reply-To: <20240303152635.2762696-1-maarten@rmail.be>
From: detule <ogjoneski@gmail.com>
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 <ogjoneski@gmail.com>
Signed-off-by: Maarten Vanraes <maarten@rmail.be>
---
.../interface/vchiq_arm/vchiq_arm.c | 33 ++++++++++++++++---
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index e306f420d767..eb15aa011a22 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -24,6 +24,7 @@
#include <linux/platform_device.h>
#include <linux/compat.h>
#include <linux/dma-mapping.h>
+#include <linux/dmapool.h>
#include <linux/rcupdate.h>
#include <linux/delay.h>
#include <linux/slab.h>
@@ -54,6 +55,8 @@
#define ARM_DS_ACTIVE BIT(2)
+#define VCHIQ_DMA_POOL_SIZE PAGE_SIZE
+
/* Override the default prefix, which would be vchiq_arm (from the filename) */
#undef MODULE_PARAM_PREFIX
#define MODULE_PARAM_PREFIX DEVICE_NAME "."
@@ -136,6 +139,7 @@ struct vchiq_pagelist_info {
struct pagelist *pagelist;
size_t pagelist_buffer_size;
dma_addr_t dma_addr;
+ bool is_from_pool;
enum dma_data_direction dma_dir;
unsigned int num_pages;
unsigned int pages_need_release;
@@ -156,6 +160,7 @@ static void __iomem *g_regs;
* of 32.
*/
static unsigned int g_cache_line_size = 32;
+static struct dma_pool *g_dma_pool;
static unsigned int g_use_36bit_addrs = 0;
static unsigned int g_fragments_size;
static char *g_fragments_base;
@@ -198,8 +203,13 @@ cleanup_pagelistinfo(struct vchiq_instance *instance, struct vchiq_pagelist_info
if (pagelistinfo->pages_need_release)
unpin_user_pages(pagelistinfo->pages, pagelistinfo->num_pages);
- dma_free_coherent(instance->state->dev, pagelistinfo->pagelist_buffer_size,
- pagelistinfo->pagelist, pagelistinfo->dma_addr);
+ if (pagelistinfo->is_from_pool) {
+ dma_pool_free(g_dma_pool, pagelistinfo->pagelist,
+ pagelistinfo->dma_addr);
+ } else {
+ dma_free_coherent(instance->state->dev, pagelistinfo->pagelist_buffer_size,
+ pagelistinfo->pagelist, pagelistinfo->dma_addr);
+ }
}
static inline bool
@@ -234,6 +244,7 @@ create_pagelist(struct vchiq_instance *instance, char *buf, char __user *ubuf,
u32 *addrs;
unsigned int num_pages, offset, i, k;
int actual_pages;
+ bool is_from_pool;
size_t pagelist_size;
struct scatterlist *scatterlist, *sg;
int dma_buffers;
@@ -263,8 +274,14 @@ create_pagelist(struct vchiq_instance *instance, char *buf, char __user *ubuf,
/* Allocate enough storage to hold the page pointers and the page
* list
*/
- pagelist = dma_alloc_coherent(instance->state->dev, pagelist_size, &dma_addr,
- GFP_KERNEL);
+ if (pagelist_size > VCHIQ_DMA_POOL_SIZE) {
+ pagelist = dma_alloc_coherent(instance->state->dev, pagelist_size, &dma_addr,
+ GFP_KERNEL);
+ is_from_pool = false;
+ } else {
+ pagelist = dma_pool_alloc(g_dma_pool, GFP_KERNEL, &dma_addr);
+ is_from_pool = true;
+ }
dev_dbg(instance->state->dev, "arm: %pK\n", pagelist);
@@ -285,6 +302,7 @@ create_pagelist(struct vchiq_instance *instance, char *buf, char __user *ubuf,
pagelistinfo->pagelist = pagelist;
pagelistinfo->pagelist_buffer_size = pagelist_size;
pagelistinfo->dma_addr = dma_addr;
+ pagelistinfo->is_from_pool = is_from_pool;
pagelistinfo->dma_dir = (type == PAGELIST_WRITE) ?
DMA_TO_DEVICE : DMA_FROM_DEVICE;
pagelistinfo->num_pages = num_pages;
@@ -625,6 +643,13 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state
dev_dbg(&pdev->dev, "arm: vchiq_init - done (slots %pK, phys %pad)\n",
vchiq_slot_zero, &slot_phys);
g_dma_dev = dma_dev ?: dev;
+ g_dma_pool = dmam_pool_create("vchiq_scatter_pool", dev,
+ VCHIQ_DMA_POOL_SIZE, g_cache_line_size,
+ 0);
+ if (!g_dma_pool) {
+ dev_err(dev, "failed to create dma pool");
+ return -ENOMEM;
+ }
vchiq_call_connected_callbacks();
--
2.41.0
next prev parent reply other threads:[~2024-03-03 15:27 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-03 15:09 [RFC PATCH 00/13] bcm2835-codec: driver for HW codecs Maarten Vanraes
2024-03-03 15:09 ` [RFC PATCH 01/13] staging: mmal-vchiq: Avoid use of bool in structures Maarten Vanraes
2024-03-04 7:30 ` Andrzej Pietrasiewicz
2024-03-05 18:00 ` Maarten
2024-03-03 15:09 ` [RFC PATCH 02/13] staging: mmal-vchiq: Update mmal_parameters.h with recently defined params Maarten Vanraes
2024-03-03 15:09 ` [RFC PATCH 03/13] staging: mmal-vchiq: Fix memory leak in error path Maarten Vanraes
2024-03-04 7:38 ` Andrzej Pietrasiewicz
2024-03-05 18:02 ` Maarten
2024-03-03 15:09 ` [RFC PATCH 04/13] media: videodev2.h: Add a format for column YUV4:2:0 modes Maarten Vanraes
2024-03-04 18:10 ` Nicolas Dufresne
2024-03-05 18:14 ` Maarten
2024-03-06 20:46 ` Nicolas Dufresne
2024-03-05 18:53 ` Dave Stevenson
2024-03-05 19:43 ` Maarten
2024-03-10 12:42 ` Maarten
2024-03-10 12:54 ` Maarten
2024-03-03 15:10 ` [RFC PATCH 05/13] staging: vchiq_arm: Add 36-bit address support Maarten Vanraes
2024-03-07 10:19 ` Krzysztof Kozlowski
2024-03-07 10:23 ` Maarten
2024-03-03 15:10 ` Maarten Vanraes [this message]
2024-03-03 15:10 ` [RFC PATCH 07/13] staging/vchiq-mmal: Add buffer flags for interlaced video Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 08/13] staging/vchiq-mmal: Add parameters for interlaced video support Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 09/13] staging/vchiq-mmal: Add the deinterlace image effects enums Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 10/13] staging/mmal-vchiq: Rationalise included headers Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 11/13] staging: mmal-vchiq: Reset buffers_with_vpu on port_enable Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 12/13] vc04_services: vchiq-mmal: Add defines for mmal_es_format flags Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 13/13] staging: vc04_services: Add a V4L2 M2M codec driver Maarten Vanraes
2024-03-04 17:58 ` Nicolas Dufresne
2024-03-05 19:35 ` Maarten
2024-03-06 21:14 ` Nicolas Dufresne
2024-03-24 12:35 ` Maarten
2024-04-01 9:45 ` Maarten
2024-04-01 9:56 ` Maarten
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240303152635.2762696-7-maarten@rmail.be \
--to=maarten@rmail.be \
--cc=kbingham@kernel.org \
--cc=kernel-list@raspberrypi.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=ogjoneski@gmail.com \
--cc=umang.jain@ideasonboard.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).