Make the zipf/pareto state per file
authorJens Axboe <axboe@kernel.dk>
Wed, 7 Nov 2012 08:15:45 +0000 (09:15 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Nov 2012 08:15:45 +0000 (09:15 +0100)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
HOWTO
eta.c
file.h
filesetup.c
fio.h
init.c
io_u.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.
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/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;
 }