blob: d85f956f7c552a7e78b5fc18fdec1e6f9a17f372 [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 Axboeaae22ca2006-09-05 10:46:22 +02005 * Copyright (C) 2006 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>
Jens Axboeebac4652005-12-08 15:25:21 +010027#include <signal.h>
28#include <time.h>
Jens Axboedbe11252007-02-11 00:19:51 +010029#include <locale.h>
Jens Axboe36167d82007-02-18 05:41:31 +010030#include <assert.h>
Jens Axboeebac4652005-12-08 15:25:21 +010031#include <sys/stat.h>
32#include <sys/wait.h>
33#include <sys/ipc.h>
34#include <sys/shm.h>
Jens Axboeebac4652005-12-08 15:25:21 +010035#include <sys/mman.h>
36
37#include "fio.h"
Jens Axboe210f43b2007-04-17 19:52:18 +020038#include "hash.h"
Jens Axboeebac4652005-12-08 15:25:21 +010039
Jens Axboecfc99db2007-03-14 10:34:47 +010040unsigned long page_mask;
41unsigned long page_size;
Jens Axboe29d610e2007-02-06 13:25:33 +010042#define ALIGN(buf) \
43 (char *) (((unsigned long) (buf) + page_mask) & ~page_mask)
Jens Axboeebac4652005-12-08 15:25:21 +010044
45int groupid = 0;
46int thread_number = 0;
Jens Axboe9cedf162007-03-12 11:29:30 +010047int nr_process = 0;
48int nr_thread = 0;
Jens Axboeebac4652005-12-08 15:25:21 +010049int shm_id = 0;
Jens Axboe53cdc682006-10-18 11:50:58 +020050int temp_stall_ts;
Jens Axboeebac4652005-12-08 15:25:21 +010051
Jens Axboe07739b52007-03-08 20:25:46 +010052static struct fio_sem *startup_sem;
Jens Axboe6ce15a32007-01-12 09:04:41 +010053static volatile int fio_abort;
Jens Axboe437c9b72007-02-13 18:20:37 +010054static int exit_value;
Jens Axboeebac4652005-12-08 15:25:21 +010055
Jens Axboebb3884d2007-01-17 17:23:11 +110056struct io_log *agg_io_log[2];
57
Jens Axboeebac4652005-12-08 15:25:21 +010058#define TERMINATE_ALL (-1)
Jens Axboe75154842006-06-01 13:56:09 +020059#define JOB_START_TIMEOUT (5 * 1000)
Jens Axboeebac4652005-12-08 15:25:21 +010060
Jens Axboe6ce15a32007-01-12 09:04:41 +010061static inline void td_set_runstate(struct thread_data *td, int runstate)
62{
63 td->runstate = runstate;
64}
65
Jens Axboe390c40e2007-03-05 12:35:29 +010066static void terminate_threads(int group_id)
Jens Axboeebac4652005-12-08 15:25:21 +010067{
Jens Axboe34572e22006-10-20 09:33:18 +020068 struct thread_data *td;
Jens Axboeebac4652005-12-08 15:25:21 +010069 int i;
70
Jens Axboe34572e22006-10-20 09:33:18 +020071 for_each_td(td, i) {
Jens Axboeebac4652005-12-08 15:25:21 +010072 if (group_id == TERMINATE_ALL || groupid == td->groupid) {
Jens Axboeef5fffa2007-04-17 13:42:47 +020073 if (td->runstate <= TD_RUNNING)
Jens Axboec1302d42007-03-05 20:18:31 +010074 kill(td->pid, SIGQUIT);
Jens Axboeebac4652005-12-08 15:25:21 +010075 td->terminate = 1;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010076 td->o.start_delay = 0;
Jens Axboeebac4652005-12-08 15:25:21 +010077 }
78 }
79}
80
81static void sig_handler(int sig)
82{
83 switch (sig) {
84 case SIGALRM:
85 update_io_ticks();
86 disk_util_timer_arm();
87 print_thread_status();
88 break;
89 default:
Jens Axboe6ce15a32007-01-12 09:04:41 +010090 printf("\nfio: terminating on signal %d\n", sig);
Jens Axboeebac4652005-12-08 15:25:21 +010091 fflush(stdout);
Jens Axboe390c40e2007-03-05 12:35:29 +010092 terminate_threads(TERMINATE_ALL);
Jens Axboeebac4652005-12-08 15:25:21 +010093 break;
94 }
95}
96
Jens Axboe906c8d72006-06-13 09:37:56 +020097/*
Jens Axboe906c8d72006-06-13 09:37:56 +020098 * Check if we are above the minimum rate given.
99 */
Jens Axboeebac4652005-12-08 15:25:21 +0100100static int check_min_rate(struct thread_data *td, struct timeval *now)
101{
Jens Axboe09042002007-02-23 10:56:22 +0100102 unsigned long long bytes = 0;
Jens Axboe4e991c22007-03-15 11:41:11 +0100103 unsigned long iops = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100104 unsigned long spent;
105 unsigned long rate;
Jens Axboeebac4652005-12-08 15:25:21 +0100106
107 /*
Jens Axboe780bf1a2007-02-28 11:13:49 +0100108 * No minimum rate set, always ok
109 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100110 if (!td->o.ratemin && !td->o.rate_iops_min)
Jens Axboe780bf1a2007-02-28 11:13:49 +0100111 return 0;
112
113 /*
Jens Axboeebac4652005-12-08 15:25:21 +0100114 * allow a 2 second settle period in the beginning
115 */
116 if (mtime_since(&td->start, now) < 2000)
117 return 0;
118
Jens Axboe4e991c22007-03-15 11:41:11 +0100119 if (td_read(td)) {
120 iops += td->io_blocks[DDIR_READ];
Jens Axboe09042002007-02-23 10:56:22 +0100121 bytes += td->this_io_bytes[DDIR_READ];
Jens Axboe4e991c22007-03-15 11:41:11 +0100122 }
123 if (td_write(td)) {
124 iops += td->io_blocks[DDIR_WRITE];
Jens Axboe09042002007-02-23 10:56:22 +0100125 bytes += td->this_io_bytes[DDIR_WRITE];
Jens Axboe4e991c22007-03-15 11:41:11 +0100126 }
Jens Axboe09042002007-02-23 10:56:22 +0100127
Jens Axboeebac4652005-12-08 15:25:21 +0100128 /*
129 * if rate blocks is set, sample is running
130 */
Jens Axboe4e991c22007-03-15 11:41:11 +0100131 if (td->rate_bytes || td->rate_blocks) {
Jens Axboeebac4652005-12-08 15:25:21 +0100132 spent = mtime_since(&td->lastrate, now);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100133 if (spent < td->o.ratecycle)
Jens Axboeebac4652005-12-08 15:25:21 +0100134 return 0;
135
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100136 if (td->o.rate) {
Jens Axboe4e991c22007-03-15 11:41:11 +0100137 /*
138 * check bandwidth specified rate
139 */
140 if (bytes < td->rate_bytes) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100141 log_err("%s: min rate %u not met\n", td->o.name, td->o.ratemin);
Jens Axboe413dd452007-02-23 09:26:09 +0100142 return 1;
Jens Axboe4e991c22007-03-15 11:41:11 +0100143 } else {
144 rate = (bytes - td->rate_bytes) / spent;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100145 if (rate < td->o.ratemin || bytes < td->rate_bytes) {
146 log_err("%s: min rate %u not met, got %luKiB/sec\n", td->o.name, td->o.ratemin, rate);
Jens Axboe4e991c22007-03-15 11:41:11 +0100147 return 1;
148 }
149 }
150 } else {
151 /*
152 * checks iops specified rate
153 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100154 if (iops < td->o.rate_iops) {
155 log_err("%s: min iops rate %u not met\n", td->o.name, td->o.rate_iops);
Jens Axboe4e991c22007-03-15 11:41:11 +0100156 return 1;
157 } else {
158 rate = (iops - td->rate_blocks) / spent;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100159 if (rate < td->o.rate_iops_min || iops < td->rate_blocks) {
160 log_err("%s: min iops rate %u not met, got %lu\n", td->o.name, td->o.rate_iops_min, rate);
Jens Axboe4e991c22007-03-15 11:41:11 +0100161 }
Jens Axboe413dd452007-02-23 09:26:09 +0100162 }
Jens Axboeebac4652005-12-08 15:25:21 +0100163 }
164 }
165
Jens Axboe09042002007-02-23 10:56:22 +0100166 td->rate_bytes = bytes;
Jens Axboe4e991c22007-03-15 11:41:11 +0100167 td->rate_blocks = iops;
Jens Axboeebac4652005-12-08 15:25:21 +0100168 memcpy(&td->lastrate, now, sizeof(*now));
169 return 0;
170}
171
172static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
173{
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100174 if (!td->o.timeout)
Jens Axboeebac4652005-12-08 15:25:21 +0100175 return 0;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100176 if (mtime_since(&td->epoch, t) >= td->o.timeout * 1000)
Jens Axboeebac4652005-12-08 15:25:21 +0100177 return 1;
178
179 return 0;
180}
181
Jens Axboe906c8d72006-06-13 09:37:56 +0200182/*
183 * When job exits, we can cancel the in-flight IO if we are using async
184 * io. Attempt to do so.
185 */
Jens Axboeebac4652005-12-08 15:25:21 +0100186static void cleanup_pending_aio(struct thread_data *td)
187{
Jens Axboeebac4652005-12-08 15:25:21 +0100188 struct list_head *entry, *n;
Jens Axboeebac4652005-12-08 15:25:21 +0100189 struct io_u *io_u;
190 int r;
191
192 /*
193 * get immediately available events, if any
194 */
Jens Axboed7762cf2007-02-23 12:34:57 +0100195 r = io_u_queued_complete(td, 0);
Jens Axboeb2fdda42007-02-20 20:52:51 +0100196 if (r < 0)
197 return;
Jens Axboeebac4652005-12-08 15:25:21 +0100198
199 /*
200 * now cancel remaining active events
201 */
Jens Axboe2866c822006-10-09 15:57:48 +0200202 if (td->io_ops->cancel) {
Jens Axboeebac4652005-12-08 15:25:21 +0100203 list_for_each_safe(entry, n, &td->io_u_busylist) {
204 io_u = list_entry(entry, struct io_u, list);
205
Jens Axboe0c6e7512007-02-22 11:19:39 +0100206 /*
207 * if the io_u isn't in flight, then that generally
208 * means someone leaked an io_u. complain but fix
209 * it up, so we don't stall here.
210 */
211 if ((io_u->flags & IO_U_F_FLIGHT) == 0) {
212 log_err("fio: non-busy IO on busy list\n");
Jens Axboeebac4652005-12-08 15:25:21 +0100213 put_io_u(td, io_u);
Jens Axboe0c6e7512007-02-22 11:19:39 +0100214 } else {
215 r = td->io_ops->cancel(td, io_u);
216 if (!r)
217 put_io_u(td, io_u);
218 }
Jens Axboeebac4652005-12-08 15:25:21 +0100219 }
220 }
221
Jens Axboe97601022007-02-18 12:47:29 +0100222 if (td->cur_depth)
Jens Axboed7762cf2007-02-23 12:34:57 +0100223 r = io_u_queued_complete(td, td->cur_depth);
Jens Axboeebac4652005-12-08 15:25:21 +0100224}
225
Jens Axboe906c8d72006-06-13 09:37:56 +0200226/*
Jens Axboe858a3d42006-10-24 14:54:44 +0200227 * Helper to handle the final sync of a file. Works just like the normal
228 * io path, just does everything sync.
229 */
230static int fio_io_sync(struct thread_data *td, struct fio_file *f)
231{
232 struct io_u *io_u = __get_io_u(td);
Jens Axboe858a3d42006-10-24 14:54:44 +0200233 int ret;
234
235 if (!io_u)
236 return 1;
237
238 io_u->ddir = DDIR_SYNC;
239 io_u->file = f;
240
241 if (td_io_prep(td, io_u)) {
242 put_io_u(td, io_u);
243 return 1;
244 }
245
Jens Axboe755200a2007-02-19 13:08:12 +0100246requeue:
Jens Axboe858a3d42006-10-24 14:54:44 +0200247 ret = td_io_queue(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100248 if (ret < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100249 td_verror(td, io_u->error, "td_io_queue");
Jens Axboe858a3d42006-10-24 14:54:44 +0200250 put_io_u(td, io_u);
Jens Axboe858a3d42006-10-24 14:54:44 +0200251 return 1;
Jens Axboe36167d82007-02-18 05:41:31 +0100252 } else if (ret == FIO_Q_QUEUED) {
Jens Axboed7762cf2007-02-23 12:34:57 +0100253 if (io_u_queued_complete(td, 1) < 0)
Jens Axboe36167d82007-02-18 05:41:31 +0100254 return 1;
Jens Axboe36167d82007-02-18 05:41:31 +0100255 } else if (ret == FIO_Q_COMPLETED) {
256 if (io_u->error) {
Jens Axboee1161c32007-02-22 19:36:48 +0100257 td_verror(td, io_u->error, "td_io_queue");
Jens Axboe36167d82007-02-18 05:41:31 +0100258 return 1;
259 }
Jens Axboe858a3d42006-10-24 14:54:44 +0200260
Jens Axboed7762cf2007-02-23 12:34:57 +0100261 if (io_u_sync_complete(td, io_u) < 0)
Jens Axboeb2fdda42007-02-20 20:52:51 +0100262 return 1;
Jens Axboe755200a2007-02-19 13:08:12 +0100263 } else if (ret == FIO_Q_BUSY) {
264 if (td_io_commit(td))
265 return 1;
266 goto requeue;
Jens Axboe858a3d42006-10-24 14:54:44 +0200267 }
268
269 return 0;
270}
271
272/*
Jens Axboe34403fb2007-03-02 21:43:25 +0100273 * The main verify engine. Runs over the writes we previously submitted,
Jens Axboe906c8d72006-06-13 09:37:56 +0200274 * reads the blocks back in, and checks the crc/md5 of the data.
275 */
Jens Axboe1e97cce2006-12-05 11:44:16 +0100276static void do_verify(struct thread_data *td)
Jens Axboeebac4652005-12-08 15:25:21 +0100277{
Jens Axboe53cdc682006-10-18 11:50:58 +0200278 struct fio_file *f;
Jens Axboe36167d82007-02-18 05:41:31 +0100279 struct io_u *io_u;
Jens Axboeaf52b342007-03-13 10:07:47 +0100280 int ret, min_events;
281 unsigned int i;
Jens Axboee5b401d2006-10-18 16:03:40 +0200282
283 /*
284 * sync io first and invalidate cache, to make sure we really
285 * read from disk.
286 */
287 for_each_file(td, f, i) {
Jens Axboe3d7b4852007-03-13 14:50:28 +0100288 if (!(f->flags & FIO_FILE_OPEN))
289 continue;
Jens Axboeb2fdda42007-02-20 20:52:51 +0100290 if (fio_io_sync(td, f))
291 break;
292 if (file_invalidate_cache(td, f))
293 break;
Jens Axboee5b401d2006-10-18 16:03:40 +0200294 }
Jens Axboeebac4652005-12-08 15:25:21 +0100295
Jens Axboeb2fdda42007-02-20 20:52:51 +0100296 if (td->error)
297 return;
298
Jens Axboeebac4652005-12-08 15:25:21 +0100299 td_set_runstate(td, TD_VERIFYING);
300
Jens Axboe36167d82007-02-18 05:41:31 +0100301 io_u = NULL;
302 while (!td->terminate) {
Jens Axboe54517922007-03-05 10:06:06 +0100303 int ret2;
304
Jens Axboeebac4652005-12-08 15:25:21 +0100305 io_u = __get_io_u(td);
306 if (!io_u)
307 break;
308
Jens Axboe069c2912007-02-21 23:02:39 +0100309 if (runtime_exceeded(td, &io_u->start_time)) {
310 put_io_u(td, io_u);
Jens Axboe53cdc682006-10-18 11:50:58 +0200311 break;
Jens Axboe069c2912007-02-21 23:02:39 +0100312 }
Jens Axboe53cdc682006-10-18 11:50:58 +0200313
Jens Axboe069c2912007-02-21 23:02:39 +0100314 if (get_next_verify(td, io_u)) {
315 put_io_u(td, io_u);
Jens Axboeebac4652005-12-08 15:25:21 +0100316 break;
Jens Axboe069c2912007-02-21 23:02:39 +0100317 }
Jens Axboeebac4652005-12-08 15:25:21 +0100318
Jens Axboe069c2912007-02-21 23:02:39 +0100319 if (td_io_prep(td, io_u)) {
320 put_io_u(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100321 break;
Jens Axboe069c2912007-02-21 23:02:39 +0100322 }
Jens Axboed7762cf2007-02-23 12:34:57 +0100323
324 io_u->end_io = verify_io_u;
Jens Axboe36167d82007-02-18 05:41:31 +0100325
Jens Axboe11786802007-03-05 18:33:22 +0100326 ret = td_io_queue(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100327 switch (ret) {
328 case FIO_Q_COMPLETED:
329 if (io_u->error)
Jens Axboe22819ec2007-02-18 07:47:14 +0100330 ret = -io_u->error;
Jens Axboe9e9d1642007-03-12 09:37:46 +0100331 else if (io_u->resid) {
Jens Axboe36167d82007-02-18 05:41:31 +0100332 int bytes = io_u->xfer_buflen - io_u->resid;
Jens Axboed460eb32007-04-16 21:39:33 +0200333 struct fio_file *f = io_u->file;
Jens Axboe36167d82007-02-18 05:41:31 +0100334
Jens Axboe9e9d1642007-03-12 09:37:46 +0100335 /*
336 * zero read, fail
337 */
338 if (!bytes) {
339 td_verror(td, ENODATA, "full resid");
340 put_io_u(td, io_u);
341 break;
342 }
Jens Axboe8400d9b2007-03-28 11:10:09 +0200343
Jens Axboe36167d82007-02-18 05:41:31 +0100344 io_u->xfer_buflen = io_u->resid;
345 io_u->xfer_buf += bytes;
Jens Axboe8400d9b2007-03-28 11:10:09 +0200346 io_u->offset += bytes;
Jens Axboed460eb32007-04-16 21:39:33 +0200347 f->last_completed_pos = io_u->offset;
Jens Axboe8400d9b2007-03-28 11:10:09 +0200348
Jens Axboe30061b92007-04-17 13:31:34 +0200349 td->ts.short_io_u[io_u->ddir]++;
350
Jens Axboed460eb32007-04-16 21:39:33 +0200351 if (io_u->offset == f->real_file_size)
Jens Axboe8400d9b2007-03-28 11:10:09 +0200352 goto sync_done;
353
Jens Axboe11786802007-03-05 18:33:22 +0100354 requeue_io_u(td, &io_u);
355 } else {
Jens Axboe8400d9b2007-03-28 11:10:09 +0200356sync_done:
Jens Axboe11786802007-03-05 18:33:22 +0100357 ret = io_u_sync_complete(td, io_u);
358 if (ret < 0)
359 break;
Jens Axboe36167d82007-02-18 05:41:31 +0100360 }
Jens Axboe36167d82007-02-18 05:41:31 +0100361 continue;
362 case FIO_Q_QUEUED:
363 break;
Jens Axboe755200a2007-02-19 13:08:12 +0100364 case FIO_Q_BUSY:
365 requeue_io_u(td, &io_u);
Jens Axboe54517922007-03-05 10:06:06 +0100366 ret2 = td_io_commit(td);
367 if (ret2 < 0)
368 ret = ret2;
Jens Axboe755200a2007-02-19 13:08:12 +0100369 break;
Jens Axboe36167d82007-02-18 05:41:31 +0100370 default:
371 assert(ret < 0);
Jens Axboee1161c32007-02-22 19:36:48 +0100372 td_verror(td, -ret, "td_io_queue");
Jens Axboeebac4652005-12-08 15:25:21 +0100373 break;
374 }
375
Jens Axboe99784632007-02-19 10:06:17 +0100376 if (ret < 0 || td->error)
Jens Axboeebac4652005-12-08 15:25:21 +0100377 break;
378
Jens Axboe3af6ef32007-02-18 06:57:43 +0100379 /*
380 * if we can queue more, do so. but check if there are
381 * completed io_u's first.
382 */
Jens Axboe97601022007-02-18 12:47:29 +0100383 min_events = 0;
Jens Axboee916b392007-02-20 14:37:26 +0100384 if (queue_full(td) || ret == FIO_Q_BUSY) {
Jens Axboe3af6ef32007-02-18 06:57:43 +0100385 min_events = 1;
Jens Axboe3af6ef32007-02-18 06:57:43 +0100386
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100387 if (td->cur_depth > td->o.iodepth_low)
388 min_events = td->cur_depth - td->o.iodepth_low;
Jens Axboee916b392007-02-20 14:37:26 +0100389 }
390
Jens Axboe3af6ef32007-02-18 06:57:43 +0100391 /*
392 * Reap required number of io units, if any, and do the
393 * verification on them through the callback handler
394 */
Jens Axboed7762cf2007-02-23 12:34:57 +0100395 if (io_u_queued_complete(td, min_events) < 0)
Jens Axboe36167d82007-02-18 05:41:31 +0100396 break;
397 }
398
Jens Axboec01c0392007-02-26 12:43:42 +0100399 if (!td->error) {
400 min_events = td->cur_depth;
401
402 if (min_events)
403 ret = io_u_queued_complete(td, min_events);
404 } else
Jens Axboeebac4652005-12-08 15:25:21 +0100405 cleanup_pending_aio(td);
406
407 td_set_runstate(td, TD_RUNNING);
408}
409
Jens Axboe32cd46a2006-06-07 13:40:40 +0200410/*
Jens Axboe906c8d72006-06-13 09:37:56 +0200411 * Main IO worker function. It retrieves io_u's to process and queues
Jens Axboe32cd46a2006-06-07 13:40:40 +0200412 * and reaps them, checking for rate and errors along the way.
413 */
Jens Axboeebac4652005-12-08 15:25:21 +0100414static void do_io(struct thread_data *td)
415{
Jens Axboe02bcaa82006-11-24 10:42:00 +0100416 struct timeval s;
Jens Axboeebac4652005-12-08 15:25:21 +0100417 unsigned long usec;
Jens Axboeaf52b342007-03-13 10:07:47 +0100418 unsigned int i;
419 int ret = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100420
Jens Axboe5853e5a2006-06-08 14:41:05 +0200421 td_set_runstate(td, TD_RUNNING);
422
Jens Axboe7bb48f82007-03-27 15:30:28 +0200423 while ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) {
Jens Axboe97601022007-02-18 12:47:29 +0100424 struct timeval comp_time;
425 long bytes_done = 0;
Jens Axboe84585002006-10-19 20:26:22 +0200426 int min_evts = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100427 struct io_u *io_u;
Jens Axboe54517922007-03-05 10:06:06 +0100428 int ret2;
Jens Axboeebac4652005-12-08 15:25:21 +0100429
430 if (td->terminate)
431 break;
432
Jens Axboe3d7c3912007-02-19 13:16:12 +0100433 io_u = get_io_u(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100434 if (!io_u)
435 break;
436
437 memcpy(&s, &io_u->start_time, sizeof(s));
Jens Axboe97601022007-02-18 12:47:29 +0100438
439 if (runtime_exceeded(td, &s)) {
440 put_io_u(td, io_u);
441 break;
442 }
Jens Axboe36167d82007-02-18 05:41:31 +0100443
Jens Axboe11786802007-03-05 18:33:22 +0100444 ret = td_io_queue(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100445 switch (ret) {
446 case FIO_Q_COMPLETED:
Jens Axboe54517922007-03-05 10:06:06 +0100447 if (io_u->error)
448 ret = -io_u->error;
Jens Axboe9e9d1642007-03-12 09:37:46 +0100449 else if (io_u->resid) {
Jens Axboe36167d82007-02-18 05:41:31 +0100450 int bytes = io_u->xfer_buflen - io_u->resid;
Jens Axboed460eb32007-04-16 21:39:33 +0200451 struct fio_file *f = io_u->file;
Jens Axboe36167d82007-02-18 05:41:31 +0100452
Jens Axboe9e9d1642007-03-12 09:37:46 +0100453 /*
454 * zero read, fail
455 */
456 if (!bytes) {
457 td_verror(td, ENODATA, "full resid");
458 put_io_u(td, io_u);
459 break;
460 }
461
Jens Axboe36167d82007-02-18 05:41:31 +0100462 io_u->xfer_buflen = io_u->resid;
463 io_u->xfer_buf += bytes;
Jens Axboe5a7c5682007-03-28 11:07:20 +0200464 io_u->offset += bytes;
Jens Axboed460eb32007-04-16 21:39:33 +0200465 f->last_completed_pos = io_u->offset;
Jens Axboe5a7c5682007-03-28 11:07:20 +0200466
Jens Axboe30061b92007-04-17 13:31:34 +0200467 td->ts.short_io_u[io_u->ddir]++;
468
Jens Axboed460eb32007-04-16 21:39:33 +0200469 if (io_u->offset == f->real_file_size)
Jens Axboe5a7c5682007-03-28 11:07:20 +0200470 goto sync_done;
471
Jens Axboe11786802007-03-05 18:33:22 +0100472 requeue_io_u(td, &io_u);
473 } else {
Jens Axboe5a7c5682007-03-28 11:07:20 +0200474sync_done:
Jens Axboe11786802007-03-05 18:33:22 +0100475 fio_gettime(&comp_time, NULL);
476 bytes_done = io_u_sync_complete(td, io_u);
477 if (bytes_done < 0)
478 ret = bytes_done;
Jens Axboe36167d82007-02-18 05:41:31 +0100479 }
Jens Axboe36167d82007-02-18 05:41:31 +0100480 break;
481 case FIO_Q_QUEUED:
Jens Axboe7e77dd02007-02-20 10:57:34 +0100482 /*
483 * if the engine doesn't have a commit hook,
484 * the io_u is really queued. if it does have such
485 * a hook, it has to call io_u_queued() itself.
486 */
487 if (td->io_ops->commit == NULL)
488 io_u_queued(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100489 break;
Jens Axboe755200a2007-02-19 13:08:12 +0100490 case FIO_Q_BUSY:
491 requeue_io_u(td, &io_u);
Jens Axboe54517922007-03-05 10:06:06 +0100492 ret2 = td_io_commit(td);
493 if (ret2 < 0)
494 ret = ret2;
Jens Axboe755200a2007-02-19 13:08:12 +0100495 break;
Jens Axboe36167d82007-02-18 05:41:31 +0100496 default:
497 assert(ret < 0);
498 put_io_u(td, io_u);
499 break;
Jens Axboeebac4652005-12-08 15:25:21 +0100500 }
501
Jens Axboe99784632007-02-19 10:06:17 +0100502 if (ret < 0 || td->error)
Jens Axboe36167d82007-02-18 05:41:31 +0100503 break;
504
Jens Axboe97601022007-02-18 12:47:29 +0100505 /*
506 * See if we need to complete some commands
507 */
Jens Axboe755200a2007-02-19 13:08:12 +0100508 if (ret == FIO_Q_QUEUED || ret == FIO_Q_BUSY) {
Jens Axboe97601022007-02-18 12:47:29 +0100509 min_evts = 0;
Jens Axboee916b392007-02-20 14:37:26 +0100510 if (queue_full(td) || ret == FIO_Q_BUSY) {
Jens Axboe36167d82007-02-18 05:41:31 +0100511 min_evts = 1;
Jens Axboeebac4652005-12-08 15:25:21 +0100512
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100513 if (td->cur_depth > td->o.iodepth_low)
514 min_evts = td->cur_depth - td->o.iodepth_low;
Jens Axboee916b392007-02-20 14:37:26 +0100515 }
516
Jens Axboe97601022007-02-18 12:47:29 +0100517 fio_gettime(&comp_time, NULL);
Jens Axboed7762cf2007-02-23 12:34:57 +0100518 bytes_done = io_u_queued_complete(td, min_evts);
Jens Axboe97601022007-02-18 12:47:29 +0100519 if (bytes_done < 0)
Jens Axboe36167d82007-02-18 05:41:31 +0100520 break;
Jens Axboeebac4652005-12-08 15:25:21 +0100521 }
522
Jens Axboe97601022007-02-18 12:47:29 +0100523 if (!bytes_done)
524 continue;
525
Jens Axboeebac4652005-12-08 15:25:21 +0100526 /*
527 * the rate is batched for now, it should work for batches
528 * of completions except the very first one which may look
529 * a little bursty
530 */
Jens Axboe97601022007-02-18 12:47:29 +0100531 usec = utime_since(&s, &comp_time);
Jens Axboeebac4652005-12-08 15:25:21 +0100532
Jens Axboe413dd452007-02-23 09:26:09 +0100533 rate_throttle(td, usec, bytes_done);
Jens Axboeebac4652005-12-08 15:25:21 +0100534
Jens Axboe97601022007-02-18 12:47:29 +0100535 if (check_min_rate(td, &comp_time)) {
Jens Axboe98aa62d2006-11-07 14:16:19 +0100536 if (exitall_on_terminate)
Jens Axboe390c40e2007-03-05 12:35:29 +0100537 terminate_threads(td->groupid);
Jens Axboee1161c32007-02-22 19:36:48 +0100538 td_verror(td, ENODATA, "check_min_rate");
Jens Axboeebac4652005-12-08 15:25:21 +0100539 break;
540 }
541
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100542 if (td->o.thinktime) {
Jens Axboe9c1f7432007-01-03 20:43:19 +0100543 unsigned long long b;
544
545 b = td->io_blocks[0] + td->io_blocks[1];
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100546 if (!(b % td->o.thinktime_blocks)) {
Jens Axboe48097d52007-02-17 06:30:44 +0100547 int left;
548
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100549 if (td->o.thinktime_spin)
550 __usec_sleep(td->o.thinktime_spin);
Jens Axboe48097d52007-02-17 06:30:44 +0100551
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100552 left = td->o.thinktime - td->o.thinktime_spin;
Jens Axboe48097d52007-02-17 06:30:44 +0100553 if (left)
554 usec_sleep(td, left);
555 }
Jens Axboe9c1f7432007-01-03 20:43:19 +0100556 }
Jens Axboeebac4652005-12-08 15:25:21 +0100557 }
558
Jens Axboe4d2413c2006-11-23 11:58:59 +0100559 if (!td->error) {
Jens Axboe3d7c3912007-02-19 13:16:12 +0100560 struct fio_file *f;
561
Jens Axboec01c0392007-02-26 12:43:42 +0100562 i = td->cur_depth;
563 if (i)
564 ret = io_u_queued_complete(td, i);
Jens Axboeebac4652005-12-08 15:25:21 +0100565
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100566 if (should_fsync(td) && td->o.end_fsync) {
Jens Axboe84585002006-10-19 20:26:22 +0200567 td_set_runstate(td, TD_FSYNCING);
Jens Axboe3d7b4852007-03-13 14:50:28 +0100568
569 for_each_file(td, f, i) {
570 if (!(f->flags & FIO_FILE_OPEN))
571 continue;
Jens Axboe858a3d42006-10-24 14:54:44 +0200572 fio_io_sync(td, f);
Jens Axboe3d7b4852007-03-13 14:50:28 +0100573 }
Jens Axboe84585002006-10-19 20:26:22 +0200574 }
Jens Axboec01c0392007-02-26 12:43:42 +0100575 } else
576 cleanup_pending_aio(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100577}
578
Jens Axboeebac4652005-12-08 15:25:21 +0100579static void cleanup_io_u(struct thread_data *td)
580{
581 struct list_head *entry, *n;
582 struct io_u *io_u;
583
584 list_for_each_safe(entry, n, &td->io_u_freelist) {
585 io_u = list_entry(entry, struct io_u, list);
586
587 list_del(&io_u->list);
588 free(io_u);
589 }
590
Jens Axboe2f9ade32006-10-20 11:25:52 +0200591 free_io_mem(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100592}
593
Jens Axboe6b9cea22006-10-30 17:00:24 +0100594/*
595 * "randomly" fill the buffer contents
596 */
Jens Axboee9459e52007-04-17 15:46:32 +0200597static void fill_io_buf(struct thread_data *td, struct io_u *io_u, int max_bs)
Jens Axboe6b9cea22006-10-30 17:00:24 +0100598{
Jens Axboe210f43b2007-04-17 19:52:18 +0200599 long *ptr = io_u->buf;
Jens Axboe6b9cea22006-10-30 17:00:24 +0100600
Jens Axboee9459e52007-04-17 15:46:32 +0200601 if (!td->o.zero_buffers) {
602 while ((void *) ptr - io_u->buf < max_bs) {
Jens Axboe210f43b2007-04-17 19:52:18 +0200603 *ptr = rand() * GOLDEN_RATIO_PRIME;
Jens Axboee9459e52007-04-17 15:46:32 +0200604 ptr++;
605 }
606 } else
607 memset(ptr, 0, max_bs);
Jens Axboe6b9cea22006-10-30 17:00:24 +0100608}
609
Jens Axboeebac4652005-12-08 15:25:21 +0100610static int init_io_u(struct thread_data *td)
611{
Jens Axboe2b4ce342007-03-21 10:32:54 +0100612 unsigned long long buf_size;
Jens Axboeebac4652005-12-08 15:25:21 +0100613 struct io_u *io_u;
Jens Axboea00735e2006-11-03 08:58:08 +0100614 unsigned int max_bs;
Jens Axboeebac4652005-12-08 15:25:21 +0100615 int i, max_units;
616 char *p;
617
Jens Axboe2866c822006-10-09 15:57:48 +0200618 if (td->io_ops->flags & FIO_SYNCIO)
Jens Axboeebac4652005-12-08 15:25:21 +0100619 max_units = 1;
620 else
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100621 max_units = td->o.iodepth;
Jens Axboeebac4652005-12-08 15:25:21 +0100622
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100623 max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
Jens Axboe2b4ce342007-03-21 10:32:54 +0100624 buf_size = (unsigned long long) max_bs * (unsigned long long) max_units;
625 buf_size += page_mask;
626 if (buf_size != (size_t) buf_size) {
627 log_err("fio: IO memory too large. Reduce max_bs or iodepth\n");
628 return 1;
629 }
630
631 td->orig_buffer_size = buf_size;
Jens Axboe74b025b2006-12-19 15:18:14 +0100632
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100633 if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE)
634 td->orig_buffer_size = (td->orig_buffer_size + td->o.hugepage_size - 1) & ~(td->o.hugepage_size - 1);
Jens Axboe4afbf662007-03-20 10:33:11 +0100635 else if (td->orig_buffer_size & page_mask)
636 td->orig_buffer_size = (td->orig_buffer_size + page_mask) & ~page_mask;
Jens Axboeebac4652005-12-08 15:25:21 +0100637
Jens Axboe2f9ade32006-10-20 11:25:52 +0200638 if (allocate_io_mem(td))
639 return 1;
Jens Axboeebac4652005-12-08 15:25:21 +0100640
Jens Axboeebac4652005-12-08 15:25:21 +0100641 p = ALIGN(td->orig_buffer);
642 for (i = 0; i < max_units; i++) {
643 io_u = malloc(sizeof(*io_u));
644 memset(io_u, 0, sizeof(*io_u));
645 INIT_LIST_HEAD(&io_u->list);
646
Jens Axboea00735e2006-11-03 08:58:08 +0100647 io_u->buf = p + max_bs * i;
Jens Axboee9459e52007-04-17 15:46:32 +0200648
Jens Axboe660a1cb2007-04-17 15:37:47 +0200649 if (td_write(td))
Jens Axboee9459e52007-04-17 15:46:32 +0200650 fill_io_buf(td, io_u, max_bs);
Jens Axboe6b9cea22006-10-30 17:00:24 +0100651
Jens Axboeb1ff3402006-02-17 11:35:58 +0100652 io_u->index = i;
Jens Axboe0c6e7512007-02-22 11:19:39 +0100653 io_u->flags = IO_U_F_FREE;
Jens Axboeebac4652005-12-08 15:25:21 +0100654 list_add(&io_u->list, &td->io_u_freelist);
655 }
656
Jens Axboe433afcb2007-02-22 10:39:01 +0100657 io_u_init_timeout();
658
Jens Axboeebac4652005-12-08 15:25:21 +0100659 return 0;
660}
661
Jens Axboeda867742006-06-06 10:39:10 -0700662static int switch_ioscheduler(struct thread_data *td)
663{
664 char tmp[256], tmp2[128];
665 FILE *f;
666 int ret;
667
Jens Axboeba0fbe12007-03-09 14:34:23 +0100668 if (td->io_ops->flags & FIO_DISKLESSIO)
Jens Axboef48b4672006-10-27 11:30:07 +0200669 return 0;
670
Jens Axboeda867742006-06-06 10:39:10 -0700671 sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
672
673 f = fopen(tmp, "r+");
674 if (!f) {
Jens Axboecbf5c1d2007-04-16 12:56:00 +0200675 if (errno == ENOENT) {
676 log_err("fio: os or kernel doesn't support IO scheduler switching\n");
677 return 0;
678 }
679 td_verror(td, errno, "fopen iosched");
Jens Axboeda867742006-06-06 10:39:10 -0700680 return 1;
681 }
682
683 /*
684 * Set io scheduler.
685 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100686 ret = fwrite(td->o.ioscheduler, strlen(td->o.ioscheduler), 1, f);
Jens Axboeda867742006-06-06 10:39:10 -0700687 if (ferror(f) || ret != 1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100688 td_verror(td, errno, "fwrite");
Jens Axboeda867742006-06-06 10:39:10 -0700689 fclose(f);
690 return 1;
691 }
692
693 rewind(f);
694
695 /*
696 * Read back and check that the selected scheduler is now the default.
697 */
698 ret = fread(tmp, 1, sizeof(tmp), f);
699 if (ferror(f) || ret < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100700 td_verror(td, errno, "fread");
Jens Axboeda867742006-06-06 10:39:10 -0700701 fclose(f);
702 return 1;
703 }
704
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100705 sprintf(tmp2, "[%s]", td->o.ioscheduler);
Jens Axboeda867742006-06-06 10:39:10 -0700706 if (!strstr(tmp, tmp2)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100707 log_err("fio: io scheduler %s not found\n", td->o.ioscheduler);
Jens Axboee1161c32007-02-22 19:36:48 +0100708 td_verror(td, EINVAL, "iosched_switch");
Jens Axboeda867742006-06-06 10:39:10 -0700709 fclose(f);
710 return 1;
711 }
712
713 fclose(f);
714 return 0;
715}
716
Jens Axboea978ba62007-03-08 14:29:03 +0100717static int clear_io_state(struct thread_data *td)
Jens Axboeebac4652005-12-08 15:25:21 +0100718{
Jens Axboe53cdc682006-10-18 11:50:58 +0200719 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100720 unsigned int i;
721 int ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100722
Jens Axboe756867b2007-03-06 15:19:24 +0100723 td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100724 td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
Jens Axboe20dc95c2005-12-09 10:29:35 +0100725 td->zone_bytes = 0;
Jens Axboed7d3b492007-03-12 08:02:10 +0100726 td->rate_bytes = 0;
Jens Axboe4e991c22007-03-15 11:41:11 +0100727 td->rate_blocks = 0;
Jens Axboe38d77ca2007-03-21 14:20:20 +0100728 td->rw_end_set[0] = td->rw_end_set[1] = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100729
Jens Axboec1324df2007-02-19 19:06:41 +0100730 td->last_was_sync = 0;
731
Jens Axboea978ba62007-03-08 14:29:03 +0100732 for_each_file(td, f, i)
733 td_io_close_file(td, f);
734
735 ret = 0;
Jens Axboe53cdc682006-10-18 11:50:58 +0200736 for_each_file(td, f, i) {
Jens Axboea978ba62007-03-08 14:29:03 +0100737 ret = td_io_open_file(td, f);
738 if (ret)
739 break;
Jens Axboe53cdc682006-10-18 11:50:58 +0200740 }
Jens Axboea978ba62007-03-08 14:29:03 +0100741
742 return ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100743}
744
Jens Axboe906c8d72006-06-13 09:37:56 +0200745/*
746 * Entry point for the thread based jobs. The process based jobs end up
747 * here as well, after a little setup.
748 */
Jens Axboeebac4652005-12-08 15:25:21 +0100749static void *thread_main(void *data)
750{
Jens Axboe69008992006-11-24 13:12:56 +0100751 unsigned long long runtime[2];
Jens Axboeebac4652005-12-08 15:25:21 +0100752 struct thread_data *td = data;
Jens Axboe38d77ca2007-03-21 14:20:20 +0100753 unsigned long elapsed;
Jens Axboea978ba62007-03-08 14:29:03 +0100754 int clear_state;
Jens Axboeebac4652005-12-08 15:25:21 +0100755
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100756 if (!td->o.use_thread)
Jens Axboeebac4652005-12-08 15:25:21 +0100757 setsid();
758
759 td->pid = getpid();
760
Jens Axboeaea47d42006-05-26 19:27:29 +0200761 INIT_LIST_HEAD(&td->io_u_freelist);
762 INIT_LIST_HEAD(&td->io_u_busylist);
Jens Axboe755200a2007-02-19 13:08:12 +0100763 INIT_LIST_HEAD(&td->io_u_requeues);
Jens Axboeaea47d42006-05-26 19:27:29 +0200764 INIT_LIST_HEAD(&td->io_log_list);
Jens Axboe8de8f042007-03-27 10:36:12 +0200765 INIT_LIST_HEAD(&td->io_hist_list);
Jens Axboebb5d7d02007-03-27 10:21:25 +0200766 td->io_hist_tree = RB_ROOT;
Jens Axboeaea47d42006-05-26 19:27:29 +0200767
Jens Axboeebac4652005-12-08 15:25:21 +0100768 if (init_io_u(td))
Jens Axboebda4fd92007-03-12 11:21:48 +0100769 goto err_sem;
Jens Axboeebac4652005-12-08 15:25:21 +0100770
771 if (fio_setaffinity(td) == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100772 td_verror(td, errno, "cpu_set_affinity");
Jens Axboebda4fd92007-03-12 11:21:48 +0100773 goto err_sem;
Jens Axboeebac4652005-12-08 15:25:21 +0100774 }
775
Jens Axboeaea47d42006-05-26 19:27:29 +0200776 if (init_iolog(td))
Jens Axboebda4fd92007-03-12 11:21:48 +0100777 goto err_sem;
Jens Axboeaea47d42006-05-26 19:27:29 +0200778
Jens Axboeebac4652005-12-08 15:25:21 +0100779 if (td->ioprio) {
780 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100781 td_verror(td, errno, "ioprio_set");
Jens Axboebda4fd92007-03-12 11:21:48 +0100782 goto err_sem;
Jens Axboeebac4652005-12-08 15:25:21 +0100783 }
784 }
785
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100786 if (nice(td->o.nice) == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100787 td_verror(td, errno, "nice");
Jens Axboebda4fd92007-03-12 11:21:48 +0100788 goto err_sem;
Jens Axboeb6f4d882006-06-02 10:32:51 +0200789 }
790
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100791 if (td->o.ioscheduler && switch_ioscheduler(td))
Jens Axboebda4fd92007-03-12 11:21:48 +0100792 goto err_sem;
Jens Axboeda867742006-06-06 10:39:10 -0700793
Jens Axboe75154842006-06-01 13:56:09 +0200794 td_set_runstate(td, TD_INITIALIZED);
Jens Axboe07739b52007-03-08 20:25:46 +0100795 fio_sem_up(startup_sem);
796 fio_sem_down(td->mutex);
Jens Axboeebac4652005-12-08 15:25:21 +0100797
Jens Axboe37f56872007-03-09 12:42:35 +0100798 /*
799 * the ->mutex semaphore is now no longer used, close it to avoid
800 * eating a file descriptor
801 */
802 fio_sem_remove(td->mutex);
803
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100804 if (!td->o.create_serialize && setup_files(td))
Jens Axboeebac4652005-12-08 15:25:21 +0100805 goto err;
Jens Axboeb5af8292007-03-08 12:43:13 +0100806
807 if (td_io_init(td))
Jens Axboe21972cd2006-11-23 12:39:16 +0100808 goto err;
Jens Axboeebac4652005-12-08 15:25:21 +0100809
Jens Axboeb5af8292007-03-08 12:43:13 +0100810 if (open_files(td))
Jens Axboe7d6c5282007-02-05 10:52:10 +0100811 goto err;
812
Jens Axboe68727072007-03-15 20:49:25 +0100813 if (init_random_map(td))
814 goto err;
815
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100816 if (td->o.exec_prerun) {
817 if (system(td->o.exec_prerun) < 0)
Jens Axboe69cfd7e2007-02-07 13:58:53 +0100818 goto err;
819 }
Jens Axboe4e0ba8a2006-06-06 09:36:28 +0200820
Jens Axboe69008992006-11-24 13:12:56 +0100821 fio_gettime(&td->epoch, NULL);
Jens Axboe433afcb2007-02-22 10:39:01 +0100822 memcpy(&td->timeout_end, &td->epoch, sizeof(td->epoch));
Jens Axboe756867b2007-03-06 15:19:24 +0100823 getrusage(RUSAGE_SELF, &td->ts.ru_start);
Jens Axboe69008992006-11-24 13:12:56 +0100824
825 runtime[0] = runtime[1] = 0;
Jens Axboea978ba62007-03-08 14:29:03 +0100826 clear_state = 0;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100827 while (td->o.loops--) {
Jens Axboe02bcaa82006-11-24 10:42:00 +0100828 fio_gettime(&td->start, NULL);
Jens Axboe756867b2007-03-06 15:19:24 +0100829 memcpy(&td->ts.stat_sample_time, &td->start, sizeof(td->start));
Jens Axboeebac4652005-12-08 15:25:21 +0100830
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100831 if (td->o.ratemin)
Jens Axboe756867b2007-03-06 15:19:24 +0100832 memcpy(&td->lastrate, &td->ts.stat_sample_time, sizeof(td->lastrate));
Jens Axboeebac4652005-12-08 15:25:21 +0100833
Jens Axboea978ba62007-03-08 14:29:03 +0100834 if (clear_state && clear_io_state(td))
835 break;
836
Jens Axboeebac4652005-12-08 15:25:21 +0100837 prune_io_piece_log(td);
838
Jens Axboeba0fbe12007-03-09 14:34:23 +0100839 do_io(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100840
Jens Axboea978ba62007-03-08 14:29:03 +0100841 clear_state = 1;
842
Jens Axboe38d77ca2007-03-21 14:20:20 +0100843 if (td_read(td) && td->io_bytes[DDIR_READ]) {
844 if (td->rw_end_set[DDIR_READ])
845 elapsed = utime_since(&td->start, &td->rw_end[DDIR_READ]);
846 else
847 elapsed = utime_since_now(&td->start);
848
849 runtime[DDIR_READ] += elapsed;
850 }
851 if (td_write(td) && td->io_bytes[DDIR_WRITE]) {
852 if (td->rw_end_set[DDIR_WRITE])
853 elapsed = utime_since(&td->start, &td->rw_end[DDIR_WRITE]);
854 else
855 elapsed = utime_since_now(&td->start);
856
857 runtime[DDIR_WRITE] += elapsed;
858 }
Jens Axboe413dd452007-02-23 09:26:09 +0100859
Jens Axboeebac4652005-12-08 15:25:21 +0100860 if (td->error || td->terminate)
861 break;
862
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100863 if (td->o.verify == VERIFY_NONE)
Jens Axboeebac4652005-12-08 15:25:21 +0100864 continue;
865
Jens Axboea978ba62007-03-08 14:29:03 +0100866 if (clear_io_state(td))
867 break;
868
Jens Axboe02bcaa82006-11-24 10:42:00 +0100869 fio_gettime(&td->start, NULL);
Jens Axboeebac4652005-12-08 15:25:21 +0100870
871 do_verify(td);
872
Jens Axboe69008992006-11-24 13:12:56 +0100873 runtime[DDIR_READ] += utime_since_now(&td->start);
Jens Axboeebac4652005-12-08 15:25:21 +0100874
875 if (td->error || td->terminate)
876 break;
877 }
878
Jens Axboe36dff962006-11-24 13:29:20 +0100879 update_rusage_stat(td);
Jens Axboe756867b2007-03-06 15:19:24 +0100880 td->ts.runtime[0] = runtime[0] / 1000;
881 td->ts.runtime[1] = runtime[1] / 1000;
882 td->ts.total_run_time = mtime_since_now(&td->epoch);
883 td->ts.io_bytes[0] = td->io_bytes[0];
884 td->ts.io_bytes[1] = td->io_bytes[1];
Jens Axboe69008992006-11-24 13:12:56 +0100885
Jens Axboe756867b2007-03-06 15:19:24 +0100886 if (td->ts.bw_log)
887 finish_log(td, td->ts.bw_log, "bw");
888 if (td->ts.slat_log)
889 finish_log(td, td->ts.slat_log, "slat");
890 if (td->ts.clat_log)
891 finish_log(td, td->ts.clat_log, "clat");
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100892 if (td->o.write_iolog_file)
Jens Axboe843a7412006-06-01 21:14:21 -0700893 write_iolog_close(td);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100894 if (td->o.exec_postrun) {
895 if (system(td->o.exec_postrun) < 0)
896 log_err("fio: postrun %s failed\n", td->o.exec_postrun);
Jens Axboe69cfd7e2007-02-07 13:58:53 +0100897 }
Jens Axboeebac4652005-12-08 15:25:21 +0100898
899 if (exitall_on_terminate)
Jens Axboe390c40e2007-03-05 12:35:29 +0100900 terminate_threads(td->groupid);
Jens Axboeebac4652005-12-08 15:25:21 +0100901
902err:
Jens Axboe5bf13a52007-02-17 01:51:47 +0100903 if (td->error)
904 printf("fio: pid=%d, err=%d/%s\n", td->pid, td->error, td->verror);
Jens Axboe53cdc682006-10-18 11:50:58 +0200905 close_files(td);
Jens Axboe2866c822006-10-09 15:57:48 +0200906 close_ioengine(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100907 cleanup_io_u(td);
Jens Axboed23bb322007-03-23 15:57:56 +0100908 options_mem_free(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100909 td_set_runstate(td, TD_EXITED);
Jens Axboe43d76802007-02-21 16:35:29 +0100910 return (void *) (unsigned long) td->error;
Jens Axboebda4fd92007-03-12 11:21:48 +0100911err_sem:
912 fio_sem_up(startup_sem);
913 goto err;
Jens Axboeebac4652005-12-08 15:25:21 +0100914}
915
Jens Axboe906c8d72006-06-13 09:37:56 +0200916/*
917 * We cannot pass the td data into a forked process, so attach the td and
918 * pass it to the thread worker.
919 */
Jens Axboea6418142007-02-17 04:47:18 +0100920static int fork_main(int shmid, int offset)
Jens Axboeebac4652005-12-08 15:25:21 +0100921{
922 struct thread_data *td;
Jens Axboea6418142007-02-17 04:47:18 +0100923 void *data, *ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100924
925 data = shmat(shmid, NULL, 0);
926 if (data == (void *) -1) {
Jens Axboea6418142007-02-17 04:47:18 +0100927 int __err = errno;
928
Jens Axboeebac4652005-12-08 15:25:21 +0100929 perror("shmat");
Jens Axboea6418142007-02-17 04:47:18 +0100930 return __err;
Jens Axboeebac4652005-12-08 15:25:21 +0100931 }
932
933 td = data + offset * sizeof(struct thread_data);
Jens Axboea6418142007-02-17 04:47:18 +0100934 ret = thread_main(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100935 shmdt(data);
Jens Axboe43d76802007-02-21 16:35:29 +0100936 return (int) (unsigned long) ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100937}
938
Jens Axboe906c8d72006-06-13 09:37:56 +0200939/*
Jens Axboe906c8d72006-06-13 09:37:56 +0200940 * Run over the job map and reap the threads that have exited, if any.
941 */
Jens Axboeebac4652005-12-08 15:25:21 +0100942static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
943{
Jens Axboe34572e22006-10-20 09:33:18 +0200944 struct thread_data *td;
Jens Axboefab6aa72007-02-17 06:19:24 +0100945 int i, cputhreads, pending, status, ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100946
947 /*
948 * reap exited threads (TD_EXITED -> TD_REAPED)
949 */
Jens Axboe4d2413c2006-11-23 11:58:59 +0100950 pending = cputhreads = 0;
Jens Axboe34572e22006-10-20 09:33:18 +0200951 for_each_td(td, i) {
Jens Axboe3707f452007-02-22 12:26:57 +0100952 int flags = 0;
Jens Axboea2f77c92007-02-22 11:53:00 +0100953
Jens Axboe84585002006-10-19 20:26:22 +0200954 /*
955 * ->io_ops is NULL for a thread that has closed its
956 * io engine
957 */
Jens Axboeba0fbe12007-03-09 14:34:23 +0100958 if (td->io_ops && !strcmp(td->io_ops->name, "cpuio"))
Jens Axboeb990b5c2006-09-14 09:48:22 +0200959 cputhreads++;
960
Jens Axboea2f77c92007-02-22 11:53:00 +0100961 if (!td->pid || td->runstate == TD_REAPED)
962 continue;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100963 if (td->o.use_thread) {
Jens Axboe3707f452007-02-22 12:26:57 +0100964 if (td->runstate == TD_EXITED) {
965 td_set_runstate(td, TD_REAPED);
966 goto reaped;
967 }
968 continue;
969 }
Jens Axboea2f77c92007-02-22 11:53:00 +0100970
971 flags = WNOHANG;
972 if (td->runstate == TD_EXITED)
973 flags = 0;
974
975 /*
976 * check if someone quit or got killed in an unusual way
977 */
978 ret = waitpid(td->pid, &status, flags);
Jens Axboe3707f452007-02-22 12:26:57 +0100979 if (ret < 0) {
Jens Axboea2f77c92007-02-22 11:53:00 +0100980 if (errno == ECHILD) {
981 log_err("fio: pid=%d disappeared %d\n", td->pid, td->runstate);
982 td_set_runstate(td, TD_REAPED);
983 goto reaped;
984 }
985 perror("waitpid");
986 } else if (ret == td->pid) {
987 if (WIFSIGNALED(status)) {
Jens Axboefab6aa72007-02-17 06:19:24 +0100988 int sig = WTERMSIG(status);
989
Jens Axboed9244942007-03-05 12:32:32 +0100990 if (sig != SIGQUIT)
991 log_err("fio: pid=%d, got signal=%d\n", td->pid, sig);
Jens Axboefab6aa72007-02-17 06:19:24 +0100992 td_set_runstate(td, TD_REAPED);
993 goto reaped;
994 }
Jens Axboea2f77c92007-02-22 11:53:00 +0100995 if (WIFEXITED(status)) {
996 if (WEXITSTATUS(status) && !td->error)
997 td->error = WEXITSTATUS(status);
Jens Axboefab6aa72007-02-17 06:19:24 +0100998
Jens Axboea2f77c92007-02-22 11:53:00 +0100999 td_set_runstate(td, TD_REAPED);
1000 goto reaped;
Jens Axboea6418142007-02-17 04:47:18 +01001001 }
1002 }
Jens Axboeebac4652005-12-08 15:25:21 +01001003
Jens Axboea2f77c92007-02-22 11:53:00 +01001004 /*
1005 * thread is not dead, continue
1006 */
gurudas paie48676b2007-04-11 12:44:27 +02001007 pending++;
Jens Axboea2f77c92007-02-22 11:53:00 +01001008 continue;
Jens Axboefab6aa72007-02-17 06:19:24 +01001009reaped:
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001010 if (td->o.use_thread) {
Jens Axboe3707f452007-02-22 12:26:57 +01001011 long ret;
1012
1013 if (pthread_join(td->thread, (void *) &ret))
1014 perror("pthread_join");
1015 }
1016
Jens Axboeebac4652005-12-08 15:25:21 +01001017 (*nr_running)--;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001018 (*m_rate) -= td->o.ratemin;
1019 (*t_rate) -= td->o.rate;
gurudas paie48676b2007-04-11 12:44:27 +02001020 pending--;
Jens Axboea2f77c92007-02-22 11:53:00 +01001021
1022 if (td->error)
1023 exit_value++;
Jens Axboeebac4652005-12-08 15:25:21 +01001024 }
Jens Axboeb990b5c2006-09-14 09:48:22 +02001025
Jens Axboe4d2413c2006-11-23 11:58:59 +01001026 if (*nr_running == cputhreads && !pending)
Jens Axboe390c40e2007-03-05 12:35:29 +01001027 terminate_threads(TERMINATE_ALL);
Jens Axboeebac4652005-12-08 15:25:21 +01001028}
1029
Jens Axboe906c8d72006-06-13 09:37:56 +02001030/*
1031 * Main function for kicking off and reaping jobs, as needed.
1032 */
Jens Axboeebac4652005-12-08 15:25:21 +01001033static void run_threads(void)
1034{
Jens Axboeebac4652005-12-08 15:25:21 +01001035 struct thread_data *td;
1036 unsigned long spent;
1037 int i, todo, nr_running, m_rate, t_rate, nr_started;
Jens Axboefcb6ade2006-05-31 12:14:35 +02001038
Jens Axboe2f9ade32006-10-20 11:25:52 +02001039 if (fio_pin_memory())
1040 return;
Jens Axboeebac4652005-12-08 15:25:21 +01001041
Jens Axboec6ae0a52006-06-12 11:04:44 +02001042 if (!terse_output) {
Jens Axboe9cedf162007-03-12 11:29:30 +01001043 printf("Starting ");
1044 if (nr_thread)
1045 printf("%d thread%s", nr_thread, nr_thread > 1 ? "s" : "");
1046 if (nr_process) {
1047 if (nr_thread)
1048 printf(" and ");
1049 printf("%d process%s", nr_process, nr_process > 1 ? "es" : "");
1050 }
1051 printf("\n");
Jens Axboec6ae0a52006-06-12 11:04:44 +02001052 fflush(stdout);
1053 }
Jens Axboec04f7ec2006-05-31 10:13:16 +02001054
Jens Axboe4efa9702006-05-31 11:56:49 +02001055 signal(SIGINT, sig_handler);
1056 signal(SIGALRM, sig_handler);
1057
Jens Axboeebac4652005-12-08 15:25:21 +01001058 todo = thread_number;
1059 nr_running = 0;
1060 nr_started = 0;
1061 m_rate = t_rate = 0;
1062
Jens Axboe34572e22006-10-20 09:33:18 +02001063 for_each_td(td, i) {
Jens Axboe263e5292006-10-18 15:37:01 +02001064 print_status_init(td->thread_number - 1);
Jens Axboeebac4652005-12-08 15:25:21 +01001065
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001066 if (!td->o.create_serialize) {
Jens Axboe380cf262007-01-11 14:01:27 +01001067 init_disk_util(td);
Jens Axboeebac4652005-12-08 15:25:21 +01001068 continue;
Jens Axboe380cf262007-01-11 14:01:27 +01001069 }
Jens Axboeebac4652005-12-08 15:25:21 +01001070
1071 /*
1072 * do file setup here so it happens sequentially,
1073 * we don't want X number of threads getting their
1074 * client data interspersed on disk
1075 */
Jens Axboe53cdc682006-10-18 11:50:58 +02001076 if (setup_files(td)) {
Jens Axboe5bf13a52007-02-17 01:51:47 +01001077 exit_value++;
1078 if (td->error)
1079 log_err("fio: pid=%d, err=%d/%s\n", td->pid, td->error, td->verror);
Jens Axboeebac4652005-12-08 15:25:21 +01001080 td_set_runstate(td, TD_REAPED);
1081 todo--;
1082 }
Jens Axboe380cf262007-01-11 14:01:27 +01001083
1084 init_disk_util(td);
Jens Axboeebac4652005-12-08 15:25:21 +01001085 }
1086
Jens Axboea2f77c92007-02-22 11:53:00 +01001087 set_genesis_time();
1088
Jens Axboeebac4652005-12-08 15:25:21 +01001089 while (todo) {
Jens Axboe75154842006-06-01 13:56:09 +02001090 struct thread_data *map[MAX_JOBS];
1091 struct timeval this_start;
1092 int this_jobs = 0, left;
1093
Jens Axboeebac4652005-12-08 15:25:21 +01001094 /*
1095 * create threads (TD_NOT_CREATED -> TD_CREATED)
1096 */
Jens Axboe34572e22006-10-20 09:33:18 +02001097 for_each_td(td, i) {
Jens Axboeebac4652005-12-08 15:25:21 +01001098 if (td->runstate != TD_NOT_CREATED)
1099 continue;
1100
1101 /*
1102 * never got a chance to start, killed by other
1103 * thread for some reason
1104 */
1105 if (td->terminate) {
1106 todo--;
1107 continue;
1108 }
1109
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001110 if (td->o.start_delay) {
Jens Axboe263e5292006-10-18 15:37:01 +02001111 spent = mtime_since_genesis();
Jens Axboeebac4652005-12-08 15:25:21 +01001112
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001113 if (td->o.start_delay * 1000 > spent)
Jens Axboeebac4652005-12-08 15:25:21 +01001114 continue;
1115 }
1116
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001117 if (td->o.stonewall && (nr_started || nr_running))
Jens Axboeebac4652005-12-08 15:25:21 +01001118 break;
1119
Jens Axboe75154842006-06-01 13:56:09 +02001120 /*
1121 * Set state to created. Thread will transition
1122 * to TD_INITIALIZED when it's done setting up.
1123 */
Jens Axboeebac4652005-12-08 15:25:21 +01001124 td_set_runstate(td, TD_CREATED);
Jens Axboe75154842006-06-01 13:56:09 +02001125 map[this_jobs++] = td;
Jens Axboeebac4652005-12-08 15:25:21 +01001126 nr_started++;
1127
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001128 if (td->o.use_thread) {
Jens Axboeebac4652005-12-08 15:25:21 +01001129 if (pthread_create(&td->thread, NULL, thread_main, td)) {
1130 perror("thread_create");
1131 nr_started--;
Jens Axboec8bb6fa2007-03-12 11:03:04 +01001132 break;
Jens Axboeebac4652005-12-08 15:25:21 +01001133 }
1134 } else {
Jens Axboe07739b52007-03-08 20:25:46 +01001135 if (!fork()) {
Jens Axboea6418142007-02-17 04:47:18 +01001136 int ret = fork_main(shm_id, i);
1137
1138 exit(ret);
Jens Axboeebac4652005-12-08 15:25:21 +01001139 }
1140 }
Jens Axboe07739b52007-03-08 20:25:46 +01001141 fio_sem_down(startup_sem);
Jens Axboeebac4652005-12-08 15:25:21 +01001142 }
1143
1144 /*
Jens Axboe75154842006-06-01 13:56:09 +02001145 * Wait for the started threads to transition to
1146 * TD_INITIALIZED.
Jens Axboeebac4652005-12-08 15:25:21 +01001147 */
Jens Axboe02bcaa82006-11-24 10:42:00 +01001148 fio_gettime(&this_start, NULL);
Jens Axboe75154842006-06-01 13:56:09 +02001149 left = this_jobs;
Jens Axboe6ce15a32007-01-12 09:04:41 +01001150 while (left && !fio_abort) {
Jens Axboe75154842006-06-01 13:56:09 +02001151 if (mtime_since_now(&this_start) > JOB_START_TIMEOUT)
1152 break;
1153
1154 usleep(100000);
1155
1156 for (i = 0; i < this_jobs; i++) {
1157 td = map[i];
1158 if (!td)
1159 continue;
Jens Axboeb6f4d882006-06-02 10:32:51 +02001160 if (td->runstate == TD_INITIALIZED) {
Jens Axboe75154842006-06-01 13:56:09 +02001161 map[i] = NULL;
1162 left--;
Jens Axboeb6f4d882006-06-02 10:32:51 +02001163 } else if (td->runstate >= TD_EXITED) {
1164 map[i] = NULL;
1165 left--;
1166 todo--;
1167 nr_running++; /* work-around... */
Jens Axboe75154842006-06-01 13:56:09 +02001168 }
1169 }
1170 }
1171
1172 if (left) {
Jens Axboe3b70d7e2006-06-08 21:48:46 +02001173 log_err("fio: %d jobs failed to start\n", left);
Jens Axboe75154842006-06-01 13:56:09 +02001174 for (i = 0; i < this_jobs; i++) {
1175 td = map[i];
1176 if (!td)
1177 continue;
1178 kill(td->pid, SIGTERM);
1179 }
1180 break;
1181 }
1182
1183 /*
Jens Axboeb6f4d882006-06-02 10:32:51 +02001184 * start created threads (TD_INITIALIZED -> TD_RUNNING).
Jens Axboe75154842006-06-01 13:56:09 +02001185 */
Jens Axboe34572e22006-10-20 09:33:18 +02001186 for_each_td(td, i) {
Jens Axboe75154842006-06-01 13:56:09 +02001187 if (td->runstate != TD_INITIALIZED)
Jens Axboeebac4652005-12-08 15:25:21 +01001188 continue;
1189
1190 td_set_runstate(td, TD_RUNNING);
1191 nr_running++;
1192 nr_started--;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001193 m_rate += td->o.ratemin;
1194 t_rate += td->o.rate;
Jens Axboe75154842006-06-01 13:56:09 +02001195 todo--;
Jens Axboe07739b52007-03-08 20:25:46 +01001196 fio_sem_up(td->mutex);
Jens Axboeebac4652005-12-08 15:25:21 +01001197 }
1198
1199 reap_threads(&nr_running, &t_rate, &m_rate);
1200
1201 if (todo)
1202 usleep(100000);
1203 }
1204
1205 while (nr_running) {
1206 reap_threads(&nr_running, &t_rate, &m_rate);
1207 usleep(10000);
1208 }
1209
1210 update_io_ticks();
Jens Axboe2f9ade32006-10-20 11:25:52 +02001211 fio_unpin_memory();
Jens Axboeebac4652005-12-08 15:25:21 +01001212}
1213
Jens Axboeebac4652005-12-08 15:25:21 +01001214int main(int argc, char *argv[])
1215{
Jens Axboe29d610e2007-02-06 13:25:33 +01001216 long ps;
1217
Jens Axboedbe11252007-02-11 00:19:51 +01001218 /*
1219 * We need locale for number printing, if it isn't set then just
1220 * go with the US format.
1221 */
1222 if (!getenv("LC_NUMERIC"))
1223 setlocale(LC_NUMERIC, "en_US");
1224
Jens Axboeebac4652005-12-08 15:25:21 +01001225 if (parse_options(argc, argv))
1226 return 1;
1227
Jens Axboe4b472fa2007-04-04 11:04:34 +02001228 if (!thread_number)
1229 return 0;
Jens Axboeebac4652005-12-08 15:25:21 +01001230
Jens Axboe29d610e2007-02-06 13:25:33 +01001231 ps = sysconf(_SC_PAGESIZE);
1232 if (ps < 0) {
1233 log_err("Failed to get page size\n");
1234 return 1;
1235 }
1236
Jens Axboecfc99db2007-03-14 10:34:47 +01001237 page_size = ps;
Jens Axboe29d610e2007-02-06 13:25:33 +01001238 page_mask = ps - 1;
1239
Jens Axboebb3884d2007-01-17 17:23:11 +11001240 if (write_bw_log) {
1241 setup_log(&agg_io_log[DDIR_READ]);
1242 setup_log(&agg_io_log[DDIR_WRITE]);
1243 }
1244
Jens Axboe07739b52007-03-08 20:25:46 +01001245 startup_sem = fio_sem_init(0);
1246
Jens Axboea2f77c92007-02-22 11:53:00 +01001247 set_genesis_time();
1248
Jens Axboeebac4652005-12-08 15:25:21 +01001249 disk_util_timer_arm();
1250
1251 run_threads();
Jens Axboe6ce15a32007-01-12 09:04:41 +01001252
Jens Axboebb3884d2007-01-17 17:23:11 +11001253 if (!fio_abort) {
Jens Axboe6ce15a32007-01-12 09:04:41 +01001254 show_run_stats();
Jens Axboebb3884d2007-01-17 17:23:11 +11001255 if (write_bw_log) {
1256 __finish_log(agg_io_log[DDIR_READ],"agg-read_bw.log");
1257 __finish_log(agg_io_log[DDIR_WRITE],"agg-write_bw.log");
1258 }
1259 }
Jens Axboeebac4652005-12-08 15:25:21 +01001260
Jens Axboe07739b52007-03-08 20:25:46 +01001261 fio_sem_remove(startup_sem);
Jens Axboe437c9b72007-02-13 18:20:37 +01001262 return exit_value;
Jens Axboeebac4652005-12-08 15:25:21 +01001263}