Commit 27d81ace authored by Jian Yu's avatar Jian Yu Committed by Greg Kroah-Hartman

staging: lustre: replace direct LNet HZ access with kernel APIs

On some customers' systems, the kernel was compiled with HZ defined
to 100, instead of 1000. This improves performance for HPC applications.
However, to use these systems with Lustre, customers have to re-build
Lustre for the kernel because Lustre directly uses the defined constant
HZ.

Since kernel 2.6.21, some non-HZ dependent timing APIs become non-
inline functions, which can be used in Lustre codes to replace the
direct HZ access.

These kernel APIs include:
 jiffies_to_msecs()
 jiffies_to_usecs()
 jiffies_to_timespec()
 msecs_to_jiffies()
 usecs_to_jiffies()
 timespec_to_jiffies()

And here are some samples of the replacement:
 HZ            -> msecs_to_jiffies(MSEC_PER_SEC)
 n * HZ        -> msecs_to_jiffies(n * MSEC_PER_SEC)
 HZ / n        -> msecs_to_jiffies(MSEC_PER_SEC / n)
 n / HZ        -> jiffies_to_msecs(n) / MSEC_PER_SEC
 n / HZ * 1000 -> jiffies_to_msecs(n)

This patch replaces the direct HZ access in lnet module.
Signed-off-by: default avatarJian Yu <jian.yu@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5443Reviewed-by: default avatarNathaniel Clark <nathaniel.l.clark@intel.com>
Reviewed-by: default avatarJames Simmons <uja.ornl@gmail.com>
Reviewed-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 933d36ba
...@@ -691,7 +691,8 @@ kiblnd_send_keepalive(kib_conn_t *conn) ...@@ -691,7 +691,8 @@ kiblnd_send_keepalive(kib_conn_t *conn)
{ {
return (*kiblnd_tunables.kib_keepalive > 0) && return (*kiblnd_tunables.kib_keepalive > 0) &&
cfs_time_after(jiffies, conn->ibc_last_send + cfs_time_after(jiffies, conn->ibc_last_send +
*kiblnd_tunables.kib_keepalive * HZ); msecs_to_jiffies(*kiblnd_tunables.kib_keepalive *
MSEC_PER_SEC));
} }
static inline int static inline int
......
...@@ -1147,7 +1147,9 @@ kiblnd_queue_tx_locked(kib_tx_t *tx, kib_conn_t *conn) ...@@ -1147,7 +1147,9 @@ kiblnd_queue_tx_locked(kib_tx_t *tx, kib_conn_t *conn)
LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED); LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED);
tx->tx_queued = 1; tx->tx_queued = 1;
tx->tx_deadline = jiffies + (*kiblnd_tunables.kib_timeout * HZ); tx->tx_deadline = jiffies +
msecs_to_jiffies(*kiblnd_tunables.kib_timeout *
MSEC_PER_SEC);
if (!tx->tx_conn) { if (!tx->tx_conn) {
kiblnd_conn_addref(conn); kiblnd_conn_addref(conn);
...@@ -3188,7 +3190,7 @@ kiblnd_connd(void *arg) ...@@ -3188,7 +3190,7 @@ kiblnd_connd(void *arg)
kiblnd_data.kib_peer_hash_size; kiblnd_data.kib_peer_hash_size;
} }
deadline += p * HZ; deadline += msecs_to_jiffies(p * MSEC_PER_SEC);
spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags); spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);
} }
......
...@@ -2011,8 +2011,10 @@ LNetCtl(unsigned int cmd, void *arg) ...@@ -2011,8 +2011,10 @@ LNetCtl(unsigned int cmd, void *arg)
case IOC_LIBCFS_NOTIFY_ROUTER: case IOC_LIBCFS_NOTIFY_ROUTER:
secs_passed = (ktime_get_real_seconds() - data->ioc_u64[0]); secs_passed = (ktime_get_real_seconds() - data->ioc_u64[0]);
secs_passed *= msecs_to_jiffies(MSEC_PER_SEC);
return lnet_notify(NULL, data->ioc_nid, data->ioc_flags, return lnet_notify(NULL, data->ioc_nid, data->ioc_flags,
jiffies - secs_passed * HZ); jiffies - secs_passed);
case IOC_LIBCFS_LNET_DIST: case IOC_LIBCFS_LNET_DIST:
rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]); rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]);
......
...@@ -262,7 +262,7 @@ int ...@@ -262,7 +262,7 @@ int
lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout) lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout)
{ {
int rc; int rc;
long ticks = timeout * HZ; long jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
unsigned long then; unsigned long then;
struct timeval tv; struct timeval tv;
...@@ -282,10 +282,7 @@ lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout) ...@@ -282,10 +282,7 @@ lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout)
if (timeout) { if (timeout) {
/* Set send timeout to remaining time */ /* Set send timeout to remaining time */
tv = (struct timeval) { jiffies_to_timeval(jiffies_left, &tv);
.tv_sec = ticks / HZ,
.tv_usec = ((ticks % HZ) * 1000000) / HZ
};
rc = kernel_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, rc = kernel_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
(char *)&tv, sizeof(tv)); (char *)&tv, sizeof(tv));
if (rc) { if (rc) {
...@@ -297,7 +294,7 @@ lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout) ...@@ -297,7 +294,7 @@ lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout)
then = jiffies; then = jiffies;
rc = kernel_sendmsg(sock, &msg, &iov, 1, nob); rc = kernel_sendmsg(sock, &msg, &iov, 1, nob);
ticks -= jiffies - then; jiffies_left -= jiffies - then;
if (rc == nob) if (rc == nob)
return 0; return 0;
...@@ -310,7 +307,7 @@ lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout) ...@@ -310,7 +307,7 @@ lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout)
return -ECONNABORTED; return -ECONNABORTED;
} }
if (ticks <= 0) if (jiffies_left <= 0)
return -EAGAIN; return -EAGAIN;
buffer = ((char *)buffer) + rc; buffer = ((char *)buffer) + rc;
...@@ -324,12 +321,12 @@ int ...@@ -324,12 +321,12 @@ int
lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout) lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout)
{ {
int rc; int rc;
long ticks = timeout * HZ; long jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
unsigned long then; unsigned long then;
struct timeval tv; struct timeval tv;
LASSERT(nob > 0); LASSERT(nob > 0);
LASSERT(ticks > 0); LASSERT(jiffies_left > 0);
for (;;) { for (;;) {
struct kvec iov = { struct kvec iov = {
...@@ -341,10 +338,7 @@ lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout) ...@@ -341,10 +338,7 @@ lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout)
}; };
/* Set receive timeout to remaining time */ /* Set receive timeout to remaining time */
tv = (struct timeval) { jiffies_to_timeval(jiffies_left, &tv);
.tv_sec = ticks / HZ,
.tv_usec = ((ticks % HZ) * 1000000) / HZ
};
rc = kernel_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, rc = kernel_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
(char *)&tv, sizeof(tv)); (char *)&tv, sizeof(tv));
if (rc) { if (rc) {
...@@ -355,7 +349,7 @@ lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout) ...@@ -355,7 +349,7 @@ lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout)
then = jiffies; then = jiffies;
rc = kernel_recvmsg(sock, &msg, &iov, 1, nob, 0); rc = kernel_recvmsg(sock, &msg, &iov, 1, nob, 0);
ticks -= jiffies - then; jiffies_left -= jiffies - then;
if (rc < 0) if (rc < 0)
return rc; return rc;
...@@ -369,7 +363,7 @@ lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout) ...@@ -369,7 +363,7 @@ lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout)
if (!nob) if (!nob)
return 0; return 0;
if (ticks <= 0) if (jiffies_left <= 0)
return -ETIMEDOUT; return -ETIMEDOUT;
} }
} }
......
...@@ -1252,7 +1252,7 @@ lstcon_rpc_pinger(void *arg) ...@@ -1252,7 +1252,7 @@ lstcon_rpc_pinger(void *arg)
if (nd->nd_state != LST_NODE_ACTIVE) if (nd->nd_state != LST_NODE_ACTIVE)
continue; continue;
intv = (jiffies - nd->nd_stamp) / HZ; intv = (jiffies - nd->nd_stamp) / msecs_to_jiffies(MSEC_PER_SEC);
if (intv < nd->nd_timeout / 2) if (intv < nd->nd_timeout / 2)
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment