提交 0d3a9abe 编写于 作者: R Rafael J. Wysocki 提交者: Linus Torvalds

[PATCH] swsusp: Measure memory shrinking time

Make swsusp measure and print the time needed to shrink memory during the
suspend.
Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Nigel Cunningham <nigel@suspend2.net>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 112cecb2
...@@ -171,3 +171,7 @@ extern int swsusp_read(void); ...@@ -171,3 +171,7 @@ extern int swsusp_read(void);
extern int swsusp_write(void); extern int swsusp_write(void);
extern void swsusp_close(void); extern void swsusp_close(void);
extern int suspend_enter(suspend_state_t state); extern int suspend_enter(suspend_state_t state);
struct timeval;
extern void swsusp_show_speed(struct timeval *, struct timeval *,
unsigned int, char *);
...@@ -133,26 +133,6 @@ static int wait_on_bio_chain(struct bio **bio_chain) ...@@ -133,26 +133,6 @@ static int wait_on_bio_chain(struct bio **bio_chain)
return ret; return ret;
} }
static void show_speed(struct timeval *start, struct timeval *stop,
unsigned nr_pages, char *msg)
{
s64 elapsed_centisecs64;
int centisecs;
int k;
int kps;
elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
centisecs = elapsed_centisecs64;
if (centisecs == 0)
centisecs = 1; /* avoid div-by-zero */
k = nr_pages * (PAGE_SIZE / 1024);
kps = (k * 100) / centisecs;
printk("%s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", msg, k,
centisecs / 100, centisecs % 100,
kps / 1000, (kps % 1000) / 10);
}
/* /*
* Saving part * Saving part
*/ */
...@@ -375,7 +355,7 @@ static int save_image(struct swap_map_handle *handle, ...@@ -375,7 +355,7 @@ static int save_image(struct swap_map_handle *handle,
error = err2; error = err2;
if (!error) if (!error)
printk("\b\b\b\bdone\n"); printk("\b\b\b\bdone\n");
show_speed(&start, &stop, nr_to_write, "Wrote"); swsusp_show_speed(&start, &stop, nr_to_write, "Wrote");
return error; return error;
} }
...@@ -562,7 +542,7 @@ static int load_image(struct swap_map_handle *handle, ...@@ -562,7 +542,7 @@ static int load_image(struct swap_map_handle *handle,
if (!snapshot_image_loaded(snapshot)) if (!snapshot_image_loaded(snapshot))
error = -ENODATA; error = -ENODATA;
} }
show_speed(&start, &stop, nr_to_read, "Read"); swsusp_show_speed(&start, &stop, nr_to_read, "Read");
return error; return error;
} }
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <linux/bootmem.h> #include <linux/bootmem.h>
#include <linux/syscalls.h> #include <linux/syscalls.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/time.h>
#include "power.h" #include "power.h"
...@@ -163,6 +164,34 @@ void free_all_swap_pages(int swap, struct bitmap_page *bitmap) ...@@ -163,6 +164,34 @@ void free_all_swap_pages(int swap, struct bitmap_page *bitmap)
} }
} }
/**
* swsusp_show_speed - print the time elapsed between two events represented by
* @start and @stop
*
* @nr_pages - number of pages processed between @start and @stop
* @msg - introductory message to print
*/
void swsusp_show_speed(struct timeval *start, struct timeval *stop,
unsigned nr_pages, char *msg)
{
s64 elapsed_centisecs64;
int centisecs;
int k;
int kps;
elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
centisecs = elapsed_centisecs64;
if (centisecs == 0)
centisecs = 1; /* avoid div-by-zero */
k = nr_pages * (PAGE_SIZE / 1024);
kps = (k * 100) / centisecs;
printk("%s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", msg, k,
centisecs / 100, centisecs % 100,
kps / 1000, (kps % 1000) / 10);
}
/** /**
* swsusp_shrink_memory - Try to free as much memory as needed * swsusp_shrink_memory - Try to free as much memory as needed
* *
...@@ -187,8 +216,10 @@ int swsusp_shrink_memory(void) ...@@ -187,8 +216,10 @@ int swsusp_shrink_memory(void)
unsigned long pages = 0; unsigned long pages = 0;
unsigned int i = 0; unsigned int i = 0;
char *p = "-\\|/"; char *p = "-\\|/";
struct timeval start, stop;
printk("Shrinking memory... "); printk("Shrinking memory... ");
do_gettimeofday(&start);
do { do {
long size, highmem_size; long size, highmem_size;
...@@ -222,7 +253,9 @@ int swsusp_shrink_memory(void) ...@@ -222,7 +253,9 @@ int swsusp_shrink_memory(void)
} }
printk("\b%c", p[i++%4]); printk("\b%c", p[i++%4]);
} while (tmp > 0); } while (tmp > 0);
do_gettimeofday(&stop);
printk("\bdone (%lu pages freed)\n", pages); printk("\bdone (%lu pages freed)\n", pages);
swsusp_show_speed(&start, &stop, pages, "Freed");
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册