linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ulf Hansson <ulf.hansson@linaro.org>
To: Dmitry Osipenko <digetx@gmail.com>
Cc: "Thierry Reding" <thierry.reding@gmail.com>,
	"Jonathan Hunter" <jonathanh@nvidia.com>,
	"Viresh Kumar" <vireshk@kernel.org>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Peter De Schrijver" <pdeschrijver@nvidia.com>,
	"Mikko Perttunen" <mperttunen@nvidia.com>,
	"Peter Chen" <peter.chen@kernel.org>,
	"Lee Jones" <lee.jones@linaro.org>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Nishanth Menon" <nm@ti.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"Michael Turquette" <mturquette@baylibre.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	linux-tegra <linux-tegra@vger.kernel.org>,
	"Linux PM" <linux-pm@vger.kernel.org>,
	"Linux USB List" <linux-usb@vger.kernel.org>,
	linux-staging@lists.linux.dev, linux-pwm@vger.kernel.org,
	linux-mmc <linux-mmc@vger.kernel.org>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	DTML <devicetree@vger.kernel.org>,
	linux-clk <linux-clk@vger.kernel.org>,
	"Mark Brown" <broonie@kernel.org>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Lucas Stach" <dev@lynxeye.de>, "Stefan Agner" <stefan@agner.ch>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"David Heidelberg" <david@ixit.cz>
Subject: Re: [PATCH v13 06/35] clk: tegra: Support runtime PM and power domain
Date: Wed, 6 Oct 2021 14:38:35 +0200	[thread overview]
Message-ID: <CAPDyKFq_-HGPRNiNDmnEbuah0mUYoRUWVs1SvbQ6VNMMwEcXjA@mail.gmail.com> (raw)
In-Reply-To: <4bdba8a2-4b9b-ed7d-e6ca-9218d8200a85@gmail.com>

On Wed, 6 Oct 2021 at 00:19, Dmitry Osipenko <digetx@gmail.com> wrote:
>
> 05.10.2021 16:10, Ulf Hansson пишет:
> > On Sat, 2 Oct 2021 at 22:44, Dmitry Osipenko <digetx@gmail.com> wrote:
> >>
> >> 01.10.2021 15:32, Ulf Hansson пишет:
> >>>> +static __maybe_unused int tegra_clock_pm_suspend(struct device *dev)
> >>>> +{
> >>>> +       struct tegra_clk_device *clk_dev = dev_get_drvdata(dev);
> >>>> +
> >>>> +       /*
> >>>> +        * Power management of the clock is entangled with the Tegra PMC
> >>>> +        * GENPD because PMC driver enables/disables clocks for toggling
> >>>> +        * of the PD's on/off state.
> >>>> +        *
> >>>> +        * The PMC GENPD is resumed in NOIRQ phase, before RPM of the clocks
> >>>> +        * becomes available, hence PMC can't use clocks at the early resume
> >>>> +        * phase if RPM is involved. For example when 3d clock is enabled,
> >>>> +        * it may enable the parent PLL clock that needs to be RPM-resumed.
> >>>> +        *
> >>>> +        * Secondly, the PLL clocks may be enabled by the low level suspend
> >>>> +        * code, so we need to assume that PLL is in enabled state during
> >>>> +        * suspend.
> >>>> +        *
> >>>> +        * We will keep PLLs and system clock resumed during suspend time.
> >>>> +        * All PLLs on all SoCs are low power and system clock is always-on,
> >>>> +        * so practically not much is changed here.
> >>>> +        */
> >>>> +
> >>>> +       return clk_prepare(clk_dev->hw->clk);
> >>> I am trying to understand, more exactly, what you intend to achieve
> >>> with the clk_prepare() here. It looks a bit weird, to me. Can you try
> >>> to elaborate a bit more on the use case?
> >>
> >> The Tegra GENPD driver enable/disable clocks when domain is turned on.
> >
> > Okay. I noticed that in tegra_genpd_power_on(). And the same clocks
> > are enabled/disabled also in tegra_genpd_power_off(), when powering
> > off the PM domain.
> >
> > So I guess the problem kind of exists for tegra_genpd_power_off() too?
>
> Both OFF/ON are affected by the same problem. If domain was already
> turned OFF before genpd_suspend_noirq(), then the OFF problem isn't visible.
>
> I reproduced the OFF problem by removing the clk prepare/unprepare from
> the suspend/resume of the clk driver and making some extra changes to
> clock tree topology and etc to trigger the problem on Nexus 7.
>
> tegra-pmc 7000e400.pmc: failed to turn off PM domain heg: -13
>
> I happens from genpd_suspend_noirq() -> tegra_genpd_power_off() -> clk
> -> GENPD -> I2C -> runtime-pm.
>
> -13 is EACCES, it comes from the runtime PM of I2C device. RPM is
> prohibited/disabled during late (NOIRQ) suspend by the drivers core.

Thanks for the clarification!

>
> >> This can't be done during early system resume, when domains are getting
> >> turned on by the drivers core, because when clock is enabled, it's
> >> getting prepared (RPM-resumed) and this preparation fails because
> >> performance state of the clock goes up and it doesn't work during the
> >> early resume time since I2C, which applies the state to hardware, is
> >> suspended and can't work at that early time.
> >
> > This sounds complicated and I still don't quite follow all of it, sorry.
> >
> > So, tegra_genpd_power_on() gets called from genpd_resume_noirq(), when
> > the first device of the attached devices to genpd gets resumed. And
> > vice versa for tegra_genpd_power_off() and genpd_suspend_noirq().
> >
> > Are you saying that trying to enable/disable clocks from
> > tegra_genpd_power_on|off() in these paths doesn't work, because it
> > would also require the performance state to be changed, which would
> > fail because the I2C bus/driver is suspended?
>
> Yes, but it's actually not I2C bus/driver that is suspended, it's
> runtime PM that is unavailable during NOIRQ. The I2C driver itself is
> suspended after domains are turned OFF and resumed before they are
> enabled. It's just runtime PM API that is unavailable. I'm wondering if
> this could be changed.

In principle what you ask for, is if we can avoid calling
__pm_runtime_disable() in __device_suspend_late() (and vice versa in
device_resume_early()).

I think the short answer is no, at least from a generic point of view.
Maybe we can figure out a way to allow this on a per device basis, as
an opt-in solution. I am not sure what Rafael would think about this,
let's see.

Another option to address the problem is already available to use for
these kinds of cases. This would be to add also a pair of
->suspend|resume() callbacks to I2C driver. Along the lines of the
below.

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index c883044715f3..589bf872ab25 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -1918,6 +1918,7 @@ static int __maybe_unused
tegra_i2c_resume(struct device *dev)
 }

 static const struct dev_pm_ops tegra_i2c_pm = {
+       SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_put_noidle, pm_runtime_get_sync)
        SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume)
        SET_RUNTIME_PM_OPS(tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume,
                           NULL)

In this way, the device would already be runtime resumed, if there is
call to pm_runtime_get_sync() from the clock framework due to the
clk_prepare|unprepare() being called. If that also turns out to happen
*after* runtime PM has been disabled for the device, the call to
pm_runtime_get_sync() would still succeed (returning 1, see
rpm_resume()), rather than a negative error code.

Yes, we may end up runtime resuming the device during system suspend,
even if it turns out not to be needed. Although, that doesn't seem to
be the case for the Tegra I2C driver, right?

>
> I'm also wondering if we could add some 'was_enabled' flag to GENPDs,
> setting it by genpd_suspend_noirq() for the enabled domains, and then
> powering-on GENPDs from genpd_resume_noirq() only if they were in the
> enabled state during genpd_suspend_noirq() time. It actually puzzled me
> for a quite long time why GENPD core enables domains unconditionally
> during early resume. This should solve a part of the problem and it
> makes suspend/resume a bit safer because there is a smaller chance to
> crash hardware during suspend, at least it's easier to debug.

Just because the PM domain was already off at genpd_suspend_noirq(),
doesn't mean that it can stay powered off at genpd_resume_noirq(). At
least as is today.

The main reason why genpd_resume_noirq() powers on the PM domain, is
because it's not possible for the consumer drivers to rely on runtime
PM to do it (because runtime PM has been disabled by the PM core).

>
> >> Secondly, Tegra has arch-specific low level assembly which touches
> >> clocks during last phase of system suspend and in the beginning of
> >> resume. Hence, clocks should stay prepared during suspend just because
> >> technically clock should be prepared before it can be enabled.
> >
> > So the low level code is gating and ungating the clock behind the back
> > of the clock driver then? Why is that done like that, more exactly?
>
> I revisited that code again, and it shouldn't touch the clocks.
> I changed that code to not toggle the clocks [1] sometime ago, but
> forgot about it.
>
> [1] https://git.kernel.org/linus/680ae4452
>
> >>> Is this rather about making sure that the clock's corresponding PM
> >>> domain stays powered on during system suspend? In that case, I think
> >>> there may be an alternative option....
> >>>
> >>
> >> This is not about domain staying powered on, this is about keeping the
> >> performance state of the domain high during suspend.
> >
> > Right, so the PM domain managed in tegra_genpd_power_on|off() can
> > still be powered on/off, as long as the clock remains ungated?
>
> Not ungated, but prepared.

Okay, thanks for clarifying!

In summary, it sounds like you should be able to fix this problem in
the I2C driver as I suggested above. If that works, that seems much
better.

Moreover, it would leave the clocks gated/unprepared when the system
is fully suspended, which I guess is better from an energy point of
view?

Kind regards
Uffe

  parent reply	other threads:[~2021-10-06 12:39 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-26 22:40 [PATCH v13 00/35] NVIDIA Tegra power management patches for 5.16 Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 01/35] opp: Change type of dev_pm_opp_attach_genpd(names) argument Dmitry Osipenko
2021-10-04  9:11   ` Viresh Kumar
2021-09-26 22:40 ` [PATCH v13 02/35] soc/tegra: Add devm_tegra_core_dev_init_opp_table_common() Dmitry Osipenko
2021-10-01 12:50   ` Ulf Hansson
2021-10-01 19:15     ` Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 03/35] soc/tegra: pmc: Disable PMC state syncing Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 04/35] soc/tegra: Don't print error message when OPPs not available Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 05/35] dt-bindings: clock: tegra-car: Document new clock sub-nodes Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 06/35] clk: tegra: Support runtime PM and power domain Dmitry Osipenko
2021-10-01 12:32   ` Ulf Hansson
2021-10-01 19:50     ` Dmitry Osipenko
2021-10-02 20:44     ` Dmitry Osipenko
2021-10-05 13:10       ` Ulf Hansson
2021-10-05 22:19         ` Dmitry Osipenko
2021-10-05 22:43           ` Dmitry Osipenko
2021-10-06  2:40             ` Dmitry Osipenko
2021-10-06 12:43             ` Ulf Hansson
2021-10-06 21:14               ` Dmitry Osipenko
2021-10-06 22:01                 ` Dmitry Osipenko
2021-10-06 23:21                   ` Dmitry Osipenko
2021-10-07  9:18                     ` Ulf Hansson
2021-10-07 10:36                       ` Dmitry Osipenko
2021-10-06 12:38           ` Ulf Hansson [this message]
2021-10-06 21:20             ` Dmitry Osipenko
2021-10-06 21:25             ` Dmitry Osipenko
2021-10-06 22:03             ` Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 07/35] dt-bindings: host1x: Document OPP and power domain properties Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 08/35] dt-bindings: host1x: Document Memory Client resets of Host1x, GR2D and GR3D Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 09/35] gpu: host1x: Add runtime PM and OPP support Dmitry Osipenko
2021-10-01 13:24   ` Ulf Hansson
2021-09-26 22:40 ` [PATCH v13 10/35] gpu: host1x: Add host1x_channel_stop() Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 11/35] drm/tegra: dc: Support OPP and SoC core voltage scaling Dmitry Osipenko
2021-10-01 13:27   ` Ulf Hansson
2021-10-16 15:36     ` Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 12/35] drm/tegra: hdmi: Add OPP support Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 13/35] drm/tegra: gr2d: Support generic power domain and runtime PM Dmitry Osipenko
2021-10-01 13:39   ` Ulf Hansson
2021-10-01 14:29     ` Dmitry Osipenko
2021-10-01 14:55       ` Ulf Hansson
2021-10-01 19:00         ` Dmitry Osipenko
2021-10-04 11:01           ` Ulf Hansson
2021-10-04 15:57             ` Dmitry Osipenko
2021-10-05  8:45               ` Ulf Hansson
2021-10-05 17:16                 ` Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 14/35] drm/tegra: gr3d: " Dmitry Osipenko
2021-10-01 14:06   ` Ulf Hansson
2021-10-01 21:25     ` Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 15/35] drm/tegra: vic: Support system suspend Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 16/35] usb: chipidea: tegra: Add runtime PM and OPP support Dmitry Osipenko
2021-09-30  0:40   ` Dmitry Osipenko
2021-09-30 14:06   ` Peter Chen
2021-09-30 14:08     ` Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 17/35] bus: tegra-gmi: " Dmitry Osipenko
2021-10-01 14:18   ` Ulf Hansson
2021-09-26 22:40 ` [PATCH v13 18/35] pwm: tegra: " Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 19/35] mmc: sdhci-tegra: " Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 20/35] mtd: rawnand: tegra: " Dmitry Osipenko
2021-10-01 14:24   ` Ulf Hansson
2021-10-01 14:35     ` Dmitry Osipenko
2021-10-01 15:01       ` Ulf Hansson
2021-10-17  8:38         ` Dmitry Osipenko
2021-10-19 11:40           ` Ulf Hansson
2021-09-26 22:40 ` [PATCH v13 21/35] spi: tegra20-slink: Add " Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 22/35] media: dt: bindings: tegra-vde: Convert to schema Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 23/35] media: dt: bindings: tegra-vde: Document OPP and power domain Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 24/35] media: staging: tegra-vde: Support generic " Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 25/35] soc/tegra: fuse: Reset hardware Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 26/35] soc/tegra: fuse: Use resource-managed helpers Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 27/35] soc/tegra: regulators: Prepare for suspend Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 28/35] soc/tegra: pmc: Rename 3d power domains Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 29/35] soc/tegra: pmc: Rename core power domain Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 30/35] soc/tegra: pmc: Enable core domain support for Tegra20 and Tegra30 Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 31/35] ARM: tegra: Add OPP tables and power domains to Tegra20 device-trees Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 32/35] ARM: tegra: Add OPP tables and power domains to Tegra30 device-trees Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 33/35] ARM: tegra: Add Memory Client resets to Tegra20 GR2D, GR3D and Host1x Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 34/35] ARM: tegra: Add Memory Client resets to Tegra30 " Dmitry Osipenko
2021-09-26 22:40 ` [PATCH v13 35/35] ARM: tegra20/30: Disable unused host1x hardware Dmitry Osipenko
2021-10-01 14:36 ` [PATCH v13 00/35] NVIDIA Tegra power management patches for 5.16 Ulf Hansson
2021-10-01 14:40   ` Dmitry Osipenko
2021-10-01 15:02     ` Ulf Hansson
2021-10-04  9:11 ` Viresh Kumar
2021-10-04 14:52   ` Dmitry Osipenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPDyKFq_-HGPRNiNDmnEbuah0mUYoRUWVs1SvbQ6VNMMwEcXjA@mail.gmail.com \
    --to=ulf.hansson@linaro.org \
    --cc=adrian.hunter@intel.com \
    --cc=broonie@kernel.org \
    --cc=david@ixit.cz \
    --cc=dev@lynxeye.de \
    --cc=devicetree@vger.kernel.org \
    --cc=digetx@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jonathanh@nvidia.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=mperttunen@nvidia.com \
    --cc=mturquette@baylibre.com \
    --cc=nm@ti.com \
    --cc=pdeschrijver@nvidia.com \
    --cc=peter.chen@kernel.org \
    --cc=richard@nod.at \
    --cc=sboyd@kernel.org \
    --cc=stefan@agner.ch \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=vigneshr@ti.com \
    --cc=vireshk@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).