From db0b09018e77114667a1b0fbd6c04194f56cb492 Mon Sep 17 00:00:00 2001 From: Cyril Bordage Date: Tue, 6 Jul 2021 14:26:09 +0200 Subject: [PATCH] LU-13299 lnet: add "stats reset" to lnetctl This new command resets stats shown by "lnetctl stats show". It could be useful when debugging connectivity issues, by making easier the process to detect the changes in stats from the clean state rather than on top of historical values. Signed-off-by: Cyril Bordage Change-Id: I4195a862fa5e04d96ac4c2b1509b625c90fbb579 Reviewed-on: https://review.whamcloud.com/44150 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Amir Shehata Reviewed-by: Oleg Drokin --- lnet/include/uapi/linux/lnet/libcfs_ioctl.h | 3 ++- lnet/lnet/api-ni.c | 8 ++++++++ lnet/utils/lnetconfig/liblnetconfig.c | 26 ++++++++++++++++++++++++++ lnet/utils/lnetconfig/liblnetconfig.h | 8 ++++++++ lnet/utils/lnetctl.c | 20 ++++++++++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lnet/include/uapi/linux/lnet/libcfs_ioctl.h b/lnet/include/uapi/linux/lnet/libcfs_ioctl.h index 9ae2d4e..a17eae5 100644 --- a/lnet/include/uapi/linux/lnet/libcfs_ioctl.h +++ b/lnet/include/uapi/linux/lnet/libcfs_ioctl.h @@ -153,7 +153,8 @@ struct libcfs_ioctl_data { #define IOC_LIBCFS_GET_UDSP_SIZE _IOWR(IOC_LIBCFS_TYPE, 107, IOCTL_CONFIG_SIZE) #define IOC_LIBCFS_GET_UDSP _IOWR(IOC_LIBCFS_TYPE, 108, IOCTL_CONFIG_SIZE) #define IOC_LIBCFS_GET_CONST_UDSP_INFO _IOWR(IOC_LIBCFS_TYPE, 109, IOCTL_CONFIG_SIZE) -#define IOC_LIBCFS_MAX_NR 109 +#define IOC_LIBCFS_RESET_LNET_STATS _IOWR(IOC_LIBCFS_TYPE, 110, IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_MAX_NR 110 extern int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data); diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 033e418..2bef416 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -3953,6 +3953,14 @@ LNetCtl(unsigned int cmd, void *arg) return rc; } + case IOC_LIBCFS_RESET_LNET_STATS: + { + mutex_lock(&the_lnet.ln_api_mutex); + lnet_counters_reset(); + mutex_unlock(&the_lnet.ln_api_mutex); + return 0; + } + case IOC_LIBCFS_CONFIG_RTR: config = arg; diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index 6a30c59..afa127c 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -3946,6 +3946,32 @@ out: return rc; } +int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc) +{ + struct libcfs_ioctl_data data; + int rc = LUSTRE_CFG_RC_NO_ERR; + int l_errno; + char err_str[LNET_MAX_STR_LEN]; + + LIBCFS_IOC_INIT(data); + + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_RESET_LNET_STATS, &data); + if (rc) { + l_errno = errno; + snprintf(err_str, + sizeof(err_str), + "\"cannot reset lnet statistics: %s\"", + strerror(l_errno)); + rc = -l_errno; + } else { + snprintf(err_str, sizeof(err_str), "\"success\""); + rc = LUSTRE_CFG_RC_NO_ERR; + } + + cYAML_build_error(rc, seq_no, SHOW_CMD, "statistics", err_str, err_rc); + return rc; +} + typedef int (*cmd_handler_t)(struct cYAML *tree, struct cYAML **show_rc, struct cYAML **err_rc); diff --git a/lnet/utils/lnetconfig/liblnetconfig.h b/lnet/utils/lnetconfig/liblnetconfig.h index afe11b6..c9ecf03 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.h +++ b/lnet/utils/lnetconfig/liblnetconfig.h @@ -602,6 +602,14 @@ int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc, struct cYAML **err_rc); /* + * lustre_lnet_reset_stats + * Resets internal LNET statistics. + * + * err_rc - YAML strucutre of the resultant return code. + */ +int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc); + +/* * lustre_lnet_modify_peer * Handle a peer config or delete operation. * diff --git a/lnet/utils/lnetctl.c b/lnet/utils/lnetctl.c index 4003acd..47d1ab0 100644 --- a/lnet/utils/lnetctl.c +++ b/lnet/utils/lnetctl.c @@ -60,6 +60,7 @@ static int jt_set_transaction_to(int argc, char **argv); static int jt_set_recov_intrv(int argc, char **argv); static int jt_set_rtr_sensitivity(int argc, char **argv); static int jt_set_hsensitivity(int argc, char **argv); +static int jt_reset_stats(int argc, char **argv); static int jt_add_peer_nid(int argc, char **argv); static int jt_del_peer_nid(int argc, char **argv); static int jt_set_max_intf(int argc, char **argv); @@ -176,6 +177,7 @@ command_t routing_cmds[] = { command_t stats_cmds[] = { {"show", jt_show_stats, 0, "show LNET statistics\n"}, + {"reset", jt_reset_stats, 0, "reset LNET statistics\n"}, { 0, 0, 0, NULL } }; @@ -569,6 +571,24 @@ static int jt_set_hsensitivity(int argc, char **argv) return rc; } +static int jt_reset_stats(int argc, char **argv) +{ + int rc; + struct cYAML *err_rc = NULL; + + rc = check_cmd(stats_cmds, "stats", "reset", 0, argc, argv); + if (rc) + return rc; + + rc = lustre_lnet_reset_stats(-1, &err_rc); + if (rc != LUSTRE_CFG_RC_NO_ERR) + cYAML_print_tree2file(stderr, err_rc); + + cYAML_free_tree(err_rc); + + return rc; +} + static int jt_set_transaction_to(int argc, char **argv) { long int value; -- 1.8.3.1