blob: 7a084e0acb96247dddb2af6a10b62fee2ce7a769 [file] [log] [blame]
Jens Axboe5f350952006-11-07 15:20:59 +01001#include "../fio.h"
2#include "../os.h"
Jens Axboe2866c822006-10-09 15:57:48 +02003
Jens Axboeba0fbe12007-03-09 14:34:23 +01004static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u)
5{
6 __usec_sleep(td->cpucycle);
7 return FIO_Q_COMPLETED;
8}
9
Jens Axboeea2877a2006-10-10 08:30:24 +020010static int fio_cpuio_setup(struct thread_data fio_unused *td)
11{
Jens Axboeba0fbe12007-03-09 14:34:23 +010012 struct fio_file *f;
13 int i;
14
15 td->total_file_size = -1;
16 td->io_size = td->total_file_size;
17 td->total_io_size = td->io_size;
18
19 for_each_file(td, f, i) {
20 f->real_file_size = -1;
21 f->file_size = -1;
22 }
23
Jens Axboeea2877a2006-10-10 08:30:24 +020024 return 0;
25}
26
Jens Axboe2866c822006-10-09 15:57:48 +020027static int fio_cpuio_init(struct thread_data *td)
28{
29 if (!td->cpuload) {
Jens Axboeba0fbe12007-03-09 14:34:23 +010030 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
Jens Axboe2866c822006-10-09 15:57:48 +020031 return 1;
Jens Axboeba0fbe12007-03-09 14:34:23 +010032 }
33
34 if (td->cpuload > 100)
Jens Axboe2866c822006-10-09 15:57:48 +020035 td->cpuload = 100;
36
Jens Axboeba0fbe12007-03-09 14:34:23 +010037 /*
38 * set thinktime_sleep and thinktime_spin appropriately
39 */
40 td->thinktime_blocks = 1;
41 td->thinktime_spin = 0;
42 td->thinktime = (td->cpucycle * (100 - td->cpuload)) / td->cpuload;
Jens Axboe2866c822006-10-09 15:57:48 +020043
Jens Axboeba0fbe12007-03-09 14:34:23 +010044 td->nr_files = td->open_files = 1;
45 return 0;
46}
47
48static int fio_cpuio_open(struct thread_data fio_unused *td, struct fio_file *f)
49{
50 f->fd = 0;
Jens Axboe2866c822006-10-09 15:57:48 +020051 return 0;
52}
53
Jens Axboe5f350952006-11-07 15:20:59 +010054static struct ioengine_ops ioengine = {
Jens Axboe2866c822006-10-09 15:57:48 +020055 .name = "cpuio",
56 .version = FIO_IOOPS_VERSION,
Jens Axboeba0fbe12007-03-09 14:34:23 +010057 .queue = fio_cpuio_queue,
Jens Axboe2866c822006-10-09 15:57:48 +020058 .init = fio_cpuio_init,
Jens Axboeea2877a2006-10-10 08:30:24 +020059 .setup = fio_cpuio_setup,
Jens Axboeba0fbe12007-03-09 14:34:23 +010060 .open_file = fio_cpuio_open,
61 .flags = FIO_SYNCIO | FIO_DISKLESSIO,
Jens Axboe2866c822006-10-09 15:57:48 +020062};
Jens Axboe5f350952006-11-07 15:20:59 +010063
64static void fio_init fio_cpuio_register(void)
65{
66 register_ioengine(&ioengine);
67}
68
69static void fio_exit fio_cpuio_unregister(void)
70{
71 unregister_ioengine(&ioengine);
72}