Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3512714pxb; Mon, 4 Oct 2021 04:04:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhgd9yL49O/6BCOSYyMGN5OSsnv3zmWU6wPViVFydXhM8IYbNtEVwR4NTgIf51nWk4lEPi X-Received: by 2002:a17:90b:80f:: with SMTP id bk15mr14898673pjb.107.1633345477977; Mon, 04 Oct 2021 04:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633345477; cv=none; d=google.com; s=arc-20160816; b=AaeswXuaiO6s8kukuDAw8v7sgwAPvmtzRvYHI/tIpGFq9h6XbL/Af7u/AlgSYB3I/q KiGd3oYPK8hx1SGfsi2tRMhIm8O0XgT8auZR/2KCRYqqbmh9laxSerVex7DyFeeKlqhq jw7sn9IhOhU1n194KKVoi0f32pr2j4aHboTNoSc+8YvSW/MDY3mbr8n+MwqbdHEQO+nN CpnPM6mXhd3E2UEyFfrSIQCBV/jT9j8GeRRIsy2+yji/87XghtKv3lLGwzLFWzFC5Qer ZRfNq0/vDCs5f6iz0HP8ebLFYv38OsJ2/MgUSdKQ1/pVl1SxBtg9VpvkYxQ0c/U2ZRTf JROg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=URCJeJ//i21kt2HQZuP4+ONPAa0mUFJTP/rOPl6nrkU=; b=lnd885DrhCDIliAkFUnv4I2EttKBqHEURVgeasFAHhKpBHT5r1+MjCwAVb4jygD/+O AV/4qXQjkz+EGSbxJq4/E/8snX7/97H7y4cWH20Al8l8Db+zFrXQLS8cNBEeM+wWWEFM Da+jK6QToQiCePaGvSOcWra8T5CkZwNw1hafXPwVrY7X93uHz9OJBslInvchERkFaY7H RFW7F7lwsbYe2buRZBlSWTWDQk0Kqy/oOnTLQIhW3/z6L9fpCszxshAaOnXuplqLH/J5 JnJa4DbQeYkOXWqLF1vCqtA5U8rtmWQEZhGP1y7xQuovba5pTSrC9UMY/MJRvo/HC3Yr IX0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hDM2Ru5I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id np5si25282027pjb.129.2021.10.04.04.04.16; Mon, 04 Oct 2021 04:04:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hDM2Ru5I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232812AbhJDLDb (ORCPT + 99 others); Mon, 4 Oct 2021 07:03:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232693AbhJDLDa (ORCPT ); Mon, 4 Oct 2021 07:03:30 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83503C061745 for ; Mon, 4 Oct 2021 04:01:41 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id e15so69871548lfr.10 for ; Mon, 04 Oct 2021 04:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=URCJeJ//i21kt2HQZuP4+ONPAa0mUFJTP/rOPl6nrkU=; b=hDM2Ru5ICrroBNDxLmX0If6DCGiyxNrOCxoYD447SPukcHDmbBPLNisrdhOLXQ0z+O XAGpgeNiSLvK62mVR4ycyTMTlxOUILWm5ec3jHIazC1TTcmE73Wiu6Uw4vHsUObQZ88A VxG8L26gqN1qrB2CE408IFuJmANo6HHn/LiqpAKVqjl4+Fv6k7ICtg/O46hugliGIxbi S/OxLLbFm/pg/rjpCfpNW1Knl+/16xjrIofQdoho7b+zWsc33s3wkXlvS7VH5BYU8/rA bq9k2sPB1ak/yK37C/Nh9dpokzhoA+CoGOF3/o+k0JQbg3KEE7GgAczasadRr+Ip1+pd ujCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=URCJeJ//i21kt2HQZuP4+ONPAa0mUFJTP/rOPl6nrkU=; b=ehNQm1G/dE9xqmpZg2Mzjldb9l9awaCVsnZbPE78pMygP0d/CcvnUuVf3m4cSwk1Nl M5qiesTsBuBD5MRuSl7Nst4MHUWQkVT2ckUyEktfQF/1yYdUb/vsS1Qg3Dr/0q+leHVr FFiVuIMt53JonD5kYL5JsUeyNNUoh3nYLxMl8U93h1rWVxsuCH1waGL1kqTCXVMuYLUC /JqDHnLxso13AAHZwcsimdn6KzNuFqt9J3IEBG0O0cf4Y7JnfV2ulJZnAnZ8rUjJWkdZ P78Jl4eoHeZ9VZxr0fbXt2AjOciq+uRDQYP+X9SFIYTNx6pcXkLjXwSHfXQDTM4Gb3jB 0kKg== X-Gm-Message-State: AOAM530+aUKuqA/N2Ycs39PB0QuUH7OVlzf11hYvbG6THHJktp//lOgy MrtUXeXTEsgPJeiT8kShUjJCLi4czzJ8CKkOzX0FiA== X-Received: by 2002:a05:6512:2397:: with SMTP id c23mr13296805lfv.358.1633345298337; Mon, 04 Oct 2021 04:01:38 -0700 (PDT) MIME-Version: 1.0 References: <20210926224058.1252-1-digetx@gmail.com> <20210926224058.1252-14-digetx@gmail.com> <8d75436d-864a-7ce0-ba53-daa8b663035a@gmail.com> In-Reply-To: <8d75436d-864a-7ce0-ba53-daa8b663035a@gmail.com> From: Ulf Hansson Date: Mon, 4 Oct 2021 13:01:01 +0200 Message-ID: Subject: Re: [PATCH v13 13/35] drm/tegra: gr2d: Support generic power domain and runtime PM To: Dmitry Osipenko Cc: "Rafael J. Wysocki" , Thierry Reding , Jonathan Hunter , Viresh Kumar , Stephen Boyd , Peter De Schrijver , Mikko Perttunen , Peter Chen , Lee Jones , =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , Nishanth Menon , Adrian Hunter , Michael Turquette , Linux Kernel Mailing List , linux-tegra , Linux PM , Linux USB List , linux-staging@lists.linux.dev, linux-pwm@vger.kernel.org, linux-mmc , dri-devel , DTML , linux-clk , Mark Brown , Vignesh Raghavendra , Richard Weinberger , Miquel Raynal , Lucas Stach , Stefan Agner , Mauro Carvalho Chehab , David Heidelberg Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 1 Oct 2021 at 21:00, Dmitry Osipenko wrote: > > 01.10.2021 17:55, Ulf Hansson =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > > On Fri, 1 Oct 2021 at 16:29, Dmitry Osipenko wrote: > >> > >> 01.10.2021 16:39, Ulf Hansson =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > >>> On Mon, 27 Sept 2021 at 00:42, Dmitry Osipenko wro= te: > >>>> > >>>> Add runtime power management and support generic power domains. > >>>> > >>>> Tested-by: Peter Geis # Ouya T30 > >>>> Tested-by: Paul Fertser # PAZ00 T20 > >>>> Tested-by: Nicolas Chauvet # PAZ00 T20 and TK1 T= 124 > >>>> Tested-by: Matt Merhar # Ouya T30 > >>>> Signed-off-by: Dmitry Osipenko > >>>> --- > >>>> drivers/gpu/drm/tegra/gr2d.c | 155 ++++++++++++++++++++++++++++++++= +-- > >>> > >>> [...] > >>> > >>>> static int gr2d_remove(struct platform_device *pdev) > >>>> @@ -259,15 +312,101 @@ static int gr2d_remove(struct platform_device= *pdev) > >>>> return err; > >>>> } > >>>> > >>>> + pm_runtime_dont_use_autosuspend(&pdev->dev); > >>>> + pm_runtime_disable(&pdev->dev); > >>> > >>> There is no guarantee that the ->runtime_suspend() has been invoked > >>> here, which means that clock may be left prepared/enabled beyond this > >>> point. > >>> > >>> I suggest you call pm_runtime_force_suspend(), instead of > >>> pm_runtime_disable(), to make sure that gets done. > >> > >> The pm_runtime_disable() performs the final synchronization, please se= e [1]. > >> > >> [1] > >> https://elixir.bootlin.com/linux/v5.15-rc3/source/drivers/base/power/r= untime.c#L1412 > > > > pm_runtime_disable() end up calling _pm_runtime_barrier(), which calls > > cancel_work_sync() if dev->power.request_pending has been set. > > > > If the work that was punted to the pm_wq in rpm_idle() has not been > > started yet, we end up just canceling it. In other words, there are no > > guarantees it runs to completion. > > You're right. Although, in a case of this particular patch, the syncing > is actually implicitly done by pm_runtime_dont_use_autosuspend(). > > But for drivers which don't use auto-suspend, there is no sync. This > looks like a disaster, it's a very common pattern for drivers to > 'put+disable'. > > > Moreover, use space may have bumped the usage count via sysfs for the > > device (pm_runtime_forbid()) to keep the device runtime resumed. > > Right, this is also a disaster in a case of driver removal. > > >> Calling pm_runtime_force_suspend() isn't correct because each 'enable' > >> must have the corresponding 'disable'. Hence there is no problem here. > > > > pm_runtime_force_suspend() calls pm_runtime_disable(), so I think that > > should be fine. No? > > [adding Rafael] > > Rafael, could you please explain how drivers are supposed to properly > suspend and disable RPM to cut off power and reset state that was > altered by the driver's resume callback? What we're missing? Is Ulf's > suggestion acceptable? > > The RPM state of a device is getting reset on driver's removal, hence > all refcounts that were bumped by the rpm-resume callback of the device > driver will be screwed up if device is kept resumed after removal. I > just verified that it's true in practice. Note that, what makes the Tegra drivers a bit special is that they are always built with CONFIG_PM being set (selected from the "SoC" Kconfig). Therefore, pm_runtime_force_suspend() can work for some of these cases. Using this, would potentially avoid the driver from having to runtime resume the device in ->remove(), according to the below generic sequence, which is used in many drivers. pm_runtime_get_sync() clk_disable_unprepare() (+ additional things to turn off the device) pm_runtime_disable() pm_runtime_put_noidle() Kind regards Uffe