From: Jens Axboe Date: Wed, 6 May 2015 20:15:35 +0000 (-0600) Subject: Add support for options being a power-of-2 X-Git-Tag: fio-2.2.8~14 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=0f38bbef532ef9da0d43382dca58a20e57c63dc1;hp=92330695e64a42fd5dc54a6970a4b8122d3cd80e Add support for options being a power-of-2 Split out the is_power_of_2() from fio.h and make it independent. Signed-off-by: Jens Axboe --- diff --git a/engines/libaio.c b/engines/libaio.c index 8ba21f89..9685c99d 100644 --- a/engines/libaio.c +++ b/engines/libaio.c @@ -12,6 +12,7 @@ #include #include "../fio.h" +#include "../lib/pow2.h" static int fio_libaio_commit(struct thread_data *td); diff --git a/eta.c b/eta.c index 167bf5f6..e458457a 100644 --- a/eta.c +++ b/eta.c @@ -6,6 +6,7 @@ #include #include "fio.h" +#include "lib/pow2.h" static char __run_str[REAL_MAX_JOBS + 1]; static char run_str[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS)]; diff --git a/fio.h b/fio.h index a4637bb9..0d5a0efb 100644 --- a/fio.h +++ b/fio.h @@ -631,11 +631,6 @@ static inline unsigned int td_min_bs(struct thread_data *td) return min(td->o.min_bs[DDIR_TRIM], min_bs); } -static inline int is_power_of_2(uint64_t val) -{ - return (val != 0 && ((val & (val - 1)) == 0)); -} - static inline int td_async_processing(struct thread_data *td) { return (td->flags & TD_F_NEED_LOCK) != 0; diff --git a/gclient.c b/gclient.c index 42bc7614..d7d9616e 100644 --- a/gclient.c +++ b/gclient.c @@ -13,6 +13,7 @@ #include "graph.h" #include "gclient.h" #include "printing.h" +#include "lib/pow2.h" static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts, struct group_run_stats *rs); diff --git a/io_u.c b/io_u.c index d00e6e3f..e67149d8 100644 --- a/io_u.c +++ b/io_u.c @@ -12,6 +12,7 @@ #include "lib/rand.h" #include "lib/axmap.h" #include "err.h" +#include "lib/pow2.h" struct io_completion_data { int nr; /* input */ diff --git a/lib/pow2.h b/lib/pow2.h new file mode 100644 index 00000000..f3ca4d7b --- /dev/null +++ b/lib/pow2.h @@ -0,0 +1,11 @@ +#ifndef FIO_POW2_H +#define FIO_POW2_H + +#include + +static inline int is_power_of_2(uint64_t val) +{ + return (val != 0 && ((val & (val - 1)) == 0)); +} + +#endif diff --git a/parse.c b/parse.c index 7912212e..745056bd 100644 --- a/parse.c +++ b/parse.c @@ -17,6 +17,7 @@ #include "options.h" #include "minmax.h" #include "lib/ieee754.h" +#include "lib/pow2.h" #ifdef CONFIG_ARITHMETIC #include "y.tab.h" @@ -521,6 +522,10 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data, if (ret) break; + if (o->pow2 && !is_power_of_2(ull)) { + log_err("%s: must be a power-of-2\n", o->name); + return 1; + } if (o->maxval && ull > o->maxval) { log_err("max value out of range: %llu" diff --git a/parse.h b/parse.h index 15f2e06e..264243b2 100644 --- a/parse.h +++ b/parse.h @@ -75,6 +75,7 @@ struct fio_option { int is_seconds; /* time value with seconds base */ int is_time; /* time based value */ int no_warn_def; + int pow2; /* must be a power-of-2 */ }; typedef int (str_cb_fn)(void *, char *); diff --git a/stat.c b/stat.c index d143d36c..9a30bea4 100644 --- a/stat.c +++ b/stat.c @@ -13,6 +13,7 @@ #include "json.h" #include "lib/getrusage.h" #include "idletime.h" +#include "lib/pow2.h" struct fio_mutex *stat_mutex;