public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* rtcwake doesn't reset wakealarm
@ 2012-09-11 11:11 Giacomo
  2012-09-12  9:52 ` Giacomo
  0 siblings, 1 reply; 8+ messages in thread
From: Giacomo @ 2012-09-11 11:11 UTC (permalink / raw)
  To: util-linux

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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rtcwake doesn't reset wakealarm
  2012-09-11 11:11 rtcwake doesn't reset wakealarm Giacomo
@ 2012-09-12  9:52 ` Giacomo
  2012-09-12 10:09   ` Karel Zak
  0 siblings, 1 reply; 8+ messages in thread
From: Giacomo @ 2012-09-12  9:52 UTC (permalink / raw)
  To: util-linux

Giacomo <giacomo.perale@...> writes:

> 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). 
> 
> 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.
> 

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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rtcwake doesn't reset wakealarm
  2012-09-12  9:52 ` Giacomo
@ 2012-09-12 10:09   ` Karel Zak
  2012-09-12 10:31     ` Karel Zak
  0 siblings, 1 reply; 8+ messages in thread
From: Karel Zak @ 2012-09-12 10:09 UTC (permalink / raw)
  To: Giacomo; +Cc: util-linux, Paul Fox


 Let's add Paul to CC ;-)

On Wed, Sep 12, 2012 at 09:52:14AM +0000, Giacomo wrote:
> Giacomo <giacomo.perale@...> writes:
> 
> > 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). 
> > 
> > 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.
> > 
> 
> 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
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe util-linux" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rtcwake doesn't reset wakealarm
  2012-09-12 10:09   ` Karel Zak
@ 2012-09-12 10:31     ` Karel Zak
  2012-09-12 14:33       ` Giacomo
  2012-09-13 16:31       ` Paul Fox
  0 siblings, 2 replies; 8+ messages in thread
From: Karel Zak @ 2012-09-12 10:31 UTC (permalink / raw)
  To: Giacomo; +Cc: util-linux, Paul Fox

On Wed, Sep 12, 2012 at 12:09:16PM +0200, Karel Zak wrote:
> 
>  Let's add Paul to CC ;-)
> 
> On Wed, Sep 12, 2012 at 09:52:14AM +0000, Giacomo wrote:
> > Giacomo <giacomo.perale@...> writes:
> > 
> > > 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). 
> > > 
> > > 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.
> > > 
> > 
> > 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



>From 7413ac3f50102236415267f19b23f9839a6403b0 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Wed, 12 Sep 2012 12:22:13 +0200
Subject: [PATCH] rtcwake: reset wakealarm

> 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).
>
> 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.

Reported-by: Giacomo <giacomo.perale@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
---
 sys-utils/rtcwake.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index 0e16bd3..6e2701a 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -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);
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: rtcwake doesn't reset wakealarm
  2012-09-12 10:31     ` Karel Zak
@ 2012-09-12 14:33       ` Giacomo
  2012-09-12 17:33         ` Giacomo
  2012-09-13 16:31       ` Paul Fox
  1 sibling, 1 reply; 8+ messages in thread
From: Giacomo @ 2012-09-12 14:33 UTC (permalink / raw)
  To: util-linux

Karel Zak <kzak@...> writes:

> 
> On Wed, Sep 12, 2012 at 12:09:16PM +0200, Karel Zak wrote:
> > 
> >  Let's add Paul to CC 
> > 
> > On Wed, Sep 12, 2012 at 09:52:14AM +0000, Giacomo wrote:
> > > Giacomo <giacomo.perale@...> writes:
> > > 
> > > > 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.
> > > > 
> > > 
> > > 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


--- sys-utils/rtcwake.c	2012-07-23 23:21:56.466320628 +0200
+++ sys-utils/rtcwake.c	2012-09-12 16:13:40.927245246 +0200
@@ -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;


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rtcwake doesn't reset wakealarm
  2012-09-12 14:33       ` Giacomo
@ 2012-09-12 17:33         ` Giacomo
  2012-09-13 11:25           ` Karel Zak
  0 siblings, 1 reply; 8+ messages in thread
From: Giacomo @ 2012-09-12 17:33 UTC (permalink / raw)
  To: util-linux

Giacomo <giacomo.perale@...> writes:

> 
> Karel Zak <kzak@...> writes:
> 
> > 
> > On Wed, Sep 12, 2012 at 12:09:16PM +0200, Karel Zak wrote:
> > > 
> > >  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_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
> 

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

---

--- sys-utils/rtcwake.c	2012-07-23 23:21:56.466320628 +0200
+++ sys-utils/rtcwake.c	2012-09-12 19:22:07.772244322 +0200
@@ -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;





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rtcwake doesn't reset wakealarm
  2012-09-12 17:33         ` Giacomo
@ 2012-09-13 11:25           ` Karel Zak
  0 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2012-09-13 11:25 UTC (permalink / raw)
  To: Giacomo; +Cc: util-linux

On Wed, Sep 12, 2012 at 05:33:39PM +0000, Giacomo wrote:
> 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."

Good point.

> 
> 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.

 Applied, thanks. (You forgot 'Signed-off-by:' but I guess you agree
 with this line in the commit message... )

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rtcwake doesn't reset wakealarm
  2012-09-12 10:31     ` Karel Zak
  2012-09-12 14:33       ` Giacomo
@ 2012-09-13 16:31       ` Paul Fox
  1 sibling, 0 replies; 8+ messages in thread
From: Paul Fox @ 2012-09-13 16:31 UTC (permalink / raw)
  To: Karel Zak; +Cc: Giacomo, util-linux

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


karel wrote:
 > On Wed, Sep 12, 2012 at 12:09:16PM +0200, Karel Zak wrote:
 > > 
 > >  Let's add Paul to CC ;-)
 > > 
 > > On Wed, Sep 12, 2012 at 09:52:14AM +0000, Giacomo wrote:
 > > > Giacomo <giacomo.perale@...> writes:
 > > > 
 > > > > 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). 
 > > > > 
 > > > > 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.
 > > > > 
 > > > 
 > > > 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
 > 
 > 
 > 
 > >From 7413ac3f50102236415267f19b23f9839a6403b0 Mon Sep 17 00:00:00 2001
 > From: Karel Zak <kzak@redhat.com>
 > Date: Wed, 12 Sep 2012 12:22:13 +0200
 > Subject: [PATCH] rtcwake: reset wakealarm
 > 
 > > 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).
 > >
 > > 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.
 > 
 > Reported-by: Giacomo <giacomo.perale@gmail.com>
 > Signed-off-by: Karel Zak <kzak@redhat.com>
 > ---
 >  sys-utils/rtcwake.c |   12 +++++++-----
 >  1 files changed, 7 insertions(+), 5 deletions(-)
 > 
 > diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
 > index 0e16bd3..6e2701a 100644
 > --- a/sys-utils/rtcwake.c
 > +++ b/sys-utils/rtcwake.c
 > @@ -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);
 > -- 
 > 1.7.7.6

=---------------------
 paul fox, pgf@laptop.org

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-09-13 16:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-11 11:11 rtcwake doesn't reset wakealarm Giacomo
2012-09-12  9:52 ` Giacomo
2012-09-12 10:09   ` Karel Zak
2012-09-12 10:31     ` Karel Zak
2012-09-12 14:33       ` Giacomo
2012-09-12 17:33         ` Giacomo
2012-09-13 11:25           ` Karel Zak
2012-09-13 16:31       ` Paul Fox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox