aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/tests/mtd_speedtest.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/tests/mtd_speedtest.c')
-rw-r--r--drivers/mtd/tests/mtd_speedtest.c80
1 files changed, 73 insertions, 7 deletions
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 161feeb7b8b9..627d4e2466a3 100644
--- a/drivers/mtd/tests/mtd_speedtest.c
+++ b/drivers/mtd/tests/mtd_speedtest.c
@@ -16,7 +16,7 @@
16 * 16 *
17 * Test read and write speed of a MTD device. 17 * Test read and write speed of a MTD device.
18 * 18 *
19 * Author: Adrian Hunter <ext-adrian.hunter@nokia.com> 19 * Author: Adrian Hunter <adrian.hunter@nokia.com>
20 */ 20 */
21 21
22#include <linux/init.h> 22#include <linux/init.h>
@@ -33,6 +33,11 @@ static int dev;
33module_param(dev, int, S_IRUGO); 33module_param(dev, int, S_IRUGO);
34MODULE_PARM_DESC(dev, "MTD device number to use"); 34MODULE_PARM_DESC(dev, "MTD device number to use");
35 35
36static int count;
37module_param(count, int, S_IRUGO);
38MODULE_PARM_DESC(count, "Maximum number of eraseblocks to use "
39 "(0 means use all)");
40
36static struct mtd_info *mtd; 41static struct mtd_info *mtd;
37static unsigned char *iobuf; 42static unsigned char *iobuf;
38static unsigned char *bbt; 43static unsigned char *bbt;
@@ -89,6 +94,33 @@ static int erase_eraseblock(int ebnum)
89 return 0; 94 return 0;
90} 95}
91 96
97static int multiblock_erase(int ebnum, int blocks)
98{
99 int err;
100 struct erase_info ei;
101 loff_t addr = ebnum * mtd->erasesize;
102
103 memset(&ei, 0, sizeof(struct erase_info));
104 ei.mtd = mtd;
105 ei.addr = addr;
106 ei.len = mtd->erasesize * blocks;
107
108 err = mtd->erase(mtd, &ei);
109 if (err) {
110 printk(PRINT_PREF "error %d while erasing EB %d, blocks %d\n",
111 err, ebnum, blocks);
112 return err;
113 }
114
115 if (ei.state == MTD_ERASE_FAILED) {
116 printk(PRINT_PREF "some erase error occurred at EB %d,"
117 "blocks %d\n", ebnum, blocks);
118 return -EIO;
119 }
120
121 return 0;
122}
123
92static int erase_whole_device(void) 124static int erase_whole_device(void)
93{ 125{
94 int err; 126 int err;
@@ -282,13 +314,16 @@ static inline void stop_timing(void)
282 314
283static long calc_speed(void) 315static long calc_speed(void)
284{ 316{
285 long ms, k, speed; 317 uint64_t k;
318 long ms;
286 319
287 ms = (finish.tv_sec - start.tv_sec) * 1000 + 320 ms = (finish.tv_sec - start.tv_sec) * 1000 +
288 (finish.tv_usec - start.tv_usec) / 1000; 321 (finish.tv_usec - start.tv_usec) / 1000;
289 k = goodebcnt * mtd->erasesize / 1024; 322 if (ms == 0)
290 speed = (k * 1000) / ms; 323 return 0;
291 return speed; 324 k = goodebcnt * (mtd->erasesize / 1024) * 1000;
325 do_div(k, ms);
326 return k;
292} 327}
293 328
294static int scan_for_bad_eraseblocks(void) 329static int scan_for_bad_eraseblocks(void)
@@ -320,13 +355,16 @@ out:
320 355
321static int __init mtd_speedtest_init(void) 356static int __init mtd_speedtest_init(void)
322{ 357{
323 int err, i; 358 int err, i, blocks, j, k;
324 long speed; 359 long speed;
325 uint64_t tmp; 360 uint64_t tmp;
326 361
327 printk(KERN_INFO "\n"); 362 printk(KERN_INFO "\n");
328 printk(KERN_INFO "=================================================\n"); 363 printk(KERN_INFO "=================================================\n");
329 printk(PRINT_PREF "MTD device: %d\n", dev); 364 if (count)
365 printk(PRINT_PREF "MTD device: %d count: %d\n", dev, count);
366 else
367 printk(PRINT_PREF "MTD device: %d\n", dev);
330 368
331 mtd = get_mtd_device(NULL, dev); 369 mtd = get_mtd_device(NULL, dev);
332 if (IS_ERR(mtd)) { 370 if (IS_ERR(mtd)) {
@@ -353,6 +391,9 @@ static int __init mtd_speedtest_init(void)
353 (unsigned long long)mtd->size, mtd->erasesize, 391 (unsigned long long)mtd->size, mtd->erasesize,
354 pgsize, ebcnt, pgcnt, mtd->oobsize); 392 pgsize, ebcnt, pgcnt, mtd->oobsize);
355 393
394 if (count > 0 && count < ebcnt)
395 ebcnt = count;
396
356 err = -ENOMEM; 397 err = -ENOMEM;
357 iobuf = kmalloc(mtd->erasesize, GFP_KERNEL); 398 iobuf = kmalloc(mtd->erasesize, GFP_KERNEL);
358 if (!iobuf) { 399 if (!iobuf) {
@@ -484,6 +525,31 @@ static int __init mtd_speedtest_init(void)
484 speed = calc_speed(); 525 speed = calc_speed();
485 printk(PRINT_PREF "erase speed is %ld KiB/s\n", speed); 526 printk(PRINT_PREF "erase speed is %ld KiB/s\n", speed);
486 527
528 /* Multi-block erase all eraseblocks */
529 for (k = 1; k < 7; k++) {
530 blocks = 1 << k;
531 printk(PRINT_PREF "Testing %dx multi-block erase speed\n",
532 blocks);
533 start_timing();
534 for (i = 0; i < ebcnt; ) {
535 for (j = 0; j < blocks && (i + j) < ebcnt; j++)
536 if (bbt[i + j])
537 break;
538 if (j < 1) {
539 i++;
540 continue;
541 }
542 err = multiblock_erase(i, j);
543 if (err)
544 goto out;
545 cond_resched();
546 i += j;
547 }
548 stop_timing();
549 speed = calc_speed();
550 printk(PRINT_PREF "%dx multi-block erase speed is %ld KiB/s\n",
551 blocks, speed);
552 }
487 printk(PRINT_PREF "finished\n"); 553 printk(PRINT_PREF "finished\n");
488out: 554out:
489 kfree(iobuf); 555 kfree(iobuf);