Whamcloud - gitweb
LU-9019 libcfs: avoid using HZ and msecs_to_jiffies() 20/35520/2
authorJames Simmons <uja.ornl@yahoo.com>
Mon, 15 Jul 2019 15:28:32 +0000 (11:28 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 24 Jul 2019 04:20:45 +0000 (04:20 +0000)
HZ is a constant selected with the configuration of the kernel
and msecs_to_jiffies() is a inline function in jiffies.h. Because
we are out of tree that means prebuilt lustre packages could be
installed on a node with different values which impact the
behavior of the file system. This was addressed earlier but
regression have crept back in. Fix up all those instances by
replacing msec_to_jiffies() and HZ with cfs_time_seconds() which
translates seconds to jiffies with nsec_to_jiffies(). Add to
spelling.txt to avoid new regressions.

Change-Id: Ie13efe83774db498bb5475ed47a057bbd42d47bf
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/35520
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
21 files changed:
contrib/scripts/spelling.txt
libcfs/libcfs/fail.c
libcfs/libcfs/linux/linux-crypto.c
lnet/klnds/o2iblnd/o2iblnd_cb.c
lnet/lnet/api-ni.c
lnet/lnet/lib-socket.c
lustre/ldlm/ldlm_lib.c
lustre/ldlm/ldlm_resource.c
lustre/lfsck/lfsck_lib.c
lustre/llite/llite_lib.c
lustre/llite/statahead.c
lustre/lov/lov_io.c
lustre/mdt/mdt_handler.c
lustre/mgc/mgc_request.c
lustre/obdclass/integrity.c
lustre/obdclass/obd_mount_server.c
lustre/osc/osc_request.c
lustre/osd-ldiskfs/osd_handler.c
lustre/osp/osp_precreate.c
lustre/ptlrpc/gss/gss_svc_upcall.c
lustre/ptlrpc/sec.c

index c964883..540b4f4 100644 (file)
@@ -97,6 +97,7 @@ cfs_time_before_64||ktime_before
 cfs_time_current||jiffies
 cfs_time_current_64||ktime_get
 cfs_time_current_sec||ktime_get_real_seconds
+msecs_to_jiffies|cfs_time_seconds
 DEFINE_TIMER||CFS_DEFINE_TIMER
 DN_MAX_BONUSLEN||DN_BONUS_SIZE(dnodesize)
 DN_OLD_MAX_BONUSLEN||DN_BONUS_SIZE(DNODE_MIN_SIZE)
@@ -123,6 +124,7 @@ lnet_magicversion_t||struct lnet_magicversion
 lnet_ni_status_t||struct lnet_ni_status
 lnet_ping_info_t||struct lnet_ping_info
 lnet_process_id_packed_t||struct lnet_process_id_packed
+HZ||cfs_time_seconds
 LPD64||%lld
 LPLD||%ld
 LPLU||%lu
index 9e564e9..304faae 100644 (file)
@@ -130,7 +130,7 @@ int __cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
                CERROR("cfs_fail_timeout id %x sleeping for %dms\n", id, ms);
                while (ktime_before(ktime_get(), till)) {
                        set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(msecs_to_jiffies(1000) / 10);
+                       schedule_timeout(cfs_time_seconds(1) / 10);
                        set_current_state(TASK_RUNNING);
                        if (!cfs_fail_loc) {
                                CERROR("cfs_fail_timeout interrupted\n");
index dce1734..42ae8e5 100644 (file)
@@ -350,7 +350,7 @@ static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg)
        memset(buf, 0xAD, PAGE_SIZE);
        kunmap(page);
 
-       for (start = jiffies, end = start + msecs_to_jiffies(MSEC_PER_SEC / 4),
+       for (start = jiffies, end = start + cfs_time_seconds(1) / 4,
             bcount = 0; time_before(jiffies, end) && err == 0; bcount++) {
                struct ahash_request *req;
                int i;
index c6fb08f..49b0709 100644 (file)
@@ -3617,7 +3617,7 @@ kiblnd_connd (void *arg)
                                             kiblnd_data.kib_peer_hash_size;
                        }
 
-                       deadline += msecs_to_jiffies(p * MSEC_PER_SEC);
+                       deadline += cfs_time_seconds(p);
                        spin_lock_irqsave(lock, flags);
                }
 
index 8784577..be77024 100644 (file)
@@ -3917,9 +3917,9 @@ LNetCtl(unsigned int cmd, void *arg)
                /* If timeout is negative then set default of 3 minutes */
                if (((s32)data->ioc_u32[1] <= 0) ||
                    data->ioc_u32[1] > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
-                       timeout = msecs_to_jiffies(DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC);
+                       timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
                else
-                       timeout = msecs_to_jiffies(data->ioc_u32[1]);
+                       timeout = nsecs_to_jiffies(data->ioc_u32[1] * NSEC_PER_MSEC);
 
                rc = lnet_ping(id, timeout, data->ioc_pbuf1,
                               data->ioc_plen1 / sizeof(struct lnet_process_id));
@@ -3939,9 +3939,9 @@ LNetCtl(unsigned int cmd, void *arg)
                /* If timeout is negative then set default of 3 minutes */
                if (((s32)ping->op_param) <= 0 ||
                    ping->op_param > (DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC))
-                       timeout = msecs_to_jiffies(DEFAULT_PEER_TIMEOUT * MSEC_PER_SEC);
+                       timeout = cfs_time_seconds(DEFAULT_PEER_TIMEOUT);
                else
-                       timeout = msecs_to_jiffies(ping->op_param);
+                       timeout = nsecs_to_jiffies(ping->op_param * NSEC_PER_MSEC);
 
                rc = lnet_ping(ping->ping_id, timeout,
                               ping->ping_buf,
@@ -4087,7 +4087,7 @@ static int lnet_ping(struct lnet_process_id id, signed long timeout,
        int which;
        int unlinked = 0;
        int replied = 0;
-       const signed long a_long_time = msecs_to_jiffies(60 * MSEC_PER_SEC);
+       const signed long a_long_time = cfs_time_seconds(60);
        struct lnet_ping_buffer *pbuf;
        struct lnet_process_id tmpid;
        int i;
index 4a8bf1a..0c9a640 100644 (file)
@@ -68,7 +68,7 @@ int
 lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout)
 {
        int             rc;
-       long            jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
+       long            jiffies_left = cfs_time_seconds(timeout);
        unsigned long   then;
        struct timeval  tv;
 
@@ -87,15 +87,7 @@ lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout)
 
                if (timeout != 0) {
                        /* Set send timeout to remaining time */
-                       tv = (struct timeval) {
-                               .tv_sec = jiffies_left /
-                                         msecs_to_jiffies(MSEC_PER_SEC),
-                               .tv_usec = ((jiffies_left %
-                                            msecs_to_jiffies(MSEC_PER_SEC)) *
-                                            USEC_PER_SEC) /
-                                            msecs_to_jiffies(MSEC_PER_SEC)
-                       };
-
+                       jiffies_to_timeval(jiffies_left, &tv);
                        rc = kernel_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
                                               (char *)&tv, sizeof(tv));
                        if (rc != 0) {
@@ -135,7 +127,7 @@ int
 lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout)
 {
        int             rc;
-       long            jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
+       long            jiffies_left = cfs_time_seconds(timeout);
        unsigned long   then;
        struct timeval  tv;
 
@@ -152,13 +144,7 @@ lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout)
                };
 
                /* Set receive timeout to remaining time */
-               tv = (struct timeval) {
-                       .tv_sec = jiffies_left / msecs_to_jiffies(MSEC_PER_SEC),
-                       .tv_usec = ((jiffies_left %
-                                       msecs_to_jiffies(MSEC_PER_SEC)) *
-                                       USEC_PER_SEC) /
-                                       msecs_to_jiffies(MSEC_PER_SEC)
-               };
+               jiffies_to_timeval(jiffies_left, &tv);
                rc = kernel_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
                                       (char *)&tv, sizeof(tv));
                if (rc != 0) {
index 6faf0b8..0a29250 100644 (file)
@@ -2144,7 +2144,7 @@ repeat:
 
        while (wait_event_timeout(obd->obd_next_transno_waitq,
                                  check_routine(lut),
-                                 msecs_to_jiffies(60 * MSEC_PER_SEC)) == 0)
+                                 cfs_time_seconds(60)) == 0)
                ; /* wait indefinitely for event, but don't trigger watchdog */
 
        if (obd->obd_abort_recovery) {
index 6d28079..311d2aa 100644 (file)
@@ -1193,8 +1193,8 @@ static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force)
                       ldlm_ns_name(ns), atomic_read(&ns->ns_bref));
 force_wait:
                if (force)
-                       lwi = LWI_TIMEOUT(msecs_to_jiffies(obd_timeout *
-                                         MSEC_PER_SEC) / 4, NULL, NULL);
+                       lwi = LWI_TIMEOUT(cfs_time_seconds(1) / 4,
+                                         NULL, NULL);
 
                rc = l_wait_event(ns->ns_waitq,
                                  atomic_read(&ns->ns_bref) == 0, &lwi);
index 4e96050..cec8577 100644 (file)
@@ -1841,14 +1841,12 @@ bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
        bool dirty = false;
 
        if (limit != LFSCK_SPEED_NO_LIMIT) {
-               if (limit > msecs_to_jiffies(MSEC_PER_SEC)) {
-                       lfsck->li_sleep_rate = limit /
-                                              msecs_to_jiffies(MSEC_PER_SEC);
+               if (limit > cfs_time_seconds(1)) {
+                       lfsck->li_sleep_rate = limit / cfs_time_seconds(1);
                        lfsck->li_sleep_jif = 1;
                } else {
                        lfsck->li_sleep_rate = 1;
-                       lfsck->li_sleep_jif = msecs_to_jiffies(MSEC_PER_SEC) /
-                                             limit;
+                       lfsck->li_sleep_jif = cfs_time_seconds(1) / limit;
                }
        } else {
                lfsck->li_sleep_jif = 0;
@@ -3045,7 +3043,7 @@ again:
        if (unlikely(rc == -EINPROGRESS)) {
                retry = true;
                set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC));
+               schedule_timeout(cfs_time_seconds(1));
                set_current_state(TASK_RUNNING);
                if (!signal_pending(current) &&
                    thread_is_running(&lfsck->li_thread))
index bdd70c1..b1da9ec 100644 (file)
@@ -810,7 +810,7 @@ void ll_kill_super(struct super_block *sb)
                /* wait running statahead threads to quit */
                while (atomic_read(&sbi->ll_sa_running) > 0) {
                        set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC >> 3));
+                       schedule_timeout(cfs_time_seconds(1 >> 3));
                }
        }
 
index 0b75ccc..d2ba2b0 100644 (file)
@@ -1191,8 +1191,7 @@ out:
         * safely because statahead RPC will access sai data */
        while (sai->sai_sent != sai->sai_replied) {
                /* in case we're not woken up, timeout wait */
-               lwi = LWI_TIMEOUT(msecs_to_jiffies(MSEC_PER_SEC >> 3),
-                                 NULL, NULL);
+               lwi = LWI_TIMEOUT(cfs_time_seconds(1) >> 3, NULL, NULL);
                l_wait_event(sa_thread->t_ctl_waitq,
                        sai->sai_sent == sai->sai_replied, &lwi);
        }
index 2fa95f5..d67dfa7 100644 (file)
@@ -451,7 +451,7 @@ static int lov_io_mirror_init(struct lov_io *lio, struct lov_object *obj,
        ++io->ci_ndelay_tried;
        if (io->ci_ndelay && io->ci_ndelay_tried >= comp->lo_mirror_count) {
                set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC)); /* 10ms */
+               schedule_timeout(cfs_time_seconds(1)); /* 10ms */
                if (signal_pending(current))
                        RETURN(-EINTR);
 
index 771f6eb..9167c83 100644 (file)
@@ -3542,7 +3542,7 @@ static int mdt_tgt_connect(struct tgt_session_info *tsi)
            cfs_fail_val ==
            tsi2mdt_info(tsi)->mti_mdt->mdt_seq_site.ss_node_id) {
                set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(msecs_to_jiffies(3 * MSEC_PER_SEC));
+               schedule_timeout(cfs_time_seconds(3));
        }
 
        return tgt_connect(tsi);
index 2c111b6..cc63705 100644 (file)
@@ -641,9 +641,9 @@ static int mgc_requeue_thread(void *data)
                /* Always wait a few seconds to allow the server who
                   caused the lock revocation to finish its setup, plus some
                   random so everyone doesn't try to reconnect at once. */
-               to = msecs_to_jiffies(MGC_TIMEOUT_MIN_SECONDS * MSEC_PER_SEC);
+               to = cfs_time_seconds(MGC_TIMEOUT_MIN_SECONDS);
                /* rand is centi-seconds */
-               to += msecs_to_jiffies(rand * MSEC_PER_SEC / 100);
+               to += cfs_time_seconds(rand) / 100;
                lwi = LWI_TIMEOUT(to, NULL, NULL);
                l_wait_event(rq_waitq, rq_state & (RQ_STOP | RQ_PRECLEANUP),
                             &lwi);
index e6d6d85..3895545 100644 (file)
@@ -227,7 +227,7 @@ static void obd_t10_performance_test(const char *obd_name,
        memset(buf, 0xAD, PAGE_SIZE);
        kunmap(page);
 
-       for (start = jiffies, end = start + msecs_to_jiffies(MSEC_PER_SEC / 4),
+       for (start = jiffies, end = start + cfs_time_seconds(1) / 4,
             bcount = 0; time_before(jiffies, end) && rc == 0; bcount++) {
                rc = __obd_t10_performance_test(obd_name, cksum_type, page,
                                                buf_len / PAGE_SIZE);
index 42af490..99448a2 100644 (file)
@@ -1233,8 +1233,7 @@ again:
                                /* The connection with MGS is not established.
                                 * Try again after 2 seconds. Interruptable. */
                                set_current_state(TASK_INTERRUPTIBLE);
-                               schedule_timeout(
-                                       msecs_to_jiffies(MSEC_PER_SEC) * 2);
+                               schedule_timeout(cfs_time_seconds(2));
                                set_current_state(TASK_RUNNING);
                                if (!signal_pending(current))
                                        goto again;
index 163d5b2..b0ff640 100644 (file)
@@ -902,12 +902,13 @@ static void osc_grant_work_handler(struct work_struct *data)
        if (client_gtd.gtd_stopped == 1)
                return;
 
-       if (next_shrink > ktime_get_seconds())
-               schedule_delayed_work(&work, msecs_to_jiffies(
-                                       (next_shrink - ktime_get_seconds()) *
-                                       MSEC_PER_SEC));
-       else
+       if (next_shrink > ktime_get_seconds()) {
+               time64_t delay = next_shrink - ktime_get_seconds();
+
+               schedule_delayed_work(&work, cfs_time_seconds(delay));
+       } else {
                schedule_work(&work.work);
+       }
 }
 
 void osc_schedule_grant_work(void)
index 0a7cdee..4c1b96e 100644 (file)
@@ -1883,7 +1883,7 @@ static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
                 */
                if (last_credits != oh->ot_credits &&
                    time_after(jiffies, last_printed +
-                              msecs_to_jiffies(60 * MSEC_PER_SEC)) &&
+                              cfs_time_seconds(60)) &&
                    osd_transaction_size(dev) > 512) {
                        CWARN("%s: credits %u > trans_max %u\n", osd_name(dev),
                              oh->ot_credits, osd_transaction_size(dev));
index 66ae03b..b806159 100644 (file)
@@ -1252,8 +1252,7 @@ static int osp_precreate_thread(void *_arg)
                         */
                        rc = osp_precreate_cleanup_orphans(&env, d);
                        if (rc != 0) {
-                               schedule_timeout_interruptible(
-                                       msecs_to_jiffies(MSEC_PER_SEC));
+                               schedule_timeout_interruptible(cfs_time_seconds(1));
                                continue;
                        }
                }
index 96ffd1b..58eb5e4 100644 (file)
@@ -934,10 +934,10 @@ cache_check:
                        read_unlock(&rsi_cache.hash_lock);
 
                        if (valid == 0) {
-                               unsigned long jiffies;
-                               jiffies = msecs_to_jiffies(MSEC_PER_SEC *
-                                         GSS_SVC_UPCALL_TIMEOUT);
-                               schedule_timeout(jiffies);
+                               unsigned long timeout;
+
+                               timeout = cfs_time_seconds(GSS_SVC_UPCALL_TIMEOUT);
+                               schedule_timeout(timeout);
                        }
                        cache_get(&rsip->h);
                        goto cache_check;
@@ -1128,8 +1128,7 @@ int __init gss_init_svc_upcall(void)
                if (atomic_read(&rsi_cache.readers) > 0)
                        break;
                set_current_state(TASK_UNINTERRUPTIBLE);
-               LASSERT(msecs_to_jiffies(MSEC_PER_SEC / 4) > 0);
-               schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC / 4));
+               schedule_timeout(cfs_time_seconds(1) / 4);
        }
 
        if (atomic_read(&rsi_cache.readers) == 0)
index f0e7e1f..068bfd3 100644 (file)
@@ -592,7 +592,7 @@ int sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req)
                       newctx, newctx->cc_flags);
 
                set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC));
+               schedule_timeout(cfs_time_seconds(1));
        } else if (unlikely(test_bit(PTLRPC_CTX_UPTODATE_BIT, &newctx->cc_flags)
                            == 0)) {
                /*
@@ -823,7 +823,7 @@ again:
        req->rq_restart = 0;
        spin_unlock(&req->rq_lock);
 
-       lwi = LWI_TIMEOUT_INTR(msecs_to_jiffies(timeout * MSEC_PER_SEC),
+       lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout),
                               ctx_refresh_timeout,
                               ctx_refresh_interrupt, req);
        rc = l_wait_event(req->rq_reply_waitq, ctx_check_refresh(ctx), &lwi);