rtcwake doesn't reset wakealarm
Hi,
I recently upgraded to util-linux 2.22 and I noticed that powertop started reporting about 50-60 wakeups per second caused by rtc (interrupt 8).
I quickly found out that this happened when I used rtcwake to wake up the machine, and that after the reboot /sys/class/rtc/rtc0/wakealarm was still set to the scheduled wakeup time (now in the past). Resetting it to 0 with "echo 0 > /sys/class/rtc/rtc0/wakealarm" made the interrupt stop.
After a quick investigation I discovered that this is caused by commit 1707576155daf644c5df3c1776b52fd297ff9318 ("rtcwake: only invoke RTC_AIE_ON/OFF ioctls in pairs"): my system uses RTC_WKALM_SET so ioctl_aie_on stays false and RTC_AIE_OFF doesn't get called.
I removed the check to revert to the previous behaviour and after my machine rebooted /sys/class/rtc/rtc0/wakealarm was correctly (I suppose) set to 0, rtc didn't fire regular interrupts anymore and there were apparently no negative consequences.
Is this a bug or am I missing something?
Thanks,
Giacomo
PS. I'm not subscribed to the list so please cc me if you need other information.
Quoted 12 lines · Giacomo
I recently upgraded to util-linux 2.22 and I noticed that powertop started reporting about 50-60 wakeups per second caused by rtc (interrupt 8).
I quickly found out that this happened when I used rtcwake to wake up the machine, and that after the reboot
/sys/class/rtc/rtc0/wakealarmwas still set to the scheduled wakeup time (now in the past).After a quick investigation I discovered that this is caused by commit
1707576155daf644c5df3c1776b52fd297ff9318("rtcwake: only invoke RTC_AIE_ON/OFF ioctls in pairs"): my system usesRTC_WKALM_SETsoioctl_aie_onstays false andRTC_AIE_OFFdoesn't get called.
Hi,
that commit also broke "disable". This is what happens on my system:
KazeNoTani ~ # cat /sys/class/rtc/rtc0/wakealarm KazeNoTani ~ # rtcwake -m show
alarm: off
KazeNoTani ~ # rtcwake -m no -s 300
rtcwake: wakeup using /dev/rtc0 at Wed Sep 12 09:40:31 2012 KazeNoTani ~ # rtcwake -m show
alarm: on Wed Sep 12 09:40:32 2012
KazeNoTani ~ # cat /sys/class/rtc/rtc0/wakealarm 1347442831
KazeNoTani ~ # rtcwake -m disable
KazeNoTani ~ # rtcwake -m show
alarm: on Wed Sep 12 09:40:32 2012
KazeNoTani ~ # cat /sys/class/rtc/rtc0/wakealarm 1347442831
KazeNoTani ~ # echo 0 > /sys/class/rtc/rtc0/wakealarm KazeNoTani ~ # cat /sys/class/rtc/rtc0/wakealarm KazeNoTani ~ # rtcwake -m show
alarm: off
rtcwake -m disable doesn't remove the alarm. This is because as it is implemented now "-m disable" does nothing but break and rely on the call to RTC_AIE_OFF that was always done at the end of the execution of rtcwake, but now is conditional on "ioctl_aie_on" that doesn't get set in most cases.
Thanks,
Giacomo
Karel Zak
maintainerLet's add Paul to CC ;-)
Quoted 54 lines · Giacomo
Quoted 12 lines · Giacomo
I recently upgraded to util-linux 2.22 and I noticed that powertop started reporting about 50-60 wakeups per second caused by rtc (interrupt 8).
I quickly found out that this happened when I used rtcwake to wake up the machine, and that after the reboot
/sys/class/rtc/rtc0/wakealarmwas still set to the scheduled wakeup time (now in the past).After a quick investigation I discovered that this is caused by commit
1707576155daf644c5df3c1776b52fd297ff9318("rtcwake: only invoke RTC_AIE_ON/OFF ioctls in pairs"): my system usesRTC_WKALM_SETsoioctl_aie_onstays false andRTC_AIE_OFFdoesn't get called.Hi,
that commit also broke "disable". This is what happens on my system:
KazeNoTani ~ # cat
/sys/class/rtc/rtc0/wakealarmKazeNoTani ~ # rtcwake -m show
alarm: off
KazeNoTani ~ # rtcwake -m no -s 300
rtcwake: wakeup using/dev/rtc0at Wed Sep 12 09:40:31 2012 KazeNoTani ~ # rtcwake -m show
alarm: on Wed Sep 12 09:40:32 2012
KazeNoTani ~ # cat/sys/class/rtc/rtc0/wakealarm1347442831
KazeNoTani ~ # rtcwake -m disable
KazeNoTani ~ # rtcwake -m show
alarm: on Wed Sep 12 09:40:32 2012
KazeNoTani ~ # cat/sys/class/rtc/rtc0/wakealarm1347442831
KazeNoTani ~ # echo 0 >/sys/class/rtc/rtc0/wakealarmKazeNoTani ~ # cat/sys/class/rtc/rtc0/wakealarmKazeNoTani ~ # rtcwake -m show
alarm: offrtcwake -m disable doesn't remove the alarm. This is because as it is implemented now "-m disable" does nothing but break and rely on the call to
RTC_AIE_OFFthat was always done at the end of the execution of rtcwake, but now is conditional on "ioctl_aie_on" that doesn't get set in most cases.Thanks,
Giacomo
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Karel Zak
maintainerQuoted 22 lines · Karel Zak
Let's add Paul to CC ;-)
Quoted 18 lines · Giacomo
Quoted 12 lines · Giacomo
I recently upgraded to util-linux 2.22 and I noticed that powertop started reporting about 50-60 wakeups per second caused by rtc (interrupt 8).
I quickly found out that this happened when I used rtcwake to wake up the machine, and that after the reboot
/sys/class/rtc/rtc0/wakealarmwas still set to the scheduled wakeup time (now in the past).After a quick investigation I discovered that this is caused by commit
1707576155daf644c5df3c1776b52fd297ff9318("rtcwake: only invoke RTC_AIE_ON/OFF ioctls in pairs"): my system usesRTC_WKALM_SETsoioctl_aie_onstays false andRTC_AIE_OFFdoesn't get called.Hi,
that commit also broke "disable". This is what happens on my system:
Please, test the patch below. I hope it fixes the problem.
Karel
Quoted 1 line
From
7413ac3f50102236415267f19b23f9839a6403b0Mon Sep 17 00:00:00 2001
From: Karel Zak <[email protected]>
Date: Wed, 12 Sep 2012 12:22:13 +0200
Subject: [PATCH] rtcwake: reset wakealarm
Quoted 9 lines
I recently upgraded to util-linux 2.22 and I noticed that powertop started reporting about 50-60 wakeups per second caused by rtc (interrupt 8).
I quickly found out that this happened when I used rtcwake to wake up the machine, and that after the reboot
/sys/class/rtc/rtc0/wakealarmwas still set to the scheduled wakeup time (now in the past).
Quoted 5 lines
After a quick investigation I discovered that this is caused by commit
1707576155daf644c5df3c1776b52fd297ff9318("rtcwake: only invoke RTC_AIE_ON/OFF ioctls in pairs"): my system usesRTC_WKALM_SETsoioctl_aie_onstays false andRTC_AIE_OFFdoesn't get called.
--- sys-utils/rtcwake.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)
sys-utils/rtcwake.c +7 -5
@@ -64,7 +64,7 @@ enum ClockMode {static unsigned verbose;static unsigned dryrun; -static unsigned ioctl_aie_on;/* ioctl(AIE_ON) succeeded */ +static unsigned alarm_on;/* RTC_ALM_SET+RTC_AIE_ON or RTC_WKALM_SET */ enum ClockMode clock_mode =CM_AUTO ;static struct option long_options[] = {
@@ -243,12 +243,13 @@ static int setup_alarm(int fd, time_t *wakeup)warn (_ ("enable rtc alarm failed" ));return -1 ; } - ioctl_aie_on =1 ; + alarm_on =1 ; }else {warn (_ ("set rtc wake alarm failed" ));return -1 ; } - } + }else if (!dryrun) + alarm_on =1 ;return 0 ; }
@@ -524,6 +525,7 @@ int main(int argc, char **argv) alarm, sys_time, rtc_time, seconds);if (strcmp (suspend,"show" ) &&strcmp (suspend,"disable" )) { +if (strcmp (suspend,"no" ) &&strcmp (suspend,"on" ) &&strcmp (suspend,"off" ) &&is_suspend_available (suspend) <=0 ) {errx (EXIT_FAILURE ,_ ("suspend to \"%s\" unavailable" ), suspend);
@@ -598,7 +600,7 @@ int main(int argc, char **argv) } }else if (strcmp (suspend,"disable" ) ==0 ) { -/* just break, alarm gets disabled in the end */ + alarm_on =1 ;/* alarm gets disabled in the end */ if (verbose)printf (_ ("suspend mode: disable; disabling alarm\n" ));
@@ -616,7 +618,7 @@ int main(int argc, char **argv)suspend_system (suspend); } -if (!dryrun && ioctl_aie_on &&ioctl (fd,RTC_AIE_OFF ,0 ) <0 ) +if (!dryrun && alarm_on &&ioctl (fd,RTC_AIE_OFF ,0 ) <0 )warn (_ ("disable rtc alarm interrupt failed" ));close (fd);
Signature · 1 line
1.7.7.6
Quoted 5 lines · Karel Zak
Quoted 3 lines · Karel Zak
Let's add Paul to CC
Quoted 7 lines
Quoted 7 lines · Giacomo
Quoted 6 lines
Quoted 4 lines · Giacomo
After a quick investigation I discovered that this is caused by commit
1707576155daf644c5df3c1776b52fd297ff9318("rtcwake: only invoke RTC_AIE_ON/OFF
ioctls in pairs"): my system usesRTC_WKALM_SETsoioctl_aie_onstays
false and
Quoted 11 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
RTC_AIE_OFFdoesn't get called.Hi,
that commit also broke "disable". This is what happens on my system:
Please, test the patch below. I hope it fixes the problem.
Karel
Hi,
it should work but I'm afraid it won't fix Paul's original problem, because even if RTC_AIE_ON fails RTC_AIE_OFF will still be called and generate an error.
According to "man rtc", "when using [RTC_WKALM_RD,RTC_WKALM_SET], RTC_AIE_ON and RTC_AIE_OFF are not used", so the right thing to do should be using RTC_AIE_OFF to clear the alarm only when RTC_ALM_SET+RTC_AIE_ON was used to set it up (that is, when ioctl_aie_on=1), and RTC_WKALM_SET with the "enabled" flag set to false otherwise.
The attached patch works for me (I hope it doesn't get mangled in the posting, you can find it on pastebin too: http://pastebin.com/wugHPx3w).
Giacomo
rtcwake.c +19 -2
@@ -388,6 +388,8 @@unsigned seconds =0 ;char *suspend =DEFAULT_MODE ; +struct rtc_wkalrm wake; +int rc =EXIT_SUCCESS ;int t;int fd;
@@ -616,8 +618,23 @@suspend_system (suspend); } -if (!dryrun && ioctl_aie_on &&ioctl (fd,RTC_AIE_OFF ,0 ) <0 ) -warn (_ ("disable rtc alarm interrupt failed" )); +if (!dryrun) { +/* clear the alarm with RTC_AIE_OFF if RTC_ALM_SET+RTC_AIE_ON +* was used to enable it otherwise use the preferred RTC_WKALM_SET +*/ +if (ioctl_aie_on &&ioctl (fd,RTC_AIE_OFF ,0 ) <0 ) { +warn (_ ("disable rtc alarm interrupt failed" )); + }else { +if (ioctl (fd,RTC_WKALM_RD , &wake) <0 ) +warn (_ ("disable rtc alarm interrupt failed" )); +else { + wake.enabled =0 ; + +if (ioctl (fd,RTC_WKALM_SET , &wake) <0 ) +warn (_ ("disable rtc alarm interrupt failed" )); + } + } + }close (fd);return rc;
Quoted 30 lines · Giacomo
Quoted 10 lines · Karel Zak
Quoted 3 lines · Karel Zak
Let's add Paul to CC
Please, test the patch below. I hope it fixes the problem.
Karel
Hi,
it should work but I'm afraid it won't fix Paul's original problem, because even if
RTC_AIE_ONfailsRTC_AIE_OFFwill still be called and generate an error.According to "man rtc", "when using [RTC_WKALM_RD,RTC_WKALM_SET],
RTC_AIE_ONandRTC_AIE_OFFare not used", so the right thing to do should be usingRTC_AIE_OFF
to clear the alarm only when RTC_ALM_SET+RTC_AIE_ON was used to set it up (that
is, when ioctl_aie_on=1), andRTC_WKALM_SETwith the "enabled" flag set to false
otherwise.
Quoted 6 lines
The attached patch works for me (I hope it doesn't get mangled in the posting,
you can find it on pastebin too: http://pastebin.com/wugHPx3w).Giacomo
That was needlessly complex. The issue never was "don't call RTC_AIE_OFF if you didn't call RTC_AIE_ON before," it was "don't call RTC_AIE_OFF if it is not supported."
So to disable an alarm use the same logic used to enable it: first try RTC_WKALM_SET with the "enabled" flag set to false, if it fails fall back to RTC_AIE_OFF.
This patch works for me as well and it seems to me it's cleaner than my previous one.
Giacomo
PS. if it's mangled http://pastebin.com/CUtVkfiQ
---
rtcwake.c +19 -4
@@ -64,7 +64,6 @@static unsigned verbose;static unsigned dryrun; -static unsigned ioctl_aie_on;/* ioctl(AIE_ON) succeeded */ enum ClockMode clock_mode =CM_AUTO ;static struct option long_options[] = {
@@ -243,7 +242,6 @@warn (_ ("enable rtc alarm failed" ));return -1 ; } - ioctl_aie_on =1 ; }else {warn (_ ("set rtc wake alarm failed" ));return -1 ;
@@ -393,6 +391,8 @@int fd;time_t alarm =0 ; +struct rtc_wkalrm wake; +setlocale (LC_ALL ,"" );bindtextdomain (PACKAGE ,LOCALEDIR );textdomain (PACKAGE );
@@ -616,8 +616,23 @@suspend_system (suspend); } -if (!dryrun && ioctl_aie_on &&ioctl (fd,RTC_AIE_OFF ,0 ) <0 ) -warn (_ ("disable rtc alarm interrupt failed" )); +if (!dryrun) { +/* try to disable the alarm with the preferred RTC_WKALM_RD and +* RTC_WKALM_SET calls, if it fails fall back to RTC_AIE_OFF +*/ +if (ioctl (fd,RTC_WKALM_RD , &wake) <0 ) { +if (ioctl (fd,RTC_AIE_OFF ,0 ) <0 ) { +warn (_ ("disable rtc alarm interrupt failed" )); + rc =EXIT_FAILURE ; + } + }else { + wake.enabled =0 ; +if (ioctl (fd,RTC_WKALM_SET , &wake) <0 ) { +warn (_ ("disable rtc alarm interrupt failed" )); + rc =EXIT_FAILURE ; + } + } + }close (fd);return rc;
Quoted 3 lines · Giacomo
That was needlessly complex. The issue never was "don't call
RTC_AIE_OFFif you didn't callRTC_AIE_ONbefore," it was "don't callRTC_AIE_OFFif it is not supported."
Good point.
Quoted 7 lines
So to disable an alarm use the same logic used to enable it: first try
RTC_WKALM_SETwith the "enabled" flag set to false, if it fails fall back toRTC_AIE_OFF.This patch works for me as well and it seems to me it's cleaner than my previous one.
Applied, thanks. (You forgot 'Signed-off-by:' but I guess you agree with this line in the commit message... )
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
thanks for cc'ing me. my apologies for both the breakage (it seemed so simple! :-) and the delay in reply.
i see you've committed a fix for this yesterday: i'll try to test it soon and make sure it's okay.
i might have proposed a slightly different (and i think simpler) change. i would revert my original patch, and instead, simply remove the failure case of RTC_AIE_OFF -- i.e., this:
if (!dryrun && ioctl_aie_on && ioctl(fd, RTC_AIE_OFF, 0) < 0)
warn(_("disable rtc alarm interrupt failed"));
becomes this:
if (!dryrun)
ioctl(fd, RTC_AIE_OFF, 0);my bug was always a cosmetic one -- on a platform which doesn't implement RTC_AIE_XXX at all, the original code causes a spurious call, but worse, a spurious message.
paul
Quoted 113 lines · karel
Quoted 22 lines · Karel Zak
Let's add Paul to CC ;-)
Quoted 18 lines · Giacomo
Quoted 12 lines · Giacomo
I recently upgraded to util-linux 2.22 and I noticed that powertop started reporting about 50-60 wakeups per second caused by rtc (interrupt 8).
I quickly found out that this happened when I used rtcwake to wake up the machine, and that after the reboot
/sys/class/rtc/rtc0/wakealarmwas still set to the scheduled wakeup time (now in the past).After a quick investigation I discovered that this is caused by commit
1707576155daf644c5df3c1776b52fd297ff9318("rtcwake: only invoke RTC_AIE_ON/OFF ioctls in pairs"): my system usesRTC_WKALM_SETsoioctl_aie_onstays false andRTC_AIE_OFFdoesn't get called.Hi,
that commit also broke "disable". This is what happens on my system:
Please, test the patch below. I hope it fixes the problem.
Karel
Quoted 1 line
From
7413ac3f50102236415267f19b23f9839a6403b0Mon Sep 17 00:00:00 2001From: Karel Zak <[email protected]>
Date: Wed, 12 Sep 2012 12:22:13 +0200
Subject: [PATCH] rtcwake: reset wakealarmQuoted 9 lines
I recently upgraded to util-linux 2.22 and I noticed that powertop started reporting about 50-60 wakeups per second caused by rtc (interrupt 8).
I quickly found out that this happened when I used rtcwake to wake up the machine, and that after the reboot
/sys/class/rtc/rtc0/wakealarmwas still set to the scheduled wakeup time (now in the past).Quoted 5 lines
After a quick investigation I discovered that this is caused by commit
1707576155daf644c5df3c1776b52fd297ff9318("rtcwake: only invoke RTC_AIE_ON/OFF ioctls in pairs"): my system usesRTC_WKALM_SETsoioctl_aie_onstays false andRTC_AIE_OFFdoesn't get called.Reported-by Giacomo <[email protected]>Signed-off-by Karel Zak <[email protected]>--- sys-utils/rtcwake.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)sys-utils/rtcwake.c +7
-5@@ -64,7 +64,7 @@ enum ClockMode {static unsigned verbose;static unsigned dryrun; -static unsigned ioctl_aie_on;/* ioctl(AIE_ON) succeeded */ +static unsigned alarm_on;/* RTC_ALM_SET+RTC_AIE_ON or RTC_WKALM_SET */ enum ClockMode clock_mode =CM_AUTO ;static struct option long_options[] = {@@ -243,12 +243,13 @@ static int setup_alarm(int fd, time_t *wakeup)warn (_ ("enable rtc alarm failed" ));return -1 ; } - ioctl_aie_on =1 ; + alarm_on =1 ; }else {warn (_ ("set rtc wake alarm failed" ));return -1 ; } - } + }else if (!dryrun) + alarm_on =1 ;return 0 ; }@@ -524,6 +525,7 @@ int main(int argc, char **argv) alarm, sys_time, rtc_time, seconds);if (strcmp (suspend,"show" ) &&strcmp (suspend,"disable" )) { +if (strcmp (suspend,"no" ) &&strcmp (suspend,"on" ) &&strcmp (suspend,"off" ) &&is_suspend_available (suspend) <=0 ) {errx (EXIT_FAILURE ,_ ("suspend to \"%s\" unavailable" ), suspend);@@ -598,7 +600,7 @@ int main(int argc, char **argv) } }else if (strcmp (suspend,"disable" ) ==0 ) { -/* just break, alarm gets disabled in the end */ + alarm_on =1 ;/* alarm gets disabled in the end */ if (verbose)printf (_ ("suspend mode: disable; disabling alarm\n" ));@@ -616,7 +618,7 @@ int main(int argc, char **argv)suspend_system (suspend); } -if (!dryrun && ioctl_aie_on &&ioctl (fd,RTC_AIE_OFF ,0 ) <0 ) +if (!dryrun && alarm_on &&ioctl (fd,RTC_AIE_OFF ,0 ) <0 )warn (_ ("disable rtc alarm interrupt failed" ));close (fd);Signature · 1 line
1.7.7.6
=---------------------
paul fox, [email protected]