X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=engines%2Fcpu.c;h=3d855e363c3212ba3d0c656ac5e2e92de1da1c05;hp=27ec6da1f261575bdd98999cacb81184e2c78d77;hb=f70afaca743f2971312d9928f069a9ea7daeccf7;hpb=4d9345ae968ca92ace3dab06c25a9b73159cb329 diff --git a/engines/cpu.c b/engines/cpu.c index 27ec6da1..3d855e36 100644 --- a/engines/cpu.c +++ b/engines/cpu.c @@ -1,30 +1,114 @@ +/* + * CPU engine + * + * Doesn't transfer any data, merely burns CPU cycles according to + * the settings. + * + */ #include "../fio.h" -#include "../os.h" +#include "../optgroup.h" -static int fio_cpuio_setup(struct thread_data fio_unused *td) +struct cpu_options { + void *pad; + unsigned int cpuload; + unsigned int cpucycle; + unsigned int exit_io_done; +}; + +static struct fio_option options[] = { + { + .name = "cpuload", + .lname = "CPU load", + .type = FIO_OPT_INT, + .off1 = offsetof(struct cpu_options, cpuload), + .help = "Use this percentage of CPU", + .category = FIO_OPT_C_GENERAL, + .group = FIO_OPT_G_INVALID, + }, + { + .name = "cpuchunks", + .lname = "CPU chunk", + .type = FIO_OPT_INT, + .off1 = offsetof(struct cpu_options, cpucycle), + .help = "Length of the CPU burn cycles (usecs)", + .def = "50000", + .parent = "cpuload", + .hide = 1, + .category = FIO_OPT_C_GENERAL, + .group = FIO_OPT_G_INVALID, + }, + { + .name = "exit_on_io_done", + .lname = "Exit when IO threads are done", + .type = FIO_OPT_BOOL, + .off1 = offsetof(struct cpu_options, exit_io_done), + .help = "Exit when IO threads finish", + .def = "0", + .category = FIO_OPT_C_GENERAL, + .group = FIO_OPT_G_INVALID, + }, + { + .name = NULL, + }, +}; + + +static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u) { - return 0; + struct cpu_options *co = td->eo; + + if (co->exit_io_done && !fio_running_or_pending_io_threads()) { + td->done = 1; + return FIO_Q_BUSY; + } + + usec_spin(co->cpucycle); + return FIO_Q_COMPLETED; } static int fio_cpuio_init(struct thread_data *td) { - if (!td->cpuload) { - td_vmsg(td, EINVAL, "cpu thread needs rate"); + struct thread_options *o = &td->o; + struct cpu_options *co = td->eo; + + if (!co->cpuload) { + td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio"); return 1; - } else if (td->cpuload > 100) - td->cpuload = 100; + } + + if (co->cpuload > 100) + co->cpuload = 100; + + /* + * set thinktime_sleep and thinktime_spin appropriately + */ + o->thinktime_blocks = 1; + o->thinktime_spin = 0; + o->thinktime = (co->cpucycle * (100 - co->cpuload)) / co->cpuload; + + o->nr_files = o->open_files = 1; - td->nr_files = 0; + log_info("%s: ioengine=%s, cpuload=%u, cpucycle=%u\n", + td->o.name, td->io_ops->name, co->cpuload, co->cpucycle); return 0; } +static int fio_cpuio_open(struct thread_data fio_unused *td, + struct fio_file fio_unused *f) +{ + return 0; +} + static struct ioengine_ops ioengine = { .name = "cpuio", .version = FIO_IOOPS_VERSION, + .queue = fio_cpuio_queue, .init = fio_cpuio_init, - .setup = fio_cpuio_setup, - .flags = FIO_CPUIO | FIO_NULLIO, + .open_file = fio_cpuio_open, + .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO, + .options = options, + .option_struct_size = sizeof(struct cpu_options), }; static void fio_init fio_cpuio_register(void)