| 1 | /* |
| 2 | * CPU engine |
| 3 | * |
| 4 | * Doesn't transfer any data, merely burns CPU cycles according to |
| 5 | * the settings. |
| 6 | * |
| 7 | */ |
| 8 | #include "../fio.h" |
| 9 | #include "../os.h" |
| 10 | |
| 11 | static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u) |
| 12 | { |
| 13 | __usec_sleep(td->o.cpucycle); |
| 14 | return FIO_Q_COMPLETED; |
| 15 | } |
| 16 | |
| 17 | static int fio_cpuio_setup(struct thread_data fio_unused *td) |
| 18 | { |
| 19 | struct fio_file *f; |
| 20 | unsigned int i; |
| 21 | |
| 22 | td->o.size = -1; |
| 23 | td->io_size = td->o.size; |
| 24 | td->total_io_size = td->io_size; |
| 25 | |
| 26 | for_each_file(td, f, i) { |
| 27 | f->real_file_size = -1; |
| 28 | f->file_size = -1; |
| 29 | } |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static int fio_cpuio_init(struct thread_data *td) |
| 35 | { |
| 36 | struct thread_options *o = &td->o; |
| 37 | |
| 38 | if (!o->cpuload) { |
| 39 | td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio"); |
| 40 | return 1; |
| 41 | } |
| 42 | |
| 43 | if (o->cpuload > 100) |
| 44 | o->cpuload = 100; |
| 45 | |
| 46 | /* |
| 47 | * set thinktime_sleep and thinktime_spin appropriately |
| 48 | */ |
| 49 | o->thinktime_blocks = 1; |
| 50 | o->thinktime_spin = 0; |
| 51 | o->thinktime = (o->cpucycle * (100 - o->cpuload)) / o->cpuload; |
| 52 | |
| 53 | o->nr_files = o->open_files = 1; |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int fio_cpuio_open(struct thread_data fio_unused *td, struct fio_file *f) |
| 58 | { |
| 59 | f->fd = 0; |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static struct ioengine_ops ioengine = { |
| 64 | .name = "cpuio", |
| 65 | .version = FIO_IOOPS_VERSION, |
| 66 | .queue = fio_cpuio_queue, |
| 67 | .init = fio_cpuio_init, |
| 68 | .setup = fio_cpuio_setup, |
| 69 | .open_file = fio_cpuio_open, |
| 70 | .flags = FIO_SYNCIO | FIO_DISKLESSIO, |
| 71 | }; |
| 72 | |
| 73 | static void fio_init fio_cpuio_register(void) |
| 74 | { |
| 75 | register_ioengine(&ioengine); |
| 76 | } |
| 77 | |
| 78 | static void fio_exit fio_cpuio_unregister(void) |
| 79 | { |
| 80 | unregister_ioengine(&ioengine); |
| 81 | } |