2011年1月23日 星期日

愛情觀

有時跟朋友聊起愛情觀

很多人的想法都不同

有的更是說的跟做的不同

但是他們至少有個機會可以珍惜

常常聽到的就是  愛變成理所當然

人生苦短  又何必太計較呢

勇敢去愛就對了~~

2011年1月2日 星期日

ACPI RTC WakeUp

The above indicates this system can wake from state S4 and that the wakeup time can be set.
The ACPI specifications defines the following so-called "global states" -- from Wikipedia ACPI
  • G1 Sleeping subdivides into the four states S1 through S4.
    • S1: The CPU(s) stop executing instructions.
    • S2: The CPU is powered off.
    • S3: Suspend to RAM.
    • S4: Suspend to disk or hibernate.
  • G2 (S5) Soft Off Almost the same as G3 but computer can "wake" from input from the keyboard, clock, modem, LAN, or USB device.
  • G3 Mechanical Off
Next, check your BIOS for the wakeup alarm function. This setting is likely found under a sub-menu of "Power Management Setup", "APM", or "Advanced" - you just need to poke around to find it. It will likely be called something like Wake From Alarm, Power-on by Alarm, Wake from RTC, RTC Resume, etc.

S3 (Suspend to RAM)

First, see the BIOS setup section above to confirm which powerdown states your computer's ACPI supports. Some computers are unable to wake up from S5 (Soft Off) by an RTC alarm set through ACPI. For example some HP Compaq desktop computers allow you to set wakeup from BIOS at a specific time and at specific week days, however it is ignored ACPI alarm. In this case you may want to try to see if it does wake up from S3 (Suspend to RAM) instead.
The following check needs pm-utils package to work. You may also want to turn off X windows, as quite a few drivers don't like suspend to RAM.
# Set the alarm to five minutes in the future 
 echo 0 > /sys/class/rtc/rtc0/wakealarm
 echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm

 /usr/sbin/pm-suspend

If the computer wakes up after 5 minutes, then congratulations.
Because "suspend to RAM" may not be very stable with the exotic hardware that a lot of mythTV users have, we want to reboot after we wake up from suspend. In fact we can add an init.d script that will suspend the computer just before it physically reboots, on wake up the computer will then do the actual reboot.




關於在 Linux 下做 RTC WakeUp 與自動排程
首先, 自動排程與 Cron or Crontab 有關, 可以參考http://linux.vbird.org/linux_basic/0430cron.php
RTC WakeUp 有兩種, 要先查看 RTC Alarm 是在哪裡
1. /proc/acpi/alarm
2. /sys/class/rtc/rtc0/wakealarm
所以設定 RTC Alarm 有兩種方法, 詳情可以參考以下兩篇文章:
摘錄如下:
1.
代表設定 40 秒之後發出 alarm,並且同時也會 enable ACPI
所以下面的命令就可以將系統 suspend to memory40 秒後 resume
# echo "+00-00-00 00:00:40" > /proc/acpi/alarm
# echo "mem" > /sys/power/state
2.
要查看支援哪些 suspend mode
# more /sys/power/state
standby mem disk
這個 RTC WakeUp 已經在 GF8100 platform with Ubnutu 8.04.01  測試 OK!!
我們可以透過 ACPI 提供的 interface,設置 RTC alarm,如此在 alarm 發出 IRQ 時,ACPI 就會 resume systemEPC 中的 genrtc module 並不支援 alarm interrupt。如果手動加入 rtc module,雖然它有支援 alarm interrupt,但是透過 rtc module 來設 alarm,與透過 ACPI interface 的差別就在於,ACPI 是否有 enable event
我們可以看看 kernel source 中,driver/acpi/sleep/proc.c
acpi_system_write_alarm 這個 function,設定 RTC alarm 之後,還會做這一行
acpi_enable_event(ACPI_EVENT_RTC, 0);
單獨透過 rtc module 是不會跑這行的。

要查看支援哪些 suspend mode
# more /sys/power/state
standby mem disk
它們分別代表 S1 S3 S4
這種方式可以用軟體來做 suspend-resume 的測試。它和 suspend 後按 power button resume 的原理不盡相同。因為 power button 的訊號是透過 GPIO 接到 EC,然後再透過 LPC 來通知南橋。RTC 本身就在南橋內了,並無透過 EC
kernel 2.6.22 之後,ACPI 改用另一個 interface 來取代 /proc/acpi/alarm。相關資訊,請參照
http://www.mythtv.org/wiki/index.php/ACPI_Wakeup

後來在網路上找到一篇有用的文章「ACPI Wakeup 」裡面有說明如何設定定時從S1/S3回來。 我是在SLES11上試了Suspend to RAM WakeAlarm Timer 的簡單方法, 參考裡面的範例把喚醒的時間設為1分鐘...試完之後結果真的可以呢~ 超高興, 系統會在時間到時自動的被叫起來 :D
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo `date '+%s' -d '+ 1 minutes'` > /sys/class/rtc/rtc0/wakealarm
pm-suspend
12步驟主要是在歸零和設定定時, 進入S3 (Suspend to RAM) 主要是第3個命令, 如果要進入S1只要換這命令就好了, 1&2步不用動, 以這個script再配上shell loop 就可以做長時間的測試啦。
[*] Software Suspend (EXPERIMENTAL)  (y)
;
支援系統suspend(休眠),打開這項功能後, 可用swsusp或者shutdown -z 來掛起系統. 這樣系統會將你當前正在進行的工作(也就是當前記憶體中的內容)作成一個鏡象保存到你的交換分區中, 在你下一次啟動時使用啟動參數"resume=/dev/交換分區".內核就會將上一次的工作內核從鏡象檔中恢復到記憶體,這可以大大提高系統的啟動速 度. 當你不想恢復上次的工作時向內核傳遞參數“noresume".不過系統啟動後你的交換分區將不可以使用, 你可以使用mkswap命令來重新格式化你的交換分區. 這個功能不需要高級電源管理的支援.

Plurk