Fio uses the struct io_sample to log attributes of each IO. When the log_offset option is set, fio uses the struct io_sample_offset instead which has the additional field dedicated to the offset data. Fio chooses one of these two structs by the log_offset option to minimize memory usage for IO sampling. However, the dedicated struct io_sample_offset is not flexible and makes it difficult to add new sampling items. To allow adding new sampling items, drop the struct io_sample_offset. Instead, introduce the variable length array "uint64_t aux[]" at the end of the struct io_sample which holds any auxiliary sampling data. At this moment, it holds only one item "offset" as the first array element. The following patch will add a new item. Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@xxxxxxx> --- client.c | 8 +++----- iolog.c | 4 +--- iolog.h | 19 ++++++++++++------- server.c | 8 +++----- stat.c | 7 ++----- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/client.c b/client.c index 4cb7dffe..0b6044dd 100644 --- a/client.c +++ b/client.c @@ -1726,11 +1726,9 @@ static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd, s->bs = le64_to_cpu(s->bs); s->priority = le16_to_cpu(s->priority); - if (ret->log_offset) { - struct io_sample_offset *so = (void *) s; - - so->offset = le64_to_cpu(so->offset); - } + if (ret->log_offset) + s->aux[IOS_AUX_OFFSET_INDEX] = + le64_to_cpu(s->aux[IOS_AUX_OFFSET_INDEX]); if (ret->log_type == IO_LOG_TYPE_HIST) { s->data.plat_entry = (struct io_u_plat_entry *)(((char *)s) + sizeof(*s)); diff --git a/iolog.c b/iolog.c index 06b51ea0..bb1ade86 100644 --- a/iolog.c +++ b/iolog.c @@ -1038,7 +1038,6 @@ static int print_sample_fields(char **p, size_t *left, const char *fmt, ...) { void flush_samples(FILE *f, void *samples, uint64_t sample_size) { struct io_sample *s; - struct io_sample_offset *sa; bool log_offset, log_prio, log_avg_max; uint64_t i, nr_samples; char buf[256]; @@ -1058,7 +1057,6 @@ void flush_samples(FILE *f, void *samples, uint64_t sample_size) for (i = 0; i < nr_samples; i++) { s = __get_sample(samples, log_offset, i); - sa = (void *) s; p = buf; left = sizeof(buf); @@ -1082,7 +1080,7 @@ void flush_samples(FILE *f, void *samples, uint64_t sample_size) if (log_offset) { ret = print_sample_fields(&p, &left, ", %llu", - (unsigned long long) sa->offset); + (unsigned long long) s->aux[IOS_AUX_OFFSET_INDEX]); if (ret) return; } diff --git a/iolog.h b/iolog.h index 26dd5cca..d868921b 100644 --- a/iolog.h +++ b/iolog.h @@ -54,11 +54,14 @@ struct io_sample { uint32_t __ddir; uint16_t priority; uint64_t bs; + uint64_t aux[]; }; -struct io_sample_offset { - struct io_sample s; - uint64_t offset; +/* + * Enumerate indexes of auxiliary log data in struct io_sample aux[] array + */ +enum { + IOS_AUX_OFFSET_INDEX, }; enum { @@ -180,12 +183,14 @@ static inline void io_sample_set_ddir(struct io_log *log, io->__ddir = ddir | log->log_ddir_mask; } -static inline size_t __log_entry_sz(int log_offset) +static inline size_t __log_entry_sz(bool log_offset) { + size_t ret = sizeof(struct io_sample); + if (log_offset) - return sizeof(struct io_sample_offset); - else - return sizeof(struct io_sample); + ret += sizeof(uint64_t); + + return ret; } static inline size_t log_entry_sz(struct io_log *log) diff --git a/server.c b/server.c index afaeb348..dbb9eb5e 100644 --- a/server.c +++ b/server.c @@ -2295,11 +2295,9 @@ int fio_send_iolog(struct thread_data *td, struct io_log *log, const char *name) s->__ddir = __cpu_to_le32(s->__ddir); s->bs = cpu_to_le64(s->bs); - if (log->log_offset) { - struct io_sample_offset *so = (void *) s; - - so->offset = cpu_to_le64(so->offset); - } + if (log->log_offset) + s->aux[IOS_AUX_OFFSET_INDEX] = + cpu_to_le64(s->aux[IOS_AUX_OFFSET_INDEX]); } } diff --git a/stat.c b/stat.c index 03681b9d..56d04e7a 100644 --- a/stat.c +++ b/stat.c @@ -3063,11 +3063,8 @@ static void __add_log_sample(struct io_log *iolog, unsigned long t, s->bs = sample->bs; s->priority = sample->priority; - if (iolog->log_offset) { - struct io_sample_offset *so = (void *) s; - - so->offset = sample->offset; - } + if (iolog->log_offset) + s->aux[IOS_AUX_OFFSET_INDEX] = sample->offset; cur_log->nr_samples++; return; -- 2.45.2