nr_files conflict with filename
[fio.git] / engines / cpu.c
CommitLineData
5f350952
JA
1#include "../fio.h"
2#include "../os.h"
2866c82d 3
ba0fbe10
JA
4static 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
ea2877a4
JA
10static int fio_cpuio_setup(struct thread_data fio_unused *td)
11{
ba0fbe10 12 struct fio_file *f;
af52b345 13 unsigned int i;
ba0fbe10
JA
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
ea2877a4
JA
24 return 0;
25}
26
2866c82d
JA
27static int fio_cpuio_init(struct thread_data *td)
28{
29 if (!td->cpuload) {
ba0fbe10 30 td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
2866c82d 31 return 1;
ba0fbe10
JA
32 }
33
34 if (td->cpuload > 100)
2866c82d
JA
35 td->cpuload = 100;
36
ba0fbe10
JA
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;
2866c82d 43
ba0fbe10
JA
44 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;
2866c82d
JA
51 return 0;
52}
53
5f350952 54static struct ioengine_ops ioengine = {
2866c82d
JA
55 .name = "cpuio",
56 .version = FIO_IOOPS_VERSION,
ba0fbe10 57 .queue = fio_cpuio_queue,
2866c82d 58 .init = fio_cpuio_init,
ea2877a4 59 .setup = fio_cpuio_setup,
ba0fbe10
JA
60 .open_file = fio_cpuio_open,
61 .flags = FIO_SYNCIO | FIO_DISKLESSIO,
2866c82d 62};
5f350952
JA
63
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}