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