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 | 0353050 | 2012-03-19 21:45:12 +0100 | [diff] [blame] | 10 | struct cpu_options { |
| 11 | struct thread_data *td; |
| 12 | unsigned int cpuload; |
| 13 | unsigned int cpucycle; |
| 14 | }; |
| 15 | |
| 16 | static struct fio_option options[] = { |
| 17 | { |
| 18 | .name = "cpuload", |
| 19 | .lname = "CPU load", |
| 20 | .type = FIO_OPT_INT, |
| 21 | .off1 = offsetof(struct cpu_options, cpuload), |
| 22 | .help = "Use this percentage of CPU", |
| 23 | .category = FIO_OPT_C_GENERAL, |
| 24 | .group = FIO_OPT_G_INVALID, |
| 25 | }, |
| 26 | { |
| 27 | .name = "cpuchunks", |
| 28 | .lname = "CPU chunk", |
| 29 | .type = FIO_OPT_INT, |
| 30 | .off1 = offsetof(struct cpu_options, cpucycle), |
| 31 | .help = "Length of the CPU burn cycles (usecs)", |
| 32 | .def = "50000", |
| 33 | .parent = "cpuload", |
| 34 | .hide = 1, |
| 35 | .category = FIO_OPT_C_GENERAL, |
| 36 | .group = FIO_OPT_G_INVALID, |
| 37 | }, |
| 38 | { |
| 39 | .name = NULL, |
| 40 | }, |
| 41 | }; |
| 42 | |
| 43 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 44 | static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u) |
| 45 | { |
Jens Axboe | 0353050 | 2012-03-19 21:45:12 +0100 | [diff] [blame] | 46 | struct cpu_options *co = td->eo; |
| 47 | |
| 48 | usec_spin(co->cpucycle); |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 49 | return FIO_Q_COMPLETED; |
| 50 | } |
| 51 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 52 | static int fio_cpuio_init(struct thread_data *td) |
| 53 | { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 54 | struct thread_options *o = &td->o; |
Jens Axboe | 0353050 | 2012-03-19 21:45:12 +0100 | [diff] [blame] | 55 | struct cpu_options *co = td->eo; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 56 | |
Jens Axboe | 0353050 | 2012-03-19 21:45:12 +0100 | [diff] [blame] | 57 | if (!co->cpuload) { |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 58 | td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio"); |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 59 | return 1; |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Jens Axboe | 0353050 | 2012-03-19 21:45:12 +0100 | [diff] [blame] | 62 | if (co->cpuload > 100) |
| 63 | co->cpuload = 100; |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 64 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 65 | /* |
| 66 | * set thinktime_sleep and thinktime_spin appropriately |
| 67 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 68 | o->thinktime_blocks = 1; |
| 69 | o->thinktime_spin = 0; |
Jens Axboe | 0353050 | 2012-03-19 21:45:12 +0100 | [diff] [blame] | 70 | o->thinktime = (co->cpucycle * (100 - co->cpuload)) / co->cpuload; |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 71 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 72 | o->nr_files = o->open_files = 1; |
Jens Axboe | 0353050 | 2012-03-19 21:45:12 +0100 | [diff] [blame] | 73 | |
| 74 | log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->o.name, |
| 75 | co->cpuload, co->cpucycle); |
| 76 | |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | |
Jens Axboe | f4e62a5 | 2007-04-11 21:20:03 +0200 | [diff] [blame] | 80 | static int fio_cpuio_open(struct thread_data fio_unused *td, |
| 81 | struct fio_file fio_unused *f) |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 82 | { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 86 | static struct ioengine_ops ioengine = { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 87 | .name = "cpuio", |
| 88 | .version = FIO_IOOPS_VERSION, |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 89 | .queue = fio_cpuio_queue, |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 90 | .init = fio_cpuio_init, |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 91 | .open_file = fio_cpuio_open, |
Jens Axboe | 1f809d1 | 2007-10-25 18:34:02 +0200 | [diff] [blame] | 92 | .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO, |
Jens Axboe | 0353050 | 2012-03-19 21:45:12 +0100 | [diff] [blame] | 93 | .options = options, |
| 94 | .option_struct_size = sizeof(struct cpu_options), |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 95 | }; |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 96 | |
| 97 | static void fio_init fio_cpuio_register(void) |
| 98 | { |
| 99 | register_ioengine(&ioengine); |
| 100 | } |
| 101 | |
| 102 | static void fio_exit fio_cpuio_unregister(void) |
| 103 | { |
| 104 | unregister_ioengine(&ioengine); |
| 105 | } |