MythTV ACPI Wakeup


MythTV
LogoTelevision viewing has changed quite a lot in my household since I started using a MythTV box. I no longer worry about what is on and when...I just turn on the box and look at the stuff it has remembered to record for me when I feel like watching some TV. On of the trickiest elements I found was getting the machine to reliably wake up to make recordings at obscene o'clock and shut down when idle. I guess I could have left it running 24x7, but that's not the environmentally sound option. This is how I tackled the wakeup problem.

Blootube Wide Theme Main
Page Many (most) motherboards have an ability to wake up at a certain time, but this must be manually set from the system setup pages. I initially tried the NVRAM Wakeup utility. This utility works by directly writing wakeup time and date information into non-volatile memory and is very tightly coupled to hardware and software revisions. My motherboard (an A7V880 BIOS rev 1008) was supported out of the box and it seemed to work. Unfortunately though, this motherboard has other issues that I needed to remedy with a BIOS update (to 1009.001). This meant that I had to go through a repetitive routine to have NVRAM Wakeup guess the memory locations of interest. I did get a working setup but I had to manually hack the automated guess, and even then there were elements of doubt. Every so often the machine would wake to corrupted NVRAM contents :( . While I am not certain that the wakeup routines were the cause I thought I'd migrate to a method that was marginally less risky.

Blootube Wide Theme Upcoming
RecordingsThe Linux kernel ACPI implementation exposes the BIOS alarm system as a file /proc/acpi/alarm. If you look at the content of this file is gives a human-readable representation of the currently set alarm time like 00-00-05 21:30:00. By writing to the file in the same format you can set the alarm time although usually the month and year are ignored, and 00 in the day field means any-day. The time must be written to the alarm file in whatever time zone the hardware clock is set (UTC) on most Linux-only machines, but sometimes local time if the machine is shared with Windows). There is another way to write the time that avoids needing to know whether the hardware clock is UTC or not. Writing time in this format +00-00-01 02:45:00 will cause the kernel to add the specified days, hours, minutes, and seconds to whatever the current time is and store that in the alarm. I wrote the script linked below to do just that. It acts as a drop-in replacement for nvram-wakeup and accepts the same options and inputs (although it ignores most of them). The desired wakeup time is passed from MythTV as a UNIX time stamp: seconds since 1970-01-01 00:00:00 UTC. Appropriate mathematics is done and a time delta is stored into the alarm file. The script is limited to times within 31 days, which should be adequate for most purposes. This script has been working well for the past month.

I believe there are two other gotchas that might be of interest:

  • On some motherboards the alarm time is reset if the hardware clock time is updated during shutdown. This is usually in a script halt.sh (or the like). You can work around it by reseting the alram after setting the time; something like:
BACKUP_TIME=$(cat /proc/acpi/alarm) 
... the existing clock setting code (hwclock)
echo $BACKUP_TIME > /proc/acpi/alarm  
  • From kernel version 2.6.21 or 22 this support is likely to disappear and be replaced with less PC-centric clock handling. When this occurs I will be rewriting the script.

Now, if only I could perfect the commercial skipping feature :)

Clear skies!

Download ACPI Wakeup Script

The MythTV screen shots are from the very ornamental Blootube wide theme by Justin Hornsby.