From: James Simmons Date: Mon, 15 Jul 2019 15:28:32 +0000 (-0400) Subject: LU-9019 libcfs: avoid using HZ and msecs_to_jiffies() X-Git-Tag: 2.12.57~113 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=0c2cc920370e5dcf99e141610020d75082d2898c LU-9019 libcfs: avoid using HZ and msecs_to_jiffies() 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 Reviewed-on: https://review.whamcloud.com/35520 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index c964883..540b4f4 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -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 diff --git a/libcfs/libcfs/fail.c b/libcfs/libcfs/fail.c index 9e564e9..304faae 100644 --- a/libcfs/libcfs/fail.c +++ b/libcfs/libcfs/fail.c @@ -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"); diff --git a/libcfs/libcfs/linux/linux-crypto.c b/libcfs/libcfs/linux/linux-crypto.c index dce1734..42ae8e5 100644 --- a/libcfs/libcfs/linux/linux-crypto.c +++ b/libcfs/libcfs/linux/linux-crypto.c @@ -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; diff --git a/lnet/klnds/o2iblnd/o2iblnd_cb.c b/lnet/klnds/o2iblnd/o2iblnd_cb.c index c6fb08f..49b0709 100644 --- a/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -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); } diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 8784577..be77024 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -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; diff --git a/lnet/lnet/lib-socket.c b/lnet/lnet/lib-socket.c index 4a8bf1a..0c9a640 100644 --- a/lnet/lnet/lib-socket.c +++ b/lnet/lnet/lib-socket.c @@ -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) { diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index 6faf0b8..0a29250 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -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) { diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 6d28079..311d2aa 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -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); diff --git a/lustre/lfsck/lfsck_lib.c b/lustre/lfsck/lfsck_lib.c index 4e96050..cec8577 100644 --- a/lustre/lfsck/lfsck_lib.c +++ b/lustre/lfsck/lfsck_lib.c @@ -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)) diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index bdd70c1..b1da9ec 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -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)); } } diff --git a/lustre/llite/statahead.c b/lustre/llite/statahead.c index 0b75ccc..d2ba2b0 100644 --- a/lustre/llite/statahead.c +++ b/lustre/llite/statahead.c @@ -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); } diff --git a/lustre/lov/lov_io.c b/lustre/lov/lov_io.c index 2fa95f5..d67dfa7 100644 --- a/lustre/lov/lov_io.c +++ b/lustre/lov/lov_io.c @@ -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); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 771f6eb..9167c83 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -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); diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index 2c111b6..cc63705 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -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); diff --git a/lustre/obdclass/integrity.c b/lustre/obdclass/integrity.c index e6d6d85..3895545 100644 --- a/lustre/obdclass/integrity.c +++ b/lustre/obdclass/integrity.c @@ -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); diff --git a/lustre/obdclass/obd_mount_server.c b/lustre/obdclass/obd_mount_server.c index 42af490..99448a2 100644 --- a/lustre/obdclass/obd_mount_server.c +++ b/lustre/obdclass/obd_mount_server.c @@ -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; diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index 163d5b2..b0ff640 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -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) diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 0a7cdee..4c1b96e 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -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)); diff --git a/lustre/osp/osp_precreate.c b/lustre/osp/osp_precreate.c index 66ae03b..b806159 100644 --- a/lustre/osp/osp_precreate.c +++ b/lustre/osp/osp_precreate.c @@ -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; } } diff --git a/lustre/ptlrpc/gss/gss_svc_upcall.c b/lustre/ptlrpc/gss/gss_svc_upcall.c index 96ffd1b..58eb5e4 100644 --- a/lustre/ptlrpc/gss/gss_svc_upcall.c +++ b/lustre/ptlrpc/gss/gss_svc_upcall.c @@ -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) diff --git a/lustre/ptlrpc/sec.c b/lustre/ptlrpc/sec.c index f0e7e1f..068bfd3 100644 --- a/lustre/ptlrpc/sec.c +++ b/lustre/ptlrpc/sec.c @@ -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);