From patchwork Fri May 3 09:12:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 2516331 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id 33F2D3FD1A for ; Fri, 3 May 2013 09:13:39 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UYC3d-0005Xm-IS; Fri, 03 May 2013 09:13:37 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UYC3a-0003Hg-Mn; Fri, 03 May 2013 09:13:34 +0000 Received: from mail-pd0-f172.google.com ([209.85.192.172]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UYC3V-0003GY-98 for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2013 09:13:31 +0000 Received: by mail-pd0-f172.google.com with SMTP id 5so824187pdd.31 for ; Fri, 03 May 2013 02:13:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=ZtDal1D1NYE3GurVHsT9DOy6LUwEanifPSdYNTC1jpk=; b=Dy+IaQS2PR8nDmrqa9SyjKsMSA/X+ZsFluj3nnuYEYZ8sk+jCAvnpj84GHv2S5tXO1 woPPOo0pTJGQte8KlpJz52LOv+PmBCWjrgp32pQPnsJtFarub+P3AVLTcVc7vvRe/JBa UGEMyGtI/VmKFoT6bLKai8ZkzNHrZEA5ZlVdHPW4DfAt73A4vzy+6cbMkX9o1GzgQ17x R6gF6d2zN8d/VgyaiRDEEvvATeEfRY8RkdLAH3vgrsWMTYuFw2uM/fG3w7IlZrMzHClR 38mL3FyWHaYdcNq8U9JLHWiVNUW2brJNtYGxnoz8HokslCeDuDZwplfnxNU6lskpZUR6 kGow== X-Received: by 10.68.202.104 with SMTP id kh8mr12859644pbc.74.1367572384432; Fri, 03 May 2013 02:13:04 -0700 (PDT) Received: from localhost ([183.37.199.50]) by mx.google.com with ESMTPSA id uf2sm10902336pbc.41.2013.05.03.02.13.00 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 03 May 2013 02:13:03 -0700 (PDT) From: Ming Lei To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] ARM: DMA-mapping: mark all !DMA_TO_DEVICE pages in unmapping as clean Date: Fri, 3 May 2013 17:12:45 +0800 Message-Id: <1367572365-18905-1-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130503_051329_386038_80BEAF50 X-CRM114-Status: GOOD ( 13.40 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.192.172 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (tom.leiming[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Nicolas Pitre , Catalin Marinas , Ming Lei , Russell King , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org It is common for one sg to include many pages, so mark all these pages as clean to avoid unnecessary flushing on them in set_pte_at() or update_mmu_cache(). The patch might improve loading performance of applciation code a bit. On the below test code to read file(~1GByte size) from usb mass storage disk to buffer created with mmap(PROT_READ | PROT_EXEC) on Pandaboard, average ~1% improvement can be observed with the patch on 10 times test. #define _GNU_SOURCE #include #include #include #include #include #include #include #include unsigned int sum = 0; static unsigned long tv_diff(struct timeval *tv1, struct timeval *tv2) { return (tv2->tv_sec - tv1->tv_sec) * 1000000 + (tv2->tv_usec - tv1->tv_usec); } int main(int argc, char *argv[]) { char *mbuffer; int fd; int i; unsigned long page_size, size; struct stat stat; struct timeval t1, t2; page_size = getpagesize(); fd = open(argv[1], O_RDONLY); assert(fd >= 0); fstat(fd, &stat); size = stat.st_size; printf("%s: file %s, file size %lu, page size %lu\n", argv[0], read_filename, size, page_size); gettimeofday(&t1, NULL); mbuffer = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0); for (i = 0 ; i < size ; i += page_size) sum += mbuffer[i]; munmap(mbuffer, page_size); gettimeofday(&t2, NULL); printf("\tread mmaped time: %luus\n", tv_diff(&t1, &t2)); close(fd); } Cc: Nicolas Pitre Cc: Catalin Marinas Cc: Marek Szyprowski Cc: Russell King Signed-off-by: Ming Lei --- arch/arm/mm/dma-mapping.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index e9db6b4..e63124a 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -879,10 +879,23 @@ static void __dma_page_dev_to_cpu(struct page *page, unsigned long off, dma_cache_maint_page(page, off, size, dir, dmac_unmap_area); /* - * Mark the D-cache clean for this page to avoid extra flushing. + * Mark the D-cache clean for these pages to avoid extra flushing. */ - if (dir != DMA_TO_DEVICE && off == 0 && size >= PAGE_SIZE) - set_bit(PG_dcache_clean, &page->flags); + if (dir != DMA_TO_DEVICE && size >= PAGE_SIZE) { + unsigned long pfn; + size_t left = size; + + pfn = page_to_pfn(page); + if (off) { + pfn++; + left -= PAGE_SIZE - off % PAGE_SIZE; + } + while (left >= PAGE_SIZE) { + page = pfn_to_page(pfn++); + set_bit(PG_dcache_clean, &page->flags); + left -= PAGE_SIZE; + } + } } /**