Merge branch 'master' of ssh://brick.kernel.dk/data/git/fio
authorJens Axboe <axboe@kernel.dk>
Wed, 7 Nov 2012 12:39:18 +0000 (13:39 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Nov 2012 12:39:18 +0000 (13:39 +0100)
14 files changed:
HOWTO
Makefile
eta.c
file.h
filesetup.c
fio.h
gettime-thread.c [new file with mode: 0644]
gettime.c
gettime.h
init.c
io_u.c
t/ieee754.c
t/stest.c
time.c

diff --git a/HOWTO b/HOWTO
index a7bd1fb07da4a9ad872e054958ee39514fadc0dc..40fe65fe9bc6d65cfc14cbe2e5565189fee2ae9d 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1385,7 +1385,7 @@ Idle      Run
 ----    ---
 P              Thread setup, but not started.
 C              Thread created.
-I              Thread initialized, waiting.
+I              Thread initialized, waiting or generating necessary data.
        p       Thread running pre-reading file(s).
        R       Running, doing sequential reads.
        r       Running, doing random reads.
index f0f3ea0f00c03050cfb1435ecda14ef33e227f25..f59f809616e73b73a1d132f9e2fc318ab5b75347 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ SOURCE := gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
                lib/num2str.c lib/ieee754.c $(wildcard crc/*.c) engines/cpu.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
                memalign.c server.c client.c iolog.c backend.c libfio.c flow.c \
-               json.c lib/zipf.c
+               json.c lib/zipf.c gettime-thread.c
 
 ifeq ($(UNAME), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c helpers.c cgroup.c trim.c \
@@ -69,11 +69,11 @@ endif
 OBJS = $(SOURCE:.c=.o)
 
 T_SMALLOC_OBJS = t/stest.o
-T_SMALLOC_OBJS += mutex.o smalloc.o t/log.o
+T_SMALLOC_OBJS += gettime.o mutex.o smalloc.o t/log.o
 T_SMALLOC_PROGS = t/stest
 
 T_IEEE_OBJS = t/ieee754.o
-T_IEEE_OBJS += ieee754.o
+T_IEEE_OBJS += lib/ieee754.o
 T_IEEE_PROGS = t/ieee754
 
 T_ZIPF_OBS = t/genzipf.o
diff --git a/eta.c b/eta.c
index 075ce8c81a010b1e57e0a7d31d5c8f7259b69a47..1f67301a902124e6b922ca980bc5796928525eb3 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -78,6 +78,7 @@ static void check_str_update(struct thread_data *td)
                c = 'C';
                break;
        case TD_INITIALIZED:
+       case TD_SETTING_UP:
                c = 'I';
                break;
        case TD_NOT_CREATED:
@@ -318,7 +319,9 @@ int calc_thread_status(struct jobs_eta *je, int force)
                } else if (td->runstate == TD_RAMP) {
                        je->nr_running++;
                        je->nr_ramp++;
-               } else if (td->runstate < TD_RUNNING)
+               } else if (td->runstate == TD_SETTING_UP)
+                       je->nr_running++;
+               else if (td->runstate < TD_RUNNING)
                        je->nr_pending++;
 
                if (je->elapsed_sec >= 3)
diff --git a/file.h b/file.h
index 42fd58c8d09bb3dd66e4b3d02694282db771c19b..38e9d0d43003c466ae13defebea219db8057b7c1 100644 (file)
--- a/file.h
+++ b/file.h
@@ -5,6 +5,7 @@
 #include "compiler/compiler.h"
 #include "io_ddir.h"
 #include "flist.h"
+#include "lib/zipf.h"
 
 /*
  * The type of object we are working on
@@ -112,6 +113,11 @@ struct fio_file {
        unsigned long last_free_lookup;
        unsigned failed_rands;
 
+       /*
+        * Used for zipf random distribution
+        */
+       struct zipf_state zipf;
+
        int references;
        enum fio_file_flags flags;
 
index 9679c88d28245f287d64f13092a72631f7121fca..ac69c65ea8f44956debb01bca32bef41c2675fb2 100644 (file)
@@ -862,12 +862,49 @@ int pre_read_files(struct thread_data *td)
        return 1;
 }
 
+static int __init_rand_distribution(struct thread_data *td, struct fio_file *f)
+{
+       unsigned int range_size;
+       unsigned long nranges;
+
+       range_size = min(td->o.min_bs[DDIR_READ], td->o.min_bs[DDIR_WRITE]);
+
+       nranges = (f->real_file_size + range_size - 1) / range_size;
+
+       if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
+               zipf_init(&f->zipf, nranges, td->o.zipf_theta);
+       else
+               pareto_init(&f->zipf, nranges, td->o.pareto_h);
+
+       return 1;
+}
+
+static int init_rand_distribution(struct thread_data *td)
+{
+       struct fio_file *f;
+       unsigned int i;
+       int state;
+
+       if (td->o.random_distribution == FIO_RAND_DIST_RANDOM)
+               return 0;
+
+       state = td->runstate;
+       td_set_runstate(td, TD_SETTING_UP);
+       for_each_file(td, f, i)
+               __init_rand_distribution(td, f);
+       td_set_runstate(td, state);
+
+       return 1;
+}
+
 int init_random_map(struct thread_data *td)
 {
        unsigned long long blocks, num_maps;
        struct fio_file *f;
        unsigned int i;
 
+       if (init_rand_distribution(td))
+               return 0;
        if (td->o.norandommap || !td_random(td))
                return 0;
 
diff --git a/fio.h b/fio.h
index 7eb0abba0fa5572222e08a3caa7db63198bc0a98..1526d191a6eab03911696c2e7c45aab566be2385 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -39,7 +39,6 @@ struct thread_data;
 #include "server.h"
 #include "stat.h"
 #include "flow.h"
-#include "lib/zipf.h"
 
 #ifdef FIO_HAVE_GUASI
 #include <guasi.h>
@@ -457,11 +456,6 @@ struct thread_data {
                struct frand_state __random_state;
        };
 
-       /*
-        * Used for zipf random distribution
-        */
-       struct zipf_state zipf;
-
        struct timeval start;   /* start of this loop */
        struct timeval epoch;   /* time job was started */
        struct timeval last_issue;
@@ -691,6 +685,7 @@ enum {
        TD_NOT_CREATED = 0,
        TD_CREATED,
        TD_INITIALIZED,
+       TD_SETTING_UP,
        TD_RAMP,
        TD_RUNNING,
        TD_PRE_READING,
diff --git a/gettime-thread.c b/gettime-thread.c
new file mode 100644 (file)
index 0000000..da40904
--- /dev/null
@@ -0,0 +1,78 @@
+#include <unistd.h>
+#include <math.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include "fio.h"
+#include "smalloc.h"
+
+struct timeval *fio_tv;
+int fio_gtod_offload = 0;
+int fio_gtod_cpu = -1;
+static pthread_t gtod_thread;
+
+void fio_gtod_init(void)
+{
+       fio_tv = smalloc(sizeof(struct timeval));
+       assert(fio_tv);
+}
+
+static void fio_gtod_update(void)
+{
+       gettimeofday(fio_tv, NULL);
+}
+
+static void *gtod_thread_main(void *data)
+{
+       struct fio_mutex *mutex = data;
+
+       fio_mutex_up(mutex);
+
+       /*
+        * As long as we have jobs around, update the clock. It would be nice
+        * to have some way of NOT hammering that CPU with gettimeofday(),
+        * but I'm not sure what to use outside of a simple CPU nop to relax
+        * it - we don't want to lose precision.
+        */
+       while (threads) {
+               fio_gtod_update();
+               nop;
+       }
+
+       return NULL;
+}
+
+int fio_start_gtod_thread(void)
+{
+       struct fio_mutex *mutex;
+       pthread_attr_t attr;
+       int ret;
+
+       mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
+       if (!mutex)
+               return 1;
+
+       pthread_attr_init(&attr);
+       pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
+       ret = pthread_create(&gtod_thread, &attr, gtod_thread_main, NULL);
+       pthread_attr_destroy(&attr);
+       if (ret) {
+               log_err("Can't create gtod thread: %s\n", strerror(ret));
+               goto err;
+       }
+
+       ret = pthread_detach(gtod_thread);
+       if (ret) {
+               log_err("Can't detatch gtod thread: %s\n", strerror(ret));
+               goto err;
+       }
+
+       dprint(FD_MUTEX, "wait on startup_mutex\n");
+       fio_mutex_down(mutex);
+       dprint(FD_MUTEX, "done waiting on startup_mutex\n");
+err:
+       fio_mutex_remove(mutex);
+       return ret;
+}
+
+
index 5b4928758b47f83c729082e399820ae2edc09a26..35d685e1576149974d5e77f18db2b1fb180f3a9e 100644 (file)
--- a/gettime.c
+++ b/gettime.c
@@ -19,11 +19,6 @@ static unsigned long last_cycles;
 static struct timeval last_tv;
 static int last_tv_valid;
 
-static struct timeval *fio_tv;
-int fio_gtod_offload = 0;
-int fio_gtod_cpu = -1;
-static pthread_t gtod_thread;
-
 enum fio_cs fio_clock_source = FIO_PREFERRED_CLOCK_SOURCE;
 
 #ifdef FIO_DEBUG_TIME
@@ -267,66 +262,68 @@ void fio_clock_init(void)
        calibrate_cpu_clock();
 }
 
-void fio_gtod_init(void)
+unsigned long long utime_since(struct timeval *s, struct timeval *e)
 {
-       fio_tv = smalloc(sizeof(struct timeval));
-       assert(fio_tv);
+       long sec, usec;
+       unsigned long long ret;
+
+       sec = e->tv_sec - s->tv_sec;
+       usec = e->tv_usec - s->tv_usec;
+       if (sec > 0 && usec < 0) {
+               sec--;
+               usec += 1000000;
+       }
+
+       /*
+        * time warp bug on some kernels?
+        */
+       if (sec < 0 || (sec == 0 && usec < 0))
+               return 0;
+
+       ret = sec * 1000000ULL + usec;
+
+       return ret;
 }
 
-static void fio_gtod_update(void)
+unsigned long long utime_since_now(struct timeval *s)
 {
-       gettimeofday(fio_tv, NULL);
+       struct timeval t;
+
+       fio_gettime(&t, NULL);
+       return utime_since(s, &t);
 }
 
-static void *gtod_thread_main(void *data)
+unsigned long mtime_since(struct timeval *s, struct timeval *e)
 {
-       struct fio_mutex *mutex = data;
+       long sec, usec, ret;
 
-       fio_mutex_up(mutex);
-
-       /*
-        * As long as we have jobs around, update the clock. It would be nice
-        * to have some way of NOT hammering that CPU with gettimeofday(),
-        * but I'm not sure what to use outside of a simple CPU nop to relax
-        * it - we don't want to lose precision.
-        */
-       while (threads) {
-               fio_gtod_update();
-               nop;
+       sec = e->tv_sec - s->tv_sec;
+       usec = e->tv_usec - s->tv_usec;
+       if (sec > 0 && usec < 0) {
+               sec--;
+               usec += 1000000;
        }
 
-       return NULL;
+       if (sec < 0 || (sec == 0 && usec < 0))
+               return 0;
+
+       sec *= 1000UL;
+       usec /= 1000UL;
+       ret = sec + usec;
+
+       return ret;
 }
 
-int fio_start_gtod_thread(void)
+unsigned long mtime_since_now(struct timeval *s)
 {
-       struct fio_mutex *mutex;
-       pthread_attr_t attr;
-       int ret;
-
-       mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
-       if (!mutex)
-               return 1;
-
-       pthread_attr_init(&attr);
-       pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
-       ret = pthread_create(&gtod_thread, &attr, gtod_thread_main, NULL);
-       pthread_attr_destroy(&attr);
-       if (ret) {
-               log_err("Can't create gtod thread: %s\n", strerror(ret));
-               goto err;
-       }
+       struct timeval t;
+       void *p = __builtin_return_address(0);
 
-       ret = pthread_detach(gtod_thread);
-       if (ret) {
-               log_err("Can't detatch gtod thread: %s\n", strerror(ret));
-               goto err;
-       }
+       fio_gettime(&t, p);
+       return mtime_since(s, &t);
+}
 
-       dprint(FD_MUTEX, "wait on startup_mutex\n");
-       fio_mutex_down(mutex);
-       dprint(FD_MUTEX, "done waiting on startup_mutex\n");
-err:
-       fio_mutex_remove(mutex);
-       return ret;
+unsigned long time_since_now(struct timeval *s)
+{
+       return mtime_since_now(s) / 1000;
 }
index 87cc895492a5f2ac75809f5e6e1bfedb972a21c3..309ef2108a646e764b9e3e120cfecd7d8e9cf802 100644 (file)
--- a/gettime.h
+++ b/gettime.h
@@ -15,4 +15,6 @@ extern void fio_gtod_init(void);
 extern void fio_clock_init(void);
 extern int fio_start_gtod_thread(void);
 
+extern struct timeval *fio_tv;
+
 #endif
diff --git a/init.c b/init.c
index bf4aa03041435a038bd6fd72b636cab10ddd4c9a..23be863141a3ff670d84780eccb52b924ab0cb66 100644 (file)
--- a/init.c
+++ b/init.c
@@ -382,24 +382,6 @@ static int fixed_block_size(struct thread_options *o)
                o->min_bs[DDIR_READ] == o->min_bs[DDIR_TRIM];
 }
 
-static void init_rand_distribution(struct thread_data *td)
-{
-       unsigned int range_size;
-       unsigned long nranges;
-
-       if (td->o.random_distribution == FIO_RAND_DIST_RANDOM)
-               return;
-
-       range_size = min(td->o.min_bs[DDIR_READ], td->o.min_bs[DDIR_WRITE]);
-
-       nranges = (td->o.size + range_size - 1) / range_size;
-
-       if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
-               zipf_init(&td->zipf, nranges, td->o.zipf_theta);
-       else
-               pareto_init(&td->zipf, nranges, td->o.pareto_h);
-}
-
 /*
  * Lazy way of fixing up options that depend on each other. We could also
  * define option callback handlers, but this is easier.
@@ -610,8 +592,6 @@ static int fixup_options(struct thread_data *td)
                td->o.compress_percentage = 0;
        }
 
-       init_rand_distribution(td);
-
        return ret;
 }
 
diff --git a/io_u.c b/io_u.c
index 688249bd8a727e7910d72388a829f7249b5ee059..551c5ffa3158859783d4475ab82c7c837b63cac5 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -238,7 +238,7 @@ static int __get_next_rand_offset_zipf(struct thread_data *td,
                                       struct fio_file *f, enum fio_ddir ddir,
                                       unsigned long long *b)
 {
-       *b = zipf_next(&td->zipf);
+       *b = zipf_next(&f->zipf);
        return 0;
 }
 
@@ -246,7 +246,7 @@ static int __get_next_rand_offset_pareto(struct thread_data *td,
                                         struct fio_file *f, enum fio_ddir ddir,
                                         unsigned long long *b)
 {
-       *b = pareto_next(&td->zipf);
+       *b = pareto_next(&f->zipf);
        return 0;
 }
 
index afc25f3cf0122336bac03330e45a14b5b24c72b8..3898ab74c1afe5b65834c3500bda72d730d20df3 100644 (file)
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include "../ieee754.h"
+#include "../lib/ieee754.h"
 
 static double values[] = { -17.23, 17.23, 123.4567, 98765.4321, 0.0 };
 
index c1794843948392ba1ed1c48f08c2ac0519fcb1b1..0da8f2cf8670aad2cef31de9b0abedd5e86f1f93 100644 (file)
--- a/t/stest.c
+++ b/t/stest.c
@@ -6,6 +6,8 @@
 #include "../flist.h"
 
 FILE *f_err;
+struct timeval *fio_tv = NULL;
+unsigned int fio_debug = 0;
 
 #define MAGIC1 0xa9b1c8d2
 #define MAGIC2 0xf0a1e9b3
@@ -82,3 +84,7 @@ int main(int argc, char *argv[])
        scleanup();
        return 0;
 }
+
+void __dprint(int type, const char *str, ...)
+{
+}
diff --git a/time.c b/time.c
index 4af84bc7cc5b6a2e1f0be57f284e3e6c3d57f2c8..c4d1d4c7c6ee5da1cac47011d0ccd86a1ae1e78a 100644 (file)
--- a/time.c
+++ b/time.c
@@ -6,72 +6,6 @@
 static struct timeval genesis;
 static unsigned long ns_granularity;
 
-unsigned long long utime_since(struct timeval *s, struct timeval *e)
-{
-       long sec, usec;
-       unsigned long long ret;
-
-       sec = e->tv_sec - s->tv_sec;
-       usec = e->tv_usec - s->tv_usec;
-       if (sec > 0 && usec < 0) {
-               sec--;
-               usec += 1000000;
-       }
-
-       /*
-        * time warp bug on some kernels?
-        */
-       if (sec < 0 || (sec == 0 && usec < 0))
-               return 0;
-
-       ret = sec * 1000000ULL + usec;
-
-       return ret;
-}
-
-unsigned long long utime_since_now(struct timeval *s)
-{
-       struct timeval t;
-
-       fio_gettime(&t, NULL);
-       return utime_since(s, &t);
-}
-
-unsigned long mtime_since(struct timeval *s, struct timeval *e)
-{
-       long sec, usec, ret;
-
-       sec = e->tv_sec - s->tv_sec;
-       usec = e->tv_usec - s->tv_usec;
-       if (sec > 0 && usec < 0) {
-               sec--;
-               usec += 1000000;
-       }
-
-       if (sec < 0 || (sec == 0 && usec < 0))
-               return 0;
-
-       sec *= 1000UL;
-       usec /= 1000UL;
-       ret = sec + usec;
-
-       return ret;
-}
-
-unsigned long mtime_since_now(struct timeval *s)
-{
-       struct timeval t;
-       void *p = __builtin_return_address(0);
-
-       fio_gettime(&t, p);
-       return mtime_since(s, &t);
-}
-
-unsigned long time_since_now(struct timeval *s)
-{
-       return mtime_since_now(s) / 1000;
-}
-
 /*
  * busy looping version for the last few usec
  */