From owner-svn-src-all@freebsd.org Fri May 13 11:02:03 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BB5F4B39A27; Fri, 13 May 2016 11:02:03 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 728B9132D; Fri, 13 May 2016 11:02:03 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4DB22tH012485; Fri, 13 May 2016 11:02:02 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4DB22QI012484; Fri, 13 May 2016 11:02:02 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201605131102.u4DB22QI012484@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Fri, 13 May 2016 11:02:02 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2016 11:02:03 -0000 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 #include -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) {