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)));
77 static struct fio_option options[] = {
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,
89 .lname = "Load multiplier",
92 .help = "ACT load multipler (default 1x)",
94 .category = FIO_OPT_C_PROFILE,
95 .group = FIO_OPT_G_ACT,
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",
104 .category = FIO_OPT_C_PROFILE,
105 .group = FIO_OPT_G_ACT,
108 .name = "threads-per-queue",
109 .lname = "Number of read IO threads per device",
111 .roff1 = &threads_per_queue,
112 .help = "Number of read IO threads per device",
114 .category = FIO_OPT_C_PROFILE,
115 .group = FIO_OPT_G_ACT,
118 .name = "read-req-num-512-blocks",
119 .lname = "Number of 512b blocks to read",
121 .roff1 = &num_read_blocks,
122 .help = "Number of 512b blocks to read at the time",
124 .category = FIO_OPT_C_PROFILE,
125 .group = FIO_OPT_G_ACT,
128 .name = "large-block-op-kbytes",
129 .lname = "Size of large block ops (writes)",
131 .roff1 = &write_size,
132 .help = "Size of large block ops (writes)",
134 .category = FIO_OPT_C_PROFILE,
135 .group = FIO_OPT_G_ACT,
139 .lname = "Run ACT prep phase",
140 .type = FIO_OPT_STR_SET,
142 .help = "Set to run ACT prep phase",
143 .category = FIO_OPT_C_PROFILE,
144 .group = FIO_OPT_G_ACT,
151 static int act_add_opt(const char *str, ...)
157 if (opt_idx == ACT_MAX_OPTS) {
158 log_err("act: ACT_MAX_OPTS is too small\n");
163 len = vsnprintf(buffer, sizeof(buffer), str, args);
167 act_opts[opt_idx++] = strdup(buffer);
172 static int act_add_rw(const char *dev, int reads)
174 if (act_add_opt("name=act-%s-%s", reads ? "read" : "write", dev))
176 if (act_add_opt("filename=%s", dev))
178 if (act_add_opt("rw=%s", reads ? "randread" : "randwrite"))
181 int rload = load * R_LOAD / threads_per_queue;
183 if (act_add_opt("numjobs=%u", threads_per_queue))
185 if (act_add_opt("rate_iops=%u", rload))
187 if (act_add_opt("bs=%u", num_read_blocks * 512))
190 const int rsize = write_size / (num_read_blocks * 512);
191 int wload = (load * W_LOAD + rsize - 1) / rsize;
193 if (act_add_opt("rate_iops=%u", wload))
195 if (act_add_opt("bs=%u", write_size))
202 static int act_add_dev_prep(const char *dev)
204 /* Add sequential zero phase */
205 if (act_add_opt("name=act-prep-zeroes-%s", dev))
207 if (act_add_opt("filename=%s", dev))
209 if (act_add_opt("bs=1M"))
211 if (act_add_opt("zero_buffers"))
213 if (act_add_opt("rw=write"))
216 /* Randomly overwrite device */
217 if (act_add_opt("name=act-prep-salt-%s", dev))
219 if (act_add_opt("stonewall"))
221 if (act_add_opt("filename=%s", dev))
223 if (act_add_opt("bs=4k"))
225 if (act_add_opt("ioengine=libaio"))
227 if (act_add_opt("iodepth=64"))
229 if (act_add_opt("rw=randwrite"))
235 static int act_add_dev(const char *dev)
238 return act_add_dev_prep(dev);
240 if (act_add_opt("runtime=%llus", test_duration))
242 if (act_add_opt("time_based=1"))
245 if (act_add_rw(dev, 1))
247 if (act_add_rw(dev, 0))
254 * Fill our private options into the command line
256 static int act_prep_cmdline(void)
259 log_err("act: you need to set IO target(s) with the "
260 "device-names option.\n");
269 dev = strsep(&device_names, ",");
273 if (act_add_dev(dev)) {
274 log_err("act: failed adding device to the mix\n");
282 static int act_io_u_lat(struct thread_data *td, uint64_t usec)
284 struct act_prof_data *apd = td->prof_data;
285 struct act_slice *slice;
293 * Really should not happen, but lets not let jitter at the end
296 if (apd->cur_slice >= apd->nr_slices)
299 slice = &apd->slices[apd->cur_slice];
302 for (i = ACT_MAX_CRIT - 1; i >= 0; i--) {
303 if (usec > act_pass[i].max_usec) {
304 slice->lat_buckets[i]++;
309 if (time_since_now(&apd->sample_tv) < SAMPLE_SEC)
312 /* SAMPLE_SEC has passed, check criteria for pass */
313 for (i = 0; i < ACT_MAX_CRIT; i++) {
314 perm = (1000.0 * slice->lat_buckets[i]) / slice->total_ios;
315 if (perm < act_pass[i].max_perm)
318 log_err("act: %f%% exceeds pass criteria of %f%%\n", perm / 10.0, (double) act_pass[i].max_perm / 10.0);
323 fio_gettime(&apd->sample_tv, NULL);
328 static void get_act_ref(void)
330 fio_mutex_down(act_run_data->mutex);
331 act_run_data->pending++;
332 fio_mutex_up(act_run_data->mutex);
335 static int show_slice(struct act_slice *slice, unsigned int slice_num)
337 unsigned int i, failed = 0;
339 log_info(" %2u", slice_num);
341 for (i = 0; i < ACT_MAX_CRIT; i++) {
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)
348 log_info("\t%2.2f", perc);
350 for (i = 0; i < ACT_MAX_CRIT; i++) {
353 if (slice->total_ios)
354 perc = 100.0 * (double) slice->lat_buckets[i] / (double) slice->total_ios;
355 log_info("\t%2.2f", perc);
362 static void act_show_all_stats(void)
364 unsigned int i, fails = 0;
366 log_info(" trans device\n");
367 log_info(" %%>(ms) %%>(ms)\n");
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);
376 log_info(" ----- ----- ----- ------ ----- ----- ------\n");
378 for (i = 0; i < act_run_data->nr_slices; i++)
379 fails += show_slice(&act_run_data->slices[i], i + 1);
381 log_info("\nact: test complete, device(s): %s\n", fails ? "FAILED" : "PASSED");
384 static void put_act_ref(struct thread_data *td)
386 struct act_prof_data *apd = td->prof_data;
387 unsigned int i, slice;
389 fio_mutex_down(act_run_data->mutex);
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;
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];
400 dst->total_ios += src->total_ios;
402 for (i = 0; i < ACT_MAX_CRIT; i++)
403 dst->lat_buckets[i] += src->lat_buckets[i];
406 if (!--act_run_data->pending)
407 act_show_all_stats();
409 fio_mutex_up(act_run_data->mutex);
412 static int act_td_init(struct thread_data *td)
414 struct act_prof_data *apd;
415 unsigned int nr_slices;
419 apd = calloc(sizeof(*apd), 1);
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;
423 fio_gettime(&apd->sample_tv, NULL);
428 static void act_td_exit(struct thread_data *td)
430 struct act_prof_data *apd = td->prof_data;
435 td->prof_data = NULL;
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,
444 static struct profile_ops act_profile = {
446 .desc = "ACT Aerospike like benchmark",
448 .prep_cmd = act_prep_cmdline,
450 .io_ops = &act_io_ops,
453 static void fio_init act_register(void)
455 act_run_data = calloc(sizeof(*act_run_data), 1);
456 act_run_data->mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED);
458 if (register_profile(&act_profile))
459 log_err("fio: failed to register profile 'act'\n");
462 static void fio_exit act_unregister(void)
464 while (org_idx && org_idx < opt_idx)
465 free((void *) act_opts[++org_idx]);
467 unregister_profile(&act_profile);
468 fio_mutex_remove(act_run_data->mutex);
469 free(act_run_data->slices);