Received: by 10.223.185.116 with SMTP id b49csp193249wrg; Tue, 13 Feb 2018 19:38:21 -0800 (PST) X-Google-Smtp-Source: AH8x227b6FZS6dQFu9mf2VAOsSimozdUfGWP2P1bd6MCNR7G+QangpekCMAfHWDZ7sWEMxuO5lET X-Received: by 2002:a17:902:aa45:: with SMTP id c5-v6mr3103450plr.93.1518579501891; Tue, 13 Feb 2018 19:38:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518579501; cv=none; d=google.com; s=arc-20160816; b=sLijlkdN8xjzQ24pk8YyF3tyIq3IEQBRVaV7htKEQRRvUluRqJcSWY/HiPiZn7w3cA Osr+s3/CWd6zSDE4aJM6uV+WNezYnlIEpP9u6w210+1VgFMHWkSJbnQEA4l5dpb+uWf8 SSp8iwJ2efY+c1ZYVgvunJ9u7NcNWxXm+7NdfPC+55WxWywq7qB1HlUCWkOmGMX36gEV shpJ8WbnP8WfkN+4V2UQvLwwSGToB2voqkElqw+8t70d8B0sddBuh99DSzT1Q9zCms2H mLvwQuwTOrVtTFtpgS1NMfuxaiPCoeItu6On5ZnbOMN9JQf0N3nWSt/cutPUz11VddJs UhQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=h4jNVvOcjbnJs2694vumFVslZVLSe4jroeucRCubSI8=; b=FDFF+hK2lzsY0X7vNGJMhEz4z1lUkaf6jTf00uc6etYYWAdNI783gkW7cIgf+3TRJY OgVpdkqVvElQp5mDPVzmZLNvDYKJ4KYTC67X+nxEgVHCLUgu2BLRsyH8np7Dd5yXMYLy eKYlS87B3Fz5ut0I2XIyNSAnnhSqcJFCnR075HPRv8iYLOZ/lmE/iBQDXMtpZuQnT8f9 0nC938m02QpRcn9kb5cYNpAZWFpD6xikGTYQqpQ5dcz185mBtx10dXDPJT0fn4vui1WX RBgTv0gKxPRHlaKT64qRn4geO0gNAaMObVNqkNeYT3fH2AYU1ixdrDSASGk9rVUviugC QXRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fBefBmWu; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u7-v6si293170plr.241.2018.02.13.19.38.07; Tue, 13 Feb 2018 19:38:21 -0800 (PST) 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=@chromium.org header.s=google header.b=fBefBmWu; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966763AbeBNDhI (ORCPT + 99 others); Tue, 13 Feb 2018 22:37:08 -0500 Received: from mail-vk0-f41.google.com ([209.85.213.41]:42914 "EHLO mail-vk0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966671AbeBNDhH (ORCPT ); Tue, 13 Feb 2018 22:37:07 -0500 Received: by mail-vk0-f41.google.com with SMTP id b132so5164780vke.9 for ; Tue, 13 Feb 2018 19:37:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=h4jNVvOcjbnJs2694vumFVslZVLSe4jroeucRCubSI8=; b=fBefBmWux7ECTzQ/VxSs6q+qlPO+uW2ZzRzpZRD2KN2nEAXBsrO+AEP4DhMqrknH7w 7621MUmTa/a76nIfapDgmgZ/gQwXMFKWpP+qIi1dyJwMYhnB1k8th+vhDIGL+jtTThi3 G+cpSyXfg/1pJL98EuiTXv4EtR+rBfTXRoJ+M= 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; bh=h4jNVvOcjbnJs2694vumFVslZVLSe4jroeucRCubSI8=; b=qIBcyOD9Om/P0jjOZMR5g6QttVYa7m9oV0wEpvBs0H7zuy+pmm+TXBkJ18zjobZlS2 Ui8UOcUq0xoZpqMtTGJkg0V6vQilC6Yo2Yhtokf3TDQGnnvjKb9ykvbKeJahRYpBIn9v mJQoCjuBlY4at0x1f5FXos5873llCDYbWja1qun+p30tpEd+npHloURznHZPqlL78LQK T5u27mcldMNhCW4XGOQn09vM70Sc/qw+yGhQvF6j6S2/Wa+tQgWToaHDgVVwKloXyfVJ 09Q7vgJFTroF1sbDMax+EjVNOVFyqenJs6TFlyKjIPjUTKdHhGb6E9P8ALcDAnO4MsvC dSeA== X-Gm-Message-State: APf1xPBc2dgABhTk9Bh83Xjkm5+L58byHOFPN7eDqIXn4xLocwW3LD5s /4npWpIGxo1Veb4esq8StDgYkB5vujs= X-Received: by 10.31.151.147 with SMTP id z141mr3439064vkd.113.1518579426296; Tue, 13 Feb 2018 19:37:06 -0800 (PST) Received: from mail-vk0-f48.google.com (mail-vk0-f48.google.com. [209.85.213.48]) by smtp.gmail.com with ESMTPSA id m39sm5878794uai.15.2018.02.13.19.37.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 19:37:06 -0800 (PST) Received: by mail-vk0-f48.google.com with SMTP id j204so12096502vke.12 for ; Tue, 13 Feb 2018 19:37:05 -0800 (PST) X-Received: by 10.31.191.79 with SMTP id p76mr2932262vkf.28.1518579109913; Tue, 13 Feb 2018 19:31:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.0.68 with HTTP; Tue, 13 Feb 2018 19:31:29 -0800 (PST) In-Reply-To: <20180213164205.GA7599@jcrouse-lnx.qualcomm.com> References: <1517999482-17317-1-git-send-email-vivek.gautam@codeaurora.org> <1517999482-17317-7-git-send-email-vivek.gautam@codeaurora.org> <20180213164205.GA7599@jcrouse-lnx.qualcomm.com> From: Tomasz Figa Date: Wed, 14 Feb 2018 12:31:29 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 6/6] drm/msm: iommu: Replace runtime calls with runtime suppliers To: Tomasz Figa , Vivek Gautam , Mark Rutland , devicetree@vger.kernel.org, linux-pm@vger.kernel.org, David Airlie , Will Deacon , "Rafael J. Wysocki" , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , dri-devel , Linux Kernel Mailing List , Rob Herring , Greg KH , freedreno , Robin Murphy , Stephen Boyd , linux-arm-msm 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 Hi Jordan, On Wed, Feb 14, 2018 at 1:42 AM, Jordan Crouse wrote: > On Tue, Feb 13, 2018 at 06:10:38PM +0900, Tomasz Figa wrote: >> Hi Vivek, >> >> Thanks for the patch. Please see my comments inline. >> >> On Wed, Feb 7, 2018 at 7:31 PM, Vivek Gautam >> wrote: >> > While handling the concerned iommu, there should not be a >> > need to power control the drm devices from iommu interface. >> > If these drm devices need to be powered around this time, >> > the respective drivers should take care of this. >> > >> > Replace the pm_runtime_get/put_sync() with >> > pm_runtime_get/put_suppliers() calls, to power-up >> > the connected iommu through the device link interface. >> > In case the device link is not setup these get/put_suppliers() >> > calls will be a no-op, and the iommu driver should take care of >> > powering on its devices accordingly. >> > >> > Signed-off-by: Vivek Gautam >> > --- >> > drivers/gpu/drm/msm/msm_iommu.c | 16 ++++++++-------- >> > 1 file changed, 8 insertions(+), 8 deletions(-) >> > >> > diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c >> > index b23d33622f37..1ab629bbee69 100644 >> > --- a/drivers/gpu/drm/msm/msm_iommu.c >> > +++ b/drivers/gpu/drm/msm/msm_iommu.c >> > @@ -40,9 +40,9 @@ static int msm_iommu_attach(struct msm_mmu *mmu, const char * const *names, >> > struct msm_iommu *iommu = to_msm_iommu(mmu); >> > int ret; >> > >> > - pm_runtime_get_sync(mmu->dev); >> > + pm_runtime_get_suppliers(mmu->dev); >> > ret = iommu_attach_device(iommu->domain, mmu->dev); >> > - pm_runtime_put_sync(mmu->dev); >> > + pm_runtime_put_suppliers(mmu->dev); >> >> For me, it looks like a wrong place to handle runtime PM of IOMMU >> here. iommu_attach_device() calls into IOMMU driver's attach_device() >> callback and that's where necessary runtime PM gets should happen, if >> any. In other words, driver A (MSM DRM driver) shouldn't be dealing >> with power state of device controlled by driver B (ARM SMMU). > > This whole thing is confused by the fact that on MSM the GPU and the GPU IOMMU > share some of the same clocks and power rail so turning on the GPU also > turned on the IOMMU register banks by extension. This is surprisingly not a very surprising case. Exactly the same can be seen on Rockchip SoCs and we're solving the problem using the solution I suggested. In fact, my suggestions to this thread are based on the design we chose for Rockchip, due to the high level of similarity (+/- the GPU directly programming IOMMU registers, which is not present there, but AFAICT it doesn't pose a problem here). > > But if we put that aside the question is who should be responsible for > controlling the power in this relationship and there are several good reasons to > leave it up to the client device. The most important reason is when we move to > the per-instance model where the GPU self-programmings the SMMU registers. In > that case, the driver will need to make sure that the SMMU is powered up before > submitting the command and then removing the power vote when the commands > are done to save energy. I might need more insight on what's going on in your hardware, but with my current understanding I'd argue that that is not right, because: - When submitting commands to the GPU, the GPU driver will pm_runtime_get_sync() on the GPU device, which will automatically do the same on all the linked suppliers, which would also include the SMMU itself. The role of device links here is exactly that the GPU driver doesn't have to care which other devices need to be brought up. - When the GPU is operating, the SMMU power must be supplied anyway, because it needs to be doing the translations, right? Note that by "power" I really mean the physical power supply in the SoC, e.g. as for a power domain. The runtime PM API in its current form (e.g. binary off or on operation) is unsuitable for managing other things, such as clocks (and there is ongoing work on improving it, e.g. by adding support for multiple power states). ^^ The above would be actually guaranteed by your hardware design, where SMMU and GPU share the power domain and clocks. (We used to rely on this in old downstream implementation of Rockchip IOMMU and master drivers in Chromium OS kernel, before we moved to handling the clocks explicitly in the IOMMU driver and properly using device links to manage the power domain and state restoration.) > > Additionally, there might be legitimate reasons in the driver to batch > operations - you may wish to attach the device and then map several global > buffers immediately - having driver side control prevents several unneeded power > transitions. As I mentioned before, these operations wouldn't normally need any power transitions, since mapping with the TLB powered down boils down to just updating the page tables in memory. However, as Robin mentioned before, there might be some hardware factors, such as TLB being powered separately (or retaining contents in some other way), where this wouldn't be ensured indeed. Still, that's where runtime PM autosuspend feature (i.e. delayed suspend) comes to the rescue, with the advantage of handling the cases when the master driver receives map/unmap requests not batched (but maybe a slight drawback in terms of the suspend not happening instantly and losing some power, but it's about power domains, so mainly leakage current, isn't it?) > > Perhaps the right answer is to do both - allow for the driver to enable the > supplier but also do the right power operations at the appropriately places in > the IOMMU driver. > >> This is also important for the reasons I stated in my comments to >> "[PATCH v7 1/6] base: power: runtime: Export >> pm_runtime_get/put_suppliers". Quoting for everyone's convenience: >> >> >> There are however cases in which the consumer wants to power-on >> >> the supplier, but not itself. >> >> E.g., A Graphics or multimedia driver wants to power-on the SMMU >> >> to unmap a buffer and finish the TLB operations without powering >> >> on itself. >> > >> >This sounds strange to me. If the SMMU is powered down, wouldn't the >> >TLB lose its contents as well (and so no flushing needed)? >> > > >> >Other than that, what kind of hardware operations would be needed >> >besides just updating the page tables from the CPU? >> > > >> In other words, the SMMU driver can deal with hardware state based on >> return value of pm_runtime_get_sync() or pm_runtime_get_if_in_use() >> and decide whether some operations are necessary or not, e.g. >> - a state restore is necessary if the domain was powered off, but we >> are bringing the master on, >> - a flush may not be required when (un)mapping with the domain powered off, >> - etc. > > I agree that there is probably some advanced logic that we can do to > conclusively figure out the state of the hardware and improve the behavior. > I would love to see the SMMU driver get smarter but for the moment we can't > trust it and so we need to force the behavior from the GPU driver. The current > code works for a5x and earlier but on sdm845 we can (no longer) treat the GPU > and the SMMU as the same device for power purposes so we need this code. Hmm, you've lost me there. Above you mention that "on MSM the GPU and the GPU IOMMU share some of the same clocks and power rail". Is this no longer the case for sdm845? If so, would you mind shedding a bit more light on how this looks there? Best regards, Tomasz