iolog: drop struct io_sample_offset
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Thu, 29 Aug 2024 08:58:21 +0000 (17:58 +0900)
committerVincent Fu <vincent.fu@samsung.com>
Wed, 4 Sep 2024 17:59:44 +0000 (13:59 -0400)
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@wdc.com>
Link: https://lore.kernel.org/r/20240829085826.999859-5-shinichiro.kawasaki@wdc.com
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
client.c
iolog.c
iolog.h
server.c
stat.c

index 4cb7dffede753d52f641afd1d4f1a448588a8509..0b6044dda489f2721eb7680413747ec3b3c1585d 100644 (file)
--- 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 06b51ea0a6e43cd30882990f4bd87674d5b5836d..bb1ade865910371f4f6efeab3af2f084f006aeb1 100644 (file)
--- 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 26dd5cca81f388e194199caf4197dcf9368592b7..d868921b408b3a65db546f5c644a7dc72b0d6191 100644 (file)
--- 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)
index afaeb3482b0fd0072c123bf78b925b5a35176bf1..dbb9eb5ea9454c663e556d95452d153ee99ae343 100644 (file)
--- 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 03681b9dcd367130f8add4b98f19d3db3dd58484..56d04e7af0266b7375e87151f16c6df251e8c3ea 100644 (file)
--- 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;