From owner-svn-src-head@freebsd.org Thu Jul 13 18:27:24 2017 Return-Path: Delivered-To: svn-src-head@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 42A8EDAAF04; Thu, 13 Jul 2017 18:27:24 +0000 (UTC) (envelope-from markj@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 0C11A84117; Thu, 13 Jul 2017 18:27:23 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v6DIRNSE010894; Thu, 13 Jul 2017 18:27:23 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v6DIRNpE010893; Thu, 13 Jul 2017 18:27:23 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201707131827.v6DIRNpE010893@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 13 Jul 2017 18:27:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r320956 - head/sys/compat/linuxkpi/common/include/linux X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/sys/compat/linuxkpi/common/include/linux X-SVN-Commit-Revision: 320956 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jul 2017 18:27:24 -0000 Author: markj Date: Thu Jul 13 18:27:22 2017 New Revision: 320956 URL: https://svnweb.freebsd.org/changeset/base/320956 Log: Add some functions to jiffies.h. Also add some checks for overflow to existing functions. Reviewed by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D11533 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 Thu Jul 13 17:37:32 2017 (r320955) +++ head/sys/compat/linuxkpi/common/include/linux/jiffies.h Thu Jul 13 18:27:22 2017 (r320956) @@ -68,11 +68,14 @@ timespec_to_jiffies(const struct timespec *ts) } static inline int -msecs_to_jiffies(const u64 msec) +msecs_to_jiffies(uint64_t msec) { - u64 result; + uint64_t msec_max, result; - result = howmany(msec * (u64)hz, 1000ULL); + msec_max = -1ULL / (uint64_t)hz; + if (msec > msec_max) + msec = msec_max; + result = howmany(msec * (uint64_t)hz, 1000ULL); if (result > MAX_JIFFY_OFFSET) result = MAX_JIFFY_OFFSET; @@ -80,27 +83,61 @@ msecs_to_jiffies(const u64 msec) } static inline int -usecs_to_jiffies(const u64 u) +usecs_to_jiffies(uint64_t usec) { - u64 result; + uint64_t usec_max, result; - result = howmany(u * (u64)hz, 1000000ULL); + usec_max = -1ULL / (uint64_t)hz; + if (usec > usec_max) + usec = usec_max; + result = howmany(usec * (uint64_t)hz, 1000000ULL); if (result > MAX_JIFFY_OFFSET) result = MAX_JIFFY_OFFSET; return ((int)result); } -static inline u64 -nsecs_to_jiffies(const u64 n) +static inline uint64_t +nsecs_to_jiffies64(uint64_t nsec) { + uint64_t nsec_max, result; + + nsec_max = -1ULL / (uint64_t)hz; + if (nsec > nsec_max) + nsec = nsec_max; + result = howmany(nsec * (uint64_t)hz, 1000000000ULL); + if (result > MAX_JIFFY_OFFSET) + result = MAX_JIFFY_OFFSET; + + return (result); +} + +static inline uint64_t +nsecs_to_jiffies(uint64_t n) +{ + return (usecs_to_jiffies(howmany(n, 1000ULL))); } -static inline u64 +static inline uint64_t +jiffies_to_nsecs(int j) +{ + + return ((1000000000ULL / hz) * (uint64_t)(unsigned int)j); +} + +static inline uint64_t +jiffies_to_usecs(int j) +{ + + return ((1000000ULL / hz) * (uint64_t)(unsigned int)j); +} + +static inline uint64_t get_jiffies_64(void) { - return ((u64)(unsigned)ticks); + + return ((uint64_t)(unsigned int)ticks); } static inline int