blob: a408727399d388dc4ba5f993163cf13552eb0f80 [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>
Jens Axboedbe11252007-02-11 00:19:51 +010025#include <locale.h>
Jens Axboea5b01f12010-11-11 09:19:49 +010026#include <time.h>
Jens Axboeebac4652005-12-08 15:25:21 +010027
28#include "fio.h"
Jens Axboe210f43b2007-04-17 19:52:18 +020029#include "hash.h"
Jens Axboe2e5cdb12008-03-01 18:52:49 +010030#include "smalloc.h"
Jens Axboe4f5af7b2009-06-03 08:45:40 +020031#include "verify.h"
Jens Axboea917a8b2010-09-02 13:23:20 +020032#include "trim.h"
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020033#include "diskutil.h"
Jens Axboe07b32322010-03-05 09:48:44 +010034#include "profile.h"
Jens Axboed54a1442010-03-25 23:07:35 +010035#include "lib/rand.h"
Jens Axboe91aea6e2011-04-25 20:46:58 +020036#include "memalign.h"
Jens Axboe009b1be2011-09-29 18:27:02 -060037#include "server.h"
Jens Axboeebac4652005-12-08 15:25:21 +010038
Bruce Cran70781062012-04-03 18:00:00 -060039uintptr_t page_mask;
40uintptr_t page_size;
Jens Axboed529ee12009-07-01 10:33:03 +020041
Jens Axboe0ad5edc2011-10-05 12:39:06 +020042static int endian_check(void)
43{
44 union {
45 uint8_t c[8];
46 uint64_t v;
47 } u;
48 int le = 0, be = 0;
49
50 u.v = 0x12;
51 if (u.c[7] == 0x12)
52 be = 1;
53 else if (u.c[0] == 0x12)
54 le = 1;
55
Jens Axboe0dcebdf2013-01-23 15:42:16 -070056#if defined(CONFIG_LITTLE_ENDIAN)
Jens Axboe0ad5edc2011-10-05 12:39:06 +020057 if (be)
58 return 1;
Jens Axboe0dcebdf2013-01-23 15:42:16 -070059#elif defined(CONFIG_BIG_ENDIAN)
Jens Axboe0ad5edc2011-10-05 12:39:06 +020060 if (le)
61 return 1;
62#else
63 return 1;
64#endif
65
66 if (!le && !be)
67 return 1;
68
69 return 0;
70}
71
Jens Axboe50d16972011-09-29 17:45:28 -060072int main(int argc, char *argv[], char *envp[])
73{
74 long ps;
75
Jens Axboe0ad5edc2011-10-05 12:39:06 +020076 if (endian_check()) {
77 log_err("fio: endianness settings appear wrong.\n");
78 log_err("fio: please report this to fio@vger.kernel.org\n");
79 return 1;
80 }
81
Jens Axboe67bf9822013-01-10 11:23:19 +010082#if !defined(CONFIG_GETTIMEOFDAY) && !defined(CONFIG_CLOCK_GETTIME)
83#error "No available clock source!"
84#endif
85
Jens Axboe50d16972011-09-29 17:45:28 -060086 arch_init(envp);
87
88 sinit();
89
90 /*
91 * We need locale for number printing, if it isn't set then just
92 * go with the US format.
93 */
94 if (!getenv("LC_NUMERIC"))
95 setlocale(LC_NUMERIC, "en_US");
96
97 ps = sysconf(_SC_PAGESIZE);
98 if (ps < 0) {
99 log_err("Failed to get page size\n");
100 return 1;
101 }
102
103 page_size = ps;
104 page_mask = ps - 1;
105
106 fio_keywords_init();
107
108 if (parse_options(argc, argv))
109 return 1;
110
Jens Axboefa80fea2012-12-09 20:29:00 +0100111 fio_time_init();
112
Jens Axboe2e1df072012-02-09 11:15:02 +0100113 if (nr_clients)
114 return fio_handle_clients();
115 else
116 return fio_backend();
Jens Axboe50d16972011-09-29 17:45:28 -0600117}