blob: 7e4d7374accd24399a6d780639f5c94f05c5c9a3 [file] [log] [blame]
Jens Axboeda751ca2007-03-14 10:59:33 +01001/*
2 * CPU engine
3 *
4 * Doesn't transfer any data, merely burns CPU cycles according to
5 * the settings.
6 *
7 */
Jens Axboe5f350952006-11-07 15:20:59 +01008#include "../fio.h"
Jens Axboe2866c822006-10-09 15:57:48 +02009
Jens Axboe03530502012-03-19 21:45:12 +010010struct cpu_options {
Jens Axboe6a605302014-10-29 08:30:07 -060011 void *pad;
Jens Axboe03530502012-03-19 21:45:12 +010012 unsigned int cpuload;
13 unsigned int cpucycle;
Jens Axboe046395d2014-04-09 13:57:38 -060014 unsigned int exit_io_done;
Jens Axboe03530502012-03-19 21:45:12 +010015};
16
17static struct fio_option options[] = {
18 {
19 .name = "cpuload",
20 .lname = "CPU load",
21 .type = FIO_OPT_INT,
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,
26 },
27 {
28 .name = "cpuchunks",
29 .lname = "CPU chunk",
30 .type = FIO_OPT_INT,
31 .off1 = offsetof(struct cpu_options, cpucycle),
32 .help = "Length of the CPU burn cycles (usecs)",
33 .def = "50000",
34 .parent = "cpuload",
35 .hide = 1,
36 .category = FIO_OPT_C_GENERAL,
37 .group = FIO_OPT_G_INVALID,
38 },
39 {
Jens Axboe046395d2014-04-09 13:57:38 -060040 .name = "exit_on_io_done",
41 .lname = "Exit when IO threads are done",
42 .type = FIO_OPT_BOOL,
43 .off1 = offsetof(struct cpu_options, exit_io_done),
44 .help = "Exit when IO threads finish",
45 .def = "0",
46 .category = FIO_OPT_C_GENERAL,
47 .group = FIO_OPT_G_INVALID,
48 },
49 {
Jens Axboe03530502012-03-19 21:45:12 +010050 .name = NULL,
51 },
52};
53
54
Jens Axboeba0fbe12007-03-09 14:34:23 +010055static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u)
56{
Jens Axboe03530502012-03-19 21:45:12 +010057 struct cpu_options *co = td->eo;
58
Jens Axboe046395d2014-04-09 13:57:38 -060059 if (co->exit_io_done && !fio_running_or_pending_io_threads()) {
60 td->done = 1;
61 return FIO_Q_BUSY;
62 }
63
Jens Axboe03530502012-03-19 21:45:12 +010064 usec_spin(co->cpucycle);
Jens Axboeba0fbe12007-03-09 14:34:23 +010065 return FIO_Q_COMPLETED;
66}
67
Jens Axboe2866c822006-10-09 15:57:48 +020068static int fio_cpuio_init(struct thread_data *td)
69{
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010070 struct thread_options *o = &td->o;
Jens Axboe03530502012-03-19 21:45:12 +010071 struct cpu_options *co = td->eo;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010072
Jens Axboe03530502012-03-19 21:45:12 +010073 if (!co->cpuload) {
Jens Axboeba0fbe12007-03-09 14:34:23 +010074 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
Jens Axboe2866c822006-10-09 15:57:48 +020075 return 1;
Jens Axboeba0fbe12007-03-09 14:34:23 +010076 }
77
Jens Axboe03530502012-03-19 21:45:12 +010078 if (co->cpuload > 100)
79 co->cpuload = 100;
Jens Axboe2866c822006-10-09 15:57:48 +020080
Jens Axboeba0fbe12007-03-09 14:34:23 +010081 /*
82 * set thinktime_sleep and thinktime_spin appropriately
83 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010084 o->thinktime_blocks = 1;
85 o->thinktime_spin = 0;
Jens Axboe03530502012-03-19 21:45:12 +010086 o->thinktime = (co->cpucycle * (100 - co->cpuload)) / co->cpuload;
Jens Axboe2866c822006-10-09 15:57:48 +020087
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010088 o->nr_files = o->open_files = 1;
Jens Axboe03530502012-03-19 21:45:12 +010089
90 log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->o.name,
91 co->cpuload, co->cpucycle);
92
Jens Axboeba0fbe12007-03-09 14:34:23 +010093 return 0;
94}
95
Jens Axboef4e62a52007-04-11 21:20:03 +020096static int fio_cpuio_open(struct thread_data fio_unused *td,
97 struct fio_file fio_unused *f)
Jens Axboeba0fbe12007-03-09 14:34:23 +010098{
Jens Axboe2866c822006-10-09 15:57:48 +020099 return 0;
100}
101
Jens Axboe5f350952006-11-07 15:20:59 +0100102static struct ioengine_ops ioengine = {
Jens Axboe2866c822006-10-09 15:57:48 +0200103 .name = "cpuio",
104 .version = FIO_IOOPS_VERSION,
Jens Axboeba0fbe12007-03-09 14:34:23 +0100105 .queue = fio_cpuio_queue,
Jens Axboe2866c822006-10-09 15:57:48 +0200106 .init = fio_cpuio_init,
Jens Axboeba0fbe12007-03-09 14:34:23 +0100107 .open_file = fio_cpuio_open,
Jens Axboe1f809d12007-10-25 18:34:02 +0200108 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO,
Jens Axboe03530502012-03-19 21:45:12 +0100109 .options = options,
110 .option_struct_size = sizeof(struct cpu_options),
Jens Axboe2866c822006-10-09 15:57:48 +0200111};
Jens Axboe5f350952006-11-07 15:20:59 +0100112
113static void fio_init fio_cpuio_register(void)
114{
115 register_ioengine(&ioengine);
116}
117
118static void fio_exit fio_cpuio_unregister(void)
119{
120 unregister_ioengine(&ioengine);
121}