The mtd tests' code recodes tests' start time and finish time by storing real time in struct timeval. This will cause problems on 32-bit architectures in 2038 when time_t overflows. Since the tests' code just needs delta value between start and end time, it is not necessary to record them in real time. This patch changes the code to use the monotonic time instead, replaces do_gettimeofday() and struct timeval with ktime_get() and ktime_t.
Signed-off-by: DengChao chao.deng@linaro.org --- drivers/mtd/tests/speedtest.c | 9 ++++----- drivers/mtd/tests/torturetest.c | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/tests/speedtest.c b/drivers/mtd/tests/speedtest.c index 5a6f31a..039cf92 100644 --- a/drivers/mtd/tests/speedtest.c +++ b/drivers/mtd/tests/speedtest.c @@ -49,7 +49,7 @@ static int pgsize; static int ebcnt; static int pgcnt; static int goodebcnt; -static struct timeval start, finish; +static ktime_t start, finish;
static int multiblock_erase(int ebnum, int blocks) { @@ -168,12 +168,12 @@ static int read_eraseblock_by_2pages(int ebnum)
static inline void start_timing(void) { - do_gettimeofday(&start); + start = ktime_get(); }
static inline void stop_timing(void) { - do_gettimeofday(&finish); + finish = ktime_get(); }
static long calc_speed(void) @@ -181,8 +181,7 @@ static long calc_speed(void) uint64_t k; long ms;
- ms = (finish.tv_sec - start.tv_sec) * 1000 + - (finish.tv_usec - start.tv_usec) / 1000; + ms = ktime_ms_delta(finish, start); if (ms == 0) return 0; k = (uint64_t)goodebcnt * (mtd->erasesize / 1024) * 1000; diff --git a/drivers/mtd/tests/torturetest.c b/drivers/mtd/tests/torturetest.c index e5d6e6d..3c8a86b 100644 --- a/drivers/mtd/tests/torturetest.c +++ b/drivers/mtd/tests/torturetest.c @@ -79,18 +79,18 @@ static unsigned char *check_buf; static unsigned int erase_cycles;
static int pgsize; -static struct timeval start, finish; +static ktime_t start, finish;
static void report_corrupt(unsigned char *read, unsigned char *written);
static inline void start_timing(void) { - do_gettimeofday(&start); + start = ktime_get(); }
static inline void stop_timing(void) { - do_gettimeofday(&finish); + finish = ktime_get(); }
/* @@ -333,8 +333,7 @@ static int __init tort_init(void) long ms;
stop_timing(); - ms = (finish.tv_sec - start.tv_sec) * 1000 + - (finish.tv_usec - start.tv_usec) / 1000; + ms = ktime_ms_delta(finish, start); pr_info("%08u erase cycles done, took %lu " "milliseconds (%lu seconds)\n", erase_cycles, ms, ms / 1000);