For non-file engines, set ->real_file_size if total size is known
[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_sleep(td->o.cpucycle);
13         return FIO_Q_COMPLETED;
14 }
15
16 static 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                 if (td->o.size)
23                         f->real_file_size = td->o.size / td->o.nr_files;
24                 else
25                         f->real_file_size = -1ULL;
26         }
27
28         return 0;
29 }
30
31 static int fio_cpuio_init(struct thread_data *td)
32 {
33         struct thread_options *o = &td->o;
34
35         if (!o->cpuload) {
36                 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
37                 return 1;
38         }
39
40         if (o->cpuload > 100)
41                 o->cpuload = 100;
42
43         /*
44          * set thinktime_sleep and thinktime_spin appropriately
45          */
46         o->thinktime_blocks = 1;
47         o->thinktime_spin = 0;
48         o->thinktime = (o->cpucycle * (100 - o->cpuload)) / o->cpuload;
49
50         o->nr_files = o->open_files = 1;
51         return 0;
52 }
53
54 static int fio_cpuio_open(struct thread_data fio_unused *td,
55                           struct fio_file fio_unused *f)
56 {
57         return 0;
58 }
59
60 static struct ioengine_ops ioengine = {
61         .name           = "cpuio",
62         .version        = FIO_IOOPS_VERSION,
63         .queue          = fio_cpuio_queue,
64         .init           = fio_cpuio_init,
65         .setup          = fio_cpuio_setup,
66         .open_file      = fio_cpuio_open,
67         .flags          = FIO_SYNCIO | FIO_DISKLESSIO,
68 };
69
70 static void fio_init fio_cpuio_register(void)
71 {
72         register_ioengine(&ioengine);
73 }
74
75 static void fio_exit fio_cpuio_unregister(void)
76 {
77         unregister_ioengine(&ioengine);
78 }