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 | |
0353050f JA |
10 | struct cpu_options { |
11 | struct thread_data *td; | |
12 | unsigned int cpuload; | |
13 | unsigned int cpucycle; | |
14 | }; | |
15 | ||
16 | static struct fio_option options[] = { | |
17 | { | |
18 | .name = "cpuload", | |
19 | .lname = "CPU load", | |
20 | .type = FIO_OPT_INT, | |
21 | .off1 = offsetof(struct cpu_options, cpuload), | |
22 | .help = "Use this percentage of CPU", | |
23 | .category = FIO_OPT_C_GENERAL, | |
24 | .group = FIO_OPT_G_INVALID, | |
25 | }, | |
26 | { | |
27 | .name = "cpuchunks", | |
28 | .lname = "CPU chunk", | |
29 | .type = FIO_OPT_INT, | |
30 | .off1 = offsetof(struct cpu_options, cpucycle), | |
31 | .help = "Length of the CPU burn cycles (usecs)", | |
32 | .def = "50000", | |
33 | .parent = "cpuload", | |
34 | .hide = 1, | |
35 | .category = FIO_OPT_C_GENERAL, | |
36 | .group = FIO_OPT_G_INVALID, | |
37 | }, | |
38 | { | |
39 | .name = NULL, | |
40 | }, | |
41 | }; | |
42 | ||
43 | ||
ba0fbe10 JA |
44 | static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u) |
45 | { | |
0353050f JA |
46 | struct cpu_options *co = td->eo; |
47 | ||
48 | usec_spin(co->cpucycle); | |
ba0fbe10 JA |
49 | return FIO_Q_COMPLETED; |
50 | } | |
51 | ||
2866c82d JA |
52 | static int fio_cpuio_init(struct thread_data *td) |
53 | { | |
2dc1bbeb | 54 | struct thread_options *o = &td->o; |
0353050f | 55 | struct cpu_options *co = td->eo; |
2dc1bbeb | 56 | |
0353050f | 57 | if (!co->cpuload) { |
ba0fbe10 | 58 | td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio"); |
2866c82d | 59 | return 1; |
ba0fbe10 JA |
60 | } |
61 | ||
0353050f JA |
62 | if (co->cpuload > 100) |
63 | co->cpuload = 100; | |
2866c82d | 64 | |
ba0fbe10 JA |
65 | /* |
66 | * set thinktime_sleep and thinktime_spin appropriately | |
67 | */ | |
2dc1bbeb JA |
68 | o->thinktime_blocks = 1; |
69 | o->thinktime_spin = 0; | |
0353050f | 70 | o->thinktime = (co->cpucycle * (100 - co->cpuload)) / co->cpuload; |
2866c82d | 71 | |
2dc1bbeb | 72 | o->nr_files = o->open_files = 1; |
0353050f JA |
73 | |
74 | log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->o.name, | |
75 | co->cpuload, co->cpucycle); | |
76 | ||
ba0fbe10 JA |
77 | return 0; |
78 | } | |
79 | ||
f4e62a5f JA |
80 | static int fio_cpuio_open(struct thread_data fio_unused *td, |
81 | struct fio_file fio_unused *f) | |
ba0fbe10 | 82 | { |
2866c82d JA |
83 | return 0; |
84 | } | |
85 | ||
5f350952 | 86 | static struct ioengine_ops ioengine = { |
2866c82d JA |
87 | .name = "cpuio", |
88 | .version = FIO_IOOPS_VERSION, | |
ba0fbe10 | 89 | .queue = fio_cpuio_queue, |
2866c82d | 90 | .init = fio_cpuio_init, |
ba0fbe10 | 91 | .open_file = fio_cpuio_open, |
1f809d15 | 92 | .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO, |
0353050f JA |
93 | .options = options, |
94 | .option_struct_size = sizeof(struct cpu_options), | |
2866c82d | 95 | }; |
5f350952 JA |
96 | |
97 | static void fio_init fio_cpuio_register(void) | |
98 | { | |
99 | register_ioengine(&ioengine); | |
100 | } | |
101 | ||
102 | static void fio_exit fio_cpuio_unregister(void) | |
103 | { | |
104 | unregister_ioengine(&ioengine); | |
105 | } |