aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2006-12-06 23:34:32 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-07 11:39:28 -0500
commit0d3a9abe8ae055e1052295698bcd0722c92eff47 (patch)
tree84225335704f0989a1556ba093732e023618b8f6 /kernel/power
parent112cecb2cc0e7341db92281ba04b26c41bb8146d (diff)
[PATCH] swsusp: Measure memory shrinking time
Make swsusp measure and print the time needed to shrink memory during the suspend. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Cc: Pavel Machek <pavel@ucw.cz> Cc: Nigel Cunningham <nigel@suspend2.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/power')
-rw-r--r--kernel/power/power.h4
-rw-r--r--kernel/power/swap.c24
-rw-r--r--kernel/power/swsusp.c33
3 files changed, 39 insertions, 22 deletions
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 3763343bde2f..3afa5dbe6bc5 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -171,3 +171,7 @@ extern int swsusp_read(void);
171extern int swsusp_write(void); 171extern int swsusp_write(void);
172extern void swsusp_close(void); 172extern void swsusp_close(void);
173extern int suspend_enter(suspend_state_t state); 173extern int suspend_enter(suspend_state_t state);
174
175struct timeval;
176extern void swsusp_show_speed(struct timeval *, struct timeval *,
177 unsigned int, char *);
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 52e70ca832a8..dedf8797b723 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -133,26 +133,6 @@ static int wait_on_bio_chain(struct bio **bio_chain)
133 return ret; 133 return ret;
134} 134}
135 135
136static void show_speed(struct timeval *start, struct timeval *stop,
137 unsigned nr_pages, char *msg)
138{
139 s64 elapsed_centisecs64;
140 int centisecs;
141 int k;
142 int kps;
143
144 elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
145 do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
146 centisecs = elapsed_centisecs64;
147 if (centisecs == 0)
148 centisecs = 1; /* avoid div-by-zero */
149 k = nr_pages * (PAGE_SIZE / 1024);
150 kps = (k * 100) / centisecs;
151 printk("%s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", msg, k,
152 centisecs / 100, centisecs % 100,
153 kps / 1000, (kps % 1000) / 10);
154}
155
156/* 136/*
157 * Saving part 137 * Saving part
158 */ 138 */
@@ -375,7 +355,7 @@ static int save_image(struct swap_map_handle *handle,
375 error = err2; 355 error = err2;
376 if (!error) 356 if (!error)
377 printk("\b\b\b\bdone\n"); 357 printk("\b\b\b\bdone\n");
378 show_speed(&start, &stop, nr_to_write, "Wrote"); 358 swsusp_show_speed(&start, &stop, nr_to_write, "Wrote");
379 return error; 359 return error;
380} 360}
381 361
@@ -562,7 +542,7 @@ static int load_image(struct swap_map_handle *handle,
562 if (!snapshot_image_loaded(snapshot)) 542 if (!snapshot_image_loaded(snapshot))
563 error = -ENODATA; 543 error = -ENODATA;
564 } 544 }
565 show_speed(&start, &stop, nr_to_read, "Read"); 545 swsusp_show_speed(&start, &stop, nr_to_read, "Read");
566 return error; 546 return error;
567} 547}
568 548
diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c
index 68de5c1dbd78..aa31432bbd97 100644
--- a/kernel/power/swsusp.c
+++ b/kernel/power/swsusp.c
@@ -49,6 +49,7 @@
49#include <linux/bootmem.h> 49#include <linux/bootmem.h>
50#include <linux/syscalls.h> 50#include <linux/syscalls.h>
51#include <linux/highmem.h> 51#include <linux/highmem.h>
52#include <linux/time.h>
52 53
53#include "power.h" 54#include "power.h"
54 55
@@ -164,6 +165,34 @@ void free_all_swap_pages(int swap, struct bitmap_page *bitmap)
164} 165}
165 166
166/** 167/**
168 * swsusp_show_speed - print the time elapsed between two events represented by
169 * @start and @stop
170 *
171 * @nr_pages - number of pages processed between @start and @stop
172 * @msg - introductory message to print
173 */
174
175void swsusp_show_speed(struct timeval *start, struct timeval *stop,
176 unsigned nr_pages, char *msg)
177{
178 s64 elapsed_centisecs64;
179 int centisecs;
180 int k;
181 int kps;
182
183 elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
184 do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
185 centisecs = elapsed_centisecs64;
186 if (centisecs == 0)
187 centisecs = 1; /* avoid div-by-zero */
188 k = nr_pages * (PAGE_SIZE / 1024);
189 kps = (k * 100) / centisecs;
190 printk("%s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", msg, k,
191 centisecs / 100, centisecs % 100,
192 kps / 1000, (kps % 1000) / 10);
193}
194
195/**
167 * swsusp_shrink_memory - Try to free as much memory as needed 196 * swsusp_shrink_memory - Try to free as much memory as needed
168 * 197 *
169 * ... but do not OOM-kill anyone 198 * ... but do not OOM-kill anyone
@@ -187,8 +216,10 @@ int swsusp_shrink_memory(void)
187 unsigned long pages = 0; 216 unsigned long pages = 0;
188 unsigned int i = 0; 217 unsigned int i = 0;
189 char *p = "-\\|/"; 218 char *p = "-\\|/";
219 struct timeval start, stop;
190 220
191 printk("Shrinking memory... "); 221 printk("Shrinking memory... ");
222 do_gettimeofday(&start);
192 do { 223 do {
193 long size, highmem_size; 224 long size, highmem_size;
194 225
@@ -222,7 +253,9 @@ int swsusp_shrink_memory(void)
222 } 253 }
223 printk("\b%c", p[i++%4]); 254 printk("\b%c", p[i++%4]);
224 } while (tmp > 0); 255 } while (tmp > 0);
256 do_gettimeofday(&stop);
225 printk("\bdone (%lu pages freed)\n", pages); 257 printk("\bdone (%lu pages freed)\n", pages);
258 swsusp_show_speed(&start, &stop, pages, "Freed");
226 259
227 return 0; 260 return 0;
228} 261}