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