public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* swsusp cleanups
@ 2002-05-15 19:52 Pavel Machek
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Machek @ 2002-05-15 19:52 UTC (permalink / raw)
  To: alan, kernel list, fchabaud

Hi!

This cleans up swsusp a bit, many of this originaly by Florent. Oh,
this makes it actually turn off machine, not debugging behaviour we
had before. Please apply.

								Pavel

--- linux-ac/drivers/ide/ide-disk.c	Thu May  9 00:02:39 2002
+++ linux-swsusp.24/drivers/ide/ide-disk.c	Wed May 15 21:35:13 2002
@@ -1540,7 +1540,6 @@
 void ide_disk_suspend(void)
 {
 	int i;
-	printk("ide_disk_suspend()\n");
 	while (ide_disks_busy()) {
 		printk("*");
 		schedule();
@@ -1562,7 +1561,6 @@
 void ide_disk_unsuspend(void)
 {
 	int i;
-	printk("ide_disk_unsuspend()\n");
 	for (i=0; i<MAX_HWIFS; i++) {
 		struct hwgroup_s *hwgroup = ide_hwifs[i].hwgroup;
 
@@ -1576,7 +1574,6 @@
 void ide_disk_resume(void)
 {
 	int i;
-	printk("ide_disk_resume()\n");
 	for (i=0; i<MAX_HWIFS; i++) {
 		struct hwgroup_s *hwgroup = ide_hwifs[i].hwgroup;
 
--- linux-ac/kernel/suspend.c	Thu May  9 00:02:42 2002
+++ linux-swsusp.24/kernel/suspend.c	Wed May 15 21:41:02 2002
@@ -161,6 +161,7 @@
 #define	DEBUG_DEFAULT	1
 #undef	DEBUG_PROCESS
 #undef	DEBUG_SLOW
+#define TEST_SWSUSP 0		/* Set to 1 to reboot instead of halt machine after suspension */
 
 #ifdef DEBUG_DEFAULT
 #define PRINTD(func, f, a...)	\
@@ -380,7 +381,7 @@
 			swapfile_used[i]=SWAPFILE_UNUSED;
 		} else {
 			if(!len) {
-	    			PRINTS(KERN_WARNING "resume= option should be used to set suspend device" );
+	    			printk(KERN_WARNING "resume= option should be used to set suspend device" );
 				if(root_swap == 0xFFFF) {
 					swapfile_used[i] = SWAPFILE_SUSPEND;
 					root_swap = i;
@@ -834,10 +835,6 @@
 	 * filesystem clean: it is not. (And it does not matter, if we resume
 	 * correctly, we'll mark system clean, anyway.)
 	 */
-#if 0
-	do_suspend_sync();
-/* Is this really so bright idea? We might corrupt FS here! */
-#endif
 	return 0;
 }
 
@@ -848,12 +845,11 @@
 #ifdef CONFIG_VT
 	printk(KERN_EMERG "shift_state: %04x\n", shift_state);
 	mdelay(1000);
-	if ((shift_state & (1 << KG_CTRL)))
-		machine_power_off();
+	if (TEST_SWSUSP ^ (!!(shift_state & (1 << KG_CTRL))))
+		machine_restart(NULL);
 	else
 #endif
-		machine_restart(NULL);
-
+		machine_power_off();
 
 	printk(KERN_EMERG "%sProbably not capable for powerdown. System halted.\n", name_suspend);
 	machine_halt();
@@ -862,17 +858,6 @@
 	/* NOTREACHED */
 }
 
-static void restore_task(void)
-{
-	MDELAY(1000);
-#if 0
-	/* Should not be neccessary -- we saved whole CPU context */
-	PRINTR( "Activating task\n" );
-	activate_mm(current->mm,current->mm);
-	activate_task(current);
-#endif
-}
-
 /* forward decl */
 static void do_software_suspend(void);
 
@@ -909,9 +894,6 @@
 	mark_swapfiles(((swp_entry_t) {0}), MARK_SWAP_RESUME);
 	PRINTK( "ok\n" );
 
-#if 0
-	restore_task ();	/* Should not be neccessary! */
-#endif
 #ifdef SUSPEND_CONSOLE
 	update_screen(fg_console);	/* Hmm, is this the problem? */
 #endif
@@ -975,9 +957,6 @@
 			 */
 			PRINTS( "Syncing disks before copy\n" );
 			do_suspend_sync();
-#if 0
-			schedule_timeout(1*HZ);	/* Is this needed to get data properly to disk? */
-#endif
 			drivers_suspend();
 			if(drivers_suspend()==0)
 				do_magic(0);			/* This function returns after machine woken up from resume */
@@ -1148,13 +1127,14 @@
 		return -1;
 	}
 	memcpy(buf, bh->b_data, PAGE_SIZE);
-	brelse(bh);			/* FIXME: maybe bforget should be here */
+	BUG_ON(!buffer_uptodate(bh));
+	brelse(bh);
 	return 0;
 } 
 
 /* Checked up-to HERE */
 
-int resume_try_to_read(const char * specialfile)
+static int resume_try_to_read(const char * specialfile, int noresume)
 {
 	union diskpage *cur;
 	swp_entry_t next;
@@ -1284,7 +1264,7 @@
 			printk( "%sError %d resuming\n", name_resume, error );
 			panic("Wanted to resume but it did not work\n");
 	}
-	set_blocksize(resume_device, blksize);	/* Needed! In case its is normal swap space */
+	set_blocksize(resume_device, blksize);	/* Needed! In case it is normal swap space */
 	MDELAY(1000);
 	return error;
 }
@@ -1322,7 +1302,7 @@
 	}
 
 	printk( "resuming from %s\n", resume_file);
-	if(resume_try_to_read(resume_file))
+	if(resume_try_to_read(resume_file, 0))
 		goto read_failure;
 	do_magic(1);
 	panic("This never returns");
@@ -1332,8 +1312,7 @@
 	return;
 }
 
-
-int resume_setup(char *str)
+static int __init resume_setup(char *str)
 {
 	if(resume_status)
 		return 1;
@@ -1347,7 +1326,7 @@
 static int __init software_noresume(char *str)
 {
 	if(!resume_status)
-		printk(KERN_WARNING "noresume option has overridden a resume= option\n");
+		printk(KERN_WARNING "noresume option lacks a resume= option\n");
 	resume_status = NORESUME;
 	
 	return 1;

-- 
(about SSSCA) "I don't say this lightly.  However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy." --hpa

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

* swsusp cleanups
@ 2002-05-23 21:45 Pavel Machek
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Machek @ 2002-05-23 21:45 UTC (permalink / raw)
  To: kernel list, torvalds

Hi!

These are cleanups. They do not change any code, except killing
printk's. Please apply.
								Pavel

--- linux-swsusp.linus/Documentation/swsusp.txt	Wed May 22 21:12:16 2002
+++ linux-swsusp/Documentation/swsusp.txt	Wed May 22 10:49:32 2002
@@ -138,7 +138,6 @@
 Not so important ideas for implementing
 
 - If a real time process is running then don't suspend the machine.
-- Is there any sense in compressing the outwritten pages?
 - Support for power.conf file as in Solaris, autoshutdown, special
   devicetypes support, maybe in sysctl.
 - Introduce timeout for SMP locking. But first locking ought to work :O
--- linux-swsusp.linus/arch/i386/kernel/acpi_wakeup.S	Wed May 22 21:12:16 2002
+++ linux-swsusp/arch/i386/kernel/acpi_wakeup.S	Wed May 22 23:22:53 2002
@@ -17,11 +17,6 @@
 	cli
 	cld
 	  
-# setup video mode
-#	movw	$0x4117, %bx		# 0x4000 for linear framebuffer
-#	movw	$0x4f02, %ax
-#	int	$0x10
-
 	# setup data segment
 	movw	%cs, %ax
 
--- linux-swsusp.linus/drivers/acpi/acpi_system.c	Wed May 22 21:12:16 2002
+++ linux-swsusp/drivers/acpi/acpi_system.c	Wed May 22 21:16:32 2002
@@ -271,11 +272,9 @@
 		break;
 	}
 
-	printk("acpi_restore_register_state...");
 	acpi_restore_register_state();
 	restore_flags(flags);
 
-	printk("acpi returning...");
 	return status;
 }
 
@@ -322,9 +321,7 @@
 	 * no matter what.
 	 */
 	acpi_system_restore_state(state);
-	printk("acpi_leave_sleep_state...");
 	acpi_leave_sleep_state(state);
-	printk("ook\n");
 
 	/* make sure interrupts are enabled */
 	ACPI_ENABLE_IRQS();
--- linux-swsusp.linus/drivers/pci/power.c	Wed May 22 21:12:16 2002
+++ linux-swsusp/drivers/pci/power.c	Wed May 22 21:19:46 2002
@@ -110,7 +110,7 @@
 	return error;
 }
 
-int pci_pm_suspend(u32 state)
+static int pci_pm_suspend(u32 state)
 {
 	struct list_head *list;
 	struct pci_bus *bus;
@@ -123,7 +123,7 @@
 	return 0;
 }
 
-int pci_pm_resume(void)
+static int pci_pm_resume(void)
 {
 	struct list_head *list;
 	struct pci_bus *bus;
--- linux-swsusp.linus/include/asm-i386/suspend.h	Wed May 22 21:12:17 2002
+++ linux-swsusp/include/asm-i386/suspend.h	Wed May 22 23:26:51 2002
@@ -209,15 +209,12 @@
 
 	/*
 	 * now restore the descriptor tables to their proper values
+	 * ltr is done i fix_processor_context().
 	 */
 	asm volatile ("lgdt (%0)" :: "m" (saved_context.gdt_limit));
 	asm volatile ("lidt (%0)" :: "m" (saved_context.idt_limit));
 	asm volatile ("lldt (%0)" :: "m" (saved_context.ldt));
 
-#if 0
-	asm volatile ("ltr (%0)"  :: "m" (saved_context.tr));
-#endif
-
 	fix_processor_context();
 
 	/*
@@ -230,7 +227,6 @@
 
 #endif
 #ifdef SUSPEND_C
-#if 1
 /* Local variables for do_magic */
 static int loop __nosavedata = 0;
 static int loop2 __nosavedata = 0;
@@ -269,36 +265,38 @@
 /*
  * Final function for resuming: after copying the pages to their original
  * position, it restores the register state.
+ *
+ * What about page tables? Writing data pages may toggle
+ * accessed/dirty bits in our page tables. That should be no problems
+ * with 4MB page tables. That's why we require have_pse.  
+ *
+ * This loops destroys stack from under itself, so it better should
+ * not use any stack space, itself. When this function is entered at
+ * resume time, we move stack to _old_ place.  This is means that this
+ * function must use no stack and no local variables in registers,
+ * until calling restore_processor_context();
+ *
+ * Critical section here: noone should touch saved memory after
+ * do_magic_resume_1; copying works, because nr_copy_pages,
+ * pagedir_nosave, loop and loop2 are nosavedata.
  */
-
 	do_magic_resume_1();
 
-	/* Critical section here: noone should touch memory from now */
-	/* This works, because nr_copy_pages, pagedir_nosave, loop and loop2 are nosavedata */
 	for (loop=0; loop < nr_copy_pages; loop++) {
-		/* You may not call something (like copy_page) here:
-		   We may absolutely not use stack at this point */
+		/* You may not call something (like copy_page) here: see above */
 		for (loop2=0; loop2 < PAGE_SIZE; loop2++) {
 			*(((char *)((pagedir_nosave+loop)->orig_address))+loop2) =
 				*(((char *)((pagedir_nosave+loop)->address))+loop2);
 			__flush_tlb();
 		}
 	}
-/* FIXME: What about page tables? Writing data pages may toggle
-   accessed/dirty bits in our page tables. That should be no problems
-   with 4MB page tables. That's why we require have_pse. */
-
-/* Danger: previous loop probably destroyed our current stack. Better hope it did not use
-   any stack space, itself.
-
-   When this function is entered at resume time, we move stack to _old_ place.
-   This is means that this function must use no stack and no local variables in registers.
-*/
+
 	restore_processor_context();
-/* Ahah, we now run with our old stack, and with registers copied from suspend time */
+
+/* Ahah, we now run with our old stack, and with registers copied from
+   suspend time */
 
 	do_magic_resume_2();
 }
-#endif
 #endif 
 
--- linux-swsusp.linus/kernel/suspend.c	Wed May 22 21:12:17 2002
+++ linux-swsusp/kernel/suspend.c	Wed May 22 22:05:48 2002
@@ -11,7 +11,7 @@
  * 
  * Pavel Machek <pavel@ucw.cz>:
  * Modifications, defectiveness pointing, being with me at the very beginning,
- * suspend to swap space, stop all tasks.
+ * suspend to swap space, stop all tasks. Port to 2.4.18-ac and 2.5.17.
  *
  * Steve Doddi <dirk@loth.demon.co.uk>: 
  * Support the possibility of hardware state restoring.
@@ -41,8 +41,6 @@
  * bdflush from this task. (check apm.c for something similar).
  */
 
-/* FIXME: try to poison to memory */
-
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/swapctl.h>
@@ -122,7 +120,7 @@
    Warning: this is evil. There are actually two pagedirs at time of
    resume. One is "pagedir_save", which is empty frame allocated at
    time of suspend, that must be freed. Second is "pagedir_nosave", 
-   allocated at time of resume, that travells through memory not to
+   allocated at time of resume, that travels through memory not to
    collide with anything.
  */
 static suspend_pagedir_t *pagedir_nosave __nosavedata = NULL;
@@ -143,8 +141,6 @@
 /*
  * XXX: We try to keep some more pages free so that I/O operations succeed
  * without paging. Might this be more?
- *
- * [If this is not enough, might it corrupt our data silently?]
  */
 #define PAGES_FOR_IO	512
 
@@ -310,7 +306,6 @@
 
 static void do_suspend_sync(void)
 {
-//	sync_dev(0); FIXME
 	while (1) {
 		run_task_queue(&tq_disk);
 		if (!TQ_ACTIVE(tq_disk))
@@ -640,7 +633,6 @@
 	MDELAY(1000);
 	if (freeze_processes()) {
 		PRINTS( "Not all processes stopped!\n" );
-//		panic("Some processes survived?\n");
 		thaw_processes();
 		return 1;
 	}
@@ -649,70 +641,16 @@
 }
 
 /*
- *	Free as much memory as possible
- */
-
-static void **eaten_memory;
-
-static void eat_memory(void)
-{
-	int i = 0;
-	void **c= eaten_memory, *m;
-
-	printk("Eating pages ");
-	while ((m = (void *) get_free_page(GFP_HIGHUSER))) {
-		memset(m, 0, PAGE_SIZE);
-		eaten_memory = m;
-		if (!(i%100))
-			printk( ".(%d)", i ); 
-		*eaten_memory = c;
-		c = eaten_memory;
-		i++; 
-#if 1
-	/* 40000 == 160MB */
-	/* 10000 for 64MB */
-	/* 2500 for  16MB */
-		if (i > 40000)
-			break;
-#endif
-	}
-	printk("(%dK)\n", i*4);
-}
-
-static void free_memory(void)
-{
-	int i = 0;
-	void **c = eaten_memory, *f;
-	
-	printk( "Freeing pages " );
-	while (c) {
-		if (!(i%5000))
-		printk( "." ); 
-		f = *c;
-		c = *c;
-		if (f) { free_page( (long) f ); i++; }
-	}
-	printk( "(%dK)\n", i*4 );
-	eaten_memory = NULL;
-}
-
-/*
  * Try to free as much memory as possible, but do not OOM-kill anyone
  *
  * Notice: all userland should be stopped at this point, or livelock is possible.
  */
 static void free_some_memory(void)
 {
-#if 1
 	PRINTS("Freeing memory: ");
 	while (try_to_free_pages(&contig_page_data.node_zones[ZONE_HIGHMEM], GFP_KSWAPD, 0))
 		printk(".");
 	printk("\n");
-#else
-	printk("Using memeat\n");
-	eat_memory();
-	free_memory();
-#endif
 }
 
 /* Make disk drivers accept operations, again */
@@ -809,7 +747,6 @@
 	 *
 	 * Following line enforces not writing to disk until we choose.
 	 */
-	suspend_device = NODEV;					/* We do not want any writes, thanx */
 	drivers_unsuspend();
 	spin_unlock_irq(&suspend_pagedir_lock);
 	PRINTS( "critical section/: done (%d pages copied)\n", nr_copy_pages );
@@ -991,8 +923,7 @@
 	}
 }
 
-#define does_collide(addr)	\
-		does_collide_order(pagedir_nosave, addr, 0)
+#define does_collide(addr) does_collide_order(pagedir_nosave, addr, 0)
 
 /*
  * Returns true if given address/order collides with any orig_address 
@@ -1015,7 +946,6 @@
  * We check here that pagedir & pages it points to won't collide with pages
  * where we're going to restore from the loaded pages later
  */
-
 static int check_pagedir(void)
 {
 	int i;
@@ -1036,14 +966,13 @@
 
 static int relocate_pagedir(void)
 {
-	/* This is deep magic
-	   We have to avoid recursion (not to overflow kernel stack), and that's why
-	   code looks pretty cryptic
-	*/
+	/*
+	 * We have to avoid recursion (not to overflow kernel stack),
+	 * and that's why code looks pretty cryptic 
+	 */
 	suspend_pagedir_t *new_pagedir, *old_pagedir = pagedir_nosave;
 	void **eaten_memory = NULL;
 	void **c = eaten_memory, *m, *f;
-
 
 	if(!does_collide_order(old_pagedir, (unsigned long)old_pagedir, pagedir_order)) {
 		printk("not neccessary\n");

									Pavel
-- 
(about SSSCA) "I don't say this lightly.  However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy." --hpa

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

* swsusp: cleanups
@ 2002-11-12 21:51 Pavel Machek
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Machek @ 2002-11-12 21:51 UTC (permalink / raw)
  To: torvalds, kernel list

Hi!

These are cleanups, it makes swsusp really power down machine (out of
test mode for now), uses new "memory shrinking" interface by akpm, and
avoids calling drivers_resume() with interupts disabled. Please
apply,
								Pavel


--- clean/kernel/suspend.c	2002-11-01 00:37:42.000000000 +0100
+++ linux-swsusp/kernel/suspend.c	2002-11-08 11:37:06.000000000 +0100
@@ -145,10 +145,10 @@
 /*
  * Debug
  */
 #undef	DEBUG_DEFAULT
 #undef	DEBUG_PROCESS
 #undef	DEBUG_SLOW
-#define TEST_SWSUSP 1		/* Set to 1 to reboot instead of halt machine after suspension */
+#define TEST_SWSUSP 0		/* Set to 1 to reboot instead of halt machine after suspension */
 
 #ifdef DEBUG_DEFAULT
 # define PRINTK(f, a...)       printk(f, ## a)
@@ -235,6 +235,7 @@
 	} while(todo);
 	
 	printk( "|\n" );
+	BUG_ON(in_atomic());
 	return 0;
 }
 
@@ -489,7 +490,6 @@
 			if (PageNosave(page))
 				continue;
 
-
 			if ((chunk_size=is_head_of_free_region(page))!=0) {
 				pfn += chunk_size - 1;
 				continue;
@@ -500,9 +500,8 @@
 			/*
 			 * Just copy whole code segment. Hopefully it is not that big.
 			 */
-			if (ADDRESS(pfn) >= (unsigned long)
-				&__nosave_begin && ADDRESS(pfn) < 
-				(unsigned long)&__nosave_end) {
+			if ((ADDRESS(pfn) >= (unsigned long) &__nosave_begin) && 
+			    (ADDRESS(pfn) <  (unsigned long) &__nosave_end)) {
 				PRINTK("[nosave %x]", ADDRESS(pfn));
 				continue;
 			}
@@ -623,7 +623,7 @@
 static void free_some_memory(void)
 {
 	printk("Freeing memory: ");
-	while (try_to_free_pages(&contig_page_data.node_zones[ZONE_HIGHMEM], GFP_KSWAPD, 0))
+	while (shrink_all_memory(10000))
 		printk(".");
 	printk("|\n");
 }
@@ -676,7 +676,7 @@
 	}
 }
 
-static int suspend_save_image(void)
+static int suspend_prepare_image(void)
 {
 	struct sysinfo i;
 	unsigned int nr_needed_pages = 0;
@@ -725,9 +725,15 @@
 	 *
 	 * Following line enforces not writing to disk until we choose.
 	 */
-	drivers_unsuspend();
-	spin_unlock_irq(&suspend_pagedir_lock);
+
 	printk( "critical section/: done (%d pages copied)\n", nr_copy_pages );
+	spin_unlock_irq(&suspend_pagedir_lock);
+	return 0;
+}
+
+void suspend_save_image(void)
+{
+	drivers_unsuspend();
 
 	lock_swapdevices();
 	write_suspend_image();
@@ -738,7 +744,6 @@
 	 * filesystem clean: it is not. (And it does not matter, if we resume
 	 * correctly, we'll mark system clean, anyway.)
 	 */
-	return 0;
 }
 
 void suspend_power_down(void)
@@ -788,8 +793,8 @@
 
 	PRINTK( "Freeing prev allocated pagedir\n" );
 	free_suspend_pagedir((unsigned long) pagedir_save);
-	drivers_resume(RESUME_ALL_PHASES);
 	spin_unlock_irq(&suspend_pagedir_lock);
+	drivers_resume(RESUME_ALL_PHASES);
 
 	PRINTK( "Fixing swap signatures... " );
 	mark_swapfiles(((swp_entry_t) {0}), MARK_SWAP_RESUME);
@@ -804,14 +809,17 @@
 {
 	mb();
 	barrier();
+	BUG_ON(in_atomic());
 	spin_lock_irq(&suspend_pagedir_lock);
 }
 
 void do_magic_suspend_2(void)
 {
 	read_swapfiles();
-	if (!suspend_save_image())
+	if (!suspend_prepare_image()) {	/* suspend_save_image realeses suspend_pagedir_lock */
+		suspend_save_image();
 		suspend_power_down();	/* FIXME: if suspend_power_down is commented out, console is lost after few suspends ?! */
+	}
 
 	printk(KERN_EMERG "%sSuspend failed, trying to recover...\n", name_suspend);
 	MDELAY(1000); /* So user can wait and report us messages if armageddon comes :-) */

-- 
Worst form of spam? Adding advertisment signatures ala sourceforge.net.
What goes next? Inserting advertisment *into* email?

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

end of thread, other threads:[~2002-11-13 20:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-23 21:45 swsusp cleanups Pavel Machek
  -- strict thread matches above, loose matches on Subject: below --
2002-11-12 21:51 swsusp: cleanups Pavel Machek
2002-05-15 19:52 swsusp cleanups Pavel Machek

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