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