From: Jens Axboe Date: Wed, 7 Nov 2012 08:15:45 +0000 (+0100) Subject: Make the zipf/pareto state per file X-Git-Tag: fio-2.0.11~28^2 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=9c6f63166eaecc13e4b2ca1d80cc1b5e6185fd43 Make the zipf/pareto state per file Signed-off-by: Jens Axboe --- diff --git a/HOWTO b/HOWTO index a7bd1fb0..40fe65fe 100644 --- 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 075ce8c8..1f67301a 100644 --- 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 42fd58c8..38e9d0d4 100644 --- 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; diff --git a/filesetup.c b/filesetup.c index 9679c88d..ac69c65e 100644 --- a/filesetup.c +++ b/filesetup.c @@ -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 7eb0abba..1526d191 100644 --- 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 @@ -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 bf4aa030..23be8631 100644 --- 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 688249bd..551c5ffa 100644 --- 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; }