Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 1 | /* |
Jens Axboe | da751ca | 2007-03-14 10:59:33 +0100 | [diff] [blame] | 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. |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 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" |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 15 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 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 | |
Jens Axboe | e7d2e61 | 2007-12-11 10:49:39 +0100 | [diff] [blame] | 29 | static int fio_null_getevents(struct thread_data *td, unsigned int min_events, |
| 30 | unsigned int fio_unused max, |
| 31 | struct timespec fio_unused *t) |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 32 | { |
| 33 | struct null_data *nd = td->io_ops->data; |
Jens Axboe | 7401c08 | 2007-03-09 13:45:11 +0100 | [diff] [blame] | 34 | int ret = 0; |
| 35 | |
| 36 | if (min_events) { |
| 37 | ret = nd->events; |
| 38 | nd->events = 0; |
| 39 | } |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 40 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | static int fio_null_commit(struct thread_data *td) |
| 45 | { |
| 46 | struct null_data *nd = td->io_ops->data; |
| 47 | |
Jens Axboe | ed8bd84 | 2007-03-27 09:56:08 +0200 | [diff] [blame] | 48 | if (!nd->events) { |
Jens Axboe | 838bc70 | 2008-05-22 13:08:23 +0200 | [diff] [blame] | 49 | io_u_mark_submit(td, nd->queued); |
Jens Axboe | ed8bd84 | 2007-03-27 09:56:08 +0200 | [diff] [blame] | 50 | nd->events = nd->queued; |
| 51 | nd->queued = 0; |
| 52 | } |
| 53 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 57 | static int fio_null_queue(struct thread_data fio_unused *td, struct io_u *io_u) |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 58 | { |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 59 | struct null_data *nd = td->io_ops->data; |
| 60 | |
Jens Axboe | 7101d9c | 2007-09-12 13:12:39 +0200 | [diff] [blame] | 61 | fio_ro_check(td, io_u); |
| 62 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 63 | if (td->io_ops->flags & FIO_SYNCIO) |
| 64 | return FIO_Q_COMPLETED; |
Jens Axboe | ed8bd84 | 2007-03-27 09:56:08 +0200 | [diff] [blame] | 65 | if (nd->events) |
| 66 | return FIO_Q_BUSY; |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 67 | |
| 68 | nd->io_us[nd->queued++] = io_u; |
| 69 | return FIO_Q_QUEUED; |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 72 | static int fio_null_open(struct thread_data fio_unused *td, |
| 73 | struct fio_file fio_unused *f) |
| 74 | { |
| 75 | return 0; |
| 76 | } |
| 77 | |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 78 | static 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); |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | static int fio_null_init(struct thread_data *td) |
| 90 | { |
| 91 | struct null_data *nd = malloc(sizeof(*nd)); |
| 92 | |
| 93 | memset(nd, 0, sizeof(*nd)); |
| 94 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 95 | if (td->o.iodepth != 1) { |
| 96 | nd->io_us = malloc(td->o.iodepth * sizeof(struct io_u *)); |
| 97 | memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *)); |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 98 | } else |
| 99 | td->io_ops->flags |= FIO_SYNCIO; |
| 100 | |
| 101 | td->io_ops->data = nd; |
| 102 | return 0; |
| 103 | } |
| 104 | |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 105 | static struct ioengine_ops ioengine = { |
| 106 | .name = "null", |
| 107 | .version = FIO_IOOPS_VERSION, |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 108 | .queue = fio_null_queue, |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 109 | .commit = fio_null_commit, |
| 110 | .getevents = fio_null_getevents, |
| 111 | .event = fio_null_event, |
| 112 | .init = fio_null_init, |
| 113 | .cleanup = fio_null_cleanup, |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 114 | .open_file = fio_null_open, |
Jens Axboe | 65afa5f | 2007-03-09 13:23:14 +0100 | [diff] [blame] | 115 | .flags = FIO_DISKLESSIO, |
Jens Axboe | a94ea28 | 2006-11-24 12:37:34 +0100 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | static void fio_init fio_null_register(void) |
| 119 | { |
| 120 | register_ioengine(&ioengine); |
| 121 | } |
| 122 | |
| 123 | static void fio_exit fio_null_unregister(void) |
| 124 | { |
| 125 | unregister_ioengine(&ioengine); |
| 126 | } |