2 #include "../profile.h"
4 #include "../optgroup.h"
12 #define SAMPLE_SEC 3600 /* 1h checks */
14 struct act_pass_criteria {
15 unsigned int max_usec;
16 unsigned int max_perm;
18 #define ACT_MAX_CRIT 3
20 static struct act_pass_criteria act_pass[ACT_MAX_CRIT] = {
36 uint64_t lat_buckets[ACT_MAX_CRIT];
41 struct fio_mutex *mutex;
44 struct act_slice *slices;
45 unsigned int nr_slices;
47 static struct act_run_data *act_run_data;
49 struct act_prof_data {
50 struct timeval sample_tv;
51 struct act_slice *slices;
52 unsigned int cur_slice;
53 unsigned int nr_slices;
56 static char *device_names;
57 static unsigned int load;
58 static unsigned int prep;
59 static unsigned int threads_per_queue;
60 static unsigned int num_read_blocks;
61 static unsigned int write_size;
62 static unsigned long long test_duration;
64 #define ACT_MAX_OPTS 128
65 static const char *act_opts[ACT_MAX_OPTS] = {
68 "random_generator=lfsr",
73 static unsigned int opt_idx = 5;
74 static unsigned int org_idx;
76 static int act_add_opt(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
83 unsigned int threads_per_queue;
84 unsigned int num_read_blocks;
85 unsigned int write_size;
86 unsigned long long test_duration;
89 static struct act_options act_options;
91 static struct fio_option options[] = {
93 .name = "device-names",
94 .lname = "device-names",
95 .type = FIO_OPT_STR_STORE,
96 .off1 = offsetof(struct act_options, device_names),
97 .help = "Devices to use",
98 .category = FIO_OPT_C_PROFILE,
99 .group = FIO_OPT_G_ACT,
103 .lname = "Load multiplier",
105 .off1 = offsetof(struct act_options, load),
106 .help = "ACT load multipler (default 1x)",
108 .category = FIO_OPT_C_PROFILE,
109 .group = FIO_OPT_G_ACT,
112 .name = "test-duration",
113 .lname = "Test duration",
114 .type = FIO_OPT_STR_VAL_TIME,
115 .off1 = offsetof(struct act_options, test_duration),
116 .help = "How long the entire test takes to run",
118 .category = FIO_OPT_C_PROFILE,
119 .group = FIO_OPT_G_ACT,
122 .name = "threads-per-queue",
123 .lname = "Number of read IO threads per device",
125 .off1 = offsetof(struct act_options, threads_per_queue),
126 .help = "Number of read IO threads per device",
128 .category = FIO_OPT_C_PROFILE,
129 .group = FIO_OPT_G_ACT,
132 .name = "read-req-num-512-blocks",
133 .lname = "Number of 512b blocks to read",
135 .off1 = offsetof(struct act_options, num_read_blocks),
136 .help = "Number of 512b blocks to read at the time",
138 .category = FIO_OPT_C_PROFILE,
139 .group = FIO_OPT_G_ACT,
142 .name = "large-block-op-kbytes",
143 .lname = "Size of large block ops (writes)",
145 .off1 = offsetof(struct act_options, write_size),
146 .help = "Size of large block ops (writes)",
148 .category = FIO_OPT_C_PROFILE,
149 .group = FIO_OPT_G_ACT,
153 .lname = "Run ACT prep phase",
154 .type = FIO_OPT_STR_SET,
155 .off1 = offsetof(struct act_options, prep),
156 .help = "Set to run ACT prep phase",
157 .category = FIO_OPT_C_PROFILE,
158 .group = FIO_OPT_G_ACT,
165 static int act_add_opt(const char *str, ...)
171 if (opt_idx == ACT_MAX_OPTS) {
172 log_err("act: ACT_MAX_OPTS is too small\n");
177 len = vsnprintf(buffer, sizeof(buffer), str, args);
181 act_opts[opt_idx++] = strdup(buffer);
186 static int act_add_rw(const char *dev, int reads)
188 if (act_add_opt("name=act-%s-%s", reads ? "read" : "write", dev))
190 if (act_add_opt("filename=%s", dev))
192 if (act_add_opt("rw=%s", reads ? "randread" : "randwrite"))
195 int rload = load * R_LOAD / threads_per_queue;
197 if (act_add_opt("numjobs=%u", threads_per_queue))
199 if (act_add_opt("rate_iops=%u", rload))
201 if (act_add_opt("bs=%u", num_read_blocks * 512))
204 const int rsize = write_size / (num_read_blocks * 512);
205 int wload = (load * W_LOAD + rsize - 1) / rsize;
207 if (act_add_opt("rate_iops=%u", wload))
209 if (act_add_opt("bs=%u", write_size))
216 static int act_add_dev_prep(const char *dev)
218 /* Add sequential zero phase */
219 if (act_add_opt("name=act-prep-zeroes-%s", dev))
221 if (act_add_opt("filename=%s", dev))
223 if (act_add_opt("bs=1M"))
225 if (act_add_opt("zero_buffers"))
227 if (act_add_opt("rw=write"))
230 /* Randomly overwrite device */
231 if (act_add_opt("name=act-prep-salt-%s", dev))
233 if (act_add_opt("stonewall"))
235 if (act_add_opt("filename=%s", dev))
237 if (act_add_opt("bs=4k"))
239 if (act_add_opt("ioengine=libaio"))
241 if (act_add_opt("iodepth=64"))
243 if (act_add_opt("rw=randwrite"))
249 static int act_add_dev(const char *dev)
252 return act_add_dev_prep(dev);
254 if (act_add_opt("runtime=%llus", test_duration))
256 if (act_add_opt("time_based=1"))
259 if (act_add_rw(dev, 1))
261 if (act_add_rw(dev, 0))
268 * Fill our private options into the command line
270 static int act_prep_cmdline(void)
273 log_err("act: you need to set IO target(s) with the "
274 "device-names option.\n");
283 dev = strsep(&device_names, ",");
287 if (act_add_dev(dev)) {
288 log_err("act: failed adding device to the mix\n");
296 static int act_io_u_lat(struct thread_data *td, uint64_t usec)
298 struct act_prof_data *apd = td->prof_data;
299 struct act_slice *slice;
307 * Really should not happen, but lets not let jitter at the end
310 if (apd->cur_slice >= apd->nr_slices)
313 slice = &apd->slices[apd->cur_slice];
316 for (i = ACT_MAX_CRIT - 1; i >= 0; i--) {
317 if (usec > act_pass[i].max_usec) {
318 slice->lat_buckets[i]++;
323 if (time_since_now(&apd->sample_tv) < SAMPLE_SEC)
326 /* SAMPLE_SEC has passed, check criteria for pass */
327 for (i = 0; i < ACT_MAX_CRIT; i++) {
328 perm = (1000.0 * slice->lat_buckets[i]) / slice->total_ios;
329 if (perm < act_pass[i].max_perm)
332 log_err("act: %f%% exceeds pass criteria of %f%%\n", perm / 10.0, (double) act_pass[i].max_perm / 10.0);
337 fio_gettime(&apd->sample_tv, NULL);
342 static void get_act_ref(void)
344 fio_mutex_down(act_run_data->mutex);
345 act_run_data->pending++;
346 fio_mutex_up(act_run_data->mutex);
349 static int show_slice(struct act_slice *slice, unsigned int slice_num)
351 unsigned int i, failed = 0;
353 log_info(" %2u", slice_num);
355 for (i = 0; i < ACT_MAX_CRIT; i++) {
358 if (slice->total_ios)
359 perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios;
360 if ((perc * 10.0) >= act_pass[i].max_perm)
362 log_info("\t%2.2f", perc);
364 for (i = 0; i < ACT_MAX_CRIT; i++) {
367 if (slice->total_ios)
368 perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios;
369 log_info("\t%2.2f", perc);
376 static void act_show_all_stats(void)
378 unsigned int i, fails = 0;
380 log_info(" trans device\n");
381 log_info(" %%>(ms) %%>(ms)\n");
384 for (i = 0; i < ACT_MAX_CRIT; i++)
385 log_info("\t %2u", act_pass[i].max_usec / 1000);
386 for (i = 0; i < ACT_MAX_CRIT; i++)
387 log_info("\t %2u", act_pass[i].max_usec / 1000);
390 log_info(" ----- ----- ----- ------ ----- ----- ------\n");
392 for (i = 0; i < act_run_data->nr_slices; i++)
393 fails += show_slice(&act_run_data->slices[i], i + 1);
395 log_info("\nact: test complete, device(s): %s\n", fails ? "FAILED" : "PASSED");
398 static void put_act_ref(struct thread_data *td)
400 struct act_prof_data *apd = td->prof_data;
401 unsigned int i, slice;
403 fio_mutex_down(act_run_data->mutex);
405 if (!act_run_data->slices) {
406 act_run_data->slices = calloc(apd->nr_slices, sizeof(struct act_slice));
407 act_run_data->nr_slices = apd->nr_slices;
410 for (slice = 0; slice < apd->nr_slices; slice++) {
411 struct act_slice *dst = &act_run_data->slices[slice];
412 struct act_slice *src = &apd->slices[slice];
414 dst->total_ios += src->total_ios;
416 for (i = 0; i < ACT_MAX_CRIT; i++)
417 dst->lat_buckets[i] += src->lat_buckets[i];
420 if (!--act_run_data->pending)
421 act_show_all_stats();
423 fio_mutex_up(act_run_data->mutex);
426 static int act_td_init(struct thread_data *td)
428 struct act_prof_data *apd;
429 unsigned int nr_slices;
433 apd = calloc(1, sizeof(*apd));
434 nr_slices = (test_duration + SAMPLE_SEC - 1) / SAMPLE_SEC;
435 apd->slices = calloc(nr_slices, sizeof(struct act_slice));
436 apd->nr_slices = nr_slices;
437 fio_gettime(&apd->sample_tv, NULL);
442 static void act_td_exit(struct thread_data *td)
444 struct act_prof_data *apd = td->prof_data;
449 td->prof_data = NULL;
452 static struct prof_io_ops act_io_ops = {
453 .td_init = act_td_init,
454 .td_exit = act_td_exit,
455 .io_u_lat = act_io_u_lat,
458 static struct profile_ops act_profile = {
460 .desc = "ACT Aerospike like benchmark",
462 .opt_data = &act_options,
463 .prep_cmd = act_prep_cmdline,
465 .io_ops = &act_io_ops,
468 static void fio_init act_register(void)
470 act_run_data = calloc(1, sizeof(*act_run_data));
471 act_run_data->mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED);
473 if (register_profile(&act_profile))
474 log_err("fio: failed to register profile 'act'\n");
477 static void fio_exit act_unregister(void)
479 while (org_idx && org_idx < opt_idx)
480 free((void *) act_opts[++org_idx]);
482 unregister_profile(&act_profile);
483 fio_mutex_remove(act_run_data->mutex);
484 free(act_run_data->slices);