Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4128289imm; Mon, 15 Oct 2018 09:30:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV62O6B6Ka+0ADlLpQcqOoSFLus9Fal62osA0nO/5jl8ZFCqjaiYL1pHdRP1XYCd61jEzbxBB X-Received: by 2002:a63:c0f:: with SMTP id b15-v6mr16937665pgl.400.1539621037503; Mon, 15 Oct 2018 09:30:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539621037; cv=none; d=google.com; s=arc-20160816; b=dcOWC/+GXyglBgZBe8w0CZipfpGq7Oc9hLV2vWFcwkCYhZvKwXaQ9S6+Ei/75gH1kv SRoxYiR5k5g6R0h1wCBLz8QHmrWWAeob3qnqkE4tixQ1DjKu2bZ9G3AAtYWKCwDR+nei KlOXlKIxa7ZomlLYAXBKXBl22opSv5mnxo9DkADU7m3Dp5rVFjzyX0GE1E2J+Y1uHZv6 3IXazv4xaEoE8ju59T46y5vuDJowpapbM6xvLq3el1uLmmC9qNELX4V3acNab2Tq3Qsr S29BYQC/nJjH/lHiu+Ee0GHLHWbAYcke8rCJYFR65J+BRZQmi4WtFoHCuwdzKUrDISTU Q4/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=xYRy9SRnULVc3qiQzz/PbPzMeHic+kzBhHSg8coo4qg=; b=cjY7+M7jOnAZsyrBvxNmYKN4mlXJ1jT7uGyKkXmSfebBi+j/xQGrv1MRm7lSvtHtWj miSwEr2TJ05RoLsfg1652cji/mtamfSzIR7RvpiZ9CoinkaTpgfcsTCJPgJ/Y3Ahbr6H qEH4qFgQi7EYLP4+6ar/qGD/qsgF2zLiNHERZd7QdeDq9iVX+42+qeBYglRStOaukflV CzCc77JLl5zj7QcK+oX3397YVBEjAbkxik1cv79ZNqGbvxRLNOKidSGCfQQBpucX23Rr A/y8myiZqkz75CURFvmr+bcZm47pgmt1bHiazsFzNTgK9aoifvisfCR9rwTKrP9uAH1s LzCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H5iC2apw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10-v6si11484708pgi.223.2018.10.15.09.30.21; Mon, 15 Oct 2018 09:30:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H5iC2apw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726935AbeJPAPE (ORCPT + 99 others); Mon, 15 Oct 2018 20:15:04 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35721 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726836AbeJPAPE (ORCPT ); Mon, 15 Oct 2018 20:15:04 -0400 Received: by mail-wr1-f65.google.com with SMTP id w5-v6so22082743wrt.2 for ; Mon, 15 Oct 2018 09:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=xYRy9SRnULVc3qiQzz/PbPzMeHic+kzBhHSg8coo4qg=; b=H5iC2apwzMq3+3ynCf4vggdbyhrQhqlNWpDVqMAA7inmzIGGCpbCkIyd52jFmYvW+e H48M/dY98ezD1fhQjekOSqrGo9JAGQOKOLYtcApiklaSyxQxFyMIKBEbpuL1MksXS+Do wq+qTDk8j8tD7N1Mai5vcMTgatzJkOiXweE4Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=xYRy9SRnULVc3qiQzz/PbPzMeHic+kzBhHSg8coo4qg=; b=tSESJzI2xKk9brfsPZYXD2KAeYCvqeO2ZjFmBYGbOYN2jPR/WyGnVPJqGvxjPGOpIi rY+37F8RSlEE9mpkk68U2HCsZPY5ehHbHM6EB3s/Vmi2uD6aLN+1IJSYAqb9NEoxXZxy 4pVwQcSIXsiiT6q0HcLfvKR7ZfzXFFKEDVKzgDBX5TYTxGAtkxdwaEGEkk6Lt/XO/KhQ T5wR2pEi/4MUvxqFqO2W2dO0hYGZw7frg9LHNB3PxPZUP8luWmjAU8UHa7Je6uRiQcLC SXYwe2mTh0HNHVdjfBXN7bn4EodvWYFqTTH3gOvXa1qEQ2IbeNoYhyrL0nV5M+DtZIXJ /eNA== X-Gm-Message-State: ABuFfoiC20H4CwN2eiZ0pGevGH+zaKOnRq+s6BX93FqQEL/DWt1Ggnml SoHRahhi9fYKmHxULAbscQbGa2wviWQrkFC/Ez20Dw== X-Received: by 2002:a05:6000:1008:: with SMTP id a8mr15268457wrx.271.1539620945458; Mon, 15 Oct 2018 09:29:05 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:b485:0:0:0:0:0 with HTTP; Mon, 15 Oct 2018 09:29:04 -0700 (PDT) In-Reply-To: <7534ca1d-f874-7809-6125-d9fc72f70e39@redhat.com> References: <1539214413-26173-1-git-send-email-john.stultz@linaro.org> <7534ca1d-f874-7809-6125-d9fc72f70e39@redhat.com> From: John Stultz Date: Mon, 15 Oct 2018 09:29:04 -0700 Message-ID: Subject: Re: [PATCH] staging: ion: Rework ion_map_dma_buf() to minimize re-mapping To: Laura Abbott Cc: lkml , Beata Michalska , Matt Szczesiak , Anders Pedersen , John Reitan , Liam Mark , Sumit Semwal , Greg Kroah-Hartman , Todd Kjos , Martijn Coenen , dri-devel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 12, 2018 at 10:51 AM, Laura Abbott wrote: > On 10/10/2018 04:33 PM, John Stultz wrote: >> >> Since 4.12, much later narrowed down to commit 2a55e7b5e544 >> ("staging: android: ion: Call dma_map_sg for syncing and mapping"), >> we have seen graphics performance issues on the HiKey960. >> >> This was initially confounded by the fact that the out-of-tree >> DRM driver was using HiSi custom ION heap which broke with the >> 4.12 ION abi changes, so there was lots of suspicion that the >> performance problems were due to switching to a somewhat simple >> cma based DRM driver for HiKey960. Additionally, as no >> performance regression was seen w/ the original HiKey board >> (which is SMP, not big.LITTLE as w/ HiKey960), there was some >> thought that the out-of-tree EAS code wasn't quite optimized. >> >> But after chasing a number of other leads, I found that >> reverting the ION code to 4.11-era got the majority of the >> graphics performance back (there may yet be further EAS tweaks >> needed), which lead me to the dma_map_sg change. >> >> In talking w/ Laura and Liam, it was suspected that the extra >> cache operations were causing the trouble. Additionally, I found >> that part of the reason we didn't see this w/ the original >> HiKey board is that its (proprietary blob) GL code uses ion_mmap >> and ion_map_dma_buf is called very rarely, where as with >> HiKey960, the (also proprietary blob) GL code calls >> ion_map_dma_buf much more frequently via the kernel driver. >> >> Anyway, with the cause of the performance regression isolated, >> I've tried to find a way to improve the performance of the >> current code. >> >> This approach, which I've mostly copied from the drm_prime >> implementation is to try to track the direction we're mapping >> the buffers so we can avoid calling dma_map/unmap_sg on every >> ion_map_dma_buf/ion_unmap_dma_buf call, and instead try to do >> the work in attach/detach paths. >> >> I'm not 100% sure of the correctness here, so close review would >> be good, but it gets the performance back to being similar to >> reverting the ION code to the 4.11-era. >> >> Feedback would be greatly appreciated! >> ... >> @@ -264,7 +291,6 @@ static void ion_unmap_dma_buf(struct >> dma_buf_attachment *attachment, >> struct sg_table *table, >> enum dma_data_direction direction) >> { >> - dma_unmap_sg(attachment->dev, table->sgl, table->nents, >> direction); > > > This changes the semantics so that the only time a buffer > gets unmapped is on detach. I don't think we want to restrict > Ion to that behavior but I also don't know if anyone else > is relying on that. I thought there might have been some Qualcomm > stuff that did that (Liam? Todd?) > > I suspect most of the cost of the dma_map/dma_unmap is from the > cache flushing and not the actual mapping operations. If this > is the case, another option might be to figure out how to > incorporate dma_attrs so drivers can use DMA_ATTR_SKIP_CPU_SYNC > to decide when they actually want to sync. Ok. Thanks so much for the feedback and the suggestion. I'll try to look into dma_attrs here shortly. thanks -john