mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-01-12 12:22:42 +00:00
mtd: tests: use random32 instead of home-brewed generator
This is a clean-up patch which removes the own pseudo-random numbers generator from the speed- and stress-tests and makes them use the 'random32()' generator instead. [dwmw2: Merge later fix for negative offsets] Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
This commit is contained in:
parent
3166df0d04
commit
bfea1d4ee5
@ -26,6 +26,7 @@
|
|||||||
#include <linux/mtd/mtd.h>
|
#include <linux/mtd/mtd.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
|
#include <linux/random.h>
|
||||||
|
|
||||||
#define PRINT_PREF KERN_INFO "mtd_speedtest: "
|
#define PRINT_PREF KERN_INFO "mtd_speedtest: "
|
||||||
|
|
||||||
@ -47,25 +48,13 @@ static int ebcnt;
|
|||||||
static int pgcnt;
|
static int pgcnt;
|
||||||
static int goodebcnt;
|
static int goodebcnt;
|
||||||
static struct timeval start, finish;
|
static struct timeval start, finish;
|
||||||
static unsigned long next = 1;
|
|
||||||
|
|
||||||
static inline unsigned int simple_rand(void)
|
|
||||||
{
|
|
||||||
next = next * 1103515245 + 12345;
|
|
||||||
return (unsigned int)((next / 65536) % 32768);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void simple_srand(unsigned long seed)
|
|
||||||
{
|
|
||||||
next = seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_random_data(unsigned char *buf, size_t len)
|
static void set_random_data(unsigned char *buf, size_t len)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < len; ++i)
|
for (i = 0; i < len; ++i)
|
||||||
buf[i] = simple_rand();
|
buf[i] = random32();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int erase_eraseblock(int ebnum)
|
static int erase_eraseblock(int ebnum)
|
||||||
@ -407,7 +396,6 @@ static int __init mtd_speedtest_init(void)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
simple_srand(1);
|
|
||||||
set_random_data(iobuf, mtd->erasesize);
|
set_random_data(iobuf, mtd->erasesize);
|
||||||
|
|
||||||
err = scan_for_bad_eraseblocks();
|
err = scan_for_bad_eraseblocks();
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/vmalloc.h>
|
#include <linux/vmalloc.h>
|
||||||
|
#include <linux/random.h>
|
||||||
|
|
||||||
#define PRINT_PREF KERN_INFO "mtd_stresstest: "
|
#define PRINT_PREF KERN_INFO "mtd_stresstest: "
|
||||||
|
|
||||||
@ -48,28 +49,13 @@ static int pgsize;
|
|||||||
static int bufsize;
|
static int bufsize;
|
||||||
static int ebcnt;
|
static int ebcnt;
|
||||||
static int pgcnt;
|
static int pgcnt;
|
||||||
static unsigned long next = 1;
|
|
||||||
|
|
||||||
static inline unsigned int simple_rand(void)
|
|
||||||
{
|
|
||||||
next = next * 1103515245 + 12345;
|
|
||||||
return (unsigned int)((next / 65536) % 32768);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void simple_srand(unsigned long seed)
|
|
||||||
{
|
|
||||||
next = seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rand_eb(void)
|
static int rand_eb(void)
|
||||||
{
|
{
|
||||||
int eb;
|
unsigned int eb;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
if (ebcnt < 32768)
|
eb = random32();
|
||||||
eb = simple_rand();
|
|
||||||
else
|
|
||||||
eb = (simple_rand() << 15) | simple_rand();
|
|
||||||
/* Read or write up 2 eraseblocks at a time - hence 'ebcnt - 1' */
|
/* Read or write up 2 eraseblocks at a time - hence 'ebcnt - 1' */
|
||||||
eb %= (ebcnt - 1);
|
eb %= (ebcnt - 1);
|
||||||
if (bbt[eb])
|
if (bbt[eb])
|
||||||
@ -79,24 +65,18 @@ again:
|
|||||||
|
|
||||||
static int rand_offs(void)
|
static int rand_offs(void)
|
||||||
{
|
{
|
||||||
int offs;
|
unsigned int offs;
|
||||||
|
|
||||||
if (bufsize < 32768)
|
offs = random32();
|
||||||
offs = simple_rand();
|
|
||||||
else
|
|
||||||
offs = (simple_rand() << 15) | simple_rand();
|
|
||||||
offs %= bufsize;
|
offs %= bufsize;
|
||||||
return offs;
|
return offs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rand_len(int offs)
|
static int rand_len(int offs)
|
||||||
{
|
{
|
||||||
int len;
|
unsigned int len;
|
||||||
|
|
||||||
if (bufsize < 32768)
|
len = random32();
|
||||||
len = simple_rand();
|
|
||||||
else
|
|
||||||
len = (simple_rand() << 15) | simple_rand();
|
|
||||||
len %= (bufsize - offs);
|
len %= (bufsize - offs);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
@ -211,7 +191,7 @@ static int do_write(void)
|
|||||||
|
|
||||||
static int do_operation(void)
|
static int do_operation(void)
|
||||||
{
|
{
|
||||||
if (simple_rand() & 1)
|
if (random32() & 1)
|
||||||
return do_read();
|
return do_read();
|
||||||
else
|
else
|
||||||
return do_write();
|
return do_write();
|
||||||
@ -302,9 +282,8 @@ static int __init mtd_stresstest_init(void)
|
|||||||
}
|
}
|
||||||
for (i = 0; i < ebcnt; i++)
|
for (i = 0; i < ebcnt; i++)
|
||||||
offsets[i] = mtd->erasesize;
|
offsets[i] = mtd->erasesize;
|
||||||
simple_srand(current->pid);
|
|
||||||
for (i = 0; i < bufsize; i++)
|
for (i = 0; i < bufsize; i++)
|
||||||
writebuf[i] = simple_rand();
|
writebuf[i] = random32();
|
||||||
|
|
||||||
err = scan_for_bad_eraseblocks();
|
err = scan_for_bad_eraseblocks();
|
||||||
if (err)
|
if (err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user