[PATCH] Implement file syncing as data direction
[fio.git] / fio.c
1 /*
2  * fio - the flexible io tester
3  *
4  * Copyright (C) 2005 Jens Axboe <axboe@suse.de>
5  * Copyright (C) 2006 Jens Axboe <axboe@kernel.dk>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <string.h>
25 #include <signal.h>
26 #include <time.h>
27 #include <assert.h>
28 #include <sys/stat.h>
29 #include <sys/wait.h>
30 #include <sys/ipc.h>
31 #include <sys/shm.h>
32 #include <sys/ioctl.h>
33 #include <sys/mman.h>
34
35 #include "fio.h"
36 #include "os.h"
37
38 #define MASK    (4095)
39
40 #define ALIGN(buf)      (char *) (((unsigned long) (buf) + MASK) & ~(MASK))
41
42 int groupid = 0;
43 int thread_number = 0;
44 int shm_id = 0;
45 int temp_stall_ts;
46 char *fio_inst_prefix = _INST_PREFIX;
47
48 static volatile int startup_sem;
49
50 #define TERMINATE_ALL           (-1)
51 #define JOB_START_TIMEOUT       (5 * 1000)
52
53 static void terminate_threads(int group_id)
54 {
55         struct thread_data *td;
56         int i;
57
58         for_each_td(td, i) {
59                 if (group_id == TERMINATE_ALL || groupid == td->groupid) {
60                         td->terminate = 1;
61                         td->start_delay = 0;
62                 }
63         }
64 }
65
66 static void sig_handler(int sig)
67 {
68         switch (sig) {
69                 case SIGALRM:
70                         update_io_ticks();
71                         disk_util_timer_arm();
72                         print_thread_status();
73                         break;
74                 default:
75                         printf("\nfio: terminating on signal\n");
76                         fflush(stdout);
77                         terminate_threads(TERMINATE_ALL);
78                         break;
79         }
80 }
81
82 /*
83  * Check if we are above the minimum rate given.
84  */
85 static int check_min_rate(struct thread_data *td, struct timeval *now)
86 {
87         unsigned long spent;
88         unsigned long rate;
89         int ddir = td->ddir;
90
91         /*
92          * allow a 2 second settle period in the beginning
93          */
94         if (mtime_since(&td->start, now) < 2000)
95                 return 0;
96
97         /*
98          * if rate blocks is set, sample is running
99          */
100         if (td->rate_bytes) {
101                 spent = mtime_since(&td->lastrate, now);
102                 if (spent < td->ratecycle)
103                         return 0;
104
105                 rate = (td->this_io_bytes[ddir] - td->rate_bytes) / spent;
106                 if (rate < td->ratemin) {
107                         fprintf(f_out, "%s: min rate %d not met, got %ldKiB/sec\n", td->name, td->ratemin, rate);
108                         return 1;
109                 }
110         }
111
112         td->rate_bytes = td->this_io_bytes[ddir];
113         memcpy(&td->lastrate, now, sizeof(*now));
114         return 0;
115 }
116
117 static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
118 {
119         if (!td->timeout)
120                 return 0;
121         if (mtime_since(&td->epoch, t) >= td->timeout * 1000)
122                 return 1;
123
124         return 0;
125 }
126
127 static inline void td_set_runstate(struct thread_data *td, int runstate)
128 {
129         td->runstate = runstate;
130 }
131
132 static struct fio_file *get_next_file(struct thread_data *td)
133 {
134         unsigned int old_next_file = td->next_file;
135         struct fio_file *f;
136
137         do {
138                 f = &td->files[td->next_file];
139
140                 td->next_file++;
141                 if (td->next_file >= td->nr_files)
142                         td->next_file = 0;
143
144                 if (f->fd != -1)
145                         break;
146
147                 f = NULL;
148         } while (td->next_file != old_next_file);
149
150         return f;
151 }
152
153 /*
154  * When job exits, we can cancel the in-flight IO if we are using async
155  * io. Attempt to do so.
156  */
157 static void cleanup_pending_aio(struct thread_data *td)
158 {
159         struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
160         struct list_head *entry, *n;
161         struct io_completion_data icd;
162         struct io_u *io_u;
163         int r;
164
165         /*
166          * get immediately available events, if any
167          */
168         r = td_io_getevents(td, 0, td->cur_depth, &ts);
169         if (r > 0) {
170                 icd.nr = r;
171                 ios_completed(td, &icd);
172         }
173
174         /*
175          * now cancel remaining active events
176          */
177         if (td->io_ops->cancel) {
178                 list_for_each_safe(entry, n, &td->io_u_busylist) {
179                         io_u = list_entry(entry, struct io_u, list);
180
181                         r = td->io_ops->cancel(td, io_u);
182                         if (!r)
183                                 put_io_u(td, io_u);
184                 }
185         }
186
187         if (td->cur_depth) {
188                 r = td_io_getevents(td, td->cur_depth, td->cur_depth, NULL);
189                 if (r > 0) {
190                         icd.nr = r;
191                         ios_completed(td, &icd);
192                 }
193         }
194 }
195
196 /*
197  * The main verify engine. Runs over the writes we previusly submitted,
198  * reads the blocks back in, and checks the crc/md5 of the data.
199  */
200 void do_verify(struct thread_data *td)
201 {
202         struct timeval t;
203         struct io_u *io_u, *v_io_u = NULL;
204         struct io_completion_data icd;
205         struct fio_file *f;
206         int ret, i;
207
208         /*
209          * sync io first and invalidate cache, to make sure we really
210          * read from disk.
211          */
212         for_each_file(td, f, i) {
213                 td_io_sync(td, f);
214                 file_invalidate_cache(td, f);
215         }
216
217         td_set_runstate(td, TD_VERIFYING);
218
219         do {
220                 if (td->terminate)
221                         break;
222
223                 gettimeofday(&t, NULL);
224                 if (runtime_exceeded(td, &t))
225                         break;
226
227                 io_u = __get_io_u(td);
228                 if (!io_u)
229                         break;
230
231                 if (get_next_verify(td, io_u)) {
232                         put_io_u(td, io_u);
233                         break;
234                 }
235
236                 f = get_next_file(td);
237                 if (!f)
238                         break;
239
240                 io_u->file = f;
241
242                 if (td_io_prep(td, io_u)) {
243                         put_io_u(td, io_u);
244                         break;
245                 }
246
247                 ret = td_io_queue(td, io_u);
248                 if (ret) {
249                         put_io_u(td, io_u);
250                         td_verror(td, ret);
251                         break;
252                 }
253
254                 /*
255                  * we have one pending to verify, do that while
256                  * we are doing io on the next one
257                  */
258                 if (do_io_u_verify(td, &v_io_u))
259                         break;
260
261                 ret = td_io_getevents(td, 1, 1, NULL);
262                 if (ret != 1) {
263                         if (ret < 0)
264                                 td_verror(td, ret);
265                         break;
266                 }
267
268                 v_io_u = td->io_ops->event(td, 0);
269                 icd.nr = 1;
270                 icd.error = 0;
271                 io_completed(td, v_io_u, &icd);
272
273                 if (icd.error) {
274                         td_verror(td, icd.error);
275                         put_io_u(td, v_io_u);
276                         v_io_u = NULL;
277                         break;
278                 }
279
280                 /*
281                  * if we can't submit more io, we need to verify now
282                  */
283                 if (queue_full(td) && do_io_u_verify(td, &v_io_u))
284                         break;
285
286         } while (1);
287
288         do_io_u_verify(td, &v_io_u);
289
290         if (td->cur_depth)
291                 cleanup_pending_aio(td);
292
293         td_set_runstate(td, TD_RUNNING);
294 }
295
296 /*
297  * Not really an io thread, all it does is burn CPU cycles in the specified
298  * manner.
299  */
300 static void do_cpuio(struct thread_data *td)
301 {
302         struct timeval e;
303         int split = 100 / td->cpuload;
304         int i = 0;
305
306         while (!td->terminate) {
307                 gettimeofday(&e, NULL);
308
309                 if (runtime_exceeded(td, &e))
310                         break;
311
312                 if (!(i % split))
313                         __usec_sleep(10000);
314                 else
315                         usec_sleep(td, 10000);
316
317                 i++;
318         }
319 }
320
321 /*
322  * Main IO worker function. It retrieves io_u's to process and queues
323  * and reaps them, checking for rate and errors along the way.
324  */
325 static void do_io(struct thread_data *td)
326 {
327         struct io_completion_data icd;
328         struct timeval s, e;
329         unsigned long usec;
330         struct fio_file *f;
331         int i, ret = 0;
332
333         td_set_runstate(td, TD_RUNNING);
334
335         while (td->this_io_bytes[td->ddir] < td->io_size) {
336                 struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
337                 struct timespec *timeout;
338                 int min_evts = 0;
339                 struct io_u *io_u;
340
341                 if (td->terminate)
342                         break;
343
344                 f = get_next_file(td);
345                 if (!f)
346                         break;
347
348                 io_u = get_io_u(td, f);
349                 if (!io_u)
350                         break;
351
352                 memcpy(&s, &io_u->start_time, sizeof(s));
353
354                 ret = td_io_queue(td, io_u);
355                 if (ret) {
356                         put_io_u(td, io_u);
357                         td_verror(td, ret);
358                         break;
359                 }
360
361                 add_slat_sample(td, io_u->ddir, mtime_since(&io_u->start_time, &io_u->issue_time));
362
363                 if (td->cur_depth < td->iodepth) {
364                         timeout = &ts;
365                         min_evts = 0;
366                 } else {
367                         timeout = NULL;
368                         min_evts = 1;
369                 }
370
371                 ret = td_io_getevents(td, min_evts, td->cur_depth, timeout);
372                 if (ret < 0) {
373                         td_verror(td, ret);
374                         break;
375                 } else if (!ret)
376                         continue;
377
378                 icd.nr = ret;
379                 ios_completed(td, &icd);
380                 if (icd.error) {
381                         td_verror(td, icd.error);
382                         break;
383                 }
384
385                 /*
386                  * the rate is batched for now, it should work for batches
387                  * of completions except the very first one which may look
388                  * a little bursty
389                  */
390                 gettimeofday(&e, NULL);
391                 usec = utime_since(&s, &e);
392
393                 rate_throttle(td, usec, icd.bytes_done[td->ddir]);
394
395                 if (check_min_rate(td, &e)) {
396                         if (rate_quit)
397                                 terminate_threads(td->groupid);
398                         td_verror(td, ENOMEM);
399                         break;
400                 }
401
402                 if (runtime_exceeded(td, &e))
403                         break;
404
405                 if (td->thinktime)
406                         usec_sleep(td, td->thinktime);
407         }
408
409         if (!ret) {
410                 if (td->cur_depth)
411                         cleanup_pending_aio(td);
412
413                 if (should_fsync(td) && td->end_fsync) {
414                         td_set_runstate(td, TD_FSYNCING);
415                         for_each_file(td, f, i)
416                                 td_io_sync(td, f);
417                 }
418         }
419 }
420
421 static void cleanup_io_u(struct thread_data *td)
422 {
423         struct list_head *entry, *n;
424         struct io_u *io_u;
425
426         list_for_each_safe(entry, n, &td->io_u_freelist) {
427                 io_u = list_entry(entry, struct io_u, list);
428
429                 list_del(&io_u->list);
430                 free(io_u);
431         }
432
433         free_io_mem(td);
434 }
435
436 static int init_io_u(struct thread_data *td)
437 {
438         struct io_u *io_u;
439         int i, max_units;
440         char *p;
441
442         if (td->io_ops->flags & FIO_CPUIO)
443                 return 0;
444
445         if (td->io_ops->flags & FIO_SYNCIO)
446                 max_units = 1;
447         else
448                 max_units = td->iodepth;
449
450         td->orig_buffer_size = td->max_bs * max_units + MASK;
451
452         if (allocate_io_mem(td))
453                 return 1;
454
455         p = ALIGN(td->orig_buffer);
456         for (i = 0; i < max_units; i++) {
457                 io_u = malloc(sizeof(*io_u));
458                 memset(io_u, 0, sizeof(*io_u));
459                 INIT_LIST_HEAD(&io_u->list);
460
461                 io_u->buf = p + td->max_bs * i;
462                 io_u->index = i;
463                 list_add(&io_u->list, &td->io_u_freelist);
464         }
465
466         return 0;
467 }
468
469 static int switch_ioscheduler(struct thread_data *td)
470 {
471         char tmp[256], tmp2[128];
472         FILE *f;
473         int ret;
474
475         sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
476
477         f = fopen(tmp, "r+");
478         if (!f) {
479                 td_verror(td, errno);
480                 return 1;
481         }
482
483         /*
484          * Set io scheduler.
485          */
486         ret = fwrite(td->ioscheduler, strlen(td->ioscheduler), 1, f);
487         if (ferror(f) || ret != 1) {
488                 td_verror(td, errno);
489                 fclose(f);
490                 return 1;
491         }
492
493         rewind(f);
494
495         /*
496          * Read back and check that the selected scheduler is now the default.
497          */
498         ret = fread(tmp, 1, sizeof(tmp), f);
499         if (ferror(f) || ret < 0) {
500                 td_verror(td, errno);
501                 fclose(f);
502                 return 1;
503         }
504
505         sprintf(tmp2, "[%s]", td->ioscheduler);
506         if (!strstr(tmp, tmp2)) {
507                 log_err("fio: io scheduler %s not found\n", td->ioscheduler);
508                 td_verror(td, EINVAL);
509                 fclose(f);
510                 return 1;
511         }
512
513         fclose(f);
514         return 0;
515 }
516
517 static void clear_io_state(struct thread_data *td)
518 {
519         struct fio_file *f;
520         int i;
521
522         td->stat_io_bytes[0] = td->stat_io_bytes[1] = 0;
523         td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
524         td->zone_bytes = 0;
525
526         for_each_file(td, f, i) {
527                 f->last_pos = 0;
528                 if (td->io_ops->flags & FIO_SYNCIO)
529                         lseek(f->fd, SEEK_SET, 0);
530
531                 if (f->file_map)
532                         memset(f->file_map, 0, f->num_maps * sizeof(long));
533         }
534 }
535
536 /*
537  * Entry point for the thread based jobs. The process based jobs end up
538  * here as well, after a little setup.
539  */
540 static void *thread_main(void *data)
541 {
542         struct thread_data *td = data;
543
544         if (!td->use_thread)
545                 setsid();
546
547         td->pid = getpid();
548
549         INIT_LIST_HEAD(&td->io_u_freelist);
550         INIT_LIST_HEAD(&td->io_u_busylist);
551         INIT_LIST_HEAD(&td->io_hist_list);
552         INIT_LIST_HEAD(&td->io_log_list);
553
554         if (init_io_u(td))
555                 goto err;
556
557         if (fio_setaffinity(td) == -1) {
558                 td_verror(td, errno);
559                 goto err;
560         }
561
562         if (td_io_init(td))
563                 goto err;
564
565         if (init_iolog(td))
566                 goto err;
567
568         if (td->ioprio) {
569                 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
570                         td_verror(td, errno);
571                         goto err;
572                 }
573         }
574
575         if (nice(td->nice) == -1) {
576                 td_verror(td, errno);
577                 goto err;
578         }
579
580         if (init_random_state(td))
581                 goto err;
582
583         if (td->ioscheduler && switch_ioscheduler(td))
584                 goto err;
585
586         td_set_runstate(td, TD_INITIALIZED);
587         fio_sem_up(&startup_sem);
588         fio_sem_down(&td->mutex);
589
590         if (!td->create_serialize && setup_files(td))
591                 goto err;
592
593         gettimeofday(&td->epoch, NULL);
594
595         if (td->exec_prerun)
596                 system(td->exec_prerun);
597
598         while (td->loops--) {
599                 getrusage(RUSAGE_SELF, &td->ru_start);
600                 gettimeofday(&td->start, NULL);
601                 memcpy(&td->stat_sample_time, &td->start, sizeof(td->start));
602
603                 if (td->ratemin)
604                         memcpy(&td->lastrate, &td->stat_sample_time, sizeof(td->lastrate));
605
606                 clear_io_state(td);
607                 prune_io_piece_log(td);
608
609                 if (td->io_ops->flags & FIO_CPUIO)
610                         do_cpuio(td);
611                 else
612                         do_io(td);
613
614                 td->runtime[td->ddir] += mtime_since_now(&td->start);
615                 if (td_rw(td) && td->io_bytes[td->ddir ^ 1])
616                         td->runtime[td->ddir ^ 1] = td->runtime[td->ddir];
617
618                 update_rusage_stat(td);
619
620                 if (td->error || td->terminate)
621                         break;
622
623                 if (td->verify == VERIFY_NONE)
624                         continue;
625
626                 clear_io_state(td);
627                 gettimeofday(&td->start, NULL);
628
629                 do_verify(td);
630
631                 td->runtime[DDIR_READ] += mtime_since_now(&td->start);
632
633                 if (td->error || td->terminate)
634                         break;
635         }
636
637         if (td->bw_log)
638                 finish_log(td, td->bw_log, "bw");
639         if (td->slat_log)
640                 finish_log(td, td->slat_log, "slat");
641         if (td->clat_log)
642                 finish_log(td, td->clat_log, "clat");
643         if (td->write_iolog)
644                 write_iolog_close(td);
645         if (td->exec_postrun)
646                 system(td->exec_postrun);
647
648         if (exitall_on_terminate)
649                 terminate_threads(td->groupid);
650
651 err:
652         close_files(td);
653         close_ioengine(td);
654         cleanup_io_u(td);
655         td_set_runstate(td, TD_EXITED);
656         return NULL;
657
658 }
659
660 /*
661  * We cannot pass the td data into a forked process, so attach the td and
662  * pass it to the thread worker.
663  */
664 static void *fork_main(int shmid, int offset)
665 {
666         struct thread_data *td;
667         void *data;
668
669         data = shmat(shmid, NULL, 0);
670         if (data == (void *) -1) {
671                 perror("shmat");
672                 return NULL;
673         }
674
675         td = data + offset * sizeof(struct thread_data);
676         thread_main(td);
677         shmdt(data);
678         return NULL;
679 }
680
681 /*
682  * Run over the job map and reap the threads that have exited, if any.
683  */
684 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
685 {
686         struct thread_data *td;
687         int i, cputhreads;
688
689         /*
690          * reap exited threads (TD_EXITED -> TD_REAPED)
691          */
692         cputhreads = 0;
693         for_each_td(td, i) {
694                 /*
695                  * ->io_ops is NULL for a thread that has closed its
696                  * io engine
697                  */
698                 if (td->io_ops && td->io_ops->flags & FIO_CPUIO)
699                         cputhreads++;
700
701                 if (td->runstate != TD_EXITED)
702                         continue;
703
704                 td_set_runstate(td, TD_REAPED);
705
706                 if (td->use_thread) {
707                         long ret;
708
709                         if (pthread_join(td->thread, (void *) &ret))
710                                 perror("thread_join");
711                 } else
712                         waitpid(td->pid, NULL, 0);
713
714                 (*nr_running)--;
715                 (*m_rate) -= td->ratemin;
716                 (*t_rate) -= td->rate;
717         }
718
719         if (*nr_running == cputhreads)
720                 terminate_threads(TERMINATE_ALL);
721 }
722
723 /*
724  * Main function for kicking off and reaping jobs, as needed.
725  */
726 static void run_threads(void)
727 {
728         struct thread_data *td;
729         unsigned long spent;
730         int i, todo, nr_running, m_rate, t_rate, nr_started;
731
732         if (fio_pin_memory())
733                 return;
734
735         if (!terse_output) {
736                 printf("Starting %d thread%s\n", thread_number, thread_number > 1 ? "s" : "");
737                 fflush(stdout);
738         }
739
740         signal(SIGINT, sig_handler);
741         signal(SIGALRM, sig_handler);
742
743         todo = thread_number;
744         nr_running = 0;
745         nr_started = 0;
746         m_rate = t_rate = 0;
747
748         for_each_td(td, i) {
749                 print_status_init(td->thread_number - 1);
750
751                 init_disk_util(td);
752
753                 if (!td->create_serialize)
754                         continue;
755
756                 /*
757                  * do file setup here so it happens sequentially,
758                  * we don't want X number of threads getting their
759                  * client data interspersed on disk
760                  */
761                 if (setup_files(td)) {
762                         td_set_runstate(td, TD_REAPED);
763                         todo--;
764                 }
765         }
766
767         time_init();
768
769         while (todo) {
770                 struct thread_data *map[MAX_JOBS];
771                 struct timeval this_start;
772                 int this_jobs = 0, left;
773
774                 /*
775                  * create threads (TD_NOT_CREATED -> TD_CREATED)
776                  */
777                 for_each_td(td, i) {
778                         if (td->runstate != TD_NOT_CREATED)
779                                 continue;
780
781                         /*
782                          * never got a chance to start, killed by other
783                          * thread for some reason
784                          */
785                         if (td->terminate) {
786                                 todo--;
787                                 continue;
788                         }
789
790                         if (td->start_delay) {
791                                 spent = mtime_since_genesis();
792
793                                 if (td->start_delay * 1000 > spent)
794                                         continue;
795                         }
796
797                         if (td->stonewall && (nr_started || nr_running))
798                                 break;
799
800                         /*
801                          * Set state to created. Thread will transition
802                          * to TD_INITIALIZED when it's done setting up.
803                          */
804                         td_set_runstate(td, TD_CREATED);
805                         map[this_jobs++] = td;
806                         fio_sem_init(&startup_sem, 1);
807                         nr_started++;
808
809                         if (td->use_thread) {
810                                 if (pthread_create(&td->thread, NULL, thread_main, td)) {
811                                         perror("thread_create");
812                                         nr_started--;
813                                 }
814                         } else {
815                                 if (fork())
816                                         fio_sem_down(&startup_sem);
817                                 else {
818                                         fork_main(shm_id, i);
819                                         exit(0);
820                                 }
821                         }
822                 }
823
824                 /*
825                  * Wait for the started threads to transition to
826                  * TD_INITIALIZED.
827                  */
828                 gettimeofday(&this_start, NULL);
829                 left = this_jobs;
830                 while (left) {
831                         if (mtime_since_now(&this_start) > JOB_START_TIMEOUT)
832                                 break;
833
834                         usleep(100000);
835
836                         for (i = 0; i < this_jobs; i++) {
837                                 td = map[i];
838                                 if (!td)
839                                         continue;
840                                 if (td->runstate == TD_INITIALIZED) {
841                                         map[i] = NULL;
842                                         left--;
843                                 } else if (td->runstate >= TD_EXITED) {
844                                         map[i] = NULL;
845                                         left--;
846                                         todo--;
847                                         nr_running++; /* work-around... */
848                                 }
849                         }
850                 }
851
852                 if (left) {
853                         log_err("fio: %d jobs failed to start\n", left);
854                         for (i = 0; i < this_jobs; i++) {
855                                 td = map[i];
856                                 if (!td)
857                                         continue;
858                                 kill(td->pid, SIGTERM);
859                         }
860                         break;
861                 }
862
863                 /*
864                  * start created threads (TD_INITIALIZED -> TD_RUNNING).
865                  */
866                 for_each_td(td, i) {
867                         if (td->runstate != TD_INITIALIZED)
868                                 continue;
869
870                         td_set_runstate(td, TD_RUNNING);
871                         nr_running++;
872                         nr_started--;
873                         m_rate += td->ratemin;
874                         t_rate += td->rate;
875                         todo--;
876                         fio_sem_up(&td->mutex);
877                 }
878
879                 reap_threads(&nr_running, &t_rate, &m_rate);
880
881                 if (todo)
882                         usleep(100000);
883         }
884
885         while (nr_running) {
886                 reap_threads(&nr_running, &t_rate, &m_rate);
887                 usleep(10000);
888         }
889
890         update_io_ticks();
891         fio_unpin_memory();
892 }
893
894 int main(int argc, char *argv[])
895 {
896         if (parse_options(argc, argv))
897                 return 1;
898
899         if (!thread_number) {
900                 log_err("Nothing to do\n");
901                 return 1;
902         }
903
904         disk_util_timer_arm();
905
906         run_threads();
907         show_run_stats();
908
909         return 0;
910 }