From patchwork Fri Dec 13 22:24:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22396 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5B10E23FF5 for ; Fri, 13 Dec 2013 22:26:56 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id oy12sf4849930veb.1 for ; Fri, 13 Dec 2013 14:26:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=CJ+4vY2TrWTESXPeapaKr4IFzyTX7ahV89h9DOtyMIM=; b=UlMNU7WtuFf8hvzZBwH6J3THDujMWDZLDEBFSLKmp9YdBZwY+HK545Cu/nB9twYrCv Cc+ZcqdLAaz1020y3GsTJCdBYO6XzWOGptEVLhp9PTvvx5WUhDMDe2Y/L2nEIfDlkmk1 9LACZUPOoG65OEwE1sSQgaBoYHVD0zL7FdDIvVgGXJH4Du42iXGuVc/ZhtLEz+lowz+M E0nkcuCxLGGE5ds+/d7cfoNgCfbv7h5XZoxzVbT5enNuYiG/CQTYgPCz9I6h1tnWhmU8 uN76tSHgLr3dh/+cb51wjriy+zqkUGNiAUmZ83TU37AC6d6/hdk7UsLj4LiIh9ib0ot1 +4xA== X-Gm-Message-State: ALoCoQmMwiJudBDRpaYe2nagpZyWMhEhvLsML4/wXz6oMIzP1eUo9A/RPXwapADCz6CpjscxyJhN X-Received: by 10.58.204.2 with SMTP id ku2mr1650424vec.39.1386973616222; Fri, 13 Dec 2013 14:26:56 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.62.199 with SMTP id a7ls1252857qes.87.gmail; Fri, 13 Dec 2013 14:26:56 -0800 (PST) X-Received: by 10.58.246.136 with SMTP id xw8mr2164887vec.41.1386973616080; Fri, 13 Dec 2013 14:26:56 -0800 (PST) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id lu1si1194411vcb.88.2013.12.13.14.26.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:56 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id la4so1766039vcb.29 for ; Fri, 13 Dec 2013 14:26:56 -0800 (PST) X-Received: by 10.53.13.44 with SMTP id ev12mr1859452vdd.17.1386973616011; Fri, 13 Dec 2013 14:26:56 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp73504vcz; Fri, 13 Dec 2013 14:26:55 -0800 (PST) X-Received: by 10.68.89.162 with SMTP id bp2mr5893112pbb.151.1386973615176; Fri, 13 Dec 2013 14:26:55 -0800 (PST) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) by mx.google.com with ESMTPS id tr4si2473744pab.324.2013.12.13.14.26.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:55 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.53 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.160.53; Received: by mail-pb0-f53.google.com with SMTP id ma3so3131640pbc.40 for ; Fri, 13 Dec 2013 14:26:54 -0800 (PST) X-Received: by 10.68.232.37 with SMTP id tl5mr6154609pbc.86.1386973614686; Fri, 13 Dec 2013 14:26:54 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id qz9sm7457908pbc.3.2013.12.13.14.26.53 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:53 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , Rebecca Schultz Zavin , John Stultz Subject: [PATCH 031/115] gpu: ion: Add support for cached mappings that don't fault Date: Fri, 13 Dec 2013 14:24:05 -0800 Message-Id: <1386973529-4884-32-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Rebecca Schultz Zavin We have found that faulting in the mappings for cached allocations has a significant performance impact and is only a benefit if only a small part of the buffer is touched by the cpu (an uncommon case for software rendering). This patch introduces a ION_FLAG_CACHED_NEEDS_SYNC which determines whether a mapping should be created by faulting or at mmap time. If this flag is set, userspace must manage the caches explictly using the SYNC ioctl. Signed-off-by: Rebecca Schultz Zavin [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion.c | 28 ++++++++++++++++++---------- drivers/staging/android/ion/ion.h | 3 +++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 3aeb41c..d1c7b84 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -164,7 +164,8 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, return ERR_PTR(PTR_ERR(table)); } buffer->sg_table = table; - if (buffer->flags & ION_FLAG_CACHED) { + if (buffer->flags & ION_FLAG_CACHED && + !(buffer->flags & ION_FLAG_CACHED_NEEDS_SYNC)) { for_each_sg(buffer->sg_table->sgl, sg, buffer->sg_table->nents, i) { if (sg_dma_len(sg) == PAGE_SIZE) @@ -763,7 +764,8 @@ static void ion_buffer_sync_for_device(struct ion_buffer *buffer, pr_debug("%s: syncing for device %s\n", __func__, dev ? dev_name(dev) : "null"); - if (!(buffer->flags & ION_FLAG_CACHED)) + if (!(buffer->flags & ION_FLAG_CACHED) || + (buffer->flags & ION_FLAG_CACHED_NEEDS_SYNC)) return; mutex_lock(&buffer->lock); @@ -853,18 +855,22 @@ static int ion_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma) return -EINVAL; } - if (buffer->flags & ION_FLAG_CACHED) { + if (buffer->flags & ION_FLAG_CACHED && + !(buffer->flags & ION_FLAG_CACHED_NEEDS_SYNC)) { vma->vm_private_data = buffer; vma->vm_ops = &ion_vma_ops; ion_vm_open(vma); - } else { - vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); - mutex_lock(&buffer->lock); - /* now map it to userspace */ - ret = buffer->heap->ops->map_user(buffer->heap, buffer, vma); - mutex_unlock(&buffer->lock); + return 0; } + if (!(buffer->flags & ION_FLAG_CACHED)) + vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); + + mutex_lock(&buffer->lock); + /* now map it to userspace */ + ret = buffer->heap->ops->map_user(buffer->heap, buffer, vma); + mutex_unlock(&buffer->lock); + if (ret) pr_err("%s: failure mapping buffer to userspace\n", __func__); @@ -1021,7 +1027,9 @@ static int ion_sync_for_device(struct ion_client *client, int fd) return -EINVAL; } buffer = dmabuf->priv; - ion_buffer_sync_for_device(buffer, NULL, DMA_BIDIRECTIONAL); + + dma_sync_sg_for_device(NULL, buffer->sg_table->sgl, + buffer->sg_table->nents, DMA_BIDIRECTIONAL); dma_buf_put(dmabuf); return 0; } diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 83baa38..072d64d 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -50,6 +50,9 @@ enum ion_heap_type { cached, ion will do cache maintenance when the buffer is mapped for dma */ +#define ION_FLAG_CACHED_NEEDS_SYNC 2 /* mappings of this buffer will created + at mmap time, if this is set + caches must be managed manually */ #ifdef __KERNEL__ struct ion_device;