public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alexey Starikovskiy <aystarik@gmail.com>
Cc: Johannes Berg <johannes@sipsolutions.net>,
	Pekka Enberg <penberg@cs.helsinki.fi>,
	linux-pm@lists.linux-foundation.org, Pavel Machek <pavel@ucw.cz>,
	Nigel Cunningham <nigel@nigel.suspend2.net>
Subject: Re: Re: [PATCH] swsusp: do not use pm_ops (was: Re: suspend2 merge (was: Re: CFS and suspend2: hang in atomic copy))
Date: Wed, 2 May 2007 15:42:24 +0200	[thread overview]
Message-ID: <200705021542.24988.rjw@sisk.pl> (raw)
In-Reply-To: <8f8ff01d0705012213j54f15c4er2897731336b1ddb5@mail.gmail.com>

Hi,

On Wednesday, 2 May 2007 07:13, Alexey Starikovskiy wrote:
> Rafael,
> 
> On resume ACPI expects
> boot kernel do pm_prepare().
> resumed kernel do pm_finish() before device_resume().

Well, lets analyse what pm_prepare() actually does.  If my understading of
the code in there and the ACPI spec [1] is correct, it does the following:

(1) Sets the firmware waking vector (doesn't matter for hibernation)
(2) Prepares the wake-up devices for a state transition, by calling their _PSW
methods ("to enable wake" according to the spec)
(3) Disables the GPEs that cannot wake up the system
(4) Runs the _PTS and _GTS methods
(5) Runs the _SST method
(6) Disables all GPEs

Now, there's a couple of problems with that regardless of what it's used for,
as far as I can see:

a) The spec (in Section 7.2) says that (2) should be done *after* the _PTS
method is called

b) The spec (Section 7.3.2) says:

"This [_PTS] method is called after OSPM has notified native device drivers of
the sleep state transition and before the OSPM has had a chance to fully
prepare the system for a sleep state transition."

We don't seem to be doing this.  Moreover, Section 15.1.6 of the spec say that
"OSPM places all device drivers into their respective Dx state" *before* _PTS
is executed, so it doesn't look like _PTS should be executed before
device_suspend().

c) According to the spec (Section 15.1.6) "OSPM saves any other processor’s
context (other than the local processor) to memory" *after* executing _PTS,
but *before* _GTS is executed, but we do this after _GTS is executed.
Moreover, the waking vector should be written into FACS after the "other
processor’s context" has been saved, but *before* _GTS is executed.

d) The spec (Section 7.3.3) says literally this:

" _GTS allows ACPI system firmware to perform any required system specific
functions prior to entering a system sleep state. OSPM will set the sleep
enable (SLP_EN) bit in the PM1 control register immediately following the
execution of the _GTS control method without performing any other physical I/O
or allowing any interrupt servicing."

However, in our code _GTS is executed *waaay* before setting the SLP_EN bit
in PM1, which only happens in acpi_enter_sleep_state() called from
acpi_pm_enter(), *after* we've executed device_suspend() with IRQs enabled
and, in the hibernation case, called device_resume() and saved the image
(oh, dear).

e) It implicitly follows from d) that _SST should be executed before _GTS
and after we run device_suspend().

f) I'm not sure if the disabling of all GPEs before device_suspend() is
actually a good idea.

Next, we can consider acpi_pm_finish().  Again, if my understading of the code
in there and the ACPI spec [1] is correct, it does the following:

(7) Sets SLP_EN and SLP_TYPE to state S0
(8) Executes the _SST method (Waking)
(9) Executes the _BFS (Back From Sleep) method
(10) Executes the _WAK method
(11) Enables the runtime GPEs
(12) Enables the power button
(13) Executes the _SST method (Working)
(14) Disables the wake-up capability of devices
(15) Resets the firmware waking vector (doesn't matter for hibernation)

Now, there seems to be nothing wrong with that *if* it's executed while
resuming from RAM, for example, but it doesn't seem to be suitable for using
in such a way as we do this in the resume-during-hibernation code path.

Consider a hibernation (aka suspend to disk) transition (ie. an operation in
which we snapshot the system memory, save the image and shut the system down).

Currently, we call acpi_pm_prepare(PM_SUSPEND_DISK) and run device_suspend(),
which seems to be in many ways agaist the ACPI spec.  The spec, as I understand
it, indicates that we should run device_suspend() first and then execute the
_PTS method.  We shouldn't, however, execute either _GTS, or _SST just yet.

Next, we suspend sysdevs etc., and create the memory snapshot.  We want
to be able to save it, so w call acpi_pm_finish(), which causes _BFS and _WAK
to be executed *after* _GTS, which is clearly against the spec (might this be the
reason why (7) is sometimes necessary?).  Moreover, calling _BFS at this stage
makes no sense, IMHO, since there hasn't been any transition (the system has
not slept).  What I think we should do at this point is to execute _WAK only,
which means "power transition aborted" to the firmware, and continue with
device_resume().

Next, we save the image and now we'd like to put the system to "sleep", so
we use acpi_pm_enter(PM_SUSPEND_DISK), but we shouldn't do that, since the
power transition has been aborted by _WAK in acpi_pm_finish()!  Thus we should
start the transition again, run device_suspend(), execute _PTS, do (2) and (3),
save the "other processor's context" etc., execute _SST(S4), execute _GTS and
set SLP_EN in PM1 etc.

When we restore the system state from a hibernation image, the "boot kernel" is
first started.  It loads the image into memory, calls
device_suspend(PMSG_PRETHAW), suspends sysdevs etc., and replaces itself with
the "resumed kernel".  It doesn't call acpi_pm_prepare(), which I think is
right, because it doesn't want to start any power transition, not even a
fake one.  Now, the "resumed kernel" takes control, resumes sysdevs and calls
acpi_pm_finish(), which seems to be about OK, except that I'm not sure if _BFS
should be executed in that case (the ACPI spec seems to assume that the
hibernation image will be loaded into memory by a boot loader).

Concluding, it seems to me that the "restore" code path is correct, but the
"hibernate" code path is not and should be reworked.  Also, it seems that
acpi_pm_prepare() and acpi_pm_enter() should be fixed for the s2ram case
either (_PTS should be executed after device_suspend() and _GTS should
be executed in acpi_pm_enter(), right before the transition is completed).

Greetings,
Rafael


[1] Advanced Configuration and Power Interface Specification, Revision 3.0,
September 2, 2004

  reply	other threads:[~2007-05-02 13:42 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20070425072350.GA6866@ucw.cz>
     [not found] ` <Pine.LNX.4.64.0704251239110.8406@vaio.localdomain>
     [not found]   ` <alpine.LFD.0.98.0704251252070.9964@woody.linux-foundation.org>
     [not found]     ` <20070425202741.GC17387@elf.ucw.cz>
     [not found]       ` <alpine.LFD.0.98.0704251332090.9964@woody.linux-foundation.org>
     [not found]         ` <20070425214420.GG17387@elf.ucw.cz>
     [not found]           ` <alpine.LFD.0.98.0704251515140.9964@woody.linux-foundation.org>
     [not found]             ` <1177540027.5025.87.camel@nigel.suspend2.net>
     [not found]               ` <alpine.LFD.0.98.0704251550210.9964@woody.linux-foundation.org>
     [not found]                 ` <1177583998.6814.42.camel@johannes.berg>
     [not found]                   ` <20070426113005.GU17387@elf.ucw.cz>
2007-04-26 16:31                     ` suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy) Johannes Berg
2007-04-26 18:40                       ` Rafael J. Wysocki
2007-04-26 18:40                         ` Johannes Berg
     [not found]                         ` <1177612802.6814.121.camel@johannes.berg>
2007-04-26 19:02                           ` Rafael J. Wysocki
     [not found]                           ` <200704262102.38568.rjw@sisk.pl>
2007-04-27  9:41                             ` Johannes Berg
     [not found]                             ` <1177666915.7828.35.camel@johannes.berg>
2007-04-27 10:09                               ` Johannes Berg
2007-04-27 10:18                               ` Rafael J. Wysocki
     [not found]                               ` <200704271218.07120.rjw@sisk.pl>
2007-04-27 10:19                                 ` Johannes Berg
     [not found]                                 ` <1177669179.7828.53.camel@johannes.berg>
     [not found]                                   ` <200704271409.56687.rjw@sisk.pl>
2007-04-27 12:07                                     ` Johannes Berg
2007-04-27 12:09                                   ` Rafael J. Wysocki
2007-04-29 12:48                       ` [PATCH] swsusp: do not use pm_ops (was: Re: suspend2 merge (was: Re: CFS and suspend2: hang in atomic copy)) R. J. Wysocki
2007-04-29 12:53                         ` Rafael J. Wysocki
2007-04-30  8:29                         ` Johannes Berg
2007-04-30 14:51                           ` Rafael J. Wysocki
2007-04-30 14:59                             ` Johannes Berg
2007-05-01 14:05                               ` Rafael J. Wysocki
2007-05-01 22:02                                 ` Rafael J. Wysocki
2007-05-02  5:13                                   ` Alexey Starikovskiy
2007-05-02 13:42                                     ` Rafael J. Wysocki [this message]
2007-05-02 14:11                                       ` Alexey Starikovskiy
2007-05-02 19:26                                         ` ACPI code in platform mode hibernation code paths (was: Re: [PATCH] swsusp: do not use pm_ops) Rafael J. Wysocki
     [not found]                                         ` <200705022126.47897.rjw@sisk.pl>
2007-05-03 22:48                                           ` Pavel Machek
     [not found]                                           ` <20070503224807.GD13426@elf.ucw.cz>
2007-05-03 23:14                                             ` Rafael J. Wysocki
2007-05-04 10:54                                             ` Johannes Berg
     [not found]                                             ` <1178276072.7408.7.camel@johannes.berg>
2007-05-04 12:08                                               ` Pavel Machek
     [not found]                                               ` <20070504120802.GF13426@elf.ucw.cz>
2007-05-04 12:29                                                 ` Rafael J. Wysocki
2007-05-02  8:21                                   ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: suspend2 merge (was: Re: CFS and suspend2: hang in atomic copy)) Johannes Berg
2007-05-02  9:02                                     ` Rafael J. Wysocki
2007-05-02  9:16                                     ` Pavel Machek
2007-05-02  9:25                                       ` Johannes Berg
2007-05-03 14:00                                         ` Alan Stern
2007-05-03 17:17                                           ` Rafael J. Wysocki
2007-05-03 18:33                                             ` Alan Stern
2007-05-03 19:47                                               ` Rafael J. Wysocki
2007-05-03 19:59                                                 ` Alan Stern
2007-05-03 20:21                                                   ` Rafael J. Wysocki
2007-05-04 14:40                                                     ` Alan Stern
2007-05-04 20:20                                                       ` Rafael J. Wysocki
2007-05-04 20:21                                                         ` Johannes Berg
2007-05-04 20:55                                                           ` Pavel Machek
2007-05-04 21:08                                                             ` Johannes Berg
2007-05-04 21:15                                                               ` Pavel Machek
2007-05-04 21:53                                                                 ` Rafael J. Wysocki
2007-05-04 21:53                                                                   ` Johannes Berg
2007-05-04 22:25                                                                     ` Rafael J. Wysocki
2007-05-05 15:52                                                                   ` Alan Stern
2007-05-07  1:16                                                                     ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: ...) David Brownell
2007-05-07 21:00                                                                       ` Rafael J. Wysocki
2007-05-07 21:45                                                                         ` David Brownell
2007-05-07 22:16                                                                           ` Rafael J. Wysocki
2007-05-09 19:23                                                                             ` David Brownell
2007-05-04 21:06                                                           ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: suspend2 merge (was: Re: CFS and suspend2: hang in atomic copy)) Rafael J. Wysocki
2007-05-04 20:58                                                       ` Pavel Machek
2007-05-04 21:24                                                         ` Rafael J. Wysocki
2007-05-05 16:19                                                           ` Alan Stern
2007-05-05 17:46                                                             ` Rafael J. Wysocki
2007-05-05 21:42                                                               ` Alan Stern
2007-05-05 22:14                                                                 ` Rafael J. Wysocki
2007-05-04 21:40                                                       ` David Brownell
2007-05-04 22:19                                                         ` Rafael J. Wysocki
2007-05-07  1:05                                                           ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: ...)) David Brownell
2007-05-05 16:08                                                         ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: suspend2 merge (was: Re: CFS and suspend2: hang in atomic copy)) Alan Stern
2007-05-05 17:50                                                           ` Rafael J. Wysocki
2007-05-05 21:43                                                             ` Alan Stern
2007-05-05 22:16                                                               ` Rafael J. Wysocki
2007-05-07  1:31                                                           ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: ...) David Brownell
2007-05-07 16:33                                                             ` Alan Stern
2007-05-07 20:49                                                               ` Pavel Machek
2007-05-07 21:38                                                                 ` Alan Stern
2007-05-08  0:30                                                                   ` Pavel Machek
2007-05-03 20:33                                               ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: suspend2 merge (was: Re: CFS and suspend2: hang in atomic copy)) David Brownell
2007-05-03 20:33                                           ` David Brownell
2007-05-03 20:51                                             ` Rafael J. Wysocki
2007-05-04 14:51                                             ` Alan Stern
2007-05-04 14:56                                               ` Johannes Berg
2007-05-04 20:27                                                 ` Rafael J. Wysocki
2007-05-04 22:00                                               ` David Brownell
2007-05-05 15:49                                                 ` Alan Stern
2007-05-07  1:10                                                   ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: ...)) David Brownell
2007-05-07 18:46                                                     ` Alan Stern
2007-05-07 21:29                                                       ` Rafael J. Wysocki
2007-05-07 22:22                                                         ` Alan Stern
2007-05-07 22:47                                                           ` Rafael J. Wysocki
2007-05-08 14:56                                                             ` Alan Stern
2007-05-08 19:59                                                               ` Rafael J. Wysocki
2007-05-08 21:26                                                                 ` Alan Stern
2007-05-09  8:17                                                               ` Pavel Machek
2007-05-09 15:21                                                                 ` Alan Stern
2007-05-09 19:35                                                               ` David Brownell
2007-05-09 20:04                                                                 ` Alan Stern
2007-05-09 20:21                                                                   ` David Brownell
2007-05-10 15:17                                                                     ` Alan Stern
2007-05-09 21:07                                                                   ` Pavel Machek
2007-05-07 21:43                                                       ` David Brownell
2007-05-07 22:41                                                         ` Alan Stern
2007-05-03 22:18                                           ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: suspend2 merge (was: Re: CFS and suspend2: hang in atomic copy)) Pavel Machek
2007-05-04 14:57                                             ` Alan Stern
2007-05-04 20:50                                               ` Rafael J. Wysocki
2007-05-04 20:49                                                 ` Johannes Berg
2007-05-04 21:11                                                   ` Rafael J. Wysocki
2007-05-04 21:23                                                     ` Johannes Berg
2007-05-04 21:55                                                       ` Rafael J. Wysocki
2007-05-04 21:54                                                         ` Johannes Berg
2007-05-04 22:21                                                           ` Rafael J. Wysocki
2007-05-05 15:37                                                             ` Alan Stern
2007-05-05 18:49                                                               ` Rafael J. Wysocki
2007-05-05 21:44                                                                 ` Alan Stern
2007-05-05 22:36                                                                   ` Rafael J. Wysocki
2007-05-06 22:01                                                                     ` Alan Stern
2007-05-06 22:31                                                                       ` Rafael J. Wysocki
2007-05-07  1:37                                                                       ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: ..) David Brownell
2007-05-08  2:57                                                                         ` Greg KH
2007-05-07  8:51                                                                 ` Re: [PATCH] swsusp: do not use pm_ops (was: Re: suspend2 merge (was: Re: CFS and suspend2: hang in atomic copy)) Johannes Berg
2007-05-04 22:12                                                         ` David Brownell
2007-05-04 22:31                                                           ` Rafael J. Wysocki
2007-05-05 16:15                                                       ` Alan Stern
2007-05-02 13:43                                       ` Rafael J. Wysocki

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=200705021542.24988.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=aystarik@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=nigel@nigel.suspend2.net \
    --cc=pavel@ucw.cz \
    --cc=penberg@cs.helsinki.fi \
    /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