Move os/arch/compiler headers into directories
[fio.git] / engines / cpu.c
... / ...
CommitLineData
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
10static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u)
11{
12 __usec_sleep(td->o.cpucycle);
13 return FIO_Q_COMPLETED;
14}
15
16static int fio_cpuio_setup(struct thread_data fio_unused *td)
17{
18 struct fio_file *f;
19 unsigned int i;
20
21 for_each_file(td, f, i)
22 f->real_file_size = -1ULL;
23
24 return 0;
25}
26
27static int fio_cpuio_init(struct thread_data *td)
28{
29 struct thread_options *o = &td->o;
30
31 if (!o->cpuload) {
32 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
33 return 1;
34 }
35
36 if (o->cpuload > 100)
37 o->cpuload = 100;
38
39 /*
40 * set thinktime_sleep and thinktime_spin appropriately
41 */
42 o->thinktime_blocks = 1;
43 o->thinktime_spin = 0;
44 o->thinktime = (o->cpucycle * (100 - o->cpuload)) / o->cpuload;
45
46 o->nr_files = o->open_files = 1;
47 return 0;
48}
49
50static int fio_cpuio_open(struct thread_data fio_unused *td, struct fio_file *f)
51{
52 f->fd = 0;
53 return 0;
54}
55
56static struct ioengine_ops ioengine = {
57 .name = "cpuio",
58 .version = FIO_IOOPS_VERSION,
59 .queue = fio_cpuio_queue,
60 .init = fio_cpuio_init,
61 .setup = fio_cpuio_setup,
62 .open_file = fio_cpuio_open,
63 .flags = FIO_SYNCIO | FIO_DISKLESSIO,
64};
65
66static void fio_init fio_cpuio_register(void)
67{
68 register_ioengine(&ioengine);
69}
70
71static void fio_exit fio_cpuio_unregister(void)
72{
73 unregister_ioengine(&ioengine);
74}