Jens Axboe | da751ca | 2007-03-14 10:59:33 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * CPU engine |
| 3 | * |
| 4 | * Doesn't transfer any data, merely burns CPU cycles according to |
| 5 | * the settings. |
| 6 | * |
| 7 | */ |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 8 | #include "../fio.h" |
| 9 | #include "../os.h" |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 10 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 11 | static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u) |
| 12 | { |
| 13 | __usec_sleep(td->cpucycle); |
| 14 | return FIO_Q_COMPLETED; |
| 15 | } |
| 16 | |
Jens Axboe | ea2877a | 2006-10-10 08:30:24 +0200 | [diff] [blame] | 17 | static int fio_cpuio_setup(struct thread_data fio_unused *td) |
| 18 | { |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 19 | struct fio_file *f; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 20 | unsigned int i; |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 21 | |
| 22 | td->total_file_size = -1; |
| 23 | td->io_size = td->total_file_size; |
| 24 | td->total_io_size = td->io_size; |
| 25 | |
| 26 | for_each_file(td, f, i) { |
| 27 | f->real_file_size = -1; |
| 28 | f->file_size = -1; |
| 29 | } |
| 30 | |
Jens Axboe | ea2877a | 2006-10-10 08:30:24 +0200 | [diff] [blame] | 31 | return 0; |
| 32 | } |
| 33 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 34 | static int fio_cpuio_init(struct thread_data *td) |
| 35 | { |
| 36 | if (!td->cpuload) { |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 37 | td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio"); |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 38 | return 1; |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | if (td->cpuload > 100) |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 42 | td->cpuload = 100; |
| 43 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 44 | /* |
| 45 | * set thinktime_sleep and thinktime_spin appropriately |
| 46 | */ |
| 47 | td->thinktime_blocks = 1; |
| 48 | td->thinktime_spin = 0; |
| 49 | td->thinktime = (td->cpucycle * (100 - td->cpuload)) / td->cpuload; |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 50 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 51 | td->nr_files = td->open_files = 1; |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static int fio_cpuio_open(struct thread_data fio_unused *td, struct fio_file *f) |
| 56 | { |
| 57 | f->fd = 0; |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 61 | static struct ioengine_ops ioengine = { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 62 | .name = "cpuio", |
| 63 | .version = FIO_IOOPS_VERSION, |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 64 | .queue = fio_cpuio_queue, |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 65 | .init = fio_cpuio_init, |
Jens Axboe | ea2877a | 2006-10-10 08:30:24 +0200 | [diff] [blame] | 66 | .setup = fio_cpuio_setup, |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 67 | .open_file = fio_cpuio_open, |
| 68 | .flags = FIO_SYNCIO | FIO_DISKLESSIO, |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 69 | }; |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 70 | |
| 71 | static void fio_init fio_cpuio_register(void) |
| 72 | { |
| 73 | register_ioengine(&ioengine); |
| 74 | } |
| 75 | |
| 76 | static void fio_exit fio_cpuio_unregister(void) |
| 77 | { |
| 78 | unregister_ioengine(&ioengine); |
| 79 | } |