4 * Doesn't transfer any data, merely burns CPU cycles according to
9 #include "../optgroup.h"
14 unsigned int cpucycle;
15 unsigned int exit_io_done;
18 static struct fio_option options[] = {
23 .off1 = offsetof(struct cpu_options, cpuload),
24 .help = "Use this percentage of CPU",
25 .category = FIO_OPT_C_GENERAL,
26 .group = FIO_OPT_G_INVALID,
32 .off1 = offsetof(struct cpu_options, cpucycle),
33 .help = "Length of the CPU burn cycles (usecs)",
37 .category = FIO_OPT_C_GENERAL,
38 .group = FIO_OPT_G_INVALID,
41 .name = "exit_on_io_done",
42 .lname = "Exit when IO threads are done",
44 .off1 = offsetof(struct cpu_options, exit_io_done),
45 .help = "Exit when IO threads finish",
47 .category = FIO_OPT_C_GENERAL,
48 .group = FIO_OPT_G_INVALID,
56 static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u)
58 struct cpu_options *co = td->eo;
60 if (co->exit_io_done && !fio_running_or_pending_io_threads()) {
65 usec_spin(co->cpucycle);
66 return FIO_Q_COMPLETED;
69 static int fio_cpuio_init(struct thread_data *td)
71 struct thread_options *o = &td->o;
72 struct cpu_options *co = td->eo;
75 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
79 if (co->cpuload > 100)
83 * set thinktime_sleep and thinktime_spin appropriately
85 o->thinktime_blocks = 1;
86 o->thinktime_spin = 0;
87 o->thinktime = (co->cpucycle * (100 - co->cpuload)) / co->cpuload;
89 o->nr_files = o->open_files = 1;
91 log_info("%s: ioengine=%s, cpuload=%u, cpucycle=%u\n",
92 td->o.name, td->io_ops->name, co->cpuload, co->cpucycle);
97 static int fio_cpuio_open(struct thread_data fio_unused *td,
98 struct fio_file fio_unused *f)
103 static struct ioengine_ops ioengine = {
105 .version = FIO_IOOPS_VERSION,
106 .queue = fio_cpuio_queue,
107 .init = fio_cpuio_init,
108 .open_file = fio_cpuio_open,
109 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO,
111 .option_struct_size = sizeof(struct cpu_options),
114 static void fio_init fio_cpuio_register(void)
116 register_ioengine(&ioengine);
119 static void fio_exit fio_cpuio_unregister(void)
121 unregister_ioengine(&ioengine);