2 #include "../profile.h"
11 #define SAMPLE_SEC 3600 /* 1h checks */
13 struct act_pass_criteria {
14 unsigned int max_usec;
15 unsigned int max_perm;
17 #define ACT_MAX_CRIT 3
19 static struct act_pass_criteria act_pass[ACT_MAX_CRIT] = {
35 uint64_t lat_buckets[ACT_MAX_CRIT];
40 struct fio_mutex *mutex;
43 struct act_slice *slices;
44 unsigned int nr_slices;
46 static struct act_run_data *act_run_data;
48 struct act_prof_data {
49 struct timeval sample_tv;
50 struct act_slice *slices;
51 unsigned int cur_slice;
52 unsigned int nr_slices;
55 static char *device_names;
56 static unsigned int load;
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;
61 static unsigned long long test_duration;
63 #define ACT_MAX_OPTS 128
64 static const char *act_opts[ACT_MAX_OPTS] = {
67 "random_generator=lfsr",
72 static unsigned int opt_idx = 5;
73 static unsigned int org_idx;
75 static int act_add_opt(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
82 unsigned int threads_per_queue;
83 unsigned int num_read_blocks;
84 unsigned int write_size;
85 unsigned long long test_duration;
88 static struct act_options act_options;
90 static struct fio_option options[] = {
92 .name = "device-names",
93 .lname = "device-names",
94 .type = FIO_OPT_STR_STORE,
95 .off1 = offsetof(struct act_options, device_names),
96 .help = "Devices to use",
97 .category = FIO_OPT_C_PROFILE,
98 .group = FIO_OPT_G_ACT,
102 .lname = "Load multiplier",
104 .off1 = offsetof(struct act_options, load),
105 .help = "ACT load multipler (default 1x)",
107 .category = FIO_OPT_C_PROFILE,
108 .group = FIO_OPT_G_ACT,
111 .name = "test-duration",
112 .lname = "Test duration",
113 .type = FIO_OPT_STR_VAL_TIME,
114 .off1 = offsetof(struct act_options, test_duration),
115 .help = "How long the entire test takes to run",
117 .category = FIO_OPT_C_PROFILE,
118 .group = FIO_OPT_G_ACT,
121 .name = "threads-per-queue",
122 .lname = "Number of read IO threads per device",
124 .off1 = offsetof(struct act_options, threads_per_queue),
125 .help = "Number of read IO threads per device",
127 .category = FIO_OPT_C_PROFILE,
128 .group = FIO_OPT_G_ACT,
131 .name = "read-req-num-512-blocks",
132 .lname = "Number of 512b blocks to read",
134 .off1 = offsetof(struct act_options, num_read_blocks),
135 .help = "Number of 512b blocks to read at the time",
137 .category = FIO_OPT_C_PROFILE,
138 .group = FIO_OPT_G_ACT,
141 .name = "large-block-op-kbytes",
142 .lname = "Size of large block ops (writes)",
144 .off1 = offsetof(struct act_options, write_size),
145 .help = "Size of large block ops (writes)",
147 .category = FIO_OPT_C_PROFILE,
148 .group = FIO_OPT_G_ACT,
152 .lname = "Run ACT prep phase",
153 .type = FIO_OPT_STR_SET,
154 .off1 = offsetof(struct act_options, prep),
155 .help = "Set to run ACT prep phase",
156 .category = FIO_OPT_C_PROFILE,
157 .group = FIO_OPT_G_ACT,
164 static int act_add_opt(const char *str, ...)
170 if (opt_idx == ACT_MAX_OPTS) {
171 log_err("act: ACT_MAX_OPTS is too small\n");
176 len = vsnprintf(buffer, sizeof(buffer), str, args);
180 act_opts[opt_idx++] = strdup(buffer);
185 static int act_add_rw(const char *dev, int reads)
187 if (act_add_opt("name=act-%s-%s", reads ? "read" : "write", dev))
189 if (act_add_opt("filename=%s", dev))
191 if (act_add_opt("rw=%s", reads ? "randread" : "randwrite"))
194 int rload = load * R_LOAD / threads_per_queue;
196 if (act_add_opt("numjobs=%u", threads_per_queue))
198 if (act_add_opt("rate_iops=%u", rload))
200 if (act_add_opt("bs=%u", num_read_blocks * 512))
203 const int rsize = write_size / (num_read_blocks * 512);
204 int wload = (load * W_LOAD + rsize - 1) / rsize;
206 if (act_add_opt("rate_iops=%u", wload))
208 if (act_add_opt("bs=%u", write_size))
215 static int act_add_dev_prep(const char *dev)
217 /* Add sequential zero phase */
218 if (act_add_opt("name=act-prep-zeroes-%s", dev))
220 if (act_add_opt("filename=%s", dev))
222 if (act_add_opt("bs=1M"))
224 if (act_add_opt("zero_buffers"))
226 if (act_add_opt("rw=write"))
229 /* Randomly overwrite device */
230 if (act_add_opt("name=act-prep-salt-%s", dev))
232 if (act_add_opt("stonewall"))
234 if (act_add_opt("filename=%s", dev))
236 if (act_add_opt("bs=4k"))
238 if (act_add_opt("ioengine=libaio"))
240 if (act_add_opt("iodepth=64"))
242 if (act_add_opt("rw=randwrite"))
248 static int act_add_dev(const char *dev)
251 return act_add_dev_prep(dev);
253 if (act_add_opt("runtime=%llus", test_duration))
255 if (act_add_opt("time_based=1"))
258 if (act_add_rw(dev, 1))
260 if (act_add_rw(dev, 0))
267 * Fill our private options into the command line
269 static int act_prep_cmdline(void)
272 log_err("act: you need to set IO target(s) with the "
273 "device-names option.\n");
282 dev = strsep(&device_names, ",");
286 if (act_add_dev(dev)) {
287 log_err("act: failed adding device to the mix\n");
295 static int act_io_u_lat(struct thread_data *td, uint64_t usec)
297 struct act_prof_data *apd = td->prof_data;
298 struct act_slice *slice;
306 * Really should not happen, but lets not let jitter at the end
309 if (apd->cur_slice >= apd->nr_slices)
312 slice = &apd->slices[apd->cur_slice];
315 for (i = ACT_MAX_CRIT - 1; i >= 0; i--) {
316 if (usec > act_pass[i].max_usec) {
317 slice->lat_buckets[i]++;
322 if (time_since_now(&apd->sample_tv) < SAMPLE_SEC)
325 /* SAMPLE_SEC has passed, check criteria for pass */
326 for (i = 0; i < ACT_MAX_CRIT; i++) {
327 perm = (1000.0 * slice->lat_buckets[i]) / slice->total_ios;
328 if (perm < act_pass[i].max_perm)
331 log_err("act: %f%% exceeds pass criteria of %f%%\n", perm / 10.0, (double) act_pass[i].max_perm / 10.0);
336 fio_gettime(&apd->sample_tv, NULL);
341 static void get_act_ref(void)
343 fio_mutex_down(act_run_data->mutex);
344 act_run_data->pending++;
345 fio_mutex_up(act_run_data->mutex);
348 static int show_slice(struct act_slice *slice, unsigned int slice_num)
350 unsigned int i, failed = 0;
352 log_info(" %2u", slice_num);
354 for (i = 0; i < ACT_MAX_CRIT; i++) {
357 if (slice->total_ios)
358 perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios;
359 if ((perc * 10.0) >= act_pass[i].max_perm)
361 log_info("\t%2.2f", perc);
363 for (i = 0; i < ACT_MAX_CRIT; i++) {
366 if (slice->total_ios)
367 perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios;
368 log_info("\t%2.2f", perc);
375 static void act_show_all_stats(void)
377 unsigned int i, fails = 0;
379 log_info(" trans device\n");
380 log_info(" %%>(ms) %%>(ms)\n");
383 for (i = 0; i < ACT_MAX_CRIT; i++)
384 log_info("\t %2u", act_pass[i].max_usec / 1000);
385 for (i = 0; i < ACT_MAX_CRIT; i++)
386 log_info("\t %2u", act_pass[i].max_usec / 1000);
389 log_info(" ----- ----- ----- ------ ----- ----- ------\n");
391 for (i = 0; i < act_run_data->nr_slices; i++)
392 fails += show_slice(&act_run_data->slices[i], i + 1);
394 log_info("\nact: test complete, device(s): %s\n", fails ? "FAILED" : "PASSED");
397 static void put_act_ref(struct thread_data *td)
399 struct act_prof_data *apd = td->prof_data;
400 unsigned int i, slice;
402 fio_mutex_down(act_run_data->mutex);
404 if (!act_run_data->slices) {
405 act_run_data->slices = calloc(apd->nr_slices, sizeof(struct act_slice));
406 act_run_data->nr_slices = apd->nr_slices;
409 for (slice = 0; slice < apd->nr_slices; slice++) {
410 struct act_slice *dst = &act_run_data->slices[slice];
411 struct act_slice *src = &apd->slices[slice];
413 dst->total_ios += src->total_ios;
415 for (i = 0; i < ACT_MAX_CRIT; i++)
416 dst->lat_buckets[i] += src->lat_buckets[i];
419 if (!--act_run_data->pending)
420 act_show_all_stats();
422 fio_mutex_up(act_run_data->mutex);
425 static int act_td_init(struct thread_data *td)
427 struct act_prof_data *apd;
428 unsigned int nr_slices;
432 apd = calloc(1, sizeof(*apd));
433 nr_slices = (test_duration + SAMPLE_SEC - 1) / SAMPLE_SEC;
434 apd->slices = calloc(nr_slices, sizeof(struct act_slice));
435 apd->nr_slices = nr_slices;
436 fio_gettime(&apd->sample_tv, NULL);
441 static void act_td_exit(struct thread_data *td)
443 struct act_prof_data *apd = td->prof_data;
448 td->prof_data = NULL;
451 static struct prof_io_ops act_io_ops = {
452 .td_init = act_td_init,
453 .td_exit = act_td_exit,
454 .io_u_lat = act_io_u_lat,
457 static struct profile_ops act_profile = {
459 .desc = "ACT Aerospike like benchmark",
461 .opt_data = &act_options,
462 .prep_cmd = act_prep_cmdline,
464 .io_ops = &act_io_ops,
467 static void fio_init act_register(void)
469 act_run_data = calloc(1, sizeof(*act_run_data));
470 act_run_data->mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED);
472 if (register_profile(&act_profile))
473 log_err("fio: failed to register profile 'act'\n");
476 static void fio_exit act_unregister(void)
478 while (org_idx && org_idx < opt_idx)
479 free((void *) act_opts[++org_idx]);
481 unregister_profile(&act_profile);
482 fio_mutex_remove(act_run_data->mutex);
483 free(act_run_data->slices);