Re: sleepy linux self-test

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Pavel Machek <pavel@...>
Cc: kernel list <linux-kernel@...>, Linux-pm mailing list <linux-pm@...>
Date: Saturday, February 2, 2008 - 9:49 am

* Pavel Machek <pavel@ucw.cz> wrote:


thanks. Find below it rebased against latest -git. (there was a trivial 
merge reject in power/Kconfig)

	Ingo

---
 drivers/rtc/rtc-cmos.c |   38 ++++++++++++++++++++++++++++++++++---
 kernel/power/Kconfig   |   10 +++++++--
 kernel/power/Makefile  |    2 -
 kernel/power/sleepy.c  |   50 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+), 6 deletions(-)

Index: linux/drivers/rtc/rtc-cmos.c
===================================================================
--- linux.orig/drivers/rtc/rtc-cmos.c
+++ linux/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,35 @@ 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;
+
+	if (!pc_rtc_device)
+		return -EFAULT;
+	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 +460,8 @@ cmos_do_probe(struct device *dev, struct
 	if (cmos_rtc.dev)
 		return -EBUSY;
 
+	pc_rtc_device = dev;
+
 	if (!ports)
 		return -ENODEV;
 
@@ -546,7 +577,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);
@@ -561,6 +592,7 @@ static void __exit cmos_do_remove(struct
 	struct cmos_rtc	*cmos = dev_get_drvdata(dev);
 	struct resource *ports;
 
+	pc_rtc_device = NULL;
 	cmos_do_shutdown();
 
 	if (is_valid_irq(cmos->irq))
Index: linux/kernel/power/Kconfig
===================================================================
--- linux.orig/kernel/power/Kconfig
+++ linux/kernel/power/Kconfig
@@ -74,14 +74,20 @@ config PM_TRACE_RTC
 	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 SMP
Index: linux/kernel/power/Makefile
===================================================================
--- linux.orig/kernel/power/Makefile
+++ linux/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
Index: linux/kernel/power/sleepy.c
===================================================================
--- /dev/null
+++ linux/kernel/power/sleepy.c
@@ -0,0 +1,50 @@
+/*
+ * 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 <linux/kthread.h>
+
+#include <asm/percpu.h>
+
+#include "power.h"
+
+extern int set_alarm(int length);
+
+int ksleepyd(void *data)
+{
+	msleep(5000);
+	while (1) {
+		if (set_alarm(5))
+			return -EFAULT;
+		pm_suspend(PM_SUSPEND_MEM);
+		msleep(500000);
+	}
+}
+
+#ifdef CONFIG_PM_SLEEPY_TEST
+static int
+test_sleep(void)
+{
+	wake_up_process(kthread_create(ksleepyd, NULL, "ksleepyd"));
+	return 0;
+}
+
+late_initcall(test_sleep);
+#endif
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
sleepy linux self-test, Pavel Machek, (Wed Jan 30, 9:17 am)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Thu Jan 31, 9:55 pm)
Re: [linux-pm] sleepy linux self-test, Pavel Machek, (Sat Feb 2, 8:47 am)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sat Feb 2, 1:31 pm)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sat Feb 2, 2:00 pm)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sat Feb 2, 3:13 pm)
Re: [linux-pm] sleepy linux self-test, Pavel Machek, (Sat Feb 2, 3:32 pm)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sat Feb 2, 3:38 pm)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sat Feb 2, 10:37 pm)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sun Feb 3, 1:05 am)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sun Feb 3, 1:14 am)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sun Feb 3, 3:18 am)
Re: [linux-pm] sleepy linux self-test, Sam Ravnborg, (Sun Feb 3, 3:51 am)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sun Feb 3, 4:26 am)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sun Feb 3, 1:19 am)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sun Feb 3, 1:35 am)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sun Feb 3, 1:54 am)
Re: [linux-pm] sleepy linux self-test, Pavel Machek, (Sun Feb 10, 5:02 pm)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sun Feb 3, 3:05 am)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sun Feb 3, 3:32 am)
Re: [linux-pm] sleepy linux self-test, Rafael J. Wysocki, (Sun Feb 3, 8:21 am)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sun Feb 3, 9:16 am)
Re: [linux-pm] sleepy linux self-test, Pavel Machek, (Mon Feb 18, 4:56 am)
[patch] suspend/resume self-test, Ingo Molnar, (Mon Feb 18, 5:46 am)
Re: [patch] suspend/resume self-test, Rafael J. Wysocki, (Mon Feb 18, 7:06 am)
Re: [patch] suspend/resume self-test, Pavel Machek, (Mon Feb 18, 5:53 am)
Re: [patch] suspend/resume self-test, David Brownell, (Mon Feb 18, 6:40 am)
Re: [patch] suspend/resume self-test, Ingo Molnar, (Mon Feb 18, 9:09 am)
Re: [patch] suspend/resume self-test, David Brownell, (Mon Feb 18, 4:16 pm)
Re: [patch] suspend/resume self-test, Ingo Molnar, (Tue Feb 19, 10:40 am)
Re: [patch] suspend/resume self-test, Pavel Machek, (Tue Feb 19, 6:11 am)
Re: [patch] suspend/resume self-test, Ingo Molnar, (Tue Feb 19, 10:43 am)
Re: [patch] suspend/resume self-test, David Brownell, (Tue Feb 19, 3:12 pm)
Re: [patch] suspend/resume self-test, Ingo Molnar, (Wed Feb 20, 6:15 am)
Re: [patch] suspend/resume self-test, Rafael J. Wysocki, (Mon Feb 18, 7:04 am)
Re: [linux-pm] sleepy linux self-test, Rafael J. Wysocki, (Sun Feb 3, 5:29 pm)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sun Feb 3, 6:42 pm)
Re: [linux-pm] sleepy linux self-test, Pavel Machek, (Sun Feb 3, 6:48 pm)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sun Feb 3, 7:08 pm)
Re: [linux-pm] sleepy linux self-test, Pavel Machek, (Sun Feb 10, 5:03 pm)
Re: [linux-pm] sleepy linux self-test, Rafael J. Wysocki, (Sun Feb 3, 6:43 pm)
Re: [linux-pm] sleepy linux self-test, Pavel Machek, (Sat Feb 2, 3:59 pm)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sat Feb 2, 1:51 pm)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sat Feb 2, 9:50 am)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sat Feb 2, 1:49 pm)
Re: [linux-pm] sleepy linux self-test, Ingo Molnar, (Sat Feb 2, 2:06 pm)
Re: [linux-pm] sleepy linux self-test, David Brownell, (Sat Feb 2, 3:47 pm)
Re: sleepy linux self-test, Ingo Molnar, (Wed Jan 30, 3:36 pm)
Re: sleepy linux self-test, Pavel Machek, (Wed Jan 30, 7:26 pm)
Re: sleepy linux self-test, Ingo Molnar, (Fri Feb 1, 10:22 am)
Re: sleepy linux self-test, Pavel Machek, (Sat Feb 2, 8:45 am)
Re: sleepy linux self-test, Ingo Molnar, (Sat Feb 2, 9:51 am)
Re: sleepy linux self-test, Ingo Molnar, (Sat Feb 2, 9:49 am)
Re: sleepy linux self-test, Ingo Molnar, (Wed Jan 30, 12:35 pm)
Re: sleepy linux self-test, Pavel Machek, (Wed Jan 30, 12:39 pm)