Comment 0 for bug 571977

Revision history for this message
Jeff Lane  (bladernr) wrote : [Lucid] Possible race condition involving rtc wakealarm when hibernating a system

I'm working on a test script that sets a time in the future in /sys/class/rtc/rtc0/wakealarm and then uses pm-suspend to hibernate a system. I believe I've found a race condition that's causing my tests to fail.

First, the steps to recreate:
0: cat /proc/driver/rtc and verify that alarm_IRQ says 'no'
1: echo '+180' > /sys/class/rtc/rtc0/wakealarm
1.5: cat /proc/driver/rtc and verify that alarm_IRQ says 'yes' and the correct alarm time is set
2: sudo pm-suspend
3: wait 3 minutes
4: system wakes itself
5: wait for system to fully wake (disk activity to stop, or at the very least, keyboard and mouse function to resume on desktop)
6: cat /proc/driver/rtc and verify that current time is > alarm time and alarm_IRQ still says 'yes'

The test, when putting the system into an S3 state, does not suffer from this issue. It DOES when I'm using S4. I think the reason is that S3 wakes quickly enough that the kernel can register that the alarm fired and reset /proc/driver/rtc accordingly, however, when waking from suspend, the kernel takes far longer to wake, causing it to think that even though the rtc's alarm_IRQ fired the IRQ didn't fire, so the kernel does not reset /proc/driver/rtc.

For example, this is the output from (my comments highlighted with ##

# watch -n 5 'cat /proc/driver/rtc |head -5'

## First observation, note alarm_date is empty, this is after echoing '0' to /sys/class/rtc/rtc0/wakealarm
rtc_time : 20:35:11
rtc_date : 2010-04-29
alrm_time : 20:38:03
alrm_date : ****-**-29
alarm_IRQ : no
## wakealarm set
rtc_time : 20:35:16
rtc_date : 2010-04-29
alrm_time : 20:37:11
alrm_date : 2010-04-29
alarm_IRQ : yes
## executing pm-hibernate now
rtc_time : 20:35:21
rtc_date : 2010-04-29
alrm_time : 20:37:11
alrm_date : 2010-04-29
alarm_IRQ : yes
rtc_time : 20:35:26
rtc_date : 2010-04-29
alrm_time : 20:37:11
alrm_date : 2010-04-29
alarm_IRQ : yes
## System is now asleep.
## IRQ must be firing, because system wakes itself at this point after sleeping for the proscribed number of seconds (180)
rtc_time : 20:38:16
rtc_date : 2010-04-29
alrm_time : 20:37:11
alrm_date : 2010-04-30
alarm_IRQ : yes
## first report after system is fully awake. Note that rtc_time is now a full 60 seconds ahead of alarm time.

I'm not sure what's actually causing this behaviour, but what it seems as though the kernel isn't actually registering that the IRQ actually fired during a hibernate (or the rtc is broken, but it works fine during S3 tests and I can verify that the IRQ fires and alarm_IRQ resets to 'no' in S3 tests).

In any case, a race is created that isn't met in S3 testing due to the nearly instantaneous kernel resumption from that sleep state, where it is created (or at least the race is lost) when resuming from S4 due to the length of time it takes to resume from that state.)

because of this, subsequent setting of /sys/class/rtc/rtc0/wakealarm will fail without first clearing it with a '0' and if a piece of software is actually looking to see if the RTC fired it's alarm_IRQ, that software will believe that the IRQ has not been fired due to /driver/proc/rtc incorrectly reporting the event.

ProblemType: Bug
DistroRelease: Ubuntu 10.04
Package: linux-image-2.6.32-21-generic 2.6.32-21.32
Regression: No
Reproducible: Yes
ProcVersionSignature: Ubuntu 2.6.32-21.32-generic 2.6.32.11+drm33.2
Uname: Linux 2.6.32-21-generic x86_64
NonfreeKernelModules: nvidia
AlsaVersion: Advanced Linux Sound Architecture Driver Version 1.0.21.
AplayDevices:
 **** List of PLAYBACK Hardware Devices ****
 card 0: Intel [HDA Intel], device 0: STAC92xx Analog [STAC92xx Analog]
   Subdevices: 1/1
   Subdevice #0: subdevice #0
Architecture: amd64
ArecordDevices:
 **** List of CAPTURE Hardware Devices ****
 card 0: Intel [HDA Intel], device 0: STAC92xx Analog [STAC92xx Analog]
   Subdevices: 1/1
   Subdevice #0: subdevice #0
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC0: bladernr 2029 F.... pulseaudio
CRDA: Error: [Errno 2] No such file or directory
Card0.Amixer.info:
 Card hw:0 'Intel'/'HDA Intel at 0xf0f20000 irq 22'
   Mixer name : 'IDT 92HD83C1X5'
   Components : 'HDA:111d7604,102802a2,00100104'
   Controls : 16
   Simple ctrls : 10
Card1.Amixer.info:
 Card hw:1 'NVidia'/'HDA NVidia at 0xcdefc000 irq 16'
   Mixer name : 'Nvidia ID a'
   Components : 'HDA:10de000a,10de0101,00100100'
   Controls : 0
   Simple ctrls : 0
Card1.Amixer.values:

Date: Thu Apr 29 20:55:42 2010
HibernationDevice: RESUME=UUID=f4e6db09-5257-40b2-ba2a-0718fc0b3f0d
InstallationMedia: Ubuntu 9.10 "Karmic Koala" - Release amd64 (20091027)
MachineType: Alienware M15x
ProcCmdLine: BOOT_IMAGE=/boot/vmlinuz-2.6.32-21-generic root=UUID=acc23352-13ab-4854-b1d7-a1099a5bf3a5 ro quiet splash
ProcEnviron:
 LANG=en_US.UTF-8
 SHELL=/bin/bash
RelatedPackageVersions: linux-firmware 1.34
SourcePackage: linux
dmi.bios.date: 03/11/2010
dmi.bios.vendor: Alienware
dmi.bios.version: A05
dmi.board.vendor: Alienware
dmi.board.version: A05
dmi.chassis.type: 8
dmi.chassis.vendor: Alienware
dmi.chassis.version: A05
dmi.modalias: dmi:bvnAlienware:bvrA05:bd03/11/2010:svnAlienware:pnM15x:pvrA05:rvnAlienware:rn:rvrA05:cvnAlienware:ct8:cvrA05:
dmi.product.name: M15x
dmi.product.version: A05
dmi.sys.vendor: Alienware