summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@samsung.com>2017-10-27 19:19:45 +0300
committerBen Pfaff <blp@ovn.org>2017-10-27 10:51:44 -0700
commitbf168c45b90ae5a23a558ae30f52b46a36890a55 (patch)
tree7e35ee6831bfc54722fabf2a7a6a42e75e3de5ad /lib
parent6f39e18df4e1230be25e2e43bea2cf9fa548142a (diff)
downloadopenvswitch-bf168c45b90ae5a23a558ae30f52b46a36890a55.tar.gz
timeval: Add functions with microsecond granularity.
Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/timeval.c35
-rw-r--r--lib/timeval.h4
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/timeval.c b/lib/timeval.c
index 2c7f43a41..b50ff85a5 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -231,6 +231,29 @@ time_wall_msec(void)
return time_msec__(&wall_clock);
}
+static long long int
+time_usec__(struct clock *c)
+{
+ struct timespec ts;
+
+ time_timespec__(c, &ts);
+ return timespec_to_usec(&ts);
+}
+
+/* Returns a monotonic timer, in microseconds. */
+long long int
+time_usec(void)
+{
+ return time_usec__(&monotonic_clock);
+}
+
+/* Returns the current time, in microseconds. */
+long long int
+time_wall_usec(void)
+{
+ return time_usec__(&wall_clock);
+}
+
/* Configures the program to die with SIGALRM 'secs' seconds from now, if
* 'secs' is nonzero, or disables the feature if 'secs' is zero. */
void
@@ -358,6 +381,18 @@ timeval_to_msec(const struct timeval *tv)
return (long long int) tv->tv_sec * 1000 + tv->tv_usec / 1000;
}
+long long int
+timespec_to_usec(const struct timespec *ts)
+{
+ return (long long int) ts->tv_sec * 1000 * 1000 + ts->tv_nsec / 1000;
+}
+
+long long int
+timeval_to_usec(const struct timeval *tv)
+{
+ return (long long int) tv->tv_sec * 1000 * 1000 + tv->tv_usec;
+}
+
/* Returns the monotonic time at which the "time" module was initialized, in
* milliseconds. */
long long int
diff --git a/lib/timeval.h b/lib/timeval.h
index 7957dadfb..c3dbb5161 100644
--- a/lib/timeval.h
+++ b/lib/timeval.h
@@ -54,6 +54,8 @@ time_t time_now(void);
time_t time_wall(void);
long long int time_msec(void);
long long int time_wall_msec(void);
+long long int time_usec(void);
+long long int time_wall_usec(void);
void time_timespec(struct timespec *);
void time_wall_timespec(struct timespec *);
void time_alarm(unsigned int secs);
@@ -61,7 +63,9 @@ int time_poll(struct pollfd *, int n_pollfds, HANDLE *handles,
long long int timeout_when, int *elapsed);
long long int timespec_to_msec(const struct timespec *);
+long long int timespec_to_usec(const struct timespec *);
long long int timeval_to_msec(const struct timeval *);
+long long int timeval_to_usec(const struct timeval *);
struct tm_msec *localtime_msec(long long int now, struct tm_msec *result);
struct tm_msec *gmtime_msec(long long int now, struct tm_msec *result);