Makes it 3x faster here.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
rbtree.o diskutil.o fifo.o blktrace.o smalloc.o filehash.o helpers.o \
cgroup.o profile.o debug.o
+OBJS += lib/rand.o
+
OBJS += crc/crc7.o
OBJS += crc/crc16.o
OBJS += crc/crc32.o
eta.o verify.o memory.o io_u.o parse.o mutex.o options.o \
rbtree.o smalloc.o filehash.o helpers.o profile.o debug.o
+OBJS += lib/rand.o
+
OBJS += crc/crc7.o
OBJS += crc/crc16.o
OBJS += crc/crc32.o
eta.o verify.o memory.o io_u.o parse.o mutex.o options.o \
rbtree.o smalloc.o filehash.o helpers.o profile.o debug.o
+OBJS += lib/rand.o
+
OBJS += crc/crc7.o
OBJS += crc/crc16.o
OBJS += crc/crc32.o
rbtree.o fifo.o smalloc.o filehash.o lib/strsep.o helpers.o solaris.o \
profile.o debug.o
+OBJS += lib/rand.o
+
OBJS += crc/crc7.o
OBJS += crc/crc16.o
OBJS += crc/crc32.o
#include "fio.h"
#include "hash.h"
#include "verify.h"
+#include "lib/rand.h"
struct io_completion_data {
int nr; /* input */
if (!td->o.zero_buffers) {
while ((void *) ptr - io_u->buf < max_bs) {
- *ptr = rand() * GOLDEN_RATIO_PRIME;
+ *ptr = __rand(&__fio_rand_state);
ptr++;
}
} else
--- /dev/null
+#include "rand.h"
+
+struct frand_state __fio_rand_state;
+
+static inline int __seed(unsigned int x, unsigned int m)
+{
+ return (x < m) ? x + m : x;
+}
+
+void init_rand(struct frand_state *state)
+{
+#define LCG(x) ((x) * 69069) /* super-duper LCG */
+
+ state->s1 = __seed(LCG((2^31) + (2^17) + (2^7)), 1);
+ state->s2 = __seed(LCG(state->s1), 7);
+ state->s3 = __seed(LCG(state->s2), 15);
+
+ __rand(state);
+ __rand(state);
+ __rand(state);
+ __rand(state);
+ __rand(state);
+ __rand(state);
+}
--- /dev/null
+#ifndef FIO_RAND_H
+#define FIO_RAND_H
+
+struct frand_state {
+ unsigned int s1, s2, s3;
+};
+
+extern struct frand_state __fio_rand_state;
+
+static inline unsigned int __rand(struct frand_state *state)
+{
+#define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
+
+ state->s1 = TAUSWORTHE(state->s1, 13, 19, 4294967294UL, 12);
+ state->s2 = TAUSWORTHE(state->s2, 2, 25, 4294967288UL, 4);
+ state->s3 = TAUSWORTHE(state->s3, 3, 11, 4294967280UL, 17);
+
+ return (state->s1 ^ state->s2 ^ state->s3);
+}
+
+extern void init_rand(struct frand_state *);
+
+#endif