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