diff options
author | Jens Axboe <jens.axboe@oracle.com> | 2008-06-04 20:13:04 +0200 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2008-06-04 20:13:04 +0200 |
commit | dc873b6f4a536c332b72cce268d5a7ccd356a891 (patch) | |
tree | ba42b3db0ebbcffad2c90afe194edd159f953632 | |
parent | da28353c3fb45a8a6ee00d1133efd483c0ae684c (diff) | |
download | fio-dc873b6f4a536c332b72cce268d5a7ccd356a891.tar.gz fio-dc873b6f4a536c332b72cce268d5a7ccd356a891.tar.bz2 |
Add OS agnostic RAND_MAX
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r-- | filesetup.c | 6 | ||||
-rw-r--r-- | io_u.c | 11 | ||||
-rw-r--r-- | os/os-freebsd.h | 2 | ||||
-rw-r--r-- | os/os-linux.h | 2 | ||||
-rw-r--r-- | os/os-solaris.h | 3 | ||||
-rw-r--r-- | 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; @@ -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]; @@ -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 |