+int fio_running_or_pending_io_threads(void)
+{
+ struct thread_data *td;
+ int i;
+
+ for_each_td(td, i) {
+ if (td->flags & TD_F_NOIO)
+ continue;
+ if (td->runstate < TD_EXITED)
+ return 1;
+ }
+
+ return 0;
+}
+
+int fio_set_fd_nonblocking(int fd, const char *who)
+{
+ int flags;
+
+ flags = fcntl(fd, F_GETFL);
+ if (flags < 0)
+ log_err("fio: %s failed to get file flags: %s\n", who, strerror(errno));
+ else {
+ int new_flags = flags | O_NONBLOCK;
+
+ new_flags = fcntl(fd, F_SETFL, new_flags);
+ if (new_flags < 0)
+ log_err("fio: %s failed to get file flags: %s\n", who, strerror(errno));
+ }
+
+ return flags;
+}
+
+static int endian_check(void)
+{
+ union {
+ uint8_t c[8];
+ uint64_t v;
+ } u;
+ int le = 0, be = 0;
+
+ u.v = 0x12;
+ if (u.c[7] == 0x12)
+ be = 1;
+ else if (u.c[0] == 0x12)
+ le = 1;
+
+#if defined(CONFIG_LITTLE_ENDIAN)
+ if (be)
+ return 1;
+#elif defined(CONFIG_BIG_ENDIAN)
+ if (le)
+ return 1;
+#else
+ return 1;
+#endif
+
+ if (!le && !be)
+ return 1;
+
+ return 0;
+}
+
+int initialize_fio(char *envp[])
+{
+ long ps;
+
+ if (endian_check()) {
+ log_err("fio: endianness settings appear wrong.\n");
+ log_err("fio: please report this to fio@vger.kernel.org\n");
+ return 1;
+ }
+
+#if !defined(CONFIG_GETTIMEOFDAY) && !defined(CONFIG_CLOCK_GETTIME)
+#error "No available clock source!"
+#endif
+
+ arch_init(envp);
+
+ sinit();