Whamcloud - gitweb
LU-9019 selftest: remove remaining cfs_time wrappers 41/31041/3
authorJames Simmons <uja.ornl@yahoo.com>
Thu, 22 Feb 2018 18:00:25 +0000 (13:00 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 3 Mar 2018 04:28:42 +0000 (04:28 +0000)
Remove remaining libcfs time wrappers from lnet selftest. Migrate
crp_stamp to nanoseconds and both timestamps nd_stamp, sn_start to
ktime. The move away from jiffies which can vary on platforms to
something that is the consistent on every node. This will ensure
that the reported results to the user will always be correct.

Test-Parameters: trivial testlist=lnet-selftest

Change-Id: Id8d1b195f690c69635de60dd9b501f6d97f90f4d
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/31041
Tested-by: Jenkins
Reviewed-by: Doug Oucharek <dougso@me.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lnet/include/uapi/linux/lnet/lnetst.h
lnet/selftest/conrpc.c
lnet/selftest/conrpc.h
lnet/selftest/console.c
lnet/selftest/console.h
lnet/selftest/framework.c
lnet/selftest/selftest.h
lnet/selftest/timer.c

index 7bdf186..06d5283 100644 (file)
@@ -65,7 +65,7 @@
 
 struct lst_sid {
        lnet_nid_t      ses_nid;        /* nid of console node */
-       __u64           ses_stamp;      /* time stamp */
+       __s64           ses_stamp;      /* time stamp in milliseconds */
 };                                     /*** session id */
 
 extern struct lst_sid LST_INVALID_SID;
index 96a57f2..56a6bde 100644 (file)
@@ -69,11 +69,11 @@ lstcon_rpc_done(struct srpc_client_rpc *rpc)
        /* not an orphan RPC */
        crpc->crp_finished = 1;
 
-       if (crpc->crp_stamp == 0) {
+       if (crpc->crp_stamp_ns == 0) {
                /* not aborted */
-               LASSERT (crpc->crp_status == 0);
+               LASSERT(crpc->crp_status == 0);
 
-               crpc->crp_stamp  = cfs_time_current();
+               crpc->crp_stamp_ns = ktime_get_ns();
                crpc->crp_status = rpc->crpc_status;
        }
 
@@ -89,19 +89,15 @@ lstcon_rpc_init(struct lstcon_node *nd, int service, unsigned int feats,
                int bulk_npg, int bulk_len, int embedded,
                struct lstcon_rpc *crpc)
 {
+       memset(crpc, 0, sizeof(*crpc));
+
        crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
                                       feats, bulk_npg, bulk_len,
                                       lstcon_rpc_done, (void *)crpc);
        if (crpc->crp_rpc == NULL)
                return -ENOMEM;
 
-       crpc->crp_trans    = NULL;
        crpc->crp_node     = nd;
-       crpc->crp_posted   = 0;
-       crpc->crp_finished = 0;
-       crpc->crp_unpacked = 0;
-       crpc->crp_status   = 0;
-       crpc->crp_stamp    = 0;
        crpc->crp_embedded = embedded;
        INIT_LIST_HEAD(&crpc->crp_link);
 
@@ -292,16 +288,16 @@ lstcon_rpc_trans_abort(struct lstcon_rpc_trans *trans, int error)
                spin_lock(&rpc->crpc_lock);
 
                if (!crpc->crp_posted || /* not posted */
-                   crpc->crp_stamp != 0) { /* rpc done or aborted already */
-                       if (crpc->crp_stamp == 0) {
-                               crpc->crp_stamp = cfs_time_current();
+                   crpc->crp_stamp_ns != 0) { /* rpc done or aborted already */
+                       if (crpc->crp_stamp_ns == 0) {
+                               crpc->crp_stamp_ns = ktime_get_ns();
                                crpc->crp_status = -EINTR;
                        }
                        spin_unlock(&rpc->crpc_lock);
                        continue;
                }
 
-               crpc->crp_stamp  = cfs_time_current();
+               crpc->crp_stamp_ns  = ktime_get_ns();
                crpc->crp_status = error;
 
                spin_unlock(&rpc->crpc_lock);
@@ -312,10 +308,10 @@ lstcon_rpc_trans_abort(struct lstcon_rpc_trans *trans, int error)
                        continue;
 
                nd = crpc->crp_node;
-               if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
+               if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
                        continue;
 
-               nd->nd_stamp = crpc->crp_stamp;
+               nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
                nd->nd_state = LST_NODE_DOWN;
        }
 }
@@ -388,8 +384,8 @@ lstcon_rpc_get_reply(struct lstcon_rpc *crpc, struct srpc_msg **msgpp)
        struct srpc_client_rpc *rpc = crpc->crp_rpc;
        struct srpc_generic_reply *rep;
 
-        LASSERT (nd != NULL && rpc != NULL);
-        LASSERT (crpc->crp_stamp != 0);
+       LASSERT(nd != NULL && rpc != NULL);
+       LASSERT(crpc->crp_stamp_ns != 0);
 
         if (crpc->crp_status != 0) {
                 *msgpp = NULL;
@@ -402,11 +398,11 @@ lstcon_rpc_get_reply(struct lstcon_rpc *crpc, struct srpc_msg **msgpp)
                 crpc->crp_unpacked = 1;
         }
 
-        if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
-                return 0;
+       if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
+               return 0;
 
-        nd->nd_stamp = crpc->crp_stamp;
-        rep = &(*msgpp)->msg_body.reply;
+       nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
+       rep = &(*msgpp)->msg_body.reply;
 
         if (rep->sid.ses_nid == LNET_NID_ANY)
                 nd->nd_state = LST_NODE_UNKNOWN;
@@ -433,7 +429,7 @@ lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans,
        list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
                lstcon_rpc_stat_total(stat, 1);
 
-               LASSERT(crpc->crp_stamp != 0);
+               LASSERT(crpc->crp_stamp_ns != 0);
 
                 error = lstcon_rpc_get_reply(crpc, &rep);
                 if (error != 0) {
@@ -477,9 +473,9 @@ lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
        struct lstcon_rpc *crpc;
        struct srpc_msg *msg;
        struct lstcon_node *nd;
-       cfs_duration_t dur;
        struct timeval tv;
        int error;
+       s64 dur;
 
        LASSERT(head_up != NULL);
 
@@ -497,15 +493,15 @@ lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
 
                ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
 
-               LASSERT(crpc->crp_stamp != 0);
+               LASSERT(crpc->crp_stamp_ns != 0);
 
-                error = lstcon_rpc_get_reply(crpc, &msg);
+               error = lstcon_rpc_get_reply(crpc, &msg);
 
-                nd = crpc->crp_node;
+               nd = crpc->crp_node;
 
-                dur = (cfs_duration_t)cfs_time_sub(crpc->crp_stamp,
-                      (cfs_time_t)console_session.ses_id.ses_stamp);
-               jiffies_to_timeval(dur, &tv);
+               dur = crpc->crp_stamp_ns -
+                     console_session.ses_id.ses_stamp * NSEC_PER_MSEC;
+               tv = ns_to_timeval(dur);
 
                if (copy_to_user(&ent->rpe_peer,
                                 &nd->nd_id, sizeof(struct lnet_process_id)) ||
@@ -1253,12 +1249,12 @@ lstcon_rpc_pinger(void *arg)
                        lstcon_rpc_put(crpc);
                }
 
-                if (nd->nd_state != LST_NODE_ACTIVE)
-                        continue;
+               if (nd->nd_state != LST_NODE_ACTIVE)
+                       continue;
 
-               intv = cfs_duration_sec(jiffies - nd->nd_stamp);
+               intv = ktime_ms_delta(ktime_get(), nd->nd_stamp) / MSEC_PER_SEC;
                if (intv < nd->nd_timeout / 2)
-                        continue;
+                       continue;
 
                rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
                                     trans->tas_features, 0, 0, 1, crpc);
index b341f8e..6eaeaa7 100644 (file)
@@ -70,7 +70,7 @@ struct lstcon_rpc {
        /** RPC is embedded in other structure and can't free it */
        unsigned int             crp_embedded:1;
         int                      crp_status;     /* console rpc errors */
-        cfs_time_t               crp_stamp;      /* replied time stamp */
+       s64                      crp_stamp_ns;   /* replied time stamp */
 };
 
 struct lstcon_rpc_trans {
index 554ce0b..45bcdfa 100644 (file)
@@ -93,13 +93,13 @@ lstcon_node_find(struct lnet_process_id id, struct lstcon_node **ndpp,
 
        ndl = (struct lstcon_ndlink *)(*ndpp + 1);
 
-        ndl->ndl_node = *ndpp;
+       ndl->ndl_node = *ndpp;
 
-        ndl->ndl_node->nd_ref   = 1;
-        ndl->ndl_node->nd_id    = id;
-        ndl->ndl_node->nd_stamp = cfs_time_current();
-        ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
-        ndl->ndl_node->nd_timeout = 0;
+       ndl->ndl_node->nd_ref   = 1;
+       ndl->ndl_node->nd_id    = id;
+       ndl->ndl_node->nd_stamp = ktime_get();
+       ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
+       ndl->ndl_node->nd_timeout = 0;
        memset(&ndl->ndl_node->nd_ping, 0, sizeof(ndl->ndl_node->nd_ping));
 
        /* queued in global hash & list, no refcount is taken by
@@ -1704,11 +1704,11 @@ lstcon_new_session_id(struct lst_sid *sid)
 {
        struct lnet_process_id id;
 
-        LASSERT (console_session.ses_state == LST_SESSION_NONE);
+       LASSERT(console_session.ses_state == LST_SESSION_NONE);
 
-        LNetGetId(1, &id);
-        sid->ses_nid   = id.nid;
-        sid->ses_stamp = cfs_time_current();
+       LNetGetId(1, &id);
+       sid->ses_nid = id.nid;
+       sid->ses_stamp = ktime_get_ns() / NSEC_PER_MSEC;
 }
 
 int
index 001d8f3..d1d9635 100644 (file)
@@ -53,7 +53,7 @@ struct lstcon_node {
         int                  nd_ref;         /* reference count */
         int                  nd_state;       /* state of the node */
         int                  nd_timeout;     /* session timeout */
-        cfs_time_t           nd_stamp;       /* timestamp of last replied RPC */
+       ktime_t                 nd_stamp;       /* last RPC reply timestamp */
        struct lstcon_rpc       nd_ping;        /* ping rpc */
 };
 
index 9709983..7e10c09 100644 (file)
@@ -277,14 +277,14 @@ sfw_init_session(struct sfw_session *sn, struct lst_sid sid,
        atomic_set(&sn->sn_ping_errors, 0);
        strlcpy(&sn->sn_name[0], name, sizeof(sn->sn_name));
 
-        sn->sn_timer_active = 0;
-        sn->sn_id           = sid;
-       sn->sn_features     = features;
-        sn->sn_timeout      = session_timeout;
-        sn->sn_started      = cfs_time_current();
-
-        timer->stt_data = sn;
-        timer->stt_func = sfw_session_expired;
+       sn->sn_timer_active = 0;
+       sn->sn_id = sid;
+       sn->sn_features = features;
+       sn->sn_timeout = session_timeout;
+       sn->sn_started = ktime_get();
+
+       timer->stt_data = sn;
+       timer->stt_func = sfw_session_expired;
        INIT_LIST_HEAD(&timer->stt_list);
 }
 
@@ -395,9 +395,9 @@ sfw_get_stats(struct srpc_stat_reqst *request, struct srpc_stat_reply *reply)
 
         /* send over the msecs since the session was started
          - with 32 bits to send, this is ~49 days */
-       cnt->running_ms      = jiffies_to_msecs(jiffies - sn->sn_started);
-       cnt->brw_errors      = atomic_read(&sn->sn_brw_errors);
-       cnt->ping_errors     = atomic_read(&sn->sn_ping_errors);
+       cnt->running_ms = ktime_ms_delta(ktime_get(), sn->sn_started);
+       cnt->brw_errors = atomic_read(&sn->sn_brw_errors);
+       cnt->ping_errors = atomic_read(&sn->sn_ping_errors);
        cnt->zombie_sessions = atomic_read(&sfw_data.fw_nzombies);
 
        cnt->active_batches = 0;
index 318759a..3f7c295 100644 (file)
@@ -333,7 +333,7 @@ struct sfw_session {
        atomic_t                sn_refcount;
        atomic_t                sn_brw_errors;
        atomic_t                sn_ping_errors;
-       cfs_time_t              sn_started;
+       ktime_t                 sn_started;
 };
 
 #define sfw_sid_equal(sid0, sid1)     ((sid0).ses_nid == (sid1).ses_nid && \
index f4e70bd..3ceec81 100644 (file)
@@ -56,7 +56,7 @@
 static struct st_timer_data {
        spinlock_t              stt_lock;
        /* start time of the slot processed previously */
-       cfs_time_t              stt_prev_slot;
+       time64_t                stt_prev_slot;
        struct list_head        stt_hash[STTIMER_NSLOTS];
        int                     stt_shuttingdown;
        wait_queue_head_t       stt_waitq;
@@ -143,20 +143,20 @@ stt_expire_list(struct list_head *slot, time64_t now)
 }
 
 static int
-stt_check_timers(cfs_time_t *last)
+stt_check_timers(time64_t *last)
 {
        int expired = 0;
        time64_t now;
-        cfs_time_t this_slot;
+       time64_t this_slot;
 
        now = ktime_get_real_seconds();
-        this_slot = now & STTIMER_SLOTTIMEMASK;
+       this_slot = now & STTIMER_SLOTTIMEMASK;
 
        spin_lock(&stt_data.stt_lock);
 
-       while (cfs_time_aftereq(this_slot, *last)) {
+       while (this_slot >= *last) {
                expired += stt_expire_list(STTIMER_SLOT(this_slot), now);
-               this_slot = cfs_time_sub(this_slot, STTIMER_SLOTTIME);
+               this_slot = this_slot - STTIMER_SLOTTIME;
        }
 
        *last = now & STTIMER_SLOTTIMEMASK;