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];
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 timespec sample_tv;
51 struct act_slice *slices;
52 unsigned int cur_slice;
53 unsigned int nr_slices;
56 #define ACT_MAX_OPTS 128
57 static const char *act_opts[ACT_MAX_OPTS] = {
60 "random_generator=lfsr",
65 static unsigned int opt_idx = 5;
66 static unsigned int org_idx;
68 static int act_add_opt(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
75 unsigned int threads_per_queue;
76 unsigned int num_read_blocks;
77 unsigned int write_size;
78 unsigned long long test_duration;
81 static struct act_options act_options;
83 static struct fio_option options[] = {
85 .name = "device-names",
86 .lname = "device-names",
87 .type = FIO_OPT_STR_STORE,
88 .off1 = offsetof(struct act_options, device_names),
89 .help = "Devices to use",
90 .category = FIO_OPT_C_PROFILE,
91 .group = FIO_OPT_G_ACT,
96 .lname = "Load multiplier",
98 .off1 = offsetof(struct act_options, load),
99 .help = "ACT load multipler (default 1x)",
101 .category = FIO_OPT_C_PROFILE,
102 .group = FIO_OPT_G_ACT,
105 .name = "test-duration",
106 .lname = "Test duration",
107 .type = FIO_OPT_STR_VAL_TIME,
108 .off1 = offsetof(struct act_options, test_duration),
109 .help = "How long the entire test takes to run",
111 .category = FIO_OPT_C_PROFILE,
112 .group = FIO_OPT_G_ACT,
115 .name = "threads-per-queue",
116 .lname = "Number of read IO threads per device",
118 .off1 = offsetof(struct act_options, threads_per_queue),
119 .help = "Number of read IO threads per device",
121 .category = FIO_OPT_C_PROFILE,
122 .group = FIO_OPT_G_ACT,
125 .name = "read-req-num-512-blocks",
126 .lname = "Number of 512B blocks to read",
128 .off1 = offsetof(struct act_options, num_read_blocks),
129 .help = "Number of 512B blocks to read at the time",
131 .category = FIO_OPT_C_PROFILE,
132 .group = FIO_OPT_G_ACT,
135 .name = "large-block-op-kbytes",
136 .lname = "Size of large block ops in KiB (writes)",
138 .off1 = offsetof(struct act_options, write_size),
139 .help = "Size of large block ops in KiB (writes)",
141 .category = FIO_OPT_C_PROFILE,
142 .group = FIO_OPT_G_ACT,
146 .lname = "Run ACT prep phase",
147 .type = FIO_OPT_STR_SET,
148 .off1 = offsetof(struct act_options, prep),
149 .help = "Set to run ACT prep phase",
150 .category = FIO_OPT_C_PROFILE,
151 .group = FIO_OPT_G_ACT,
158 static int act_add_opt(const char *str, ...)
164 if (opt_idx == ACT_MAX_OPTS) {
165 log_err("act: ACT_MAX_OPTS is too small\n");
170 len = vsnprintf(buffer, sizeof(buffer), str, args);
174 act_opts[opt_idx++] = strdup(buffer);
179 static int act_add_rw(const char *dev, int reads)
181 struct act_options *ao = &act_options;
183 if (act_add_opt("name=act-%s-%s", reads ? "read" : "write", dev))
185 if (act_add_opt("filename=%s", dev))
187 if (act_add_opt("rw=%s", reads ? "randread" : "randwrite"))
190 int rload = ao->load * R_LOAD / ao->threads_per_queue;
192 if (act_add_opt("numjobs=%u", ao->threads_per_queue))
194 if (act_add_opt("rate_iops=%u", rload))
196 if (act_add_opt("bs=%u", ao->num_read_blocks * 512))
199 const int rsize = ao->write_size / (ao->num_read_blocks * 512);
200 int wload = (ao->load * W_LOAD + rsize - 1) / rsize;
202 if (act_add_opt("rate_iops=%u", wload))
204 if (act_add_opt("bs=%u", ao->write_size))
211 static int act_add_dev_prep(const char *dev)
213 /* Add sequential zero phase */
214 if (act_add_opt("name=act-prep-zeroes-%s", dev))
216 if (act_add_opt("filename=%s", dev))
218 if (act_add_opt("bs=1048576"))
220 if (act_add_opt("zero_buffers"))
222 if (act_add_opt("rw=write"))
225 /* Randomly overwrite device */
226 if (act_add_opt("name=act-prep-salt-%s", dev))
228 if (act_add_opt("stonewall"))
230 if (act_add_opt("filename=%s", dev))
232 if (act_add_opt("bs=4096"))
234 if (act_add_opt("ioengine=libaio"))
236 if (act_add_opt("iodepth=64"))
238 if (act_add_opt("rw=randwrite"))
244 static int act_add_dev(const char *dev)
246 if (act_options.prep)
247 return act_add_dev_prep(dev);
249 if (act_add_opt("runtime=%llus", act_options.test_duration))
251 if (act_add_opt("time_based=1"))
254 if (act_add_rw(dev, 1))
256 if (act_add_rw(dev, 0))
263 * Fill our private options into the command line
265 static int act_prep_cmdline(void)
267 if (!act_options.device_names) {
268 log_err("act: you need to set IO target(s) with the "
269 "device-names option.\n");
278 dev = strsep(&act_options.device_names, ",");
282 if (act_add_dev(dev)) {
283 log_err("act: failed adding device to the mix\n");
291 static int act_io_u_lat(struct thread_data *td, uint64_t nsec)
293 struct act_prof_data *apd = td->prof_data;
294 struct act_slice *slice;
295 uint64_t usec = nsec / 1000ULL;
299 if (act_options.prep)
303 * Really should not happen, but lets not let jitter at the end
306 if (apd->cur_slice >= apd->nr_slices)
309 slice = &apd->slices[apd->cur_slice];
312 for (i = ACT_MAX_CRIT - 1; i >= 0; i--) {
313 if (usec > act_pass[i].max_usec) {
314 slice->lat_buckets[i]++;
319 if (time_since_now(&apd->sample_tv) < SAMPLE_SEC)
322 /* SAMPLE_SEC has passed, check criteria for pass */
323 for (i = 0; i < ACT_MAX_CRIT; i++) {
324 perm = (1000.0 * slice->lat_buckets[i]) / slice->total_ios;
325 if (perm < act_pass[i].max_perm)
328 log_err("act: %f%% exceeds pass criteria of %f%%\n", perm / 10.0, (double) act_pass[i].max_perm / 10.0);
333 fio_gettime(&apd->sample_tv, NULL);
338 static void get_act_ref(void)
340 fio_sem_down(act_run_data->sem);
341 act_run_data->pending++;
342 fio_sem_up(act_run_data->sem);
345 static int show_slice(struct act_slice *slice, unsigned int slice_num)
347 unsigned int i, failed = 0;
349 log_info(" %2u", slice_num);
351 for (i = 0; i < ACT_MAX_CRIT; i++) {
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)
358 log_info("\t%2.2f", perc);
360 for (i = 0; i < ACT_MAX_CRIT; i++) {
363 if (slice->total_ios)
364 perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios;
365 log_info("\t%2.2f", perc);
372 static void act_show_all_stats(void)
374 unsigned int i, fails = 0;
376 log_info(" trans device\n");
377 log_info(" %%>(ms) %%>(ms)\n");
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);
386 log_info(" ----- ----- ----- ------ ----- ----- ------\n");
388 for (i = 0; i < act_run_data->nr_slices; i++)
389 fails += show_slice(&act_run_data->slices[i], i + 1);
391 log_info("\nact: test complete, device(s): %s\n", fails ? "FAILED" : "PASSED");
394 static void put_act_ref(struct thread_data *td)
396 struct act_prof_data *apd = td->prof_data;
397 unsigned int i, slice;
399 fio_sem_down(act_run_data->sem);
401 if (!act_run_data->slices) {
402 act_run_data->slices = calloc(apd->nr_slices, sizeof(struct act_slice));
403 act_run_data->nr_slices = apd->nr_slices;
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];
410 dst->total_ios += src->total_ios;
412 for (i = 0; i < ACT_MAX_CRIT; i++)
413 dst->lat_buckets[i] += src->lat_buckets[i];
416 if (!--act_run_data->pending)
417 act_show_all_stats();
419 fio_sem_up(act_run_data->sem);
422 static int act_td_init(struct thread_data *td)
424 struct act_prof_data *apd;
425 unsigned int nr_slices;
429 apd = calloc(1, sizeof(*apd));
430 nr_slices = (act_options.test_duration + SAMPLE_SEC - 1) / SAMPLE_SEC;
431 apd->slices = calloc(nr_slices, sizeof(struct act_slice));
432 apd->nr_slices = nr_slices;
433 fio_gettime(&apd->sample_tv, NULL);
438 static void act_td_exit(struct thread_data *td)
440 struct act_prof_data *apd = td->prof_data;
445 td->prof_data = NULL;
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,
454 static struct profile_ops act_profile = {
456 .desc = "ACT Aerospike like benchmark",
458 .opt_data = &act_options,
459 .prep_cmd = act_prep_cmdline,
461 .io_ops = &act_io_ops,
464 static void fio_init act_register(void)
466 act_run_data = calloc(1, sizeof(*act_run_data));
467 act_run_data->sem = fio_sem_init(FIO_SEM_UNLOCKED);
469 if (register_profile(&act_profile))
470 log_err("fio: failed to register profile 'act'\n");
473 static void fio_exit act_unregister(void)
475 while (org_idx && org_idx < opt_idx)
476 free((void *) act_opts[++org_idx]);
478 unregister_profile(&act_profile);
479 fio_sem_remove(act_run_data->sem);
480 free(act_run_data->slices);