The number of arguments of add_log_sample() has increased as fields get added to the log file format. Five parameters of them (data, ddir, bs, offset and priority) are passed to __add_log_sample(). This makes the function look more complicated and log field addition harder. To simplify the function, pack the five arguments into the new struct log_sample. Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@xxxxxxx> --- stat.c | 117 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 47 deletions(-) diff --git a/stat.c b/stat.c index fac6d534..03681b9d 100644 --- a/stat.c +++ b/stat.c @@ -24,6 +24,14 @@ #define LOG_MSEC_SLACK 1 #endif +struct log_sample { + union io_sample_data data; + uint32_t ddir; + uint64_t bs; + uint64_t offset; + uint16_t priority; +}; + struct fio_sem *stat_sem; void clear_rusage_stat(struct thread_data *td) @@ -3031,17 +3039,15 @@ static struct io_logs *get_cur_log(struct io_log *iolog) return iolog->pending; } -static void __add_log_sample(struct io_log *iolog, union io_sample_data data, - enum fio_ddir ddir, unsigned long long bs, - unsigned long t, uint64_t offset, - unsigned int priority) +static void __add_log_sample(struct io_log *iolog, unsigned long t, + struct log_sample *sample) { struct io_logs *cur_log; if (iolog->disabled) return; if (flist_empty(&iolog->io_logs)) - iolog->avg_last[ddir] = t; + iolog->avg_last[sample->ddir] = t; cur_log = get_cur_log(iolog); if (cur_log) { @@ -3049,18 +3055,18 @@ static void __add_log_sample(struct io_log *iolog, union io_sample_data data, s = get_sample(iolog, cur_log, cur_log->nr_samples); - s->data = data; + s->data = sample->data; s->time = t; if (iolog->td && iolog->td->o.log_alternate_epoch) s->time += iolog->td->alternate_epoch; - io_sample_set_ddir(iolog, s, ddir); - s->bs = bs; - s->priority = priority; + io_sample_set_ddir(iolog, s, sample->ddir); + s->bs = sample->bs; + s->priority = sample->priority; if (iolog->log_offset) { struct io_sample_offset *so = (void *) s; - so->offset = offset; + so->offset = sample->offset; } cur_log->nr_samples++; @@ -3157,20 +3163,21 @@ static void __add_stat_to_log(struct io_log *iolog, enum fio_ddir ddir, * had actual samples done. */ if (iolog->avg_window[ddir].samples) { - union io_sample_data data; + struct log_sample sample = { {{ 0, 0 }}, ddir, 0, 0, 0 }; + union io_sample_data *d = &sample.data; if (log_max == IO_LOG_SAMPLE_AVG) { - data.val.val0 = iolog->avg_window[ddir].mean.u.f + 0.50; - data.val.val1 = 0; + d->val.val0 = iolog->avg_window[ddir].mean.u.f + 0.50; + d->val.val1 = 0; } else if (log_max == IO_LOG_SAMPLE_MAX) { - data.val.val0 = iolog->avg_window[ddir].max_val; - data.val.val1 = 0; + d->val.val0 = iolog->avg_window[ddir].max_val; + d->val.val1 = 0; } else { - data.val.val0 = iolog->avg_window[ddir].mean.u.f + 0.50; - data.val.val1 = iolog->avg_window[ddir].max_val; + d->val.val0 = iolog->avg_window[ddir].mean.u.f + 0.50; + d->val.val1 = iolog->avg_window[ddir].max_val; } - __add_log_sample(iolog, data, ddir, 0, elapsed, 0, 0); + __add_log_sample(iolog, elapsed, &sample); } reset_io_stat(&iolog->avg_window[ddir]); @@ -3187,11 +3194,10 @@ static void _add_stat_to_log(struct io_log *iolog, unsigned long elapsed, static unsigned long add_log_sample(struct thread_data *td, struct io_log *iolog, - union io_sample_data data, - enum fio_ddir ddir, unsigned long long bs, - uint64_t offset, unsigned int ioprio) + struct log_sample *sample) { unsigned long elapsed, this_window; + enum fio_ddir ddir = sample->ddir; if (!ddir_rw(ddir)) return 0; @@ -3202,8 +3208,7 @@ static unsigned long add_log_sample(struct thread_data *td, * If no time averaging, just add the log sample. */ if (!iolog->avg_msec) { - __add_log_sample(iolog, data, ddir, bs, elapsed, offset, - ioprio); + __add_log_sample(iolog, elapsed, sample); return 0; } @@ -3211,7 +3216,7 @@ static unsigned long add_log_sample(struct thread_data *td, * Add the sample. If the time period has passed, then * add that entry to the log and clear. */ - add_stat_sample(&iolog->avg_window[ddir], data.val.val0); + add_stat_sample(&iolog->avg_window[ddir], sample->data.val.val0); /* * If period hasn't passed, adding the above sample is all we @@ -3256,12 +3261,13 @@ void add_agg_sample(union io_sample_data data, enum fio_ddir ddir, unsigned long long bs) { struct io_log *iolog; + struct log_sample sample = { data, ddir, bs, 0, 0 }; if (!ddir_rw(ddir)) return; iolog = agg_io_log[ddir]; - __add_log_sample(iolog, data, ddir, bs, mtime_since_genesis(), 0, 0); + __add_log_sample(iolog, mtime_since_genesis(), &sample); } void add_sync_clat_sample(struct thread_stat *ts, unsigned long long nsec) @@ -3331,9 +3337,12 @@ void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, add_stat_prio_sample(ts->clat_prio[ddir], clat_prio_index, nsec); - if (td->clat_log) - add_log_sample(td, td->clat_log, sample_val(nsec), ddir, bs, - offset, ioprio); + if (td->clat_log) { + struct log_sample sample = { sample_val(nsec), ddir, bs, + offset, ioprio }; + + add_log_sample(td, td->clat_log, &sample); + } if (ts->clat_percentiles) { /* @@ -3359,6 +3368,8 @@ void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, if (this_window >= iolog->hist_msec) { uint64_t *io_u_plat; struct io_u_plat_entry *dst; + struct log_sample sample = { {{ 0, 0 }}, ddir, bs, + offset, ioprio }; /* * Make a byte-for-byte copy of the latency histogram @@ -3372,8 +3383,9 @@ void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, memcpy(&(dst->io_u_plat), io_u_plat, FIO_IO_U_PLAT_NR * sizeof(uint64_t)); flist_add(&dst->list, &hw->list); - __add_log_sample(iolog, sample_plat(dst), ddir, bs, - elapsed, offset, ioprio); + + sample.data = sample_plat(dst); + __add_log_sample(iolog, elapsed, &sample); /* * Update the last time we recorded as being now, minus @@ -3407,9 +3419,12 @@ void add_slat_sample(struct thread_data *td, struct io_u *io_u) add_stat_sample(&ts->slat_stat[ddir], nsec); - if (td->slat_log) - add_log_sample(td, td->slat_log, sample_val(nsec), ddir, - io_u->xfer_buflen, io_u->offset, io_u->ioprio); + if (td->slat_log) { + struct log_sample sample = { sample_val(nsec), ddir, + io_u->xfer_buflen, io_u->offset, io_u->ioprio }; + + add_log_sample(td, td->slat_log, &sample); + } if (ts->slat_percentiles) add_lat_percentile_sample(ts, nsec, ddir, FIO_SLAT); @@ -3433,9 +3448,12 @@ void add_lat_sample(struct thread_data *td, enum fio_ddir ddir, add_stat_sample(&ts->lat_stat[ddir], nsec); - if (td->lat_log) - add_log_sample(td, td->lat_log, sample_val(nsec), ddir, bs, - io_u->offset, io_u->ioprio); + if (td->lat_log) { + struct log_sample sample = { sample_val(nsec), ddir, bs, + io_u->offset, io_u->ioprio }; + + add_log_sample(td, td->lat_log, &sample); + } /* * When lat_percentiles=1 (default 0), the reported per priority @@ -3475,9 +3493,12 @@ void add_bw_sample(struct thread_data *td, struct io_u *io_u, add_stat_sample(&ts->bw_stat[io_u->ddir], rate); - if (td->bw_log) - add_log_sample(td, td->bw_log, sample_val(rate), io_u->ddir, - bytes, io_u->offset, io_u->ioprio); + if (td->bw_log) { + struct log_sample sample = { sample_val(rate), io_u->ddir, + bytes, io_u->offset, io_u->ioprio }; + + add_log_sample(td, td->bw_log, &sample); + } td->stat_io_bytes[io_u->ddir] = td->this_io_bytes[io_u->ddir]; @@ -3526,13 +3547,12 @@ static int __add_samples(struct thread_data *td, struct timespec *parent_tv, add_stat_sample(&stat[ddir], rate); if (log) { - unsigned long long bs = 0; + struct log_sample sample = { + sample_val(rate), ddir, 0, 0, 0 }; if (td->o.min_bs[ddir] == td->o.max_bs[ddir]) - bs = td->o.min_bs[ddir]; - - next = add_log_sample(td, log, sample_val(rate), ddir, - bs, 0, 0); + sample.bs = td->o.min_bs[ddir]; + next = add_log_sample(td, log, &sample); next_log = min(next_log, next); } @@ -3570,9 +3590,12 @@ void add_iops_sample(struct thread_data *td, struct io_u *io_u, add_stat_sample(&ts->iops_stat[io_u->ddir], 1); - if (td->iops_log) - add_log_sample(td, td->iops_log, sample_val(1), io_u->ddir, - bytes, io_u->offset, io_u->ioprio); + if (td->iops_log) { + struct log_sample sample = { sample_val(1), io_u->ddir, bytes, + io_u->offset, io_u->ioprio }; + + add_log_sample(td, td->iops_log, &sample); + } td->stat_io_blocks[io_u->ddir] = td->this_io_blocks[io_u->ddir]; -- 2.45.2