steadystate: kill ->last_in_group and ->ramp_time_over
authorJens Axboe <axboe@fb.com>
Wed, 17 Aug 2016 05:23:31 +0000 (23:23 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 17 Aug 2016 05:23:31 +0000 (23:23 -0600)
Also move to state flags. Rename ->mode to ->state, to better
reflect what it does.

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

index d9c6bd0..6f3752f 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1133,7 +1133,7 @@ static int str_steadystate_cb(void *data, const char *str)
 
        }
 
-       td->ss.mode = td->o.ss;
+       td->ss.state = td->o.ss;
        return 0;
 }
 
diff --git a/stat.c b/stat.c
index d914736..0eb87bd 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->mode & __FIO_SS_IOPS ? "iops" : "bw",
-                       ss->mode & __FIO_SS_SLOPE ? "_slope" : "",
+                       ss->state & __FIO_SS_IOPS ? "iops" : "bw",
+                       ss->state & __FIO_SS_SLOPE ? "_slope" : "",
                        (float) ss->limit,
                        ss->pct ? "%" : "");
 
@@ -1276,7 +1276,7 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
                json_object_add_value_string(tmp, "ss", ss_buf);
                json_object_add_value_int(tmp, "duration", (int)ss->dur);
                json_object_add_value_int(tmp, "steadystate_ramptime", ss->ramp_time / 1000000L);
-               json_object_add_value_int(tmp, "attained", ss->mode & __FIO_SS_ATTAINED);
+               json_object_add_value_int(tmp, "attained", ss->state & __FIO_SS_ATTAINED);
 
                snprintf(ss_buf, sizeof(ss_buf), "%f%s", (float) ss->criterion, ss->pct ? "%" : "");
                json_object_add_value_string(tmp, "criterion", ss_buf);
@@ -1294,7 +1294,7 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
                ** otherwise it actually points to the second element
                ** in the list
                */
-               if ((ss->mode & __FIO_SS_ATTAINED) || ss->sum_y == 0)
+               if ((ss->state & __FIO_SS_ATTAINED) || ss->sum_y == 0)
                        j = ss->head;
                else
                        j = ss->head == 0 ? ss->dur - 1 : ss->head - 1;
index 512500f..235deac 100644 (file)
@@ -43,7 +43,7 @@ void steadystate_setup(void)
 
                if (prev_groupid != td->groupid) {
                        if (prev_td != NULL) {
-                               prev_td->ss.last_in_group = 1;
+                               prev_td->ss.state |= __FIO_SS_LAST;
                                steadystate_alloc(prev_td);
                        }
                        prev_groupid = td->groupid;
@@ -52,7 +52,7 @@ void steadystate_setup(void)
        }
 
        if (prev_td != NULL && prev_td->o.group_reporting) {
-               prev_td->ss.last_in_group = 1;
+               prev_td->ss.state |= __FIO_SS_LAST;
                steadystate_alloc(prev_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->mode & __FIO_SS_IOPS)
+       if (ss->state & __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->mode & __FIO_SS_IOPS)
+                               if (ss->state & __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->mode & __FIO_SS_IOPS)
+                               if (ss->state & __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->mode & __FIO_SS_IOPS)
+               if (ss->state & __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->mode & __FIO_SS_IOPS)
+                               if (ss->state & __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->mode & __FIO_SS_IOPS)
+                       if (ss->state & __FIO_SS_IOPS)
                                ss->sum_y += ss->iops_data[ss->tail];
                        else
                                ss->sum_y += ss->bw_data[ss->tail];
                }
 
-               if (ss->mode & __FIO_SS_IOPS)
+               if (ss->state & __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->mode & __FIO_SS_IOPS)
+                       if (ss->state & __FIO_SS_IOPS)
                                diff = ss->iops_data[i] - mean;
                        else
                                diff = ss->bw_data[i] - mean;
@@ -209,7 +209,7 @@ void steadystate_check(void)
                struct steadystate_data *ss = &td->ss;
 
                if (!ss->dur || td->runstate <= TD_SETTING_UP ||
-                   td->runstate >= TD_EXITED || (ss->mode & __FIO_SS_ATTAINED))
+                   td->runstate >= TD_EXITED || (ss->state & __FIO_SS_ATTAINED))
                        continue;
 
                td_iops = 0;
@@ -223,13 +223,14 @@ void steadystate_check(void)
                prev_groupid = td->groupid;
 
                fio_gettime(&now, NULL);
-               if (ss->ramp_time && !ss->ramp_time_over)
+               if (ss->ramp_time && !(ss->state & __FIO_SS_RAMP_OVER)) {
                        /*
                         * Begin recording data one second after ss->ramp_time
                         * has elapsed
                         */
                        if (utime_since(&td->epoch, &now) >= (ss->ramp_time + 1000000L))
-                               ss->ramp_time_over = 1;
+                               ss->state |= __FIO_SS_RAMP_OVER;
+               }
 
                td_io_u_lock(td);
                for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
@@ -248,7 +249,7 @@ void steadystate_check(void)
                 * prev_iops/bw the first time through after ss->ramp_time
                 * is done.
                 */
-               if (ss->ramp_time_over) {
+               if (ss->state & __FIO_SS_RAMP_OVER) {
                        group_bw += 1000 * (td_bytes - ss->prev_bytes) / rate_time;
                        group_iops += 1000 * (td_iops - ss->prev_iops) / rate_time;
                        ++group_ramp_time_over;
@@ -256,7 +257,7 @@ void steadystate_check(void)
                ss->prev_iops = td_iops;
                ss->prev_bytes = td_bytes;
 
-               if (td->o.group_reporting && !ss->last_in_group)
+               if (td->o.group_reporting && !(ss->state & __FIO_SS_LAST))
                        continue;
 
                /*
@@ -281,12 +282,12 @@ void steadystate_check(void)
                        if (td->o.group_reporting) {
                                for_each_td(td2, j) {
                                        if (td2->groupid == td->groupid) {
-                                               td2->ss.mode |= __FIO_SS_ATTAINED;
+                                               td2->ss.state |= __FIO_SS_ATTAINED;
                                                fio_mark_td_terminate(td2);
                                        }
                                }
                        } else {
-                               ss->mode |= __FIO_SS_ATTAINED;
+                               ss->state |= __FIO_SS_ATTAINED;
                                fio_mark_td_terminate(td);
                        }
                }
@@ -311,9 +312,11 @@ void td_steadystate_init(struct thread_data *td)
        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->state = o->ss;
+       if (!td->ss.ramp_time)
+               ss->state |= __FIO_SS_RAMP_OVER;
+
        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;
 
index 3829ee4..43670c1 100644 (file)
@@ -18,9 +18,7 @@ struct steadystate_data {
        unsigned long long ramp_time;
        bool pct;
 
-       unsigned int mode;
-       int last_in_group;
-       int ramp_time_over;
+       unsigned int state;
 
        unsigned int head;
        unsigned int tail;
@@ -47,6 +45,8 @@ enum {
        __FIO_SS_BW             = 2,
        __FIO_SS_SLOPE          = 4,
        __FIO_SS_ATTAINED       = 8,
+       __FIO_SS_RAMP_OVER      = 16,
+       __FIO_SS_LAST           = 32,
 
        FIO_SS_IOPS             = __FIO_SS_IOPS,
        FIO_SS_IOPS_SLOPE       = __FIO_SS_IOPS | __FIO_SS_SLOPE,