diff options
author | Tina Ruchandani <ruchandani.tina@gmail.com> | 2014-10-30 14:04:53 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-11-02 19:02:55 -0500 |
commit | db597605821fccc49876705aea5db5443d67e53e (patch) | |
tree | e5893b616676da8feebd574df23270e0f1cfb41d /kernel/power/swap.c | |
parent | 0df1f2487d2f0d04703f142813d53615d62a1da4 (diff) |
PM / Hibernate: Migrate to ktime_t
This patch migrates swsusp_show_speed and its callers to using ktime_t instead
of 'struct timeval' which suffers from the y2038 problem.
Changes to swsusp_show_speed:
- use ktime_t for start and stop times
- pass start and stop times by value
Calling functions affected:
- load_image
- load_image_lzo
- save_image
- save_image_lzo
- hibernate_preallocate_memory
Design decisions:
- use ktime_t to preserve same granularity of reporting as before
- use centisecs logic as before to avoid 'div by zero' issues caused by
using seconds and nanoseconds directly
- use monotonic time (ktime_get()) since we only care about elapsed time.
Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'kernel/power/swap.c')
-rw-r--r-- | kernel/power/swap.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/kernel/power/swap.c b/kernel/power/swap.c index aaa3261dea5d..2c9d6d50a816 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/atomic.h> | 30 | #include <linux/atomic.h> |
31 | #include <linux/kthread.h> | 31 | #include <linux/kthread.h> |
32 | #include <linux/crc32.h> | 32 | #include <linux/crc32.h> |
33 | #include <linux/ktime.h> | ||
33 | 34 | ||
34 | #include "power.h" | 35 | #include "power.h" |
35 | 36 | ||
@@ -445,8 +446,8 @@ static int save_image(struct swap_map_handle *handle, | |||
445 | int nr_pages; | 446 | int nr_pages; |
446 | int err2; | 447 | int err2; |
447 | struct bio *bio; | 448 | struct bio *bio; |
448 | struct timeval start; | 449 | ktime_t start; |
449 | struct timeval stop; | 450 | ktime_t stop; |
450 | 451 | ||
451 | printk(KERN_INFO "PM: Saving image data pages (%u pages)...\n", | 452 | printk(KERN_INFO "PM: Saving image data pages (%u pages)...\n", |
452 | nr_to_write); | 453 | nr_to_write); |
@@ -455,7 +456,7 @@ static int save_image(struct swap_map_handle *handle, | |||
455 | m = 1; | 456 | m = 1; |
456 | nr_pages = 0; | 457 | nr_pages = 0; |
457 | bio = NULL; | 458 | bio = NULL; |
458 | do_gettimeofday(&start); | 459 | start = ktime_get(); |
459 | while (1) { | 460 | while (1) { |
460 | ret = snapshot_read_next(snapshot); | 461 | ret = snapshot_read_next(snapshot); |
461 | if (ret <= 0) | 462 | if (ret <= 0) |
@@ -469,12 +470,12 @@ static int save_image(struct swap_map_handle *handle, | |||
469 | nr_pages++; | 470 | nr_pages++; |
470 | } | 471 | } |
471 | err2 = hib_wait_on_bio_chain(&bio); | 472 | err2 = hib_wait_on_bio_chain(&bio); |
472 | do_gettimeofday(&stop); | 473 | stop = ktime_get(); |
473 | if (!ret) | 474 | if (!ret) |
474 | ret = err2; | 475 | ret = err2; |
475 | if (!ret) | 476 | if (!ret) |
476 | printk(KERN_INFO "PM: Image saving done.\n"); | 477 | printk(KERN_INFO "PM: Image saving done.\n"); |
477 | swsusp_show_speed(&start, &stop, nr_to_write, "Wrote"); | 478 | swsusp_show_speed(start, stop, nr_to_write, "Wrote"); |
478 | return ret; | 479 | return ret; |
479 | } | 480 | } |
480 | 481 | ||
@@ -580,8 +581,8 @@ static int save_image_lzo(struct swap_map_handle *handle, | |||
580 | int nr_pages; | 581 | int nr_pages; |
581 | int err2; | 582 | int err2; |
582 | struct bio *bio; | 583 | struct bio *bio; |
583 | struct timeval start; | 584 | ktime_t start; |
584 | struct timeval stop; | 585 | ktime_t stop; |
585 | size_t off; | 586 | size_t off; |
586 | unsigned thr, run_threads, nr_threads; | 587 | unsigned thr, run_threads, nr_threads; |
587 | unsigned char *page = NULL; | 588 | unsigned char *page = NULL; |
@@ -674,7 +675,7 @@ static int save_image_lzo(struct swap_map_handle *handle, | |||
674 | m = 1; | 675 | m = 1; |
675 | nr_pages = 0; | 676 | nr_pages = 0; |
676 | bio = NULL; | 677 | bio = NULL; |
677 | do_gettimeofday(&start); | 678 | start = ktime_get(); |
678 | for (;;) { | 679 | for (;;) { |
679 | for (thr = 0; thr < nr_threads; thr++) { | 680 | for (thr = 0; thr < nr_threads; thr++) { |
680 | for (off = 0; off < LZO_UNC_SIZE; off += PAGE_SIZE) { | 681 | for (off = 0; off < LZO_UNC_SIZE; off += PAGE_SIZE) { |
@@ -759,12 +760,12 @@ static int save_image_lzo(struct swap_map_handle *handle, | |||
759 | 760 | ||
760 | out_finish: | 761 | out_finish: |
761 | err2 = hib_wait_on_bio_chain(&bio); | 762 | err2 = hib_wait_on_bio_chain(&bio); |
762 | do_gettimeofday(&stop); | 763 | stop = ktime_get(); |
763 | if (!ret) | 764 | if (!ret) |
764 | ret = err2; | 765 | ret = err2; |
765 | if (!ret) | 766 | if (!ret) |
766 | printk(KERN_INFO "PM: Image saving done.\n"); | 767 | printk(KERN_INFO "PM: Image saving done.\n"); |
767 | swsusp_show_speed(&start, &stop, nr_to_write, "Wrote"); | 768 | swsusp_show_speed(start, stop, nr_to_write, "Wrote"); |
768 | out_clean: | 769 | out_clean: |
769 | if (crc) { | 770 | if (crc) { |
770 | if (crc->thr) | 771 | if (crc->thr) |
@@ -965,8 +966,8 @@ static int load_image(struct swap_map_handle *handle, | |||
965 | { | 966 | { |
966 | unsigned int m; | 967 | unsigned int m; |
967 | int ret = 0; | 968 | int ret = 0; |
968 | struct timeval start; | 969 | ktime_t start; |
969 | struct timeval stop; | 970 | ktime_t stop; |
970 | struct bio *bio; | 971 | struct bio *bio; |
971 | int err2; | 972 | int err2; |
972 | unsigned nr_pages; | 973 | unsigned nr_pages; |
@@ -978,7 +979,7 @@ static int load_image(struct swap_map_handle *handle, | |||
978 | m = 1; | 979 | m = 1; |
979 | nr_pages = 0; | 980 | nr_pages = 0; |
980 | bio = NULL; | 981 | bio = NULL; |
981 | do_gettimeofday(&start); | 982 | start = ktime_get(); |
982 | for ( ; ; ) { | 983 | for ( ; ; ) { |
983 | ret = snapshot_write_next(snapshot); | 984 | ret = snapshot_write_next(snapshot); |
984 | if (ret <= 0) | 985 | if (ret <= 0) |
@@ -996,7 +997,7 @@ static int load_image(struct swap_map_handle *handle, | |||
996 | nr_pages++; | 997 | nr_pages++; |
997 | } | 998 | } |
998 | err2 = hib_wait_on_bio_chain(&bio); | 999 | err2 = hib_wait_on_bio_chain(&bio); |
999 | do_gettimeofday(&stop); | 1000 | stop = ktime_get(); |
1000 | if (!ret) | 1001 | if (!ret) |
1001 | ret = err2; | 1002 | ret = err2; |
1002 | if (!ret) { | 1003 | if (!ret) { |
@@ -1005,7 +1006,7 @@ static int load_image(struct swap_map_handle *handle, | |||
1005 | if (!snapshot_image_loaded(snapshot)) | 1006 | if (!snapshot_image_loaded(snapshot)) |
1006 | ret = -ENODATA; | 1007 | ret = -ENODATA; |
1007 | } | 1008 | } |
1008 | swsusp_show_speed(&start, &stop, nr_to_read, "Read"); | 1009 | swsusp_show_speed(start, stop, nr_to_read, "Read"); |
1009 | return ret; | 1010 | return ret; |
1010 | } | 1011 | } |
1011 | 1012 | ||
@@ -1067,8 +1068,8 @@ static int load_image_lzo(struct swap_map_handle *handle, | |||
1067 | int ret = 0; | 1068 | int ret = 0; |
1068 | int eof = 0; | 1069 | int eof = 0; |
1069 | struct bio *bio; | 1070 | struct bio *bio; |
1070 | struct timeval start; | 1071 | ktime_t start; |
1071 | struct timeval stop; | 1072 | ktime_t stop; |
1072 | unsigned nr_pages; | 1073 | unsigned nr_pages; |
1073 | size_t off; | 1074 | size_t off; |
1074 | unsigned i, thr, run_threads, nr_threads; | 1075 | unsigned i, thr, run_threads, nr_threads; |
@@ -1190,7 +1191,7 @@ static int load_image_lzo(struct swap_map_handle *handle, | |||
1190 | m = 1; | 1191 | m = 1; |
1191 | nr_pages = 0; | 1192 | nr_pages = 0; |
1192 | bio = NULL; | 1193 | bio = NULL; |
1193 | do_gettimeofday(&start); | 1194 | start = ktime_get(); |
1194 | 1195 | ||
1195 | ret = snapshot_write_next(snapshot); | 1196 | ret = snapshot_write_next(snapshot); |
1196 | if (ret <= 0) | 1197 | if (ret <= 0) |
@@ -1343,7 +1344,7 @@ out_finish: | |||
1343 | wait_event(crc->done, atomic_read(&crc->stop)); | 1344 | wait_event(crc->done, atomic_read(&crc->stop)); |
1344 | atomic_set(&crc->stop, 0); | 1345 | atomic_set(&crc->stop, 0); |
1345 | } | 1346 | } |
1346 | do_gettimeofday(&stop); | 1347 | stop = ktime_get(); |
1347 | if (!ret) { | 1348 | if (!ret) { |
1348 | printk(KERN_INFO "PM: Image loading done.\n"); | 1349 | printk(KERN_INFO "PM: Image loading done.\n"); |
1349 | snapshot_write_finalize(snapshot); | 1350 | snapshot_write_finalize(snapshot); |
@@ -1359,7 +1360,7 @@ out_finish: | |||
1359 | } | 1360 | } |
1360 | } | 1361 | } |
1361 | } | 1362 | } |
1362 | swsusp_show_speed(&start, &stop, nr_to_read, "Read"); | 1363 | swsusp_show_speed(start, stop, nr_to_read, "Read"); |
1363 | out_clean: | 1364 | out_clean: |
1364 | for (i = 0; i < ring_size; i++) | 1365 | for (i = 0; i < ring_size; i++) |
1365 | free_page((unsigned long)page[i]); | 1366 | free_page((unsigned long)page[i]); |