Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Nokia Corporation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License version 2 as published by |
| 6 | * the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; see the file COPYING. If not, write to the Free Software |
| 15 | * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 16 | * |
| 17 | * Test read and write speed of a MTD device. |
| 18 | * |
Adrian Hunter | fc7fe76 | 2011-02-08 12:02:39 +0200 | [diff] [blame] | 19 | * Author: Adrian Hunter <adrian.hunter@nokia.com> |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 20 | */ |
| 21 | |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/moduleparam.h> |
| 27 | #include <linux/err.h> |
| 28 | #include <linux/mtd/mtd.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 30 | #include <linux/sched.h> |
Artem Bityutskiy | bfea1d4 | 2012-05-18 18:44:53 +0300 | [diff] [blame] | 31 | #include <linux/random.h> |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 32 | |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 33 | #include "mtd_test.h" |
| 34 | |
Wolfram Sang | 7406060 | 2011-10-30 00:11:53 +0200 | [diff] [blame] | 35 | static int dev = -EINVAL; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 36 | module_param(dev, int, S_IRUGO); |
| 37 | MODULE_PARM_DESC(dev, "MTD device number to use"); |
| 38 | |
Adrian Hunter | fc7fe76 | 2011-02-08 12:02:39 +0200 | [diff] [blame] | 39 | static int count; |
| 40 | module_param(count, int, S_IRUGO); |
| 41 | MODULE_PARM_DESC(count, "Maximum number of eraseblocks to use " |
| 42 | "(0 means use all)"); |
| 43 | |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 44 | static struct mtd_info *mtd; |
| 45 | static unsigned char *iobuf; |
| 46 | static unsigned char *bbt; |
| 47 | |
| 48 | static int pgsize; |
| 49 | static int ebcnt; |
| 50 | static int pgcnt; |
| 51 | static int goodebcnt; |
| 52 | static struct timeval start, finish; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 53 | |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 54 | static int multiblock_erase(int ebnum, int blocks) |
| 55 | { |
| 56 | int err; |
| 57 | struct erase_info ei; |
Brian Norris | 1001ff7 | 2014-07-21 19:07:12 -0700 | [diff] [blame] | 58 | loff_t addr = (loff_t)ebnum * mtd->erasesize; |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 59 | |
| 60 | memset(&ei, 0, sizeof(struct erase_info)); |
| 61 | ei.mtd = mtd; |
| 62 | ei.addr = addr; |
| 63 | ei.len = mtd->erasesize * blocks; |
| 64 | |
Artem Bityutskiy | 7e1f0dc | 2011-12-23 15:25:39 +0200 | [diff] [blame] | 65 | err = mtd_erase(mtd, &ei); |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 66 | if (err) { |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 67 | pr_err("error %d while erasing EB %d, blocks %d\n", |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 68 | err, ebnum, blocks); |
| 69 | return err; |
| 70 | } |
| 71 | |
| 72 | if (ei.state == MTD_ERASE_FAILED) { |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 73 | pr_err("some erase error occurred at EB %d," |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 74 | "blocks %d\n", ebnum, blocks); |
| 75 | return -EIO; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 81 | static int write_eraseblock(int ebnum) |
| 82 | { |
Brian Norris | 1001ff7 | 2014-07-21 19:07:12 -0700 | [diff] [blame] | 83 | loff_t addr = (loff_t)ebnum * mtd->erasesize; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 84 | |
Akinobu Mita | 8a9f4aa | 2013-08-15 22:55:09 +0900 | [diff] [blame] | 85 | return mtdtest_write(mtd, addr, mtd->erasesize, iobuf); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static int write_eraseblock_by_page(int ebnum) |
| 89 | { |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 90 | int i, err = 0; |
Brian Norris | 1001ff7 | 2014-07-21 19:07:12 -0700 | [diff] [blame] | 91 | loff_t addr = (loff_t)ebnum * mtd->erasesize; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 92 | void *buf = iobuf; |
| 93 | |
| 94 | for (i = 0; i < pgcnt; i++) { |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 95 | err = mtdtest_write(mtd, addr, pgsize, buf); |
Akinobu Mita | 8a9f4aa | 2013-08-15 22:55:09 +0900 | [diff] [blame] | 96 | if (err) |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 97 | break; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 98 | addr += pgsize; |
| 99 | buf += pgsize; |
| 100 | } |
| 101 | |
| 102 | return err; |
| 103 | } |
| 104 | |
| 105 | static int write_eraseblock_by_2pages(int ebnum) |
| 106 | { |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 107 | size_t sz = pgsize * 2; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 108 | int i, n = pgcnt / 2, err = 0; |
Brian Norris | 1001ff7 | 2014-07-21 19:07:12 -0700 | [diff] [blame] | 109 | loff_t addr = (loff_t)ebnum * mtd->erasesize; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 110 | void *buf = iobuf; |
| 111 | |
| 112 | for (i = 0; i < n; i++) { |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 113 | err = mtdtest_write(mtd, addr, sz, buf); |
Akinobu Mita | 8a9f4aa | 2013-08-15 22:55:09 +0900 | [diff] [blame] | 114 | if (err) |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 115 | return err; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 116 | addr += sz; |
| 117 | buf += sz; |
| 118 | } |
Akinobu Mita | 8a9f4aa | 2013-08-15 22:55:09 +0900 | [diff] [blame] | 119 | if (pgcnt % 2) |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 120 | err = mtdtest_write(mtd, addr, pgsize, buf); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 121 | |
| 122 | return err; |
| 123 | } |
| 124 | |
| 125 | static int read_eraseblock(int ebnum) |
| 126 | { |
Brian Norris | 1001ff7 | 2014-07-21 19:07:12 -0700 | [diff] [blame] | 127 | loff_t addr = (loff_t)ebnum * mtd->erasesize; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 128 | |
Akinobu Mita | abc173a | 2013-08-15 22:55:08 +0900 | [diff] [blame] | 129 | return mtdtest_read(mtd, addr, mtd->erasesize, iobuf); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static int read_eraseblock_by_page(int ebnum) |
| 133 | { |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 134 | int i, err = 0; |
Brian Norris | 1001ff7 | 2014-07-21 19:07:12 -0700 | [diff] [blame] | 135 | loff_t addr = (loff_t)ebnum * mtd->erasesize; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 136 | void *buf = iobuf; |
| 137 | |
| 138 | for (i = 0; i < pgcnt; i++) { |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 139 | err = mtdtest_read(mtd, addr, pgsize, buf); |
Akinobu Mita | abc173a | 2013-08-15 22:55:08 +0900 | [diff] [blame] | 140 | if (err) |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 141 | break; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 142 | addr += pgsize; |
| 143 | buf += pgsize; |
| 144 | } |
| 145 | |
| 146 | return err; |
| 147 | } |
| 148 | |
| 149 | static int read_eraseblock_by_2pages(int ebnum) |
| 150 | { |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 151 | size_t sz = pgsize * 2; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 152 | int i, n = pgcnt / 2, err = 0; |
Brian Norris | 1001ff7 | 2014-07-21 19:07:12 -0700 | [diff] [blame] | 153 | loff_t addr = (loff_t)ebnum * mtd->erasesize; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 154 | void *buf = iobuf; |
| 155 | |
| 156 | for (i = 0; i < n; i++) { |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 157 | err = mtdtest_read(mtd, addr, sz, buf); |
Akinobu Mita | abc173a | 2013-08-15 22:55:08 +0900 | [diff] [blame] | 158 | if (err) |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 159 | return err; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 160 | addr += sz; |
| 161 | buf += sz; |
| 162 | } |
Akinobu Mita | abc173a | 2013-08-15 22:55:08 +0900 | [diff] [blame] | 163 | if (pgcnt % 2) |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 164 | err = mtdtest_read(mtd, addr, pgsize, buf); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 165 | |
| 166 | return err; |
| 167 | } |
| 168 | |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 169 | static inline void start_timing(void) |
| 170 | { |
| 171 | do_gettimeofday(&start); |
| 172 | } |
| 173 | |
| 174 | static inline void stop_timing(void) |
| 175 | { |
| 176 | do_gettimeofday(&finish); |
| 177 | } |
| 178 | |
| 179 | static long calc_speed(void) |
| 180 | { |
David Lambert | e70727e | 2011-03-07 12:00:46 +0200 | [diff] [blame] | 181 | uint64_t k; |
| 182 | long ms; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 183 | |
| 184 | ms = (finish.tv_sec - start.tv_sec) * 1000 + |
| 185 | (finish.tv_usec - start.tv_usec) / 1000; |
David Lambert | e70727e | 2011-03-07 12:00:46 +0200 | [diff] [blame] | 186 | if (ms == 0) |
| 187 | return 0; |
Brian Norris | b9da8ba | 2015-02-28 02:02:26 -0800 | [diff] [blame] | 188 | k = (uint64_t)goodebcnt * (mtd->erasesize / 1024) * 1000; |
David Lambert | e70727e | 2011-03-07 12:00:46 +0200 | [diff] [blame] | 189 | do_div(k, ms); |
| 190 | return k; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 193 | static int __init mtd_speedtest_init(void) |
| 194 | { |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 195 | int err, i, blocks, j, k; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 196 | long speed; |
| 197 | uint64_t tmp; |
| 198 | |
| 199 | printk(KERN_INFO "\n"); |
| 200 | printk(KERN_INFO "=================================================\n"); |
Wolfram Sang | 7406060 | 2011-10-30 00:11:53 +0200 | [diff] [blame] | 201 | |
| 202 | if (dev < 0) { |
Masanari Iida | 064a769 | 2012-11-09 23:20:58 +0900 | [diff] [blame] | 203 | pr_info("Please specify a valid mtd-device via module parameter\n"); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 204 | pr_crit("CAREFUL: This test wipes all data on the specified MTD device!\n"); |
Wolfram Sang | 7406060 | 2011-10-30 00:11:53 +0200 | [diff] [blame] | 205 | return -EINVAL; |
| 206 | } |
| 207 | |
Adrian Hunter | fc7fe76 | 2011-02-08 12:02:39 +0200 | [diff] [blame] | 208 | if (count) |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 209 | pr_info("MTD device: %d count: %d\n", dev, count); |
Adrian Hunter | fc7fe76 | 2011-02-08 12:02:39 +0200 | [diff] [blame] | 210 | else |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 211 | pr_info("MTD device: %d\n", dev); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 212 | |
| 213 | mtd = get_mtd_device(NULL, dev); |
| 214 | if (IS_ERR(mtd)) { |
| 215 | err = PTR_ERR(mtd); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 216 | pr_err("error: cannot get MTD device\n"); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 217 | return err; |
| 218 | } |
| 219 | |
| 220 | if (mtd->writesize == 1) { |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 221 | pr_info("not NAND flash, assume page size is 512 " |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 222 | "bytes.\n"); |
| 223 | pgsize = 512; |
| 224 | } else |
| 225 | pgsize = mtd->writesize; |
| 226 | |
| 227 | tmp = mtd->size; |
| 228 | do_div(tmp, mtd->erasesize); |
| 229 | ebcnt = tmp; |
Morten Thunberg Svendsen | f5e2bae | 2010-01-06 10:48:18 +0100 | [diff] [blame] | 230 | pgcnt = mtd->erasesize / pgsize; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 231 | |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 232 | pr_info("MTD device size %llu, eraseblock size %u, " |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 233 | "page size %u, count of eraseblocks %u, pages per " |
| 234 | "eraseblock %u, OOB size %u\n", |
| 235 | (unsigned long long)mtd->size, mtd->erasesize, |
| 236 | pgsize, ebcnt, pgcnt, mtd->oobsize); |
| 237 | |
Adrian Hunter | fc7fe76 | 2011-02-08 12:02:39 +0200 | [diff] [blame] | 238 | if (count > 0 && count < ebcnt) |
| 239 | ebcnt = count; |
| 240 | |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 241 | err = -ENOMEM; |
| 242 | iobuf = kmalloc(mtd->erasesize, GFP_KERNEL); |
Brian Norris | 33777e6 | 2013-05-02 14:18:51 -0700 | [diff] [blame] | 243 | if (!iobuf) |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 244 | goto out; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 245 | |
Akinobu Mita | 99672f3 | 2013-02-27 17:05:37 -0800 | [diff] [blame] | 246 | prandom_bytes(iobuf, mtd->erasesize); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 247 | |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 248 | bbt = kzalloc(ebcnt, GFP_KERNEL); |
| 249 | if (!bbt) |
| 250 | goto out; |
| 251 | err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 252 | if (err) |
| 253 | goto out; |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 254 | for (i = 0; i < ebcnt; i++) { |
| 255 | if (!bbt[i]) |
| 256 | goodebcnt++; |
| 257 | } |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 258 | |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 259 | err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 260 | if (err) |
| 261 | goto out; |
| 262 | |
| 263 | /* Write all eraseblocks, 1 eraseblock at a time */ |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 264 | pr_info("testing eraseblock write speed\n"); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 265 | start_timing(); |
| 266 | for (i = 0; i < ebcnt; ++i) { |
| 267 | if (bbt[i]) |
| 268 | continue; |
| 269 | err = write_eraseblock(i); |
| 270 | if (err) |
| 271 | goto out; |
Richard Weinberger | 2a6a28e7 | 2015-03-29 21:52:06 +0200 | [diff] [blame] | 272 | |
| 273 | err = mtdtest_relax(); |
| 274 | if (err) |
| 275 | goto out; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 276 | } |
| 277 | stop_timing(); |
| 278 | speed = calc_speed(); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 279 | pr_info("eraseblock write speed is %ld KiB/s\n", speed); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 280 | |
| 281 | /* Read all eraseblocks, 1 eraseblock at a time */ |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 282 | pr_info("testing eraseblock read speed\n"); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 283 | start_timing(); |
| 284 | for (i = 0; i < ebcnt; ++i) { |
| 285 | if (bbt[i]) |
| 286 | continue; |
| 287 | err = read_eraseblock(i); |
| 288 | if (err) |
| 289 | goto out; |
Richard Weinberger | 2a6a28e7 | 2015-03-29 21:52:06 +0200 | [diff] [blame] | 290 | |
| 291 | err = mtdtest_relax(); |
| 292 | if (err) |
| 293 | goto out; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 294 | } |
| 295 | stop_timing(); |
| 296 | speed = calc_speed(); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 297 | pr_info("eraseblock read speed is %ld KiB/s\n", speed); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 298 | |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 299 | err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 300 | if (err) |
| 301 | goto out; |
| 302 | |
| 303 | /* Write all eraseblocks, 1 page at a time */ |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 304 | pr_info("testing page write speed\n"); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 305 | start_timing(); |
| 306 | for (i = 0; i < ebcnt; ++i) { |
| 307 | if (bbt[i]) |
| 308 | continue; |
| 309 | err = write_eraseblock_by_page(i); |
| 310 | if (err) |
| 311 | goto out; |
Richard Weinberger | 2a6a28e7 | 2015-03-29 21:52:06 +0200 | [diff] [blame] | 312 | |
| 313 | err = mtdtest_relax(); |
| 314 | if (err) |
| 315 | goto out; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 316 | } |
| 317 | stop_timing(); |
| 318 | speed = calc_speed(); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 319 | pr_info("page write speed is %ld KiB/s\n", speed); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 320 | |
| 321 | /* Read all eraseblocks, 1 page at a time */ |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 322 | pr_info("testing page read speed\n"); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 323 | start_timing(); |
| 324 | for (i = 0; i < ebcnt; ++i) { |
| 325 | if (bbt[i]) |
| 326 | continue; |
| 327 | err = read_eraseblock_by_page(i); |
| 328 | if (err) |
| 329 | goto out; |
Richard Weinberger | 2a6a28e7 | 2015-03-29 21:52:06 +0200 | [diff] [blame] | 330 | |
| 331 | err = mtdtest_relax(); |
| 332 | if (err) |
| 333 | goto out; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 334 | } |
| 335 | stop_timing(); |
| 336 | speed = calc_speed(); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 337 | pr_info("page read speed is %ld KiB/s\n", speed); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 338 | |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 339 | err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 340 | if (err) |
| 341 | goto out; |
| 342 | |
| 343 | /* Write all eraseblocks, 2 pages at a time */ |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 344 | pr_info("testing 2 page write speed\n"); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 345 | start_timing(); |
| 346 | for (i = 0; i < ebcnt; ++i) { |
| 347 | if (bbt[i]) |
| 348 | continue; |
| 349 | err = write_eraseblock_by_2pages(i); |
| 350 | if (err) |
| 351 | goto out; |
Richard Weinberger | 2a6a28e7 | 2015-03-29 21:52:06 +0200 | [diff] [blame] | 352 | |
| 353 | err = mtdtest_relax(); |
| 354 | if (err) |
| 355 | goto out; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 356 | } |
| 357 | stop_timing(); |
| 358 | speed = calc_speed(); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 359 | pr_info("2 page write speed is %ld KiB/s\n", speed); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 360 | |
| 361 | /* Read all eraseblocks, 2 pages at a time */ |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 362 | pr_info("testing 2 page read speed\n"); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 363 | start_timing(); |
| 364 | for (i = 0; i < ebcnt; ++i) { |
| 365 | if (bbt[i]) |
| 366 | continue; |
| 367 | err = read_eraseblock_by_2pages(i); |
| 368 | if (err) |
| 369 | goto out; |
Richard Weinberger | 2a6a28e7 | 2015-03-29 21:52:06 +0200 | [diff] [blame] | 370 | |
| 371 | err = mtdtest_relax(); |
| 372 | if (err) |
| 373 | goto out; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 374 | } |
| 375 | stop_timing(); |
| 376 | speed = calc_speed(); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 377 | pr_info("2 page read speed is %ld KiB/s\n", speed); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 378 | |
| 379 | /* Erase all eraseblocks */ |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 380 | pr_info("Testing erase speed\n"); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 381 | start_timing(); |
Akinobu Mita | 59b0816 | 2013-08-03 18:52:12 +0900 | [diff] [blame] | 382 | err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); |
| 383 | if (err) |
| 384 | goto out; |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 385 | stop_timing(); |
| 386 | speed = calc_speed(); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 387 | pr_info("erase speed is %ld KiB/s\n", speed); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 388 | |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 389 | /* Multi-block erase all eraseblocks */ |
| 390 | for (k = 1; k < 7; k++) { |
| 391 | blocks = 1 << k; |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 392 | pr_info("Testing %dx multi-block erase speed\n", |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 393 | blocks); |
| 394 | start_timing(); |
| 395 | for (i = 0; i < ebcnt; ) { |
| 396 | for (j = 0; j < blocks && (i + j) < ebcnt; j++) |
| 397 | if (bbt[i + j]) |
| 398 | break; |
| 399 | if (j < 1) { |
| 400 | i++; |
| 401 | continue; |
| 402 | } |
| 403 | err = multiblock_erase(i, j); |
| 404 | if (err) |
| 405 | goto out; |
Richard Weinberger | 2a6a28e7 | 2015-03-29 21:52:06 +0200 | [diff] [blame] | 406 | |
| 407 | err = mtdtest_relax(); |
| 408 | if (err) |
| 409 | goto out; |
| 410 | |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 411 | i += j; |
| 412 | } |
| 413 | stop_timing(); |
| 414 | speed = calc_speed(); |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 415 | pr_info("%dx multi-block erase speed is %ld KiB/s\n", |
Roman Tereshonkov | 4085bcc | 2011-02-08 12:02:40 +0200 | [diff] [blame] | 416 | blocks, speed); |
| 417 | } |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 418 | pr_info("finished\n"); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 419 | out: |
| 420 | kfree(iobuf); |
| 421 | kfree(bbt); |
| 422 | put_mtd_device(mtd); |
| 423 | if (err) |
Vikram Narayanan | 2c70d29 | 2012-10-10 23:10:02 +0530 | [diff] [blame] | 424 | pr_info("error %d occurred\n", err); |
Artem Bityutskiy | 72069be | 2008-12-08 13:36:18 +0200 | [diff] [blame] | 425 | printk(KERN_INFO "=================================================\n"); |
| 426 | return err; |
| 427 | } |
| 428 | module_init(mtd_speedtest_init); |
| 429 | |
| 430 | static void __exit mtd_speedtest_exit(void) |
| 431 | { |
| 432 | return; |
| 433 | } |
| 434 | module_exit(mtd_speedtest_exit); |
| 435 | |
| 436 | MODULE_DESCRIPTION("Speed test module"); |
| 437 | MODULE_AUTHOR("Adrian Hunter"); |
| 438 | MODULE_LICENSE("GPL"); |