steadystate: eliminate some steadystate_data members
authorJens Axboe <axboe@fb.com>
Wed, 17 Aug 2016 05:13:48 +0000 (23:13 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 17 Aug 2016 05:13:48 +0000 (23:13 -0600)
Working towards a goal of killing members we don't really need,
and splitting steadystate_data into a runtime part and an
output part. The latter needs to be wire safe.

Signed-off-by: Jens Axboe <axboe@fb.com>
init.c
options.c
stat.c
steadystate.c
steadystate.h

diff --git a/init.c b/init.c
index 64119eb..8d2603a 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1578,45 +1578,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                        log_info("...\n");
        }
 
-       if (o->ss_dur) {
-               steadystate_enabled = true;
-               o->ss_dur /= 1000000L;
-
-               /* put all steady state info in one place */
-               td->ss.dur = o->ss_dur;
-               td->ss.limit = o->ss_limit.u.f;
-               td->ss.ramp_time = o->ss_ramp_time;
-               td->ss.pct = o->ss_pct;
-
-               if (steadystate_check_slope(o))
-                       td->ss.check_slope = true;
-               else
-                       td->ss.check_slope = false;
-
-               if (o->ss == FIO_STEADYSTATE_IOPS || o->ss == FIO_STEADYSTATE_IOPS_SLOPE)
-                       td->ss.check_iops = true;
-               else
-                       td->ss.check_iops = false;
-
-               td->ss.bw_data = NULL;
-               td->ss.iops_data = NULL;
-               td->ss.ramp_time_over = (td->ss.ramp_time == 0);
-               td->ss.attained = 0;
-               td->ss.last_in_group = 0;
-               td->ss.head = 0;
-               td->ss.tail = 0;
-               td->ss.sum_x = o->ss_dur * (o->ss_dur - 1) / 2;
-               td->ss.sum_x_sq = (o->ss_dur - 1) * (o->ss_dur) * (2*o->ss_dur - 1) / 6;
-               td->ss.prev_bytes = 0;
-               td->ss.prev_iops = 0;
-               td->ss.sum_y = 0;
-               td->ss.oldest_y = 0;
-               td->ss.criterion = 0.0;
-               td->ss.slope = 0.0;
-               td->ss.deviation = 0.0;
-               td->ts.ss = &td->ss;
-       } else
-               td->ts.ss = NULL;
+       td_steadystate_init(td);
 
        /*
         * recurse add identical jobs, clear numjobs and stonewall options
index dfa98d3..d9c6bd0 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1069,10 +1069,8 @@ static int str_steadystate_cb(void *data, const char *str)
        char *pct;
        long long ll;
 
-       if (td->o.ss != FIO_STEADYSTATE_IOPS &&
-           td->o.ss != FIO_STEADYSTATE_IOPS_SLOPE &&
-           td->o.ss != FIO_STEADYSTATE_BW &&
-           td->o.ss != FIO_STEADYSTATE_BW_SLOPE) {
+       if (td->o.ss != FIO_SS_IOPS && td->o.ss != FIO_SS_IOPS_SLOPE &&
+           td->o.ss != FIO_SS_BW && td->o.ss != FIO_SS_BW_SLOPE) {
                /* should be impossible to get here */
                log_err("fio: unknown steady state criterion\n");
                return 1;
@@ -1103,10 +1101,7 @@ static int str_steadystate_cb(void *data, const char *str)
 
                td->o.ss_pct = true;
                td->o.ss_limit.u.f = val;
-
-
-       } else if (td->o.ss == FIO_STEADYSTATE_IOPS ||
-                  td->o.ss == FIO_STEADYSTATE_IOPS_SLOPE) {
+       } else if (td->o.ss & __FIO_SS_IOPS) {
                if (!str_to_float(nr, &val, 0)) {
                        log_err("fio: steadystate IOPS threshold postfix parsing failed\n");
                        free(nr);
@@ -1138,6 +1133,7 @@ static int str_steadystate_cb(void *data, const char *str)
 
        }
 
+       td->ss.mode = td->o.ss;
        return 0;
 }
 
@@ -4224,20 +4220,20 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .def    = "iops_slope:0.01%",
                .posval = {
                          { .ival = "iops",
-                           .oval = FIO_STEADYSTATE_IOPS,
+                           .oval = FIO_SS_IOPS,
                            .help = "maximum mean deviation of IOPS measurements",
                          },
                          { .ival = "iops_slope",
-                           .oval = FIO_STEADYSTATE_IOPS_SLOPE,
+                           .oval = FIO_SS_IOPS_SLOPE,
                            .help = "slope calculated from IOPS measurements",
                          },
                          { .ival = "bw",
-                           .oval = FIO_STEADYSTATE_BW,
+                           .oval = FIO_SS_BW,
                            .help = "maximum mean deviation of bandwidth measurements",
                          },
                          {
                            .ival = "bw_slope",
-                           .oval = FIO_STEADYSTATE_BW_SLOPE,
+                           .oval = FIO_SS_BW_SLOPE,
                            .help = "slope calculated from bandwidth measurements",
                          },
                },
diff --git a/stat.c b/stat.c
index 4bfacf7..31042ca 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1266,8 +1266,8 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
                char ss_buf[64];
 
                snprintf(ss_buf, sizeof(ss_buf), "%s%s:%f%s",
-                       ss->check_iops ? "iops" : "bw",
-                       ss->check_slope ? "_slope" : "",
+                       ss->mode & __FIO_SS_IOPS ? "iops" : "bw",
+                       ss->mode & __FIO_SS_SLOPE ? "_slope" : "",
                        (float) ss->limit,
                        ss->pct ? "%" : "");
 
index 528e952..c7a7e4c 100644 (file)
@@ -6,6 +6,17 @@
 
 bool steadystate_enabled = false;
 
+static void steadystate_alloc(struct thread_data *td)
+{
+       int i;
+
+       td->ss.bw_data = malloc(td->ss.dur * sizeof(unsigned long));
+       td->ss.iops_data = malloc(td->ss.dur * sizeof(unsigned long));
+       /* initialize so that it is obvious if the cache is not full in the output */
+       for (i = 0; i < td->ss.dur; i++)
+               td->ss.iops_data[i] = td->ss.bw_data[i] = 0;
+}
+
 void steadystate_setup(void)
 {
        int i, prev_groupid;
@@ -46,17 +57,6 @@ void steadystate_setup(void)
        }
 }
 
-void steadystate_alloc(struct thread_data *td)
-{
-       int i;
-
-       td->ss.bw_data = malloc(td->ss.dur * sizeof(unsigned long));
-       td->ss.iops_data = malloc(td->ss.dur * sizeof(unsigned long));
-       /* initialize so that it is obvious if the cache is not full in the output */
-       for (i = 0; i < td->ss.dur; i++)
-               td->ss.iops_data[i] = td->ss.bw_data[i] = 0;
-}
-
 static bool steadystate_slope(unsigned long iops, unsigned long bw,
                              struct thread_data *td)
 {
@@ -68,7 +68,7 @@ static bool steadystate_slope(unsigned long iops, unsigned long bw,
        ss->bw_data[ss->tail] = bw;
        ss->iops_data[ss->tail] = iops;
 
-       if (ss->check_iops)
+       if (ss->mode & __FIO_SS_IOPS)
                new_val = iops;
        else
                new_val = bw;
@@ -76,14 +76,14 @@ static bool steadystate_slope(unsigned long iops, unsigned long bw,
        if (ss->tail < ss->head || (ss->tail - ss->head == ss->dur - 1)) {
                if (ss->sum_y == 0) {   /* first time through */
                        for(i = 0; i < ss->dur; i++) {
-                               if (ss->check_iops)
+                               if (ss->mode & __FIO_SS_IOPS)
                                        ss->sum_y += ss->iops_data[i];
                                else
                                        ss->sum_y += ss->bw_data[i];
                                j = ss->head + i;
                                if (j >= ss->dur)
                                        j -= ss->dur;
-                               if (ss->check_iops)
+                               if (ss->mode & __FIO_SS_IOPS)
                                        ss->sum_xy += ss->iops_data[j];
                                else
                                        ss->sum_xy += ss->bw_data[j];
@@ -94,7 +94,7 @@ static bool steadystate_slope(unsigned long iops, unsigned long bw,
                        ss->sum_xy = ss->sum_xy - ss->sum_y + ss->dur * new_val;
                }
 
-               if (ss->check_iops)
+               if (ss->mode & __FIO_SS_IOPS)
                        ss->oldest_y = ss->iops_data[ss->head];
                else
                        ss->oldest_y = ss->bw_data[ss->head];
@@ -144,19 +144,19 @@ static bool steadystate_deviation(unsigned long iops, unsigned long bw,
        if (ss->tail < ss->head || (ss->tail - ss->head == ss->dur - 1)) {
                if (ss->sum_y == 0) {   /* first time through */
                        for(i = 0; i < ss->dur; i++)
-                               if (ss->check_iops)
+                               if (ss->mode & __FIO_SS_IOPS)
                                        ss->sum_y += ss->iops_data[i];
                                else
                                        ss->sum_y += ss->bw_data[i];
                } else {                /* easy to update the sum */
                        ss->sum_y -= ss->oldest_y;
-                       if (ss->check_iops)
+                       if (ss->mode & __FIO_SS_IOPS)
                                ss->sum_y += ss->iops_data[ss->tail];
                        else
                                ss->sum_y += ss->bw_data[ss->tail];
                }
 
-               if (ss->check_iops)
+               if (ss->mode & __FIO_SS_IOPS)
                        ss->oldest_y = ss->iops_data[ss->head];
                else
                        ss->oldest_y = ss->bw_data[ss->head];
@@ -165,7 +165,7 @@ static bool steadystate_deviation(unsigned long iops, unsigned long bw,
                ss->deviation = 0.0;
 
                for (i = 0; i < ss->dur; i++) {
-                       if (ss->check_iops)
+                       if (ss->mode & __FIO_SS_IOPS)
                                diff = ss->iops_data[i] - mean;
                        else
                                diff = ss->bw_data[i] - mean;
@@ -272,7 +272,7 @@ void steadystate_check(void)
                                        i, td->groupid, rate_time, group_iops,
                                        group_bw, ss->head, ss->tail);
 
-               if (steadystate_check_slope(&td->o))
+               if (td->o.ss & __FIO_SS_SLOPE)
                        ret = steadystate_slope(group_iops, group_bw, td);
                else
                        ret = steadystate_deviation(group_iops, group_bw, td);
@@ -293,4 +293,29 @@ void steadystate_check(void)
        }
 }
 
+void td_steadystate_init(struct thread_data *td)
+{
+       struct steadystate_data *ss = &td->ss;
+       struct thread_options *o = &td->o;
+
+       memset(ss, 0, sizeof(*ss));
+
+       if (!o->ss_dur)
+               return;
+
+       steadystate_enabled = true;
+       o->ss_dur /= 1000000L;
 
+       /* put all steady state info in one place */
+       ss->dur = o->ss_dur;
+       ss->limit = o->ss_limit.u.f;
+       ss->ramp_time = o->ss_ramp_time;
+       ss->pct = o->ss_pct;
+       ss->mode = o->ss;
+
+       ss->ramp_time_over = (td->ss.ramp_time == 0);
+       ss->sum_x = o->ss_dur * (o->ss_dur - 1) / 2;
+       ss->sum_x_sq = (o->ss_dur - 1) * (o->ss_dur) * (2*o->ss_dur - 1) / 6;
+
+       td->ts.ss = ss;
+}
index 5342b2c..86f975c 100644 (file)
@@ -5,7 +5,7 @@
 
 extern void steadystate_check(void);
 extern void steadystate_setup(void);
-extern void steadystate_alloc(struct thread_data *);
+extern void td_steadystate_init(struct thread_data *);
 
 extern bool steadystate_enabled;
 
@@ -16,10 +16,9 @@ struct steadystate_data {
        double limit;
        unsigned long long dur;
        unsigned long long ramp_time;
-       bool check_iops;
-       bool check_slope;
        bool pct;
 
+       unsigned int mode;
        int attained;
        int last_in_group;
        int ramp_time_over;
@@ -45,24 +44,16 @@ struct steadystate_data {
 };
 
 enum {
-       FIO_STEADYSTATE_IOPS    = 0,
-       FIO_STEADYSTATE_IOPS_SLOPE,
-       FIO_STEADYSTATE_BW,
-       FIO_STEADYSTATE_BW_SLOPE,
+       __FIO_SS_IOPS   = 1,
+       __FIO_SS_BW     = 2,
+       __FIO_SS_SLOPE  = 4,
+
+       FIO_SS_IOPS             = __FIO_SS_IOPS,
+       FIO_SS_IOPS_SLOPE       = __FIO_SS_IOPS | __FIO_SS_SLOPE,
+       FIO_SS_BW               = __FIO_SS_BW,
+       FIO_SS_BW_SLOPE         = __FIO_SS_BW | __FIO_SS_SLOPE,
 };
 
 #define STEADYSTATE_MSEC       1000
 
-static inline bool steadystate_check_slope(struct thread_options *o)
-{
-       return o->ss == FIO_STEADYSTATE_IOPS_SLOPE ||
-               o->ss == FIO_STEADYSTATE_BW_SLOPE;
-}
-
-static inline bool steadystate_check_iops(struct thread_options *o)
-{
-       return o->ss == FIO_STEADYSTATE_IOPS ||
-               o->ss == FIO_STEADYSTATE_IOPS_SLOPE;
-}
-
 #endif