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 | * |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 7 | * It also can act as external C++ engine - compiled with: |
| 8 | * |
| 9 | * g++ -O2 -g -shared -rdynamic -fPIC -o null.so null.c -DFIO_EXTERNAL_ENGINE |
| 10 | * |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 11 | */ |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <unistd.h> |
| 15 | #include <errno.h> |
| 16 | #include <assert.h> |
| 17 | |
| 18 | #include "../fio.h" |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 19 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 20 | struct null_data { |
| 21 | struct io_u **io_us; |
| 22 | int queued; |
| 23 | int events; |
| 24 | }; |
| 25 | |
| 26 | static struct io_u *fio_null_event(struct thread_data *td, int event) |
| 27 | { |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 28 | struct null_data *nd = (struct null_data *) td->io_ops->data; |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 29 | |
| 30 | return nd->io_us[event]; |
| 31 | } |
| 32 | |
Jens Axboe | e7d2e61 | 2007-12-11 10:49:39 +0100 | [diff] [blame] | 33 | static int fio_null_getevents(struct thread_data *td, unsigned int min_events, |
| 34 | unsigned int fio_unused max, |
Jens Axboe | 0cbbc39 | 2014-09-30 16:04:12 -0600 | [diff] [blame] | 35 | const struct timespec fio_unused *t) |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 36 | { |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 37 | struct null_data *nd = (struct null_data *) td->io_ops->data; |
Jens Axboe | 7401c08 | 2007-03-09 13:45:11 +0100 | [diff] [blame] | 38 | int ret = 0; |
| 39 | |
| 40 | if (min_events) { |
| 41 | ret = nd->events; |
| 42 | nd->events = 0; |
| 43 | } |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 44 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 45 | return ret; |
| 46 | } |
| 47 | |
| 48 | static int fio_null_commit(struct thread_data *td) |
| 49 | { |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 50 | struct null_data *nd = (struct null_data *) td->io_ops->data; |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 51 | |
Jens Axboe | ed8bd84 | 2007-03-27 09:56:08 +0200 | [diff] [blame] | 52 | if (!nd->events) { |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 53 | #ifndef FIO_EXTERNAL_ENGINE |
Jens Axboe | 838bc70 | 2008-05-22 13:08:23 +0200 | [diff] [blame] | 54 | io_u_mark_submit(td, nd->queued); |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 55 | #endif |
Jens Axboe | ed8bd84 | 2007-03-27 09:56:08 +0200 | [diff] [blame] | 56 | nd->events = nd->queued; |
| 57 | nd->queued = 0; |
| 58 | } |
| 59 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 60 | return 0; |
| 61 | } |
| 62 | |
Jens Axboe | f0c48a7 | 2013-04-17 19:21:14 +0200 | [diff] [blame] | 63 | static int fio_null_queue(struct thread_data *td, struct io_u *io_u) |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 64 | { |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 65 | struct null_data *nd = (struct null_data *) td->io_ops->data; |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 66 | |
Jens Axboe | 7101d9c | 2007-09-12 13:12:39 +0200 | [diff] [blame] | 67 | fio_ro_check(td, io_u); |
| 68 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 69 | if (td->io_ops->flags & FIO_SYNCIO) |
| 70 | return FIO_Q_COMPLETED; |
Jens Axboe | ed8bd84 | 2007-03-27 09:56:08 +0200 | [diff] [blame] | 71 | if (nd->events) |
| 72 | return FIO_Q_BUSY; |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 73 | |
| 74 | nd->io_us[nd->queued++] = io_u; |
| 75 | return FIO_Q_QUEUED; |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 78 | static int fio_null_open(struct thread_data fio_unused *td, |
| 79 | struct fio_file fio_unused *f) |
| 80 | { |
| 81 | return 0; |
| 82 | } |
| 83 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 84 | static void fio_null_cleanup(struct thread_data *td) |
| 85 | { |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 86 | struct null_data *nd = (struct null_data *) td->io_ops->data; |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 87 | |
| 88 | if (nd) { |
| 89 | if (nd->io_us) |
| 90 | free(nd->io_us); |
| 91 | free(nd); |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
| 95 | static int fio_null_init(struct thread_data *td) |
| 96 | { |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 97 | struct null_data *nd = (struct null_data *) malloc(sizeof(*nd)); |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 98 | |
| 99 | memset(nd, 0, sizeof(*nd)); |
| 100 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 101 | if (td->o.iodepth != 1) { |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 102 | nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *)); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 103 | memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *)); |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 104 | } else |
| 105 | td->io_ops->flags |= FIO_SYNCIO; |
| 106 | |
| 107 | td->io_ops->data = nd; |
| 108 | return 0; |
| 109 | } |
| 110 | |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 111 | #ifndef __cplusplus |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 112 | static struct ioengine_ops ioengine = { |
| 113 | .name = "null", |
| 114 | .version = FIO_IOOPS_VERSION, |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 115 | .queue = fio_null_queue, |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 116 | .commit = fio_null_commit, |
| 117 | .getevents = fio_null_getevents, |
| 118 | .event = fio_null_event, |
| 119 | .init = fio_null_init, |
| 120 | .cleanup = fio_null_cleanup, |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 121 | .open_file = fio_null_open, |
Jens Axboe | d957070 | 2014-07-23 16:19:48 +0200 | [diff] [blame] | 122 | .flags = FIO_DISKLESSIO | FIO_FAKEIO, |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | static void fio_init fio_null_register(void) |
| 126 | { |
| 127 | register_ioengine(&ioengine); |
| 128 | } |
| 129 | |
| 130 | static void fio_exit fio_null_unregister(void) |
| 131 | { |
| 132 | unregister_ioengine(&ioengine); |
| 133 | } |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 134 | |
| 135 | #else |
| 136 | |
| 137 | #ifdef FIO_EXTERNAL_ENGINE |
| 138 | extern "C" { |
Jens Axboe | 8d6ecac | 2014-02-12 21:25:20 -0700 | [diff] [blame] | 139 | void get_ioengine(struct ioengine_ops **ioengine_ptr) |
| 140 | { |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 141 | struct ioengine_ops *ioengine; |
Jens Axboe | 8d6ecac | 2014-02-12 21:25:20 -0700 | [diff] [blame] | 142 | |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 143 | *ioengine_ptr = (struct ioengine_ops *) malloc(sizeof(struct ioengine_ops)); |
| 144 | ioengine = *ioengine_ptr; |
| 145 | |
| 146 | strcpy(ioengine->name, "cpp_null"); |
| 147 | ioengine->version = FIO_IOOPS_VERSION; |
| 148 | ioengine->queue = fio_null_queue; |
| 149 | ioengine->commit = fio_null_commit; |
| 150 | ioengine->getevents = fio_null_getevents; |
| 151 | ioengine->event = fio_null_event; |
| 152 | ioengine->init = fio_null_init; |
| 153 | ioengine->cleanup = fio_null_cleanup; |
| 154 | ioengine->open_file = fio_null_open; |
Jens Axboe | d957070 | 2014-07-23 16:19:48 +0200 | [diff] [blame] | 155 | ioengine->flags = FIO_DISKLESSIO | FIO_FAKEIO; |
Daniel Gollub | 46a6747 | 2014-02-12 20:13:46 +0100 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | #endif /* FIO_EXTERNAL_ENGINE */ |
| 159 | |
| 160 | #endif /* __cplusplus */ |