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" |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 9 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 10 | static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u) |
| 11 | { |
Jens Axboe | 6dd6f2c | 2008-12-10 13:24:12 +0100 | [diff] [blame] | 12 | usec_spin(td->o.cpucycle); |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 13 | return FIO_Q_COMPLETED; |
| 14 | } |
| 15 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 16 | static int fio_cpuio_init(struct thread_data *td) |
| 17 | { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 18 | struct thread_options *o = &td->o; |
| 19 | |
| 20 | if (!o->cpuload) { |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 21 | td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio"); |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 22 | return 1; |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 23 | } |
| 24 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 25 | if (o->cpuload > 100) |
| 26 | o->cpuload = 100; |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 27 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 28 | /* |
| 29 | * set thinktime_sleep and thinktime_spin appropriately |
| 30 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 31 | o->thinktime_blocks = 1; |
| 32 | o->thinktime_spin = 0; |
| 33 | o->thinktime = (o->cpucycle * (100 - o->cpuload)) / o->cpuload; |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 34 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 35 | o->nr_files = o->open_files = 1; |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | |
Jens Axboe | f4e62a5 | 2007-04-11 21:20:03 +0200 | [diff] [blame] | 39 | static int fio_cpuio_open(struct thread_data fio_unused *td, |
| 40 | struct fio_file fio_unused *f) |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 41 | { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 45 | static struct ioengine_ops ioengine = { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 46 | .name = "cpuio", |
| 47 | .version = FIO_IOOPS_VERSION, |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 48 | .queue = fio_cpuio_queue, |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 49 | .init = fio_cpuio_init, |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 50 | .open_file = fio_cpuio_open, |
Jens Axboe | 1f809d1 | 2007-10-25 18:34:02 +0200 | [diff] [blame] | 51 | .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO, |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 52 | }; |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 53 | |
| 54 | static void fio_init fio_cpuio_register(void) |
| 55 | { |
| 56 | register_ioengine(&ioengine); |
| 57 | } |
| 58 | |
| 59 | static void fio_exit fio_cpuio_unregister(void) |
| 60 | { |
| 61 | unregister_ioengine(&ioengine); |
| 62 | } |