All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: Ingo Molnar <mingo@elte.hu>,
	kernel list <linux-kernel@vger.kernel.org>,
	Linux-pm mailing list <linux-pm@lists.osdl.org>
Subject: sleepy linux self-test
Date: Wed, 30 Jan 2008 14:17:48 +0100	[thread overview]
Message-ID: <20080130131748.GA3796@elf.ucw.cz> (raw)

Hi!

This version should work, at least it did not fail in my testing. It
does one test 5 second after bootup, then periodically once per 500
seconds. Different parameters are trivial to tweak.

Signed-off-by: Pavel Machek <pavel@suse.cz>

diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 29cf145..5bbdb70 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -78,7 +78,7 @@ static inline int is_intr(u8 rtc_intr)
 
 /*----------------------------------------------------------------*/
 
-static int cmos_read_time(struct device *dev, struct rtc_time *t)
+int cmos_read_time(struct device *dev, struct rtc_time *t)
 {
 	/* REVISIT:  if the clock has a "century" register, use
 	 * that instead of the heuristic in get_rtc_time().
@@ -170,7 +170,7 @@ static int cmos_read_alarm(struct device
 	return 0;
 }
 
-static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
+int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
 {
 	struct cmos_rtc	*cmos = dev_get_drvdata(dev);
 	unsigned char	mon, mday, hrs, min, sec;
@@ -394,6 +394,33 @@ static const struct rtc_class_ops cmos_r
 /*----------------------------------------------------------------*/
 
 static struct cmos_rtc	cmos_rtc;
+static struct device *pc_rtc_device;
+
+int set_alarm(int length)
+{
+	ssize_t retval;
+	unsigned long now, alarm;
+	struct rtc_wkalrm alm;
+
+	retval = cmos_read_time(pc_rtc_device, &alm.time);
+	if (retval < 0) {
+		printk("Auto sleep: can't get time?\n");
+		return retval;
+	}
+	rtc_tm_to_time(&alm.time, &now);
+	printk("Auto sleep: Now %ld\n", now);
+
+	alarm = now+length;
+	rtc_time_to_tm(alarm, &alm.time);
+
+	retval = cmos_set_alarm(pc_rtc_device, &alm);
+	if (retval < 0) {
+		printk("Auto sleep: can't set alarm.\n");
+		return retval;
+	}
+	printk("Auto sleep: Alarm set\n");
+	return 0;
+}
 
 static irqreturn_t cmos_interrupt(int irq, void *p)
 {
@@ -431,6 +458,8 @@ cmos_do_probe(struct device *dev, struct
 	if (cmos_rtc.dev)
 		return -EBUSY;
 
+	pc_rtc_device = dev;
+
 	if (!ports)
 		return -ENODEV;
 
@@ -546,7 +575,7 @@ cleanup0:
 
 static void cmos_do_shutdown(void)
 {
-	unsigned char	rtc_control;
+	unsigned char rtc_control;
 
 	spin_lock_irq(&rtc_lock);
 	rtc_control = CMOS_READ(RTC_CONTROL);
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 8e186c6..b719fd3 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -53,14 +53,20 @@ config PM_TRACE
 	RTC across reboots, so that you can debug a machine that just hangs
 	during suspend (or more commonly, during resume).
 
-	To use this debugging feature you should attempt to suspend the machine,
-	then reboot it, then run
+	To use this debugging feature you should attempt to suspend the
+	machine, then reboot it, then run
 
 		dmesg -s 1000000 | grep 'hash matches'
 
 	CAUTION: this option will cause your machine's real-time clock to be
 	set to an invalid time after a resume.
 
+config PM_SLEEPY_TEST
+	bool "Test suspend/resume during bootup"
+	depends on PM_DEBUG && PM_SLEEP && RTC_DRV_CMOS
+	---help---
+	This option will suspend/resume your machine during bootup.
+
 config PM_SLEEP_SMP
 	bool
 	depends on SUSPEND_SMP_POSSIBLE || HIBERNATION_SMP_POSSIBLE
diff --git a/kernel/power/Makefile b/kernel/power/Makefile
index f7dfff2..e5693d6 100644
--- a/kernel/power/Makefile
+++ b/kernel/power/Makefile
@@ -5,7 +5,7 @@ endif
 
 obj-y				:= main.o
 obj-$(CONFIG_PM_LEGACY)		+= pm.o
-obj-$(CONFIG_PM_SLEEP)		+= process.o console.o
+obj-$(CONFIG_PM_SLEEP)		+= process.o console.o sleepy.o
 obj-$(CONFIG_HIBERNATION)	+= swsusp.o disk.o snapshot.o swap.o user.o
 
 obj-$(CONFIG_MAGIC_SYSRQ)	+= poweroff.o
diff --git a/kernel/power/sleepy.c b/kernel/power/sleepy.c
new file mode 100644
index 0000000..d363260
--- /dev/null
+++ b/kernel/power/sleepy.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007 Pavel Machek <pavel@suse.cz>
+ * 
+ * This file is released under the GPLv2
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/suspend.h>
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/cpu.h>
+#include <linux/resume-trace.h>
+#include <linux/freezer.h>
+#include <linux/vmstat.h>
+#include <linux/syscalls.h>
+#include <linux/rtc.h>
+
+#include <asm/percpu.h>
+
+#include "power.h"
+
+extern int set_alarm(int length);
+
+#ifdef CONFIG_PM_SLEEPY_TEST
+static int
+test_sleep(void)
+{
+	set_alarm(5);
+	pm_suspend(PM_SUSPEND_MEM);
+	return 0;
+}
+
+late_initcall(test_sleep);
+#endif

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

             reply	other threads:[~2008-01-30 13:17 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-30 13:17 Pavel Machek [this message]
2008-01-30 16:35 ` sleepy linux self-test Ingo Molnar
2008-01-30 16:35   ` Ingo Molnar
2008-01-30 16:39   ` Pavel Machek
2008-01-30 19:36 ` Ingo Molnar
2008-01-30 23:26   ` Pavel Machek
2008-02-01 14:22     ` Ingo Molnar
2008-02-02 12:45       ` Pavel Machek
2008-02-02 13:49         ` Ingo Molnar
2008-02-02 13:51         ` Ingo Molnar
2008-02-01  1:55 ` [linux-pm] " David Brownell
2008-02-02 12:47   ` Pavel Machek
2008-02-02 13:50     ` Ingo Molnar
2008-02-02 17:49       ` David Brownell
2008-02-02 17:49       ` [linux-pm] " David Brownell
2008-02-02 18:06         ` Ingo Molnar
2008-02-02 19:47           ` David Brownell
2008-02-02 19:47           ` [linux-pm] " David Brownell
2008-02-02 18:06         ` Ingo Molnar
2008-02-02 13:50     ` Ingo Molnar
2008-02-02 17:31     ` David Brownell
2008-02-02 17:31     ` [linux-pm] " David Brownell
2008-02-02 17:51       ` David Brownell
2008-02-02 17:51       ` David Brownell
2008-02-02 18:00       ` Ingo Molnar
2008-02-02 18:00       ` [linux-pm] " Ingo Molnar
2008-02-02 19:13         ` David Brownell
2008-02-02 19:32           ` Pavel Machek
2008-02-02 19:38             ` Ingo Molnar
2008-02-02 19:38             ` [linux-pm] " Ingo Molnar
2008-02-02 19:59               ` Pavel Machek
2008-02-02 19:59               ` Pavel Machek
2008-02-03  2:37               ` [linux-pm] " David Brownell
2008-02-03  5:05                 ` Ingo Molnar
2008-02-03  5:05                 ` [linux-pm] " Ingo Molnar
2008-02-03  5:14                   ` Ingo Molnar
2008-02-03  5:19                     ` Ingo Molnar
2008-02-03  5:19                     ` [linux-pm] " Ingo Molnar
2008-02-03  5:35                       ` Ingo Molnar
2008-02-03  5:35                       ` [linux-pm] " Ingo Molnar
2008-02-03  5:54                         ` Ingo Molnar
2008-02-03  7:05                           ` Ingo Molnar
2008-02-03  7:05                           ` [linux-pm] " Ingo Molnar
2008-02-03  7:32                             ` David Brownell
2008-02-03  7:32                             ` [linux-pm] " David Brownell
2008-02-03 12:21                               ` Rafael J. Wysocki
2008-02-03 12:21                               ` [linux-pm] " Rafael J. Wysocki
2008-02-03 13:16                                 ` David Brownell
2008-02-03 13:16                                 ` [linux-pm] " David Brownell
2008-02-03 21:29                                   ` Rafael J. Wysocki
2008-02-03 21:29                                   ` [linux-pm] " Rafael J. Wysocki
2008-02-03 22:42                                     ` David Brownell
2008-02-03 22:43                                       ` Rafael J. Wysocki
2008-02-03 22:43                                       ` Rafael J. Wysocki
2008-02-03 22:48                                       ` Pavel Machek
2008-02-03 22:48                                       ` [linux-pm] " Pavel Machek
2008-02-03 23:08                                         ` David Brownell
2008-02-10 21:03                                           ` Pavel Machek
2008-02-10 21:03                                           ` Pavel Machek
2008-02-03 23:08                                         ` David Brownell
2008-02-03 22:42                                     ` David Brownell
2008-02-18  8:56                                   ` Pavel Machek
2008-02-18  8:56                                   ` [linux-pm] " Pavel Machek
2008-02-18  9:46                                     ` [patch] suspend/resume self-test Ingo Molnar
2008-02-18  9:46                                     ` Ingo Molnar
2008-02-18  9:53                                       ` Pavel Machek
2008-02-18 10:40                                         ` David Brownell
2008-02-18 10:40                                         ` David Brownell
2008-02-18 11:04                                           ` Rafael J. Wysocki
2008-02-18 11:04                                           ` Rafael J. Wysocki
2008-02-18 13:09                                           ` Ingo Molnar
2008-02-18 20:16                                             ` David Brownell
2008-02-18 20:16                                             ` David Brownell
2008-02-19 10:11                                               ` Pavel Machek
2008-02-19 10:11                                                 ` Pavel Machek
2008-02-19 14:43                                                 ` Ingo Molnar
2008-02-19 14:43                                                 ` Ingo Molnar
2008-02-19 19:12                                                   ` David Brownell
2008-02-20 10:15                                                     ` Ingo Molnar
2008-02-20 10:15                                                     ` Ingo Molnar
2008-02-19 19:12                                                   ` David Brownell
2008-02-19 14:40                                               ` Ingo Molnar
2008-02-19 14:40                                               ` Ingo Molnar
2008-02-18 13:09                                           ` Ingo Molnar
2008-02-18  9:53                                       ` Pavel Machek
2008-02-18 11:06                                       ` Rafael J. Wysocki
2008-02-18 11:06                                       ` Rafael J. Wysocki
2008-02-10 21:02                           ` [linux-pm] sleepy linux self-test Pavel Machek
2008-02-10 21:02                           ` Pavel Machek
2008-02-03  5:54                         ` Ingo Molnar
2008-02-03  7:18                     ` David Brownell
2008-02-03  7:18                     ` [linux-pm] " David Brownell
2008-02-03  7:51                       ` Sam Ravnborg
2008-02-03  7:51                       ` [linux-pm] " Sam Ravnborg
2008-02-03  8:26                         ` David Brownell
2008-02-03  8:26                         ` [linux-pm] " David Brownell
2008-02-03  5:14                   ` Ingo Molnar
2008-02-03  2:37               ` David Brownell
2008-02-02 19:32           ` Pavel Machek
2008-02-02 19:13         ` David Brownell
2008-02-02 12:47   ` Pavel Machek
2008-02-01  1:55 ` David Brownell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080130131748.GA3796@elf.ucw.cz \
    --to=pavel@ucw.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.osdl.org \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.