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