X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=engines%2Fcpu.c;h=7643a8c591c39942b95db763694eac93bef59d98;hb=42ff945ce285e9864cdafe32e27e8ef421ea5aab;hp=b6f9075d365be76fe944a33101cf6eff3b195b88;hpb=af52b3455ad892322aab2791282b6bd4efdfdbf3;p=fio.git diff --git a/engines/cpu.c b/engines/cpu.c index b6f9075d..7643a8c5 100644 --- a/engines/cpu.c +++ b/engines/cpu.c @@ -1,53 +1,102 @@ +/* + * 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_queue(struct thread_data *td, struct io_u fio_unused *io_u) -{ - __usec_sleep(td->cpucycle); - return FIO_Q_COMPLETED; -} +struct cpu_options { + void *pad; + unsigned int cpuload; + unsigned int cpucycle; + unsigned int exit_io_done; +}; -static int fio_cpuio_setup(struct thread_data fio_unused *td) -{ - struct fio_file *f; - unsigned int i; +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, + }, +}; - td->total_file_size = -1; - td->io_size = td->total_file_size; - td->total_io_size = td->io_size; - for_each_file(td, f, i) { - f->real_file_size = -1; - f->file_size = -1; +static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u) +{ + struct cpu_options *co = td->eo; + + if (co->exit_io_done && !fio_running_or_pending_io_threads()) { + td->done = 1; + return FIO_Q_BUSY; } - return 0; + usec_spin(co->cpucycle); + return FIO_Q_COMPLETED; } static int fio_cpuio_init(struct thread_data *td) { - if (!td->cpuload) { + 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; } - if (td->cpuload > 100) - td->cpuload = 100; + if (co->cpuload > 100) + co->cpuload = 100; /* * set thinktime_sleep and thinktime_spin appropriately */ - td->thinktime_blocks = 1; - td->thinktime_spin = 0; - td->thinktime = (td->cpucycle * (100 - td->cpuload)) / td->cpuload; + o->thinktime_blocks = 1; + o->thinktime_spin = 0; + o->thinktime = (co->cpucycle * (100 - co->cpuload)) / co->cpuload; + + o->nr_files = o->open_files = 1; + + log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->o.name, + co->cpuload, co->cpucycle); - td->nr_files = td->open_files = 1; return 0; } -static int fio_cpuio_open(struct thread_data fio_unused *td, struct fio_file *f) +static int fio_cpuio_open(struct thread_data fio_unused *td, + struct fio_file fio_unused *f) { - f->fd = 0; return 0; } @@ -56,9 +105,10 @@ static struct ioengine_ops ioengine = { .version = FIO_IOOPS_VERSION, .queue = fio_cpuio_queue, .init = fio_cpuio_init, - .setup = fio_cpuio_setup, .open_file = fio_cpuio_open, - .flags = FIO_SYNCIO | FIO_DISKLESSIO, + .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO, + .options = options, + .option_struct_size = sizeof(struct cpu_options), }; static void fio_init fio_cpuio_register(void)