Date: Fri, 13 May 2016 11:02:02 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299656 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <201605131102.u4DB22QI012484@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Fri May 13 11:02:02 2016 New Revision: 299656 URL: https://svnweb.freebsd.org/changeset/base/299656 Log: Implement nsecs_to_jiffies() in the LinuxKPI and while at it streamline the rest of the xxx_to_jiffies() functions to have a constant 64-bit argument and use identical range checks for the result. Specifically preserve msecs_to_jiffies(0) returning 0. See r282743 for further details. MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/jiffies.h Modified: head/sys/compat/linuxkpi/common/include/linux/jiffies.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/jiffies.h Fri May 13 10:59:46 2016 (r299655) +++ head/sys/compat/linuxkpi/common/include/linux/jiffies.h Fri May 13 11:02:02 2016 (r299656) @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,16 +39,6 @@ #include <sys/kernel.h> #include <sys/limits.h> -static inline int -msecs_to_jiffies(int msec) -{ - struct timeval tv; - - tv.tv_sec = msec / 1000; - tv.tv_usec = (msec % 1000) * 1000; - return (tvtohz(&tv) - 1); -} - #define jiffies ticks #define jiffies_64 ticks #define jiffies_to_msecs(x) (((int64_t)(x)) * 1000 / hz) @@ -78,17 +68,35 @@ timespec_to_jiffies(const struct timespe } static inline int -usecs_to_jiffies(const unsigned int u) +msecs_to_jiffies(const u64 msec) { u64 result; - result = ((u64)u * hz + 1000000 - 1) / 1000000; + result = howmany(msec * (u64)hz, 1000ULL); if (result > MAX_JIFFY_OFFSET) result = MAX_JIFFY_OFFSET; return ((int)result); } +static inline int +usecs_to_jiffies(const u64 u) +{ + u64 result; + + result = howmany(u * (u64)hz, 1000000ULL); + if (result > MAX_JIFFY_OFFSET) + result = MAX_JIFFY_OFFSET; + + return ((int)result); +} + +static inline u64 +nsecs_to_jiffies(const u64 n) +{ + return (usecs_to_jiffies(howmany(n, 1000ULL))); +} + static inline u64 get_jiffies_64(void) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605131102.u4DB22QI012484>