Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 1 | /* |
Jens Axboe | da751ca | 2007-03-14 10:59:33 +0100 | [diff] [blame^] | 2 | * null engine |
| 3 | * |
| 4 | * IO engine that doesn't do any real IO transfers, it just pretends to. |
| 5 | * The main purpose is to test fio itself. |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 6 | * |
| 7 | */ |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <unistd.h> |
| 11 | #include <errno.h> |
| 12 | #include <assert.h> |
| 13 | |
| 14 | #include "../fio.h" |
| 15 | #include "../os.h" |
| 16 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 17 | struct null_data { |
| 18 | struct io_u **io_us; |
| 19 | int queued; |
| 20 | int events; |
| 21 | }; |
| 22 | |
| 23 | static struct io_u *fio_null_event(struct thread_data *td, int event) |
| 24 | { |
| 25 | struct null_data *nd = td->io_ops->data; |
| 26 | |
| 27 | return nd->io_us[event]; |
| 28 | } |
| 29 | |
Jens Axboe | 7401c08 | 2007-03-09 13:45:11 +0100 | [diff] [blame] | 30 | static int fio_null_getevents(struct thread_data *td, int min_events, |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 31 | int fio_unused max, struct timespec fio_unused *t) |
| 32 | { |
| 33 | struct null_data *nd = td->io_ops->data; |
Jens Axboe | 7401c08 | 2007-03-09 13:45:11 +0100 | [diff] [blame] | 34 | int ret = 0; |
| 35 | |
| 36 | if (min_events) { |
| 37 | ret = nd->events; |
| 38 | nd->events = 0; |
| 39 | } |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 40 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | static int fio_null_commit(struct thread_data *td) |
| 45 | { |
| 46 | struct null_data *nd = td->io_ops->data; |
| 47 | |
Jens Axboe | 7401c08 | 2007-03-09 13:45:11 +0100 | [diff] [blame] | 48 | nd->events += nd->queued; |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 49 | nd->queued = 0; |
| 50 | return 0; |
| 51 | } |
| 52 | |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 53 | static int fio_null_queue(struct thread_data fio_unused *td, struct io_u *io_u) |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 54 | { |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 55 | struct null_data *nd = td->io_ops->data; |
| 56 | |
| 57 | if (td->io_ops->flags & FIO_SYNCIO) |
| 58 | return FIO_Q_COMPLETED; |
| 59 | |
| 60 | nd->io_us[nd->queued++] = io_u; |
| 61 | return FIO_Q_QUEUED; |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 64 | static int fio_null_setup(struct thread_data *td) |
| 65 | { |
| 66 | struct fio_file *f; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 67 | unsigned int i; |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 68 | |
| 69 | if (!td->total_file_size) { |
| 70 | log_err("fio: need size= set\n"); |
| 71 | return 1; |
| 72 | } |
| 73 | |
| 74 | td->io_size = td->total_file_size; |
| 75 | td->total_io_size = td->io_size; |
| 76 | |
| 77 | for_each_file(td, f, i) { |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 78 | f->real_file_size = td->total_io_size / td->nr_files; |
| 79 | f->file_size = f->real_file_size; |
| 80 | } |
| 81 | |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 85 | static int fio_null_open(struct thread_data fio_unused *td, |
| 86 | struct fio_file fio_unused *f) |
| 87 | { |
Jens Axboe | 640e942 | 2007-03-08 14:09:59 +0100 | [diff] [blame] | 88 | f->fd = 0; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 92 | static void fio_null_cleanup(struct thread_data *td) |
| 93 | { |
| 94 | struct null_data *nd = td->io_ops->data; |
| 95 | |
| 96 | if (nd) { |
| 97 | if (nd->io_us) |
| 98 | free(nd->io_us); |
| 99 | free(nd); |
| 100 | td->io_ops->data = NULL; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static int fio_null_init(struct thread_data *td) |
| 105 | { |
| 106 | struct null_data *nd = malloc(sizeof(*nd)); |
| 107 | |
| 108 | memset(nd, 0, sizeof(*nd)); |
| 109 | |
| 110 | if (td->iodepth != 1) { |
| 111 | nd->io_us = malloc(td->iodepth * sizeof(struct io_u *)); |
| 112 | memset(nd->io_us, 0, td->iodepth * sizeof(struct io_u *)); |
| 113 | } else |
| 114 | td->io_ops->flags |= FIO_SYNCIO; |
| 115 | |
| 116 | td->io_ops->data = nd; |
| 117 | return 0; |
| 118 | } |
| 119 | |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 120 | static struct ioengine_ops ioengine = { |
| 121 | .name = "null", |
| 122 | .version = FIO_IOOPS_VERSION, |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 123 | .setup = fio_null_setup, |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 124 | .queue = fio_null_queue, |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 125 | .commit = fio_null_commit, |
| 126 | .getevents = fio_null_getevents, |
| 127 | .event = fio_null_event, |
| 128 | .init = fio_null_init, |
| 129 | .cleanup = fio_null_cleanup, |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 130 | .open_file = fio_null_open, |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 131 | .flags = FIO_DISKLESSIO, |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | static void fio_init fio_null_register(void) |
| 135 | { |
| 136 | register_ioengine(&ioengine); |
| 137 | } |
| 138 | |
| 139 | static void fio_exit fio_null_unregister(void) |
| 140 | { |
| 141 | unregister_ioengine(&ioengine); |
| 142 | } |