A few more kb_base fixups
authorJens Axboe <jens.axboe@oracle.com>
Sat, 18 Jul 2009 19:04:09 +0000 (21:04 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Sat, 18 Jul 2009 19:04:09 +0000 (21:04 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
eta.c
options.c
parse.c
parse.h

diff --git a/eta.c b/eta.c
index 6629c29d1c8591fee2a4d1671da0eac8d6f69a58..8dbff985cac272795038a53d21ff14037fd6e825 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -232,6 +232,7 @@ void print_thread_status(void)
        static unsigned int rate[2], iops[2];
        static int linelen_last;
        static int eta_good;
+       int i2p = 0;
 
        if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER)
                return;
@@ -292,6 +293,8 @@ void print_thread_status(void)
                eta_sec = 0;
 
        for_each_td(td, i) {
+               if (!i2p && is_power_of_2(td->o.kb_base))
+                       i2p = 1;
                if (exitall_on_terminate) {
                        if (eta_secs[i] < eta_sec)
                                eta_sec = eta_secs[i];
@@ -334,8 +337,8 @@ void print_thread_status(void)
        if (m_rate || t_rate) {
                char *tr, *mr;
 
-               mr = num2str(m_rate, 4, 0, 1);
-               tr = num2str(t_rate, 4, 0, 1);
+               mr = num2str(m_rate, 4, 0, i2p);
+               tr = num2str(t_rate, 4, 0, i2p);
                printf(", CR=%s/%s KB/s", tr, mr);
                free(tr);
                free(mr);
@@ -355,8 +358,8 @@ void print_thread_status(void)
                        sprintf(perc_str, "%3.1f%% done", perc);
                }
 
-               rate_str[0] = num2str(rate[0], 5, 10, 1);
-               rate_str[1] = num2str(rate[1], 5, 10, 1);
+               rate_str[0] = num2str(rate[0], 5, 10, i2p);
+               rate_str[1] = num2str(rate[1], 5, 10, i2p);
 
                iops_str[0] = num2str(iops[0], 4, 1, 0);
                iops_str[1] = num2str(iops[1], 4, 1, 0);
index bd7a85e528d554d0f66ecdce74d3f45b3ba7b6a6..6941af0e8d9efa91e1a7a0d67152e9266322432f 100644 (file)
--- a/options.c
+++ b/options.c
@@ -15,8 +15,6 @@
 #include "parse.h"
 #include "lib/fls.h"
 
-unsigned int fio_kb_base = 1024;
-
 #define td_var_offset(var)     ((size_t) &((struct thread_options *)0)->var)
 
 /*
@@ -84,7 +82,7 @@ static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
                } else
                        perc = -1;
 
-               if (str_to_decimal(fname, &val, 1)) {
+               if (str_to_decimal(fname, &val, 1, &td)) {
                        log_err("fio: bssplit conversion failed\n");
                        free(td->o.bssplit);
                        return 1;
@@ -639,7 +637,6 @@ static int kb_base_verify(struct fio_option *o, void *data)
                return 1;
        }
 
-       fio_kb_base = td->o.kb_base;
        return 0;
 }
 
@@ -1719,3 +1716,16 @@ void options_mem_free(struct thread_data fio_unused *td)
        __options_mem(td, 0);
 #endif
 }
+
+unsigned int fio_get_kb_base(void *data)
+{
+       struct thread_data *td = data;
+       unsigned int kb_base = 0;
+
+       if (td)
+               kb_base = td->o.kb_base;
+       if (!kb_base)
+               kb_base = 1024;
+
+       return kb_base;
+}
diff --git a/parse.c b/parse.c
index 0bf28a5bd72463d574560d828859669b9b0122c2..b0ea3d3a5bae985d14c1a7f71a5bf2198ae45615 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -14,7 +14,7 @@
 #include "debug.h"
 
 static struct fio_option *fio_options;
-extern unsigned int fio_kb_base;
+extern unsigned int fio_get_kb_base(void *);
 
 static int vp_cmp(const void *p1, const void *p2)
 {
@@ -113,8 +113,9 @@ static unsigned long get_mult_time(char c)
        }
 }
 
-static unsigned long long get_mult_bytes(char c)
+static unsigned long long get_mult_bytes(char c, void *data)
 {
+       unsigned int kb_base = fio_get_kb_base(data);
        unsigned long long ret = 1;
 
        switch (c) {
@@ -122,19 +123,19 @@ static unsigned long long get_mult_bytes(char c)
                break;
        case 'p':
        case 'P':
-               ret *= (unsigned long long) fio_kb_base;
+               ret *= (unsigned long long) kb_base;
        case 't':
        case 'T':
-               ret *= (unsigned long long) fio_kb_base;
+               ret *= (unsigned long long) kb_base;
        case 'g':
        case 'G':
-               ret *= (unsigned long long) fio_kb_base;
+               ret *= (unsigned long long) kb_base;
        case 'm':
        case 'M':
-               ret *= (unsigned long long) fio_kb_base;
+               ret *= (unsigned long long) kb_base;
        case 'k':
        case 'K':
-               ret *= (unsigned long long) fio_kb_base;
+               ret *= (unsigned long long) kb_base;
                break;
        }
 
@@ -144,7 +145,7 @@ static unsigned long long get_mult_bytes(char c)
 /*
  * convert string into decimal value, noting any size suffix
  */
-int str_to_decimal(const char *str, long long *val, int kilo)
+int str_to_decimal(const char *str, long long *val, int kilo, void *data)
 {
        int len, base;
 
@@ -162,21 +163,21 @@ int str_to_decimal(const char *str, long long *val, int kilo)
                return 1;
 
        if (kilo)
-               *val *= get_mult_bytes(str[len - 1]);
+               *val *= get_mult_bytes(str[len - 1], data);
        else
                *val *= get_mult_time(str[len - 1]);
 
        return 0;
 }
 
-static int check_str_bytes(const char *p, long long *val)
+static int check_str_bytes(const char *p, long long *val, void *data)
 {
-       return str_to_decimal(p, val, 1);
+       return str_to_decimal(p, val, 1, data);
 }
 
 static int check_str_time(const char *p, long long *val)
 {
-       return str_to_decimal(p, val, 0);
+       return str_to_decimal(p, val, 0, NULL);
 }
 
 void strip_blank_front(char **p)
@@ -209,7 +210,7 @@ void strip_blank_end(char *p)
        *(s + 1) = '\0';
 }
 
-static int check_range_bytes(const char *str, long *val)
+static int check_range_bytes(const char *str, long *val, void *data)
 {
        char suffix;
 
@@ -217,7 +218,7 @@ static int check_range_bytes(const char *str, long *val)
                return 1;
 
        if (sscanf(str, "%lu%c", val, &suffix) == 2) {
-               *val *= get_mult_bytes(suffix);
+               *val *= get_mult_bytes(suffix, data);
                return 0;
        }
 
@@ -318,7 +319,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                if (is_time)
                        ret = check_str_time(ptr, &ull);
                else
-                       ret = check_str_bytes(ptr, &ull);
+                       ret = check_str_bytes(ptr, &ull, data);
 
                if (ret)
                        break;
@@ -385,8 +386,8 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                p1 = tmp;
 
                ret = 1;
-               if (!check_range_bytes(p1, &ul1) &&
-                   !check_range_bytes(p2, &ul2)) {
+               if (!check_range_bytes(p1, &ul1, data) &&
+                   !check_range_bytes(p2, &ul2, data)) {
                        ret = 0;
                        if (ul1 > ul2) {
                                unsigned long foo = ul1;
diff --git a/parse.h b/parse.h
index 677b62b969850582c8e6419d838ec549b6b5dc5f..5b1a53deb748a1beb61dfce5ae5b62c087b7c2c4 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -62,7 +62,7 @@ extern void options_init(struct fio_option *);
 
 extern void strip_blank_front(char **);
 extern void strip_blank_end(char *);
-extern int str_to_decimal(const char *, long long *, int);
+extern int str_to_decimal(const char *, long long *, int, void *);
 
 /*
  * Handlers for the options