blob: f0a8ee2636d015116055d69148a0f524dfc50f40 [file] [log] [blame]
Jens Axboeebac4652005-12-08 15:25:21 +01001/*
2 * fio - the flexible io tester
3 *
4 * Copyright (C) 2005 Jens Axboe <axboe@suse.de>
Jens Axboe2e1df072012-02-09 11:15:02 +01005 * Copyright (C) 2006-2012 Jens Axboe <axboe@kernel.dk>
Jens Axboeebac4652005-12-08 15:25:21 +01006 *
Jens Axboe8e9fe632006-10-24 15:11:09 +02007 * The license below covers all files distributed with fio unless otherwise
8 * noted in the file itself.
9 *
Jens Axboeebac4652005-12-08 15:25:21 +010010 * This program is free software; you can redistribute it and/or modify
Jens Axboe8e9fe632006-10-24 15:11:09 +020011 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
Jens Axboeebac4652005-12-08 15:25:21 +010013 *
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 */
Jens Axboeebac4652005-12-08 15:25:21 +010024#include <unistd.h>
25#include <fcntl.h>
26#include <string.h>
Bruce Cran9b836562011-01-08 19:49:54 +010027#include <limits.h>
Jens Axboeebac4652005-12-08 15:25:21 +010028#include <signal.h>
29#include <time.h>
Jens Axboedbe11252007-02-11 00:19:51 +010030#include <locale.h>
Jens Axboe36167d82007-02-18 05:41:31 +010031#include <assert.h>
Jens Axboea5b01f12010-11-11 09:19:49 +010032#include <time.h>
Jens Axboeebac4652005-12-08 15:25:21 +010033#include <sys/stat.h>
34#include <sys/wait.h>
35#include <sys/ipc.h>
36#include <sys/shm.h>
Jens Axboeebac4652005-12-08 15:25:21 +010037#include <sys/mman.h>
38
39#include "fio.h"
Jens Axboe210f43b2007-04-17 19:52:18 +020040#include "hash.h"
Jens Axboe2e5cdb12008-03-01 18:52:49 +010041#include "smalloc.h"
Jens Axboe4f5af7b2009-06-03 08:45:40 +020042#include "verify.h"
Jens Axboea917a8b2010-09-02 13:23:20 +020043#include "trim.h"
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020044#include "diskutil.h"
Jens Axboea696fa22009-12-04 10:05:02 +010045#include "cgroup.h"
Jens Axboe07b32322010-03-05 09:48:44 +010046#include "profile.h"
Jens Axboed54a1442010-03-25 23:07:35 +010047#include "lib/rand.h"
Jens Axboe91aea6e2011-04-25 20:46:58 +020048#include "memalign.h"
Jens Axboe009b1be2011-09-29 18:27:02 -060049#include "server.h"
Jens Axboeebac4652005-12-08 15:25:21 +010050
Jens Axboecfc99db2007-03-14 10:34:47 +010051unsigned long page_mask;
52unsigned long page_size;
Jens Axboed529ee12009-07-01 10:33:03 +020053
Jens Axboeebac4652005-12-08 15:25:21 +010054int groupid = 0;
Jens Axboe11e950b2011-10-16 21:34:14 +020055unsigned int thread_number = 0;
56unsigned int nr_process = 0;
57unsigned int nr_thread = 0;
Jens Axboeebac4652005-12-08 15:25:21 +010058int shm_id = 0;
Jens Axboe53cdc682006-10-18 11:50:58 +020059int temp_stall_ts;
Jens Axboed3eeeab2008-04-06 12:19:05 +020060unsigned long done_secs = 0;
Jens Axboeebac4652005-12-08 15:25:21 +010061
Jens Axboed09a64a2011-10-13 11:38:56 +020062/*
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
Jens Axboed3cc4eb2011-08-25 14:24:03 +020069unsigned long arch_flags = 0;
70
Jens Axboe0ad5edc2011-10-05 12:39:06 +020071static 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
Jens Axboe50d16972011-09-29 17:45:28 -0600101int main(int argc, char *argv[], char *envp[])
102{
103 long ps;
104
Jens Axboe0ad5edc2011-10-05 12:39:06 +0200105 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
Jens Axboe50d16972011-09-29 17:45:28 -0600111 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
Jens Axboe2e1df072012-02-09 11:15:02 +0100136 if (nr_clients)
137 return fio_handle_clients();
138 else
139 return fio_backend();
Jens Axboe50d16972011-09-29 17:45:28 -0600140}