From: Stephen M. Cameron Date: Tue, 11 Nov 2014 03:31:26 +0000 (-0700) Subject: Fixup some of the time (usec) based conversions X-Git-Tag: fio-2.1.14~4 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=88038bc7193e648cef39061e0b8d6ef8203a1e63;hp=77b451cc30ab109050235e80b4988ab3abbe6d13 Fixup some of the time (usec) based conversions Modified by Jens to fixup some of the mtime/utime confusion, and add a specific ->is_time to options to get rid of future issues in this area. Signed-off-by: Jens Axboe --- diff --git a/eta.c b/eta.c index db08e2ab..5be5aed3 100644 --- a/eta.c +++ b/eta.c @@ -555,8 +555,7 @@ void display_thread_status(struct jobs_eta *je) if (!eta_new_line_init) { fio_gettime(&disp_eta_new_line, NULL); eta_new_line_init = 1; - } else if (eta_new_line && - mtime_since_now(&disp_eta_new_line) > eta_new_line * 1000) { + } else if (eta_new_line && mtime_since_now(&disp_eta_new_line) > eta_new_line) { fio_gettime(&disp_eta_new_line, NULL); eta_new_line_pending = 1; } diff --git a/exp/expression-parser.l b/exp/expression-parser.l index 856596ac..50bd3832 100644 --- a/exp/expression-parser.l +++ b/exp/expression-parser.l @@ -42,6 +42,9 @@ extern int yyerror(long long *result, double *dresult, static void __attribute__((unused)) yyunput(int c, char *buf_ptr); static int __attribute__((unused)) input(void); +/* set by parser -- this is another thing which makes the parser thread-unsafe :(. */ +int lexer_value_is_time = 0; /* for determining if "m" suffix means mega- or minutes */ + #define set_suffix_value(yylval, i_val, d_val, has_d_val) \ (yylval).v.dval = (d_val); \ (yylval).v.ival = (i_val); \ @@ -57,7 +60,7 @@ static int __attribute__((unused)) input(void); set_suffix_value(yylval, 1024, 1024.0, 0); return SUFFIX; } -[Mm]|[Mm][bB] { +[Mm][bB] { set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0); return SUFFIX; } @@ -103,6 +106,14 @@ static int __attribute__((unused)) input(void); set_suffix_value(yylval, 1000000LL, 1000000.0 , 0); return SUFFIX; } +[mM] { + if (!lexer_value_is_time) { + set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0); + } else { + set_suffix_value(yylval, 60LL * 1000000LL, 60.0 * 1000000.0, 0); + } + return SUFFIX; + } [dD] { set_suffix_value(yylval, 60LL * 60LL * 24LL * 1000000LL, 60.0 * 60.0 * 24.0 * 1000000.0, 0); diff --git a/exp/expression-parser.y b/exp/expression-parser.y index 8ae0c01e..d664b8ed 100644 --- a/exp/expression-parser.y +++ b/exp/expression-parser.y @@ -43,6 +43,7 @@ int yyerror(__attribute__((unused)) long long *result, extern int yylex(void); extern void yyrestart(FILE *file); +extern int lexer_value_is_time; %} @@ -214,10 +215,11 @@ static void setup_to_parse_string(const char *string) } int evaluate_arithmetic_expression(const char *buffer, long long *ival, double *dval, - double implied_units) + double implied_units, int is_time) { int rc, units_specified = 0, has_error = 0; + lexer_value_is_time = is_time; setup_to_parse_string(buffer); rc = yyparse(ival, dval, &has_error, &units_specified); yyrestart(NULL); diff --git a/exp/test-expression-parser.c b/exp/test-expression-parser.c index 93c766a1..bf3fb3ed 100644 --- a/exp/test-expression-parser.c +++ b/exp/test-expression-parser.c @@ -25,7 +25,7 @@ #include "../y.tab.h" extern int evaluate_arithmetic_expression(const char *buffer, long long *ival, - double *dval, double implied_units); + double *dval, double implied_units, int is_time); int main(int argc, char *argv[]) { @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) rc = strlen(buffer); if (rc > 0 && buffer[rc - 1] == '\n') buffer[rc - 1] = '\0'; - rc = evaluate_arithmetic_expression(buffer, &result, &dresult, 1.0); + rc = evaluate_arithmetic_expression(buffer, &result, &dresult, 1.0, 0); if (!rc) { printf("%lld (%20.20lf)\n", result, dresult); } else { diff --git a/init.c b/init.c index c2c126b5..70d5d069 100644 --- a/init.c +++ b/init.c @@ -1968,12 +1968,12 @@ int parse_cmd_line(int argc, char *argv[], int client_type) case 'E': { long long t = 0; - if (str_to_decimal(optarg, &t, 0, NULL, 1)) { + if (check_str_time(optarg, &t, 1)) { log_err("fio: failed parsing eta time %s\n", optarg); exit_val = 1; do_exit++; } - eta_new_line = t; + eta_new_line = t / 1000; break; } case 'd': @@ -2175,13 +2175,13 @@ int parse_cmd_line(int argc, char *argv[], int client_type) case 'L': { long long val; - if (check_str_time(optarg, &val, 0)) { + if (check_str_time(optarg, &val, 1)) { log_err("fio: failed parsing time %s\n", optarg); do_exit++; exit_val = 1; break; } - status_interval = val * 1000; + status_interval = val / 1000; break; } case '?': diff --git a/options.c b/options.c index 529b8f05..ac094804 100644 --- a/options.c +++ b/options.c @@ -102,7 +102,7 @@ static int bssplit_ddir(struct thread_options *o, int ddir, char *str) } else perc = -1U; - if (str_to_decimal(fname, &val, 1, o, 0)) { + if (str_to_decimal(fname, &val, 1, o, 0, 0)) { log_err("fio: bssplit conversion failed\n"); free(bssplit); return 1; @@ -342,7 +342,7 @@ static int str_rw_cb(void *data, const char *str) else { long long val; - if (str_to_decimal(nr, &val, 1, o, 0)) { + if (str_to_decimal(nr, &val, 1, o, 0, 0)) { log_err("fio: rw postfix parsing failed\n"); free(nr); return 1; @@ -738,7 +738,7 @@ static int str_random_distribution_cb(void *data, const char *str) return 0; nr = get_opt_postfix(str); - if (nr && !str_to_float(nr, &val)) { + if (nr && !str_to_float(nr, &val, 0)) { log_err("fio: random postfix parsing failed\n"); free(nr); return 1; @@ -2177,6 +2177,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Only start job when this period has passed", .def = "0", .is_seconds = 1, + .is_time = 1, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, }, @@ -2189,6 +2190,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "Stop workload when this amount of time has passed", .def = "0", .is_seconds = 1, + .is_time = 1, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, }, @@ -2217,6 +2219,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = td_var_offset(ramp_time), .help = "Ramp up time before measuring performance", .is_seconds = 1, + .is_time = 1, .category = FIO_OPT_C_GENERAL, .group = FIO_OPT_G_RUNTIME, }, @@ -2770,6 +2773,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = td_var_offset(thinktime), .help = "Idle time between IO buffers (usec)", .def = "0", + .is_time = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_THINKTIME, }, @@ -2780,6 +2784,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .off1 = td_var_offset(thinktime_spin), .help = "Start think time by spinning this amount (usec)", .def = "0", + .is_time = 1, .parent = "thinktime", .hide = 1, .category = FIO_OPT_C_IO, @@ -2863,6 +2868,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_INT, .off1 = td_var_offset(max_latency), .help = "Maximum tolerated IO latency (usec)", + .is_time = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_LATPROF, }, @@ -2872,6 +2878,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_STR_VAL_TIME, .off1 = td_var_offset(latency_target), .help = "Ramp to max queue depth supporting this latency", + .is_time = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_LATPROF, }, @@ -2881,6 +2888,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .type = FIO_OPT_STR_VAL_TIME, .off1 = td_var_offset(latency_window), .help = "Time to sustain latency_target", + .is_time = 1, .category = FIO_OPT_C_IO, .group = FIO_OPT_G_LATPROF, }, diff --git a/parse.c b/parse.c index 282baa4c..42096471 100644 --- a/parse.c +++ b/parse.c @@ -269,7 +269,8 @@ static unsigned long long get_mult_bytes(const char *str, int len, void *data, } extern int evaluate_arithmetic_expression(const char *buffer, long long *ival, - double *dval, double implied_units); + double *dval, double implied_units, + int is_time); #ifdef CONFIG_ARITHMETIC /* @@ -278,7 +279,7 @@ extern int evaluate_arithmetic_expression(const char *buffer, long long *ival, * original number parsing code. Once sufficiently sure that the arithmetic * code is always getting the right answers, these can be removed. */ -static void verify_exp_parser_float(const char *str, double implied_units) +static void verify_exp_parser_float(const char *str, double implied_units, int is_time) { long long ival; double dval, tmpval; @@ -286,7 +287,7 @@ static void verify_exp_parser_float(const char *str, double implied_units) if (sscanf(str, "%lf", &tmpval) != 1) return; - if (evaluate_arithmetic_expression(str, &ival, &dval, implied_units) != 0) { + if (evaluate_arithmetic_expression(str, &ival, &dval, implied_units, is_time) != 0) { log_info("Arithmetic failed on '%s'\n", str); return; } @@ -296,7 +297,8 @@ static void verify_exp_parser_float(const char *str, double implied_units) } } -static void verify_exp_parser_decimal(const char *str, long long val, int kilo, int is_seconds) +static void verify_exp_parser_decimal(const char *str, long long val, int kilo, int is_seconds, + int is_time) { int rc; long long ival; @@ -306,7 +308,7 @@ static void verify_exp_parser_decimal(const char *str, long long val, int kilo, if (is_seconds) implied_units = 1000000.0; - rc = evaluate_arithmetic_expression(str, &ival, &dval, implied_units); + rc = evaluate_arithmetic_expression(str, &ival, &dval, implied_units, is_time); if (!rc) { if (ival != val) log_info("Arithmetic failed on '%s', expected %lld, got %lld\n", @@ -320,7 +322,7 @@ static void verify_exp_parser_decimal(const char *str, long long val, int kilo, /* * Convert string into a floating number. Return 1 for success and 0 otherwise. */ -int str_to_float(const char *str, double *val) +int str_to_float(const char *str, double *val, int is_time) { #ifdef CONFIG_ARITHMETIC int rc; @@ -328,13 +330,13 @@ int str_to_float(const char *str, double *val) double dval; if (str[0] == '(') { - rc = evaluate_arithmetic_expression(str, &ival, &dval, 1.0); + rc = evaluate_arithmetic_expression(str, &ival, &dval, 1.0, is_time); if (!rc) { *val = dval; return 1; } } else { - verify_exp_parser_float(str, 1.0); + verify_exp_parser_float(str, 1.0, is_time); } #endif return 1 == sscanf(str, "%lf", val); @@ -344,7 +346,7 @@ int str_to_float(const char *str, double *val) * convert string into decimal value, noting any size suffix */ int str_to_decimal(const char *str, long long *val, int kilo, void *data, - int is_seconds) + int is_seconds, int is_time) { int len, base; int rc = 1; @@ -362,7 +364,7 @@ int str_to_decimal(const char *str, long long *val, int kilo, void *data, if (is_seconds) implied_units = 1000000.0; if (str[0] == '(') - rc = evaluate_arithmetic_expression(str, &ival, &dval, implied_units); + rc = evaluate_arithmetic_expression(str, &ival, &dval, implied_units, is_time); if (str[0] == '(' && !rc) { if (!kilo && is_seconds) *val = ival / 1000000LL; @@ -394,19 +396,19 @@ int str_to_decimal(const char *str, long long *val, int kilo, void *data, } else *val *= get_mult_time(str, len, is_seconds); #ifdef CONFIG_ARITHMETIC - verify_exp_parser_decimal(str, *val, kilo, is_seconds); + verify_exp_parser_decimal(str, *val, kilo, is_seconds, is_time); #endif return 0; } int check_str_bytes(const char *p, long long *val, void *data) { - return str_to_decimal(p, val, 1, data, 0); + return str_to_decimal(p, val, 1, data, 0, 0); } int check_str_time(const char *p, long long *val, int is_seconds) { - return str_to_decimal(p, val, 0, NULL, is_seconds); + return str_to_decimal(p, val, 0, NULL, is_seconds, 1); } void strip_blank_front(char **p) @@ -448,7 +450,7 @@ static int check_range_bytes(const char *str, long *val, void *data) { long long __val; - if (!str_to_decimal(str, &__val, 1, data, 0)) { + if (!str_to_decimal(str, &__val, 1, data, 0, 0)) { *val = __val; return 0; } @@ -552,6 +554,9 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data, fio_opt_str_val_fn *fn = o->cb; char tmp[128], *p; + if (!is_time && o->is_time) + is_time = o->is_time; + strncpy(tmp, ptr, sizeof(tmp) - 1); p = strchr(tmp, ','); if (p) @@ -655,7 +660,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data, o->maxlen); return 1; } - if (!str_to_float(ptr, &uf)) { + if (!str_to_float(ptr, &uf, 0)) { /* this breaks if we ever have lists of times */ log_err("not a floating point value: %s\n", ptr); return 1; } diff --git a/parse.h b/parse.h index 2a1e06a4..a9d726dd 100644 --- a/parse.h +++ b/parse.h @@ -73,6 +73,7 @@ struct fio_option { unsigned int group; /* who to group with */ void *gui_data; int is_seconds; /* time value with seconds base */ + int is_time; /* time based value */ int no_warn_def; }; @@ -89,10 +90,10 @@ extern void options_free(struct fio_option *, void *); extern void strip_blank_front(char **); extern void strip_blank_end(char *); -extern int str_to_decimal(const char *, long long *, int, void *, int); +extern int str_to_decimal(const char *, long long *, int, void *, int, int); extern int check_str_bytes(const char *p, long long *val, void *data); extern int check_str_time(const char *p, long long *val, int); -extern int str_to_float(const char *str, double *val); +extern int str_to_float(const char *str, double *val, int is_time); /* * Handlers for the options