免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2628 | 回复: 0
打印 上一主题 下一主题

ACPI Wakeup [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-06 16:44 |只看该作者 |倒序浏览

                ACPI Wakeup
From MythTV
Jump to:
navigation
,
search
   

System
Wakeup
Contents [
hide
]
1
Introduction
2 BIOS setup

3 Using /proc/acpi/alarm

4 Using
/sys/class/rtc/rtc0/wakealarm
5
Troubleshooting
5.1 Check your hardware

5.2 Check your linux
distribution
5.3 Check if interface
exists
5.4 Initiate manually

5.5 UTC or localtime

5.6 Disable hwclock updates (FUSSY
BIOS)
5.7 Set wakeup time two times (FUSSY
BIOS)
5.8 More glitches (FUSSY
BIOS)
6 Additional source of
info
7
Extra Information
    7.1 Activating ACPI support when
    compiling your own kernel

8
User experience

[
edit
]
Introduction
The Advanced Configuration and Power Interface (ACPI) specification is an
open industry standard first released in December 1996 developed by HP, Intel,
Microsoft, Phoenix, and Toshiba that defines common interfaces for hardware
recognition, motherboard and device configuration and power management.
The ACPI Real Time Clock Alarm Function can be used on your mythTV system to
wake-up your machine at a certain time and/or date.
If you don't have an ACPI-compliant BIOS, you could use
nvram-wakeup

instead, which is a small program which modifies the BIOS settings memory
(NVRAM) directly. All modern BIOSes should support ACPI, however.
[
edit
]
BIOS setup
You will most likely need to disable "wake from RTC alarm" option in your
BIOS. It will probably be called something like Wake from RTC, Wake From Alarm,
RTC Resume, etc.
[
edit
]
Using /proc/acpi/alarm

Note: The
/proc/acpci/alarm function was deprecated with kernel 2.6.22 onwards, so is only
available for Linux distributions earlier than opensuse10.2 etc. From 2.6.22
onwards Linux RTC has moved to /sys/class/RTC, however openSUSE 10.3 disabled
this due to major problems, do not upgrade to 10.3 if ACPI wakeup is needed.
Check if the wakeup function works: The commands set the wakeup time to 5
minute from now, regardless of whether the RTC is in UTC or locatltime and than
turns off the machine.
# echo "+00-00-00 00:05:00" > /proc/acpi/alarm
# shutdown -t now
If you're machine does not start 5 minutes later, check the following:
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. (Note: If you have a 2.6.22+ kernel, see next
section instead.)
$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

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.
For example (Assuming bios is in localtime):
Wakeup time format: yyyy-MM-dd hh:mm:ss
Set wakeuptime command: sudo sh -c 'echo $time > /proc/acpi/alarm'
[
edit
]
Using /sys/class/rtc/rtc0/wakealarm

openSUSE 10.3 has
/sys/class/rtc disabled in the kernel due to some
problems. Currently ACPI wakeup does not work with openSUSE 10.3.
Possible solution is to use a newer kernel or migrate to another version of
openSUSE.
Beginning with kernel 2.6.22 /proc/acpi/alarm has been removed and
replaced with /sys/class/rtc/rtc0/wakealarm. The key differences with the
wakealarm interface are:
  • Instead of accepting a formatted time, wakealarm accepts the number of
    seconds since Jan 1, 1970.
  • If you want to change the wakealarm time, you first need to reset the time.
  • 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.

    Warning: The wakealarm
    interface is incompatible with the kernel's old "Enhanced Real Time Clock
    Support" and "Generic /dev/rtc emulation" options. If your kernel was built with
    these enabled your kernel log will contain messages such as rtc_cmos: probe of 00:03 failed with error -16The solution is to
    rebuild your kernel with the above two options excluded (find them under Drivers
    -> Character Devices) and the various RTC interfaces (found under Drivers
    -> Real Time Clock) included. From a .config point of view CONFIG_RTC and
    CONFIG_GEN_RTC must be unset and, at a minimum, RTC_INTF_SYSFS must be set.

    Note: If you can't find
    /sys/class/rtc/rtc0/wakealarm, and you're running a modular kernel, it might be
    the case that the correct module is not loaded. In that case, make sure the rtc
    module is unloaded, and then load the rtc-cmos module: rmmod rtc
    modprobe rtc-cmos
    [
    edit
    ]
    Troubleshooting
    Getting autostart using alarm can be quite frustrating. Here's some tips on
    getting it working.
    [
    edit
    ]
    Check your hardware
    Check if your BIOS supports ACPI/RTC You will need to have a motherboard that
    supports both ACPI and a Real Time Clock Alarm Functions in the BIOS. Check your
    BIOS and look for 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.
    [
    edit
    ]
    Check your linux distribution
    Check your kernel version
    uname -a
    Kernel 2.6.22 and higher use /sys/class/rtc/rtc0/wakealarm
    Older kernels use /proc/acpi/alarm
    Check if ACPI is enabled in your kernel and working.
    $powersave -S
      ACPI
    [
    edit
    ]
    Check if interface exists
    Kernel 2.6.22 and higher use
    ls /sys/class/rtc/rtc0/wakealarm
    Older kernels
    ls /proc/acpi/alarm
    [
    edit
    ]
    Initiate manually
    The following example will set the wakeup time to 5 minute from now,
    regardless of whether the RTC is in UTC or locatltime. You may not see the
    change in the bios, but it should still work.
    if you are using the /proc/acpi/alarm interface echo "+00-00-00 00:05:00" > /proc/acpi/alarm
    Check that it was written, the format is YYYY-MM-DD HH:MM:SS
    cat /proc/acpi/alarm
    If the year part looks like "0007" instead of "2007", change +00 with +2000;
    Shutdown your machine and wait for it to wakeup
    shutdown -h now
    if you are using the 2.6.22+ rtcX interface echo 0 > /sys/class/rtc/rtc0/wakealarm
    echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm
    Check that something was written
    cat /sys/class/rtc/rtc0/wakealarm
    Shutdown your machine and wait for it to wakeup
    shutdown -h now
    [
    edit
    ]
    UTC or localtime
    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 set 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"`))

    # Offset from GMT as the awk function does timezone correction.
    tzone=3600
    #and then send it to /proc/acpi/wakeup in the format we saw above
    y=`(echo $(($sfn - $tzone))|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.
    [
    edit
    ]
    Disable hwclock updates (FUSSY BIOS)
    If the 'initiate manual' does not work:
    Most linux distributions write the current system time back to the bios when
    shutting down the machine. Some BIOSes refuse to wake up if the hardware clock
    is modified after the alarm timer has been set. To avoid that the current system
    time is written back to the hardware clock it required to change your startup
    scripts. This is distribution specific, so here are some examples:
    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
    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

    openSUSE
    modifying /etc/sysconfig/clock holds a switch to write back
    system time to the hardware clock
    ==>  SYSTOHC="yes"
    # Is set to "yes" write back the system time to the hardware
    # clock at reboot or shutdown. Usefull if hardware clock is
    # much more inaccurate than system clock.  Set to "no" if
    # system time does it wrong due e.g. missed timer interrupts.
    # If set to "no" the hardware clock adjust feature is also
    # skipped because it is rather useless without writing back
    # the system time to the hardware clock.
                   
    ==>  SYSTOHC="no"
    [
    edit
    ]
    Set wakeup time two times (FUSSY BIOS)
    For some motherboards, 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
    [
    edit
    ]
    More glitches (FUSSY BIOS)
    • 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.

    • On many boards, when the RTC setting is enabled in the BIOS, 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.

    [
    edit
    ]
    Additional source of info

    -
    help.ubuntu.com/community/MythTV/Install/WhatNext/ACPIWake


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


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


    -
    Very good article about wakeup, Linux Magazine

    [
    edit
    ]
    Extra Information
    [
    edit
    ]
    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: 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.
    [
    edit
    ]
    User experience
    Moosylog
    -
    March 2007: Works fine with MSI RS482M-IL and openSUSE 10.2 after I made the
    following change to /etc/sysconfig/clock.....SYSTOHC="yes" to SYSTOHC="no".
    Turpie
    : Works great
    with the Asus
    M2NPV-VM.
    Rad
    : Yep, but needs a
    recent bios version
    Murph
    - April 2007:
    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
    - August
    2007: 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
    -
    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.
    Dumdideldum
    -
    September 2007: Works with Epox 8rda+ running Ubuntu Feisty. It is important to
    disable the wakeup on rtc in the Bios and editing the /etc/init.d/hwclock.sh as
    described in the Ubuntu guide linked in the section below.
    Pkendall
    -
    September 2007: Works fine with MSI K9NBPM2-FID running Ubuntu Feisty. As above,
    edit the hwclock.sh file and make sure Bios RTC wakeup is disabled.
    Jmwislez
    -
    September 2007: Problem with ASUS P5GD1 motherboard (BIOS v1.014). Writing 'echo
    "2007-09-09 14:15:00" > /proc/acpi/alarm' works perfectly, reading via 'cat
    /proc/acpi/alarm' yields the expected '2007-09-09 14:15:00', but the system
    doesn't start at the specified time. After a manually initiated boot, 'cat
    /proc/acpi/alarm' yields '2007-09-00 14:15:00', with '00' for the day.
    Thewizzard
    -
    October 2007: Works with MSI K7N2 Delta-ILSR, be sure to use the hwclock.sh
    script and have it set the time two times.
    Spitzbub
    -
    December 2007: Works with Biostar NF325-A7, be sure to modify your
    /etc/init.d/hwclock.sh script (or equivalent) to set the wake-up time again
    after the --systohc, as described above under Fussy Bios.
    Per
    Olofsson - December 2007: Works very well with Asus P5GC-VM motherboard and
    Debian lenny with Linux 2.6.22. I don't use the "fussy BIOS" hack since I only
    suspend the system instead of shutting it down.
    KIB
    - February 2008:
    Shuttle XPC model SS58G2 / SS58v10, motherboard FS58V10 works with Mythbuntu
    7.10, kernel 2.6.22-14. Required BIOS settings - PM Wake Up Events ->
    IRQ8:enabled, PCIPME:enabled, Powerup by Alarm:disabled. I use /proc/acpi/alarm
    interface and the patch to hwclock.sh and hwclockfirst.sh is requred as above.
    Wake on LAN works as well - just add "ethtool -s eth0 wol umbg" to /etc/rc.local
    .
    imcecil
    - April
    2008: Work for Asus P5n-E SLI Gentoo 2.6.24 configured the Kernel as required
    above but used time_t as the wakeup time format (time since epoch) which seems
    to work when echoed straight to /sys/class/rtc/rtc0/wakealarm.
    Cymen
    - April 2008:
    Works great for PCChips P53G but be sure to only have the rtc-cmos module loaded
    (not the rtc module -- if rtc module is loaded, unload both rtc and rtc-cmos and
    then load rtc-cmos again and the device will appear in /sys...). Blacklist the
    rtc module or don't compile it in (the option in under "character drivers" is
    the one to be excluded).
    Retrieved from "
    http://www.mythtv.org/wiki/index.php/ACPI_Wakeup
    "
                   
                   
                   
                   
                   

    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/52215/showart_728472.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP