519
523
static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
520
524
struct timespec *ts1, struct timespec *ts2)
522
unsigned int rate, sectors = bytes >> 9;
526
unsigned int rate, iops, sectors = bytes >> 9;
523
527
struct timespec ts;
525
529
ts = timespec_sub(*ts2, *ts1);
527
531
rate = mmc_test_rate(bytes, &ts);
532
iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
529
534
printk(KERN_INFO "%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
530
"seconds (%u kB/s, %u KiB/s)\n",
535
"seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
531
536
mmc_hostname(test->card->host), sectors, sectors >> 1,
532
537
(sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
533
(unsigned long)ts.tv_nsec, rate / 1000, rate / 1024);
538
(unsigned long)ts.tv_nsec, rate / 1000, rate / 1024,
539
iops / 100, iops % 100);
535
mmc_test_save_transfer_result(test, 1, sectors, ts, rate);
541
mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops);
542
548
unsigned int count, struct timespec *ts1,
543
549
struct timespec *ts2)
545
unsigned int rate, sectors = bytes >> 9;
551
unsigned int rate, iops, sectors = bytes >> 9;
546
552
uint64_t tot = bytes * count;
547
553
struct timespec ts;
549
555
ts = timespec_sub(*ts2, *ts1);
551
557
rate = mmc_test_rate(tot, &ts);
558
iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
553
560
printk(KERN_INFO "%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
554
"%lu.%09lu seconds (%u kB/s, %u KiB/s)\n",
561
"%lu.%09lu seconds (%u kB/s, %u KiB/s, "
555
563
mmc_hostname(test->card->host), count, sectors, count,
556
564
sectors >> 1, (sectors & 1 ? ".5" : ""),
557
565
(unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec,
558
rate / 1000, rate / 1024);
566
rate / 1000, rate / 1024, iops / 100, iops % 100);
560
mmc_test_save_transfer_result(test, count, sectors, ts, rate);
568
mmc_test_save_transfer_result(test, count, sectors, ts, rate, iops);
1428
* Initialize an area for testing large transfers. The size of the area is the
1429
* preferred erase size which is a good size for optimal transfer speed. Note
1430
* that is typically 4MiB for modern cards. The test area is set to the middle
1431
* of the card because cards may have different charateristics at the front
1432
* (for FAT file system optimization). Optionally, the area is erased (if the
1433
* card supports it) which may improve write performance. Optionally, the area
1434
* is filled with data for subsequent read tests.
1436
* Initialize an area for testing large transfers. The test area is set to the
1437
* middle of the card because cards may have different charateristics at the
1438
* front (for FAT file system optimization). Optionally, the area is erased
1439
* (if the card supports it) which may improve write performance. Optionally,
1440
* the area is filled with data for subsequent read tests.
1436
1442
static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
1438
1444
struct mmc_test_area *t = &test->area;
1439
unsigned long min_sz = 64 * 1024;
1445
unsigned long min_sz = 64 * 1024, sz;
1442
1448
ret = mmc_test_set_blksize(test, 512);
1446
if (test->card->pref_erase > TEST_AREA_MAX_SIZE >> 9)
1447
t->max_sz = TEST_AREA_MAX_SIZE;
1449
t->max_sz = (unsigned long)test->card->pref_erase << 9;
1452
/* Make the test area size about 4MiB */
1453
sz = (unsigned long)test->card->pref_erase << 9;
1455
while (t->max_sz < 4 * 1024 * 1024)
1457
while (t->max_sz > TEST_AREA_MAX_SIZE && t->max_sz > sz)
1451
1460
t->max_segs = test->card->host->max_segs;
1452
1461
t->max_seg_sz = test->card->host->max_seg_size;
1778
static unsigned int rnd_next = 1;
1780
static unsigned int mmc_test_rnd_num(unsigned int rnd_cnt)
1784
rnd_next = rnd_next * 1103515245 + 12345;
1785
r = (rnd_next >> 16) & 0x7fff;
1786
return (r * rnd_cnt) >> 15;
1789
static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print,
1792
unsigned int dev_addr, cnt, rnd_addr, range1, range2, last_ea = 0, ea;
1794
struct timespec ts1, ts2, ts;
1799
rnd_addr = mmc_test_capacity(test->card) / 4;
1800
range1 = rnd_addr / test->card->pref_erase;
1801
range2 = range1 / ssz;
1803
getnstimeofday(&ts1);
1804
for (cnt = 0; cnt < UINT_MAX; cnt++) {
1805
getnstimeofday(&ts2);
1806
ts = timespec_sub(ts2, ts1);
1807
if (ts.tv_sec >= 10)
1809
ea = mmc_test_rnd_num(range1);
1813
dev_addr = rnd_addr + test->card->pref_erase * ea +
1814
ssz * mmc_test_rnd_num(range2);
1815
ret = mmc_test_area_io(test, sz, dev_addr, write, 0, 0);
1820
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1824
static int mmc_test_random_perf(struct mmc_test_card *test, int write)
1830
for (sz = 512; sz < test->area.max_tfr; sz <<= 1) {
1832
* When writing, try to get more consistent results by running
1833
* the test twice with exactly the same I/O but outputting the
1834
* results only for the 2nd run.
1838
ret = mmc_test_rnd_perf(test, write, 0, sz);
1843
ret = mmc_test_rnd_perf(test, write, 1, sz);
1847
sz = test->area.max_tfr;
1850
ret = mmc_test_rnd_perf(test, write, 0, sz);
1855
return mmc_test_rnd_perf(test, write, 1, sz);
1859
* Random read performance by transfer size.
1861
static int mmc_test_random_read_perf(struct mmc_test_card *test)
1863
return mmc_test_random_perf(test, 0);
1867
* Random write performance by transfer size.
1869
static int mmc_test_random_write_perf(struct mmc_test_card *test)
1871
return mmc_test_random_perf(test, 1);
1874
static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
1875
unsigned int tot_sz, int max_scatter)
1877
unsigned int dev_addr, i, cnt, sz, ssz;
1878
struct timespec ts1, ts2;
1881
sz = test->area.max_tfr;
1883
* In the case of a maximally scattered transfer, the maximum transfer
1884
* size is further limited by using PAGE_SIZE segments.
1887
struct mmc_test_area *t = &test->area;
1888
unsigned long max_tfr;
1890
if (t->max_seg_sz >= PAGE_SIZE)
1891
max_tfr = t->max_segs * PAGE_SIZE;
1893
max_tfr = t->max_segs * t->max_seg_sz;
1899
dev_addr = mmc_test_capacity(test->card) / 4;
1900
if (tot_sz > dev_addr << 9)
1901
tot_sz = dev_addr << 9;
1903
dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
1905
getnstimeofday(&ts1);
1906
for (i = 0; i < cnt; i++) {
1907
ret = mmc_test_area_io(test, sz, dev_addr, write,
1913
getnstimeofday(&ts2);
1915
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1920
static int mmc_test_large_seq_perf(struct mmc_test_card *test, int write)
1924
for (i = 0; i < 10; i++) {
1925
ret = mmc_test_seq_perf(test, write, 10 * 1024 * 1024, 1);
1929
for (i = 0; i < 5; i++) {
1930
ret = mmc_test_seq_perf(test, write, 100 * 1024 * 1024, 1);
1934
for (i = 0; i < 3; i++) {
1935
ret = mmc_test_seq_perf(test, write, 1000 * 1024 * 1024, 1);
1944
* Large sequential read performance.
1946
static int mmc_test_large_seq_read_perf(struct mmc_test_card *test)
1948
return mmc_test_large_seq_perf(test, 0);
1952
* Large sequential write performance.
1954
static int mmc_test_large_seq_write_perf(struct mmc_test_card *test)
1956
return mmc_test_large_seq_perf(test, 1);
1769
1959
static const struct mmc_test_case mmc_test_cases[] = {
1771
1961
.name = "Basic write (no data verification)",
2005
2195
.cleanup = mmc_test_area_cleanup,
2199
.name = "Random read performance by transfer size",
2200
.prepare = mmc_test_area_prepare,
2201
.run = mmc_test_random_read_perf,
2202
.cleanup = mmc_test_area_cleanup,
2206
.name = "Random write performance by transfer size",
2207
.prepare = mmc_test_area_prepare,
2208
.run = mmc_test_random_write_perf,
2209
.cleanup = mmc_test_area_cleanup,
2213
.name = "Large sequential read into scattered pages",
2214
.prepare = mmc_test_area_prepare,
2215
.run = mmc_test_large_seq_read_perf,
2216
.cleanup = mmc_test_area_cleanup,
2220
.name = "Large sequential write from scattered pages",
2221
.prepare = mmc_test_area_prepare,
2222
.run = mmc_test_large_seq_write_perf,
2223
.cleanup = mmc_test_area_cleanup,
2010
2228
static DEFINE_MUTEX(mmc_test_lock);