[Pm-utils] Question about hooks and suspend-hybrid.

Victor Lowther victor.lowther at gmail.com
Tue Jul 1 05:29:08 PDT 2008

On Tue, 2008-07-01 at 13:59 +0200, Stefan Seyfried wrote:
> Hi,
> Victor Lowther wrote:
> > A good guideline is "on a suspend_hybrid, run whichever of the suspend
> > or hibernate hooks saves the most state".  For the grub hook, that would
> > be the hibernate hook.  For the video hooks, that would be the suspend
> > hook.  
> Unfortunately, only the hooks themselves know what they are doing, so we need
> to give them a parameter to tell them we are going to do s2both.
> Am i correct in assuming that hooks should be called with "suspend_hybrid"
> during suspend, even though this is not implemented yet?

For that matter right now only two hooks care about the difference
between suspend and hibernate: the grub hook, and the video hook.  The
rest of them run the same code on both -- they only care about going to
sleep and waking up, and do not care how we are doing it.

> >> Actually looking at src/pm-action.in it seems that for suspend_hybrid, also
> >> plain "suspend" and "resume" actions are given to the hooks, but this is of
> >> course not entirely correct, and it is contrary to the documentation in
> >> HOWTO.hooks...
> > 
> > More like the documentation documents a case we do not yet handle, and
> > the code assumes that if anyone is actually using suspend_hybrid, in
> > practice it ends up being a normal suspend/resume cycle the majority of
> > the time.  Not a perfect way to handle things, granted, but without a
> > way of telling what mode we woke up from the least confusing to code
> > for.
> > 
> >> Might i suggest we use a "suspend_hybrid"/"resume_hybrid"-combination for
> >> telling the hooks what to do?
> > 
> > I do not think that a resume_hybrid flag is the right thing to do -- it
> > does not correspond to an actual wakeup state, we will always be either
> > resuming from suspend or hibernate.
> However, even if we resume from suspend, in the hybrid case i need to e.g.
> reset the stuff that was done by the grub hook (which needs to prepare for a
> possible s2disk).
> To do it 100% correct, we might need a "resume_hybrid" and a "thaw_hybrid"
> version. However, i'm not sure if this would not be seriously overengineered,
> since only very few hooks might need to something special in the hybrid case,
> and it probably will not really hurt to just do this all the time, even in the
> "normal" resume case.
> Another solution would be to give a second parameter to the hooks, like
> ./$hook suspend hybrid
> ...
> ./$hook resume hybrid
> Old and non-hybrid-aware hooks would just ignore the second parameter, hooks
> that need to know about hybrid can detect that it is there and act
> accordingly. How does that sound?

How about just passing $METHOD as the second parameter?  Less parsing
needed that way, and it sets the stage for some more hook simplification
in the future -- instead of this being our hook skeleton:


case $1 in
	suspend|hibernate) do_sleep_stuff ;;
	resume|thaw) do_wake_stuff ;;
	*) o_noes ;;

we can make this be out hook skeleton:


case $1 in
	suspend) do_sleep_stuff $2 ;;
	resume)  do_wake_stuff $2 ;;
	*) o_noes ;;

but that should be left for pm-utils 2.x or somewhere further down the

> > What we need is for the kernel to
> > actually be able to tell us that information so that we can run the
> > power hooks with the appropriate parameter for the state we are actually
> > waking up from.
> Well, i can code this in s2both. I need to overhaul the exit codes anyway.
> In-kernel suspend cannot do hybrid anyway AFAIK.

Depends on whether or not your in-kernel suspend is actually tuxonice in
disguise. :)

> So what i will be doing right now in my pm-utils version is:
>  - call hooks with "suspend_hybrid" during suspend
>  - call hooks with "resume", as if returning from s2ram. Some hooks will do
>    just a bit more in this case, which should not hurt.
> If we agree that the above 2-parameter version is better, i can quickly adapt
> to that, but i want to start testing real soon.

Does just passing $METHOD as the second parameter work for you?

> Thanks, and have fun,
> 	Stefan
Victor Lowther
Ubuntu Certified Professional

More information about the Pm-utils mailing list