Whamcloud - gitweb
LU-445 lnet: Make previous change backwards compatible
[fs/lustre-release.git] / lnet / utils / lst.c
index 37a7580..ee835f1 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -26,7 +24,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -645,7 +643,7 @@ jt_lst_show_session(int argc, char **argv)
                 return -1;
         }
 
-        fprintf(stdout, "%s ID: %Lu@%s, KEY: %d NODES: %d\n",
+        fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d NODES: %d\n",
                 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
                 key, ndinfo.nle_nnode);
 
@@ -1558,18 +1556,18 @@ lst_lnet_stat_value(int bw, int send, int off)
 
 static void
 lst_timeval_diff(struct timeval *tv1,
-                 struct timeval *tv2, struct timeval *df)
+                struct timeval *tv2, struct timeval *df)
 {
-        if (tv1->tv_usec >= tv2->tv_usec) {
-                df->tv_sec  = tv1->tv_sec - tv2->tv_sec;
-                df->tv_usec = tv1->tv_usec - tv2->tv_usec;
-                return;
-        }
+       if (tv1->tv_usec >= tv2->tv_usec) {
+               df->tv_sec  = tv1->tv_sec - tv2->tv_sec;
+               df->tv_usec = tv1->tv_usec - tv2->tv_usec;
+               return;
+       }
 
-        df->tv_sec  = tv1->tv_sec - 1 - tv2->tv_sec;
-        df->tv_usec = tv1->tv_sec + 1000000 - tv2->tv_usec;
+       df->tv_sec  = tv1->tv_sec - 1 - tv2->tv_sec;
+       df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
 
-        return;
+       return;
 }
 
 void
@@ -1692,7 +1690,7 @@ lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
 
 void
 lst_print_stat(char *name, cfs_list_t *resultp,
-               int idx, int lnet, int bwrt, int rdwr, int type)
+              int idx, int lnet, int bwrt, int rdwr, int type)
 {
         cfs_list_t        tmp[2];
         lstcon_rpc_ent_t *new;
@@ -1703,7 +1701,6 @@ lst_print_stat(char *name, cfs_list_t *resultp,
         srpc_counters_t  *srpc_old;
         lnet_counters_t  *lnet_new;
         lnet_counters_t  *lnet_old;
-        struct timeval    tv;
         float             delta;
         int               errcount = 0;
 
@@ -1754,9 +1751,26 @@ lst_print_stat(char *name, cfs_list_t *resultp,
                 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
                 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
 
-                lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
+               /* Prior to version 2.3, the running_ms field was a counter for
+                * the number of running tests.  We are looking at this value
+                * to determine if it is a millisecond timestamep (>= 2.3) or a
+                * test counter (< 2.3).  The number 500 is being used for this
+                * barrier as the test counter should never get this high, and
+                * the timestamp should never get this low. */
+
+               if (sfwk_new->running_ms > 500) {
+                       /* use the timestamp from the remote node, not our
+                        * rpe_stamp from when we copied up the data out of
+                        * the kernel */
 
-                delta = tv.tv_sec + (float)tv.tv_usec/1000000;
+                       delta = (float) (sfwk_new->running_ms -
+                                       sfwk_old->running_ms) / 1000;
+               } else {
+                       struct timeval    tv;
+
+                       lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
+                       delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
+               }
 
                 if (!lnet) /* TODO */
                         continue;
@@ -1785,6 +1799,7 @@ jt_lst_stat(int argc, char **argv)
         int                   optidx  = 0;
         int                   timeout = 5; /* default timeout, 5 sec */
         int                   delay   = 5; /* default delay, 5 sec */
+        int                   count   = -1; /* run forever */
         int                   lnet    = 1; /* lnet stat by default */
         int                   bwrt    = 0;
         int                   rdwr    = 0;
@@ -1795,18 +1810,19 @@ jt_lst_stat(int argc, char **argv)
 
         static struct option stat_opts[] =
         {
-                {"timeout", required_argument, 0, 't' },
-                {"delay"  , required_argument, 0, 'd' },
-                {"lnet"   , no_argument,       0, 'l' },
-                {"rpc"    , no_argument,       0, 'c' },
-                {"bw"     , no_argument,       0, 'b' },
-                {"rate"   , no_argument,       0, 'a' },
-                {"read"   , no_argument,       0, 'r' },
-                {"write"  , no_argument,       0, 'w' },
-                {"avg"    , no_argument,       0, 'g' },
-                {"min"    , no_argument,       0, 'n' },
-                {"max"    , no_argument,       0, 'x' },
-                {0,         0,                 0,  0  }
+               {"timeout"   , required_argument, 0, 't' },
+               {"delay"     , required_argument, 0, 'd' },
+               {"count"     , required_argument, 0, 'o' },
+               {"lnet"      , no_argument,      0, 'l' },
+               {"rpc"       , no_argument,      0, 'c' },
+               {"bw"        , no_argument,      0, 'b' },
+               {"rate"      , no_argument,      0, 'a' },
+               {"read"      , no_argument,      0, 'r' },
+               {"write"     , no_argument,      0, 'w' },
+               {"avg"       , no_argument,      0, 'g' },
+               {"min"       , no_argument,      0, 'n' },
+               {"max"       , no_argument,      0, 'x' },
+               {0,            0,                0,  0  }
         };
 
         if (session_key == 0) {
@@ -1816,7 +1832,7 @@ jt_lst_stat(int argc, char **argv)
         }
 
         while (1) {
-                c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
+               c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
 
                 if (c == -1)
                         break;
@@ -1828,6 +1844,9 @@ jt_lst_stat(int argc, char **argv)
                 case 'd':
                         delay = atoi(optarg);
                         break;
+                case 'o':
+                        count = atoi(optarg);
+                        break;
                 case 'l':
                         lnet = 1;
                         break;
@@ -1867,6 +1886,7 @@ jt_lst_stat(int argc, char **argv)
                         }
                         type |= 4;
                         break;
+
                 default:
                         lst_print_usage(argv[0]);
                         return -1;
@@ -1883,6 +1903,15 @@ jt_lst_stat(int argc, char **argv)
                 return -1;
         }
 
+        if (count < -1) {
+            fprintf(stderr, "Invalid count value\n");
+            return -1;
+        }
+
+        /* extra count to get first data point */
+        if (count != -1)
+            count++;
+
         CFS_INIT_LIST_HEAD(&head);
 
         while (optind < argc) {
@@ -1893,7 +1922,7 @@ jt_lst_stat(int argc, char **argv)
                 cfs_list_add_tail(&srp->srp_link, &head);
         }
 
-        while (1) {
+        do {
                 time_t  now = time(NULL);
 
                 if (now - last < delay) {
@@ -1914,14 +1943,17 @@ jt_lst_stat(int argc, char **argv)
                                 goto out;
                         }
 
-                        lst_print_stat(srp->srp_name, srp->srp_result,
-                                       idx, lnet, bwrt, rdwr, type);
+                       lst_print_stat(srp->srp_name, srp->srp_result,
+                                      idx, lnet, bwrt, rdwr, type);
 
                         lst_reset_rpcent(&srp->srp_result[1 - idx]);
                 }
 
                 idx = 1 - idx;
-        }
+
+                if (count > 0)
+                        count--;
+        } while (count == -1 || count > 0);
 
 out:
         while (!cfs_list_empty(&head)) {
@@ -1996,7 +2028,7 @@ jt_lst_show_error(int argc, char **argv)
         cfs_list_for_each_entry_typed(srp, &head, lst_stat_req_param_t,
                                       srp_link) {
                 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
-                                    srp->srp_ids, 5, &srp->srp_result[0]);
+                                    srp->srp_ids, 10, &srp->srp_result[0]);
 
                 if (rc == -1) {
                         lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
@@ -3137,9 +3169,9 @@ static command_t lst_cmdlist[] = {
          "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]"            },
         {"list_group",          jt_lst_list_group,      NULL,
           "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..."    },
-        {"stat",                jt_lst_stat,            NULL,
-         "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
-         " [--timeout #] [--delay #] GROUP [GROUP]"                                     },
+       {"stat",                jt_lst_stat,            NULL,
+        "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
+        " [--timeout #] [--delay #] [--count #] GROUP [GROUP]"                         },
         {"show_error",          jt_lst_show_error,      NULL,
          "Usage: lst show_error NAME | IDS ..."                                         },
         {"add_batch",           jt_lst_add_batch,       NULL,