From patchwork Mon Feb 1 03:43:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhilash Jindal X-Patchwork-Id: 8175861 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0E7CEBEEE5 for ; Mon, 1 Feb 2016 03:43:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A94D22020F for ; Mon, 1 Feb 2016 03:43:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B54320155 for ; Mon, 1 Feb 2016 03:43:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933627AbcBADnM (ORCPT ); Sun, 31 Jan 2016 22:43:12 -0500 Received: from mail-ig0-f171.google.com ([209.85.213.171]:36868 "EHLO mail-ig0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751311AbcBADnL (ORCPT ); Sun, 31 Jan 2016 22:43:11 -0500 Received: by mail-ig0-f171.google.com with SMTP id 5so2790353igt.0 for ; Sun, 31 Jan 2016 19:43:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=AsNpezFuIFITFv7bfdg1TfUG4ptHea0UYlBh5yvYfTg=; b=iGkDNBTxTIdnph3t4A0is3d6C6mMHx3H1YenuN8x+H9clqIj/8UXjGzB84IzeGbyjP ETzd4HwJPzrtg79OLDEDczgLTFyKP7u3SlP3BjKzk4CyJHNIW3hy++9u4072ZZOqUHg9 X1wkLzuLwprRisufK7O+Q32p28u3XF/olKDojQBnVWch/l1Ekiv/pjucaHjqEeCPpUHk DttJKhRbF3pfvqmboFgWBrvOSFinFkTEUeOz2GZ/E9t1RZKYiJUvGFGLOAW8JzorbIAr YL/JzayNthVsW7wUamxqeq2BsJEcjNlfv7eWTcGGnnNlTLldAAzS0gw0XU7QLNKV/tb1 RXBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=AsNpezFuIFITFv7bfdg1TfUG4ptHea0UYlBh5yvYfTg=; b=BHdvzswpiPz7QntIm3m+oxtRszwE3FQBCPFKA4vGaeUGQFY29P/2hXBFbSc/Rnomg0 WWHUN0bjlP/O9VZyNtYCm/h4plb4/Uxor1GZTEDZQO6ppYFR2umULdbSxH+8S1qZKWSR 9KLcTwaHiDsrPbcH5gwnncR5tURIn4h6ohmzMwBRPYzyjwjIvrbrNuCDhGzJn1StnCj4 3muewGOt5WNwlJkfpG24UpmnLZEef3xRgsc5/Icl0N5KTyg/ldyW3TBkKau0P4N0J4jY MWoxgIHh+swn8h2vXxGrTORhktAJtnpj62QomLgIlLbfxpJG7UfUgmv9KfU+KrGMVRaV AeOA== X-Gm-Message-State: AG10YORj1VQkkQnqsjjo9rJg8hY3FszBsBgNq1QrPhboDt6k9pWWQOy5Lxi/7N+1NBmb/w== X-Received: by 10.50.8.42 with SMTP id o10mr8585884iga.59.1454298190726; Sun, 31 Jan 2016 19:43:10 -0800 (PST) Received: from sp12.ecn.purdue.edu.ecn.purdue.edu (eprof.ecn.purdue.edu. [128.46.101.56]) by smtp.gmail.com with ESMTPSA id l91sm6953213ioi.3.2016.01.31.19.43.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Jan 2016 19:43:10 -0800 (PST) From: Abhilash Jindal To: linux-mmc@vger.kernel.org Cc: ulf.hansson@linaro.org, Abhilash Jindal Subject: [PATCH] mmc: mmc-test: y2038, use boottime to compare time Date: Sun, 31 Jan 2016 22:43:08 -0500 Message-Id: <1454298188-17174-1-git-send-email-klock.android@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Wall time obtained from getnstimeofday gives 32 bit timeval which can only represent time until January 2038. This patch moves to ktime_t, a 64-bit time. Also, wall time is susceptible to sudden jumps due to user setting the time or due to NTP. Boot time is constantly increasing time better suited for subtracting two timestamps. Signed-off-by: Abhilash Jindal --- drivers/mmc/card/mmc_test.c | 113 +++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 58 deletions(-) diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c index 7fc9174..d04d446 100644 --- a/drivers/mmc/card/mmc_test.c +++ b/drivers/mmc/card/mmc_test.c @@ -97,7 +97,7 @@ struct mmc_test_transfer_result { struct list_head link; unsigned int count; unsigned int sectors; - struct timespec ts; + ktime_t tm; unsigned int rate; unsigned int iops; }; @@ -487,13 +487,9 @@ static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem, /* * 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, ktime_t tm) { - uint64_t ns; - - ns = ts->tv_sec; - ns *= 1000000000; - ns += ts->tv_nsec; + uint64_t ns = ktime_to_ns(tm); bytes *= 1000000000; @@ -514,7 +510,7 @@ static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts) * Save transfer results for future usage */ 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, ktime_t tm, unsigned int rate, unsigned int iops) { struct mmc_test_transfer_result *tr; @@ -528,7 +524,7 @@ static void mmc_test_save_transfer_result(struct mmc_test_card *test, tr->count = count; tr->sectors = sectors; - tr->ts = ts; + tr->tm = tm; tr->rate = rate; tr->iops = iops; @@ -539,15 +535,14 @@ static void mmc_test_save_transfer_result(struct mmc_test_card *test, * Print the transfer rate. */ static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes, - struct timespec *ts1, struct timespec *ts2) + ktime_t tm1, ktime_t tm2) { unsigned int rate, iops, sectors = bytes >> 9; - struct timespec ts; - - ts = timespec_sub(*ts2, *ts1); + ktime_t tm = ktime_sub(tm1, tm2); + struct timespec ts = ktime_to_timespec(tm); - rate = mmc_test_rate(bytes, &ts); - iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */ + rate = mmc_test_rate(bytes, tm); + iops = mmc_test_rate(100, tm); /* I/O ops per sec x 100 */ pr_info("%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu " "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n", @@ -556,24 +551,23 @@ static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes, (unsigned long)ts.tv_nsec, rate / 1000, rate / 1024, iops / 100, iops % 100); - mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops); + mmc_test_save_transfer_result(test, 1, sectors, tm, rate, iops); } /* * Print the average transfer rate. */ static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes, - unsigned int count, struct timespec *ts1, - struct timespec *ts2) + unsigned int count, ktime_t tm1, + ktime_t tm2) { unsigned int rate, iops, sectors = bytes >> 9; uint64_t tot = bytes * count; - struct timespec ts; - - ts = timespec_sub(*ts2, *ts1); + ktime_t tm = ktime_sub(tm2, tm1); + struct timespec ts = ktime_to_timespec(tm); - rate = mmc_test_rate(tot, &ts); - iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */ + rate = mmc_test_rate(tot, tm); + iops = mmc_test_rate(count * 100, tm); /* I/O ops per sec x 100 */ pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took " "%lu.%09lu seconds (%u kB/s, %u KiB/s, " @@ -584,7 +578,7 @@ static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes, rate / 1000, rate / 1024, iops / 100, iops % 100, test->area.sg_len); - mmc_test_save_transfer_result(test, count, sectors, ts, rate, iops); + mmc_test_save_transfer_result(test, count, sectors, tm, rate, iops); } /* @@ -1391,7 +1385,7 @@ static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz, int max_scatter, int timed, int count, bool nonblock, int min_sg_len) { - struct timespec ts1, ts2; + ktime_t tm1, tm2; int ret = 0; int i; struct mmc_test_area *t = &test->area; @@ -1417,7 +1411,7 @@ static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz, return ret; if (timed) - getnstimeofday(&ts1); + tm1 = ktime_get_boottime(); if (nonblock) ret = mmc_test_nonblock_transfer(test, t->sg, t->sg_len, dev_addr, t->blocks, 512, write, count); @@ -1431,10 +1425,10 @@ static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz, return ret; if (timed) - getnstimeofday(&ts2); + tm2 = ktime_get_boottime(); if (timed) - mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2); + mmc_test_print_avg_rate(test, sz, count, tm1, tm2); return 0; } @@ -1689,7 +1683,7 @@ static int mmc_test_profile_trim_perf(struct mmc_test_card *test) struct mmc_test_area *t = &test->area; unsigned long sz; unsigned int dev_addr; - struct timespec ts1, ts2; + ktime_t tm1, tm2; int ret; if (!mmc_can_trim(test->card)) @@ -1700,20 +1694,20 @@ static int mmc_test_profile_trim_perf(struct mmc_test_card *test) for (sz = 512; sz < t->max_sz; sz <<= 1) { dev_addr = t->dev_addr + (sz >> 9); - getnstimeofday(&ts1); + tm1 = ktime_get_boottime(); ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG); if (ret) return ret; - getnstimeofday(&ts2); - mmc_test_print_rate(test, sz, &ts1, &ts2); + tm2 = ktime_get_boottime(); + mmc_test_print_rate(test, sz, tm1, tm2); } dev_addr = t->dev_addr; - getnstimeofday(&ts1); + tm1 = ktime_get_boottime(); ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG); if (ret) return ret; - getnstimeofday(&ts2); - mmc_test_print_rate(test, sz, &ts1, &ts2); + tm2 = ktime_get_boottime(); + mmc_test_print_rate(test, sz, tm1, tm2); return 0; } @@ -1721,20 +1715,20 @@ static int mmc_test_seq_read_perf(struct mmc_test_card *test, unsigned long sz) { struct mmc_test_area *t = &test->area; unsigned int dev_addr, i, cnt; - struct timespec ts1, ts2; + ktime_t tm1, tm2; int ret; cnt = t->max_sz / sz; dev_addr = t->dev_addr; - getnstimeofday(&ts1); + tm1 = ktime_get_boottime(); for (i = 0; i < cnt; i++) { ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0); if (ret) return ret; dev_addr += (sz >> 9); } - getnstimeofday(&ts2); - mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); + tm2 = ktime_get_boottime(); + mmc_test_print_avg_rate(test, sz, cnt, tm1, tm2); return 0; } @@ -1760,7 +1754,7 @@ static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz) { struct mmc_test_area *t = &test->area; unsigned int dev_addr, i, cnt; - struct timespec ts1, ts2; + ktime_t tm1, tm2; int ret; ret = mmc_test_area_erase(test); @@ -1768,15 +1762,15 @@ static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz) return ret; cnt = t->max_sz / sz; dev_addr = t->dev_addr; - getnstimeofday(&ts1); + tm1 = ktime_get_boottime(); for (i = 0; i < cnt; i++) { ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0); if (ret) return ret; dev_addr += (sz >> 9); } - getnstimeofday(&ts2); - mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); + tm2 = ktime_get_boottime(); + mmc_test_print_avg_rate(test, sz, cnt, tm1, tm2); return 0; } @@ -1806,7 +1800,7 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test) struct mmc_test_area *t = &test->area; unsigned long sz; unsigned int dev_addr, i, cnt; - struct timespec ts1, ts2; + ktime_t tm1, tm2; int ret; if (!mmc_can_trim(test->card)) @@ -1824,7 +1818,7 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test) return ret; cnt = t->max_sz / sz; dev_addr = t->dev_addr; - getnstimeofday(&ts1); + tm1 = ktime_get_boottime(); for (i = 0; i < cnt; i++) { ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG); @@ -1832,8 +1826,8 @@ static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test) return ret; dev_addr += (sz >> 9); } - getnstimeofday(&ts2); - mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); + tm2 = ktime_get_boottime(); + mmc_test_print_avg_rate(test, sz, cnt, tm1, tm2); } return 0; } @@ -1854,7 +1848,8 @@ 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 ssz; - struct timespec ts1, ts2, ts; + ktime_t tm1, tm2, tm; + struct timespec ts; int ret; ssz = sz >> 9; @@ -1863,10 +1858,11 @@ static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print, range1 = rnd_addr / test->card->pref_erase; range2 = range1 / ssz; - getnstimeofday(&ts1); + tm1 = ktime_get_boottime(); for (cnt = 0; cnt < UINT_MAX; cnt++) { - getnstimeofday(&ts2); - ts = timespec_sub(ts2, ts1); + tm2 = ktime_get_boottime(); + tm = ktime_sub(tm2, tm1); + ts = ktime_to_timespec(tm); if (ts.tv_sec >= 10) break; ea = mmc_test_rnd_num(range1); @@ -1880,7 +1876,7 @@ static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print, return ret; } if (print) - mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); + mmc_test_print_avg_rate(test, sz, cnt, tm1, tm2); return 0; } @@ -1940,7 +1936,7 @@ static int mmc_test_seq_perf(struct mmc_test_card *test, int write, { struct mmc_test_area *t = &test->area; unsigned int dev_addr, i, cnt, sz, ssz; - struct timespec ts1, ts2; + ktime_t tm1, tm2; int ret; sz = t->max_tfr; @@ -1967,7 +1963,7 @@ static int mmc_test_seq_perf(struct mmc_test_card *test, int write, cnt = tot_sz / sz; dev_addr &= 0xffff0000; /* Round to 64MiB boundary */ - getnstimeofday(&ts1); + tm1 = ktime_get_boottime(); for (i = 0; i < cnt; i++) { ret = mmc_test_area_io(test, sz, dev_addr, write, max_scatter, 0); @@ -1975,9 +1971,9 @@ static int mmc_test_seq_perf(struct mmc_test_card *test, int write, return ret; dev_addr += ssz; } - getnstimeofday(&ts2); + tm2 = ktime_get_boottime(); - mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); + mmc_test_print_avg_rate(test, sz, cnt, tm1, tm2); return 0; } @@ -2748,10 +2744,11 @@ static int mtf_test_show(struct seq_file *sf, void *data) seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result); list_for_each_entry(tr, &gr->tr_lst, link) { + struct timespec ts = ktime_to_timespec(tr->tm); seq_printf(sf, "%u %d %lu.%09lu %u %u.%02u\n", tr->count, tr->sectors, - (unsigned long)tr->ts.tv_sec, - (unsigned long)tr->ts.tv_nsec, + (unsigned long)ts.tv_sec, + (unsigned long)ts.tv_nsec, tr->rate, tr->iops / 100, tr->iops % 100); } }