View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 6 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Sun Oct 25, 2009 4:43 am 
Offline
Joined: Mon Sep 28, 2009 5:42 am
Posts: 50
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, http://en.opensuse.org/NVidia_Suspend_HOWTO. I have
Code:
 Option         "NvAGP" "1"
in the Device section of /etc/X11/xorg.conf. Also in /etc/modprobe.conf I have
Code:
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
Code:
sudo pacman -Sy pm-utils


In /etc/pm/config.d/modules
Code:
# 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)
Code:
#!/bin/bash

RUNSV_SERVICES="lcdd lircd mythbackend"
suspend_services()
{
        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
                fi
        done
}
resume_services()
{
        for sv in $RUNSV_SERVICES; do
                sv up $sv
        done
}
case "$1" in
        hibernate|suspend)
                suspend_services
                ;;
        thaw|resume)
                resume_services
                ;;
        *) exit $NA
                ;;
esac
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
Code:
sudo pm-suspend


mythtv setup
Main references http://www.mythtv.org/wiki/index.php/ACPI_Wakeup and http://www.mythtv.org/wiki/index.php/Mythwelcome

In mythtv-setup Shutdown/Wakeup settings
Code:
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
Code:
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:
Code:
#!/bin/bash
# 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:
Code:
#!/bin/bash
# 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.

Debugging
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
Code:
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm
this checks the current bios info
Code:
cat /proc/driver/rtc
Reboot (or suspend) to test.

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 26, 2009 4:35 am 
Offline
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location: Germany
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?

_________________
ASUS AT3N7A-I (Atom 330)
TBS 8922 PCI (DVB-S2)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 27, 2009 4:54 am 
Offline
Joined: Mon Sep 28, 2009 5:42 am
Posts: 50
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 29, 2009 7:22 pm 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location: California
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?

Thanks.

_________________
Marc

The views expressed are my own and do not necessarily reflect the views of my employer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 09, 2009 7:49 pm 
Offline
Joined: Mon Sep 28, 2009 5:42 am
Posts: 50
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 21, 2009 3:35 pm 
Offline
Joined: Mon Oct 02, 2006 9:56 am
Posts: 3
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!


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu