4 * Doesn't transfer any data, merely burns CPU cycles according to
11 struct thread_data *td;
13 unsigned int cpucycle;
14 unsigned int exit_io_done;
17 static struct fio_option options[] = {
22 .off1 = offsetof(struct cpu_options, cpuload),
23 .help = "Use this percentage of CPU",
24 .category = FIO_OPT_C_GENERAL,
25 .group = FIO_OPT_G_INVALID,
31 .off1 = offsetof(struct cpu_options, cpucycle),
32 .help = "Length of the CPU burn cycles (usecs)",
36 .category = FIO_OPT_C_GENERAL,
37 .group = FIO_OPT_G_INVALID,
40 .name = "exit_on_io_done",
41 .lname = "Exit when IO threads are done",
43 .off1 = offsetof(struct cpu_options, exit_io_done),
44 .help = "Exit when IO threads finish",
46 .category = FIO_OPT_C_GENERAL,
47 .group = FIO_OPT_G_INVALID,
55 static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u)
57 struct cpu_options *co = td->eo;
59 if (co->exit_io_done && !fio_running_or_pending_io_threads()) {
64 usec_spin(co->cpucycle);
65 return FIO_Q_COMPLETED;
68 static int fio_cpuio_init(struct thread_data *td)
70 struct thread_options *o = &td->o;
71 struct cpu_options *co = td->eo;
74 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
78 if (co->cpuload > 100)
82 * set thinktime_sleep and thinktime_spin appropriately
84 o->thinktime_blocks = 1;
85 o->thinktime_spin = 0;
86 o->thinktime = (co->cpucycle * (100 - co->cpuload)) / co->cpuload;
88 o->nr_files = o->open_files = 1;
90 log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->o.name,
91 co->cpuload, co->cpucycle);
96 static int fio_cpuio_open(struct thread_data fio_unused *td,
97 struct fio_file fio_unused *f)
102 static struct ioengine_ops ioengine = {
104 .version = FIO_IOOPS_VERSION,
105 .queue = fio_cpuio_queue,
106 .init = fio_cpuio_init,
107 .open_file = fio_cpuio_open,
108 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO,
110 .option_struct_size = sizeof(struct cpu_options),
113 static void fio_init fio_cpuio_register(void)
115 register_ioengine(&ioengine);
118 static void fio_exit fio_cpuio_unregister(void)
120 unregister_ioengine(&ioengine);