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 8ba21f8959b318939786aaa21b96e21f7485d8c5..9685c99d84ec9d1705f4f8515ec3906dd4a1c2e3 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 167bf5f62b215d470e1f41d1ee95ba75968589cd..e458457a902f4df3fc3e6642c402abf6148c7016 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 a4637bb9101ca5cdaaf905687006a714804c29f9..0d5a0efb5882cbcef8fd11739667686ea6363a8c 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 42bc7614c5dba730f9a5c8dc0a997c765e63f9f0..d7d9616e4ef00d297055032fa6e600c3f28247d2 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 d00e6e3fe44a593033670cd5f226fa07395a5698..e67149d8cd2463e3bb8b06d18a70be9476b7b6d5 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 7912212ecda47594bac999e8abbecdacaf81aeb1..745056bdc8186e54743d2fb688df926084c91853 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 15f2e06e62926a9b2353ad14353827577318be72..264243b22904f68a6181a99dd85ece446a997251 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 d143d36c0c60ed1d5d6c1bca6b1aa27bd86c9212..9a30bea4d01cf57a710ed8277b23ec336ea3c0d8 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;