blob: 8bc9fd5c3c8c8919d4618bf6f149fb5b142093a6 [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 Axboeba0fbe12007-03-09 14:34:23 +010010static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u)
11{
Jens Axboe6dd6f2c2008-12-10 13:24:12 +010012 usec_spin(td->o.cpucycle);
Jens Axboeba0fbe12007-03-09 14:34:23 +010013 return FIO_Q_COMPLETED;
14}
15
Jens Axboe2866c822006-10-09 15:57:48 +020016static int fio_cpuio_init(struct thread_data *td)
17{
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010018 struct thread_options *o = &td->o;
19
20 if (!o->cpuload) {
Jens Axboeba0fbe12007-03-09 14:34:23 +010021 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
Jens Axboe2866c822006-10-09 15:57:48 +020022 return 1;
Jens Axboeba0fbe12007-03-09 14:34:23 +010023 }
24
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010025 if (o->cpuload > 100)
26 o->cpuload = 100;
Jens Axboe2866c822006-10-09 15:57:48 +020027
Jens Axboeba0fbe12007-03-09 14:34:23 +010028 /*
29 * set thinktime_sleep and thinktime_spin appropriately
30 */
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010031 o->thinktime_blocks = 1;
32 o->thinktime_spin = 0;
33 o->thinktime = (o->cpucycle * (100 - o->cpuload)) / o->cpuload;
Jens Axboe2866c822006-10-09 15:57:48 +020034
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010035 o->nr_files = o->open_files = 1;
Jens Axboeba0fbe12007-03-09 14:34:23 +010036 return 0;
37}
38
Jens Axboef4e62a52007-04-11 21:20:03 +020039static int fio_cpuio_open(struct thread_data fio_unused *td,
40 struct fio_file fio_unused *f)
Jens Axboeba0fbe12007-03-09 14:34:23 +010041{
Jens Axboe2866c822006-10-09 15:57:48 +020042 return 0;
43}
44
Jens Axboe5f350952006-11-07 15:20:59 +010045static struct ioengine_ops ioengine = {
Jens Axboe2866c822006-10-09 15:57:48 +020046 .name = "cpuio",
47 .version = FIO_IOOPS_VERSION,
Jens Axboeba0fbe12007-03-09 14:34:23 +010048 .queue = fio_cpuio_queue,
Jens Axboe2866c822006-10-09 15:57:48 +020049 .init = fio_cpuio_init,
Jens Axboeba0fbe12007-03-09 14:34:23 +010050 .open_file = fio_cpuio_open,
Jens Axboe1f809d12007-10-25 18:34:02 +020051 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO,
Jens Axboe2866c822006-10-09 15:57:48 +020052};
Jens Axboe5f350952006-11-07 15:20:59 +010053
54static void fio_init fio_cpuio_register(void)
55{
56 register_ioengine(&ioengine);
57}
58
59static void fio_exit fio_cpuio_unregister(void)
60{
61 unregister_ioengine(&ioengine);
62}