blob: 4d225f84b409a7efde36394e05dd296157ad851b [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 Axboeebac4652005-12-08 15:25:21 +010038
Jens Axboecfc99db2007-03-14 10:34:47 +010039unsigned long page_mask;
40unsigned long page_size;
Jens Axboe29d610e2007-02-06 13:25:33 +010041#define ALIGN(buf) \
42 (char *) (((unsigned long) (buf) + page_mask) & ~page_mask)
Jens Axboeebac4652005-12-08 15:25:21 +010043
44int groupid = 0;
45int thread_number = 0;
Jens Axboe9cedf162007-03-12 11:29:30 +010046int nr_process = 0;
47int nr_thread = 0;
Jens Axboeebac4652005-12-08 15:25:21 +010048int shm_id = 0;
Jens Axboe53cdc682006-10-18 11:50:58 +020049int temp_stall_ts;
Jens Axboeebac4652005-12-08 15:25:21 +010050
Jens Axboe07739b52007-03-08 20:25:46 +010051static struct fio_sem *startup_sem;
Jens Axboe6ce15a32007-01-12 09:04:41 +010052static volatile int fio_abort;
Jens Axboe437c9b72007-02-13 18:20:37 +010053static int exit_value;
Jens Axboeebac4652005-12-08 15:25:21 +010054
Jens Axboebb3884d2007-01-17 17:23:11 +110055struct io_log *agg_io_log[2];
56
Jens Axboeebac4652005-12-08 15:25:21 +010057#define TERMINATE_ALL (-1)
Jens Axboe75154842006-06-01 13:56:09 +020058#define JOB_START_TIMEOUT (5 * 1000)
Jens Axboeebac4652005-12-08 15:25:21 +010059
Jens Axboe6ce15a32007-01-12 09:04:41 +010060static inline void td_set_runstate(struct thread_data *td, int runstate)
61{
62 td->runstate = runstate;
63}
64
Jens Axboe390c40e2007-03-05 12:35:29 +010065static void terminate_threads(int group_id)
Jens Axboeebac4652005-12-08 15:25:21 +010066{
Jens Axboe34572e22006-10-20 09:33:18 +020067 struct thread_data *td;
Jens Axboeebac4652005-12-08 15:25:21 +010068 int i;
69
Jens Axboe34572e22006-10-20 09:33:18 +020070 for_each_td(td, i) {
Jens Axboeebac4652005-12-08 15:25:21 +010071 if (group_id == TERMINATE_ALL || groupid == td->groupid) {
Jens Axboeef5fffa2007-04-17 13:42:47 +020072 if (td->runstate <= TD_RUNNING)
Jens Axboec1302d42007-03-05 20:18:31 +010073 kill(td->pid, SIGQUIT);
Jens Axboeebac4652005-12-08 15:25:21 +010074 td->terminate = 1;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010075 td->o.start_delay = 0;
Jens Axboeebac4652005-12-08 15:25:21 +010076 }
77 }
78}
79
80static void sig_handler(int sig)
81{
82 switch (sig) {
83 case SIGALRM:
84 update_io_ticks();
85 disk_util_timer_arm();
86 print_thread_status();
87 break;
88 default:
Jens Axboe6ce15a32007-01-12 09:04:41 +010089 printf("\nfio: terminating on signal %d\n", sig);
Jens Axboeebac4652005-12-08 15:25:21 +010090 fflush(stdout);
Jens Axboe390c40e2007-03-05 12:35:29 +010091 terminate_threads(TERMINATE_ALL);
Jens Axboeebac4652005-12-08 15:25:21 +010092 break;
93 }
94}
95
Jens Axboe906c8d72006-06-13 09:37:56 +020096/*
Jens Axboe906c8d72006-06-13 09:37:56 +020097 * Check if we are above the minimum rate given.
98 */
Jens Axboeebac4652005-12-08 15:25:21 +010099static int check_min_rate(struct thread_data *td, struct timeval *now)
100{
Jens Axboe09042002007-02-23 10:56:22 +0100101 unsigned long long bytes = 0;
Jens Axboe4e991c22007-03-15 11:41:11 +0100102 unsigned long iops = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100103 unsigned long spent;
104 unsigned long rate;
Jens Axboeebac4652005-12-08 15:25:21 +0100105
106 /*
Jens Axboe780bf1a2007-02-28 11:13:49 +0100107 * No minimum rate set, always ok
108 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100109 if (!td->o.ratemin && !td->o.rate_iops_min)
Jens Axboe780bf1a2007-02-28 11:13:49 +0100110 return 0;
111
112 /*
Jens Axboeebac4652005-12-08 15:25:21 +0100113 * allow a 2 second settle period in the beginning
114 */
115 if (mtime_since(&td->start, now) < 2000)
116 return 0;
117
Jens Axboe4e991c22007-03-15 11:41:11 +0100118 if (td_read(td)) {
119 iops += td->io_blocks[DDIR_READ];
Jens Axboe09042002007-02-23 10:56:22 +0100120 bytes += td->this_io_bytes[DDIR_READ];
Jens Axboe4e991c22007-03-15 11:41:11 +0100121 }
122 if (td_write(td)) {
123 iops += td->io_blocks[DDIR_WRITE];
Jens Axboe09042002007-02-23 10:56:22 +0100124 bytes += td->this_io_bytes[DDIR_WRITE];
Jens Axboe4e991c22007-03-15 11:41:11 +0100125 }
Jens Axboe09042002007-02-23 10:56:22 +0100126
Jens Axboeebac4652005-12-08 15:25:21 +0100127 /*
128 * if rate blocks is set, sample is running
129 */
Jens Axboe4e991c22007-03-15 11:41:11 +0100130 if (td->rate_bytes || td->rate_blocks) {
Jens Axboeebac4652005-12-08 15:25:21 +0100131 spent = mtime_since(&td->lastrate, now);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100132 if (spent < td->o.ratecycle)
Jens Axboeebac4652005-12-08 15:25:21 +0100133 return 0;
134
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100135 if (td->o.rate) {
Jens Axboe4e991c22007-03-15 11:41:11 +0100136 /*
137 * check bandwidth specified rate
138 */
139 if (bytes < td->rate_bytes) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100140 log_err("%s: min rate %u not met\n", td->o.name, td->o.ratemin);
Jens Axboe413dd452007-02-23 09:26:09 +0100141 return 1;
Jens Axboe4e991c22007-03-15 11:41:11 +0100142 } else {
143 rate = (bytes - td->rate_bytes) / spent;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100144 if (rate < td->o.ratemin || bytes < td->rate_bytes) {
145 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 +0100146 return 1;
147 }
148 }
149 } else {
150 /*
151 * checks iops specified rate
152 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100153 if (iops < td->o.rate_iops) {
154 log_err("%s: min iops rate %u not met\n", td->o.name, td->o.rate_iops);
Jens Axboe4e991c22007-03-15 11:41:11 +0100155 return 1;
156 } else {
157 rate = (iops - td->rate_blocks) / spent;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100158 if (rate < td->o.rate_iops_min || iops < td->rate_blocks) {
159 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 +0100160 }
Jens Axboe413dd452007-02-23 09:26:09 +0100161 }
Jens Axboeebac4652005-12-08 15:25:21 +0100162 }
163 }
164
Jens Axboe09042002007-02-23 10:56:22 +0100165 td->rate_bytes = bytes;
Jens Axboe4e991c22007-03-15 11:41:11 +0100166 td->rate_blocks = iops;
Jens Axboeebac4652005-12-08 15:25:21 +0100167 memcpy(&td->lastrate, now, sizeof(*now));
168 return 0;
169}
170
171static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
172{
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100173 if (!td->o.timeout)
Jens Axboeebac4652005-12-08 15:25:21 +0100174 return 0;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100175 if (mtime_since(&td->epoch, t) >= td->o.timeout * 1000)
Jens Axboeebac4652005-12-08 15:25:21 +0100176 return 1;
177
178 return 0;
179}
180
Jens Axboe906c8d72006-06-13 09:37:56 +0200181/*
182 * When job exits, we can cancel the in-flight IO if we are using async
183 * io. Attempt to do so.
184 */
Jens Axboeebac4652005-12-08 15:25:21 +0100185static void cleanup_pending_aio(struct thread_data *td)
186{
Jens Axboeebac4652005-12-08 15:25:21 +0100187 struct list_head *entry, *n;
Jens Axboeebac4652005-12-08 15:25:21 +0100188 struct io_u *io_u;
189 int r;
190
191 /*
192 * get immediately available events, if any
193 */
Jens Axboed7762cf2007-02-23 12:34:57 +0100194 r = io_u_queued_complete(td, 0);
Jens Axboeb2fdda42007-02-20 20:52:51 +0100195 if (r < 0)
196 return;
Jens Axboeebac4652005-12-08 15:25:21 +0100197
198 /*
199 * now cancel remaining active events
200 */
Jens Axboe2866c822006-10-09 15:57:48 +0200201 if (td->io_ops->cancel) {
Jens Axboeebac4652005-12-08 15:25:21 +0100202 list_for_each_safe(entry, n, &td->io_u_busylist) {
203 io_u = list_entry(entry, struct io_u, list);
204
Jens Axboe0c6e7512007-02-22 11:19:39 +0100205 /*
206 * if the io_u isn't in flight, then that generally
207 * means someone leaked an io_u. complain but fix
208 * it up, so we don't stall here.
209 */
210 if ((io_u->flags & IO_U_F_FLIGHT) == 0) {
211 log_err("fio: non-busy IO on busy list\n");
Jens Axboeebac4652005-12-08 15:25:21 +0100212 put_io_u(td, io_u);
Jens Axboe0c6e7512007-02-22 11:19:39 +0100213 } else {
214 r = td->io_ops->cancel(td, io_u);
215 if (!r)
216 put_io_u(td, io_u);
217 }
Jens Axboeebac4652005-12-08 15:25:21 +0100218 }
219 }
220
Jens Axboe97601022007-02-18 12:47:29 +0100221 if (td->cur_depth)
Jens Axboed7762cf2007-02-23 12:34:57 +0100222 r = io_u_queued_complete(td, td->cur_depth);
Jens Axboeebac4652005-12-08 15:25:21 +0100223}
224
Jens Axboe906c8d72006-06-13 09:37:56 +0200225/*
Jens Axboe858a3d42006-10-24 14:54:44 +0200226 * Helper to handle the final sync of a file. Works just like the normal
227 * io path, just does everything sync.
228 */
229static int fio_io_sync(struct thread_data *td, struct fio_file *f)
230{
231 struct io_u *io_u = __get_io_u(td);
Jens Axboe858a3d42006-10-24 14:54:44 +0200232 int ret;
233
234 if (!io_u)
235 return 1;
236
237 io_u->ddir = DDIR_SYNC;
238 io_u->file = f;
239
240 if (td_io_prep(td, io_u)) {
241 put_io_u(td, io_u);
242 return 1;
243 }
244
Jens Axboe755200a2007-02-19 13:08:12 +0100245requeue:
Jens Axboe858a3d42006-10-24 14:54:44 +0200246 ret = td_io_queue(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100247 if (ret < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100248 td_verror(td, io_u->error, "td_io_queue");
Jens Axboe858a3d42006-10-24 14:54:44 +0200249 put_io_u(td, io_u);
Jens Axboe858a3d42006-10-24 14:54:44 +0200250 return 1;
Jens Axboe36167d82007-02-18 05:41:31 +0100251 } else if (ret == FIO_Q_QUEUED) {
Jens Axboed7762cf2007-02-23 12:34:57 +0100252 if (io_u_queued_complete(td, 1) < 0)
Jens Axboe36167d82007-02-18 05:41:31 +0100253 return 1;
Jens Axboe36167d82007-02-18 05:41:31 +0100254 } else if (ret == FIO_Q_COMPLETED) {
255 if (io_u->error) {
Jens Axboee1161c32007-02-22 19:36:48 +0100256 td_verror(td, io_u->error, "td_io_queue");
Jens Axboe36167d82007-02-18 05:41:31 +0100257 return 1;
258 }
Jens Axboe858a3d42006-10-24 14:54:44 +0200259
Jens Axboed7762cf2007-02-23 12:34:57 +0100260 if (io_u_sync_complete(td, io_u) < 0)
Jens Axboeb2fdda42007-02-20 20:52:51 +0100261 return 1;
Jens Axboe755200a2007-02-19 13:08:12 +0100262 } else if (ret == FIO_Q_BUSY) {
263 if (td_io_commit(td))
264 return 1;
265 goto requeue;
Jens Axboe858a3d42006-10-24 14:54:44 +0200266 }
267
268 return 0;
269}
270
271/*
Jens Axboe34403fb2007-03-02 21:43:25 +0100272 * The main verify engine. Runs over the writes we previously submitted,
Jens Axboe906c8d72006-06-13 09:37:56 +0200273 * reads the blocks back in, and checks the crc/md5 of the data.
274 */
Jens Axboe1e97cce2006-12-05 11:44:16 +0100275static void do_verify(struct thread_data *td)
Jens Axboeebac4652005-12-08 15:25:21 +0100276{
Jens Axboe53cdc682006-10-18 11:50:58 +0200277 struct fio_file *f;
Jens Axboe36167d82007-02-18 05:41:31 +0100278 struct io_u *io_u;
Jens Axboeaf52b342007-03-13 10:07:47 +0100279 int ret, min_events;
280 unsigned int i;
Jens Axboee5b401d2006-10-18 16:03:40 +0200281
282 /*
283 * sync io first and invalidate cache, to make sure we really
284 * read from disk.
285 */
286 for_each_file(td, f, i) {
Jens Axboe3d7b4852007-03-13 14:50:28 +0100287 if (!(f->flags & FIO_FILE_OPEN))
288 continue;
Jens Axboeb2fdda42007-02-20 20:52:51 +0100289 if (fio_io_sync(td, f))
290 break;
291 if (file_invalidate_cache(td, f))
292 break;
Jens Axboee5b401d2006-10-18 16:03:40 +0200293 }
Jens Axboeebac4652005-12-08 15:25:21 +0100294
Jens Axboeb2fdda42007-02-20 20:52:51 +0100295 if (td->error)
296 return;
297
Jens Axboeebac4652005-12-08 15:25:21 +0100298 td_set_runstate(td, TD_VERIFYING);
299
Jens Axboe36167d82007-02-18 05:41:31 +0100300 io_u = NULL;
301 while (!td->terminate) {
Jens Axboe54517922007-03-05 10:06:06 +0100302 int ret2;
303
Jens Axboeebac4652005-12-08 15:25:21 +0100304 io_u = __get_io_u(td);
305 if (!io_u)
306 break;
307
Jens Axboe069c2912007-02-21 23:02:39 +0100308 if (runtime_exceeded(td, &io_u->start_time)) {
309 put_io_u(td, io_u);
Jens Axboe53cdc682006-10-18 11:50:58 +0200310 break;
Jens Axboe069c2912007-02-21 23:02:39 +0100311 }
Jens Axboe53cdc682006-10-18 11:50:58 +0200312
Jens Axboe069c2912007-02-21 23:02:39 +0100313 if (get_next_verify(td, io_u)) {
314 put_io_u(td, io_u);
Jens Axboeebac4652005-12-08 15:25:21 +0100315 break;
Jens Axboe069c2912007-02-21 23:02:39 +0100316 }
Jens Axboeebac4652005-12-08 15:25:21 +0100317
Jens Axboe069c2912007-02-21 23:02:39 +0100318 if (td_io_prep(td, io_u)) {
319 put_io_u(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100320 break;
Jens Axboe069c2912007-02-21 23:02:39 +0100321 }
Jens Axboed7762cf2007-02-23 12:34:57 +0100322
323 io_u->end_io = verify_io_u;
Jens Axboe36167d82007-02-18 05:41:31 +0100324
Jens Axboe11786802007-03-05 18:33:22 +0100325 ret = td_io_queue(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100326 switch (ret) {
327 case FIO_Q_COMPLETED:
328 if (io_u->error)
Jens Axboe22819ec2007-02-18 07:47:14 +0100329 ret = -io_u->error;
Jens Axboe9e9d1642007-03-12 09:37:46 +0100330 else if (io_u->resid) {
Jens Axboe36167d82007-02-18 05:41:31 +0100331 int bytes = io_u->xfer_buflen - io_u->resid;
Jens Axboed460eb32007-04-16 21:39:33 +0200332 struct fio_file *f = io_u->file;
Jens Axboe36167d82007-02-18 05:41:31 +0100333
Jens Axboe9e9d1642007-03-12 09:37:46 +0100334 /*
335 * zero read, fail
336 */
337 if (!bytes) {
338 td_verror(td, ENODATA, "full resid");
339 put_io_u(td, io_u);
340 break;
341 }
Jens Axboe8400d9b2007-03-28 11:10:09 +0200342
Jens Axboe36167d82007-02-18 05:41:31 +0100343 io_u->xfer_buflen = io_u->resid;
344 io_u->xfer_buf += bytes;
Jens Axboe8400d9b2007-03-28 11:10:09 +0200345 io_u->offset += bytes;
Jens Axboed460eb32007-04-16 21:39:33 +0200346 f->last_completed_pos = io_u->offset;
Jens Axboe8400d9b2007-03-28 11:10:09 +0200347
Jens Axboe30061b92007-04-17 13:31:34 +0200348 td->ts.short_io_u[io_u->ddir]++;
349
Jens Axboed460eb32007-04-16 21:39:33 +0200350 if (io_u->offset == f->real_file_size)
Jens Axboe8400d9b2007-03-28 11:10:09 +0200351 goto sync_done;
352
Jens Axboe11786802007-03-05 18:33:22 +0100353 requeue_io_u(td, &io_u);
354 } else {
Jens Axboe8400d9b2007-03-28 11:10:09 +0200355sync_done:
Jens Axboe11786802007-03-05 18:33:22 +0100356 ret = io_u_sync_complete(td, io_u);
357 if (ret < 0)
358 break;
Jens Axboe36167d82007-02-18 05:41:31 +0100359 }
Jens Axboe36167d82007-02-18 05:41:31 +0100360 continue;
361 case FIO_Q_QUEUED:
362 break;
Jens Axboe755200a2007-02-19 13:08:12 +0100363 case FIO_Q_BUSY:
364 requeue_io_u(td, &io_u);
Jens Axboe54517922007-03-05 10:06:06 +0100365 ret2 = td_io_commit(td);
366 if (ret2 < 0)
367 ret = ret2;
Jens Axboe755200a2007-02-19 13:08:12 +0100368 break;
Jens Axboe36167d82007-02-18 05:41:31 +0100369 default:
370 assert(ret < 0);
Jens Axboee1161c32007-02-22 19:36:48 +0100371 td_verror(td, -ret, "td_io_queue");
Jens Axboeebac4652005-12-08 15:25:21 +0100372 break;
373 }
374
Jens Axboe99784632007-02-19 10:06:17 +0100375 if (ret < 0 || td->error)
Jens Axboeebac4652005-12-08 15:25:21 +0100376 break;
377
Jens Axboe3af6ef32007-02-18 06:57:43 +0100378 /*
379 * if we can queue more, do so. but check if there are
380 * completed io_u's first.
381 */
Jens Axboe97601022007-02-18 12:47:29 +0100382 min_events = 0;
Jens Axboee916b392007-02-20 14:37:26 +0100383 if (queue_full(td) || ret == FIO_Q_BUSY) {
Jens Axboe3af6ef32007-02-18 06:57:43 +0100384 min_events = 1;
Jens Axboe3af6ef32007-02-18 06:57:43 +0100385
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100386 if (td->cur_depth > td->o.iodepth_low)
387 min_events = td->cur_depth - td->o.iodepth_low;
Jens Axboee916b392007-02-20 14:37:26 +0100388 }
389
Jens Axboe3af6ef32007-02-18 06:57:43 +0100390 /*
391 * Reap required number of io units, if any, and do the
392 * verification on them through the callback handler
393 */
Jens Axboed7762cf2007-02-23 12:34:57 +0100394 if (io_u_queued_complete(td, min_events) < 0)
Jens Axboe36167d82007-02-18 05:41:31 +0100395 break;
396 }
397
Jens Axboec01c0392007-02-26 12:43:42 +0100398 if (!td->error) {
399 min_events = td->cur_depth;
400
401 if (min_events)
402 ret = io_u_queued_complete(td, min_events);
403 } else
Jens Axboeebac4652005-12-08 15:25:21 +0100404 cleanup_pending_aio(td);
405
406 td_set_runstate(td, TD_RUNNING);
407}
408
Jens Axboe32cd46a2006-06-07 13:40:40 +0200409/*
Jens Axboe906c8d72006-06-13 09:37:56 +0200410 * Main IO worker function. It retrieves io_u's to process and queues
Jens Axboe32cd46a2006-06-07 13:40:40 +0200411 * and reaps them, checking for rate and errors along the way.
412 */
Jens Axboeebac4652005-12-08 15:25:21 +0100413static void do_io(struct thread_data *td)
414{
Jens Axboe02bcaa82006-11-24 10:42:00 +0100415 struct timeval s;
Jens Axboeebac4652005-12-08 15:25:21 +0100416 unsigned long usec;
Jens Axboeaf52b342007-03-13 10:07:47 +0100417 unsigned int i;
418 int ret = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100419
Jens Axboe5853e5a2006-06-08 14:41:05 +0200420 td_set_runstate(td, TD_RUNNING);
421
Jens Axboe7bb48f82007-03-27 15:30:28 +0200422 while ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) {
Jens Axboe97601022007-02-18 12:47:29 +0100423 struct timeval comp_time;
424 long bytes_done = 0;
Jens Axboe84585002006-10-19 20:26:22 +0200425 int min_evts = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100426 struct io_u *io_u;
Jens Axboe54517922007-03-05 10:06:06 +0100427 int ret2;
Jens Axboeebac4652005-12-08 15:25:21 +0100428
429 if (td->terminate)
430 break;
431
Jens Axboe3d7c3912007-02-19 13:16:12 +0100432 io_u = get_io_u(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100433 if (!io_u)
434 break;
435
436 memcpy(&s, &io_u->start_time, sizeof(s));
Jens Axboe97601022007-02-18 12:47:29 +0100437
438 if (runtime_exceeded(td, &s)) {
439 put_io_u(td, io_u);
440 break;
441 }
Jens Axboe36167d82007-02-18 05:41:31 +0100442
Jens Axboe11786802007-03-05 18:33:22 +0100443 ret = td_io_queue(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100444 switch (ret) {
445 case FIO_Q_COMPLETED:
Jens Axboe54517922007-03-05 10:06:06 +0100446 if (io_u->error)
447 ret = -io_u->error;
Jens Axboe9e9d1642007-03-12 09:37:46 +0100448 else if (io_u->resid) {
Jens Axboe36167d82007-02-18 05:41:31 +0100449 int bytes = io_u->xfer_buflen - io_u->resid;
Jens Axboed460eb32007-04-16 21:39:33 +0200450 struct fio_file *f = io_u->file;
Jens Axboe36167d82007-02-18 05:41:31 +0100451
Jens Axboe9e9d1642007-03-12 09:37:46 +0100452 /*
453 * zero read, fail
454 */
455 if (!bytes) {
456 td_verror(td, ENODATA, "full resid");
457 put_io_u(td, io_u);
458 break;
459 }
460
Jens Axboe36167d82007-02-18 05:41:31 +0100461 io_u->xfer_buflen = io_u->resid;
462 io_u->xfer_buf += bytes;
Jens Axboe5a7c5682007-03-28 11:07:20 +0200463 io_u->offset += bytes;
Jens Axboed460eb32007-04-16 21:39:33 +0200464 f->last_completed_pos = io_u->offset;
Jens Axboe5a7c5682007-03-28 11:07:20 +0200465
Jens Axboe30061b92007-04-17 13:31:34 +0200466 td->ts.short_io_u[io_u->ddir]++;
467
Jens Axboed460eb32007-04-16 21:39:33 +0200468 if (io_u->offset == f->real_file_size)
Jens Axboe5a7c5682007-03-28 11:07:20 +0200469 goto sync_done;
470
Jens Axboe11786802007-03-05 18:33:22 +0100471 requeue_io_u(td, &io_u);
472 } else {
Jens Axboe5a7c5682007-03-28 11:07:20 +0200473sync_done:
Jens Axboe11786802007-03-05 18:33:22 +0100474 fio_gettime(&comp_time, NULL);
475 bytes_done = io_u_sync_complete(td, io_u);
476 if (bytes_done < 0)
477 ret = bytes_done;
Jens Axboe36167d82007-02-18 05:41:31 +0100478 }
Jens Axboe36167d82007-02-18 05:41:31 +0100479 break;
480 case FIO_Q_QUEUED:
Jens Axboe7e77dd02007-02-20 10:57:34 +0100481 /*
482 * if the engine doesn't have a commit hook,
483 * the io_u is really queued. if it does have such
484 * a hook, it has to call io_u_queued() itself.
485 */
486 if (td->io_ops->commit == NULL)
487 io_u_queued(td, io_u);
Jens Axboe36167d82007-02-18 05:41:31 +0100488 break;
Jens Axboe755200a2007-02-19 13:08:12 +0100489 case FIO_Q_BUSY:
490 requeue_io_u(td, &io_u);
Jens Axboe54517922007-03-05 10:06:06 +0100491 ret2 = td_io_commit(td);
492 if (ret2 < 0)
493 ret = ret2;
Jens Axboe755200a2007-02-19 13:08:12 +0100494 break;
Jens Axboe36167d82007-02-18 05:41:31 +0100495 default:
496 assert(ret < 0);
497 put_io_u(td, io_u);
498 break;
Jens Axboeebac4652005-12-08 15:25:21 +0100499 }
500
Jens Axboe99784632007-02-19 10:06:17 +0100501 if (ret < 0 || td->error)
Jens Axboe36167d82007-02-18 05:41:31 +0100502 break;
503
Jens Axboe97601022007-02-18 12:47:29 +0100504 /*
505 * See if we need to complete some commands
506 */
Jens Axboe755200a2007-02-19 13:08:12 +0100507 if (ret == FIO_Q_QUEUED || ret == FIO_Q_BUSY) {
Jens Axboe97601022007-02-18 12:47:29 +0100508 min_evts = 0;
Jens Axboee916b392007-02-20 14:37:26 +0100509 if (queue_full(td) || ret == FIO_Q_BUSY) {
Jens Axboe36167d82007-02-18 05:41:31 +0100510 min_evts = 1;
Jens Axboeebac4652005-12-08 15:25:21 +0100511
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100512 if (td->cur_depth > td->o.iodepth_low)
513 min_evts = td->cur_depth - td->o.iodepth_low;
Jens Axboee916b392007-02-20 14:37:26 +0100514 }
515
Jens Axboe97601022007-02-18 12:47:29 +0100516 fio_gettime(&comp_time, NULL);
Jens Axboed7762cf2007-02-23 12:34:57 +0100517 bytes_done = io_u_queued_complete(td, min_evts);
Jens Axboe97601022007-02-18 12:47:29 +0100518 if (bytes_done < 0)
Jens Axboe36167d82007-02-18 05:41:31 +0100519 break;
Jens Axboeebac4652005-12-08 15:25:21 +0100520 }
521
Jens Axboe97601022007-02-18 12:47:29 +0100522 if (!bytes_done)
523 continue;
524
Jens Axboeebac4652005-12-08 15:25:21 +0100525 /*
526 * the rate is batched for now, it should work for batches
527 * of completions except the very first one which may look
528 * a little bursty
529 */
Jens Axboe97601022007-02-18 12:47:29 +0100530 usec = utime_since(&s, &comp_time);
Jens Axboeebac4652005-12-08 15:25:21 +0100531
Jens Axboe413dd452007-02-23 09:26:09 +0100532 rate_throttle(td, usec, bytes_done);
Jens Axboeebac4652005-12-08 15:25:21 +0100533
Jens Axboe97601022007-02-18 12:47:29 +0100534 if (check_min_rate(td, &comp_time)) {
Jens Axboe98aa62d2006-11-07 14:16:19 +0100535 if (exitall_on_terminate)
Jens Axboe390c40e2007-03-05 12:35:29 +0100536 terminate_threads(td->groupid);
Jens Axboee1161c32007-02-22 19:36:48 +0100537 td_verror(td, ENODATA, "check_min_rate");
Jens Axboeebac4652005-12-08 15:25:21 +0100538 break;
539 }
540
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100541 if (td->o.thinktime) {
Jens Axboe9c1f7432007-01-03 20:43:19 +0100542 unsigned long long b;
543
544 b = td->io_blocks[0] + td->io_blocks[1];
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100545 if (!(b % td->o.thinktime_blocks)) {
Jens Axboe48097d52007-02-17 06:30:44 +0100546 int left;
547
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100548 if (td->o.thinktime_spin)
549 __usec_sleep(td->o.thinktime_spin);
Jens Axboe48097d52007-02-17 06:30:44 +0100550
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100551 left = td->o.thinktime - td->o.thinktime_spin;
Jens Axboe48097d52007-02-17 06:30:44 +0100552 if (left)
553 usec_sleep(td, left);
554 }
Jens Axboe9c1f7432007-01-03 20:43:19 +0100555 }
Jens Axboeebac4652005-12-08 15:25:21 +0100556 }
557
Jens Axboe4d2413c2006-11-23 11:58:59 +0100558 if (!td->error) {
Jens Axboe3d7c3912007-02-19 13:16:12 +0100559 struct fio_file *f;
560
Jens Axboec01c0392007-02-26 12:43:42 +0100561 i = td->cur_depth;
562 if (i)
563 ret = io_u_queued_complete(td, i);
Jens Axboeebac4652005-12-08 15:25:21 +0100564
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100565 if (should_fsync(td) && td->o.end_fsync) {
Jens Axboe84585002006-10-19 20:26:22 +0200566 td_set_runstate(td, TD_FSYNCING);
Jens Axboe3d7b4852007-03-13 14:50:28 +0100567
568 for_each_file(td, f, i) {
569 if (!(f->flags & FIO_FILE_OPEN))
570 continue;
Jens Axboe858a3d42006-10-24 14:54:44 +0200571 fio_io_sync(td, f);
Jens Axboe3d7b4852007-03-13 14:50:28 +0100572 }
Jens Axboe84585002006-10-19 20:26:22 +0200573 }
Jens Axboec01c0392007-02-26 12:43:42 +0100574 } else
575 cleanup_pending_aio(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100576}
577
Jens Axboeebac4652005-12-08 15:25:21 +0100578static void cleanup_io_u(struct thread_data *td)
579{
580 struct list_head *entry, *n;
581 struct io_u *io_u;
582
583 list_for_each_safe(entry, n, &td->io_u_freelist) {
584 io_u = list_entry(entry, struct io_u, list);
585
586 list_del(&io_u->list);
587 free(io_u);
588 }
589
Jens Axboe2f9ade32006-10-20 11:25:52 +0200590 free_io_mem(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100591}
592
Jens Axboe6b9cea22006-10-30 17:00:24 +0100593/*
594 * "randomly" fill the buffer contents
595 */
Jens Axboee9459e52007-04-17 15:46:32 +0200596static void fill_io_buf(struct thread_data *td, struct io_u *io_u, int max_bs)
Jens Axboe6b9cea22006-10-30 17:00:24 +0100597{
Jens Axboe66eeb292006-11-01 08:35:44 +0100598 int *ptr = io_u->buf;
Jens Axboe6b9cea22006-10-30 17:00:24 +0100599
Jens Axboee9459e52007-04-17 15:46:32 +0200600 if (!td->o.zero_buffers) {
601 while ((void *) ptr - io_u->buf < max_bs) {
602 *ptr = rand() * 0x9e370001;
603 ptr++;
604 }
605 } else
606 memset(ptr, 0, max_bs);
Jens Axboe6b9cea22006-10-30 17:00:24 +0100607}
608
Jens Axboeebac4652005-12-08 15:25:21 +0100609static int init_io_u(struct thread_data *td)
610{
Jens Axboe2b4ce342007-03-21 10:32:54 +0100611 unsigned long long buf_size;
Jens Axboeebac4652005-12-08 15:25:21 +0100612 struct io_u *io_u;
Jens Axboea00735e2006-11-03 08:58:08 +0100613 unsigned int max_bs;
Jens Axboeebac4652005-12-08 15:25:21 +0100614 int i, max_units;
615 char *p;
616
Jens Axboe2866c822006-10-09 15:57:48 +0200617 if (td->io_ops->flags & FIO_SYNCIO)
Jens Axboeebac4652005-12-08 15:25:21 +0100618 max_units = 1;
619 else
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100620 max_units = td->o.iodepth;
Jens Axboeebac4652005-12-08 15:25:21 +0100621
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100622 max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
Jens Axboe2b4ce342007-03-21 10:32:54 +0100623 buf_size = (unsigned long long) max_bs * (unsigned long long) max_units;
624 buf_size += page_mask;
625 if (buf_size != (size_t) buf_size) {
626 log_err("fio: IO memory too large. Reduce max_bs or iodepth\n");
627 return 1;
628 }
629
630 td->orig_buffer_size = buf_size;
Jens Axboe74b025b2006-12-19 15:18:14 +0100631
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100632 if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE)
633 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 +0100634 else if (td->orig_buffer_size & page_mask)
635 td->orig_buffer_size = (td->orig_buffer_size + page_mask) & ~page_mask;
Jens Axboeebac4652005-12-08 15:25:21 +0100636
Jens Axboe2f9ade32006-10-20 11:25:52 +0200637 if (allocate_io_mem(td))
638 return 1;
Jens Axboeebac4652005-12-08 15:25:21 +0100639
Jens Axboeebac4652005-12-08 15:25:21 +0100640 p = ALIGN(td->orig_buffer);
641 for (i = 0; i < max_units; i++) {
642 io_u = malloc(sizeof(*io_u));
643 memset(io_u, 0, sizeof(*io_u));
644 INIT_LIST_HEAD(&io_u->list);
645
Jens Axboea00735e2006-11-03 08:58:08 +0100646 io_u->buf = p + max_bs * i;
Jens Axboee9459e52007-04-17 15:46:32 +0200647
Jens Axboe660a1cb2007-04-17 15:37:47 +0200648 if (td_write(td))
Jens Axboee9459e52007-04-17 15:46:32 +0200649 fill_io_buf(td, io_u, max_bs);
Jens Axboe6b9cea22006-10-30 17:00:24 +0100650
Jens Axboeb1ff3402006-02-17 11:35:58 +0100651 io_u->index = i;
Jens Axboe0c6e7512007-02-22 11:19:39 +0100652 io_u->flags = IO_U_F_FREE;
Jens Axboeebac4652005-12-08 15:25:21 +0100653 list_add(&io_u->list, &td->io_u_freelist);
654 }
655
Jens Axboe433afcb2007-02-22 10:39:01 +0100656 io_u_init_timeout();
657
Jens Axboeebac4652005-12-08 15:25:21 +0100658 return 0;
659}
660
Jens Axboeda867742006-06-06 10:39:10 -0700661static int switch_ioscheduler(struct thread_data *td)
662{
663 char tmp[256], tmp2[128];
664 FILE *f;
665 int ret;
666
Jens Axboeba0fbe12007-03-09 14:34:23 +0100667 if (td->io_ops->flags & FIO_DISKLESSIO)
Jens Axboef48b4672006-10-27 11:30:07 +0200668 return 0;
669
Jens Axboeda867742006-06-06 10:39:10 -0700670 sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
671
672 f = fopen(tmp, "r+");
673 if (!f) {
Jens Axboecbf5c1d2007-04-16 12:56:00 +0200674 if (errno == ENOENT) {
675 log_err("fio: os or kernel doesn't support IO scheduler switching\n");
676 return 0;
677 }
678 td_verror(td, errno, "fopen iosched");
Jens Axboeda867742006-06-06 10:39:10 -0700679 return 1;
680 }
681
682 /*
683 * Set io scheduler.
684 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100685 ret = fwrite(td->o.ioscheduler, strlen(td->o.ioscheduler), 1, f);
Jens Axboeda867742006-06-06 10:39:10 -0700686 if (ferror(f) || ret != 1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100687 td_verror(td, errno, "fwrite");
Jens Axboeda867742006-06-06 10:39:10 -0700688 fclose(f);
689 return 1;
690 }
691
692 rewind(f);
693
694 /*
695 * Read back and check that the selected scheduler is now the default.
696 */
697 ret = fread(tmp, 1, sizeof(tmp), f);
698 if (ferror(f) || ret < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100699 td_verror(td, errno, "fread");
Jens Axboeda867742006-06-06 10:39:10 -0700700 fclose(f);
701 return 1;
702 }
703
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100704 sprintf(tmp2, "[%s]", td->o.ioscheduler);
Jens Axboeda867742006-06-06 10:39:10 -0700705 if (!strstr(tmp, tmp2)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100706 log_err("fio: io scheduler %s not found\n", td->o.ioscheduler);
Jens Axboee1161c32007-02-22 19:36:48 +0100707 td_verror(td, EINVAL, "iosched_switch");
Jens Axboeda867742006-06-06 10:39:10 -0700708 fclose(f);
709 return 1;
710 }
711
712 fclose(f);
713 return 0;
714}
715
Jens Axboea978ba62007-03-08 14:29:03 +0100716static int clear_io_state(struct thread_data *td)
Jens Axboeebac4652005-12-08 15:25:21 +0100717{
Jens Axboe53cdc682006-10-18 11:50:58 +0200718 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100719 unsigned int i;
720 int ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100721
Jens Axboe756867b2007-03-06 15:19:24 +0100722 td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100723 td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
Jens Axboe20dc95c2005-12-09 10:29:35 +0100724 td->zone_bytes = 0;
Jens Axboed7d3b492007-03-12 08:02:10 +0100725 td->rate_bytes = 0;
Jens Axboe4e991c22007-03-15 11:41:11 +0100726 td->rate_blocks = 0;
Jens Axboe38d77ca2007-03-21 14:20:20 +0100727 td->rw_end_set[0] = td->rw_end_set[1] = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100728
Jens Axboec1324df2007-02-19 19:06:41 +0100729 td->last_was_sync = 0;
730
Jens Axboea978ba62007-03-08 14:29:03 +0100731 for_each_file(td, f, i)
732 td_io_close_file(td, f);
733
734 ret = 0;
Jens Axboe53cdc682006-10-18 11:50:58 +0200735 for_each_file(td, f, i) {
Jens Axboea978ba62007-03-08 14:29:03 +0100736 ret = td_io_open_file(td, f);
737 if (ret)
738 break;
Jens Axboe53cdc682006-10-18 11:50:58 +0200739 }
Jens Axboea978ba62007-03-08 14:29:03 +0100740
741 return ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100742}
743
Jens Axboe906c8d72006-06-13 09:37:56 +0200744/*
745 * Entry point for the thread based jobs. The process based jobs end up
746 * here as well, after a little setup.
747 */
Jens Axboeebac4652005-12-08 15:25:21 +0100748static void *thread_main(void *data)
749{
Jens Axboe69008992006-11-24 13:12:56 +0100750 unsigned long long runtime[2];
Jens Axboeebac4652005-12-08 15:25:21 +0100751 struct thread_data *td = data;
Jens Axboe38d77ca2007-03-21 14:20:20 +0100752 unsigned long elapsed;
Jens Axboea978ba62007-03-08 14:29:03 +0100753 int clear_state;
Jens Axboeebac4652005-12-08 15:25:21 +0100754
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100755 if (!td->o.use_thread)
Jens Axboeebac4652005-12-08 15:25:21 +0100756 setsid();
757
758 td->pid = getpid();
759
Jens Axboeaea47d42006-05-26 19:27:29 +0200760 INIT_LIST_HEAD(&td->io_u_freelist);
761 INIT_LIST_HEAD(&td->io_u_busylist);
Jens Axboe755200a2007-02-19 13:08:12 +0100762 INIT_LIST_HEAD(&td->io_u_requeues);
Jens Axboeaea47d42006-05-26 19:27:29 +0200763 INIT_LIST_HEAD(&td->io_log_list);
Jens Axboe8de8f042007-03-27 10:36:12 +0200764 INIT_LIST_HEAD(&td->io_hist_list);
Jens Axboebb5d7d02007-03-27 10:21:25 +0200765 td->io_hist_tree = RB_ROOT;
Jens Axboeaea47d42006-05-26 19:27:29 +0200766
Jens Axboeebac4652005-12-08 15:25:21 +0100767 if (init_io_u(td))
Jens Axboebda4fd92007-03-12 11:21:48 +0100768 goto err_sem;
Jens Axboeebac4652005-12-08 15:25:21 +0100769
770 if (fio_setaffinity(td) == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100771 td_verror(td, errno, "cpu_set_affinity");
Jens Axboebda4fd92007-03-12 11:21:48 +0100772 goto err_sem;
Jens Axboeebac4652005-12-08 15:25:21 +0100773 }
774
Jens Axboeaea47d42006-05-26 19:27:29 +0200775 if (init_iolog(td))
Jens Axboebda4fd92007-03-12 11:21:48 +0100776 goto err_sem;
Jens Axboeaea47d42006-05-26 19:27:29 +0200777
Jens Axboeebac4652005-12-08 15:25:21 +0100778 if (td->ioprio) {
779 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100780 td_verror(td, errno, "ioprio_set");
Jens Axboebda4fd92007-03-12 11:21:48 +0100781 goto err_sem;
Jens Axboeebac4652005-12-08 15:25:21 +0100782 }
783 }
784
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100785 if (nice(td->o.nice) == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100786 td_verror(td, errno, "nice");
Jens Axboebda4fd92007-03-12 11:21:48 +0100787 goto err_sem;
Jens Axboeb6f4d882006-06-02 10:32:51 +0200788 }
789
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100790 if (td->o.ioscheduler && switch_ioscheduler(td))
Jens Axboebda4fd92007-03-12 11:21:48 +0100791 goto err_sem;
Jens Axboeda867742006-06-06 10:39:10 -0700792
Jens Axboe75154842006-06-01 13:56:09 +0200793 td_set_runstate(td, TD_INITIALIZED);
Jens Axboe07739b52007-03-08 20:25:46 +0100794 fio_sem_up(startup_sem);
795 fio_sem_down(td->mutex);
Jens Axboeebac4652005-12-08 15:25:21 +0100796
Jens Axboe37f56872007-03-09 12:42:35 +0100797 /*
798 * the ->mutex semaphore is now no longer used, close it to avoid
799 * eating a file descriptor
800 */
801 fio_sem_remove(td->mutex);
802
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100803 if (!td->o.create_serialize && setup_files(td))
Jens Axboeebac4652005-12-08 15:25:21 +0100804 goto err;
Jens Axboeb5af8292007-03-08 12:43:13 +0100805
806 if (td_io_init(td))
Jens Axboe21972cd2006-11-23 12:39:16 +0100807 goto err;
Jens Axboeebac4652005-12-08 15:25:21 +0100808
Jens Axboeb5af8292007-03-08 12:43:13 +0100809 if (open_files(td))
Jens Axboe7d6c5282007-02-05 10:52:10 +0100810 goto err;
811
Jens Axboe68727072007-03-15 20:49:25 +0100812 if (init_random_map(td))
813 goto err;
814
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100815 if (td->o.exec_prerun) {
816 if (system(td->o.exec_prerun) < 0)
Jens Axboe69cfd7e2007-02-07 13:58:53 +0100817 goto err;
818 }
Jens Axboe4e0ba8a2006-06-06 09:36:28 +0200819
Jens Axboe69008992006-11-24 13:12:56 +0100820 fio_gettime(&td->epoch, NULL);
Jens Axboe433afcb2007-02-22 10:39:01 +0100821 memcpy(&td->timeout_end, &td->epoch, sizeof(td->epoch));
Jens Axboe756867b2007-03-06 15:19:24 +0100822 getrusage(RUSAGE_SELF, &td->ts.ru_start);
Jens Axboe69008992006-11-24 13:12:56 +0100823
824 runtime[0] = runtime[1] = 0;
Jens Axboea978ba62007-03-08 14:29:03 +0100825 clear_state = 0;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100826 while (td->o.loops--) {
Jens Axboe02bcaa82006-11-24 10:42:00 +0100827 fio_gettime(&td->start, NULL);
Jens Axboe756867b2007-03-06 15:19:24 +0100828 memcpy(&td->ts.stat_sample_time, &td->start, sizeof(td->start));
Jens Axboeebac4652005-12-08 15:25:21 +0100829
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100830 if (td->o.ratemin)
Jens Axboe756867b2007-03-06 15:19:24 +0100831 memcpy(&td->lastrate, &td->ts.stat_sample_time, sizeof(td->lastrate));
Jens Axboeebac4652005-12-08 15:25:21 +0100832
Jens Axboea978ba62007-03-08 14:29:03 +0100833 if (clear_state && clear_io_state(td))
834 break;
835
Jens Axboeebac4652005-12-08 15:25:21 +0100836 prune_io_piece_log(td);
837
Jens Axboeba0fbe12007-03-09 14:34:23 +0100838 do_io(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100839
Jens Axboea978ba62007-03-08 14:29:03 +0100840 clear_state = 1;
841
Jens Axboe38d77ca2007-03-21 14:20:20 +0100842 if (td_read(td) && td->io_bytes[DDIR_READ]) {
843 if (td->rw_end_set[DDIR_READ])
844 elapsed = utime_since(&td->start, &td->rw_end[DDIR_READ]);
845 else
846 elapsed = utime_since_now(&td->start);
847
848 runtime[DDIR_READ] += elapsed;
849 }
850 if (td_write(td) && td->io_bytes[DDIR_WRITE]) {
851 if (td->rw_end_set[DDIR_WRITE])
852 elapsed = utime_since(&td->start, &td->rw_end[DDIR_WRITE]);
853 else
854 elapsed = utime_since_now(&td->start);
855
856 runtime[DDIR_WRITE] += elapsed;
857 }
Jens Axboe413dd452007-02-23 09:26:09 +0100858
Jens Axboeebac4652005-12-08 15:25:21 +0100859 if (td->error || td->terminate)
860 break;
861
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100862 if (td->o.verify == VERIFY_NONE)
Jens Axboeebac4652005-12-08 15:25:21 +0100863 continue;
864
Jens Axboea978ba62007-03-08 14:29:03 +0100865 if (clear_io_state(td))
866 break;
867
Jens Axboe02bcaa82006-11-24 10:42:00 +0100868 fio_gettime(&td->start, NULL);
Jens Axboeebac4652005-12-08 15:25:21 +0100869
870 do_verify(td);
871
Jens Axboe69008992006-11-24 13:12:56 +0100872 runtime[DDIR_READ] += utime_since_now(&td->start);
Jens Axboeebac4652005-12-08 15:25:21 +0100873
874 if (td->error || td->terminate)
875 break;
876 }
877
Jens Axboe36dff962006-11-24 13:29:20 +0100878 update_rusage_stat(td);
Jens Axboe756867b2007-03-06 15:19:24 +0100879 td->ts.runtime[0] = runtime[0] / 1000;
880 td->ts.runtime[1] = runtime[1] / 1000;
881 td->ts.total_run_time = mtime_since_now(&td->epoch);
882 td->ts.io_bytes[0] = td->io_bytes[0];
883 td->ts.io_bytes[1] = td->io_bytes[1];
Jens Axboe69008992006-11-24 13:12:56 +0100884
Jens Axboe756867b2007-03-06 15:19:24 +0100885 if (td->ts.bw_log)
886 finish_log(td, td->ts.bw_log, "bw");
887 if (td->ts.slat_log)
888 finish_log(td, td->ts.slat_log, "slat");
889 if (td->ts.clat_log)
890 finish_log(td, td->ts.clat_log, "clat");
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100891 if (td->o.write_iolog_file)
Jens Axboe843a7412006-06-01 21:14:21 -0700892 write_iolog_close(td);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100893 if (td->o.exec_postrun) {
894 if (system(td->o.exec_postrun) < 0)
895 log_err("fio: postrun %s failed\n", td->o.exec_postrun);
Jens Axboe69cfd7e2007-02-07 13:58:53 +0100896 }
Jens Axboeebac4652005-12-08 15:25:21 +0100897
898 if (exitall_on_terminate)
Jens Axboe390c40e2007-03-05 12:35:29 +0100899 terminate_threads(td->groupid);
Jens Axboeebac4652005-12-08 15:25:21 +0100900
901err:
Jens Axboe5bf13a52007-02-17 01:51:47 +0100902 if (td->error)
903 printf("fio: pid=%d, err=%d/%s\n", td->pid, td->error, td->verror);
Jens Axboe53cdc682006-10-18 11:50:58 +0200904 close_files(td);
Jens Axboe2866c822006-10-09 15:57:48 +0200905 close_ioengine(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100906 cleanup_io_u(td);
Jens Axboed23bb322007-03-23 15:57:56 +0100907 options_mem_free(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100908 td_set_runstate(td, TD_EXITED);
Jens Axboe43d76802007-02-21 16:35:29 +0100909 return (void *) (unsigned long) td->error;
Jens Axboebda4fd92007-03-12 11:21:48 +0100910err_sem:
911 fio_sem_up(startup_sem);
912 goto err;
Jens Axboeebac4652005-12-08 15:25:21 +0100913}
914
Jens Axboe906c8d72006-06-13 09:37:56 +0200915/*
916 * We cannot pass the td data into a forked process, so attach the td and
917 * pass it to the thread worker.
918 */
Jens Axboea6418142007-02-17 04:47:18 +0100919static int fork_main(int shmid, int offset)
Jens Axboeebac4652005-12-08 15:25:21 +0100920{
921 struct thread_data *td;
Jens Axboea6418142007-02-17 04:47:18 +0100922 void *data, *ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100923
924 data = shmat(shmid, NULL, 0);
925 if (data == (void *) -1) {
Jens Axboea6418142007-02-17 04:47:18 +0100926 int __err = errno;
927
Jens Axboeebac4652005-12-08 15:25:21 +0100928 perror("shmat");
Jens Axboea6418142007-02-17 04:47:18 +0100929 return __err;
Jens Axboeebac4652005-12-08 15:25:21 +0100930 }
931
932 td = data + offset * sizeof(struct thread_data);
Jens Axboea6418142007-02-17 04:47:18 +0100933 ret = thread_main(td);
Jens Axboeebac4652005-12-08 15:25:21 +0100934 shmdt(data);
Jens Axboe43d76802007-02-21 16:35:29 +0100935 return (int) (unsigned long) ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100936}
937
Jens Axboe906c8d72006-06-13 09:37:56 +0200938/*
Jens Axboe906c8d72006-06-13 09:37:56 +0200939 * Run over the job map and reap the threads that have exited, if any.
940 */
Jens Axboeebac4652005-12-08 15:25:21 +0100941static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
942{
Jens Axboe34572e22006-10-20 09:33:18 +0200943 struct thread_data *td;
Jens Axboefab6aa72007-02-17 06:19:24 +0100944 int i, cputhreads, pending, status, ret;
Jens Axboeebac4652005-12-08 15:25:21 +0100945
946 /*
947 * reap exited threads (TD_EXITED -> TD_REAPED)
948 */
Jens Axboe4d2413c2006-11-23 11:58:59 +0100949 pending = cputhreads = 0;
Jens Axboe34572e22006-10-20 09:33:18 +0200950 for_each_td(td, i) {
Jens Axboe3707f452007-02-22 12:26:57 +0100951 int flags = 0;
Jens Axboea2f77c92007-02-22 11:53:00 +0100952
Jens Axboe84585002006-10-19 20:26:22 +0200953 /*
954 * ->io_ops is NULL for a thread that has closed its
955 * io engine
956 */
Jens Axboeba0fbe12007-03-09 14:34:23 +0100957 if (td->io_ops && !strcmp(td->io_ops->name, "cpuio"))
Jens Axboeb990b5c2006-09-14 09:48:22 +0200958 cputhreads++;
959
Jens Axboea2f77c92007-02-22 11:53:00 +0100960 if (!td->pid || td->runstate == TD_REAPED)
961 continue;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100962 if (td->o.use_thread) {
Jens Axboe3707f452007-02-22 12:26:57 +0100963 if (td->runstate == TD_EXITED) {
964 td_set_runstate(td, TD_REAPED);
965 goto reaped;
966 }
967 continue;
968 }
Jens Axboea2f77c92007-02-22 11:53:00 +0100969
970 flags = WNOHANG;
971 if (td->runstate == TD_EXITED)
972 flags = 0;
973
974 /*
975 * check if someone quit or got killed in an unusual way
976 */
977 ret = waitpid(td->pid, &status, flags);
Jens Axboe3707f452007-02-22 12:26:57 +0100978 if (ret < 0) {
Jens Axboea2f77c92007-02-22 11:53:00 +0100979 if (errno == ECHILD) {
980 log_err("fio: pid=%d disappeared %d\n", td->pid, td->runstate);
981 td_set_runstate(td, TD_REAPED);
982 goto reaped;
983 }
984 perror("waitpid");
985 } else if (ret == td->pid) {
986 if (WIFSIGNALED(status)) {
Jens Axboefab6aa72007-02-17 06:19:24 +0100987 int sig = WTERMSIG(status);
988
Jens Axboed9244942007-03-05 12:32:32 +0100989 if (sig != SIGQUIT)
990 log_err("fio: pid=%d, got signal=%d\n", td->pid, sig);
Jens Axboefab6aa72007-02-17 06:19:24 +0100991 td_set_runstate(td, TD_REAPED);
992 goto reaped;
993 }
Jens Axboea2f77c92007-02-22 11:53:00 +0100994 if (WIFEXITED(status)) {
995 if (WEXITSTATUS(status) && !td->error)
996 td->error = WEXITSTATUS(status);
Jens Axboefab6aa72007-02-17 06:19:24 +0100997
Jens Axboea2f77c92007-02-22 11:53:00 +0100998 td_set_runstate(td, TD_REAPED);
999 goto reaped;
Jens Axboea6418142007-02-17 04:47:18 +01001000 }
1001 }
Jens Axboeebac4652005-12-08 15:25:21 +01001002
Jens Axboea2f77c92007-02-22 11:53:00 +01001003 /*
1004 * thread is not dead, continue
1005 */
gurudas paie48676b2007-04-11 12:44:27 +02001006 pending++;
Jens Axboea2f77c92007-02-22 11:53:00 +01001007 continue;
Jens Axboefab6aa72007-02-17 06:19:24 +01001008reaped:
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001009 if (td->o.use_thread) {
Jens Axboe3707f452007-02-22 12:26:57 +01001010 long ret;
1011
1012 if (pthread_join(td->thread, (void *) &ret))
1013 perror("pthread_join");
1014 }
1015
Jens Axboeebac4652005-12-08 15:25:21 +01001016 (*nr_running)--;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001017 (*m_rate) -= td->o.ratemin;
1018 (*t_rate) -= td->o.rate;
gurudas paie48676b2007-04-11 12:44:27 +02001019 pending--;
Jens Axboea2f77c92007-02-22 11:53:00 +01001020
1021 if (td->error)
1022 exit_value++;
Jens Axboeebac4652005-12-08 15:25:21 +01001023 }
Jens Axboeb990b5c2006-09-14 09:48:22 +02001024
Jens Axboe4d2413c2006-11-23 11:58:59 +01001025 if (*nr_running == cputhreads && !pending)
Jens Axboe390c40e2007-03-05 12:35:29 +01001026 terminate_threads(TERMINATE_ALL);
Jens Axboeebac4652005-12-08 15:25:21 +01001027}
1028
Jens Axboe906c8d72006-06-13 09:37:56 +02001029/*
1030 * Main function for kicking off and reaping jobs, as needed.
1031 */
Jens Axboeebac4652005-12-08 15:25:21 +01001032static void run_threads(void)
1033{
Jens Axboeebac4652005-12-08 15:25:21 +01001034 struct thread_data *td;
1035 unsigned long spent;
1036 int i, todo, nr_running, m_rate, t_rate, nr_started;
Jens Axboefcb6ade2006-05-31 12:14:35 +02001037
Jens Axboe2f9ade32006-10-20 11:25:52 +02001038 if (fio_pin_memory())
1039 return;
Jens Axboeebac4652005-12-08 15:25:21 +01001040
Jens Axboec6ae0a52006-06-12 11:04:44 +02001041 if (!terse_output) {
Jens Axboe9cedf162007-03-12 11:29:30 +01001042 printf("Starting ");
1043 if (nr_thread)
1044 printf("%d thread%s", nr_thread, nr_thread > 1 ? "s" : "");
1045 if (nr_process) {
1046 if (nr_thread)
1047 printf(" and ");
1048 printf("%d process%s", nr_process, nr_process > 1 ? "es" : "");
1049 }
1050 printf("\n");
Jens Axboec6ae0a52006-06-12 11:04:44 +02001051 fflush(stdout);
1052 }
Jens Axboec04f7ec2006-05-31 10:13:16 +02001053
Jens Axboe4efa9702006-05-31 11:56:49 +02001054 signal(SIGINT, sig_handler);
1055 signal(SIGALRM, sig_handler);
1056
Jens Axboeebac4652005-12-08 15:25:21 +01001057 todo = thread_number;
1058 nr_running = 0;
1059 nr_started = 0;
1060 m_rate = t_rate = 0;
1061
Jens Axboe34572e22006-10-20 09:33:18 +02001062 for_each_td(td, i) {
Jens Axboe263e5292006-10-18 15:37:01 +02001063 print_status_init(td->thread_number - 1);
Jens Axboeebac4652005-12-08 15:25:21 +01001064
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001065 if (!td->o.create_serialize) {
Jens Axboe380cf262007-01-11 14:01:27 +01001066 init_disk_util(td);
Jens Axboeebac4652005-12-08 15:25:21 +01001067 continue;
Jens Axboe380cf262007-01-11 14:01:27 +01001068 }
Jens Axboeebac4652005-12-08 15:25:21 +01001069
1070 /*
1071 * do file setup here so it happens sequentially,
1072 * we don't want X number of threads getting their
1073 * client data interspersed on disk
1074 */
Jens Axboe53cdc682006-10-18 11:50:58 +02001075 if (setup_files(td)) {
Jens Axboe5bf13a52007-02-17 01:51:47 +01001076 exit_value++;
1077 if (td->error)
1078 log_err("fio: pid=%d, err=%d/%s\n", td->pid, td->error, td->verror);
Jens Axboeebac4652005-12-08 15:25:21 +01001079 td_set_runstate(td, TD_REAPED);
1080 todo--;
1081 }
Jens Axboe380cf262007-01-11 14:01:27 +01001082
1083 init_disk_util(td);
Jens Axboeebac4652005-12-08 15:25:21 +01001084 }
1085
Jens Axboea2f77c92007-02-22 11:53:00 +01001086 set_genesis_time();
1087
Jens Axboeebac4652005-12-08 15:25:21 +01001088 while (todo) {
Jens Axboe75154842006-06-01 13:56:09 +02001089 struct thread_data *map[MAX_JOBS];
1090 struct timeval this_start;
1091 int this_jobs = 0, left;
1092
Jens Axboeebac4652005-12-08 15:25:21 +01001093 /*
1094 * create threads (TD_NOT_CREATED -> TD_CREATED)
1095 */
Jens Axboe34572e22006-10-20 09:33:18 +02001096 for_each_td(td, i) {
Jens Axboeebac4652005-12-08 15:25:21 +01001097 if (td->runstate != TD_NOT_CREATED)
1098 continue;
1099
1100 /*
1101 * never got a chance to start, killed by other
1102 * thread for some reason
1103 */
1104 if (td->terminate) {
1105 todo--;
1106 continue;
1107 }
1108
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001109 if (td->o.start_delay) {
Jens Axboe263e5292006-10-18 15:37:01 +02001110 spent = mtime_since_genesis();
Jens Axboeebac4652005-12-08 15:25:21 +01001111
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001112 if (td->o.start_delay * 1000 > spent)
Jens Axboeebac4652005-12-08 15:25:21 +01001113 continue;
1114 }
1115
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001116 if (td->o.stonewall && (nr_started || nr_running))
Jens Axboeebac4652005-12-08 15:25:21 +01001117 break;
1118
Jens Axboe75154842006-06-01 13:56:09 +02001119 /*
1120 * Set state to created. Thread will transition
1121 * to TD_INITIALIZED when it's done setting up.
1122 */
Jens Axboeebac4652005-12-08 15:25:21 +01001123 td_set_runstate(td, TD_CREATED);
Jens Axboe75154842006-06-01 13:56:09 +02001124 map[this_jobs++] = td;
Jens Axboeebac4652005-12-08 15:25:21 +01001125 nr_started++;
1126
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001127 if (td->o.use_thread) {
Jens Axboeebac4652005-12-08 15:25:21 +01001128 if (pthread_create(&td->thread, NULL, thread_main, td)) {
1129 perror("thread_create");
1130 nr_started--;
Jens Axboec8bb6fa2007-03-12 11:03:04 +01001131 break;
Jens Axboeebac4652005-12-08 15:25:21 +01001132 }
1133 } else {
Jens Axboe07739b52007-03-08 20:25:46 +01001134 if (!fork()) {
Jens Axboea6418142007-02-17 04:47:18 +01001135 int ret = fork_main(shm_id, i);
1136
1137 exit(ret);
Jens Axboeebac4652005-12-08 15:25:21 +01001138 }
1139 }
Jens Axboe07739b52007-03-08 20:25:46 +01001140 fio_sem_down(startup_sem);
Jens Axboeebac4652005-12-08 15:25:21 +01001141 }
1142
1143 /*
Jens Axboe75154842006-06-01 13:56:09 +02001144 * Wait for the started threads to transition to
1145 * TD_INITIALIZED.
Jens Axboeebac4652005-12-08 15:25:21 +01001146 */
Jens Axboe02bcaa82006-11-24 10:42:00 +01001147 fio_gettime(&this_start, NULL);
Jens Axboe75154842006-06-01 13:56:09 +02001148 left = this_jobs;
Jens Axboe6ce15a32007-01-12 09:04:41 +01001149 while (left && !fio_abort) {
Jens Axboe75154842006-06-01 13:56:09 +02001150 if (mtime_since_now(&this_start) > JOB_START_TIMEOUT)
1151 break;
1152
1153 usleep(100000);
1154
1155 for (i = 0; i < this_jobs; i++) {
1156 td = map[i];
1157 if (!td)
1158 continue;
Jens Axboeb6f4d882006-06-02 10:32:51 +02001159 if (td->runstate == TD_INITIALIZED) {
Jens Axboe75154842006-06-01 13:56:09 +02001160 map[i] = NULL;
1161 left--;
Jens Axboeb6f4d882006-06-02 10:32:51 +02001162 } else if (td->runstate >= TD_EXITED) {
1163 map[i] = NULL;
1164 left--;
1165 todo--;
1166 nr_running++; /* work-around... */
Jens Axboe75154842006-06-01 13:56:09 +02001167 }
1168 }
1169 }
1170
1171 if (left) {
Jens Axboe3b70d7e2006-06-08 21:48:46 +02001172 log_err("fio: %d jobs failed to start\n", left);
Jens Axboe75154842006-06-01 13:56:09 +02001173 for (i = 0; i < this_jobs; i++) {
1174 td = map[i];
1175 if (!td)
1176 continue;
1177 kill(td->pid, SIGTERM);
1178 }
1179 break;
1180 }
1181
1182 /*
Jens Axboeb6f4d882006-06-02 10:32:51 +02001183 * start created threads (TD_INITIALIZED -> TD_RUNNING).
Jens Axboe75154842006-06-01 13:56:09 +02001184 */
Jens Axboe34572e22006-10-20 09:33:18 +02001185 for_each_td(td, i) {
Jens Axboe75154842006-06-01 13:56:09 +02001186 if (td->runstate != TD_INITIALIZED)
Jens Axboeebac4652005-12-08 15:25:21 +01001187 continue;
1188
1189 td_set_runstate(td, TD_RUNNING);
1190 nr_running++;
1191 nr_started--;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001192 m_rate += td->o.ratemin;
1193 t_rate += td->o.rate;
Jens Axboe75154842006-06-01 13:56:09 +02001194 todo--;
Jens Axboe07739b52007-03-08 20:25:46 +01001195 fio_sem_up(td->mutex);
Jens Axboeebac4652005-12-08 15:25:21 +01001196 }
1197
1198 reap_threads(&nr_running, &t_rate, &m_rate);
1199
1200 if (todo)
1201 usleep(100000);
1202 }
1203
1204 while (nr_running) {
1205 reap_threads(&nr_running, &t_rate, &m_rate);
1206 usleep(10000);
1207 }
1208
1209 update_io_ticks();
Jens Axboe2f9ade32006-10-20 11:25:52 +02001210 fio_unpin_memory();
Jens Axboeebac4652005-12-08 15:25:21 +01001211}
1212
Jens Axboeebac4652005-12-08 15:25:21 +01001213int main(int argc, char *argv[])
1214{
Jens Axboe29d610e2007-02-06 13:25:33 +01001215 long ps;
1216
Jens Axboedbe11252007-02-11 00:19:51 +01001217 /*
1218 * We need locale for number printing, if it isn't set then just
1219 * go with the US format.
1220 */
1221 if (!getenv("LC_NUMERIC"))
1222 setlocale(LC_NUMERIC, "en_US");
1223
Jens Axboeebac4652005-12-08 15:25:21 +01001224 if (parse_options(argc, argv))
1225 return 1;
1226
Jens Axboe4b472fa2007-04-04 11:04:34 +02001227 if (!thread_number)
1228 return 0;
Jens Axboeebac4652005-12-08 15:25:21 +01001229
Jens Axboe29d610e2007-02-06 13:25:33 +01001230 ps = sysconf(_SC_PAGESIZE);
1231 if (ps < 0) {
1232 log_err("Failed to get page size\n");
1233 return 1;
1234 }
1235
Jens Axboecfc99db2007-03-14 10:34:47 +01001236 page_size = ps;
Jens Axboe29d610e2007-02-06 13:25:33 +01001237 page_mask = ps - 1;
1238
Jens Axboebb3884d2007-01-17 17:23:11 +11001239 if (write_bw_log) {
1240 setup_log(&agg_io_log[DDIR_READ]);
1241 setup_log(&agg_io_log[DDIR_WRITE]);
1242 }
1243
Jens Axboe07739b52007-03-08 20:25:46 +01001244 startup_sem = fio_sem_init(0);
1245
Jens Axboea2f77c92007-02-22 11:53:00 +01001246 set_genesis_time();
1247
Jens Axboeebac4652005-12-08 15:25:21 +01001248 disk_util_timer_arm();
1249
1250 run_threads();
Jens Axboe6ce15a32007-01-12 09:04:41 +01001251
Jens Axboebb3884d2007-01-17 17:23:11 +11001252 if (!fio_abort) {
Jens Axboe6ce15a32007-01-12 09:04:41 +01001253 show_run_stats();
Jens Axboebb3884d2007-01-17 17:23:11 +11001254 if (write_bw_log) {
1255 __finish_log(agg_io_log[DDIR_READ],"agg-read_bw.log");
1256 __finish_log(agg_io_log[DDIR_WRITE],"agg-write_bw.log");
1257 }
1258 }
Jens Axboeebac4652005-12-08 15:25:21 +01001259
Jens Axboe07739b52007-03-08 20:25:46 +01001260 fio_sem_remove(startup_sem);
Jens Axboe437c9b72007-02-13 18:20:37 +01001261 return exit_value;
Jens Axboeebac4652005-12-08 15:25:21 +01001262}