From: Jens Axboe Date: Tue, 15 Dec 2009 09:28:37 +0000 (+0100) Subject: Add generic random helpers X-Git-Tag: fio-1.37~15 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=535313705d69dc16f27ca38acf2f9bf7205e410d;p=fio.git Add generic random helpers FreeBSD and OSX can both use these. Signed-off-by: Jens Axboe --- diff --git a/os/os-freebsd.h b/os/os-freebsd.h index f4c5e235..8d965aad 100644 --- a/os/os-freebsd.h +++ b/os/os-freebsd.h @@ -7,11 +7,11 @@ #define FIO_HAVE_POSIXAIO #define FIO_HAVE_ODIRECT #define FIO_USE_GENERIC_BDEV_SIZE +#define FIO_USE_GENERIC_RAND #define OS_MAP_ANON MAP_ANON typedef unsigned long os_cpu_mask_t; -typedef unsigned int os_random_state_t; static inline int blockdev_invalidate_cache(int fd) { @@ -28,19 +28,6 @@ static inline unsigned long long os_phys_mem(void) return mem; } -static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) -{ - srand(seed); -} - -static inline long os_random_long(os_random_state_t *rs) -{ - long val; - - val = rand_r(rs); - return val; -} - #ifdef MADV_FREE #define FIO_MADV_FREE MADV_FREE #endif diff --git a/os/os-mac.h b/os/os-mac.h index 77c21656..1c3798bf 100644 --- a/os/os-mac.h +++ b/os/os-mac.h @@ -14,11 +14,11 @@ #define FIO_HAVE_POSIXAIO #define FIO_USE_GENERIC_BDEV_SIZE +#define FIO_USE_GENERIC_RAND #define OS_MAP_ANON MAP_ANON typedef unsigned long os_cpu_mask_t; -typedef unsigned int os_random_state_t; typedef unsigned int clockid_t; static inline int blockdev_invalidate_cache(int fd) @@ -35,18 +35,4 @@ static inline unsigned long long os_phys_mem(void) sysctl(mib, 2, &mem, &len, NULL, 0); return mem; } - -static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) -{ - srand(seed); -} - -static inline long os_random_long(os_random_state_t *rs) -{ - long val; - - val = rand_r(rs); - return val; -} - #endif diff --git a/os/os.h b/os/os.h index a14c4857..9a48c603 100644 --- a/os/os.h +++ b/os/os.h @@ -124,4 +124,21 @@ static inline int blockdev_size(int fd, unsigned long long *bytes) } #endif +#ifdef FIO_USE_GENERIC_RAND +typedef unsigned int os_random_state_t; + +static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) +{ + srand(seed); +} + +static inline long os_random_long(os_random_state_t *rs) +{ + long val; + + val = rand_r(rs); + return val; +} +#endif + #endif