LinHES Forums

R6 suspend/resume with pm-utils
Page 1 of 1

Author:  bigtoedsloth [ Sun Oct 25, 2009 4:43 am ]
Post subject:  R6 suspend/resume with pm-utils

This is really for power-saving purposes. Suspend to ram, rather than shutdown/reboot is much faster and makes for a better experience. There are a couple of tricks (waiting for services to terminate and waiting for mythbackend to accept connections) that might be more generally useful.

I have a combined frontend/backend. I'm running an nvidia graphics card, Hauppauge Nova-T 500 tuner and an Imon LCD/IR module (the one that comes with one of the first Antec Fusion Black). I use tools from the pm-utils and net-tools packages.

Graphics Card Setup
See, for instance, I have
 Option         "NvAGP" "1"
in the Device section of /etc/X11/xorg.conf. Also in /etc/modprobe.conf I have
blacklist intel_agp

pm-utils setup
The pm-utils setup makes sure that everything that can't survive a suspend/resume cycle gets shutdown cleanly before the suspend and brought back up after resume. In my case both the tuner and lirc kernel modules need to be explicitly removed. This means shutting down the lirc, lcdd and mythbackend processes before removing the modules.

Make sure that pm-utils are installed
sudo pacman -Sy pm-utils

In /etc/pm/config.d/modules
# Modules that need to be unloaded before suspend
SUSPEND_MODULES="lirc_imon dvb_usb_dib0700"
The existing pm-utils functions take care of properly removing and reinserting these modules.

In /etc/pm/sleep.d/20services (needs to have execute permission set)

RUNSV_SERVICES="lcdd lircd mythbackend"
        for sv in $RUNSV_SERVICES; do
                if [ -f /var/service/$sv/supervise/pid ]; then
                        pid=`cat /var/service/$sv/supervise/pid`
                        sv down $sv
                        while kill -0 $pid > /dev/null 2>&1; do sleep 0.1; done
        for sv in $RUNSV_SERVICES; do
                sv up $sv
case "$1" in
        *) exit $NA
Notice that I explicitly wait for each process to shutdown before moving on to the next (although I don't wait for them to start). This ensures that everything's actually stopped before the kernel modules are removed.

After making the graphics card changes and the pm-utils mods a manual call to pm-suspend (after shutting down mythfrontend) should work
sudo pm-suspend

mythtv setup
Main references and

In mythtv-setup Shutdown/Wakeup settings
Block shutdown before
    client connected:           checked
    Idletimeout (secs):         any value greater that 0
    Wakeup time format:         yyyy-MM-ddThh:mm
    Set wakeup time command:    mythshutdown --setwakeup $time
    Server Halt command:        mythshutdown --shutdown
    Pre shutdown check command: mythshutdown --check

In mythwelcome --setup
Command to Set Wakeup Time: /home/mythtv/bin/mythtv-wakeset $time
Wakeup time format: time_t
nvrm-wakeup Restart Command: (blank)
Comand to reboot: sudo /sbin/reboot
Command to shutdown: /home/mythtv/bin/mythtv-suspend
Command to run xterm: /usr/bin/mrxvt
Command to start the frontend: /usr/bin/mythfrontend

mythtv-wakeset looks like this:
# set mythtv wake-up time with UTC-adjusted time
DATE=`date -d "1970-01-01 $1 sec" "+%F %H:%M:%S" -u`
SECS=`date -d "1970-01-01 $1 sec" "+%s" -u`

# set the alarm
echo "Setting wakeup time."
echo "             Date: `date +"%F %T %z"`"
echo "            Input: $1"
echo "  Adjusted to UTC: $DATE  --  $SECS"
sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sudo sh -c "echo $SECS > /sys/class/rtc/rtc0/wakealarm"
echo "Time set."
cat /proc/driver/rtc

and mythtv-syspend looks like this:
# MythtTV suspend script

# First take down anything mythtfrontend-related
killall mythlcdserver
killall mythwelcome

# Suspend - this takes care of mythbackend
sudo pm-suspend

# Wait for the backend to accept connections
while !(netstat -pl 2>&1 | grep -q mythbackend); do sleep 0.1; done

# Bring up the frontend
export DISPLAY=:0.0
/usr/bin/mythwelcome &
Note the trick to make sure that the backend is up before starting the frontend. This prevents any annoying "Cannot connect to backend" messages. netstat is the program from the net-tools package. I think the package is installed by default.

You'll want to read the references that I've given, the appropriate man pages, plus Google (of course). Start by getting suspend/resume to work (figuring out which kernel modules need to be unloaded is fun), then make sure that the system bios will restart at the time you specify, then bringing mythtv into the mix should be straightforward.

A couple of useful snippets for checking that your motherboard bios is going to do the right thing: Manual test for reboot (as root). This sets the wakeup time 5 mins in the future
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm
this checks the current bios info
cat /proc/driver/rtc
Reboot (or suspend) to test.

The End
I think that's it. I'll edit if I remember anything else ...

Author:  alien [ Mon Oct 26, 2009 4:35 am ]
Post subject: 

Very cool! I didn't realise that rtc wakeup worked with suspend (last time I tried a couple of years ago it wouldn't work).

How did you determine which modules needed to be unloaded on your system?

Author:  bigtoedsloth [ Tue Oct 27, 2009 4:54 am ]
Post subject: 

alien wrote:
How did you determine which modules needed to be unloaded on your system?

Good question. In my case the remote, LCD and tuner didn't work on resume from suspend, so removing these modules (and the processes that depend on them) before suspending did the trick.

On my previous system (a different distribution) there was a module (ndiswrapper) which actually prevented the system from resuming properly. I didn't have that issue with LinHES, but I'm not running ndiswrapper now, either. The pm-suspend function is just a series of bash scripts, so what I ended up doing was adding in debugging statements until I could see what was going on.

Author:  marc.aronson [ Sun Nov 29, 2009 7:22 pm ]
Post subject: 

I would like to get suspend/resume working on my system, as I currently shut down the system to save power and it takes ~70 seconds to reboot. I do have a few questions:

1. How long does it take for everything to come up after a "resume"?

2. Have you had any problems with failed suspend or resumes?

3. Any thoughts as to weather or not this would work with R5.5?


Author:  bigtoedsloth [ Wed Dec 09, 2009 7:49 pm ]
Post subject: 

It takes my system about 10s to resume. I don't think that there's anything that's R6 specific about the method - apart from the use of pacman to install packages. I can't help with R5 problems, though. I have not had a single problem with suspend/resume under R6, which is a pleasant surprise.

Author:  dcy2 [ Mon Dec 21, 2009 3:35 pm ]
Post subject: 

Thanks for all the tips. The suspend part works beautifully on my Asus M2NPV-VM, but it apparently suspends just a little too well. The system won't respond to a keypress, WOL, timer, etc. I have to pull the power (and plug it back in) to get it to come back. Is there a safe way to install a more current version of pm-utils? I wondered if that might help this problem but don't want to mess too much with R6's pacman configuration and end up breaking something else. Thanks again!

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group