From: Sitsofe Wheeler Date: Sat, 20 May 2017 17:41:35 +0000 (+0100) Subject: fio: fix some struct alignment issues X-Git-Tag: fio-2.21~47 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=dbf285f75b4a447390a94a45b4c6091ac0c9f604;ds=sidebyside fio: fix some struct alignment issues 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 --- diff --git a/fio.h b/fio.h index e11a0390..ed631bc7 100644 --- 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; diff --git a/libfio.c b/libfio.c index 83107084..da22456e 100644 --- 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 aa4ad806..d8a08034 100644 --- 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[] */