fio: fix some struct alignment issues
authorSitsofe Wheeler <sitsofe@yahoo.com>
Sat, 20 May 2017 17:41:35 +0000 (18:41 +0100)
committerSitsofe Wheeler <sitsofe@yahoo.com>
Mon, 22 May 2017 16:01:09 +0000 (17:01 +0100)
Fix unaligned/misaligned accesses related to struct thread_stat and
struct jobs_eta seen when running a build produced by
CC=~/clang-3.9/build/bin/clang ./configure --disable-optimizations \
   --extra-cflags="-D__compiler_offsetof=__builtin_offsetof \
   -fsanitize=undefined"

and add to the compile time asserts to make these problems more visible.

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
fio.h
libfio.c
stat.h

diff --git a/fio.h b/fio.h
index e11a03902676285635ae5d2e2dc2b60ed83eb401..ed631bc70ab0c490c98d3e5432b6eebc109139dc 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -149,7 +149,7 @@ struct thread_data {
        unsigned int thread_number;
        unsigned int subjob_number;
        unsigned int groupid;
-       struct thread_stat ts;
+       struct thread_stat ts __attribute__ ((aligned));
 
        int client_type;
 
index 83107084a4239c096298c3bddd702b7c8166cef0..da22456e39b30e71f0d471b8a91c0bb003a6ae42 100644 (file)
--- a/libfio.c
+++ b/libfio.c
@@ -353,14 +353,17 @@ int initialize_fio(char *envp[])
         * can run into problems on archs that fault on unaligned fp
         * access (ARM).
         */
+       compiletime_assert((offsetof(struct thread_data, ts) % sizeof(void *)) == 0, "ts");
        compiletime_assert((offsetof(struct thread_stat, percentile_list) % 8) == 0, "stat percentile_list");
        compiletime_assert((offsetof(struct thread_stat, total_run_time) % 8) == 0, "total_run_time");
        compiletime_assert((offsetof(struct thread_stat, total_err_count) % 8) == 0, "total_err_count");
        compiletime_assert((offsetof(struct thread_stat, latency_percentile) % 8) == 0, "stat latency_percentile");
+       compiletime_assert((offsetof(struct thread_data, ts.clat_stat) % 8) == 0, "ts.clat_stat");
        compiletime_assert((offsetof(struct thread_options_pack, zipf_theta) % 8) == 0, "zipf_theta");
        compiletime_assert((offsetof(struct thread_options_pack, pareto_h) % 8) == 0, "pareto_h");
        compiletime_assert((offsetof(struct thread_options_pack, percentile_list) % 8) == 0, "percentile_list");
        compiletime_assert((offsetof(struct thread_options_pack, latency_percentile) % 8) == 0, "latency_percentile");
+       compiletime_assert((offsetof(struct jobs_eta, m_rate) % 8) == 0, "m_rate");
 
        err = endian_check();
        if (err) {
diff --git a/stat.h b/stat.h
index aa4ad806aa9159db7b15276fcf15853dae9c5bf8..d8a08034a5faf94c5097ad1f33623fed86a08ddb 100644 (file)
--- a/stat.h
+++ b/stat.h
@@ -242,17 +242,17 @@ struct jobs_eta {
        uint32_t nr_pending;
        uint32_t nr_setting_up;
 
-       uint32_t files_open;
-
        uint64_t m_rate[DDIR_RWDIR_CNT], t_rate[DDIR_RWDIR_CNT];
-       uint32_t m_iops[DDIR_RWDIR_CNT], t_iops[DDIR_RWDIR_CNT];
        uint64_t rate[DDIR_RWDIR_CNT];
+       uint32_t m_iops[DDIR_RWDIR_CNT], t_iops[DDIR_RWDIR_CNT];
        uint32_t iops[DDIR_RWDIR_CNT];
        uint64_t elapsed_sec;
        uint64_t eta_sec;
        uint32_t is_pow2;
        uint32_t unit_base;
 
+       uint32_t files_open;
+
        /*
         * Network 'copy' of run_str[]
         */