Commit | Line | Data |
---|---|---|
d4afedfd JA |
1 | #include "../fio.h" |
2 | #include "../profile.h" | |
3 | #include "../parse.h" | |
d220c761 | 4 | #include "../optgroup.h" |
d4afedfd | 5 | |
00f81c37 JA |
6 | /* |
7 | * 1x loads | |
8 | */ | |
d4afedfd JA |
9 | #define R_LOAD 2000 |
10 | #define W_LOAD 1000 | |
11 | ||
12 | #define SAMPLE_SEC 3600 /* 1h checks */ | |
13 | ||
14 | struct act_pass_criteria { | |
15 | unsigned int max_usec; | |
16 | unsigned int max_perm; | |
17 | }; | |
18 | #define ACT_MAX_CRIT 3 | |
19 | ||
20 | static struct act_pass_criteria act_pass[ACT_MAX_CRIT] = { | |
21 | { | |
22 | .max_usec = 1000, | |
23 | .max_perm = 50, | |
24 | }, | |
25 | { | |
78a6aad7 | 26 | .max_usec = 8000, |
d4afedfd JA |
27 | .max_perm = 10, |
28 | }, | |
29 | { | |
30 | .max_usec = 64000, | |
31 | .max_perm = 1, | |
32 | }, | |
33 | }; | |
34 | ||
90777558 JA |
35 | struct act_slice { |
36 | uint64_t lat_buckets[ACT_MAX_CRIT]; | |
37 | uint64_t total_ios; | |
38 | }; | |
39 | ||
4a88752a JA |
40 | struct act_run_data { |
41 | struct fio_mutex *mutex; | |
42 | unsigned int pending; | |
43 | ||
90777558 JA |
44 | struct act_slice *slices; |
45 | unsigned int nr_slices; | |
4a88752a JA |
46 | }; |
47 | static struct act_run_data *act_run_data; | |
48 | ||
d4afedfd | 49 | struct act_prof_data { |
8b6a404c | 50 | struct timespec sample_tv; |
90777558 JA |
51 | struct act_slice *slices; |
52 | unsigned int cur_slice; | |
53 | unsigned int nr_slices; | |
d4afedfd JA |
54 | }; |
55 | ||
00f81c37 JA |
56 | #define ACT_MAX_OPTS 128 |
57 | static const char *act_opts[ACT_MAX_OPTS] = { | |
d4afedfd | 58 | "direct=1", |
00f81c37 | 59 | "ioengine=sync", |
d4afedfd | 60 | "random_generator=lfsr", |
00f81c37 | 61 | "group_reporting=1", |
4a88752a | 62 | "thread", |
d4afedfd JA |
63 | NULL, |
64 | }; | |
4a88752a | 65 | static unsigned int opt_idx = 5; |
d4afedfd JA |
66 | static unsigned int org_idx; |
67 | ||
00f81c37 | 68 | static int act_add_opt(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2))); |
d4afedfd | 69 | |
7b504edd JA |
70 | struct act_options { |
71 | unsigned int pad; | |
72 | char *device_names; | |
73 | unsigned int load; | |
74 | unsigned int prep; | |
75 | unsigned int threads_per_queue; | |
76 | unsigned int num_read_blocks; | |
77 | unsigned int write_size; | |
78 | unsigned long long test_duration; | |
79 | }; | |
80 | ||
81 | static struct act_options act_options; | |
82 | ||
d4afedfd JA |
83 | static struct fio_option options[] = { |
84 | { | |
85 | .name = "device-names", | |
86 | .lname = "device-names", | |
87 | .type = FIO_OPT_STR_STORE, | |
7b504edd | 88 | .off1 = offsetof(struct act_options, device_names), |
d4afedfd JA |
89 | .help = "Devices to use", |
90 | .category = FIO_OPT_C_PROFILE, | |
91 | .group = FIO_OPT_G_ACT, | |
43f466e6 | 92 | .no_free = true, |
d4afedfd JA |
93 | }, |
94 | { | |
95 | .name = "load", | |
96 | .lname = "Load multiplier", | |
97 | .type = FIO_OPT_INT, | |
7b504edd | 98 | .off1 = offsetof(struct act_options, load), |
d4afedfd | 99 | .help = "ACT load multipler (default 1x)", |
00f81c37 JA |
100 | .def = "1", |
101 | .category = FIO_OPT_C_PROFILE, | |
102 | .group = FIO_OPT_G_ACT, | |
103 | }, | |
90777558 JA |
104 | { |
105 | .name = "test-duration", | |
106 | .lname = "Test duration", | |
107 | .type = FIO_OPT_STR_VAL_TIME, | |
7b504edd | 108 | .off1 = offsetof(struct act_options, test_duration), |
90777558 JA |
109 | .help = "How long the entire test takes to run", |
110 | .def = "24h", | |
111 | .category = FIO_OPT_C_PROFILE, | |
112 | .group = FIO_OPT_G_ACT, | |
113 | }, | |
00f81c37 JA |
114 | { |
115 | .name = "threads-per-queue", | |
116 | .lname = "Number of read IO threads per device", | |
117 | .type = FIO_OPT_INT, | |
7b504edd | 118 | .off1 = offsetof(struct act_options, threads_per_queue), |
00f81c37 JA |
119 | .help = "Number of read IO threads per device", |
120 | .def = "8", | |
121 | .category = FIO_OPT_C_PROFILE, | |
122 | .group = FIO_OPT_G_ACT, | |
123 | }, | |
124 | { | |
125 | .name = "read-req-num-512-blocks", | |
4870138d | 126 | .lname = "Number of 512B blocks to read", |
00f81c37 | 127 | .type = FIO_OPT_INT, |
7b504edd | 128 | .off1 = offsetof(struct act_options, num_read_blocks), |
4870138d | 129 | .help = "Number of 512B blocks to read at the time", |
00f81c37 JA |
130 | .def = "3", |
131 | .category = FIO_OPT_C_PROFILE, | |
132 | .group = FIO_OPT_G_ACT, | |
133 | }, | |
134 | { | |
135 | .name = "large-block-op-kbytes", | |
4870138d | 136 | .lname = "Size of large block ops in KiB (writes)", |
00f81c37 | 137 | .type = FIO_OPT_INT, |
7b504edd | 138 | .off1 = offsetof(struct act_options, write_size), |
4870138d | 139 | .help = "Size of large block ops in KiB (writes)", |
2b9136a3 | 140 | .def = "131072", |
00f81c37 JA |
141 | .category = FIO_OPT_C_PROFILE, |
142 | .group = FIO_OPT_G_ACT, | |
143 | }, | |
144 | { | |
145 | .name = "prep", | |
146 | .lname = "Run ACT prep phase", | |
147 | .type = FIO_OPT_STR_SET, | |
7b504edd | 148 | .off1 = offsetof(struct act_options, prep), |
00f81c37 | 149 | .help = "Set to run ACT prep phase", |
d4afedfd JA |
150 | .category = FIO_OPT_C_PROFILE, |
151 | .group = FIO_OPT_G_ACT, | |
152 | }, | |
153 | { | |
154 | .name = NULL, | |
155 | }, | |
156 | }; | |
157 | ||
00f81c37 | 158 | static int act_add_opt(const char *str, ...) |
d4afedfd JA |
159 | { |
160 | char buffer[512]; | |
161 | va_list args; | |
162 | size_t len; | |
163 | ||
00f81c37 JA |
164 | if (opt_idx == ACT_MAX_OPTS) { |
165 | log_err("act: ACT_MAX_OPTS is too small\n"); | |
166 | return 1; | |
167 | } | |
168 | ||
d4afedfd JA |
169 | va_start(args, str); |
170 | len = vsnprintf(buffer, sizeof(buffer), str, args); | |
171 | va_end(args); | |
172 | ||
173 | if (len) | |
174 | act_opts[opt_idx++] = strdup(buffer); | |
00f81c37 JA |
175 | |
176 | return 0; | |
177 | } | |
178 | ||
179 | static int act_add_rw(const char *dev, int reads) | |
180 | { | |
dae887f3 JA |
181 | struct act_options *ao = &act_options; |
182 | ||
00f81c37 JA |
183 | if (act_add_opt("name=act-%s-%s", reads ? "read" : "write", dev)) |
184 | return 1; | |
185 | if (act_add_opt("filename=%s", dev)) | |
186 | return 1; | |
187 | if (act_add_opt("rw=%s", reads ? "randread" : "randwrite")) | |
188 | return 1; | |
189 | if (reads) { | |
dae887f3 | 190 | int rload = ao->load * R_LOAD / ao->threads_per_queue; |
00f81c37 | 191 | |
dae887f3 | 192 | if (act_add_opt("numjobs=%u", ao->threads_per_queue)) |
00f81c37 JA |
193 | return 1; |
194 | if (act_add_opt("rate_iops=%u", rload)) | |
195 | return 1; | |
dae887f3 | 196 | if (act_add_opt("bs=%u", ao->num_read_blocks * 512)) |
00f81c37 JA |
197 | return 1; |
198 | } else { | |
dae887f3 JA |
199 | const int rsize = ao->write_size / (ao->num_read_blocks * 512); |
200 | int wload = (ao->load * W_LOAD + rsize - 1) / rsize; | |
00f81c37 JA |
201 | |
202 | if (act_add_opt("rate_iops=%u", wload)) | |
203 | return 1; | |
dae887f3 | 204 | if (act_add_opt("bs=%u", ao->write_size)) |
00f81c37 JA |
205 | return 1; |
206 | } | |
207 | ||
208 | return 0; | |
209 | } | |
210 | ||
211 | static int act_add_dev_prep(const char *dev) | |
212 | { | |
213 | /* Add sequential zero phase */ | |
214 | if (act_add_opt("name=act-prep-zeroes-%s", dev)) | |
215 | return 1; | |
216 | if (act_add_opt("filename=%s", dev)) | |
217 | return 1; | |
2b9136a3 | 218 | if (act_add_opt("bs=1048576")) |
00f81c37 JA |
219 | return 1; |
220 | if (act_add_opt("zero_buffers")) | |
221 | return 1; | |
222 | if (act_add_opt("rw=write")) | |
223 | return 1; | |
224 | ||
225 | /* Randomly overwrite device */ | |
226 | if (act_add_opt("name=act-prep-salt-%s", dev)) | |
227 | return 1; | |
228 | if (act_add_opt("stonewall")) | |
229 | return 1; | |
230 | if (act_add_opt("filename=%s", dev)) | |
231 | return 1; | |
2b9136a3 | 232 | if (act_add_opt("bs=4096")) |
00f81c37 JA |
233 | return 1; |
234 | if (act_add_opt("ioengine=libaio")) | |
235 | return 1; | |
236 | if (act_add_opt("iodepth=64")) | |
237 | return 1; | |
238 | if (act_add_opt("rw=randwrite")) | |
239 | return 1; | |
240 | ||
241 | return 0; | |
d4afedfd JA |
242 | } |
243 | ||
00f81c37 | 244 | static int act_add_dev(const char *dev) |
d4afedfd | 245 | { |
dae887f3 | 246 | if (act_options.prep) |
00f81c37 JA |
247 | return act_add_dev_prep(dev); |
248 | ||
dae887f3 | 249 | if (act_add_opt("runtime=%llus", act_options.test_duration)) |
00f81c37 JA |
250 | return 1; |
251 | if (act_add_opt("time_based=1")) | |
252 | return 1; | |
253 | ||
254 | if (act_add_rw(dev, 1)) | |
255 | return 1; | |
256 | if (act_add_rw(dev, 0)) | |
257 | return 1; | |
258 | ||
259 | return 0; | |
d4afedfd JA |
260 | } |
261 | ||
262 | /* | |
263 | * Fill our private options into the command line | |
264 | */ | |
265 | static int act_prep_cmdline(void) | |
266 | { | |
dae887f3 | 267 | if (!act_options.device_names) { |
90777558 JA |
268 | log_err("act: you need to set IO target(s) with the " |
269 | "device-names option.\n"); | |
d4afedfd JA |
270 | return 1; |
271 | } | |
272 | ||
273 | org_idx = opt_idx; | |
d4afedfd JA |
274 | |
275 | do { | |
276 | char *dev; | |
277 | ||
dae887f3 | 278 | dev = strsep(&act_options.device_names, ","); |
d4afedfd JA |
279 | if (!dev) |
280 | break; | |
281 | ||
00f81c37 JA |
282 | if (act_add_dev(dev)) { |
283 | log_err("act: failed adding device to the mix\n"); | |
284 | break; | |
285 | } | |
d4afedfd JA |
286 | } while (1); |
287 | ||
288 | return 0; | |
289 | } | |
290 | ||
c3a32714 | 291 | static int act_io_u_lat(struct thread_data *td, uint64_t nsec) |
d4afedfd JA |
292 | { |
293 | struct act_prof_data *apd = td->prof_data; | |
90777558 | 294 | struct act_slice *slice; |
c3a32714 | 295 | uint64_t usec = nsec / 1000ULL; |
d4afedfd JA |
296 | int i, ret = 0; |
297 | double perm; | |
298 | ||
dae887f3 | 299 | if (act_options.prep) |
00f81c37 JA |
300 | return 0; |
301 | ||
90777558 JA |
302 | /* |
303 | * Really should not happen, but lets not let jitter at the end | |
304 | * ruin our day. | |
305 | */ | |
306 | if (apd->cur_slice >= apd->nr_slices) | |
307 | return 0; | |
308 | ||
309 | slice = &apd->slices[apd->cur_slice]; | |
310 | slice->total_ios++; | |
d4afedfd | 311 | |
78a6aad7 JA |
312 | for (i = ACT_MAX_CRIT - 1; i >= 0; i--) { |
313 | if (usec > act_pass[i].max_usec) { | |
90777558 | 314 | slice->lat_buckets[i]++; |
d4afedfd JA |
315 | break; |
316 | } | |
317 | } | |
318 | ||
d4afedfd JA |
319 | if (time_since_now(&apd->sample_tv) < SAMPLE_SEC) |
320 | return 0; | |
321 | ||
322 | /* SAMPLE_SEC has passed, check criteria for pass */ | |
323 | for (i = 0; i < ACT_MAX_CRIT; i++) { | |
90777558 | 324 | perm = (1000.0 * slice->lat_buckets[i]) / slice->total_ios; |
78a6aad7 | 325 | if (perm < act_pass[i].max_perm) |
d4afedfd JA |
326 | continue; |
327 | ||
328 | log_err("act: %f%% exceeds pass criteria of %f%%\n", perm / 10.0, (double) act_pass[i].max_perm / 10.0); | |
329 | ret = 1; | |
330 | break; | |
331 | } | |
332 | ||
333 | fio_gettime(&apd->sample_tv, NULL); | |
90777558 | 334 | apd->cur_slice++; |
d4afedfd JA |
335 | return ret; |
336 | } | |
337 | ||
4a88752a JA |
338 | static void get_act_ref(void) |
339 | { | |
340 | fio_mutex_down(act_run_data->mutex); | |
341 | act_run_data->pending++; | |
342 | fio_mutex_up(act_run_data->mutex); | |
343 | } | |
344 | ||
90777558 | 345 | static int show_slice(struct act_slice *slice, unsigned int slice_num) |
4a88752a | 346 | { |
90777558 | 347 | unsigned int i, failed = 0; |
4a88752a | 348 | |
90777558 | 349 | log_info(" %2u", slice_num); |
4a88752a JA |
350 | |
351 | for (i = 0; i < ACT_MAX_CRIT; i++) { | |
90777558 | 352 | double perc = 0.0; |
4a88752a | 353 | |
90777558 JA |
354 | if (slice->total_ios) |
355 | perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios; | |
356 | if ((perc * 10.0) >= act_pass[i].max_perm) | |
357 | failed++; | |
4a88752a JA |
358 | log_info("\t%2.2f", perc); |
359 | } | |
360 | for (i = 0; i < ACT_MAX_CRIT; i++) { | |
90777558 | 361 | double perc = 0.0; |
4a88752a | 362 | |
90777558 JA |
363 | if (slice->total_ios) |
364 | perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios; | |
4a88752a JA |
365 | log_info("\t%2.2f", perc); |
366 | } | |
90777558 JA |
367 | log_info("\n"); |
368 | ||
369 | return failed; | |
370 | } | |
371 | ||
372 | static void act_show_all_stats(void) | |
373 | { | |
374 | unsigned int i, fails = 0; | |
375 | ||
376 | log_info(" trans device\n"); | |
377 | log_info(" %%>(ms) %%>(ms)\n"); | |
378 | log_info(" slice"); | |
379 | ||
380 | for (i = 0; i < ACT_MAX_CRIT; i++) | |
381 | log_info("\t %2u", act_pass[i].max_usec / 1000); | |
382 | for (i = 0; i < ACT_MAX_CRIT; i++) | |
383 | log_info("\t %2u", act_pass[i].max_usec / 1000); | |
384 | ||
385 | log_info("\n"); | |
386 | log_info(" ----- ----- ----- ------ ----- ----- ------\n"); | |
387 | ||
388 | for (i = 0; i < act_run_data->nr_slices; i++) | |
389 | fails += show_slice(&act_run_data->slices[i], i + 1); | |
4a88752a | 390 | |
90777558 | 391 | log_info("\nact: test complete, device(s): %s\n", fails ? "FAILED" : "PASSED"); |
4a88752a JA |
392 | } |
393 | ||
394 | static void put_act_ref(struct thread_data *td) | |
395 | { | |
396 | struct act_prof_data *apd = td->prof_data; | |
90777558 | 397 | unsigned int i, slice; |
4a88752a JA |
398 | |
399 | fio_mutex_down(act_run_data->mutex); | |
400 | ||
90777558 | 401 | if (!act_run_data->slices) { |
572cfb3f | 402 | act_run_data->slices = calloc(apd->nr_slices, sizeof(struct act_slice)); |
90777558 | 403 | act_run_data->nr_slices = apd->nr_slices; |
4a88752a JA |
404 | } |
405 | ||
90777558 JA |
406 | for (slice = 0; slice < apd->nr_slices; slice++) { |
407 | struct act_slice *dst = &act_run_data->slices[slice]; | |
408 | struct act_slice *src = &apd->slices[slice]; | |
409 | ||
410 | dst->total_ios += src->total_ios; | |
411 | ||
412 | for (i = 0; i < ACT_MAX_CRIT; i++) | |
413 | dst->lat_buckets[i] += src->lat_buckets[i]; | |
414 | } | |
4a88752a JA |
415 | |
416 | if (!--act_run_data->pending) | |
417 | act_show_all_stats(); | |
418 | ||
419 | fio_mutex_up(act_run_data->mutex); | |
420 | } | |
421 | ||
d4afedfd JA |
422 | static int act_td_init(struct thread_data *td) |
423 | { | |
424 | struct act_prof_data *apd; | |
90777558 | 425 | unsigned int nr_slices; |
d4afedfd | 426 | |
4a88752a JA |
427 | get_act_ref(); |
428 | ||
572cfb3f | 429 | apd = calloc(1, sizeof(*apd)); |
dae887f3 | 430 | nr_slices = (act_options.test_duration + SAMPLE_SEC - 1) / SAMPLE_SEC; |
572cfb3f | 431 | apd->slices = calloc(nr_slices, sizeof(struct act_slice)); |
90777558 | 432 | apd->nr_slices = nr_slices; |
d4afedfd JA |
433 | fio_gettime(&apd->sample_tv, NULL); |
434 | td->prof_data = apd; | |
435 | return 0; | |
436 | } | |
437 | ||
438 | static void act_td_exit(struct thread_data *td) | |
439 | { | |
90777558 JA |
440 | struct act_prof_data *apd = td->prof_data; |
441 | ||
4a88752a | 442 | put_act_ref(td); |
90777558 JA |
443 | free(apd->slices); |
444 | free(apd); | |
d4afedfd JA |
445 | td->prof_data = NULL; |
446 | } | |
447 | ||
448 | static struct prof_io_ops act_io_ops = { | |
449 | .td_init = act_td_init, | |
450 | .td_exit = act_td_exit, | |
451 | .io_u_lat = act_io_u_lat, | |
452 | }; | |
453 | ||
454 | static struct profile_ops act_profile = { | |
455 | .name = "act", | |
456 | .desc = "ACT Aerospike like benchmark", | |
457 | .options = options, | |
7b504edd | 458 | .opt_data = &act_options, |
d4afedfd JA |
459 | .prep_cmd = act_prep_cmdline, |
460 | .cmdline = act_opts, | |
461 | .io_ops = &act_io_ops, | |
462 | }; | |
463 | ||
464 | static void fio_init act_register(void) | |
465 | { | |
572cfb3f | 466 | act_run_data = calloc(1, sizeof(*act_run_data)); |
4a88752a JA |
467 | act_run_data->mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED); |
468 | ||
d4afedfd JA |
469 | if (register_profile(&act_profile)) |
470 | log_err("fio: failed to register profile 'act'\n"); | |
471 | } | |
472 | ||
473 | static void fio_exit act_unregister(void) | |
474 | { | |
475 | while (org_idx && org_idx < opt_idx) | |
476 | free((void *) act_opts[++org_idx]); | |
477 | ||
478 | unregister_profile(&act_profile); | |
4a88752a | 479 | fio_mutex_remove(act_run_data->mutex); |
90777558 | 480 | free(act_run_data->slices); |
4a88752a JA |
481 | free(act_run_data); |
482 | act_run_data = NULL; | |
d4afedfd | 483 | } |