blob: 600093052d683bc1d3e5a44d2ecd5e590e5d4786 [file] [log] [blame]
Jens Axboea94ea282006-11-24 12:37:34 +01001/*
Jens Axboeda751ca2007-03-14 10:59:33 +01002 * 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 Axboea94ea282006-11-24 12:37:34 +01006 *
Daniel Gollub46a67472014-02-12 20:13:46 +01007 * 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 Axboea94ea282006-11-24 12:37:34 +010011 */
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 Axboea94ea282006-11-24 12:37:34 +010019
Jens Axboe65afa5f2007-03-09 13:23:14 +010020struct null_data {
21 struct io_u **io_us;
22 int queued;
23 int events;
24};
25
26static struct io_u *fio_null_event(struct thread_data *td, int event)
27{
Daniel Gollub46a67472014-02-12 20:13:46 +010028 struct null_data *nd = (struct null_data *) td->io_ops->data;
Jens Axboe65afa5f2007-03-09 13:23:14 +010029
30 return nd->io_us[event];
31}
32
Jens Axboee7d2e612007-12-11 10:49:39 +010033static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
34 unsigned int fio_unused max,
Jens Axboe0cbbc392014-09-30 16:04:12 -060035 const struct timespec fio_unused *t)
Jens Axboe65afa5f2007-03-09 13:23:14 +010036{
Daniel Gollub46a67472014-02-12 20:13:46 +010037 struct null_data *nd = (struct null_data *) td->io_ops->data;
Jens Axboe7401c082007-03-09 13:45:11 +010038 int ret = 0;
39
40 if (min_events) {
41 ret = nd->events;
42 nd->events = 0;
43 }
Jens Axboe65afa5f2007-03-09 13:23:14 +010044
Jens Axboe65afa5f2007-03-09 13:23:14 +010045 return ret;
46}
47
48static int fio_null_commit(struct thread_data *td)
49{
Daniel Gollub46a67472014-02-12 20:13:46 +010050 struct null_data *nd = (struct null_data *) td->io_ops->data;
Jens Axboe65afa5f2007-03-09 13:23:14 +010051
Jens Axboeed8bd842007-03-27 09:56:08 +020052 if (!nd->events) {
Daniel Gollub46a67472014-02-12 20:13:46 +010053#ifndef FIO_EXTERNAL_ENGINE
Jens Axboe838bc702008-05-22 13:08:23 +020054 io_u_mark_submit(td, nd->queued);
Daniel Gollub46a67472014-02-12 20:13:46 +010055#endif
Jens Axboeed8bd842007-03-27 09:56:08 +020056 nd->events = nd->queued;
57 nd->queued = 0;
58 }
59
Jens Axboe65afa5f2007-03-09 13:23:14 +010060 return 0;
61}
62
Jens Axboef0c48a72013-04-17 19:21:14 +020063static int fio_null_queue(struct thread_data *td, struct io_u *io_u)
Jens Axboea94ea282006-11-24 12:37:34 +010064{
Daniel Gollub46a67472014-02-12 20:13:46 +010065 struct null_data *nd = (struct null_data *) td->io_ops->data;
Jens Axboe65afa5f2007-03-09 13:23:14 +010066
Jens Axboe7101d9c2007-09-12 13:12:39 +020067 fio_ro_check(td, io_u);
68
Jens Axboe65afa5f2007-03-09 13:23:14 +010069 if (td->io_ops->flags & FIO_SYNCIO)
70 return FIO_Q_COMPLETED;
Jens Axboeed8bd842007-03-27 09:56:08 +020071 if (nd->events)
72 return FIO_Q_BUSY;
Jens Axboe65afa5f2007-03-09 13:23:14 +010073
74 nd->io_us[nd->queued++] = io_u;
75 return FIO_Q_QUEUED;
Jens Axboea94ea282006-11-24 12:37:34 +010076}
77
Jens Axboeb5af8292007-03-08 12:43:13 +010078static int fio_null_open(struct thread_data fio_unused *td,
79 struct fio_file fio_unused *f)
80{
81 return 0;
82}
83
Jens Axboe65afa5f2007-03-09 13:23:14 +010084static void fio_null_cleanup(struct thread_data *td)
85{
Daniel Gollub46a67472014-02-12 20:13:46 +010086 struct null_data *nd = (struct null_data *) td->io_ops->data;
Jens Axboe65afa5f2007-03-09 13:23:14 +010087
88 if (nd) {
89 if (nd->io_us)
90 free(nd->io_us);
91 free(nd);
Jens Axboe65afa5f2007-03-09 13:23:14 +010092 }
93}
94
95static int fio_null_init(struct thread_data *td)
96{
Daniel Gollub46a67472014-02-12 20:13:46 +010097 struct null_data *nd = (struct null_data *) malloc(sizeof(*nd));
Jens Axboe65afa5f2007-03-09 13:23:14 +010098
99 memset(nd, 0, sizeof(*nd));
100
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100101 if (td->o.iodepth != 1) {
Daniel Gollub46a67472014-02-12 20:13:46 +0100102 nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *));
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100103 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
Jens Axboe65afa5f2007-03-09 13:23:14 +0100104 } else
105 td->io_ops->flags |= FIO_SYNCIO;
106
107 td->io_ops->data = nd;
108 return 0;
109}
110
Daniel Gollub46a67472014-02-12 20:13:46 +0100111#ifndef __cplusplus
Jens Axboea94ea282006-11-24 12:37:34 +0100112static struct ioengine_ops ioengine = {
113 .name = "null",
114 .version = FIO_IOOPS_VERSION,
Jens Axboea94ea282006-11-24 12:37:34 +0100115 .queue = fio_null_queue,
Jens Axboe65afa5f2007-03-09 13:23:14 +0100116 .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 Axboeb5af8292007-03-08 12:43:13 +0100121 .open_file = fio_null_open,
Jens Axboed9570702014-07-23 16:19:48 +0200122 .flags = FIO_DISKLESSIO | FIO_FAKEIO,
Jens Axboea94ea282006-11-24 12:37:34 +0100123};
124
125static void fio_init fio_null_register(void)
126{
127 register_ioengine(&ioengine);
128}
129
130static void fio_exit fio_null_unregister(void)
131{
132 unregister_ioengine(&ioengine);
133}
Daniel Gollub46a67472014-02-12 20:13:46 +0100134
135#else
136
137#ifdef FIO_EXTERNAL_ENGINE
138extern "C" {
Jens Axboe8d6ecac2014-02-12 21:25:20 -0700139void get_ioengine(struct ioengine_ops **ioengine_ptr)
140{
Daniel Gollub46a67472014-02-12 20:13:46 +0100141 struct ioengine_ops *ioengine;
Jens Axboe8d6ecac2014-02-12 21:25:20 -0700142
Daniel Gollub46a67472014-02-12 20:13:46 +0100143 *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 Axboed9570702014-07-23 16:19:48 +0200155 ioengine->flags = FIO_DISKLESSIO | FIO_FAKEIO;
Daniel Gollub46a67472014-02-12 20:13:46 +0100156}
157}
158#endif /* FIO_EXTERNAL_ENGINE */
159
160#endif /* __cplusplus */