From owner-svn-src-all@FreeBSD.ORG Thu Feb 28 10:21:06 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 16D594B3; Thu, 28 Feb 2013 10:21:06 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id ED824197C; Thu, 28 Feb 2013 10:21:05 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r1SAL5Bn047857; Thu, 28 Feb 2013 10:21:05 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r1SAL5NT047856; Thu, 28 Feb 2013 10:21:05 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201302281021.r1SAL5NT047856@svn.freebsd.org> From: Alexander Motin Date: Thu, 28 Feb 2013 10:21:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r247452 - head/sys/sys 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.14 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: Thu, 28 Feb 2013 10:21:06 -0000 Author: mav Date: Thu Feb 28 10:21:04 2013 New Revision: 247452 URL: http://svnweb.freebsd.org/changeset/base/247452 Log: Introduce sbintime_t type -- the simplified version of struct bintime, using 32.32 fixed point in form of single int64_t. It is much easier to use in cases where additional precision and range of struct bintime is not required. Reviewed by: bde (previous version), davide Modified: head/sys/sys/time.h Modified: head/sys/sys/time.h ============================================================================== --- head/sys/sys/time.h Thu Feb 28 08:19:55 2013 (r247451) +++ head/sys/sys/time.h Thu Feb 28 10:21:04 2013 (r247452) @@ -109,6 +109,37 @@ bintime_mul(struct bintime *bt, u_int x) ((a)->frac cmp (b)->frac) : \ ((a)->sec cmp (b)->sec)) +typedef int64_t sbintime_t; +#define SBT_1S ((sbintime_t)1 << 32) +#define SBT_1M (SBT_1S * 60) +#define SBT_1MS (SBT_1S / 1000) +#define SBT_1US (SBT_1S / 1000000) +#define SBT_1NS (SBT_1S / 1000000000) + +static __inline int +sbintime_getsec(sbintime_t sbt) +{ + + return (sbt >> 32); +} + +static __inline sbintime_t +bttosbt(const struct bintime bt) +{ + + return (((sbintime_t)bt.sec << 32) + (bt.frac >> 32)); +} + +static __inline struct bintime +sbttobt(sbintime_t sbt) +{ + struct bintime bt; + + bt.sec = sbt >> 32; + bt.frac = sbt << 32; + return (bt); +} + /*- * Background information: * @@ -156,6 +187,42 @@ timeval2bintime(const struct timeval *tv /* 18446744073709 = int(2^64 / 1000000) */ bt->frac = tv->tv_usec * (uint64_t)18446744073709LL; } + +static __inline struct timespec +sbttots(sbintime_t sbt) +{ + struct timespec ts; + + ts.tv_sec = sbt >> 32; + ts.tv_nsec = ((uint64_t)1000000000 * (uint32_t)sbt) >> 32; + return (ts); +} + +static __inline sbintime_t +tstosbt(struct timespec ts) +{ + + return (((sbintime_t)ts.tv_sec << 32) + + (ts.tv_nsec * (((uint64_t)1 << 63) / 500000000) >> 32)); +} + +static __inline struct timeval +sbttotv(sbintime_t sbt) +{ + struct timeval tv; + + tv.tv_sec = sbt >> 32; + tv.tv_usec = ((uint64_t)1000000 * (uint32_t)sbt) >> 32; + return (tv); +} + +static __inline sbintime_t +tvtosbt(struct timeval tv) +{ + + return (((sbintime_t)tv.tv_sec << 32) + + (tv.tv_usec * (((uint64_t)1 << 63) / 500000) >> 32)); +} #endif /* __BSD_VISIBLE */ #ifdef _KERNEL @@ -317,6 +384,15 @@ void binuptime(struct bintime *bt); void nanouptime(struct timespec *tsp); void microuptime(struct timeval *tvp); +static __inline sbintime_t +sbinuptime(void) +{ + struct bintime bt; + + binuptime(&bt); + return (bttosbt(bt)); +} + void bintime(struct bintime *bt); void nanotime(struct timespec *tsp); void microtime(struct timeval *tvp); @@ -325,6 +401,15 @@ void getbinuptime(struct bintime *bt); void getnanouptime(struct timespec *tsp); void getmicrouptime(struct timeval *tvp); +static __inline sbintime_t +getsbinuptime(void) +{ + struct bintime bt; + + getbinuptime(&bt); + return (bttosbt(bt)); +} + void getbintime(struct bintime *bt); void getnanotime(struct timespec *tsp); void getmicrotime(struct timeval *tvp);