From dc873b6f4a536c332b72cce268d5a7ccd356a891 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 4 Jun 2008 20:13:04 +0200 Subject: [PATCH] Add OS agnostic RAND_MAX Signed-off-by: Jens Axboe --- filesetup.c | 6 +++--- io_u.c | 11 ++++++----- os/os-freebsd.h | 2 +- os/os-linux.h | 2 +- os/os-solaris.h | 3 ++- os/os.h | 4 ++++ 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/filesetup.c b/filesetup.c index 0b297641..96d1b54f 100644 --- a/filesetup.c +++ b/filesetup.c @@ -121,12 +121,12 @@ err: static unsigned long long get_rand_file_size(struct thread_data *td) { - unsigned long long ret, size_d; + unsigned long long ret, sized; long r; r = os_random_long(&td->file_size_state); - size_d = td->o.file_size_high - td->o.file_size_low; - ret = (unsigned long long) ((double) size_d * (r / (RAND_MAX + 1.0))); + sized = td->o.file_size_high - td->o.file_size_low; + ret = (unsigned long long) ((double) sized * (r / (OS_RAND_MAX + 1.0))); ret += td->o.file_size_low; ret -= (ret % td->o.rw_min_bs); return ret; diff --git a/io_u.c b/io_u.c index 74c3295b..3f713671 100644 --- a/io_u.c +++ b/io_u.c @@ -146,7 +146,7 @@ static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, r = os_random_long(&td->random_state); dprint(FD_RANDOM, "off rand %llu\n", r); *b = (last_block(td, f, ddir) - 1) - * (r / ((unsigned long long) RAND_MAX + 1.0)); + * (r / ((unsigned long long) OS_RAND_MAX + 1.0)); /* * if we are not maintaining a random map, we are done. @@ -171,7 +171,8 @@ static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, */ loops = 10; do { - f->last_free_lookup = (f->num_maps - 1) * (r / (RAND_MAX+1.0)); + f->last_free_lookup = (f->num_maps - 1) * + (r / (OS_RAND_MAX + 1.0)); if (!get_next_free_block(td, f, ddir, b)) return 0; @@ -240,7 +241,7 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u) if (!td->o.bssplit_nr) { buflen = (unsigned int) (1 + (double) (td->o.max_bs[ddir] - 1) - * r / (RAND_MAX + 1.0)); + * r / (OS_RAND_MAX + 1.0)); } else { long perc = 0; unsigned int i; @@ -288,7 +289,7 @@ static inline enum fio_ddir get_rand_ddir(struct thread_data *td) long r; r = os_random_long(&td->rwmix_state); - v = 1 + (int) (100.0 * (r / (RAND_MAX + 1.0))); + v = 1 + (int) (100.0 * (r / (OS_RAND_MAX + 1.0))); if (v <= td->o.rwmix[DDIR_READ]) return DDIR_READ; @@ -620,7 +621,7 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, int goodf, long r = os_random_long(&td->next_file_state); fno = (unsigned int) ((double) td->o.nr_files - * (r / (RAND_MAX + 1.0))); + * (r / (OS_RAND_MAX + 1.0))); f = td->files[fno]; if (f->flags & FIO_FILE_DONE) continue; diff --git a/os/os-freebsd.h b/os/os-freebsd.h index af5fc9f6..614296a4 100644 --- a/os/os-freebsd.h +++ b/os/os-freebsd.h @@ -6,7 +6,7 @@ #define FIO_HAVE_POSIXAIO #define FIO_HAVE_ODIRECT -#define OS_MAP_ANON (MAP_ANON) +#define OS_MAP_ANON MAP_ANON typedef unsigned long os_cpu_mask_t; typedef unsigned int os_random_state_t; diff --git a/os/os-linux.h b/os/os-linux.h index a07db06b..72950c0e 100644 --- a/os/os-linux.h +++ b/os/os-linux.h @@ -29,7 +29,7 @@ #define FIO_HAVE_FALLOCATE #define FIO_HAVE_POSIXAIO_FSYNC -#define OS_MAP_ANON (MAP_ANONYMOUS) +#define OS_MAP_ANON MAP_ANONYMOUS #ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC 1 diff --git a/os/os-solaris.h b/os/os-solaris.h index 9e243e8a..759f3c1b 100644 --- a/os/os-solaris.h +++ b/os/os-solaris.h @@ -9,7 +9,8 @@ #define FIO_HAVE_FALLOCATE #define FIO_HAVE_POSIXAIO_FSYNC -#define OS_MAP_ANON (MAP_ANON) +#define OS_MAP_ANON MAP_ANON +#define OS_RAND_MAX 2147483648UL struct solaris_rand_seed { unsigned short r[3]; diff --git a/os/os.h b/os/os.h index 2dfed5e2..1cff4945 100644 --- a/os/os.h +++ b/os/os.h @@ -68,6 +68,10 @@ #define FIO_O_NOATIME 0 #endif +#ifndef OS_RAND_MAX +#define OS_RAND_MAX RAND_MAX +#endif + #ifndef FIO_HAVE_RAWBIND #define fio_lookup_raw(dev, majdev, mindev) 1 #endif -- 2.25.1