DMA Engine development
 help / color / mirror / Atom feed
From: Vinod Koul <vkoul@kernel.org>
To: Dave Jiang <dave.jiang@intel.com>
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	dan.j.williams@intel.com, tony.luck@intel.com,
	jing.lin@intel.com, ashok.raj@intel.com,
	sanjay.k.kumar@intel.com, megha.dey@intel.com,
	jacob.jun.pan@intel.com, yi.l.liu@intel.com, axboe@kernel.dk,
	akpm@linux-foundation.org, tglx@linutronix.de, mingo@redhat.com,
	bp@alien8.de, fenghua.yu@intel.com, hpa@zytor.com
Subject: Re: [PATCH RFC v3 05/14] dmaengine: add dma_request support functions
Date: Fri, 27 Dec 2019 11:16:45 +0530	[thread overview]
Message-ID: <20191227054645.GC3006@vkoul-mobl> (raw)
In-Reply-To: <157662560983.51652.13439786918385685865.stgit@djiang5-desk3.ch.intel.com>

On 17-12-19, 16:33, Dave Jiang wrote:
> In order to provide a lockless submission path, the request context needs
> to be pre-allocated rather than pulling from a memory pool.
> Use the common request allocation call request_from_pages_alloc() to
> accomplish this. The sbitmap code will be used to get the next
> free request context. This is a simplified version of what blk-mq does
> (not sbitmap_queue). The config option DMA_ENGINE_REQUEST is added so that
> only drivers that supports dma request would enable the code.

Can you give more context on this requirement of lockless submission
path? I see this and next patch are adding another set of dma APIs, so
we need a good justification, documentation and why this cant be added
to existing code :)

> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  drivers/dma/Kconfig       |    6 +++
>  drivers/dma/Makefile      |    1 
>  drivers/dma/dma-request.c |   96 +++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/dmaengine.h |   57 +++++++++++++++++++++++++++
>  4 files changed, 160 insertions(+)
>  create mode 100644 drivers/dma/dma-request.c
> 
> diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
> index 6fa1eba9d477..52a3c2086dcb 100644
> --- a/drivers/dma/Kconfig
> +++ b/drivers/dma/Kconfig
> @@ -56,6 +56,12 @@ config DMA_OF
>  	depends on OF
>  	select DMA_ENGINE
>  
> +config DMA_ENGINE_REQUEST
> +	def_bool n
> +	depends on DMA_ENGINE
> +	select SBITMAP
> +	select CONTEXT_ALLOC
> +
>  #devices
>  config ALTERA_MSGDMA
>  	tristate "Altera / Intel mSGDMA Engine"
> diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
> index 42d7e2fc64fa..f80720075399 100644
> --- a/drivers/dma/Makefile
> +++ b/drivers/dma/Makefile
> @@ -8,6 +8,7 @@ obj-$(CONFIG_DMA_ENGINE) += dmaengine.o
>  obj-$(CONFIG_DMA_VIRTUAL_CHANNELS) += virt-dma.o
>  obj-$(CONFIG_DMA_ACPI) += acpi-dma.o
>  obj-$(CONFIG_DMA_OF) += of-dma.o
> +obj-$(CONFIG_DMA_ENGINE_REQUEST) += dma-request.o
>  
>  #dmatest
>  obj-$(CONFIG_DMATEST) += dmatest.o
> diff --git a/drivers/dma/dma-request.c b/drivers/dma/dma-request.c
> new file mode 100644
> index 000000000000..43462fadf777
> --- /dev/null
> +++ b/drivers/dma/dma-request.c
> @@ -0,0 +1,96 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/* Copyright(c) 2019 Intel Corporation. All rights reserved.  */
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/mm.h>
> +#include <linux/device.h>
> +#include <linux/dmaengine.h>
> +#include <linux/mempool.h>
> +
> +struct dma_request *dma_chan_alloc_request(struct dma_chan *chan)
> +{
> +	int nr;
> +	struct dma_request *req;
> +
> +	nr = sbitmap_get(&chan->sbmap, 0, false);
> +	if (nr < 0)
> +		return NULL;
> +
> +	req = chan->rqs[nr];
> +	req->rq_private = NULL;
> +	req->callback = NULL;
> +	memset(&req->result, 0, sizeof(struct dmaengine_result));
> +	return req;
> +}
> +EXPORT_SYMBOL_GPL(dma_chan_alloc_request);
> +
> +void dma_chan_free_request(struct dma_chan *chan, struct dma_request *rq)
> +{
> +	sbitmap_clear_bit(&chan->sbmap, rq->id);
> +}
> +EXPORT_SYMBOL_GPL(dma_chan_free_request);
> +
> +void dma_chan_free_request_resources(struct dma_chan *chan)
> +{
> +	context_free_from_pages(&chan->page_list);
> +	kfree(chan->rqs);
> +}
> +EXPORT_SYMBOL_GPL(dma_chan_free_request_resources);
> +
> +static void dma_chan_assign_request(void *ctx, void *ptr, int idx)
> +{
> +	struct dma_chan *chan = (struct dma_chan *)ctx;
> +	struct dma_request *rq = ptr;
> +
> +	chan->rqs[idx] = rq;
> +}
> +
> +int dma_chan_alloc_request_resources(struct dma_chan *chan)
> +{
> +	int i, node, rc, id = 0;
> +	size_t rq_size;
> +
> +	/* Requests are already allocated */
> +	if (chan->rqs)
> +		return 0;
> +
> +	node = dev_to_node(chan->device->dev);
> +	rc = sbitmap_init_node(&chan->sbmap, chan->depth, -1,
> +			       GFP_KERNEL, node);
> +	if (rc < 0)
> +		return rc;
> +
> +	chan->rqs = kcalloc_node(chan->depth, sizeof(struct dma_request *),
> +				 GFP_KERNEL, node);
> +	if (!chan->rqs) {
> +		rc = -ENOMEM;
> +		goto fail;
> +	}
> +
> +	INIT_LIST_HEAD(&chan->page_list);
> +
> +	rq_size = round_up(sizeof(struct dma_request) +
> +			chan->max_sgs * sizeof(struct scatterlist),
> +			cache_line_size());
> +
> +	rc = context_alloc_from_pages((void *)chan, chan->depth, rq_size,
> +				      &chan->page_list, 4, node,
> +				      dma_chan_assign_request);
> +	if (rc < 0)
> +		goto fail;
> +
> +	for (i = 0; i < rc; i++) {
> +		struct dma_request *rq = chan->rqs[i];
> +
> +		rq->id = id++;
> +		rq->chan = chan;
> +	}
> +
> +	return 0;
> +
> + fail:
> +	sbitmap_free(&chan->sbmap);
> +	dma_chan_free_request_resources(chan);
> +	return rc;
> +}
> +EXPORT_SYMBOL_GPL(dma_chan_alloc_request_resources);
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index 0202d44a17a5..7bc8c3f8283f 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -12,6 +12,8 @@
>  #include <linux/scatterlist.h>
>  #include <linux/bitmap.h>
>  #include <linux/types.h>
> +#include <linux/sbitmap.h>
> +#include <linux/bvec.h>
>  #include <asm/page.h>
>  
>  /**
> @@ -176,6 +178,8 @@ struct dma_interleaved_template {
>   * @DMA_PREP_CMD: tell the driver that the data passed to DMA API is command
>   *  data and the descriptor should be in different format from normal
>   *  data descriptors.
> + *  @DMA_SUBMIT_NONBLOCK: tell the driver do not wait for resources if submit
> + *  is not possible.
>   */
>  enum dma_ctrl_flags {
>  	DMA_PREP_INTERRUPT = (1 << 0),
> @@ -186,6 +190,7 @@ enum dma_ctrl_flags {
>  	DMA_PREP_FENCE = (1 << 5),
>  	DMA_CTRL_REUSE = (1 << 6),
>  	DMA_PREP_CMD = (1 << 7),
> +	DMA_SUBMIT_NONBLOCK = (1 << 8),
>  };
>  
>  /**
> @@ -268,6 +273,13 @@ struct dma_chan {
>  	struct dma_router *router;
>  	void *route_data;
>  
> +	/* DMA request */
> +	int max_sgs;
> +	int depth;
> +	struct sbitmap sbmap;
> +	struct dma_request **rqs;
> +	struct list_head page_list;
> +
>  	void *private;
>  };
>  
> @@ -511,6 +523,25 @@ struct dma_async_tx_descriptor {
>  #endif
>  };
>  
> +struct dma_request {
> +	int id;
> +	struct dma_chan *chan;
> +	enum dma_transaction_type cmd;
> +	enum dma_ctrl_flags flags;
> +	struct bio_vec bvec;
> +	dma_addr_t pg_dma;
> +	int sg_nents;
> +	void *rq_private;
> +
> +	/* Set by driver */
> +	dma_async_tx_callback_result callback;
> +	struct dmaengine_result result;
> +	void *callback_param;
> +
> +	/* Leave as last member for flexible array of scatterlist */
> +	struct scatterlist sg[];
> +};
> +
>  #ifdef CONFIG_DMA_ENGINE
>  static inline void dma_set_unmap(struct dma_async_tx_descriptor *tx,
>  				 struct dmaengine_unmap_data *unmap)
> @@ -1359,6 +1390,32 @@ static inline int dma_get_slave_caps(struct dma_chan *chan,
>  }
>  #endif
>  
> +#ifdef CONFIG_DMA_ENGINE_REQUEST
> +struct dma_request *dma_chan_alloc_request(struct dma_chan *chan);
> +void dma_chan_free_request(struct dma_chan *chan, struct dma_request *rq);
> +void dma_chan_free_request_resources(struct dma_chan *chan);
> +int dma_chan_alloc_request_resources(struct dma_chan *chan);
> +#else
> +static inline struct dma_request *dma_chan_alloc_request(struct dma_chan *chan)
> +{
> +	return NULL;
> +}
> +
> +static inline void dma_chan_free_request(struct dma_chan *chan,
> +					 struct dma_request *rq)
> +{
> +}
> +
> +static inline void dma_chan_free_request_resources(struct dma_chan *chan)
> +{
> +}
> +
> +static inline int dma_chan_alloc_request_resources(struct dma_chan *chan)
> +{
> +	return -EOPNOTSUPP;
> +}
> +#endif
> +
>  #define dma_request_slave_channel_reason(dev, name) dma_request_chan(dev, name)
>  
>  static inline int dmaengine_desc_set_reuse(struct dma_async_tx_descriptor *tx)

-- 
~Vinod

  reply	other threads:[~2019-12-27  5:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-17 23:32 [PATCH RFC v3 00/14] idxd driver for Intel Data Streaming Accelerator Dave Jiang
2019-12-17 23:33 ` [PATCH RFC v3 01/14] x86/asm: add iosubmit_cmds512() based on movdir64b CPU instruction Dave Jiang
2020-01-04 14:18   ` Borislav Petkov
2019-12-17 23:33 ` [PATCH RFC v3 02/14] dmaengine: break out channel registration Dave Jiang
2019-12-17 23:33 ` [PATCH RFC v3 03/14] dmaengine: add new dma device registration Dave Jiang
2019-12-17 23:33 ` [PATCH RFC v3 04/14] mm: create common code from request allocation based from blk-mq code Dave Jiang
2019-12-17 23:33 ` [PATCH RFC v3 05/14] dmaengine: add dma_request support functions Dave Jiang
2019-12-27  5:46   ` Vinod Koul [this message]
2019-12-17 23:33 ` [PATCH RFC v3 06/14] dmaengine: add dma request submit and completion path support Dave Jiang
2019-12-17 23:33 ` [PATCH RFC v3 07/14] dmaengine: update dmatest to support dma request Dave Jiang
2019-12-17 23:33 ` [PATCH RFC v3 08/14] dmaengine: idxd: Init and probe for Intel data accelerators Dave Jiang
2019-12-17 23:33 ` [PATCH RFC v3 09/14] dmaengine: idxd: add configuration component of driver Dave Jiang
2019-12-27  5:50   ` Vinod Koul
2019-12-28 15:20     ` Jiang, Dave
2019-12-17 23:34 ` [PATCH RFC v3 10/14] dmaengine: idxd: add descriptor manipulation routines Dave Jiang
2019-12-17 23:34 ` [PATCH RFC v3 11/14] dmaengine: idxd: connect idxd to dmaengine subsystem Dave Jiang
2019-12-17 23:34 ` [PATCH RFC v3 12/14] dmaengine: request submit optimization Dave Jiang
2019-12-17 23:34 ` [PATCH RFC v3 13/14] dmaengine: idxd: add char driver to expose submission portal to userland Dave Jiang
2019-12-27  5:58   ` Vinod Koul
2020-01-07 17:45     ` Dave Jiang
2020-01-07 18:17       ` Dave Jiang
2020-01-07 20:18         ` Dave Jiang
2020-01-10  7:59           ` Vinod Koul
2019-12-17 23:34 ` [PATCH RFC v3 14/14] dmaengine: idxd: add sysfs ABI for idxd driver Dave Jiang

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=20191227054645.GC3006@vkoul-mobl \
    --to=vkoul@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ashok.raj@intel.com \
    --cc=axboe@kernel.dk \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=jacob.jun.pan@intel.com \
    --cc=jing.lin@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=megha.dey@intel.com \
    --cc=mingo@redhat.com \
    --cc=sanjay.k.kumar@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=yi.l.liu@intel.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