4 * IO engine that doesn't do any real IO transfers, it just pretends to.
5 * The main purpose is to test fio itself.
7 * It also can act as external C++ engine - compiled with:
9 * g++ -O2 -g -shared -rdynamic -fPIC -o cpp_null null.c \
10 * -include ../config-host.h -DFIO_EXTERNAL_ENGINE
14 * LD_LIBRARY_PATH=./engines ./fio examples/cpp_null.fio
28 static struct io_u *null_event(struct null_data *nd, int event)
30 return nd->io_us[event];
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)
47 static void null_queued(struct thread_data *td, struct null_data *nd)
51 if (!fio_fill_issue_time(td))
54 fio_gettime(&now, NULL);
56 for (int i = 0; i < nd->queued; i++) {
57 struct io_u *io_u = nd->io_us[i];
59 memcpy(&io_u->issue_time, &now, sizeof(now));
60 io_u_queued(td, io_u);
64 static int null_commit(struct thread_data *td, struct null_data *nd)
69 #ifndef FIO_EXTERNAL_ENGINE
70 io_u_mark_submit(td, nd->queued);
72 nd->events = nd->queued;
79 static enum fio_q_status null_queue(struct thread_data *td,
80 struct null_data *nd, struct io_u *io_u)
82 fio_ro_check(td, io_u);
84 if (td->io_ops->flags & FIO_SYNCIO)
85 return FIO_Q_COMPLETED;
89 nd->io_us[nd->queued++] = io_u;
93 static int null_open(struct null_data fio_unused *nd,
94 struct fio_file fio_unused *f)
99 static void null_cleanup(struct null_data *nd)
107 static struct null_data *null_init(struct thread_data *td)
109 struct null_data *nd = (struct null_data *) malloc(sizeof(*nd));
111 memset(nd, 0, sizeof(*nd));
113 if (td->o.iodepth != 1) {
114 nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *));
115 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
116 td->io_ops->flags |= FIO_ASYNCIO_SETS_ISSUE_TIME;
118 td->io_ops->flags |= FIO_SYNCIO;
120 td_set_ioengine_flags(td);
126 static struct io_u *fio_null_event(struct thread_data *td, int event)
128 return null_event(td->io_ops_data, event);
131 static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
132 unsigned int max, const struct timespec *t)
134 struct null_data *nd = td->io_ops_data;
135 return null_getevents(nd, min_events, max, t);
138 static int fio_null_commit(struct thread_data *td)
140 return null_commit(td, td->io_ops_data);
143 static enum fio_q_status fio_null_queue(struct thread_data *td,
146 return null_queue(td, td->io_ops_data, io_u);
149 static int fio_null_open(struct thread_data *td, struct fio_file *f)
151 return null_open(td->io_ops_data, f);
154 static void fio_null_cleanup(struct thread_data *td)
156 null_cleanup(td->io_ops_data);
159 static int fio_null_init(struct thread_data *td)
161 td->io_ops_data = null_init(td);
162 assert(td->io_ops_data);
166 static struct ioengine_ops ioengine = {
168 .version = FIO_IOOPS_VERSION,
169 .queue = fio_null_queue,
170 .commit = fio_null_commit,
171 .getevents = fio_null_getevents,
172 .event = fio_null_event,
173 .init = fio_null_init,
174 .cleanup = fio_null_cleanup,
175 .open_file = fio_null_open,
176 .flags = FIO_DISKLESSIO | FIO_FAKEIO,
179 static void fio_init fio_null_register(void)
181 register_ioengine(&ioengine);
184 static void fio_exit fio_null_unregister(void)
186 unregister_ioengine(&ioengine);
191 #ifdef FIO_EXTERNAL_ENGINE
194 NullData(struct thread_data *td)
196 impl_ = null_init(td);
205 static NullData *get(struct thread_data *td)
207 return reinterpret_cast<NullData *>(td->io_ops_data);
210 io_u *fio_null_event(struct thread_data *, int event)
212 return null_event(impl_, event);
215 int fio_null_getevents(struct thread_data *, unsigned int min_events,
216 unsigned int max, const struct timespec *t)
218 return null_getevents(impl_, min_events, max, t);
221 int fio_null_commit(struct thread_data *td)
223 return null_commit(td, impl_);
226 fio_q_status fio_null_queue(struct thread_data *td, struct io_u *io_u)
228 return null_queue(td, impl_, io_u);
231 int fio_null_open(struct thread_data *, struct fio_file *f)
233 return null_open(impl_, f);
237 struct null_data *impl_;
242 static struct io_u *fio_null_event(struct thread_data *td, int event)
244 return NullData::get(td)->fio_null_event(td, event);
247 static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
248 unsigned int max, const struct timespec *t)
250 return NullData::get(td)->fio_null_getevents(td, min_events, max, t);
253 static int fio_null_commit(struct thread_data *td)
255 return NullData::get(td)->fio_null_commit(td);
258 static fio_q_status fio_null_queue(struct thread_data *td, struct io_u *io_u)
260 return NullData::get(td)->fio_null_queue(td, io_u);
263 static int fio_null_open(struct thread_data *td, struct fio_file *f)
265 return NullData::get(td)->fio_null_open(td, f);
268 static int fio_null_init(struct thread_data *td)
270 td->io_ops_data = new NullData(td);
274 static void fio_null_cleanup(struct thread_data *td)
276 delete NullData::get(td);
279 static struct ioengine_ops ioengine;
280 void get_ioengine(struct ioengine_ops **ioengine_ptr)
282 *ioengine_ptr = &ioengine;
284 ioengine.name = "cpp_null";
285 ioengine.version = FIO_IOOPS_VERSION;
286 ioengine.queue = fio_null_queue;
287 ioengine.commit = fio_null_commit;
288 ioengine.getevents = fio_null_getevents;
289 ioengine.event = fio_null_event;
290 ioengine.init = fio_null_init;
291 ioengine.cleanup = fio_null_cleanup;
292 ioengine.open_file = fio_null_open;
293 ioengine.flags = FIO_DISKLESSIO | FIO_FAKEIO;
296 #endif /* FIO_EXTERNAL_ENGINE */
298 #endif /* __cplusplus */