Skip to contentSkip to conversation

swsusp3: push image reading/writing into userspace

PATCH Pavel Machek 3 participants 9 messages Sep 14, 2005 – Sep 15, 2005

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi!

Here's prototype code for swsusp3. It seems to work for me, but don't try it... yet. Code is very ugly at places, sorry, I know and will fix it. This is just proof that it can be done, and that it can be done without excessive ammount of code.

Pavel

drivers/char/mem.c +42 -0
@@ -27,6 +27,7 @@
 #include <linux/crash_dump.h>
 #include <linux/backing-dev.h>
 #include <linux/bootmem.h>
+#include <linux/suspend.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -466,6 +467,7 @@ do_write_kmem(void *p, unsigned long rea
 }
 
 
+
 /*
  * This function writes to the *virtual* memory as seen by the kernel.
  */
@@ -565,6 +567,45 @@ static ssize_t write_port(struct file * 
 }
 #endif
 
+static int
+ioctl_kmem(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+        int retval = 0;
+
+        switch (cmd) {
+	case IOCTL_FREEZE:
+		retval = sys_freeze();
+		break;
+	case IOCTL_UNFREEZE:
+		retval = sys_unfreeze();
+		break;
+	case IOCTL_ATOMIC_SNAPSHOT:
+		retval = sys_atomic_snapshot(arg);
+		break;
+	case IOCTL_ATOMIC_RESTORE:
+		{
+			int pages;
+			void *pgdir;
+			get_user(pages, (long *) arg);
+			get_user(pgdir, (long *) (arg + 4));
+			retval = sys_atomic_restore(pgdir, pages);
+		}
+		break;
+	case IOCTL_KMALLOC:
+		retval = get_zeroed_page(GFP_KERNEL);
+		break;
+	case IOCTL_KFREE:
+		free_page(arg);
+		break;
+        default:
+                retval = -ENOTTY;
+                break;
+        }
+
+        return retval;
+}
+
+
 static ssize_t read_null(struct file * file, char __user * buf,
 			 size_t count, loff_t *ppos)
 {
@@ -775,6 +816,7 @@ static struct file_operations mem_fops =
 static struct file_operations kmem_fops = {
 	.llseek		= memory_lseek,
 	.read		= read_kmem,
+	.ioctl		= ioctl_kmem,
 	.write		= write_kmem,
 	.mmap		= mmap_kmem,
 	.open		= open_kmem,
drivers/char/tipar.c +1 -1
@@ -360,7 +360,7 @@ tipar_ioctl(struct inode *inode, struct 
 
 	switch (cmd) {
 	case IOCTL_TIPAR_DELAY:
-		delay = (int)arg;    //get_user(delay, &arg);
+		delay = (int)arg;
 		break;
 	case IOCTL_TIPAR_TIMEOUT:
 		if (arg != 0)
include/linux/suspend.h +13 -0
@@ -1,6 +1,7 @@
 #ifndef _LINUX_SWSUSP_H
 #define _LINUX_SWSUSP_H
 
+#ifdef __KERNEL__
 #if defined(CONFIG_X86) || defined(CONFIG_FRV) || defined(CONFIG_PPC32)
 #include <asm/suspend.h>
 #endif
@@ -9,6 +10,7 @@
 #include <linux/config.h>
 #include <linux/init.h>
 #include <linux/pm.h>
+#endif
 
 /* page backup entry */
 typedef struct pbe {
@@ -30,6 +32,7 @@ typedef struct pbe {
 #define for_each_pb_page(pbe, pblist) \
 	for (pbe = pblist ; pbe ; pbe = (pbe+PB_PAGE_SKIP)->next)
 
+#ifdef __KERNEL__
 
 #define SWAP_FILENAME_MAXLENGTH	32
 
@@ -72,4 +75,14 @@ struct saved_context;
 void __save_processor_state(struct saved_context *ctxt);
 void __restore_processor_state(struct saved_context *ctxt);
 
+#endif
+
+#define IOCTL_FREEZE 0xeee
+#define IOCTL_UNFREEZE 0x70eee
+#define IOCTL_ATOMIC_SNAPSHOT 0x5a5707
+#define IOCTL_ATOMIC_RESTORE 0x8e5708e
+#define IOCTL_KMALLOC 0xa770c
+#define IOCTL_KFREE 0xfee
+
+
 #endif /* _LINUX_SWSUSP_H */
kernel/power/console.c +1 -0
@@ -9,6 +9,7 @@
 #include <linux/console.h>
 #include "power.h"
 
+#undef SUSPEND_CONSOLE
 static int new_loglevel = 10;
 static int orig_loglevel;
 #ifdef SUSPEND_CONSOLE
kernel/power/disk.c +18 -1
@@ -106,6 +106,7 @@ static void free_some_memory(void)
 	}
 }
 
+/* FIXME: Call it when appropriate */
 static inline void platform_finish(void)
 {
 	if (pm_disk_mode == PM_DISK_PLATFORM) {
@@ -146,12 +147,25 @@ thaw:
 
 static void unprepare_processes(void)
 {
-	platform_finish();
 	thaw_processes();
 	enable_nonboot_cpus();
 	pm_restore_console();
 }
 
+
+int sys_freeze(void)
+{
+	return prepare_processes();
+}
+
+int sys_unfreeze(void)
+{
+	thaw_processes();
+	enable_nonboot_cpus();
+	pm_restore_console();
+	return 0;
+}
+
 /**
  *	pm_suspend_disk - The granpappy of power management.
  *
@@ -247,6 +261,9 @@ static int software_resume(void)
 	if ((error = swsusp_check()))
 		goto Done;
 
+	/* Prepare processes only after swsusp_check; we could do it before,
+	   but it would mean an ugly console switch even in case of normal boot.
+	 */
 	pr_debug("PM: Preparing processes for restore.\n");
 
 	if ((error = prepare_processes())) {
kernel/power/power.h +1 -1
@@ -1,7 +1,7 @@
 #include <linux/suspend.h>
 #include <linux/utsname.h>
 
-/* With SUSPEND_CONSOLE defined, it suspend looks *really* cool, but
+/* With SUSPEND_CONSOLE defined suspend looks *really* cool, but
    we probably do not take enough locks for switching consoles, etc,
    so bad things might happen.
 */
kernel/power/swsusp.c +105 -7

235 lines not on this page · raw message

usr/swsusp.c new file +487 -0

487 lines not on this page · raw message

Signature · 1 line
if you have sharp zaurus hardware you don't need... you know my address
#1 lore raw

Hi Pavel.

Quoted 6 lines · Pavel Machek

Hi!

Here's prototype code for swsusp3. It seems to work for me, but don't try it... yet. Code is very ugly at places, sorry, I know and will fix it. This is just proof that it can be done, and that it can be done without excessive ammount of code.

No comments on the code sorry. Instead I want to ask, could you please find a different name? swsusp3 is going to make people think that it's Suspend2 redesigned. Since there hasn't been a swsusp2 (so far as I know), how about using that name instead? At least then we'll clearly differentiate the two implementations and you won't confuse/irritate users.

Regards,

Nigel

#2 lore raw
Quoted 10 lines · Nigel Cunningham

Hi Pavel.

Quoted 6 lines · Pavel Machek

Hi!

Here's prototype code for swsusp3. It seems to work for me, but don't try it... yet. Code is very ugly at places, sorry, I know and will fix it. This is just proof that it can be done, and that it can be done without excessive ammount of code.

Quoted 4 lines

No comments on the code sorry. Instead I want to ask, could you please find a different name? swsusp3 is going to make people think that it's Suspend2 redesigned. Since there hasn't been a swsusp2 (so far as I know),

swsusp2 seems to be the common/trivial name for suspend2 (at least while struggling to get any kind of suspend working here, helpful people have refered to suspend2 as swsusp2)

Quoted 3 lines

how about using that name instead? At least then we'll clearly differentiate the two implementations and you won't confuse/irritate users.

if he would use that people would get quite confused and not know if people mean your suspend2 or his swsusp2

Just a thought,

Daniel

#3 lore raw

Hi.

Quoted 11 lines · Daniel Goller
Quoted 10 lines · Nigel Cunningham

Hi Pavel.

Quoted 6 lines · Pavel Machek

Hi!

Here's prototype code for swsusp3. It seems to work for me, but don't try it... yet. Code is very ugly at places, sorry, I know and will fix it. This is just proof that it can be done, and that it can be done without excessive ammount of code.

Quoted 8 lines
Quoted 4 lines

No comments on the code sorry. Instead I want to ask, could you please find a different name? swsusp3 is going to make people think that it's Suspend2 redesigned. Since there hasn't been a swsusp2 (so far as I know),

swsusp2 seems to be the common/trivial name for suspend2 (at least while struggling to get any kind of suspend working here, helpful people have refered to suspend2 as swsusp2)

Yes, they do sometimes. But that's not right since 'sw' is at least sometimes treated as an abbreviation for swap. Suspend2 isn't limited to writing to swap. That (along with the fact that swsusp is an ugly acronym) is the reason why I've tried to push away from using that term.

Quoted 6 lines
Quoted 3 lines

how about using that name instead? At least then we'll clearly differentiate the two implementations and you won't confuse/irritate users.

if he would use that people would get quite confused and not know if people mean your suspend2 or his swsusp2

If they're clearly differentiated, that shouldn't be a problem. In fact, it would help differentiate them.

Quoted 1 line

Just a thought,

Thanks!

Nigel

Quoted 6 lines

Daniel
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw
In reply to Nigel Cunningham

Hi!

Quoted 11 lines
Quoted 4 lines

Here's prototype code for swsusp3. It seems to work for me, but don't try it... yet. Code is very ugly at places, sorry, I know and will fix it. This is just proof that it can be done, and that it can be done without excessive ammount of code.

No comments on the code sorry. Instead I want to ask, could you please find a different name? swsusp3 is going to make people think that it's Suspend2 redesigned. Since there hasn't been a swsusp2 (so far as I know), how about using that name instead? At least then we'll clearly differentiate the two implementations and you won't confuse/irritate users.

swsusp2 can't be used, it is already "taken" by suspend2 (25000 hits on google). I was actually hoping that you would release suspend4 (using swsusp3 infrastructure) :-).

I guess I could call it "uswsusp".

Pavel

Signature · 1 line
if you have sharp zaurus hardware you don't need... you know my address
#5 lore raw

Hi.

Quoted 14 lines · Pavel Machek

Hi!

Quoted 11 lines
Quoted 4 lines

Here's prototype code for swsusp3. It seems to work for me, but don't try it... yet. Code is very ugly at places, sorry, I know and will fix it. This is just proof that it can be done, and that it can be done without excessive ammount of code.

No comments on the code sorry. Instead I want to ask, could you please find a different name? swsusp3 is going to make people think that it's Suspend2 redesigned. Since there hasn't been a swsusp2 (so far as I know), how about using that name instead? At least then we'll clearly differentiate the two implementations and you won't confuse/irritate users.

Quoted 3 lines

swsusp2 can't be used, it is already "taken" by suspend2 (25000 hits on google). I was actually hoping that you would release suspend4 (using swsusp3 infrastructure) :-).

You could reclaim it. There are 10 times as many hits (239,000) for suspend2, and I've never wanted it to be called swsusp2 anyway :). As for suspend4, at the moment, I'm not planning on ever progressing beyond 2.x.

Quoted 1 line

I guess I could call it "uswsusp".

u as in micro?

Regards,

Nigel

Quoted 1 line

Pavel

#6 lore raw

Hi!

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

Here's prototype code for swsusp3. It seems to work for me, but don't try it... yet. Code is very ugly at places, sorry, I know and will fix it. This is just proof that it can be done, and that it can be done without excessive ammount of code.

No comments on the code sorry. Instead I want to ask, could you please find a different name? swsusp3 is going to make people think that it's Suspend2 redesigned. Since there hasn't been a swsusp2 (so far as I know), how about using that name instead? At least then we'll clearly differentiate the two implementations and you won't confuse/irritate users.

Quoted 8 lines
Quoted 3 lines

swsusp2 can't be used, it is already "taken" by suspend2 (25000 hits on google). I was actually hoping that you would release suspend4 (using swsusp3 infrastructure) :-).

You could reclaim it. There are 10 times as many hits (239,000) for suspend2, and I've never wanted it to be called swsusp2 anyway :). As for suspend4, at the moment, I'm not planning on ever progressing beyond 2.x.

Sorry, have to ask...

"not planning on progressing" == version number stays "2" no matter what changes, or "not planning on progressing" == not plan to use swsusp3/uswsusp infrastructure?

Quoted 3 lines
Quoted 1 line

I guess I could call it "uswsusp".

u as in micro?

Originaly I thought about it as "userland-swsusp", but micro-swsusp sounds nice, too.
Pavel

Signature · 1 line
if you have sharp zaurus hardware you don't need... you know my address
#7 lore raw

Hi.

Quoted 23 lines · Pavel Machek

Hi!

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

Here's prototype code for swsusp3. It seems to work for me, but don't try it... yet. Code is very ugly at places, sorry, I know and will fix it. This is just proof that it can be done, and that it can be done without excessive ammount of code.

No comments on the code sorry. Instead I want to ask, could you please find a different name? swsusp3 is going to make people think that it's Suspend2 redesigned. Since there hasn't been a swsusp2 (so far as I know), how about using that name instead? At least then we'll clearly differentiate the two implementations and you won't confuse/irritate users.

Quoted 8 lines
Quoted 3 lines

swsusp2 can't be used, it is already "taken" by suspend2 (25000 hits on google). I was actually hoping that you would release suspend4 (using swsusp3 infrastructure) :-).

You could reclaim it. There are 10 times as many hits (239,000) for suspend2, and I've never wanted it to be called swsusp2 anyway :). As for suspend4, at the moment, I'm not planning on ever progressing beyond 2.x.

Quoted 5 lines

Sorry, have to ask...

"not planning on progressing" == version number stays "2" no matter what changes, or "not planning on progressing" == not plan to use swsusp3/uswsusp infrastructure?

I'm not planning on ever progressing beyond 2.x because I'm seeing the code I have now as pretty much feature complete. There are a few small areas that I'd like to improve (reinstating module support being one - it was a mistake to remove it), but I don't see the need for a complete redesign. That said, I was careful to say 'at the moment'. I'm not denying for a second that things might change.

Regarding the 'swsusp3/uswsusp infrastructure': as I see it at the moment (feel free to correct me), your new revision is only moving as much code as you can to userspace (plus changes that are made necessary by that). Beyond maybe reducing the kernel size a little, I don't see any advantage to that - it just makes things more complicated and requires the user to set up more in the way of an initrd or initramfs in order to suspend and resume. You end up with more code to maintain to get the same functionality (same amount of kernel code or slightly less plus extra userland code to do all the reading and writing). I'm speaking from experience. Bernard and I moved the userinterface code to userspace to make others happy and that fact that we ended up with more code shouldn't surprise anyone. You need all the code you had before plus code for the interface (at least).

If the main impetus is seeking to reduce kernel code size, why not just provide the option of building your code as a module for those who are concerned about that statistic?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I guess I could call it "uswsusp".

u as in micro?

Originaly I thought about it as "userland-swsusp", but micro-swsusp sounds nice, too.

I think people would think of micro more readily that userland, but it's your choice :)

Regards,

Nigel
Pavel

#8 lore raw

Hi!

Quoted 11 lines
Quoted 10 lines
Quoted 4 lines

You could reclaim it. There are 10 times as many hits (239,000) for suspend2, and I've never wanted it to be called swsusp2 anyway :). As for suspend4, at the moment, I'm not planning on ever progressing beyond 2.x.

Sorry, have to ask...

"not planning on progressing" == version number stays "2" no matter what changes, or "not planning on progressing" == not plan to use swsusp3/uswsusp infrastructure?

Quoted 6 lines

I'm not planning on ever progressing beyond 2.x because I'm seeing the code I have now as pretty much feature complete. There are a few small areas that I'd like to improve (reinstating module support being one - it was a mistake to remove it), but I don't see the need for a complete redesign. That said, I was careful to say 'at the moment'. I'm not denying for a second that things might change.

Ok.

Quoted 9 lines

Regarding the 'swsusp3/uswsusp infrastructure': as I see it at the moment (feel free to correct me), your new revision is only moving as much code as you can to userspace (plus changes that are made necessary by that). Beyond maybe reducing the kernel size a little, I don't see any advantage to that - it just makes things more complicated and requires the user to set up more in the way of an initrd or initramfs in order to suspend and resume. You end up with more code to maintain to get the same functionality (same amount of kernel code or slightly less plus extra userland code to do all the reading and writing). I'm

Agreed. OTOH interface code is quite small (~100 lines).

Quoted 3 lines

If the main impetus is seeking to reduce kernel code size, why not just provide the option of building your code as a module for those who are concerned about that statistic?

It is source code size that I'm concerned about. And flexibility; with writer in userspace, I (or anyone else :-) can do all kinds of graphical progress bars, esc-to-cancel, ... that would be too ugly to do in kernel.
Pavel

Signature · 1 line
if you have sharp zaurus hardware you don't need... you know my address