Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * fio - the flexible io tester |
| 3 | * |
| 4 | * Copyright (C) 2005 Jens Axboe <axboe@suse.de> |
Jens Axboe | 2e1df07 | 2012-02-09 11:15:02 +0100 | [diff] [blame] | 5 | * Copyright (C) 2006-2012 Jens Axboe <axboe@kernel.dk> |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 6 | * |
Jens Axboe | 8e9fe63 | 2006-10-24 15:11:09 +0200 | [diff] [blame] | 7 | * The license below covers all files distributed with fio unless otherwise |
| 8 | * noted in the file itself. |
| 9 | * |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
Jens Axboe | 8e9fe63 | 2006-10-24 15:11:09 +0200 | [diff] [blame] | 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 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 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 24 | #include <unistd.h> |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 25 | #include <locale.h> |
Jens Axboe | a5b01f1 | 2010-11-11 09:19:49 +0100 | [diff] [blame] | 26 | #include <time.h> |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 27 | |
| 28 | #include "fio.h" |
Jens Axboe | 210f43b | 2007-04-17 19:52:18 +0200 | [diff] [blame] | 29 | #include "hash.h" |
Jens Axboe | 2e5cdb1 | 2008-03-01 18:52:49 +0100 | [diff] [blame] | 30 | #include "smalloc.h" |
Jens Axboe | 4f5af7b | 2009-06-03 08:45:40 +0200 | [diff] [blame] | 31 | #include "verify.h" |
Jens Axboe | a917a8b | 2010-09-02 13:23:20 +0200 | [diff] [blame] | 32 | #include "trim.h" |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 33 | #include "diskutil.h" |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 34 | #include "profile.h" |
Jens Axboe | d54a144 | 2010-03-25 23:07:35 +0100 | [diff] [blame] | 35 | #include "lib/rand.h" |
Jens Axboe | 91aea6e | 2011-04-25 20:46:58 +0200 | [diff] [blame] | 36 | #include "memalign.h" |
Jens Axboe | 009b1be | 2011-09-29 18:27:02 -0600 | [diff] [blame] | 37 | #include "server.h" |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 38 | |
Bruce Cran | 7078106 | 2012-04-03 18:00:00 -0600 | [diff] [blame^] | 39 | uintptr_t page_mask; |
| 40 | uintptr_t page_size; |
Jens Axboe | d529ee1 | 2009-07-01 10:33:03 +0200 | [diff] [blame] | 41 | |
Jens Axboe | 0ad5edc | 2011-10-05 12:39:06 +0200 | [diff] [blame] | 42 | static 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 | |
| 56 | #if defined(FIO_LITTLE_ENDIAN) |
| 57 | if (be) |
| 58 | return 1; |
| 59 | #elif defined(FIO_BIG_ENDIAN) |
| 60 | 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 Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 72 | int main(int argc, char *argv[], char *envp[]) |
| 73 | { |
| 74 | long ps; |
| 75 | |
Jens Axboe | 0ad5edc | 2011-10-05 12:39:06 +0200 | [diff] [blame] | 76 | 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 Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 82 | arch_init(envp); |
| 83 | |
| 84 | sinit(); |
| 85 | |
| 86 | /* |
| 87 | * We need locale for number printing, if it isn't set then just |
| 88 | * go with the US format. |
| 89 | */ |
| 90 | if (!getenv("LC_NUMERIC")) |
| 91 | setlocale(LC_NUMERIC, "en_US"); |
| 92 | |
| 93 | ps = sysconf(_SC_PAGESIZE); |
| 94 | if (ps < 0) { |
| 95 | log_err("Failed to get page size\n"); |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | page_size = ps; |
| 100 | page_mask = ps - 1; |
| 101 | |
| 102 | fio_keywords_init(); |
| 103 | |
| 104 | if (parse_options(argc, argv)) |
| 105 | return 1; |
| 106 | |
Jens Axboe | 2e1df07 | 2012-02-09 11:15:02 +0100 | [diff] [blame] | 107 | if (nr_clients) |
| 108 | return fio_handle_clients(); |
| 109 | else |
| 110 | return fio_backend(); |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 111 | } |