Difference between revisions of "ACPI Wakeup"

From MythTV Official Wiki
Jump to: navigation, search
(Kernel 2.6.22+ and /sys/class/rtc/rtc0/wakealarm)
Line 1: Line 1:
'''The wakeup call for your mythTV machine:'''
+
{| cellspacing=0 cellpadding=2 border=0
 
+
|width=22|{{Click || image=Go-up.png | link=System_wakeup | width=22px | height=22px}}
The BIOS on your computer’s motherboard will typically allow you to wake up your computer without additional hardware. More or less any modern machine should have a function for time-controlled booting.
+
|[[System_wakeup|System Wakeup]]
 
+
|}
The problem is how to change the wakeup time for time-controlled power up on Linux – different manufacturers and BIOS revisions mean applying different approaches as no one method is ideal for all. For example, ACPI wakeup does not work on many motherboards due to different implementations of the standard.
+
 
+
In contrast to this, NVRAM
+
wakeup can use non-volatile memory, that is the memory where the BIOS stores its data, to allow direct editing of the wakeup time. Of course, this
+
assumes that you find the right memory location, and that your BIOS actually notices that the values have changed.
+
 
+
 
+
Many MythTV users leave their backend (recording) servers running 24X7 and only power their front ends on and off. Being of a green disposition I wanted to avoid this, as even the best computers consume a reasonable amount of electricity just sitting there. There are various options available under Linux to wake your machine up from a sleep state.
+
 
+
== Nvram wakeup ==
+
 
+
The normal way of getting MythTV to power up the machine on a recording schedule is to use nvram-wakeup [[Shutdown Wakeup]]. However I was not very happy with this as direct poking of the systems Non Volatile RAM seems very dangerous to me, plus it involves a lot of messing around with custom kernels etc. Plus it just did not work for my  ECS Mother Board.
+
 
+
== Advanced Configuration and Power Interface (ACPI) ==
+
 
+
The PC Industry have been moving from the older APM power managment specification to the newer ACPI specification.  If your computer has a BIOS date more recent than 1999 and you are using a 2.6 kernel then ACPI support will most likely be enabled.
+
 
+
I have chosen to go with using ACPI to have my MythTV box wakeup while I am away , record a programme and then power itself  back down. You will find the ACPI features for your machine exposed as a collection of files and directories in /proc/acpi. For instance /proc/acpi/alarm is a file that corresponds to the Real Time Clock wakeup function on your machine.
+
 
+
Note that beginning with Linux kernel 2.6.22, /proc/acpi/alarm has been deprecated and replaced with /sys/class/rtc/rtc0/wakealarm.
+
 
+
== Activating ACPI support when compiling your own kernel ==
+
The setup of /proc/acpi/alarm is done in kernel file drivers/acpi/sleep/proc.c and controlled by the CONFIG_ACPI_SLEEP_PROC_FS flag.
+
You can test support for you architecture by going to you kernel source and do:
+
$grep -r CONFIG_ACPI_SLEEP_PROC_FS arch/*
+
  arch/x86_64/defconfig:CONFIG_ACPI_SLEEP_PROC_FS=y
+
 
+
{{Note box|To enable acpi-sleep in the kernel, it is necessary to set "Support for hot-pluggable CPUs}}
+
( Processor type and features  ---> [*] Support for hot-pluggable CPUs) so that
+
"CONFIG_HOTPLUG_CPU=y" in the ".config" file. After this it is possible to set
+
([*]  Sleep States) under ACPI support.
+
  
 
== BIOS Setup ==
 
== BIOS Setup ==
Line 39: Line 8:
 
You will need to have a motherboard that supports both ACPI and a Real Time Clock Alarm Functions in the BIOS. Dont forget to enable this in the BIOS. You will find  a tab  similar to "Advanced Power management".
 
You will need to have a motherboard that supports both ACPI and a Real Time Clock Alarm Functions in the BIOS. Dont forget to enable this in the BIOS. You will find  a tab  similar to "Advanced Power management".
  
On a via epia EN15000 board, and on ASUS M2N boards, you need to -disable- the Wake on RTC in the BIOS for the ACPI way to work. One observation is that only then does a programmed Wake on RTC also survive a reboot, otherwise it keeps getting reset. This might be an clue to others in the same situation.
+
The wake-up function is provided on most modern boards by the ability to "wake from RTC alarm" - setting a date and time in BIOS will cause the computer to power itself on and boot at the set time. This setting is likely found under a sub-menu of "Power Management" "APM", or "Advanced" - you just need to poke around to find it. It will likely be called something like Wake from RTC, Wake From Alarm, RTC Resume, etc.
 +
{{Tip box|On many boards, when this setting is enabled, it will wake only from a time set and saved from BIOS setup, and not from a time set outside of the BIOS setup environment - as we want. All of the boards the original author of this document needed this setting disabled to correctly wake with ACPI. This is the recommended starting point.}}
  
 
== Testing ACPI Wakeup Works ==
 
== Testing ACPI Wakeup Works ==
Line 188: Line 158:
 
</pre>
 
</pre>
  
=== Fussy Bios II ===
+
{{Tip box|For some motherboards, like the MS-6760 (MSI MEGA 651), it is required that you set the wakeup time two times, otherwise it will not wake up.
For some motherboards, like the MS-6760 (MSI MEGA 651), it is required that you set the wakeup time two times, otherwise it will not wake up.
+
  #echo "2005-12-29 10:10:04" >/proc/acpi/alarm && sleep 1 && echo "2005-12-29 10:10:04" >/proc/acpi/alarm}}
  #echo "2005-12-29 10:10:04" >/proc/acpi/alarm && sleep 1 && echo "2005-12-29 10:10:04" >/proc/acpi/alarm
+
  
 
Another possible glitch is, that the option 'Resume By Alarm' (or whatever it is called) is set to ''Enabled'' but wake up using <code>/proc/acpi/alarm</code> only works if the option is set to ''Disabled''. Sounds weird but works with some boards.
 
Another possible glitch is, that the option 'Resume By Alarm' (or whatever it is called) is set to ''Enabled'' but wake up using <code>/proc/acpi/alarm</code> only works if the option is set to ''Disabled''. Sounds weird but works with some boards.
 
== Alternative to NVRAM-WAKEUP: ACPI-WAKEUP ==
 
 
For those of you not comfortable poking around into NVRAM (as nvram-wakeup does) - or if your motherboard isn't supported, try acpi-wakeup.  This little gem is command line compatible (drop in replacement) with nvram-wakeup.  This application however uses the ACPI interface only - so 100% compatability!
 
 
What's more, this program will use either the passed time parameter OR the time for next mythfilldatabase wakeup in your mythconverg database (whichever comes first)!  Smart program!
 
 
You can download it at www.generationd.com.
 
  
 
== User experience  ==
 
== User experience  ==
Line 206: Line 167:
 
{{Click || image=moosy.gif | link=:User:Moosylog | width=55px | height=20px}} spent hours on ACPI on his MSI RS482M-IL board. Not working, system never wakes-up. (march 2007)
 
{{Click || image=moosy.gif | link=:User:Moosylog | width=55px | height=20px}} spent hours on ACPI on his MSI RS482M-IL board. Not working, system never wakes-up. (march 2007)
  
[[User:Turpie]]: Works great with the [[Asus M2NPV-VM]].
+
[[User:Turpie|Turpie]]: Works great with the [[Asus M2NPV-VM]].
  
 
[[User:Murph|Murph]] 09:03, 20 April 2007 (UTC)Works also great with the Legend QDI Advance 5/133E.
 
[[User:Murph|Murph]] 09:03, 20 April 2007 (UTC)Works also great with the Legend QDI Advance 5/133E.
  
[[User:mythwog]]: No problems with [[ECS PT890T-A]]. Simply wrote wake up time to /proc/acpi/alarm, halted, and system wakes up.
+
[[User:mythwog|mythwog]]: No problems with [[ECS PT890T-A]]. Simply wrote wake up time to /proc/acpi/alarm, halted, and system wakes up.
 +
 
 +
[[User:Fuchur|Fuchur]] 00:52, 13 August 2007 (UTC) had to replace the wakeup  script with the one from http://www.mythwiki.de/index.php?title=HOWTO_Mythwelcome as my mythshutdown produces another time format. Otherwise it seems to work so far.
  
--[[User:Fuchur|Fuchur]] 00:52, 13 August 2007 (UTC) had to replace the wakeup script with the one from http://www.mythwiki.de/index.php?title=HOWTO_Mythwelcome as my mythshutdown produces another time format. Otherwise it seems to work so far.
+
[[User:Mattwire|Mattwire]] 04 September 2007. Works fine with MSI K8NGM2-FID and NC6120 laptop running Ubuntu Feisty and Gutsy.  Both require modification to /etc/init.d/hwclock.sh to save the wakeup time.
  
 
== Additional source of info ==
 
== Additional source of info ==
  
 +
{{Webpage|https://help.ubuntu.com/community/MythTV/Install/WhatNext/ACPIWake|https://help.ubuntu.com/community/MythTV/Install/WhatNext/ACPIWake}}
 
{{Webpage|acpi.sourceforge.net/documentation/alarm.html|http://acpi.sourceforge.net/documentation/alarm.html}}
 
{{Webpage|acpi.sourceforge.net/documentation/alarm.html|http://acpi.sourceforge.net/documentation/alarm.html}}
  
Line 222: Line 186:
 
{{Pdf|www.linux-magazine.com/issue/46/Wakeup_Call_For_Computers.pdf|Very good article about wakeup, Linux Magazine}}
 
{{Pdf|www.linux-magazine.com/issue/46/Wakeup_Call_For_Computers.pdf|Very good article about wakeup, Linux Magazine}}
  
 +
= Extra Information =
 +
== Background to Advanced Configuration and Power Interface (ACPI) ==
  
 +
The PC Industry have been moving from the older APM power managment specification to the newer ACPI specification.  If your computer has a BIOS date more recent than 1999 and you are using a 2.6 kernel then ACPI support will most likely be enabled.
 +
 +
I have chosen to go with using ACPI to have my MythTV box wakeup while I am away , record a programme and then power itself  back down. You will find the ACPI features for your machine exposed as a collection of files and directories in /proc/acpi. For instance /proc/acpi/alarm is a file that corresponds to the Real Time Clock wakeup function on your machine.
 +
 +
Note that beginning with Linux kernel 2.6.22, /proc/acpi/alarm has been deprecated and replaced with /sys/class/rtc/rtc0/wakealarm.
 +
 +
== Activating ACPI support when compiling your own kernel ==
 +
The setup of /proc/acpi/alarm is done in kernel file drivers/acpi/sleep/proc.c and controlled by the CONFIG_ACPI_SLEEP_PROC_FS flag.
 +
You can test support for you architecture by going to you kernel source and do:
 +
$grep -r CONFIG_ACPI_SLEEP_PROC_FS arch/*
 +
  arch/x86_64/defconfig:CONFIG_ACPI_SLEEP_PROC_FS=y
 +
 +
{{Note box|To enable acpi-sleep in the kernel, it is necessary to set "Support for hot-pluggable CPUs}}
 +
( Processor type and features  ---> [*] Support for hot-pluggable CPUs) so that
 +
"CONFIG_HOTPLUG_CPU=y" in the ".config" file. After this it is possible to set
 +
([*]  Sleep States) under ACPI support.
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
 +
[[Category:Wakeup]]

Revision as of 12:30, 4 September 2007

System Wakeup

BIOS Setup

You will need to have a motherboard that supports both ACPI and a Real Time Clock Alarm Functions in the BIOS. Dont forget to enable this in the BIOS. You will find a tab similar to "Advanced Power management".

The wake-up function is provided on most modern boards by the ability to "wake from RTC alarm" - setting a date and time in BIOS will cause the computer to power itself on and boot at the set time. This setting is likely found under a sub-menu of "Power Management" "APM", or "Advanced" - you just need to poke around to find it. It will likely be called something like Wake from RTC, Wake From Alarm, RTC Resume, etc.

Information.png Tip: On many boards, when this setting is enabled, it will wake only from a time set and saved from BIOS setup, and not from a time set outside of the BIOS setup environment - as we want. All of the boards the original author of this document needed this setting disabled to correctly wake with ACPI. This is the recommended starting point.

Testing ACPI Wakeup Works

Here are the commands to check that you have ACPI working.

$powersave -S
  ACPI

Check that you have the alarm function in /proc/acpi/alarm. This prints out the RTC Alarm clock from the BIOS.

$cat /proc/acpi/alarm
 2005-**-29 10:10:04

Check that you can write a new time to the RTC Clock Alarm (you will need to be Root) Format is YYYY-MM-DD HH:MM:SS

#echo "2005-12-29 10:10:04" >/proc/acpi/alarm

Check that it was written, shut down and wait for it to wakeup.

#cat /proc/acpi/alarm
 2005-*12-29 10:10:04 
#shutdown -h now


Important.png Note: You may not see the change in the bios, but it should still work

Now go to Mythtv-Setup and setup wakeup and shutdown parameters.

Kernel 2.6.22+ and /sys/class/rtc/rtc0/wakealarm

Beginning with kernel 2.6.22 /proc/acpi/alarm has been removed and replaced with /sys/class/rtc/rtc0/wakealarm. This will affect Fedora 7 users. The key differences with the wakealarm interface are:

  1. Instead of accepting a formatted time, wakealarm accepts the number of seconds since Jan 1, 1970.
  2. If you want to change the wakealarm time, you first need to reset the time.
  3. You have to make sure that your bios clock is set to UTC time not localtime otherwise it will wakeup at the wrong time

This acpi-alarm script will function with the new sys wakealarm interface or the old acpi/alarm interface

#!/bin/sh
# $1 is the --settime switch that nvram-wakeup normally expects
# $2 is the date/time in seconds since 1970

DATE=`date -d "1970-01-01 $2 sec" "+%F %H:%M:%S" -u`
SECS=`date -d "1970-01-01 $2 sec" "+%s" -u`

# Save the wakeup time
echo "$*"  > /myth.wakeup.args
echo $DATE > /myth.wakeup.time
echo $SECS > /myth.wakeup.secs

if [ -e /sys/class/rtc/rtc0/wakealarm ]; then
        echo 0 > /sys/class/rtc/rtc0/wakealarm
        echo $SECS > /sys/class/rtc/rtc0/wakealarm
fi
if [ -e /proc/acpi/alarm ]; then
        echo $DATE > /proc/acpi/alarm
fi

If leaving the RTC wakeup alarm on the BIOS worked with the old interface, you may need to disable it when migrating to the new interface.

Trouble Shooting

Getting autostart using alarm can be quite frustrating. Here's some tips on getting it working.

UTC Bios Clock

Remember, your bios time might be in UTC rather than local time using:

  # echo "+00-00-00 00:05:00" > /proc/acpi/alarm 

will set the wakeup time to 5 minute from now, regardless of whether the RTC is in UTC or locatltime.

Since the wake-up time given by mythtv to the mythtv wakeup command is in local time, you need to do some bash handling of the obtained time to be able to setup the wakeup time in the bios in UTC (independent of daylight savings time and such). The following bash code might help here:

#!/bin/bash
stamp_file=/home/mythtv/timestamp
echo $1\ $2 > $stamp_file
# If using mythwelcome you can try the next line instead on the one above.
#echo $1 | sed "s/T/ /" >$stamp_file
# Read the date in the locale time format and add the time-zone info to the stamp_file
datum=$(/bin/date -f $stamp_file +%F\ %T\ %z)
echo $datum > $stamp_file
# reinterpret this in utc and write to alarm
utcdatum=$(/bin/date -u -f $stamp_file +%F\ %T)
echo $utcdatum > $stamp_file
#rm -f $stamp_file
#echo $utcdatum >/proc/acpi/alarm


As you noticed the echo to the acpi-alarm is commented out by default, because it is really better to check first if everything is working correctly (time format the same on your bios and such).

An alternative script to the above is the following:

#!/bin/bash
stamp_file=/home/mythtv/timestamp

#just log what we get as command line parameters
echo $1 $2 $3> $stamp_file

#i setted mythtv to output the number of seconds since epoch
#so i calculate the number of hours, minutes and seconds from
#now the computer has to wakeup:
sfn=$(($2 - `date +"%s"`))

#and then send it to /proc/acpi/wakeup in the format we saw above
y=`(echo $(($sfn - 3600))|awk '{print strftime("+00-00-00 %H:%M:%S", $1)}')`

echo "$y">/proc/acpi/alarm
echo "$y">>$stamp_file
echo "executed at `date`" >> $stamp_file
exit

This works on a lot of different EPIA and ASUS Motherboards, and is not dependent on the timezone you use in the bios.

Fussy Bios

Some motherboard bioses are extremely fussy when setting the wake up alarm. These bioses refuse to wake up if the hardware clock is modified after the alarm timer has been set. Most linux distributions do this by default when shutting down (they write the current system time back to the hardware clock). This causes the system never to wake up.

Hence check your shutdown scripts!

Under ubuntu/debian modifying /etc/init.d/hwclock.sh with the following will fix this problem:

       stop|restart|reload|force-reload)

==>         ACPITIME=`cat /proc/acpi/alarm`
                if [ "$HWCLOCKACCESS" != no ]
                then
                    if [ "$VERBOSE" != no ]
                    then
                        echo "Saving the System Clock time to the Hardware Clock..."
                    fi
                    [ "$GMT" = "-u" ] && GMT="--utc"
                        /sbin/hwclock --systohc $GMT $BADYEAR
                    if [ "$VERBOSE" != no ]
                    then
                        echo "Hardware Clock updated to `date`."
                    fi
==>              echo "$ACPITIME" > /proc/acpi/alarm

Under Fedora Core 6 modifying /etc/init.d/halt with the following will fix this problem:


==>  ACPITIME=`cat /proc/acpi/alarm`

     [ -x /sbin/hwclock ] && action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
                
==>  echo "$ACPITIME" > /proc/acpi/alarm


Information.png Tip: For some motherboards, like the MS-6760 (MSI MEGA 651), it is required that you set the wakeup time two times, otherwise it will not wake up.

#echo "2005-12-29 10:10:04" >/proc/acpi/alarm && sleep 1 && echo "2005-12-29 10:10:04" >/proc/acpi/alarm

Another possible glitch is, that the option 'Resume By Alarm' (or whatever it is called) is set to Enabled but wake up using /proc/acpi/alarm only works if the option is set to Disabled. Sounds weird but works with some boards.

User experience

   
:User:Moosylog
spent hours on ACPI on his MSI RS482M-IL board. Not working, system never wakes-up. (march 2007)

Turpie: Works great with the Asus M2NPV-VM.

Murph 09:03, 20 April 2007 (UTC)Works also great with the Legend QDI Advance 5/133E.

mythwog: No problems with ECS PT890T-A. Simply wrote wake up time to /proc/acpi/alarm, halted, and system wakes up.

Fuchur 00:52, 13 August 2007 (UTC) had to replace the wakeup script with the one from http://www.mythwiki.de/index.php?title=HOWTO_Mythwelcome as my mythshutdown produces another time format. Otherwise it seems to work so far.

Mattwire 04 September 2007. Works fine with MSI K8NGM2-FID and NC6120 laptop running Ubuntu Feisty and Gutsy. Both require modification to /etc/init.d/hwclock.sh to save the wakeup time.

Additional source of info

Webpage.png - https://help.ubuntu.com/community/MythTV/Install/WhatNext/ACPIWake

Webpage.png - http://acpi.sourceforge.net/documentation/alarm.html

Webpage.png - http://www.vdr-wiki.de/wiki/index.php/ACPI_Wakeup

Document.png - Very good article about wakeup, Linux Magazine

Extra Information

Background to Advanced Configuration and Power Interface (ACPI)

The PC Industry have been moving from the older APM power managment specification to the newer ACPI specification. If your computer has a BIOS date more recent than 1999 and you are using a 2.6 kernel then ACPI support will most likely be enabled.

I have chosen to go with using ACPI to have my MythTV box wakeup while I am away , record a programme and then power itself back down. You will find the ACPI features for your machine exposed as a collection of files and directories in /proc/acpi. For instance /proc/acpi/alarm is a file that corresponds to the Real Time Clock wakeup function on your machine.

Note that beginning with Linux kernel 2.6.22, /proc/acpi/alarm has been deprecated and replaced with /sys/class/rtc/rtc0/wakealarm.

Activating ACPI support when compiling your own kernel

The setup of /proc/acpi/alarm is done in kernel file drivers/acpi/sleep/proc.c and controlled by the CONFIG_ACPI_SLEEP_PROC_FS flag. You can test support for you architecture by going to you kernel source and do:

$grep -r CONFIG_ACPI_SLEEP_PROC_FS arch/*
 arch/x86_64/defconfig:CONFIG_ACPI_SLEEP_PROC_FS=y


Important.png Note: To enable acpi-sleep in the kernel, it is necessary to set "Support for hot-pluggable CPUs

( Processor type and features  ---> [*] Support for hot-pluggable CPUs) so that
"CONFIG_HOTPLUG_CPU=y" in the ".config" file. After this it is possible to set
([*]   Sleep States) under ACPI support.