Commit af30c0a0 authored by Shraddha Barke's avatar Shraddha Barke Committed by Brian Norris

mtd: tests: Replace timeval with ktime_t

Changes the 32-bit time type timeval to the 64-bit time type
ktime_t, since 32-bit systems using struct timeval will break in the
year 2038. Correspondingly change do_gettimeofday() to ktime_get()
since ktime_get returns a ktime_t, but do_gettimeofday returns a
struct timeval.Here, ktime_get() is used instead of ktime_get_real()
since ktime_get() uses monotonic clock.
Signed-off-by: default avatarShraddha Barke <shraddha.6596@gmail.com>
Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent e278fc71
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/init.h> #include <linux/init.h>
#include <linux/ktime.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -49,7 +50,7 @@ static int pgsize; ...@@ -49,7 +50,7 @@ static int pgsize;
static int ebcnt; static int ebcnt;
static int pgcnt; static int pgcnt;
static int goodebcnt; static int goodebcnt;
static struct timeval start, finish; static ktime_t start, finish;
static int multiblock_erase(int ebnum, int blocks) static int multiblock_erase(int ebnum, int blocks)
{ {
...@@ -168,12 +169,12 @@ static int read_eraseblock_by_2pages(int ebnum) ...@@ -168,12 +169,12 @@ static int read_eraseblock_by_2pages(int ebnum)
static inline void start_timing(void) static inline void start_timing(void)
{ {
do_gettimeofday(&start); start = ktime_get();
} }
static inline void stop_timing(void) static inline void stop_timing(void)
{ {
do_gettimeofday(&finish); finish = ktime_get();
} }
static long calc_speed(void) static long calc_speed(void)
...@@ -181,8 +182,7 @@ static long calc_speed(void) ...@@ -181,8 +182,7 @@ static long calc_speed(void)
uint64_t k; uint64_t k;
long ms; long ms;
ms = (finish.tv_sec - start.tv_sec) * 1000 + ms = ktime_ms_delta(finish, start);
(finish.tv_usec - start.tv_usec) / 1000;
if (ms == 0) if (ms == 0)
return 0; return 0;
k = (uint64_t)goodebcnt * (mtd->erasesize / 1024) * 1000; k = (uint64_t)goodebcnt * (mtd->erasesize / 1024) * 1000;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/init.h> #include <linux/init.h>
#include <linux/ktime.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -79,18 +80,18 @@ static unsigned char *check_buf; ...@@ -79,18 +80,18 @@ static unsigned char *check_buf;
static unsigned int erase_cycles; static unsigned int erase_cycles;
static int pgsize; static int pgsize;
static struct timeval start, finish; static ktime_t start, finish;
static void report_corrupt(unsigned char *read, unsigned char *written); static void report_corrupt(unsigned char *read, unsigned char *written);
static inline void start_timing(void) static inline void start_timing(void)
{ {
do_gettimeofday(&start); start = ktime_get();
} }
static inline void stop_timing(void) static inline void stop_timing(void)
{ {
do_gettimeofday(&finish); finish = ktime_get();
} }
/* /*
...@@ -333,8 +334,7 @@ static int __init tort_init(void) ...@@ -333,8 +334,7 @@ static int __init tort_init(void)
long ms; long ms;
stop_timing(); stop_timing();
ms = (finish.tv_sec - start.tv_sec) * 1000 + ms = ktime_ms_delta(finish, start);
(finish.tv_usec - start.tv_usec) / 1000;
pr_info("%08u erase cycles done, took %lu " pr_info("%08u erase cycles done, took %lu "
"milliseconds (%lu seconds)\n", "milliseconds (%lu seconds)\n",
erase_cycles, ms, ms / 1000); erase_cycles, ms, ms / 1000);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment