Commit | Line | Data |
---|---|---|
a94ea28b | 1 | /* |
da751ca9 JA |
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. | |
a94ea28b | 6 | * |
46a67478 DG |
7 | * It also can act as external C++ engine - compiled with: |
8 | * | |
cef0a835 | 9 | * g++ -O2 -g -shared -rdynamic -fPIC -o cpp_null null.c \ |
c822572d | 10 | * -include ../config-host.h -DFIO_EXTERNAL_ENGINE |
966fcbd4 | 11 | * |
12 | * to test it execute: | |
13 | * | |
14 | * LD_LIBRARY_PATH=./engines ./fio examples/cpp_null.fio | |
46a67478 | 15 | * |
a94ea28b | 16 | */ |
a94ea28b | 17 | #include <stdlib.h> |
a94ea28b JA |
18 | #include <assert.h> |
19 | ||
20 | #include "../fio.h" | |
a94ea28b | 21 | |
65afa5f2 JA |
22 | struct null_data { |
23 | struct io_u **io_us; | |
24 | int queued; | |
25 | int events; | |
26 | }; | |
27 | ||
966fcbd4 | 28 | static struct io_u *null_event(struct null_data *nd, int event) |
65afa5f2 | 29 | { |
65afa5f2 JA |
30 | return nd->io_us[event]; |
31 | } | |
32 | ||
966fcbd4 | 33 | static int null_getevents(struct null_data *nd, unsigned int min_events, |
34 | unsigned int fio_unused max, | |
35 | const struct timespec fio_unused *t) | |
65afa5f2 | 36 | { |
7401c088 | 37 | int ret = 0; |
966fcbd4 | 38 | |
7401c088 JA |
39 | if (min_events) { |
40 | ret = nd->events; | |
41 | nd->events = 0; | |
42 | } | |
65afa5f2 | 43 | |
65afa5f2 JA |
44 | return ret; |
45 | } | |
46 | ||
966fcbd4 | 47 | static int null_commit(struct thread_data *td, struct null_data *nd) |
65afa5f2 | 48 | { |
ed8bd849 | 49 | if (!nd->events) { |
46a67478 | 50 | #ifndef FIO_EXTERNAL_ENGINE |
838bc709 | 51 | io_u_mark_submit(td, nd->queued); |
46a67478 | 52 | #endif |
ed8bd849 JA |
53 | nd->events = nd->queued; |
54 | nd->queued = 0; | |
55 | } | |
56 | ||
65afa5f2 JA |
57 | return 0; |
58 | } | |
59 | ||
2e4ef4fb JA |
60 | static enum fio_q_status null_queue(struct thread_data *td, |
61 | struct null_data *nd, struct io_u *io_u) | |
a94ea28b | 62 | { |
7101d9c2 JA |
63 | fio_ro_check(td, io_u); |
64 | ||
65afa5f2 JA |
65 | if (td->io_ops->flags & FIO_SYNCIO) |
66 | return FIO_Q_COMPLETED; | |
ed8bd849 JA |
67 | if (nd->events) |
68 | return FIO_Q_BUSY; | |
65afa5f2 JA |
69 | |
70 | nd->io_us[nd->queued++] = io_u; | |
71 | return FIO_Q_QUEUED; | |
a94ea28b JA |
72 | } |
73 | ||
966fcbd4 | 74 | static int null_open(struct null_data fio_unused *nd, |
75 | struct fio_file fio_unused *f) | |
b5af8293 JA |
76 | { |
77 | return 0; | |
78 | } | |
79 | ||
966fcbd4 | 80 | static void null_cleanup(struct null_data *nd) |
65afa5f2 | 81 | { |
65afa5f2 | 82 | if (nd) { |
02a3d83f | 83 | free(nd->io_us); |
65afa5f2 | 84 | free(nd); |
65afa5f2 JA |
85 | } |
86 | } | |
87 | ||
7746976c | 88 | static struct null_data *null_init(struct thread_data *td) |
65afa5f2 | 89 | { |
7746976c | 90 | struct null_data *nd = (struct null_data *) malloc(sizeof(*nd)); |
65afa5f2 JA |
91 | |
92 | memset(nd, 0, sizeof(*nd)); | |
93 | ||
2dc1bbeb | 94 | if (td->o.iodepth != 1) { |
46a67478 | 95 | nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *)); |
2dc1bbeb | 96 | memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *)); |
65afa5f2 JA |
97 | } else |
98 | td->io_ops->flags |= FIO_SYNCIO; | |
99 | ||
7746976c | 100 | return nd; |
65afa5f2 JA |
101 | } |
102 | ||
46a67478 | 103 | #ifndef __cplusplus |
966fcbd4 | 104 | |
105 | static struct io_u *fio_null_event(struct thread_data *td, int event) | |
106 | { | |
ca65714c | 107 | return null_event(td->io_ops_data, event); |
966fcbd4 | 108 | } |
109 | ||
110 | static int fio_null_getevents(struct thread_data *td, unsigned int min_events, | |
111 | unsigned int max, const struct timespec *t) | |
112 | { | |
ca65714c | 113 | struct null_data *nd = td->io_ops_data; |
966fcbd4 | 114 | return null_getevents(nd, min_events, max, t); |
115 | } | |
116 | ||
117 | static int fio_null_commit(struct thread_data *td) | |
118 | { | |
ca65714c | 119 | return null_commit(td, td->io_ops_data); |
966fcbd4 | 120 | } |
121 | ||
2e4ef4fb JA |
122 | static enum fio_q_status fio_null_queue(struct thread_data *td, |
123 | struct io_u *io_u) | |
966fcbd4 | 124 | { |
ca65714c | 125 | return null_queue(td, td->io_ops_data, io_u); |
966fcbd4 | 126 | } |
127 | ||
128 | static int fio_null_open(struct thread_data *td, struct fio_file *f) | |
129 | { | |
ca65714c | 130 | return null_open(td->io_ops_data, f); |
966fcbd4 | 131 | } |
132 | ||
133 | static void fio_null_cleanup(struct thread_data *td) | |
134 | { | |
ca65714c | 135 | null_cleanup(td->io_ops_data); |
966fcbd4 | 136 | } |
137 | ||
138 | static int fio_null_init(struct thread_data *td) | |
139 | { | |
7746976c TK |
140 | td->io_ops_data = null_init(td); |
141 | assert(td->io_ops_data); | |
142 | return 0; | |
966fcbd4 | 143 | } |
144 | ||
a94ea28b JA |
145 | static struct ioengine_ops ioengine = { |
146 | .name = "null", | |
147 | .version = FIO_IOOPS_VERSION, | |
a94ea28b | 148 | .queue = fio_null_queue, |
65afa5f2 JA |
149 | .commit = fio_null_commit, |
150 | .getevents = fio_null_getevents, | |
151 | .event = fio_null_event, | |
152 | .init = fio_null_init, | |
153 | .cleanup = fio_null_cleanup, | |
b5af8293 | 154 | .open_file = fio_null_open, |
5c57c084 | 155 | .flags = FIO_DISKLESSIO | FIO_FAKEIO, |
a94ea28b JA |
156 | }; |
157 | ||
158 | static void fio_init fio_null_register(void) | |
159 | { | |
160 | register_ioengine(&ioengine); | |
161 | } | |
162 | ||
163 | static void fio_exit fio_null_unregister(void) | |
164 | { | |
165 | unregister_ioengine(&ioengine); | |
166 | } | |
46a67478 DG |
167 | |
168 | #else | |
169 | ||
170 | #ifdef FIO_EXTERNAL_ENGINE | |
966fcbd4 | 171 | |
172 | struct NullData { | |
173 | NullData(struct thread_data *td) | |
174 | { | |
7746976c TK |
175 | impl_ = null_init(td); |
176 | assert(impl_); | |
966fcbd4 | 177 | } |
178 | ||
179 | ~NullData() | |
180 | { | |
181 | null_cleanup(impl_); | |
182 | } | |
183 | ||
184 | static NullData *get(struct thread_data *td) | |
185 | { | |
186 | return reinterpret_cast<NullData *>(td->io_ops_data); | |
187 | } | |
188 | ||
189 | io_u *fio_null_event(struct thread_data *, int event) | |
190 | { | |
191 | return null_event(impl_, event); | |
192 | } | |
193 | ||
194 | int fio_null_getevents(struct thread_data *, unsigned int min_events, | |
195 | unsigned int max, const struct timespec *t) | |
196 | { | |
197 | return null_getevents(impl_, min_events, max, t); | |
198 | } | |
199 | ||
200 | int fio_null_commit(struct thread_data *td) | |
201 | { | |
202 | return null_commit(td, impl_); | |
203 | } | |
204 | ||
cef0a835 | 205 | fio_q_status fio_null_queue(struct thread_data *td, struct io_u *io_u) |
966fcbd4 | 206 | { |
207 | return null_queue(td, impl_, io_u); | |
208 | } | |
209 | ||
210 | int fio_null_open(struct thread_data *, struct fio_file *f) | |
211 | { | |
212 | return null_open(impl_, f); | |
213 | } | |
214 | ||
7caf10f1 | 215 | private: |
966fcbd4 | 216 | struct null_data *impl_; |
217 | }; | |
218 | ||
46a67478 | 219 | extern "C" { |
966fcbd4 | 220 | |
221 | static struct io_u *fio_null_event(struct thread_data *td, int event) | |
222 | { | |
223 | return NullData::get(td)->fio_null_event(td, event); | |
224 | } | |
225 | ||
226 | static int fio_null_getevents(struct thread_data *td, unsigned int min_events, | |
227 | unsigned int max, const struct timespec *t) | |
228 | { | |
229 | return NullData::get(td)->fio_null_getevents(td, min_events, max, t); | |
230 | } | |
231 | ||
232 | static int fio_null_commit(struct thread_data *td) | |
233 | { | |
234 | return NullData::get(td)->fio_null_commit(td); | |
235 | } | |
236 | ||
cef0a835 | 237 | static fio_q_status fio_null_queue(struct thread_data *td, struct io_u *io_u) |
966fcbd4 | 238 | { |
239 | return NullData::get(td)->fio_null_queue(td, io_u); | |
240 | } | |
241 | ||
242 | static int fio_null_open(struct thread_data *td, struct fio_file *f) | |
243 | { | |
244 | return NullData::get(td)->fio_null_open(td, f); | |
245 | } | |
246 | ||
247 | static int fio_null_init(struct thread_data *td) | |
248 | { | |
249 | td->io_ops_data = new NullData(td); | |
250 | return 0; | |
251 | } | |
252 | ||
253 | static void fio_null_cleanup(struct thread_data *td) | |
254 | { | |
255 | delete NullData::get(td); | |
256 | } | |
257 | ||
247f299a | 258 | static struct ioengine_ops ioengine; |
8d6ecac2 JA |
259 | void get_ioengine(struct ioengine_ops **ioengine_ptr) |
260 | { | |
247f299a TK |
261 | *ioengine_ptr = &ioengine; |
262 | ||
263 | ioengine.name = "cpp_null"; | |
264 | ioengine.version = FIO_IOOPS_VERSION; | |
265 | ioengine.queue = fio_null_queue; | |
266 | ioengine.commit = fio_null_commit; | |
267 | ioengine.getevents = fio_null_getevents; | |
268 | ioengine.event = fio_null_event; | |
269 | ioengine.init = fio_null_init; | |
270 | ioengine.cleanup = fio_null_cleanup; | |
271 | ioengine.open_file = fio_null_open; | |
272 | ioengine.flags = FIO_DISKLESSIO | FIO_FAKEIO; | |
46a67478 DG |
273 | } |
274 | } | |
275 | #endif /* FIO_EXTERNAL_ENGINE */ | |
276 | ||
277 | #endif /* __cplusplus */ |