*/
static inline unsigned long long __cfs_fs_time_flat(cfs_fs_time_t *t)
{
- return (unsigned long long)t->tv_sec * ONE_BILLION + t->tv_nsec;
+ return (unsigned long long)t->tv_sec * NSEC_PER_SEC + t->tv_nsec;
}
return __cfs_fs_time_flat(t1) <= __cfs_fs_time_flat(t2);
}
-#if 0
-static inline cfs_duration_t cfs_duration_build(int64_t nano)
-{
-#if (BITS_PER_LONG == 32)
- /* We cannot use do_div(t, ONE_BILLION), do_div can only process
- * 64 bits n and 32 bits base */
- int64_t t = nano * HZ;
- do_div(t, 1000);
- do_div(t, 1000000);
- return (cfs_duration_t)t;
-#else
- return (nano * HZ / ONE_BILLION);
-#endif
-}
-#endif
-
static inline cfs_duration_t cfs_time_seconds(int seconds)
{
- return ((cfs_duration_t)seconds) * HZ;
+
+ return ((cfs_duration_t)seconds) * msecs_to_jiffies(MSEC_PER_SEC);
}
static inline time_t cfs_duration_sec(cfs_duration_t d)
{
- return d / HZ;
+
+ return d / msecs_to_jiffies(MSEC_PER_SEC);
}
static inline void cfs_duration_usec(cfs_duration_t d, struct timeval *s)
{
-#if (BITS_PER_LONG == 32) && (HZ > 4096)
- __u64 t;
-
- s->tv_sec = d / HZ;
- t = (d - (cfs_duration_t)s->tv_sec * HZ) * ONE_MILLION;
- do_div(t, HZ);
- s->tv_usec = t;
+#if (BITS_PER_LONG == 32)
+ if (msecs_to_jiffies(MSEC_PER_SEC) > 4096) {
+ __u64 t;
+
+ s->tv_sec = d / msecs_to_jiffies(MSEC_PER_SEC);
+ t = (d - (cfs_duration_t)s->tv_sec *
+ msecs_to_jiffies(MSEC_PER_SEC)) * USEC_PER_SEC;
+ do_div(t, msecs_to_jiffies(MSEC_PER_SEC));
+ s->tv_usec = t;
+ } else {
+ s->tv_sec = d / msecs_to_jiffies(MSEC_PER_SEC);
+ s->tv_usec = ((d - (cfs_duration_t)s->tv_sec *
+ msecs_to_jiffies(MSEC_PER_SEC)) *
+ USEC_PER_SEC) / msecs_to_jiffies(MSEC_PER_SEC);
+ }
#else
- s->tv_sec = d / HZ;
- s->tv_usec = ((d - (cfs_duration_t)s->tv_sec * HZ) * \
- ONE_MILLION) / HZ;
+ s->tv_sec = d / msecs_to_jiffies(MSEC_PER_SEC);
+ s->tv_usec = ((d - (cfs_duration_t)s->tv_sec *
+ msecs_to_jiffies(MSEC_PER_SEC)) *
+ USEC_PER_SEC) / msecs_to_jiffies(MSEC_PER_SEC);
#endif
}
static inline void cfs_duration_nsec(cfs_duration_t d, struct timespec *s)
{
#if (BITS_PER_LONG == 32)
- __u64 t;
+ __u64 t;
- s->tv_sec = d / HZ;
- t = (d - s->tv_sec * HZ) * ONE_BILLION;
- do_div(t, HZ);
- s->tv_nsec = t;
+ s->tv_sec = d / msecs_to_jiffies(MSEC_PER_SEC);
+ t = (d - s->tv_sec * msecs_to_jiffies(MSEC_PER_SEC)) * NSEC_PER_SEC;
+ do_div(t, msecs_to_jiffies(MSEC_PER_SEC));
+ s->tv_nsec = t;
#else
- s->tv_sec = d / HZ;
- s->tv_nsec = ((d - s->tv_sec * HZ) * ONE_BILLION) / HZ;
+ s->tv_sec = d / msecs_to_jiffies(MSEC_PER_SEC);
+ s->tv_nsec = ((d - s->tv_sec * msecs_to_jiffies(MSEC_PER_SEC)) *
+ NSEC_PER_SEC) / msecs_to_jiffies(MSEC_PER_SEC);
#endif
}
int
libcfs_sock_write (struct socket *sock, void *buffer, int nob, int timeout)
{
- int rc;
- mm_segment_t oldmm = get_fs();
- long ticks = timeout * HZ;
- unsigned long then;
- struct timeval tv;
+ int rc;
+ mm_segment_t oldmm = get_fs();
+ long jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
+ unsigned long then;
+ struct timeval tv;
- LASSERT (nob > 0);
- /* Caller may pass a zero timeout if she thinks the socket buffer is
- * empty enough to take the whole message immediately */
+ LASSERT(nob > 0);
+ /* Caller may pass a zero timeout if she thinks the socket buffer is
+ * empty enough to take the whole message immediately */
for (;;) {
struct kvec iov = {
.msg_flags = (timeout == 0) ? MSG_DONTWAIT : 0
};
- if (timeout != 0) {
- /* Set send timeout to remaining time */
- tv = (struct timeval) {
- .tv_sec = ticks / HZ,
- .tv_usec = ((ticks % HZ) * 1000000) / HZ
- };
+ 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)
+ };
set_fs(KERNEL_DS);
rc = sock_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
(char *)&tv, sizeof(tv));
then = jiffies;
rc = kernel_sendmsg(sock, &msg, &iov, 1, nob);
- ticks -= jiffies - then;
+ jiffies_left -= jiffies - then;
if (rc == nob)
return 0;
return (-ECONNABORTED);
}
- if (ticks <= 0)
+ if (jiffies_left <= 0)
return -EAGAIN;
buffer = ((char *)buffer) + rc;
int
libcfs_sock_read (struct socket *sock, void *buffer, int nob, int timeout)
{
- int rc;
- mm_segment_t oldmm = get_fs();
- long ticks = timeout * HZ;
- unsigned long then;
- struct timeval tv;
+ int rc;
+ mm_segment_t oldmm = get_fs();
+ long jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
+ unsigned long then;
+ struct timeval tv;
- LASSERT (nob > 0);
- LASSERT (ticks > 0);
+ LASSERT(nob > 0);
+ LASSERT(jiffies_left > 0);
- for (;;) {
+ for (;;) {
struct kvec iov = {
.iov_base = buffer,
.iov_len = nob
.msg_flags = 0
};
- /* Set receive timeout to remaining time */
- tv = (struct timeval) {
- .tv_sec = ticks / HZ,
- .tv_usec = ((ticks % HZ) * 1000000) / HZ
- };
+ /* 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)
+ };
set_fs(KERNEL_DS);
rc = sock_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
(char *)&tv, sizeof(tv));
then = jiffies;
rc = kernel_recvmsg(sock, &msg, &iov, 1, nob, 0);
- ticks -= jiffies - then;
+ jiffies_left -= jiffies - then;
if (rc < 0)
return rc;
if (nob == 0)
return 0;
- if (ticks <= 0)
+ if (jiffies_left <= 0)
return -ETIMEDOUT;
}
}