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