2 * linux/kernel/power/swsusp.c
4 * This file provides code to write suspend image to swap and read it back.
6 * Copyright (C) 1998-2001 Gabor Kuti <seasons@fornax.hu>
7 * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@suse.cz>
9 * This file is released under the GPLv2.
11 * I'd like to thank the following people for their work:
13 * Pavel Machek <pavel@ucw.cz>:
14 * Modifications, defectiveness pointing, being with me at the very beginning,
15 * suspend to swap space, stop all tasks. Port to 2.4.18-ac and 2.5.17.
17 * Steve Doddi <dirk@loth.demon.co.uk>:
18 * Support the possibility of hardware state restoring.
20 * Raph <grey.havens@earthling.net>:
21 * Support for preserving states of network devices and virtual console
22 * (including X and svgatextmode)
24 * Kurt Garloff <garloff@suse.de>:
25 * Straightened the critical function in order to prevent compilers from
26 * playing tricks with local variables.
28 * Andreas Mohr <a.mohr@mailto.de>
30 * Alex Badea <vampire@go.ro>:
33 * Rafael J. Wysocki <rjw@sisk.pl>
34 * Reworked the freeing of memory and the handling of swap
36 * More state savers are welcome. Especially for the scsi layer...
38 * For TODOs,FIXMEs also look in Documentation/power/swsusp.txt
42 #include <linux/suspend.h>
43 #include <linux/spinlock.h>
44 #include <linux/kernel.h>
45 #include <linux/major.h>
46 #include <linux/swap.h>
48 #include <linux/swapops.h>
49 #include <linux/bootmem.h>
50 #include <linux/syscalls.h>
51 #include <linux/highmem.h>
52 #include <linux/time.h>
53 #include <linux/rbtree.h>
58 int in_suspend __nosavedata = 0;
61 * swsusp_show_speed - print the time elapsed between two events represented by
64 * @nr_pages - number of pages processed between @start and @stop
65 * @msg - introductory message to print
68 void swsusp_show_speed(struct timeval *start, struct timeval *stop,
69 unsigned nr_pages, char *msg)
71 s64 elapsed_centisecs64;
76 elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
77 do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
78 centisecs = elapsed_centisecs64;
80 centisecs = 1; /* avoid div-by-zero */
81 k = nr_pages * (PAGE_SIZE / 1024);
82 kps = (k * 100) / centisecs;
83 printk(KERN_INFO "PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n",
85 centisecs / 100, centisecs % 100,
86 kps / 1000, (kps % 1000) / 10);