diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab97bddd..5501276fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,11 @@ New API function spdk_nvme_qpair_add_cmd_error_injection() and spdk_nvme_qpair_remove_cmd_error_injection() have been added for NVMe error emulation, users can set specified command with specified error status for error emulation. +Change the name `timeout_sec` parameter to `timeout_us` in API function +spdk_nvme_ctrlr_register_timeout_callback, and also change the type from uint32_t to +uint64_t. This will give users more fine-grained control over the timeout period for +calling callback functions. + ### Build System The build system now generates a combined shared library (libspdk.so) that may be used diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index 8f10bf5cc..9f0f2fee0 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -688,12 +688,12 @@ typedef void (*spdk_nvme_timeout_cb)(void *cb_arg, * for timeout callback. * * \param ctrlr NVMe controller on which to monitor for timeout. - * \param timeout_sec Timeout value in seconds. + * \param timeout_us Timeout value in microseconds. * \param cb_fn A function pointer that points to the callback function. * \param cb_arg Argument to the callback function. */ void spdk_nvme_ctrlr_register_timeout_callback(struct spdk_nvme_ctrlr *ctrlr, - uint32_t timeout_sec, spdk_nvme_timeout_cb cb_fn, void *cb_arg); + uint64_t timeout_us, spdk_nvme_timeout_cb cb_fn, void *cb_arg); /** * NVMe I/O queue pair initialization options. diff --git a/lib/bdev/nvme/bdev_nvme.c b/lib/bdev/nvme/bdev_nvme.c index f4a58dd7d..ebf82504f 100644 --- a/lib/bdev/nvme/bdev_nvme.c +++ b/lib/bdev/nvme/bdev_nvme.c @@ -102,7 +102,7 @@ enum timeout_action { static int g_hot_insert_nvme_controller_index = 0; static enum timeout_action g_action_on_timeout = TIMEOUT_ACTION_NONE; -static int g_timeout = 0; +static uint64_t g_timeout_us = 0; static int g_nvme_adminq_poll_timeout_us = 0; static bool g_nvme_hotplug_enabled = false; static int g_nvme_hotplug_poll_timeout_us = 0; @@ -946,7 +946,7 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr, TAILQ_INSERT_TAIL(&g_nvme_ctrlrs, nvme_ctrlr, tailq); if (g_action_on_timeout != TIMEOUT_ACTION_NONE) { - spdk_nvme_ctrlr_register_timeout_callback(ctrlr, g_timeout, + spdk_nvme_ctrlr_register_timeout_callback(ctrlr, g_timeout_us, timeout_cb, NULL); } @@ -1099,6 +1099,7 @@ bdev_nvme_library_init(void) size_t i; struct nvme_probe_ctx *probe_ctx = NULL; int retry_count; + int timeout; uint32_t local_nvme_num = 0; sp = spdk_conf_find_section(NULL, "Nvme"); @@ -1124,17 +1125,29 @@ bdev_nvme_library_init(void) spdk_nvme_retry_count = retry_count; - if ((g_timeout = spdk_conf_section_get_intval(sp, "Timeout")) < 0) { + val = spdk_conf_section_get_val(sp, "TimeoutUsec"); + if (val != NULL) { + g_timeout_us = strtoll(val, NULL, 10); + } else { /* Check old name for backward compatibility */ - if ((g_timeout = spdk_conf_section_get_intval(sp, "NvmeTimeoutValue")) < 0) { - g_timeout = 0; + timeout = spdk_conf_section_get_intval(sp, "Timeout"); + if (timeout < 0) { + timeout = spdk_conf_section_get_intval(sp, "NvmeTimeoutValue"); + if (timeout < 0) { + g_timeout_us = 0; + } else { + g_timeout_us = timeout * 1000000ULL; + SPDK_WARNLOG("NvmeTimeoutValue (in seconds) was renamed to TimeoutUsec (in microseconds)\n"); + SPDK_WARNLOG("Please update your configuration file\n"); + } } else { - SPDK_WARNLOG("NvmeTimeoutValue was renamed to Timeout\n"); + g_timeout_us = timeout * 1000000ULL; + SPDK_WARNLOG("Timeout (in seconds) was renamed to TimeoutUsec (in microseconds)\n"); SPDK_WARNLOG("Please update your configuration file\n"); } } - if (g_timeout > 0) { + if (g_timeout_us > 0) { val = spdk_conf_section_get_val(sp, "ActionOnTimeout"); if (val != NULL) { if (!strcasecmp(val, "Reset")) { @@ -1566,8 +1579,8 @@ bdev_nvme_get_spdk_running_config(FILE *fp) "# this key to get the default behavior.\n"); fprintf(fp, "RetryCount %d\n", spdk_nvme_retry_count); fprintf(fp, "\n" - "# Timeout for each command, in seconds. If 0, don't track timeouts.\n"); - fprintf(fp, "Timeout %d\n", g_timeout); + "# Timeout for each command, in microseconds. If 0, don't track timeouts.\n"); + fprintf(fp, "Timeout %"PRIu64"\n", g_timeout_us); fprintf(fp, "\n" "# Action to take on command time out. Only valid when Timeout is greater\n" diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index 5f14a4e1a..3386dc494 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -2015,7 +2015,7 @@ spdk_nvme_ctrlr_register_aer_callback(struct spdk_nvme_ctrlr *ctrlr, void spdk_nvme_ctrlr_register_timeout_callback(struct spdk_nvme_ctrlr *ctrlr, - uint32_t nvme_timeout, spdk_nvme_timeout_cb cb_fn, void *cb_arg) + uint64_t timeout_us, spdk_nvme_timeout_cb cb_fn, void *cb_arg) { struct spdk_nvme_ctrlr_process *active_proc; @@ -2023,7 +2023,7 @@ spdk_nvme_ctrlr_register_timeout_callback(struct spdk_nvme_ctrlr *ctrlr, active_proc = spdk_nvme_ctrlr_get_current_process(ctrlr); if (active_proc) { - active_proc->timeout_ticks = nvme_timeout * spdk_get_ticks_hz(); + active_proc->timeout_ticks = timeout_us * spdk_get_ticks_hz() / 1000000ULL; active_proc->timeout_cb_fn = cb_fn; active_proc->timeout_cb_arg = cb_arg; }