mmap engine: make sure that page unaligned syncs work
[fio.git] / engines / cpu.c
1 #include "../fio.h"
2 #include "../os.h"
3
4 static 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
10 static int fio_cpuio_setup(struct thread_data fio_unused *td)
11 {
12         struct fio_file *f;
13         unsigned 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
24         return 0;
25 }
26
27 static int fio_cpuio_init(struct thread_data *td)
28 {
29         if (!td->cpuload) {
30                 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
31                 return 1;
32         }
33
34         if (td->cpuload > 100)
35                 td->cpuload = 100;
36
37         /*
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;
43
44         td->nr_files = td->open_files = 1;
45         return 0;
46 }
47
48 static int fio_cpuio_open(struct thread_data fio_unused *td, struct fio_file *f)
49 {
50         f->fd = 0;
51         return 0;
52 }
53
54 static struct ioengine_ops ioengine = {
55         .name           = "cpuio",
56         .version        = FIO_IOOPS_VERSION,
57         .queue          = fio_cpuio_queue,
58         .init           = fio_cpuio_init,
59         .setup          = fio_cpuio_setup,
60         .open_file      = fio_cpuio_open,
61         .flags          = FIO_SYNCIO | FIO_DISKLESSIO,
62 };
63
64 static void fio_init fio_cpuio_register(void)
65 {
66         register_ioengine(&ioengine);
67 }
68
69 static void fio_exit fio_cpuio_unregister(void)
70 {
71         unregister_ioengine(&ioengine);
72 }