Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 1 | #include "../fio.h" |
| 2 | #include "../os.h" |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 3 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame^] | 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 | |
Jens Axboe | ea2877a | 2006-10-10 08:30:24 +0200 | [diff] [blame] | 10 | static int fio_cpuio_setup(struct thread_data fio_unused *td) |
| 11 | { |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame^] | 12 | 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 Axboe | ea2877a | 2006-10-10 08:30:24 +0200 | [diff] [blame] | 24 | return 0; |
| 25 | } |
| 26 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 27 | static int fio_cpuio_init(struct thread_data *td) |
| 28 | { |
| 29 | if (!td->cpuload) { |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame^] | 30 | td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio"); |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 31 | return 1; |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame^] | 32 | } |
| 33 | |
| 34 | if (td->cpuload > 100) |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 35 | td->cpuload = 100; |
| 36 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame^] | 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; |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 43 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame^] | 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; |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 54 | static struct ioengine_ops ioengine = { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 55 | .name = "cpuio", |
| 56 | .version = FIO_IOOPS_VERSION, |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame^] | 57 | .queue = fio_cpuio_queue, |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 58 | .init = fio_cpuio_init, |
Jens Axboe | ea2877a | 2006-10-10 08:30:24 +0200 | [diff] [blame] | 59 | .setup = fio_cpuio_setup, |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame^] | 60 | .open_file = fio_cpuio_open, |
| 61 | .flags = FIO_SYNCIO | FIO_DISKLESSIO, |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 62 | }; |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 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 | } |