Add support for options being a power-of-2
authorJens Axboe <axboe@fb.com>
Wed, 6 May 2015 20:15:35 +0000 (14:15 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 6 May 2015 20:15:35 +0000 (14:15 -0600)
Split out the is_power_of_2() from fio.h and make it independent.

Signed-off-by: Jens Axboe <axboe@fb.com>
engines/libaio.c
eta.c
fio.h
gclient.c
io_u.c
lib/pow2.h [new file with mode: 0644]
parse.c
parse.h
stat.c

index 8ba21f8..9685c99 100644 (file)
@@ -12,6 +12,7 @@
 #include <libaio.h>
 
 #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 167bf5f..e458457 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #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 a4637bb..0d5a0ef 100644 (file)
--- 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;
index 42bc761..d7d9616 100644 (file)
--- 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 d00e6e3..e67149d 100644 (file)
--- 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 (file)
index 0000000..f3ca4d7
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef FIO_POW2_H
+#define FIO_POW2_H
+
+#include <inttypes.h>
+
+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 7912212..745056b 100644 (file)
--- 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 15f2e06..264243b 100644 (file)
--- 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 d143d36..9a30bea 100644 (file)
--- 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;