Commit a5b97be2 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Ulf Hansson

mmc_test: use ktime_get_ts64 for timestamps

Calling getnstimeofday() can suffer from time jumps and from the
y2038 overflow, so it is not appropriate here. Using ktime_get_ts64()
solves both problems. Using ktime_get() with ktime_t timestamps would
also work, but it seems that we mainly want to print the times as
seconds+nanoseconds, so it would require an extra division in the output.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 043f2dca
...@@ -101,7 +101,7 @@ struct mmc_test_transfer_result { ...@@ -101,7 +101,7 @@ struct mmc_test_transfer_result {
struct list_head link; struct list_head link;
unsigned int count; unsigned int count;
unsigned int sectors; unsigned int sectors;
struct timespec ts; struct timespec64 ts;
unsigned int rate; unsigned int rate;
unsigned int iops; unsigned int iops;
}; };
...@@ -510,14 +510,11 @@ static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem, ...@@ -510,14 +510,11 @@ static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem,
/* /*
* Calculate transfer rate in bytes per second. * Calculate transfer rate in bytes per second.
*/ */
static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts) static unsigned int mmc_test_rate(uint64_t bytes, struct timespec64 *ts)
{ {
uint64_t ns; uint64_t ns;
ns = ts->tv_sec; ns = timespec64_to_ns(ts);
ns *= 1000000000;
ns += ts->tv_nsec;
bytes *= 1000000000; bytes *= 1000000000;
while (ns > UINT_MAX) { while (ns > UINT_MAX) {
...@@ -537,7 +534,7 @@ static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts) ...@@ -537,7 +534,7 @@ static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts)
* Save transfer results for future usage * Save transfer results for future usage
*/ */
static void mmc_test_save_transfer_result(struct mmc_test_card *test, static void mmc_test_save_transfer_result(struct mmc_test_card *test,
unsigned int count, unsigned int sectors, struct timespec ts, unsigned int count, unsigned int sectors, struct timespec64 ts,
unsigned int rate, unsigned int iops) unsigned int rate, unsigned int iops)
{ {
struct mmc_test_transfer_result *tr; struct mmc_test_transfer_result *tr;
...@@ -562,21 +559,21 @@ static void mmc_test_save_transfer_result(struct mmc_test_card *test, ...@@ -562,21 +559,21 @@ static void mmc_test_save_transfer_result(struct mmc_test_card *test,
* Print the transfer rate. * Print the transfer rate.
*/ */
static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes, static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
struct timespec *ts1, struct timespec *ts2) struct timespec64 *ts1, struct timespec64 *ts2)
{ {
unsigned int rate, iops, sectors = bytes >> 9; unsigned int rate, iops, sectors = bytes >> 9;
struct timespec ts; struct timespec64 ts;
ts = timespec_sub(*ts2, *ts1); ts = timespec64_sub(*ts2, *ts1);
rate = mmc_test_rate(bytes, &ts); rate = mmc_test_rate(bytes, &ts);
iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */ iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
pr_info("%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu " pr_info("%s: Transfer of %u sectors (%u%s KiB) took %llu.%09u "
"seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n", "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
mmc_hostname(test->card->host), sectors, sectors >> 1, mmc_hostname(test->card->host), sectors, sectors >> 1,
(sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec, (sectors & 1 ? ".5" : ""), (u64)ts.tv_sec,
(unsigned long)ts.tv_nsec, rate / 1000, rate / 1024, (u32)ts.tv_nsec, rate / 1000, rate / 1024,
iops / 100, iops % 100); iops / 100, iops % 100);
mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops); mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops);
...@@ -586,24 +583,24 @@ static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes, ...@@ -586,24 +583,24 @@ static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
* Print the average transfer rate. * Print the average transfer rate.
*/ */
static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes, static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
unsigned int count, struct timespec *ts1, unsigned int count, struct timespec64 *ts1,
struct timespec *ts2) struct timespec64 *ts2)
{ {
unsigned int rate, iops, sectors = bytes >> 9; unsigned int rate, iops, sectors = bytes >> 9;
uint64_t tot = bytes * count; uint64_t tot = bytes * count;
struct timespec ts; struct timespec64 ts;
ts = timespec_sub(*ts2, *ts1); ts = timespec64_sub(*ts2, *ts1);
rate = mmc_test_rate(tot, &ts); rate = mmc_test_rate(tot, &ts);
iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */ iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took " pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
"%lu.%09lu seconds (%u kB/s, %u KiB/s, " "%llu.%09u seconds (%u kB/s, %u KiB/s, "
"%u.%02u IOPS, sg_len %d)\n", "%u.%02u IOPS, sg_len %d)\n",
mmc_hostname(test->card->host), count, sectors, count, mmc_hostname(test->card->host), count, sectors, count,
sectors >> 1, (sectors & 1 ? ".5" : ""), sectors >> 1, (sectors & 1 ? ".5" : ""),
(unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec, (u64)ts.tv_sec, (u32)ts.tv_nsec,
rate / 1000, rate / 1024, iops / 100, iops % 100, rate / 1000, rate / 1024, iops / 100, iops % 100,
test->area.sg_len); test->area.sg_len);
...@@ -1444,7 +1441,7 @@ static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz, ...@@ -1444,7 +1441,7 @@ static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz,
int max_scatter, int timed, int count, int max_scatter, int timed, int count,
bool nonblock, int min_sg_len) bool nonblock, int min_sg_len)
{ {
struct timespec ts1, ts2; struct timespec64 ts1, ts2;
int ret = 0; int ret = 0;
int i; int i;
struct mmc_test_area *t = &test->area; struct mmc_test_area *t = &test->area;
...@@ -1470,7 +1467,7 @@ static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz, ...@@ -1470,7 +1467,7 @@ static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz,
return ret; return ret;
if (timed) if (timed)
getnstimeofday(&ts1); ktime_get_ts64(&ts1);
if (nonblock) if (nonblock)
ret = mmc_test_nonblock_transfer(test, t->sg, t->sg_len, ret = mmc_test_nonblock_transfer(test, t->sg, t->sg_len,
dev_addr, t->blocks, 512, write, count); dev_addr, t->blocks, 512, write, count);
...@@ -1484,7 +1481,7 @@ static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz, ...@@ -1484,7 +1481,7 @@ static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz,
return ret; return ret;
if (timed) if (timed)
getnstimeofday(&ts2); ktime_get_ts64(&ts2);
if (timed) if (timed)
mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2); mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2);
...@@ -1742,7 +1739,7 @@ static int mmc_test_profile_trim_perf(struct mmc_test_card *test) ...@@ -1742,7 +1739,7 @@ static int mmc_test_profile_trim_perf(struct mmc_test_card *test)
struct mmc_test_area *t = &test->area; struct mmc_test_area *t = &test->area;
unsigned long sz; unsigned long sz;
unsigned int dev_addr; unsigned int dev_addr;
struct timespec ts1, ts2; struct timespec64 ts1, ts2;
int ret; int ret;
if (!mmc_can_trim(test->card)) if (!mmc_can_trim(test->card))
...@@ -1753,19 +1750,19 @@ static int mmc_test_profile_trim_perf(struct mmc_test_card *test) ...@@ -1753,19 +1750,19 @@ static int mmc_test_profile_trim_perf(struct mmc_test_card *test)
for (sz = 512; sz < t->max_sz; sz <<= 1) { for (sz = 512; sz < t->max_sz; sz <<= 1) {
dev_addr = t->dev_addr + (sz >> 9); dev_addr = t->dev_addr + (sz >> 9);
getnstimeofday(&ts1); ktime_get_ts64(&ts1);
ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG); ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
if (ret) if (ret)
return ret; return ret;
getnstimeofday(&ts2); ktime_get_ts64(&ts2);
mmc_test_print_rate(test, sz, &ts1, &ts2); mmc_test_print_rate(test, sz, &ts1, &ts2);
} }
dev_addr = t->dev_addr; dev_addr = t->dev_addr;
getnstimeofday(&ts1); ktime_get_ts64(&ts1);
ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG); ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
if (ret) if (ret)
return ret; return ret;
getnstimeofday(&ts2); ktime_get_ts64(&ts2);
mmc_test_print_rate(test, sz, &ts1, &ts2); mmc_test_print_rate(test, sz, &ts1, &ts2);
return 0; return 0;
} }
...@@ -1774,19 +1771,19 @@ static int mmc_test_seq_read_perf(struct mmc_test_card *test, unsigned long sz) ...@@ -1774,19 +1771,19 @@ static int mmc_test_seq_read_perf(struct mmc_test_card *test, unsigned long sz)
{ {
struct mmc_test_area *t = &test->area; struct mmc_test_area *t = &test->area;
unsigned int dev_addr, i, cnt; unsigned int dev_addr, i, cnt;
struct timespec ts1, ts2; struct timespec64 ts1, ts2;
int ret; int ret;
cnt = t->max_sz / sz; cnt = t->max_sz / sz;
dev_addr = t->dev_addr; dev_addr = t->dev_addr;
getnstimeofday(&ts1); ktime_get_ts64(&ts1);
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0); ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0);
if (ret) if (ret)
return ret; return ret;
dev_addr += (sz >> 9); dev_addr += (sz >> 9);
} }
getnstimeofday(&ts2); ktime_get_ts64(&ts2);
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
return 0; return 0;
} }
...@@ -1813,7 +1810,7 @@ static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz) ...@@ -1813,7 +1810,7 @@ static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz)
{ {
struct mmc_test_area *t = &test->area; struct mmc_test_area *t = &test->area;
unsigned int dev_addr, i, cnt; unsigned int dev_addr, i, cnt;
struct timespec ts1, ts2; struct timespec64 ts1, ts2;
int ret; int ret;
ret = mmc_test_area_erase(test); ret = mmc_test_area_erase(test);
...@@ -1821,14 +1818,14 @@ static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz) ...@@ -1821,14 +1818,14 @@ static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz)
return ret; return ret;
cnt = t->max_sz / sz; cnt = t->max_sz / sz;
dev_addr = t->dev_addr; dev_addr = t->dev_addr;
getnstimeofday(&ts1); ktime_get_ts64(&ts1);
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0); ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0);
if (ret) if (ret)
return ret; return ret;
dev_addr += (sz >> 9); dev_addr += (sz >> 9);
} }
getnstimeofday(&ts2); ktime_get_ts64(&ts2);
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
return 0; return 0;
} }
...@@ -1859,7 +1856,7 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test) ...@@ -1859,7 +1856,7 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
struct mmc_test_area *t = &test->area; struct mmc_test_area *t = &test->area;
unsigned long sz; unsigned long sz;
unsigned int dev_addr, i, cnt; unsigned int dev_addr, i, cnt;
struct timespec ts1, ts2; struct timespec64 ts1, ts2;
int ret; int ret;
if (!mmc_can_trim(test->card)) if (!mmc_can_trim(test->card))
...@@ -1877,7 +1874,7 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test) ...@@ -1877,7 +1874,7 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
return ret; return ret;
cnt = t->max_sz / sz; cnt = t->max_sz / sz;
dev_addr = t->dev_addr; dev_addr = t->dev_addr;
getnstimeofday(&ts1); ktime_get_ts64(&ts1);
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
ret = mmc_erase(test->card, dev_addr, sz >> 9, ret = mmc_erase(test->card, dev_addr, sz >> 9,
MMC_TRIM_ARG); MMC_TRIM_ARG);
...@@ -1885,7 +1882,7 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test) ...@@ -1885,7 +1882,7 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
return ret; return ret;
dev_addr += (sz >> 9); dev_addr += (sz >> 9);
} }
getnstimeofday(&ts2); ktime_get_ts64(&ts2);
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
} }
return 0; return 0;
...@@ -1907,7 +1904,7 @@ static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print, ...@@ -1907,7 +1904,7 @@ static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print,
{ {
unsigned int dev_addr, cnt, rnd_addr, range1, range2, last_ea = 0, ea; unsigned int dev_addr, cnt, rnd_addr, range1, range2, last_ea = 0, ea;
unsigned int ssz; unsigned int ssz;
struct timespec ts1, ts2, ts; struct timespec64 ts1, ts2, ts;
int ret; int ret;
ssz = sz >> 9; ssz = sz >> 9;
...@@ -1916,10 +1913,10 @@ static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print, ...@@ -1916,10 +1913,10 @@ static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print,
range1 = rnd_addr / test->card->pref_erase; range1 = rnd_addr / test->card->pref_erase;
range2 = range1 / ssz; range2 = range1 / ssz;
getnstimeofday(&ts1); ktime_get_ts64(&ts1);
for (cnt = 0; cnt < UINT_MAX; cnt++) { for (cnt = 0; cnt < UINT_MAX; cnt++) {
getnstimeofday(&ts2); ktime_get_ts64(&ts2);
ts = timespec_sub(ts2, ts1); ts = timespec64_sub(ts2, ts1);
if (ts.tv_sec >= 10) if (ts.tv_sec >= 10)
break; break;
ea = mmc_test_rnd_num(range1); ea = mmc_test_rnd_num(range1);
...@@ -1993,7 +1990,7 @@ static int mmc_test_seq_perf(struct mmc_test_card *test, int write, ...@@ -1993,7 +1990,7 @@ static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
{ {
struct mmc_test_area *t = &test->area; struct mmc_test_area *t = &test->area;
unsigned int dev_addr, i, cnt, sz, ssz; unsigned int dev_addr, i, cnt, sz, ssz;
struct timespec ts1, ts2; struct timespec64 ts1, ts2;
int ret; int ret;
sz = t->max_tfr; sz = t->max_tfr;
...@@ -2020,7 +2017,7 @@ static int mmc_test_seq_perf(struct mmc_test_card *test, int write, ...@@ -2020,7 +2017,7 @@ static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
cnt = tot_sz / sz; cnt = tot_sz / sz;
dev_addr &= 0xffff0000; /* Round to 64MiB boundary */ dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
getnstimeofday(&ts1); ktime_get_ts64(&ts1);
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
ret = mmc_test_area_io(test, sz, dev_addr, write, ret = mmc_test_area_io(test, sz, dev_addr, write,
max_scatter, 0); max_scatter, 0);
...@@ -2028,7 +2025,7 @@ static int mmc_test_seq_perf(struct mmc_test_card *test, int write, ...@@ -2028,7 +2025,7 @@ static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
return ret; return ret;
dev_addr += ssz; dev_addr += ssz;
} }
getnstimeofday(&ts2); ktime_get_ts64(&ts2);
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
...@@ -3052,10 +3049,9 @@ static int mtf_test_show(struct seq_file *sf, void *data) ...@@ -3052,10 +3049,9 @@ static int mtf_test_show(struct seq_file *sf, void *data)
seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result); seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
list_for_each_entry(tr, &gr->tr_lst, link) { list_for_each_entry(tr, &gr->tr_lst, link) {
seq_printf(sf, "%u %d %lu.%09lu %u %u.%02u\n", seq_printf(sf, "%u %d %llu.%09u %u %u.%02u\n",
tr->count, tr->sectors, tr->count, tr->sectors,
(unsigned long)tr->ts.tv_sec, (u64)tr->ts.tv_sec, (u32)tr->ts.tv_nsec,
(unsigned long)tr->ts.tv_nsec,
tr->rate, tr->iops / 100, tr->iops % 100); tr->rate, tr->iops / 100, tr->iops % 100);
} }
} }
......
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