blob: 73cde8565c78236a6ddf258f6bf90eb4ad91c881 [file] [log] [blame]
Jens Axboed4afedf2013-05-22 22:21:29 +02001#include "../fio.h"
2#include "../profile.h"
3#include "../parse.h"
4
Jens Axboe00f81c32013-05-23 09:32:31 +02005/*
6 * 1x loads
7 */
Jens Axboed4afedf2013-05-22 22:21:29 +02008#define R_LOAD 2000
9#define W_LOAD 1000
10
11#define SAMPLE_SEC 3600 /* 1h checks */
12
13struct act_pass_criteria {
14 unsigned int max_usec;
15 unsigned int max_perm;
16};
17#define ACT_MAX_CRIT 3
18
19static struct act_pass_criteria act_pass[ACT_MAX_CRIT] = {
20 {
21 .max_usec = 1000,
22 .max_perm = 50,
23 },
24 {
Jens Axboe78a6aad2013-05-23 00:29:38 +020025 .max_usec = 8000,
Jens Axboed4afedf2013-05-22 22:21:29 +020026 .max_perm = 10,
27 },
28 {
29 .max_usec = 64000,
30 .max_perm = 1,
31 },
32};
33
Jens Axboe90777552013-05-24 09:09:39 +020034struct act_slice {
35 uint64_t lat_buckets[ACT_MAX_CRIT];
36 uint64_t total_ios;
37};
38
Jens Axboe4a887522013-05-23 12:33:08 +020039struct act_run_data {
40 struct fio_mutex *mutex;
41 unsigned int pending;
42
Jens Axboe90777552013-05-24 09:09:39 +020043 struct act_slice *slices;
44 unsigned int nr_slices;
Jens Axboe4a887522013-05-23 12:33:08 +020045};
46static struct act_run_data *act_run_data;
47
Jens Axboed4afedf2013-05-22 22:21:29 +020048struct act_prof_data {
49 struct timeval sample_tv;
Jens Axboe90777552013-05-24 09:09:39 +020050 struct act_slice *slices;
51 unsigned int cur_slice;
52 unsigned int nr_slices;
Jens Axboed4afedf2013-05-22 22:21:29 +020053};
54
55static char *device_names;
Jens Axboe90777552013-05-24 09:09:39 +020056static unsigned int load;
Jens Axboe00f81c32013-05-23 09:32:31 +020057static unsigned int prep;
58static unsigned int threads_per_queue;
59static unsigned int num_read_blocks;
60static unsigned int write_size;
Jens Axboe90777552013-05-24 09:09:39 +020061static unsigned long long test_duration;
Jens Axboed4afedf2013-05-22 22:21:29 +020062
Jens Axboe00f81c32013-05-23 09:32:31 +020063#define ACT_MAX_OPTS 128
64static const char *act_opts[ACT_MAX_OPTS] = {
Jens Axboed4afedf2013-05-22 22:21:29 +020065 "direct=1",
Jens Axboe00f81c32013-05-23 09:32:31 +020066 "ioengine=sync",
Jens Axboed4afedf2013-05-22 22:21:29 +020067 "random_generator=lfsr",
Jens Axboe00f81c32013-05-23 09:32:31 +020068 "group_reporting=1",
Jens Axboe4a887522013-05-23 12:33:08 +020069 "thread",
Jens Axboed4afedf2013-05-22 22:21:29 +020070 NULL,
71};
Jens Axboe4a887522013-05-23 12:33:08 +020072static unsigned int opt_idx = 5;
Jens Axboed4afedf2013-05-22 22:21:29 +020073static unsigned int org_idx;
74
Jens Axboe00f81c32013-05-23 09:32:31 +020075static int act_add_opt(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
Jens Axboed4afedf2013-05-22 22:21:29 +020076
77static struct fio_option options[] = {
78 {
79 .name = "device-names",
80 .lname = "device-names",
81 .type = FIO_OPT_STR_STORE,
82 .roff1 = &device_names,
83 .help = "Devices to use",
84 .category = FIO_OPT_C_PROFILE,
85 .group = FIO_OPT_G_ACT,
86 },
87 {
88 .name = "load",
89 .lname = "Load multiplier",
90 .type = FIO_OPT_INT,
91 .roff1 = &load,
92 .help = "ACT load multipler (default 1x)",
Jens Axboe00f81c32013-05-23 09:32:31 +020093 .def = "1",
94 .category = FIO_OPT_C_PROFILE,
95 .group = FIO_OPT_G_ACT,
96 },
97 {
Jens Axboe90777552013-05-24 09:09:39 +020098 .name = "test-duration",
99 .lname = "Test duration",
100 .type = FIO_OPT_STR_VAL_TIME,
101 .roff1 = &test_duration,
102 .help = "How long the entire test takes to run",
103 .def = "24h",
104 .category = FIO_OPT_C_PROFILE,
105 .group = FIO_OPT_G_ACT,
106 },
107 {
Jens Axboe00f81c32013-05-23 09:32:31 +0200108 .name = "threads-per-queue",
109 .lname = "Number of read IO threads per device",
110 .type = FIO_OPT_INT,
111 .roff1 = &threads_per_queue,
112 .help = "Number of read IO threads per device",
113 .def = "8",
114 .category = FIO_OPT_C_PROFILE,
115 .group = FIO_OPT_G_ACT,
116 },
117 {
118 .name = "read-req-num-512-blocks",
119 .lname = "Number of 512b blocks to read",
120 .type = FIO_OPT_INT,
121 .roff1 = &num_read_blocks,
122 .help = "Number of 512b blocks to read at the time",
123 .def = "3",
124 .category = FIO_OPT_C_PROFILE,
125 .group = FIO_OPT_G_ACT,
126 },
127 {
128 .name = "large-block-op-kbytes",
129 .lname = "Size of large block ops (writes)",
130 .type = FIO_OPT_INT,
131 .roff1 = &write_size,
132 .help = "Size of large block ops (writes)",
133 .def = "128k",
134 .category = FIO_OPT_C_PROFILE,
135 .group = FIO_OPT_G_ACT,
136 },
137 {
138 .name = "prep",
139 .lname = "Run ACT prep phase",
140 .type = FIO_OPT_STR_SET,
141 .roff1 = &prep,
142 .help = "Set to run ACT prep phase",
Jens Axboed4afedf2013-05-22 22:21:29 +0200143 .category = FIO_OPT_C_PROFILE,
144 .group = FIO_OPT_G_ACT,
145 },
146 {
147 .name = NULL,
148 },
149};
150
Jens Axboe00f81c32013-05-23 09:32:31 +0200151static int act_add_opt(const char *str, ...)
Jens Axboed4afedf2013-05-22 22:21:29 +0200152{
153 char buffer[512];
154 va_list args;
155 size_t len;
156
Jens Axboe00f81c32013-05-23 09:32:31 +0200157 if (opt_idx == ACT_MAX_OPTS) {
158 log_err("act: ACT_MAX_OPTS is too small\n");
159 return 1;
160 }
161
Jens Axboed4afedf2013-05-22 22:21:29 +0200162 va_start(args, str);
163 len = vsnprintf(buffer, sizeof(buffer), str, args);
164 va_end(args);
165
166 if (len)
167 act_opts[opt_idx++] = strdup(buffer);
Jens Axboe00f81c32013-05-23 09:32:31 +0200168
169 return 0;
Jens Axboed4afedf2013-05-22 22:21:29 +0200170}
171
Jens Axboe00f81c32013-05-23 09:32:31 +0200172static int act_add_rw(const char *dev, int reads)
Jens Axboed4afedf2013-05-22 22:21:29 +0200173{
Jens Axboe00f81c32013-05-23 09:32:31 +0200174 if (act_add_opt("name=act-%s-%s", reads ? "read" : "write", dev))
175 return 1;
176 if (act_add_opt("filename=%s", dev))
177 return 1;
178 if (act_add_opt("rw=%s", reads ? "randread" : "randwrite"))
179 return 1;
180 if (reads) {
181 int rload = load * R_LOAD / threads_per_queue;
Jens Axboed4afedf2013-05-22 22:21:29 +0200182
Jens Axboe00f81c32013-05-23 09:32:31 +0200183 if (act_add_opt("numjobs=%u", threads_per_queue))
184 return 1;
185 if (act_add_opt("rate_iops=%u", rload))
186 return 1;
187 if (act_add_opt("bs=%u", num_read_blocks * 512))
188 return 1;
189 } else {
190 const int rsize = write_size / (num_read_blocks * 512);
191 int wload = (load * W_LOAD + rsize - 1) / rsize;
192
193 if (act_add_opt("rate_iops=%u", wload))
194 return 1;
195 if (act_add_opt("bs=%u", write_size))
196 return 1;
197 }
198
199 return 0;
200}
201
202static int act_add_dev_prep(const char *dev)
203{
204 /* Add sequential zero phase */
205 if (act_add_opt("name=act-prep-zeroes-%s", dev))
206 return 1;
207 if (act_add_opt("filename=%s", dev))
208 return 1;
209 if (act_add_opt("bs=1M"))
210 return 1;
211 if (act_add_opt("zero_buffers"))
212 return 1;
213 if (act_add_opt("rw=write"))
214 return 1;
215
216 /* Randomly overwrite device */
217 if (act_add_opt("name=act-prep-salt-%s", dev))
218 return 1;
219 if (act_add_opt("stonewall"))
220 return 1;
221 if (act_add_opt("filename=%s", dev))
222 return 1;
223 if (act_add_opt("bs=4k"))
224 return 1;
225 if (act_add_opt("ioengine=libaio"))
226 return 1;
227 if (act_add_opt("iodepth=64"))
228 return 1;
229 if (act_add_opt("rw=randwrite"))
230 return 1;
231
232 return 0;
233}
234
235static int act_add_dev(const char *dev)
236{
237 if (prep)
238 return act_add_dev_prep(dev);
239
Jens Axboe90777552013-05-24 09:09:39 +0200240 if (act_add_opt("runtime=%llus", test_duration))
Jens Axboe00f81c32013-05-23 09:32:31 +0200241 return 1;
242 if (act_add_opt("time_based=1"))
243 return 1;
244
245 if (act_add_rw(dev, 1))
246 return 1;
247 if (act_add_rw(dev, 0))
248 return 1;
249
250 return 0;
Jens Axboed4afedf2013-05-22 22:21:29 +0200251}
252
253/*
254 * Fill our private options into the command line
255 */
256static int act_prep_cmdline(void)
257{
258 if (!device_names) {
Jens Axboe90777552013-05-24 09:09:39 +0200259 log_err("act: you need to set IO target(s) with the "
260 "device-names option.\n");
Jens Axboed4afedf2013-05-22 22:21:29 +0200261 return 1;
262 }
263
264 org_idx = opt_idx;
Jens Axboed4afedf2013-05-22 22:21:29 +0200265
266 do {
267 char *dev;
268
269 dev = strsep(&device_names, ",");
270 if (!dev)
271 break;
272
Jens Axboe00f81c32013-05-23 09:32:31 +0200273 if (act_add_dev(dev)) {
274 log_err("act: failed adding device to the mix\n");
275 break;
276 }
Jens Axboed4afedf2013-05-22 22:21:29 +0200277 } while (1);
278
279 return 0;
280}
281
282static int act_io_u_lat(struct thread_data *td, uint64_t usec)
283{
284 struct act_prof_data *apd = td->prof_data;
Jens Axboe90777552013-05-24 09:09:39 +0200285 struct act_slice *slice;
Jens Axboed4afedf2013-05-22 22:21:29 +0200286 int i, ret = 0;
287 double perm;
288
Jens Axboe00f81c32013-05-23 09:32:31 +0200289 if (prep)
290 return 0;
291
Jens Axboe90777552013-05-24 09:09:39 +0200292 /*
293 * Really should not happen, but lets not let jitter at the end
294 * ruin our day.
295 */
296 if (apd->cur_slice >= apd->nr_slices)
297 return 0;
298
299 slice = &apd->slices[apd->cur_slice];
300 slice->total_ios++;
Jens Axboed4afedf2013-05-22 22:21:29 +0200301
Jens Axboe78a6aad2013-05-23 00:29:38 +0200302 for (i = ACT_MAX_CRIT - 1; i >= 0; i--) {
303 if (usec > act_pass[i].max_usec) {
Jens Axboe90777552013-05-24 09:09:39 +0200304 slice->lat_buckets[i]++;
Jens Axboed4afedf2013-05-22 22:21:29 +0200305 break;
306 }
307 }
308
Jens Axboed4afedf2013-05-22 22:21:29 +0200309 if (time_since_now(&apd->sample_tv) < SAMPLE_SEC)
310 return 0;
311
312 /* SAMPLE_SEC has passed, check criteria for pass */
313 for (i = 0; i < ACT_MAX_CRIT; i++) {
Jens Axboe90777552013-05-24 09:09:39 +0200314 perm = (1000.0 * slice->lat_buckets[i]) / slice->total_ios;
Jens Axboe78a6aad2013-05-23 00:29:38 +0200315 if (perm < act_pass[i].max_perm)
Jens Axboed4afedf2013-05-22 22:21:29 +0200316 continue;
317
318 log_err("act: %f%% exceeds pass criteria of %f%%\n", perm / 10.0, (double) act_pass[i].max_perm / 10.0);
319 ret = 1;
320 break;
321 }
322
Jens Axboed4afedf2013-05-22 22:21:29 +0200323 fio_gettime(&apd->sample_tv, NULL);
Jens Axboe90777552013-05-24 09:09:39 +0200324 apd->cur_slice++;
Jens Axboed4afedf2013-05-22 22:21:29 +0200325 return ret;
326}
327
Jens Axboe4a887522013-05-23 12:33:08 +0200328static void get_act_ref(void)
329{
330 fio_mutex_down(act_run_data->mutex);
331 act_run_data->pending++;
332 fio_mutex_up(act_run_data->mutex);
333}
334
Jens Axboe90777552013-05-24 09:09:39 +0200335static int show_slice(struct act_slice *slice, unsigned int slice_num)
336{
337 unsigned int i, failed = 0;
338
339 log_info(" %2u", slice_num);
340
341 for (i = 0; i < ACT_MAX_CRIT; i++) {
342 double perc = 0.0;
343
344 if (slice->total_ios)
345 perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios;
346 if ((perc * 10.0) >= act_pass[i].max_perm)
347 failed++;
348 log_info("\t%2.2f", perc);
349 }
350 for (i = 0; i < ACT_MAX_CRIT; i++) {
351 double perc = 0.0;
352
353 if (slice->total_ios)
354 perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios;
355 log_info("\t%2.2f", perc);
356 }
357 log_info("\n");
358
359 return failed;
360}
361
Jens Axboe4a887522013-05-23 12:33:08 +0200362static void act_show_all_stats(void)
363{
Jens Axboe90777552013-05-24 09:09:39 +0200364 unsigned int i, fails = 0;
Jens Axboe4a887522013-05-23 12:33:08 +0200365
Jens Axboe90777552013-05-24 09:09:39 +0200366 log_info(" trans device\n");
367 log_info(" %%>(ms) %%>(ms)\n");
Jens Axboe4a887522013-05-23 12:33:08 +0200368 log_info(" slice");
369
370 for (i = 0; i < ACT_MAX_CRIT; i++)
Jens Axboe90777552013-05-24 09:09:39 +0200371 log_info("\t %2u", act_pass[i].max_usec / 1000);
Jens Axboe4a887522013-05-23 12:33:08 +0200372 for (i = 0; i < ACT_MAX_CRIT; i++)
Jens Axboe90777552013-05-24 09:09:39 +0200373 log_info("\t %2u", act_pass[i].max_usec / 1000);
Jens Axboe4a887522013-05-23 12:33:08 +0200374
375 log_info("\n");
Jens Axboe90777552013-05-24 09:09:39 +0200376 log_info(" ----- ----- ----- ------ ----- ----- ------\n");
Jens Axboe4a887522013-05-23 12:33:08 +0200377
Jens Axboe90777552013-05-24 09:09:39 +0200378 for (i = 0; i < act_run_data->nr_slices; i++)
379 fails += show_slice(&act_run_data->slices[i], i + 1);
Jens Axboe4a887522013-05-23 12:33:08 +0200380
Jens Axboe90777552013-05-24 09:09:39 +0200381 log_info("\nact: test complete, device(s): %s\n", fails ? "FAILED" : "PASSED");
Jens Axboe4a887522013-05-23 12:33:08 +0200382}
383
384static void put_act_ref(struct thread_data *td)
385{
386 struct act_prof_data *apd = td->prof_data;
Jens Axboe90777552013-05-24 09:09:39 +0200387 unsigned int i, slice;
Jens Axboe4a887522013-05-23 12:33:08 +0200388
389 fio_mutex_down(act_run_data->mutex);
390
Jens Axboe90777552013-05-24 09:09:39 +0200391 if (!act_run_data->slices) {
392 act_run_data->slices = calloc(sizeof(struct act_slice), apd->nr_slices);
393 act_run_data->nr_slices = apd->nr_slices;
Jens Axboe4a887522013-05-23 12:33:08 +0200394 }
395
Jens Axboe90777552013-05-24 09:09:39 +0200396 for (slice = 0; slice < apd->nr_slices; slice++) {
397 struct act_slice *dst = &act_run_data->slices[slice];
398 struct act_slice *src = &apd->slices[slice];
399
400 dst->total_ios += src->total_ios;
401
402 for (i = 0; i < ACT_MAX_CRIT; i++)
403 dst->lat_buckets[i] += src->lat_buckets[i];
404 }
Jens Axboe4a887522013-05-23 12:33:08 +0200405
406 if (!--act_run_data->pending)
407 act_show_all_stats();
408
409 fio_mutex_up(act_run_data->mutex);
410}
411
Jens Axboed4afedf2013-05-22 22:21:29 +0200412static int act_td_init(struct thread_data *td)
413{
414 struct act_prof_data *apd;
Jens Axboe90777552013-05-24 09:09:39 +0200415 unsigned int nr_slices;
Jens Axboed4afedf2013-05-22 22:21:29 +0200416
Jens Axboe4a887522013-05-23 12:33:08 +0200417 get_act_ref();
418
Jens Axboed4afedf2013-05-22 22:21:29 +0200419 apd = calloc(sizeof(*apd), 1);
Jens Axboe90777552013-05-24 09:09:39 +0200420 nr_slices = (test_duration + SAMPLE_SEC - 1) / SAMPLE_SEC;
421 apd->slices = calloc(sizeof(struct act_slice), nr_slices);
422 apd->nr_slices = nr_slices;
Jens Axboed4afedf2013-05-22 22:21:29 +0200423 fio_gettime(&apd->sample_tv, NULL);
424 td->prof_data = apd;
425 return 0;
426}
427
428static void act_td_exit(struct thread_data *td)
429{
Jens Axboe90777552013-05-24 09:09:39 +0200430 struct act_prof_data *apd = td->prof_data;
431
Jens Axboe4a887522013-05-23 12:33:08 +0200432 put_act_ref(td);
Jens Axboe90777552013-05-24 09:09:39 +0200433 free(apd->slices);
434 free(apd);
Jens Axboed4afedf2013-05-22 22:21:29 +0200435 td->prof_data = NULL;
436}
437
438static struct prof_io_ops act_io_ops = {
439 .td_init = act_td_init,
440 .td_exit = act_td_exit,
441 .io_u_lat = act_io_u_lat,
442};
443
444static struct profile_ops act_profile = {
445 .name = "act",
446 .desc = "ACT Aerospike like benchmark",
447 .options = options,
448 .prep_cmd = act_prep_cmdline,
449 .cmdline = act_opts,
450 .io_ops = &act_io_ops,
451};
452
453static void fio_init act_register(void)
454{
Jens Axboe4a887522013-05-23 12:33:08 +0200455 act_run_data = calloc(sizeof(*act_run_data), 1);
456 act_run_data->mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED);
457
Jens Axboed4afedf2013-05-22 22:21:29 +0200458 if (register_profile(&act_profile))
459 log_err("fio: failed to register profile 'act'\n");
460}
461
462static void fio_exit act_unregister(void)
463{
464 while (org_idx && org_idx < opt_idx)
465 free((void *) act_opts[++org_idx]);
466
467 unregister_profile(&act_profile);
Jens Axboe4a887522013-05-23 12:33:08 +0200468 fio_mutex_remove(act_run_data->mutex);
Jens Axboe90777552013-05-24 09:09:39 +0200469 free(act_run_data->slices);
Jens Axboe4a887522013-05-23 12:33:08 +0200470 free(act_run_data);
471 act_run_data = NULL;
Jens Axboed4afedf2013-05-22 22:21:29 +0200472}