Move some code around to better separate front/backend
[fio.git] / fio.c
CommitLineData
ebac4655
JA
1/*
2 * fio - the flexible io tester
3 *
4 * Copyright (C) 2005 Jens Axboe <axboe@suse.de>
2e1df07d 5 * Copyright (C) 2006-2012 Jens Axboe <axboe@kernel.dk>
ebac4655 6 *
8e9fe637
JA
7 * The license below covers all files distributed with fio unless otherwise
8 * noted in the file itself.
9 *
ebac4655 10 * This program is free software; you can redistribute it and/or modify
8e9fe637
JA
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
ebac4655
JA
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
ebac4655
JA
24#include <unistd.h>
25#include <fcntl.h>
26#include <string.h>
9b836561 27#include <limits.h>
ebac4655
JA
28#include <signal.h>
29#include <time.h>
dbe1125e 30#include <locale.h>
36167d82 31#include <assert.h>
a5b01f1b 32#include <time.h>
ebac4655
JA
33#include <sys/stat.h>
34#include <sys/wait.h>
35#include <sys/ipc.h>
36#include <sys/shm.h>
ebac4655
JA
37#include <sys/mman.h>
38
39#include "fio.h"
210f43b3 40#include "hash.h"
2e5cdb11 41#include "smalloc.h"
4f5af7b2 42#include "verify.h"
a917a8b3 43#include "trim.h"
7c9b1bce 44#include "diskutil.h"
a696fa2a 45#include "cgroup.h"
07b3232d 46#include "profile.h"
d54a144d 47#include "lib/rand.h"
91aea6ec 48#include "memalign.h"
009b1be4 49#include "server.h"
ebac4655 50
cfc99db7
JA
51unsigned long page_mask;
52unsigned long page_size;
d529ee19 53
ebac4655 54int groupid = 0;
11e950bd
JA
55unsigned int thread_number = 0;
56unsigned int nr_process = 0;
57unsigned int nr_thread = 0;
ebac4655 58int shm_id = 0;
53cdc686 59int temp_stall_ts;
d3eeeabc 60unsigned long done_secs = 0;
ebac4655 61
d09a64a0
JA
62/*
63 * Just expose an empty list, if the OS does not support disk util stats
64 */
65#ifndef FIO_HAVE_DISK_UTIL
66FLIST_HEAD(disk_list);
67#endif
68
d3cc4ebf
JA
69unsigned long arch_flags = 0;
70
0ad5edcc
JA
71static int endian_check(void)
72{
73 union {
74 uint8_t c[8];
75 uint64_t v;
76 } u;
77 int le = 0, be = 0;
78
79 u.v = 0x12;
80 if (u.c[7] == 0x12)
81 be = 1;
82 else if (u.c[0] == 0x12)
83 le = 1;
84
85#if defined(FIO_LITTLE_ENDIAN)
86 if (be)
87 return 1;
88#elif defined(FIO_BIG_ENDIAN)
89 if (le)
90 return 1;
91#else
92 return 1;
93#endif
94
95 if (!le && !be)
96 return 1;
97
98 return 0;
99}
100
50d16976
JA
101int main(int argc, char *argv[], char *envp[])
102{
103 long ps;
104
0ad5edcc
JA
105 if (endian_check()) {
106 log_err("fio: endianness settings appear wrong.\n");
107 log_err("fio: please report this to fio@vger.kernel.org\n");
108 return 1;
109 }
110
50d16976
JA
111 arch_init(envp);
112
113 sinit();
114
115 /*
116 * We need locale for number printing, if it isn't set then just
117 * go with the US format.
118 */
119 if (!getenv("LC_NUMERIC"))
120 setlocale(LC_NUMERIC, "en_US");
121
122 ps = sysconf(_SC_PAGESIZE);
123 if (ps < 0) {
124 log_err("Failed to get page size\n");
125 return 1;
126 }
127
128 page_size = ps;
129 page_mask = ps - 1;
130
131 fio_keywords_init();
132
133 if (parse_options(argc, argv))
134 return 1;
135
2e1df07d
JA
136 if (nr_clients)
137 return fio_handle_clients();
138 else
139 return fio_backend();
50d16976 140}