blob: c798f1884e8dff8df9b079d87d61c8c4259ae10c [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 {
11 struct thread_data *td;
12 unsigned int cpuload;
13 unsigned int cpucycle;
14};
15
16static struct fio_option options[] = {
17 {
18 .name = "cpuload",
19 .lname = "CPU load",
20 .type = FIO_OPT_INT,
21 .off1 = offsetof(struct cpu_options, cpuload),
22 .help = "Use this percentage of CPU",
23 .category = FIO_OPT_C_GENERAL,
24 .group = FIO_OPT_G_INVALID,
25 },
26 {
27 .name = "cpuchunks",
28 .lname = "CPU chunk",
29 .type = FIO_OPT_INT,
30 .off1 = offsetof(struct cpu_options, cpucycle),
31 .help = "Length of the CPU burn cycles (usecs)",
32 .def = "50000",
33 .parent = "cpuload",
34 .hide = 1,
35 .category = FIO_OPT_C_GENERAL,
36 .group = FIO_OPT_G_INVALID,
37 },
38 {
39 .name = NULL,
40 },
41};
42
43
Jens Axboeba0fbe12007-03-09 14:34:23 +010044static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u)
45{
Jens Axboe03530502012-03-19 21:45:12 +010046 struct cpu_options *co = td->eo;
47
48 usec_spin(co->cpucycle);
Jens Axboeba0fbe12007-03-09 14:34:23 +010049 return FIO_Q_COMPLETED;
50}
51
Jens Axboe2866c822006-10-09 15:57:48 +020052static int fio_cpuio_init(struct thread_data *td)
53{
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010054 struct thread_options *o = &td->o;
Jens Axboe03530502012-03-19 21:45:12 +010055 struct cpu_options *co = td->eo;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010056
Jens Axboe03530502012-03-19 21:45:12 +010057 if (!co->cpuload) {
Jens Axboeba0fbe12007-03-09 14:34:23 +010058 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
Jens Axboe2866c822006-10-09 15:57:48 +020059 return 1;
Jens Axboeba0fbe12007-03-09 14:34:23 +010060 }
61
Jens Axboe03530502012-03-19 21:45:12 +010062 if (co->cpuload > 100)
63 co->cpuload = 100;
Jens Axboe2866c822006-10-09 15:57:48 +020064
Jens Axboeba0fbe12007-03-09 14:34:23 +010065 /*
66 * set thinktime_sleep and thinktime_spin appropriately
67 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010068 o->thinktime_blocks = 1;
69 o->thinktime_spin = 0;
Jens Axboe03530502012-03-19 21:45:12 +010070 o->thinktime = (co->cpucycle * (100 - co->cpuload)) / co->cpuload;
Jens Axboe2866c822006-10-09 15:57:48 +020071
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010072 o->nr_files = o->open_files = 1;
Jens Axboe03530502012-03-19 21:45:12 +010073
74 log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->o.name,
75 co->cpuload, co->cpucycle);
76
Jens Axboeba0fbe12007-03-09 14:34:23 +010077 return 0;
78}
79
Jens Axboef4e62a52007-04-11 21:20:03 +020080static int fio_cpuio_open(struct thread_data fio_unused *td,
81 struct fio_file fio_unused *f)
Jens Axboeba0fbe12007-03-09 14:34:23 +010082{
Jens Axboe2866c822006-10-09 15:57:48 +020083 return 0;
84}
85
Jens Axboe5f350952006-11-07 15:20:59 +010086static struct ioengine_ops ioengine = {
Jens Axboe2866c822006-10-09 15:57:48 +020087 .name = "cpuio",
88 .version = FIO_IOOPS_VERSION,
Jens Axboeba0fbe12007-03-09 14:34:23 +010089 .queue = fio_cpuio_queue,
Jens Axboe2866c822006-10-09 15:57:48 +020090 .init = fio_cpuio_init,
Jens Axboeba0fbe12007-03-09 14:34:23 +010091 .open_file = fio_cpuio_open,
Jens Axboe1f809d12007-10-25 18:34:02 +020092 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO,
Jens Axboe03530502012-03-19 21:45:12 +010093 .options = options,
94 .option_struct_size = sizeof(struct cpu_options),
Jens Axboe2866c822006-10-09 15:57:48 +020095};
Jens Axboe5f350952006-11-07 15:20:59 +010096
97static void fio_init fio_cpuio_register(void)
98{
99 register_ioengine(&ioengine);
100}
101
102static void fio_exit fio_cpuio_unregister(void)
103{
104 unregister_ioengine(&ioengine);
105}