From patchwork Fri Jan 29 09:44:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 8161211 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B5F539F96D for ; Fri, 29 Jan 2016 09:44:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BD5AE20375 for ; Fri, 29 Jan 2016 09:44:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BAEEA20374 for ; Fri, 29 Jan 2016 09:44:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752995AbcA2Jom (ORCPT ); Fri, 29 Jan 2016 04:44:42 -0500 Received: from pandora.arm.linux.org.uk ([78.32.30.218]:44218 "EHLO pandora.arm.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752835AbcA2Jok (ORCPT ); Fri, 29 Jan 2016 04:44:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=4J/w/P7CVxziv7v5jc6UX0m0cWEgzvb0RqVklAmRnAg=; b=MW/hh2UciCkodoBVEa24mZPWhxmclm2KmOV2XK949mYBW0DUlvLVpx8NCeV8CTU4jc8rGnMHrDtaVYFatUyLZBh0CxCHjkx6I8rBQAoBKWbbWbxuq7SGj+zv7IjByXd/krKaeL+sh1hBVWAdYAoxQMNnpOdR9/lc7LjFsNISFuc=; Received: from e0022681537dd.dyn.arm.linux.org.uk ([2002:4e20:1eda:1:222:68ff:fe15:37dd]:55999 helo=rmk-PC.arm.linux.org.uk) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1aP5bU-0001jP-Ru; Fri, 29 Jan 2016 09:44:33 +0000 Received: from rmk by rmk-PC.arm.linux.org.uk with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1aP5bO-0001pJ-B1; Fri, 29 Jan 2016 09:44:26 +0000 In-Reply-To: <20160129094324.GA20025@n2100.arm.linux.org.uk> References: <20160129094324.GA20025@n2100.arm.linux.org.uk> From: Russell King To: Ulf Hansson Cc: Gregory CLEMENT , linux-mmc@vger.kernel.org, Marcin Wojtas , Shawn Guo , Sascha Hauer Subject: [PATCH v4 08/25] mmc: sdhci: avoid unnecessary mapping/unmapping of align buffer MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Fri, 29 Jan 2016 09:44:26 +0000 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Russell King --- drivers/mmc/host/sdhci.c | 54 ++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 5f22b842cf25..b0655990defd 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 & SDHCI_ADMA2_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; @@ -570,22 +557,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, @@ -605,9 +577,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) @@ -2983,14 +2952,21 @@ int sdhci_add_host(struct sdhci_host *host) &host->adma_addr, GFP_KERNEL); host->align_buffer_sz = SDHCI_MAX_SEGS * SDHCI_ADMA2_ALIGN; - host->align_buffer = kmalloc(host->align_buffer_sz, GFP_KERNEL); + host->align_buffer = dma_alloc_coherent(mmc_dev(mmc), + host->align_buffer_sz, + &host->align_addr, + GFP_KERNEL); if (!host->adma_table || !host->align_buffer) { 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); pr_warn("%s: Unable to allocate ADMA buffers - falling back to standard DMA\n", mmc_hostname(mmc)); host->flags &= ~SDHCI_USE_ADMA; @@ -3002,10 +2978,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 & SDHCI_ADMA2_MASK); } /* @@ -3469,7 +3449,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;