Commit | Line | Data |
---|---|---|
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 |
10 | static 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 |
16 | static int fio_cpuio_setup(struct thread_data fio_unused *td) |
17 | { | |
ba0fbe10 | 18 | struct fio_file *f; |
af52b345 | 19 | unsigned int i; |
ba0fbe10 | 20 | |
7bb48f84 JA |
21 | for_each_file(td, f, i) |
22 | f->real_file_size = -1ULL; | |
ba0fbe10 | 23 | |
ea2877a4 JA |
24 | return 0; |
25 | } | |
26 | ||
2866c82d JA |
27 | static int fio_cpuio_init(struct thread_data *td) |
28 | { | |
2dc1bbeb JA |
29 | struct thread_options *o = &td->o; |
30 | ||
31 | if (!o->cpuload) { | |
ba0fbe10 | 32 | td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio"); |
2866c82d | 33 | return 1; |
ba0fbe10 JA |
34 | } |
35 | ||
2dc1bbeb JA |
36 | if (o->cpuload > 100) |
37 | o->cpuload = 100; | |
2866c82d | 38 | |
ba0fbe10 JA |
39 | /* |
40 | * set thinktime_sleep and thinktime_spin appropriately | |
41 | */ | |
2dc1bbeb JA |
42 | o->thinktime_blocks = 1; |
43 | o->thinktime_spin = 0; | |
44 | o->thinktime = (o->cpucycle * (100 - o->cpuload)) / o->cpuload; | |
2866c82d | 45 | |
2dc1bbeb | 46 | o->nr_files = o->open_files = 1; |
ba0fbe10 JA |
47 | return 0; |
48 | } | |
49 | ||
50 | static int fio_cpuio_open(struct thread_data fio_unused *td, struct fio_file *f) | |
51 | { | |
52 | f->fd = 0; | |
2866c82d JA |
53 | return 0; |
54 | } | |
55 | ||
5f350952 | 56 | static struct ioengine_ops ioengine = { |
2866c82d JA |
57 | .name = "cpuio", |
58 | .version = FIO_IOOPS_VERSION, | |
ba0fbe10 | 59 | .queue = fio_cpuio_queue, |
2866c82d | 60 | .init = fio_cpuio_init, |
ea2877a4 | 61 | .setup = fio_cpuio_setup, |
ba0fbe10 JA |
62 | .open_file = fio_cpuio_open, |
63 | .flags = FIO_SYNCIO | FIO_DISKLESSIO, | |
2866c82d | 64 | }; |
5f350952 JA |
65 | |
66 | static void fio_init fio_cpuio_register(void) | |
67 | { | |
68 | register_ioengine(&ioengine); | |
69 | } | |
70 | ||
71 | static void fio_exit fio_cpuio_unregister(void) | |
72 | { | |
73 | unregister_ioengine(&ioengine); | |
74 | } |