Linux, it's time to wake up!
Posted on 22 May 2010 in Articles • 3 min read
What is RTC and ACPI?
A Real Time Clock (RTC) alarm is a feature that can be used to allow a computer to 'wake up' after shut down to execute tasks every day or on a certain day. It can sometimes be found in the 'Power Management' section of a motherboard's BIOS setup [1].
In computing, the Advanced Configuration and Power Interface (ACPI) specification provides an open standard for unified operating system-centric device configuration and power management. ACPI, first released in December 1996, defines platform-independent interfaces for hardware discovery, configuration, power management and monitoring [2].
ACPI allows control of power management from within the operating system. The previous industry standard for power management, Advanced Power Management (APM), is controlled at the BIOS level. APM is activated when the system becomes idle: the longer the system idles, the less power it consumes (e.g. screen saver vs. sleep vs. suspend). In APM, the operating system has no knowledge of when the system will change power states [3].
ACPI can typically be configured from within the operating system. This is unlike APM where configuration often involves rebooting and entering the BIOS configuration screens to set parameters.
The ACPI specification defines seven states (so-called global states) for an ACPI-compliant computer-system [4]. Some of them are:
- G0 (S0) Working.
- G1 Sleeping (subdivides into the four states S1 through S4).
- G1/S3 Commonly referred to as Standby, Sleep, or Suspend to RAM. RAM remains powered
- G1/S4 Hibernation or Suspend to Disk. All content of main memory is saved to non-volatile memory such as a hard drive, and is powered down.
- G2 (S5) Soft Off. G2, S5, and Soft Off are synonyms. G2 is almost the same as G3 Mechanical Off, but some components remain powered so the computer can "wake" from input from the keyboard, clock, modem, LAN, or USB device.
If implemented, the Real Time Clock alarm must generate a hardware wake event when in the sleeping state. The RTC can be programmed to generate an alarm. An enabled RTC alarm can be used to generate a wake event when the system is in a sleeping state.
Setting up the wakeup alarm
- Open a terminal and switch to root su root.
- Check if rtc is available (kernel 2.6.22 and higher): ls /sys/class/rtc/rtc0/
- Look for the wakealarm file.
- Initialize the alarm via echo 0 > /sys/class/rtc/rtc0/wakealarm.
- Check if it has been initialzed: cat /proc/driver/rtc. At this point, the output should be similar to:
1 2 3 4 5 6 7 8 9 10 11 12 13 | rtc_time : 09:30:05 rtc_date : 2010-05-22 alrm_time : 09:34:43 alrm_date : ****-**-22 alarm_IRQ : no alrm_pending : no 24hr : yes periodic_IRQ : no update_IRQ : no HPET_emulated : yes DST_enable : no periodic_freq : 1024 batt_status : okay |
The rtc alarm is now ready to be set up. Wakealarm accepts the number of seconds since Jan 1, 1970 (this is known as "unix time", "POSIX time" or "epoch time").
You must make sure that your BIOS clock is set to UTC time - not localtime - otherwise it will wakeup at the wrong time. However, it is still possible if the BIOS clock is set to localtime (likely if you also run windows); see the section below for how to set the alarm correctly when the BIOS clock is in localtime. If you want to change the wakealarm time, you will need to write the new wakealarm time to the BIOS.
- A simple way to set the alarm to current time + 1 minute is: echo "+60" > /sys/class/rtc/rtc0/wakealarm.
- Check if the alarm has been set up: cat /proc/driver/rtc
1 2 3 | ... alarm_IRQ : yes ... |
- Now, suspend or shut down your computer. And wait until it wakes up in less than a minute :)
You can find more information about the topic at MythTV.org.
Be careful with the experiments!