Commit | Line | Data |
---|---|---|
d4afedfd JA |
1 | #include "../fio.h" |
2 | #include "../profile.h" | |
3 | #include "../parse.h" | |
4 | ||
00f81c37 JA |
5 | /* |
6 | * 1x loads | |
7 | */ | |
d4afedfd JA |
8 | #define R_LOAD 2000 |
9 | #define W_LOAD 1000 | |
10 | ||
11 | #define SAMPLE_SEC 3600 /* 1h checks */ | |
12 | ||
13 | struct act_pass_criteria { | |
14 | unsigned int max_usec; | |
15 | unsigned int max_perm; | |
16 | }; | |
17 | #define ACT_MAX_CRIT 3 | |
18 | ||
19 | static struct act_pass_criteria act_pass[ACT_MAX_CRIT] = { | |
20 | { | |
21 | .max_usec = 1000, | |
22 | .max_perm = 50, | |
23 | }, | |
24 | { | |
78a6aad7 | 25 | .max_usec = 8000, |
d4afedfd JA |
26 | .max_perm = 10, |
27 | }, | |
28 | { | |
29 | .max_usec = 64000, | |
30 | .max_perm = 1, | |
31 | }, | |
32 | }; | |
33 | ||
90777558 JA |
34 | struct act_slice { |
35 | uint64_t lat_buckets[ACT_MAX_CRIT]; | |
36 | uint64_t total_ios; | |
37 | }; | |
38 | ||
4a88752a JA |
39 | struct act_run_data { |
40 | struct fio_mutex *mutex; | |
41 | unsigned int pending; | |
42 | ||
90777558 JA |
43 | struct act_slice *slices; |
44 | unsigned int nr_slices; | |
4a88752a JA |
45 | }; |
46 | static struct act_run_data *act_run_data; | |
47 | ||
d4afedfd JA |
48 | struct act_prof_data { |
49 | struct timeval sample_tv; | |
90777558 JA |
50 | struct act_slice *slices; |
51 | unsigned int cur_slice; | |
52 | unsigned int nr_slices; | |
d4afedfd JA |
53 | }; |
54 | ||
55 | static char *device_names; | |
90777558 | 56 | static unsigned int load; |
00f81c37 JA |
57 | static unsigned int prep; |
58 | static unsigned int threads_per_queue; | |
59 | static unsigned int num_read_blocks; | |
60 | static unsigned int write_size; | |
90777558 | 61 | static unsigned long long test_duration; |
d4afedfd | 62 | |
00f81c37 JA |
63 | #define ACT_MAX_OPTS 128 |
64 | static const char *act_opts[ACT_MAX_OPTS] = { | |
d4afedfd | 65 | "direct=1", |
00f81c37 | 66 | "ioengine=sync", |
d4afedfd | 67 | "random_generator=lfsr", |
00f81c37 | 68 | "group_reporting=1", |
4a88752a | 69 | "thread", |
d4afedfd JA |
70 | NULL, |
71 | }; | |
4a88752a | 72 | static unsigned int opt_idx = 5; |
d4afedfd JA |
73 | static unsigned int org_idx; |
74 | ||
00f81c37 | 75 | static int act_add_opt(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2))); |
d4afedfd JA |
76 | |
77 | static 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)", | |
00f81c37 JA |
93 | .def = "1", |
94 | .category = FIO_OPT_C_PROFILE, | |
95 | .group = FIO_OPT_G_ACT, | |
96 | }, | |
90777558 JA |
97 | { |
98 | .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 | }, | |
00f81c37 JA |
107 | { |
108 | .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", | |
d4afedfd JA |
143 | .category = FIO_OPT_C_PROFILE, |
144 | .group = FIO_OPT_G_ACT, | |
145 | }, | |
146 | { | |
147 | .name = NULL, | |
148 | }, | |
149 | }; | |
150 | ||
00f81c37 | 151 | static int act_add_opt(const char *str, ...) |
d4afedfd JA |
152 | { |
153 | char buffer[512]; | |
154 | va_list args; | |
155 | size_t len; | |
156 | ||
00f81c37 JA |
157 | if (opt_idx == ACT_MAX_OPTS) { |
158 | log_err("act: ACT_MAX_OPTS is too small\n"); | |
159 | return 1; | |
160 | } | |
161 | ||
d4afedfd JA |
162 | 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); | |
00f81c37 JA |
168 | |
169 | return 0; | |
170 | } | |
171 | ||
172 | static int act_add_rw(const char *dev, int reads) | |
173 | { | |
174 | 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; | |
182 | ||
183 | 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 | ||
202 | static 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; | |
d4afedfd JA |
233 | } |
234 | ||
00f81c37 | 235 | static int act_add_dev(const char *dev) |
d4afedfd | 236 | { |
00f81c37 JA |
237 | if (prep) |
238 | return act_add_dev_prep(dev); | |
239 | ||
90777558 | 240 | if (act_add_opt("runtime=%llus", test_duration)) |
00f81c37 JA |
241 | 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; | |
d4afedfd JA |
251 | } |
252 | ||
253 | /* | |
254 | * Fill our private options into the command line | |
255 | */ | |
256 | static int act_prep_cmdline(void) | |
257 | { | |
258 | if (!device_names) { | |
90777558 JA |
259 | log_err("act: you need to set IO target(s) with the " |
260 | "device-names option.\n"); | |
d4afedfd JA |
261 | return 1; |
262 | } | |
263 | ||
264 | org_idx = opt_idx; | |
d4afedfd JA |
265 | |
266 | do { | |
267 | char *dev; | |
268 | ||
269 | dev = strsep(&device_names, ","); | |
270 | if (!dev) | |
271 | break; | |
272 | ||
00f81c37 JA |
273 | if (act_add_dev(dev)) { |
274 | log_err("act: failed adding device to the mix\n"); | |
275 | break; | |
276 | } | |
d4afedfd JA |
277 | } while (1); |
278 | ||
279 | return 0; | |
280 | } | |
281 | ||
282 | static int act_io_u_lat(struct thread_data *td, uint64_t usec) | |
283 | { | |
284 | struct act_prof_data *apd = td->prof_data; | |
90777558 | 285 | struct act_slice *slice; |
d4afedfd JA |
286 | int i, ret = 0; |
287 | double perm; | |
288 | ||
00f81c37 JA |
289 | if (prep) |
290 | return 0; | |
291 | ||
90777558 JA |
292 | /* |
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++; | |
d4afedfd | 301 | |
78a6aad7 JA |
302 | for (i = ACT_MAX_CRIT - 1; i >= 0; i--) { |
303 | if (usec > act_pass[i].max_usec) { | |
90777558 | 304 | slice->lat_buckets[i]++; |
d4afedfd JA |
305 | break; |
306 | } | |
307 | } | |
308 | ||
d4afedfd JA |
309 | 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++) { | |
90777558 | 314 | perm = (1000.0 * slice->lat_buckets[i]) / slice->total_ios; |
78a6aad7 | 315 | if (perm < act_pass[i].max_perm) |
d4afedfd JA |
316 | 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 | ||
323 | fio_gettime(&apd->sample_tv, NULL); | |
90777558 | 324 | apd->cur_slice++; |
d4afedfd JA |
325 | return ret; |
326 | } | |
327 | ||
4a88752a JA |
328 | static 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 | ||
90777558 | 335 | static int show_slice(struct act_slice *slice, unsigned int slice_num) |
4a88752a | 336 | { |
90777558 | 337 | unsigned int i, failed = 0; |
4a88752a | 338 | |
90777558 | 339 | log_info(" %2u", slice_num); |
4a88752a JA |
340 | |
341 | for (i = 0; i < ACT_MAX_CRIT; i++) { | |
90777558 | 342 | double perc = 0.0; |
4a88752a | 343 | |
90777558 JA |
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++; | |
4a88752a JA |
348 | log_info("\t%2.2f", perc); |
349 | } | |
350 | for (i = 0; i < ACT_MAX_CRIT; i++) { | |
90777558 | 351 | double perc = 0.0; |
4a88752a | 352 | |
90777558 JA |
353 | if (slice->total_ios) |
354 | perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios; | |
4a88752a JA |
355 | log_info("\t%2.2f", perc); |
356 | } | |
90777558 JA |
357 | log_info("\n"); |
358 | ||
359 | return failed; | |
360 | } | |
361 | ||
362 | static void act_show_all_stats(void) | |
363 | { | |
364 | unsigned int i, fails = 0; | |
365 | ||
366 | log_info(" trans device\n"); | |
367 | log_info(" %%>(ms) %%>(ms)\n"); | |
368 | log_info(" slice"); | |
369 | ||
370 | for (i = 0; i < ACT_MAX_CRIT; i++) | |
371 | log_info("\t %2u", act_pass[i].max_usec / 1000); | |
372 | for (i = 0; i < ACT_MAX_CRIT; i++) | |
373 | log_info("\t %2u", act_pass[i].max_usec / 1000); | |
374 | ||
375 | log_info("\n"); | |
376 | log_info(" ----- ----- ----- ------ ----- ----- ------\n"); | |
377 | ||
378 | for (i = 0; i < act_run_data->nr_slices; i++) | |
379 | fails += show_slice(&act_run_data->slices[i], i + 1); | |
4a88752a | 380 | |
90777558 | 381 | log_info("\nact: test complete, device(s): %s\n", fails ? "FAILED" : "PASSED"); |
4a88752a JA |
382 | } |
383 | ||
384 | static void put_act_ref(struct thread_data *td) | |
385 | { | |
386 | struct act_prof_data *apd = td->prof_data; | |
90777558 | 387 | unsigned int i, slice; |
4a88752a JA |
388 | |
389 | fio_mutex_down(act_run_data->mutex); | |
390 | ||
90777558 JA |
391 | 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; | |
4a88752a JA |
394 | } |
395 | ||
90777558 JA |
396 | 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 | } | |
4a88752a JA |
405 | |
406 | if (!--act_run_data->pending) | |
407 | act_show_all_stats(); | |
408 | ||
409 | fio_mutex_up(act_run_data->mutex); | |
410 | } | |
411 | ||
d4afedfd JA |
412 | static int act_td_init(struct thread_data *td) |
413 | { | |
414 | struct act_prof_data *apd; | |
90777558 | 415 | unsigned int nr_slices; |
d4afedfd | 416 | |
4a88752a JA |
417 | get_act_ref(); |
418 | ||
d4afedfd | 419 | apd = calloc(sizeof(*apd), 1); |
90777558 JA |
420 | 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; | |
d4afedfd JA |
423 | fio_gettime(&apd->sample_tv, NULL); |
424 | td->prof_data = apd; | |
425 | return 0; | |
426 | } | |
427 | ||
428 | static void act_td_exit(struct thread_data *td) | |
429 | { | |
90777558 JA |
430 | struct act_prof_data *apd = td->prof_data; |
431 | ||
4a88752a | 432 | put_act_ref(td); |
90777558 JA |
433 | free(apd->slices); |
434 | free(apd); | |
d4afedfd JA |
435 | td->prof_data = NULL; |
436 | } | |
437 | ||
438 | static 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 | ||
444 | static 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 | ||
453 | static void fio_init act_register(void) | |
454 | { | |
4a88752a JA |
455 | act_run_data = calloc(sizeof(*act_run_data), 1); |
456 | act_run_data->mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED); | |
457 | ||
d4afedfd JA |
458 | if (register_profile(&act_profile)) |
459 | log_err("fio: failed to register profile 'act'\n"); | |
460 | } | |
461 | ||
462 | static 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); | |
4a88752a | 468 | fio_mutex_remove(act_run_data->mutex); |
90777558 | 469 | free(act_run_data->slices); |
4a88752a JA |
470 | free(act_run_data); |
471 | act_run_data = NULL; | |
d4afedfd | 472 | } |