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