blob: c908cab8af55aff7f86a58c35483af973450800d [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"
9#include "../os.h"
Jens Axboe2866c822006-10-09 15:57:48 +020010
Jens Axboeba0fbe12007-03-09 14:34:23 +010011static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u)
12{
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010013 __usec_sleep(td->o.cpucycle);
Jens Axboeba0fbe12007-03-09 14:34:23 +010014 return FIO_Q_COMPLETED;
15}
16
Jens Axboeea2877a2006-10-10 08:30:24 +020017static int fio_cpuio_setup(struct thread_data fio_unused *td)
18{
Jens Axboeba0fbe12007-03-09 14:34:23 +010019 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +010020 unsigned int i;
Jens Axboeba0fbe12007-03-09 14:34:23 +010021
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010022 td->o.size = -1;
23 td->io_size = td->o.size;
Jens Axboeba0fbe12007-03-09 14:34:23 +010024 td->total_io_size = td->io_size;
25
26 for_each_file(td, f, i) {
27 f->real_file_size = -1;
28 f->file_size = -1;
29 }
30
Jens Axboeea2877a2006-10-10 08:30:24 +020031 return 0;
32}
33
Jens Axboe2866c822006-10-09 15:57:48 +020034static int fio_cpuio_init(struct thread_data *td)
35{
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010036 struct thread_options *o = &td->o;
37
38 if (!o->cpuload) {
Jens Axboeba0fbe12007-03-09 14:34:23 +010039 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
Jens Axboe2866c822006-10-09 15:57:48 +020040 return 1;
Jens Axboeba0fbe12007-03-09 14:34:23 +010041 }
42
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010043 if (o->cpuload > 100)
44 o->cpuload = 100;
Jens Axboe2866c822006-10-09 15:57:48 +020045
Jens Axboeba0fbe12007-03-09 14:34:23 +010046 /*
47 * set thinktime_sleep and thinktime_spin appropriately
48 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010049 o->thinktime_blocks = 1;
50 o->thinktime_spin = 0;
51 o->thinktime = (o->cpucycle * (100 - o->cpuload)) / o->cpuload;
Jens Axboe2866c822006-10-09 15:57:48 +020052
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010053 o->nr_files = o->open_files = 1;
Jens Axboeba0fbe12007-03-09 14:34:23 +010054 return 0;
55}
56
57static int fio_cpuio_open(struct thread_data fio_unused *td, struct fio_file *f)
58{
59 f->fd = 0;
Jens Axboe2866c822006-10-09 15:57:48 +020060 return 0;
61}
62
Jens Axboe5f350952006-11-07 15:20:59 +010063static struct ioengine_ops ioengine = {
Jens Axboe2866c822006-10-09 15:57:48 +020064 .name = "cpuio",
65 .version = FIO_IOOPS_VERSION,
Jens Axboeba0fbe12007-03-09 14:34:23 +010066 .queue = fio_cpuio_queue,
Jens Axboe2866c822006-10-09 15:57:48 +020067 .init = fio_cpuio_init,
Jens Axboeea2877a2006-10-10 08:30:24 +020068 .setup = fio_cpuio_setup,
Jens Axboeba0fbe12007-03-09 14:34:23 +010069 .open_file = fio_cpuio_open,
70 .flags = FIO_SYNCIO | FIO_DISKLESSIO,
Jens Axboe2866c822006-10-09 15:57:48 +020071};
Jens Axboe5f350952006-11-07 15:20:59 +010072
73static void fio_init fio_cpuio_register(void)
74{
75 register_ioengine(&ioengine);
76}
77
78static void fio_exit fio_cpuio_unregister(void)
79{
80 unregister_ioengine(&ioengine);
81}