Whamcloud - gitweb
LU-13299 lnet: add "stats reset" to lnetctl 50/44150/2
authorCyril Bordage <cbordage@whamcloud.com>
Tue, 6 Jul 2021 12:26:09 +0000 (14:26 +0200)
committerOleg Drokin <green@whamcloud.com>
Sat, 31 Jul 2021 06:39:18 +0000 (06:39 +0000)
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 <cbordage@whamcloud.com>
Change-Id: I4195a862fa5e04d96ac4c2b1509b625c90fbb579
Reviewed-on: https://review.whamcloud.com/44150
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Amir Shehata <ashehata@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/include/uapi/linux/lnet/libcfs_ioctl.h
lnet/lnet/api-ni.c
lnet/utils/lnetconfig/liblnetconfig.c
lnet/utils/lnetconfig/liblnetconfig.h
lnet/utils/lnetctl.c

index 9ae2d4e..a17eae5 100644 (file)
@@ -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);
 
index 033e418..2bef416 100644 (file)
@@ -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;
 
index 6a30c59..afa127c 100644 (file)
@@ -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);
index afe11b6..c9ecf03 100644 (file)
@@ -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.
  *
index 4003acd..47d1ab0 100644 (file)
@@ -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;