svn commit: r247452 - head/sys/sys

Alexander Motin mav at FreeBSD.org
Thu Feb 28 10:21:06 UTC 2013


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);


More information about the svn-src-head mailing list