linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Russell King <rmk+kernel@arm.linux.org.uk>,
	Ulf Hansson <ulf.hansson@linaro.org>
Cc: Marcin Wojtas <mw@semihalf.com>,
	Gregory CLEMENT <gregory.clement@free-electrons.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <kernel@pengutronix.de>,
	linux-mmc@vger.kernel.org
Subject: Re: [PATCH v2 08/24] mmc: sdhci: avoid unnecessary mapping/unmapping of align buffer
Date: Tue, 29 Dec 2015 15:44:38 +0200	[thread overview]
Message-ID: <56828E46.5090600@intel.com> (raw)
In-Reply-To: <E1aAypq-00016e-Lv@rmk-PC.arm.linux.org.uk>

On 21/12/15 13:41, Russell King wrote:
> Unnecessarily mapping and unmapping the align buffer for SD cards is
> expensive: performance measurements on iMX6 show that this gives a hit
> of 10% on hdparm buffered disk reads.
> 
> MMC/SD card IO comes from the mm/vfs which gives us page based IO, so
> for this case, the align buffer is not going to be used.  However, we
> still map and unmap this buffer.
> 
> Eliminate this by switching the align buffer to be a DMA coherent
> buffer, which needs no DMA maintenance to access the buffer.

Did you consider putting the align buffer in the same allocation
as the adma_table?

> 
> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
> ---
>  drivers/mmc/host/sdhci.c | 53 ++++++++++++++++--------------------------------
>  1 file changed, 18 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 3e718e465a1b..8a4eb1c41f3e 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -465,8 +465,6 @@ static void sdhci_adma_mark_end(void *desc)
>  static int sdhci_adma_table_pre(struct sdhci_host *host,
>  	struct mmc_data *data)
>  {
> -	int direction;
> -
>  	void *desc;
>  	void *align;
>  	dma_addr_t addr;
> @@ -483,20 +481,9 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
>  	 * We currently guess that it is LE.
>  	 */
>  
> -	if (data->flags & MMC_DATA_READ)
> -		direction = DMA_FROM_DEVICE;
> -	else
> -		direction = DMA_TO_DEVICE;
> -
> -	host->align_addr = dma_map_single(mmc_dev(host->mmc),
> -		host->align_buffer, host->align_buffer_sz, direction);
> -	if (dma_mapping_error(mmc_dev(host->mmc), host->align_addr))
> -		goto fail;
> -	BUG_ON(host->align_addr & host->align_mask);
> -
>  	host->sg_count = sdhci_pre_dma_transfer(host, data);
>  	if (host->sg_count < 0)
> -		goto unmap_align;
> +		return -EINVAL;
>  
>  	desc = host->adma_table;
>  	align = host->align_buffer;
> @@ -567,22 +554,7 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
>  		/* nop, end, valid */
>  		sdhci_adma_write_desc(host, desc, 0, 0, ADMA2_NOP_END_VALID);
>  	}
> -
> -	/*
> -	 * Resync align buffer as we might have changed it.
> -	 */
> -	if (data->flags & MMC_DATA_WRITE) {
> -		dma_sync_single_for_device(mmc_dev(host->mmc),
> -			host->align_addr, host->align_buffer_sz, direction);
> -	}
> -
>  	return 0;
> -
> -unmap_align:
> -	dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
> -		host->align_buffer_sz, direction);
> -fail:
> -	return -EINVAL;
>  }
>  
>  static void sdhci_adma_table_post(struct sdhci_host *host,
> @@ -602,9 +574,6 @@ static void sdhci_adma_table_post(struct sdhci_host *host,
>  	else
>  		direction = DMA_TO_DEVICE;
>  
> -	dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
> -		host->align_buffer_sz, direction);
> -
>  	/* Do a quick scan of the SG list for any unaligned mappings */
>  	has_unaligned = false;
>  	for_each_sg(data->sg, sg, host->sg_count, i)
> @@ -3003,6 +2972,10 @@ int sdhci_add_host(struct sdhci_host *host)
>  						      host->adma_table_sz,
>  						      &host->adma_addr,
>  						      GFP_KERNEL);
> +		host->align_buffer = dma_alloc_coherent(mmc_dev(mmc),
> +							host->align_buffer_sz,
> +							&host->align_addr,
> +							GFP_KERNEL);
>  		host->align_buffer = kmalloc(host->align_buffer_sz, GFP_KERNEL);

kmalloc line is still there

>  		if (!host->adma_table || !host->align_buffer) {
>  			if (host->adma_table)
> @@ -3010,7 +2983,11 @@ int sdhci_add_host(struct sdhci_host *host)
>  						  host->adma_table_sz,
>  						  host->adma_table,
>  						  host->adma_addr);
> -			kfree(host->align_buffer);
> +			if (host->align_buffer)
> +				dma_free_coherent(mmc_dev(mmc),
> +						  host->align_buffer_sz,
> +						  host->align_buffer,
> +						  host->align_addr);
>  			pr_warn("%s: Unable to allocate ADMA buffers - falling back to standard DMA\n",
>  				mmc_hostname(mmc));
>  			host->flags &= ~SDHCI_USE_ADMA;
> @@ -3022,10 +2999,14 @@ int sdhci_add_host(struct sdhci_host *host)
>  			host->flags &= ~SDHCI_USE_ADMA;
>  			dma_free_coherent(mmc_dev(mmc), host->adma_table_sz,
>  					  host->adma_table, host->adma_addr);
> -			kfree(host->align_buffer);
> +			dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz,
> +					  host->align_buffer, host->align_addr);
>  			host->adma_table = NULL;
>  			host->align_buffer = NULL;
>  		}
> +
> +		/* dma_alloc_coherent returns page aligned and sized buffers */
> +		BUG_ON(host->align_addr & host->align_mask);

It would be nicer not to have any BUG_ON()

>  	}
>  
>  	/*
> @@ -3489,7 +3470,9 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
>  	if (host->adma_table)
>  		dma_free_coherent(mmc_dev(mmc), host->adma_table_sz,
>  				  host->adma_table, host->adma_addr);
> -	kfree(host->align_buffer);
> +	if (host->align_buffer)
> +		dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz,
> +				  host->align_buffer, host->align_addr);
>  
>  	host->adma_table = NULL;
>  	host->align_buffer = NULL;
> 


  reply	other threads:[~2015-12-29 13:47 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-21 11:39 [PATCH v2 00/24] MMC/SDHCI fixes Russell King - ARM Linux
2015-12-21 11:40 ` [PATCH v2 01/24] mmc: core: shut up "voltage-ranges unspecified" pr_info() Russell King
2015-12-21 11:40 ` [PATCH v2 02/24] mmc: core: improve mmc_of_parse_voltage() to return better status Russell King
2015-12-21 11:40 ` [PATCH v2 03/24] mmc: block: shut up "retrying because a re-tune was needed" message Russell King
2015-12-21 11:40 ` [PATCH v2 04/24] mmc: core: report tuning command execution failure reason Russell King
2015-12-21 11:40 ` [PATCH v2 05/24] mmc: sdhci: move initialisation of command error member Russell King
2015-12-21 11:40 ` [PATCH v2 06/24] mmc: sdhci: clean up command error handling Russell King
2015-12-21 11:40 ` [PATCH v2 07/24] mmc: sdhci: command response CRC " Russell King
2015-12-29 13:08   ` Adrian Hunter
2016-01-02 12:25     ` Russell King - ARM Linux
2016-01-04 11:24       ` Adrian Hunter
2016-01-26 13:35         ` Russell King - ARM Linux
2015-12-21 11:41 ` [PATCH v2 08/24] mmc: sdhci: avoid unnecessary mapping/unmapping of align buffer Russell King
2015-12-29 13:44   ` Adrian Hunter [this message]
2016-01-02 12:29     ` Russell King - ARM Linux
2016-01-02 14:31       ` Russell King - ARM Linux
2016-01-04 11:41         ` Adrian Hunter
2016-01-04 11:50       ` Adrian Hunter
2016-01-04 11:56         ` Russell King - ARM Linux
2015-12-21 11:41 ` [PATCH v2 09/24] mmc: sdhci: clean up coding style in sdhci_adma_table_pre() Russell King
2015-12-21 11:41 ` [PATCH v2 10/24] mmc: sdhci: avoid walking SG list for writes Russell King
2015-12-21 11:41 ` [PATCH v2 11/24] mmc: sdhci: factor out common DMA cleanup in sdhci_finish_data() Russell King
2015-12-21 11:41 ` [PATCH v2 12/24] mmc: sdhci: move sdhci_pre_dma_transfer() Russell King
2015-12-21 11:41 ` [PATCH v2 13/24] mmc: sdhci: factor out sdhci_pre_dma_transfer() from sdhci_adma_table_pre() Russell King
2015-12-21 11:41 ` [PATCH v2 14/24] mmc: sdhci: pass the cookie into sdhci_pre_dma_transfer() Russell King
2015-12-21 11:41 ` [PATCH v2 15/24] mmc: sdhci: always unmap a mapped data transfer in sdhci_post_req() Russell King
2015-12-21 11:41 ` [PATCH v2 16/24] mmc: sdhci: clean up host cookie handling Russell King
2015-12-21 11:41 ` [PATCH v2 17/24] mmc: sdhci: plug DMA mapping leak on error Russell King
2015-12-21 11:41 ` [PATCH v2 18/24] mmc: sdhci-pxav3: fix higher speed mode capabilities Russell King
2015-12-21 11:54   ` Marcin Wojtas
2015-12-21 11:41 ` [PATCH v2 19/24] mmc: sdhci: further fix for DMA unmapping in sdhci_post_req() Russell King
2015-12-21 11:42 ` [PATCH v2 20/24] mmc: sdhci: fix data timeout (part 1) Russell King
2015-12-21 11:42 ` [PATCH v2 21/24] mmc: sdhci: fix data timeout (part 2) Russell King
2015-12-21 11:42 ` [PATCH v2 22/24] mmc: sdhci: prepare DMA address/size quirk handling consolidation Russell King
2015-12-21 11:42 ` [PATCH v2 23/24] mmc: sdhci: consolidate the DMA/ADMA size/address quicks Russell King
2015-12-21 11:42 ` [PATCH v2 24/24] mmc: sdhci: further code simplication Russell King
2015-12-21 12:35 ` [PATCH v2 00/24] MMC/SDHCI fixes Ulf Hansson
2015-12-21 12:51   ` Russell King - ARM Linux
2015-12-21 13:23     ` Ulf Hansson
2015-12-21 13:41       ` Russell King - ARM Linux
2015-12-21 13:59         ` Ulf Hansson
2015-12-22 11:25           ` Ulf Hansson
2015-12-22 11:40             ` Russell King - ARM Linux
2015-12-21 12:58 ` Russell King - ARM Linux

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=56828E46.5090600@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=gregory.clement@free-electrons.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-mmc@vger.kernel.org \
    --cc=mw@semihalf.com \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=shawnguo@kernel.org \
    --cc=ulf.hansson@linaro.org \
    /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).