Add logging for queue submit and complet counts
[fio.git] / engines / null.c
CommitLineData
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
JA
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"
a94ea28b 15
65afa5f2
JA
16struct null_data {
17 struct io_u **io_us;
18 int queued;
19 int events;
20};
21
22static struct io_u *fio_null_event(struct thread_data *td, int event)
23{
24 struct null_data *nd = td->io_ops->data;
25
26 return nd->io_us[event];
27}
28
e7d2e616
JA
29static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
30 unsigned int fio_unused max,
31 struct timespec fio_unused *t)
65afa5f2
JA
32{
33 struct null_data *nd = td->io_ops->data;
7401c088
JA
34 int ret = 0;
35
36 if (min_events) {
37 ret = nd->events;
38 nd->events = 0;
39 }
65afa5f2 40
65afa5f2
JA
41 return ret;
42}
43
44static int fio_null_commit(struct thread_data *td)
45{
46 struct null_data *nd = td->io_ops->data;
47
ed8bd849 48 if (!nd->events) {
838bc709 49 io_u_mark_submit(td, nd->queued);
ed8bd849
JA
50 nd->events = nd->queued;
51 nd->queued = 0;
52 }
53
65afa5f2
JA
54 return 0;
55}
56
36167d82 57static int fio_null_queue(struct thread_data fio_unused *td, struct io_u *io_u)
a94ea28b 58{
65afa5f2
JA
59 struct null_data *nd = td->io_ops->data;
60
7101d9c2
JA
61 fio_ro_check(td, io_u);
62
65afa5f2
JA
63 if (td->io_ops->flags & FIO_SYNCIO)
64 return FIO_Q_COMPLETED;
ed8bd849
JA
65 if (nd->events)
66 return FIO_Q_BUSY;
65afa5f2
JA
67
68 nd->io_us[nd->queued++] = io_u;
69 return FIO_Q_QUEUED;
a94ea28b
JA
70}
71
b5af8293
JA
72static int fio_null_open(struct thread_data fio_unused *td,
73 struct fio_file fio_unused *f)
74{
75 return 0;
76}
77
65afa5f2
JA
78static void fio_null_cleanup(struct thread_data *td)
79{
80 struct null_data *nd = td->io_ops->data;
81
82 if (nd) {
83 if (nd->io_us)
84 free(nd->io_us);
85 free(nd);
86 td->io_ops->data = NULL;
87 }
88}
89
90static int fio_null_init(struct thread_data *td)
91{
92 struct null_data *nd = malloc(sizeof(*nd));
93
94 memset(nd, 0, sizeof(*nd));
95
2dc1bbeb
JA
96 if (td->o.iodepth != 1) {
97 nd->io_us = malloc(td->o.iodepth * sizeof(struct io_u *));
98 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
65afa5f2
JA
99 } else
100 td->io_ops->flags |= FIO_SYNCIO;
101
102 td->io_ops->data = nd;
103 return 0;
104}
105
a94ea28b
JA
106static struct ioengine_ops ioengine = {
107 .name = "null",
108 .version = FIO_IOOPS_VERSION,
a94ea28b 109 .queue = fio_null_queue,
65afa5f2
JA
110 .commit = fio_null_commit,
111 .getevents = fio_null_getevents,
112 .event = fio_null_event,
113 .init = fio_null_init,
114 .cleanup = fio_null_cleanup,
b5af8293 115 .open_file = fio_null_open,
65afa5f2 116 .flags = FIO_DISKLESSIO,
a94ea28b
JA
117};
118
119static void fio_init fio_null_register(void)
120{
121 register_ioengine(&ioengine);
122}
123
124static void fio_exit fio_null_unregister(void)
125{
126 unregister_ioengine(&ioengine);
127}