Whamcloud - gitweb
LU-5718 lnet: add offset for selftest brw
[fs/lustre-release.git] / lnet / utils / lst.c
index 6ab41a9..a0e7229 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  *
  * Author: Liang Zhen <liangzhen@clusterfs.com>
  */
-
-#define _GNU_SOURCE
-
-#include <libcfs/libcfsutil.h>
+#include <errno.h>
+#include <getopt.h>
+#include <inttypes.h>
+#include <pwd.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <time.h>
+
+#include <libcfs/util/list.h>
+#include <libcfs/util/ioctl.h>
+#include <libcfs/util/parser.h>
 #include <lnet/lnetctl.h>
 #include <lnet/lnetst.h>
-/* NB: these includes are layering violation */
-#include <lustre_ver.h>
-#include <lustre/lustre_idl.h>
+#include <lnet/lnet.h>
+#include <utils/obdctl.h>
 
 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
 static lst_sid_t           session_id;
 static int                 session_key;
 
-#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 6, 50, 0)
-/* assume all nodes can understand feature LST_FEAT_BULK_LEN */
-static unsigned                   session_features = LST_FEATS_MASK;
-#else
-static unsigned                   session_features = LST_FEATS_EMPTY;
-#endif
-
-static lstcon_trans_stat_t trans_stat;
+/* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
+static unsigned                session_features = LST_FEATS_MASK;
+static lstcon_trans_stat_t     trans_stat;
 
 typedef struct list_string {
-        struct list_string *lstr_next;
-        int                 lstr_sz;
-        char                lstr_str[0];
+       struct list_string *lstr_next;
+       int                 lstr_sz;
+       char                lstr_str[0];
 } lstr_t;
 
 #ifndef offsetof
@@ -289,7 +294,7 @@ out:
                                 rc = -1;
                         }
 
-                        (*idspp)[i].pid = LUSTRE_LNET_PID;
+                       (*idspp)[i].pid = LNET_PID_LUSTRE;
                         i++;
                 }
 
@@ -401,33 +406,33 @@ lst_print_error(char *sub, const char *def_format, ...)
 }
 
 void
-lst_free_rpcent(cfs_list_t *head)
+lst_free_rpcent(struct list_head *head)
 {
-        lstcon_rpc_ent_t *ent;
+       lstcon_rpc_ent_t *ent;
 
-        while (!cfs_list_empty(head)) {
-                ent = cfs_list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
+       while (!list_empty(head)) {
+               ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
 
-                cfs_list_del(&ent->rpe_link);
-                free(ent);
-        }
+               list_del(&ent->rpe_link);
+               free(ent);
+       }
 }
 
 void
-lst_reset_rpcent(cfs_list_t *head)
+lst_reset_rpcent(struct list_head *head)
 {
-        lstcon_rpc_ent_t *ent;
+       lstcon_rpc_ent_t *ent;
 
-        cfs_list_for_each_entry_typed(ent, head, lstcon_rpc_ent_t, rpe_link) {
-                ent->rpe_sid      = LST_INVALID_SID;
-                ent->rpe_peer.nid = LNET_NID_ANY;
-                ent->rpe_peer.pid = LNET_PID_ANY;
-                ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
-        }
+       list_for_each_entry(ent, head, rpe_link) {
+               ent->rpe_sid       = LST_INVALID_SID;
+               ent->rpe_peer.nid  = LNET_NID_ANY;
+               ent->rpe_peer.pid  = LNET_PID_ANY;
+               ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
+       }
 }
 
 int
-lst_alloc_rpcent(cfs_list_t *head, int count, int offset)
+lst_alloc_rpcent(struct list_head *head, int count, int offset)
 {
         lstcon_rpc_ent_t *ent;
         int               i;
@@ -441,23 +446,23 @@ lst_alloc_rpcent(cfs_list_t *head, int count, int offset)
 
                 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
 
-                ent->rpe_sid      = LST_INVALID_SID;
-                ent->rpe_peer.nid = LNET_NID_ANY;
-                ent->rpe_peer.pid = LNET_PID_ANY;
-                cfs_list_add(&ent->rpe_link, head);
-        }
+               ent->rpe_sid      = LST_INVALID_SID;
+               ent->rpe_peer.nid = LNET_NID_ANY;
+               ent->rpe_peer.pid = LNET_PID_ANY;
+               list_add(&ent->rpe_link, head);
+       }
 
-        return 0;
+       return 0;
 }
 
 void
-lst_print_transerr(cfs_list_t *head, char *optstr)
+lst_print_transerr(struct list_head *head, char *optstr)
 {
-        lstcon_rpc_ent_t  *ent;
+       lstcon_rpc_ent_t *ent;
 
-        cfs_list_for_each_entry_typed(ent, head, lstcon_rpc_ent_t, rpe_link) {
-                if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
-                        continue;
+       list_for_each_entry(ent, head, rpe_link) {
+               if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
+                       continue;
 
                 if (ent->rpe_rpc_errno != 0) {
                         fprintf(stderr, "%s RPC failed on %s: %s\n",
@@ -480,7 +485,7 @@ int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
                          int *idx, int *count, lstcon_node_ent_t *dents);
 
 int lst_query_batch_ioctl(char *batch, int test, int server,
-                          int timeout, cfs_list_t *head);
+                         int timeout, struct list_head *head);
 
 int
 lst_ioctl(unsigned int opc, void *buf, int len)
@@ -602,7 +607,7 @@ jt_lst_new_session(int argc,  char **argv)
                 if (rc != 0)
                         snprintf(host, sizeof(host), "unknown_host");
 
-                snprintf(buf, LST_NAME_SIZE, "%s@%s", user, host);
+               snprintf(buf, sizeof(buf), "%s@%s", user, host);
                 name = buf;
 
         } else {
@@ -648,7 +653,7 @@ jt_lst_show_session(int argc, char **argv)
        int                 key;
        int                 rc;
 
-       rc = lst_session_info_ioctl(name, LST_NAME_SIZE, &key,
+       rc = lst_session_info_ioctl(name, sizeof(name), &key,
                                    &feats, &sid, &ndinfo);
 
         if (rc != 0) {
@@ -657,8 +662,8 @@ jt_lst_show_session(int argc, char **argv)
                 return -1;
         }
 
-       fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d FEATURES: %x NODES: %d\n",
-               name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
+       fprintf(stdout, "%s ID: %ju@%s, KEY: %d FEATURES: %x NODES: %d\n",
+               name, (uintmax_t)sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
                key, feats, ndinfo.nle_nnode);
 
         return 0;
@@ -716,7 +721,7 @@ jt_lst_end_session(int argc, char **argv)
 
 int
 lst_ping_ioctl(char *str, int type, int timeout,
-               int count, lnet_process_id_t *ids, cfs_list_t *head)
+              int count, lnet_process_id_t *ids, struct list_head *head)
 {
         lstio_debug_args_t args = {0};
 
@@ -778,9 +783,9 @@ lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
 int
 jt_lst_ping(int argc,  char **argv)
 {
-        cfs_list_t         head;
-        lnet_process_id_t *ids = NULL;
-        lstcon_rpc_ent_t  *ent = NULL;
+       struct list_head   head;
+       lnet_process_id_t *ids = NULL;
+       lstcon_rpc_ent_t  *ent = NULL;
         char              *str = NULL;
         int                optidx  = 0;
         int                server  = 0;
@@ -864,7 +869,7 @@ jt_lst_ping(int argc,  char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
         if (rc != 0) {
@@ -887,17 +892,17 @@ jt_lst_ping(int argc,  char **argv)
                 goto out;
         }
 
-        /* ignore RPC errors and framwork errors */
-        cfs_list_for_each_entry_typed(ent, &head, lstcon_rpc_ent_t, rpe_link) {
-                fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
-                        libcfs_id2str(ent->rpe_peer),
-                        lst_node_state2str(ent->rpe_state),
-                        (ent->rpe_state == LST_NODE_ACTIVE ||
-                         ent->rpe_state == LST_NODE_BUSY)?
-                                 (ent->rpe_rpc_errno == 0 ?
-                                         &ent->rpe_payload[0] : "Unknown") :
-                                 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
-        }
+       /* ignore RPC errors and framwork errors */
+       list_for_each_entry(ent, &head, rpe_link) {
+               fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
+                       libcfs_id2str(ent->rpe_peer),
+                       lst_node_state2str(ent->rpe_state),
+                       (ent->rpe_state == LST_NODE_ACTIVE ||
+                        ent->rpe_state == LST_NODE_BUSY) ?
+                               (ent->rpe_rpc_errno == 0 ?
+                                       &ent->rpe_payload[0] : "Unknown") :
+                               "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
+       }
 
 out:
         lst_free_rpcent(&head);
@@ -911,7 +916,7 @@ out:
 
 int
 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
-                    unsigned *featp, cfs_list_t *resultp)
+                    unsigned *featp, struct list_head *resultp)
 {
         lstio_group_nodes_args_t args = {0};
 
@@ -989,7 +994,7 @@ lst_add_group_ioctl (char *name)
 int
 jt_lst_add_group(int argc, char **argv)
 {
-       cfs_list_t         head;
+       struct list_head   head;
        lnet_process_id_t *ids;
        char              *name;
        unsigned           feats = session_features;
@@ -1023,7 +1028,7 @@ jt_lst_add_group(int argc, char **argv)
                return -1;
        }
 
-       CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
        for (i = 2; i < argc; i++) {
                /* parse address list */
@@ -1141,7 +1146,7 @@ jt_lst_del_group(int argc, char **argv)
 
 int
 lst_update_group_ioctl(int opc, char *name, int clean, int count,
-                       lnet_process_id_t *ids, cfs_list_t *resultp)
+                      lnet_process_id_t *ids, struct list_head *resultp)
 {
         lstio_group_update_args_t args = {0};
 
@@ -1160,7 +1165,7 @@ lst_update_group_ioctl(int opc, char *name, int clean, int count,
 int
 jt_lst_update_group(int argc, char **argv)
 {
-        cfs_list_t         head;
+       struct list_head         head;
         lnet_process_id_t *ids = NULL;
         char              *str = NULL;
         char              *grp = NULL;
@@ -1234,7 +1239,7 @@ jt_lst_update_group(int argc, char **argv)
 
         grp = argv[optind];
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
                 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
@@ -1491,27 +1496,27 @@ jt_lst_list_group(int argc, char **argv)
 
 int
 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
-                int timeout, cfs_list_t *resultp)
+               int timeout, struct list_head *resultp)
 {
-        lstio_stat_args_t args = {0};
+       lstio_stat_args_t args = {0};
 
-        args.lstio_sta_key     = session_key;
-        args.lstio_sta_timeout = timeout;
-        args.lstio_sta_nmlen   = strlen(name);
-        args.lstio_sta_namep   = name;
-        args.lstio_sta_count   = count;
-        args.lstio_sta_idsp    = idsp;
-        args.lstio_sta_resultp = resultp;
+       args.lstio_sta_key     = session_key;
+       args.lstio_sta_timeout = timeout;
+       args.lstio_sta_nmlen   = strlen(name);
+       args.lstio_sta_namep   = name;
+       args.lstio_sta_count   = count;
+       args.lstio_sta_idsp    = idsp;
+       args.lstio_sta_resultp = resultp;
 
-        return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
+       return lst_ioctl(LSTIO_STAT_QUERY, &args, sizeof(args));
 }
 
 typedef struct {
-        cfs_list_t              srp_link;
+       struct list_head              srp_link;
         int                     srp_count;
         char                   *srp_name;
         lnet_process_id_t      *srp_ids;
-        cfs_list_t              srp_result[2];
+       struct list_head              srp_result[2];
 } lst_stat_req_param_t;
 
 static void
@@ -1541,8 +1546,8 @@ lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
                 return -ENOMEM;
 
         memset(srp, 0, sizeof(*srp));
-        CFS_INIT_LIST_HEAD(&srp->srp_result[0]);
-        CFS_INIT_LIST_HEAD(&srp->srp_result[1]);
+       INIT_LIST_HEAD(&srp->srp_result[0]);
+       INIT_LIST_HEAD(&srp->srp_result[1]);
 
         rc = lst_get_node_count(LST_OPC_GROUP, name,
                                 &srp->srp_count, NULL);
@@ -1650,129 +1655,134 @@ lst_timeval_diff(struct timeval *tv1,
        return;
 }
 
-void
+static void
 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
-                  lnet_counters_t *lnet_old)
+                 lnet_counters_t *lnet_old, int mbs)
 {
-        float perf;
-        float rate;
-
-        perf = (float)(lnet_new->send_length -
-                       lnet_old->send_length) / (1024 * 1024) / delta;
-        lnet_stat_result.lnet_total_sndperf += perf;
+       float perf;
+       float rate;
+       unsigned int unit_divisor;
 
-        if (lnet_stat_result.lnet_min_sndperf > perf ||
-            lnet_stat_result.lnet_min_sndperf == 0)
-                lnet_stat_result.lnet_min_sndperf = perf;
+       unit_divisor = (mbs) ? (1000 * 1000) : (1024 * 1024);
+       perf = (float)(lnet_new->send_length -
+                      lnet_old->send_length) / unit_divisor / delta;
+       lnet_stat_result.lnet_total_sndperf += perf;
 
-        if (lnet_stat_result.lnet_max_sndperf < perf)
-                lnet_stat_result.lnet_max_sndperf = perf;
+       if (lnet_stat_result.lnet_min_sndperf > perf ||
+           lnet_stat_result.lnet_min_sndperf == 0)
+               lnet_stat_result.lnet_min_sndperf = perf;
 
-        perf = (float)(lnet_new->recv_length -
-                       lnet_old->recv_length) / (1024 * 1024) / delta;
-        lnet_stat_result.lnet_total_rcvperf += perf;
+       if (lnet_stat_result.lnet_max_sndperf < perf)
+               lnet_stat_result.lnet_max_sndperf = perf;
 
-        if (lnet_stat_result.lnet_min_rcvperf > perf ||
-            lnet_stat_result.lnet_min_rcvperf == 0)
-                lnet_stat_result.lnet_min_rcvperf = perf;
+       perf = (float)(lnet_new->recv_length -
+                      lnet_old->recv_length) / unit_divisor / delta;
+       lnet_stat_result.lnet_total_rcvperf += perf;
 
-        if (lnet_stat_result.lnet_max_rcvperf < perf)
-                lnet_stat_result.lnet_max_rcvperf = perf;
+       if (lnet_stat_result.lnet_min_rcvperf > perf ||
+           lnet_stat_result.lnet_min_rcvperf == 0)
+               lnet_stat_result.lnet_min_rcvperf = perf;
 
-        rate = (lnet_new->send_count - lnet_old->send_count) / delta;
-        lnet_stat_result.lnet_total_sndrate += rate;
+       if (lnet_stat_result.lnet_max_rcvperf < perf)
+               lnet_stat_result.lnet_max_rcvperf = perf;
 
-        if (lnet_stat_result.lnet_min_sndrate > rate ||
-            lnet_stat_result.lnet_min_sndrate == 0)
-                lnet_stat_result.lnet_min_sndrate = rate;
+       rate = (lnet_new->send_count - lnet_old->send_count) / delta;
+       lnet_stat_result.lnet_total_sndrate += rate;
 
-        if (lnet_stat_result.lnet_max_sndrate < rate)
-                lnet_stat_result.lnet_max_sndrate = rate;
+       if (lnet_stat_result.lnet_min_sndrate > rate ||
+           lnet_stat_result.lnet_min_sndrate == 0)
+               lnet_stat_result.lnet_min_sndrate = rate;
 
-        rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
-        lnet_stat_result.lnet_total_rcvrate += rate;
+       if (lnet_stat_result.lnet_max_sndrate < rate)
+               lnet_stat_result.lnet_max_sndrate = rate;
 
-        if (lnet_stat_result.lnet_min_rcvrate > rate ||
-            lnet_stat_result.lnet_min_rcvrate == 0)
-                lnet_stat_result.lnet_min_rcvrate = rate;
+       rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
+       lnet_stat_result.lnet_total_rcvrate += rate;
 
-        if (lnet_stat_result.lnet_max_rcvrate < rate)
-                lnet_stat_result.lnet_max_rcvrate = rate;
+       if (lnet_stat_result.lnet_min_rcvrate > rate ||
+           lnet_stat_result.lnet_min_rcvrate == 0)
+               lnet_stat_result.lnet_min_rcvrate = rate;
 
-        lnet_stat_result.lnet_stat_count ++;
+       if (lnet_stat_result.lnet_max_rcvrate < rate)
+               lnet_stat_result.lnet_max_rcvrate = rate;
 
-        lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
-                                            lnet_stat_result.lnet_stat_count;
-        lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
-                                            lnet_stat_result.lnet_stat_count;
+       lnet_stat_result.lnet_stat_count++;
 
-        lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
-                                            lnet_stat_result.lnet_stat_count;
-        lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
-                                            lnet_stat_result.lnet_stat_count;
+       lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
+                                           lnet_stat_result.lnet_stat_count;
+       lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
+                                           lnet_stat_result.lnet_stat_count;
 
+       lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
+                                           lnet_stat_result.lnet_stat_count;
+       lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
+                                           lnet_stat_result.lnet_stat_count;
 }
 
-void
-lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
+static void
+lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type, int mbs)
 {
-        int     start1 = 0;
-        int     end1   = 1;
-        int     start2 = 0;
-        int     end2   = 1;
-        int     i;
-        int     j;
+       int     start1 = 0;
+       int     end1   = 1;
+       int     start2 = 0;
+       int     end2   = 1;
+       int     i;
+       int     j;
+       char   *units;
 
-        if (lnet_stat_result.lnet_stat_count == 0)
-                return;
+       if (lnet_stat_result.lnet_stat_count == 0)
+               return;
 
-        if (bwrt == 1) /* bw only */
-                start1 = 1;
+       units = (mbs) ? "MB/s  " : "MiB/s ";
 
-        if (bwrt == 2) /* rates only */
-                end1 = 0;
+       if (bwrt == 1) /* bw only */
+               start1 = 1;
 
-        if (rdwr == 1) /* recv only */
-                start2 = 1;
+       if (bwrt == 2) /* rates only */
+               end1 = 0;
 
-        if (rdwr == 2) /* send only */
-                end2 = 0;
+       if (rdwr == 1) /* recv only */
+               start2 = 1;
 
-        for (i = start1; i <= end1; i++) {
-                fprintf(stdout, "[LNet %s of %s]\n",
-                        i == 0 ? "Rates" : "Bandwidth", name);
+       if (rdwr == 2) /* send only */
+               end2 = 0;
 
-                for (j = start2; j <= end2; j++) {
-                        fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
+       for (i = start1; i <= end1; i++) {
+               fprintf(stdout, "[LNet %s of %s]\n",
+                       i == 0 ? "Rates" : "Bandwidth", name);
 
-                        if ((type & 1) != 0) {
-                                fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
-                                                         "Avg: %-8.2f MB/s  ",
-                                        lst_lnet_stat_value(i, j, 0));
-                        }
+               for (j = start2; j <= end2; j++) {
+                       fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
 
-                        if ((type & 2) != 0) {
-                                fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
-                                                         "Min: %-8.2f MB/s  ",
-                                        lst_lnet_stat_value(i, j, 1));
-                        }
+                       if ((type & 1) != 0) {
+                               fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
+                                                        "Avg: %-8.2f %s",
+                                       lst_lnet_stat_value(i, j, 0), units);
+                       }
 
-                        if ((type & 4) != 0) {
-                                fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
-                                                         "Max: %-8.2f MB/s",
-                                        lst_lnet_stat_value(i, j, 2));
-                        }
+                       if ((type & 2) != 0) {
+                               fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
+                                                        "Min: %-8.2f %s",
+                                       lst_lnet_stat_value(i, j, 1), units);
+                       }
 
-                        fprintf(stdout, "\n");
-                }
-        }
+                       if ((type & 4) != 0) {
+                               fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
+                                                        "Max: %-8.2f %s",
+                                       lst_lnet_stat_value(i, j, 2), units);
+                       }
+
+                       fprintf(stdout, "\n");
+               }
+       }
 }
 
-void
-lst_print_stat(char *name, cfs_list_t *resultp,
-              int idx, int lnet, int bwrt, int rdwr, int type)
+static void
+lst_print_stat(char *name, struct list_head *resultp,
+              int idx, int lnet, int bwrt, int rdwr, int type,
+              int mbs)
 {
-        cfs_list_t        tmp[2];
+       struct list_head        tmp[2];
         lstcon_rpc_ent_t *new;
         lstcon_rpc_ent_t *old;
         sfw_counters_t   *sfwk_new;
@@ -1784,20 +1794,20 @@ lst_print_stat(char *name, cfs_list_t *resultp,
         float             delta;
         int               errcount = 0;
 
-        CFS_INIT_LIST_HEAD(&tmp[0]);
-        CFS_INIT_LIST_HEAD(&tmp[1]);
+       INIT_LIST_HEAD(&tmp[0]);
+       INIT_LIST_HEAD(&tmp[1]);
 
         memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
 
-        while (!cfs_list_empty(&resultp[idx])) {
-                if (cfs_list_empty(&resultp[1 - idx])) {
+       while (!list_empty(&resultp[idx])) {
+               if (list_empty(&resultp[1 - idx])) {
                         fprintf(stderr, "Group is changed, re-run stat\n");
                         break;
                 }
 
-                new = cfs_list_entry(resultp[idx].next, lstcon_rpc_ent_t,
+               new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
                                      rpe_link);
-                old = cfs_list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
+               old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
                                      rpe_link);
 
                 /* first time get stats result, can't calculate diff */
@@ -1810,11 +1820,11 @@ lst_print_stat(char *name, cfs_list_t *resultp,
                         break;
                 }
 
-                cfs_list_del(&new->rpe_link);
-                cfs_list_add_tail(&new->rpe_link, &tmp[idx]);
+               list_del(&new->rpe_link);
+               list_add_tail(&new->rpe_link, &tmp[idx]);
 
-                cfs_list_del(&old->rpe_link);
-                cfs_list_add_tail(&old->rpe_link, &tmp[1 - idx]);
+               list_del(&old->rpe_link);
+               list_add_tail(&old->rpe_link, &tmp[1 - idx]);
 
                 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
                     old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
@@ -1852,44 +1862,44 @@ lst_print_stat(char *name, cfs_list_t *resultp,
                        delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
                }
 
-                if (!lnet) /* TODO */
-                        continue;
+               if (!lnet) /* TODO */
+                       continue;
 
-                lst_cal_lnet_stat(delta, lnet_new, lnet_old);
-        }
+               lst_cal_lnet_stat(delta, lnet_new, lnet_old, mbs);
+       }
 
-        cfs_list_splice(&tmp[idx], &resultp[idx]);
-        cfs_list_splice(&tmp[1 - idx], &resultp[1 - idx]);
+       list_splice(&tmp[idx], &resultp[idx]);
+       list_splice(&tmp[1 - idx], &resultp[1 - idx]);
 
-        if (errcount > 0)
-                fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
+       if (errcount > 0)
+               fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
 
-        if (!lnet)  /* TODO */
-                return;
+       if (!lnet)  /* TODO */
+               return;
 
-        lst_print_lnet_stat(name, bwrt, rdwr, type);
+       lst_print_lnet_stat(name, bwrt, rdwr, type, mbs);
 }
 
 int
 jt_lst_stat(int argc, char **argv)
 {
-        cfs_list_t            head;
-        lst_stat_req_param_t *srp;
-        time_t                last    = 0;
-        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;
-        int                   type    = -1;
-        int                   idx     = 0;
-        int                   rc;
-        int                   c;
-
-        static struct option stat_opts[] =
-        {
+       struct list_head        head;
+       lst_stat_req_param_t *srp;
+       time_t                last    = 0;
+       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;
+       int                   type    = -1;
+       int                   idx     = 0;
+       int                   rc;
+       int                   c;
+       int                   mbs     = 0; /* report as MB/s */
+
+       static struct option stat_opts[] = {
                {"timeout"   , required_argument, 0, 't' },
                {"delay"     , required_argument, 0, 'd' },
                {"count"     , required_argument, 0, 'o' },
@@ -1902,6 +1912,7 @@ jt_lst_stat(int argc, char **argv)
                {"avg"       , no_argument,      0, 'g' },
                {"min"       , no_argument,      0, 'n' },
                {"max"       , no_argument,      0, 'x' },
+               {"mbs"       , no_argument,      0, 'm' },
                {0,            0,                0,  0  }
         };
 
@@ -1912,7 +1923,8 @@ 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:lcbarwgnxm", stat_opts,
+                               &optidx);
 
                 if (c == -1)
                         break;
@@ -1959,19 +1971,22 @@ jt_lst_stat(int argc, char **argv)
                         }
                         type |= 2;
                         break;
-                case 'x':
-                        if (type == -1) {
-                                type = 4;
-                                break;
-                        }
-                        type |= 4;
-                        break;
-
-                default:
-                        lst_print_usage(argv[0]);
-                        return -1;
-                }
-        }
+               case 'x':
+                       if (type == -1) {
+                               type = 4;
+                               break;
+                       }
+                       type |= 4;
+                       break;
+               case 'm':
+                       mbs = 1;
+                       break;
+
+               default:
+                       lst_print_usage(argv[0]);
+                       return -1;
+               }
+       }
 
         if (optind == argc) {
                 lst_print_usage(argv[0]);
@@ -1992,14 +2007,14 @@ jt_lst_stat(int argc, char **argv)
         if (count != -1)
             count++;
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         while (optind < argc) {
                 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
                 if (rc != 0)
                         goto out;
 
-                cfs_list_add_tail(&srp->srp_link, &head);
+               list_add_tail(&srp->srp_link, &head);
         }
 
         do {
@@ -2009,11 +2024,9 @@ jt_lst_stat(int argc, char **argv)
                         sleep(delay - now + last);
                         time(&now);
                 }
+               last = now;
 
-                last = now;
-
-                cfs_list_for_each_entry_typed(srp, &head, lst_stat_req_param_t,
-                                              srp_link) {
+               list_for_each_entry(srp, &head, srp_link) {
                         rc = lst_stat_ioctl(srp->srp_name,
                                             srp->srp_count, srp->srp_ids,
                                             timeout, &srp->srp_result[idx]);
@@ -2024,10 +2037,10 @@ jt_lst_stat(int argc, char **argv)
                         }
 
                        lst_print_stat(srp->srp_name, srp->srp_result,
-                                      idx, lnet, bwrt, rdwr, type);
+                                      idx, lnet, bwrt, rdwr, type, mbs);
 
-                        lst_reset_rpcent(&srp->srp_result[1 - idx]);
-                }
+                       lst_reset_rpcent(&srp->srp_result[1 - idx]);
+               }
 
                 idx = 1 - idx;
 
@@ -2036,10 +2049,10 @@ jt_lst_stat(int argc, char **argv)
         } while (count == -1 || count > 0);
 
 out:
-        while (!cfs_list_empty(&head)) {
-                srp = cfs_list_entry(head.next, lst_stat_req_param_t, srp_link);
+       while (!list_empty(&head)) {
+               srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
 
-                cfs_list_del(&srp->srp_link);
+               list_del(&srp->srp_link);
                 lst_stat_req_param_free(srp);
         }
 
@@ -2049,7 +2062,7 @@ out:
 int
 jt_lst_show_error(int argc, char **argv)
 {
-        cfs_list_t            head;
+       struct list_head            head;
         lst_stat_req_param_t *srp;
         lstcon_rpc_ent_t     *ent;
         sfw_counters_t       *sfwk;
@@ -2094,18 +2107,17 @@ jt_lst_show_error(int argc, char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         while (optind < argc) {
                 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
                 if (rc != 0)
                         goto out;
 
-                cfs_list_add_tail(&srp->srp_link, &head);
+               list_add_tail(&srp->srp_link, &head);
         }
 
-        cfs_list_for_each_entry_typed(srp, &head, lst_stat_req_param_t,
-                                      srp_link) {
+       list_for_each_entry(srp, &head, srp_link) {
                 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
                                     srp->srp_ids, 10, &srp->srp_result[0]);
 
@@ -2119,8 +2131,7 @@ jt_lst_show_error(int argc, char **argv)
 
                 ecount = 0;
 
-                cfs_list_for_each_entry_typed(ent, &srp->srp_result[0],
-                                              lstcon_rpc_ent_t, rpe_link) {
+               list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
                         if (ent->rpe_rpc_errno != 0) {
                                 ecount ++;
                                 fprintf(stderr, "RPC failure, can't show error on %s\n",
@@ -2163,10 +2174,10 @@ jt_lst_show_error(int argc, char **argv)
                 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
         }
 out:
-        while (!cfs_list_empty(&head)) {
-                srp = cfs_list_entry(head.next, lst_stat_req_param_t, srp_link);
+       while (!list_empty(&head)) {
+               srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
 
-                cfs_list_del(&srp->srp_link);
+               list_del(&srp->srp_link);
                 lst_stat_req_param_free(srp);
         }
 
@@ -2220,7 +2231,7 @@ jt_lst_add_batch(int argc, char **argv)
 }
 
 int
-lst_start_batch_ioctl (char *name, int timeout, cfs_list_t *resultp)
+lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
 {
         lstio_batch_run_args_t args = {0};
 
@@ -2236,7 +2247,7 @@ lst_start_batch_ioctl (char *name, int timeout, cfs_list_t *resultp)
 int
 jt_lst_start_batch(int argc, char **argv)
 {
-        cfs_list_t        head;
+       struct list_head        head;
         char             *batch;
         int               optidx  = 0;
         int               timeout = 0;
@@ -2292,7 +2303,7 @@ jt_lst_start_batch(int argc, char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         rc = lst_alloc_rpcent(&head, count, 0);
         if (rc != 0) {
@@ -2323,7 +2334,7 @@ jt_lst_start_batch(int argc, char **argv)
 }
 
 int
-lst_stop_batch_ioctl(char *name, int force, cfs_list_t *resultp)
+lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
 {
         lstio_batch_stop_args_t args = {0};
 
@@ -2339,7 +2350,7 @@ lst_stop_batch_ioctl(char *name, int force, cfs_list_t *resultp)
 int
 jt_lst_stop_batch(int argc, char **argv)
 {
-        cfs_list_t        head;
+       struct list_head        head;
         char             *batch;
         int               force = 0;
         int               optidx;
@@ -2395,7 +2406,7 @@ jt_lst_stop_batch(int argc, char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         rc = lst_alloc_rpcent(&head, count, 0);
         if (rc != 0) {
@@ -2692,7 +2703,7 @@ loop:
 
 int
 lst_query_batch_ioctl(char *batch, int test, int server,
-                      int timeout, cfs_list_t *head)
+                     int timeout, struct list_head *head)
 {
         lstio_batch_query_args_t args = {0};
 
@@ -2708,12 +2719,12 @@ lst_query_batch_ioctl(char *batch, int test, int server,
 }
 
 void
-lst_print_tsb_verbose(cfs_list_t *head,
+lst_print_tsb_verbose(struct list_head *head,
                       int active, int idle, int error)
 {
         lstcon_rpc_ent_t *ent;
 
-        cfs_list_for_each_entry_typed(ent, head, lstcon_rpc_ent_t, rpe_link) {
+       list_for_each_entry(ent, head, rpe_link) {
                 if (ent->rpe_priv[0] == 0 && active)
                         continue;
 
@@ -2736,7 +2747,7 @@ int
 jt_lst_query_batch(int argc, char **argv)
 {
         lstcon_test_batch_ent_t ent;
-        cfs_list_t              head;
+       struct list_head              head;
         char                   *batch   = NULL;
         time_t                  last    = 0;
         int                     optidx  = 0;
@@ -2833,7 +2844,7 @@ jt_lst_query_batch(int argc, char **argv)
         }
 
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         if (verbose) {
                 rc = lst_info_batch_ioctl(batch, test, server,
@@ -2944,6 +2955,7 @@ lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
         bulk->blk_size  = 4096;
         bulk->blk_opc   = LST_BRW_READ;
         bulk->blk_flags = LST_BRW_CHECK_NONE;
+       bulk->blk_srv_off = bulk->blk_cli_off = 0;
 
         while (i < argc) {
                 if (strcasestr(argv[i], "check=") == argv[i] ||
@@ -2959,8 +2971,10 @@ lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
                                 return -1;
                         }
 
-                } else if (strcasestr(argv[i], "size=") == argv[i] ||
-                         strcasestr(argv[i], "s=") == argv[i]) {
+               } else if (strcasestr(argv[i], "size=") == argv[i] ||
+                          strcasestr(argv[i], "s=") == argv[i]) {
+                       int max_size = sysconf(_SC_PAGESIZE) * LNET_MAX_IOV;
+
                         tok = strchr(argv[i], '=') + 1;
 
                         bulk->blk_size = strtol(tok, &end, 0);
@@ -2977,12 +2991,33 @@ lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
                         else if (*end == 'm' || *end == 'M')
                                 bulk->blk_size *= 1024 * 1024;
 
-                       if (bulk->blk_size > PAGE_CACHE_SIZE * LNET_MAX_IOV) {
+                       if (bulk->blk_size > max_size) {
                                 fprintf(stderr, "Size exceed limitation: %d bytes\n",
                                         bulk->blk_size);
                                 return -1;
                         }
 
+               } else if (strcasestr(argv[i], "off=") == argv[i]) {
+                       int     off;
+
+                       tok = strchr(argv[i], '=') + 1;
+
+                       off = strtol(tok, &end, 0);
+                       /* NB: align with sizeof(__u64) to simplify page
+                        * checking implementation */
+                       if (off < 0 || off % sizeof(__u64) != 0) {
+                               fprintf(stderr,
+                                       "Invalid offset %s/%d, it should be "
+                                       "postive value and multiple of %d\n",
+                                       tok, off, (int)sizeof(__u64));
+                               return -1;
+                       }
+
+                       /* NB: blk_srv_off is reserved so far */
+                       bulk->blk_cli_off = bulk->blk_srv_off = off;
+                       if (end == NULL)
+                               return 0;
+
                 } else if (strcasecmp(argv[i], "read") == 0 ||
                            strcasecmp(argv[i], "r") == 0) {
                         bulk->blk_opc = LST_BRW_READ;
@@ -3048,7 +3083,7 @@ lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
 int
 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
                    int dist, int span, char *sgrp, char *dgrp,
-                   void *param, int plen, int *retp, cfs_list_t *resultp)
+                  void *param, int plen, int *retp, struct list_head *resultp)
 {
         lstio_test_args_t args = {0};
 
@@ -3076,7 +3111,7 @@ lst_add_test_ioctl(char *batch, int type, int loop, int concur,
 int
 jt_lst_add_test(int argc, char **argv)
 {
-        cfs_list_t    head;
+       struct list_head    head;
         char         *batch  = NULL;
         char         *test   = NULL;
         char         *dstr   = NULL;
@@ -3178,7 +3213,7 @@ jt_lst_add_test(int argc, char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
         if (rc != 0) {
@@ -3249,7 +3284,7 @@ static command_t lst_cmdlist[] = {
           "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 #] [--count #] GROUP [GROUP]"                         },
+        " [--mbs] [--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,
@@ -3306,10 +3341,6 @@ main(int argc, char **argv)
 
         setlinebuf(stdout);
 
-        rc = libcfs_arch_init();
-        if (rc < 0)
-                return rc;
-
         rc = lst_initialize();
         if (rc < 0)
                 goto errorout;
@@ -3317,7 +3348,7 @@ main(int argc, char **argv)
         rc = ptl_initialize(argc, argv);
         if (rc < 0)
                 goto errorout;
-        
+
         Parser_init("lst > ", lst_cmdlist);
 
         if (argc != 1)  {
@@ -3328,6 +3359,5 @@ main(int argc, char **argv)
         Parser_commands();
 
 errorout:
-        libcfs_arch_cleanup();
         return rc;
 }