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