X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=steadystate.c;h=1f53ae46a88b504c225144a13563635422c72657;hp=53d303428eae6861fb9899edbaa9d24000eff63b;hb=94f218f6e5ef1eb2bc9190f72df5c8d105e0bac3;hpb=7be78a8a93b7d74d486859c2f782eb779dca6c12 diff --git a/steadystate.c b/steadystate.c index 53d30342..1f53ae46 100644 --- a/steadystate.c +++ b/steadystate.c @@ -4,14 +4,25 @@ #include "steadystate.h" #include "helper_thread.h" -bool steadystate = false; +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; struct thread_data *td, *prev_td; - if (!steadystate) + if (!steadystate_enabled) return; /* @@ -32,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; @@ -41,22 +52,11 @@ 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); } } -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->state & __FIO_SS_IOPS) new_val = iops; else new_val = bw; @@ -76,17 +76,17 @@ 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->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->check_iops) - ss->sum_xy += ss->iops_data[j]; + if (ss->state & __FIO_SS_IOPS) + ss->sum_xy += i * ss->iops_data[j]; else - ss->sum_xy += ss->bw_data[j]; + ss->sum_xy += i * ss->bw_data[j]; } } else { /* easy to update the sums */ ss->sum_y -= ss->oldest_y; @@ -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->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->check_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->check_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->check_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->check_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->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; /* @@ -272,7 +273,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); @@ -281,16 +282,43 @@ void steadystate_check(void) if (td->o.group_reporting) { for_each_td(td2, j) { if (td2->groupid == td->groupid) { - td2->ss.attained = 1; + td2->ss.state |= __FIO_SS_ATTAINED; fio_mark_td_terminate(td2); } } } else { - ss->attained = 1; + ss->state |= __FIO_SS_ATTAINED; fio_mark_td_terminate(td); } } } } +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->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; + + td->ts.ss = ss; +}