All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@baylibre.com>
To: Mason <slash.tmp@free.fr>
Cc: Alan Stern <stern@rowland.harvard.edu>,
	linux-pm <linux-pm@vger.kernel.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Pavel Machek <pavel@ucw.cz>, Arnd Bergmann <arnd@arndb.de>,
	Mans Rullgard <mans@mansr.com>,
	Sebastian Frias <sf84@laposte.net>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: Platform-specific suspend/resume code in drivers
Date: Fri, 10 Jun 2016 15:32:45 -0700	[thread overview]
Message-ID: <m2k2hwwu7m.fsf@baylibre.com> (raw)
In-Reply-To: <575A9E93.4090508@free.fr> (Mason's message of "Fri, 10 Jun 2016 13:03:47 +0200")

Mason <slash.tmp@free.fr> writes:

[...]

> Consider two SoCs, SoCA and SocB.
>
> They both have the same device D, which exposes 16 registers to interact
> with the hardware.
>
> When SoCA is suspended, it stops D's clock, but keeps D powered on,
> preserving the 16 registers. Thus when SoCA resumes, it finds the
> 16 registers in the same state as before suspending.
>
> When SoCB is suspended, it powers D down. When SoCB resumes, the
> 16 registers contain garbage/random values. Therefore, in the case
> of SoCB, the suspend routine should save the values of the registers
> to RAM (which is preserved by "contract") and restore them on resume.
>
> However, this save/restore operation is unnecessary on SoCA.
>
> Should the save/restore operation be added unconditionally to the
> driver, even if some SoCs do not need it?

Yes.  For starters, this is the way to go.  If the added save/restore is
too expensive, a few things can be done...

> In other words, do we consider the performance penalty from saving
> and restoring device registers small enough that it should be done
> systematically, even if some SoCs do not require it?

The "save" part can be made to be almost no overhead by always keeping a
"shadow" copy of the registers in memory whenever they change (not just
at suspend time.)  This could be done "manually" by the driver for the
needed registers, or with the aid of something like the regmap cache
feature.  Doing that, there's no additional time for saving context
during suspend.

On resume time, on most hardware there are at least some registers that
will have some pre-determined power-on reset value.  You could optimize
the restore context by comparing one (or a few) of the registers from
your saved context against the power-on reset values to determine if
context was lost, and thus avoid doing a full restore if needed.

Honestly however, the save/restore context time for most devices is
going to be insignificant compared with the total system-wide
suspend/resume time, so the optimizations will not likely be noticed for
system-wide suspend/resume.

However, if you would like to also implement runtime PM (and you
should), then the save/restore context for individual devices will start
to matter since for latency reasons, you will likely care about runtime
suspend/resume times for individual devices.

In that case however, the solution is use PM QoS constraints when there
are specific latency requirements so that the power-off of the device is
avoided in cases where latency constraints could not be met.

> Some device tree nodes have a property called "always-on" which is
> documented as "If present, the block is powered through an always-on
> power domain, therefore it never loses context."
>
> In that case, I suppose the driver's suspend/resume routine should:
>
> suspend:
> if (always-on is not present) {
>     save device registers to RAM;
> }
>
> resume:
> if (always-on is not present) {
>     restore device registers from RAM;
> }
>
> Do you disagree?

Yes.  I'm not a fan of using always-on for this.

Kevin

WARNING: multiple messages have this Message-ID (diff)
From: khilman@baylibre.com (Kevin Hilman)
To: linux-arm-kernel@lists.infradead.org
Subject: Platform-specific suspend/resume code in drivers
Date: Fri, 10 Jun 2016 15:32:45 -0700	[thread overview]
Message-ID: <m2k2hwwu7m.fsf@baylibre.com> (raw)
In-Reply-To: <575A9E93.4090508@free.fr> (Mason's message of "Fri, 10 Jun 2016 13:03:47 +0200")

Mason <slash.tmp@free.fr> writes:

[...]

> Consider two SoCs, SoCA and SocB.
>
> They both have the same device D, which exposes 16 registers to interact
> with the hardware.
>
> When SoCA is suspended, it stops D's clock, but keeps D powered on,
> preserving the 16 registers. Thus when SoCA resumes, it finds the
> 16 registers in the same state as before suspending.
>
> When SoCB is suspended, it powers D down. When SoCB resumes, the
> 16 registers contain garbage/random values. Therefore, in the case
> of SoCB, the suspend routine should save the values of the registers
> to RAM (which is preserved by "contract") and restore them on resume.
>
> However, this save/restore operation is unnecessary on SoCA.
>
> Should the save/restore operation be added unconditionally to the
> driver, even if some SoCs do not need it?

Yes.  For starters, this is the way to go.  If the added save/restore is
too expensive, a few things can be done...

> In other words, do we consider the performance penalty from saving
> and restoring device registers small enough that it should be done
> systematically, even if some SoCs do not require it?

The "save" part can be made to be almost no overhead by always keeping a
"shadow" copy of the registers in memory whenever they change (not just
at suspend time.)  This could be done "manually" by the driver for the
needed registers, or with the aid of something like the regmap cache
feature.  Doing that, there's no additional time for saving context
during suspend.

On resume time, on most hardware there are at least some registers that
will have some pre-determined power-on reset value.  You could optimize
the restore context by comparing one (or a few) of the registers from
your saved context against the power-on reset values to determine if
context was lost, and thus avoid doing a full restore if needed.

Honestly however, the save/restore context time for most devices is
going to be insignificant compared with the total system-wide
suspend/resume time, so the optimizations will not likely be noticed for
system-wide suspend/resume.

However, if you would like to also implement runtime PM (and you
should), then the save/restore context for individual devices will start
to matter since for latency reasons, you will likely care about runtime
suspend/resume times for individual devices.

In that case however, the solution is use PM QoS constraints when there
are specific latency requirements so that the power-off of the device is
avoided in cases where latency constraints could not be met.

> Some device tree nodes have a property called "always-on" which is
> documented as "If present, the block is powered through an always-on
> power domain, therefore it never loses context."
>
> In that case, I suppose the driver's suspend/resume routine should:
>
> suspend:
> if (always-on is not present) {
>     save device registers to RAM;
> }
>
> resume:
> if (always-on is not present) {
>     restore device registers from RAM;
> }
>
> Do you disagree?

Yes.  I'm not a fan of using always-on for this.

Kevin

  parent reply	other threads:[~2016-06-10 22:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-07  8:56 Platform-specific suspend/resume code in drivers Mason
2016-06-07  8:56 ` Mason
2016-06-07 15:06 ` Alan Stern
2016-06-07 15:06   ` Alan Stern
2016-06-08 16:26   ` Mason
2016-06-08 16:26     ` Mason
2016-06-08 17:45     ` Alan Stern
2016-06-08 17:45       ` Alan Stern
2016-06-08 21:26       ` Mason
2016-06-08 21:26         ` Mason
2016-06-09 15:05         ` Alan Stern
2016-06-09 15:05           ` Alan Stern
2016-06-10 11:03           ` Mason
2016-06-10 11:03             ` Mason
2016-06-10 14:19             ` Alan Stern
2016-06-10 14:19               ` Alan Stern
2016-06-10 22:32             ` Kevin Hilman [this message]
2016-06-10 22:32               ` Kevin Hilman
2016-06-10 13:39           ` Geert Uytterhoeven
2016-06-10 13:39             ` Geert Uytterhoeven
2016-06-09  8:52       ` Sebastian Frias
2016-06-09  8:52         ` Sebastian Frias
2016-06-09 15:14         ` Alan Stern
2016-06-09 15:14           ` Alan Stern
2016-06-18 14:35         ` Pavel Machek
2016-06-18 14:35           ` Pavel Machek

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=m2k2hwwu7m.fsf@baylibre.com \
    --to=khilman@baylibre.com \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mans@mansr.com \
    --cc=mark.rutland@arm.com \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    --cc=sf84@laposte.net \
    --cc=slash.tmp@free.fr \
    --cc=stern@rowland.harvard.edu \
    --cc=ulf.hansson@linaro.org \
    --cc=viresh.kumar@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.