+#include "openvswitch/vlog.h"
+
+VLOG_DEFINE_THIS_MODULE(timeval);
+
+#ifdef _WIN32
+typedef unsigned int clockid_t;
+
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC 1
+#endif
+
+#ifndef CLOCK_REALTIME
+#define CLOCK_REALTIME 2
+#endif
+
+/* Number of 100 ns intervals from January 1, 1601 till January 1, 1970. */
+const static unsigned long long unix_epoch = 116444736000000000;
+#endif /* _WIN32 */
+
+/* Structure set by unixctl time/warp command. */
+struct large_warp {
+ struct unixctl_conn *conn; /* Connection waiting for warp response. */
+ long long int total_warp; /* Total offset to be added to monotonic time. */
+ long long int warp; /* 'total_warp' offset done in steps of 'warp'. */
+ unsigned int main_thread_id; /* Identification for the main thread. */
+};
+
+struct clock {
+ clockid_t id; /* CLOCK_MONOTONIC or CLOCK_REALTIME. */
+
+ /* Features for use by unit tests. Protected by 'mutex'. */
+ struct ovs_mutex mutex;
+ atomic_bool slow_path; /* True if warped or stopped. */
+ struct timespec warp OVS_GUARDED; /* Offset added for unit tests. */
+ bool stopped OVS_GUARDED; /* Disable real-time updates if true. */
+ struct timespec cache OVS_GUARDED; /* Last time read from kernel. */
+ struct large_warp large_warp OVS_GUARDED; /* Connection information waiting
+ for warp response. */
+};
+
+/* Our clocks. */
+static struct clock monotonic_clock; /* CLOCK_MONOTONIC, if available. */
+static struct clock wall_clock; /* CLOCK_REALTIME. */
+
+/* The monotonic time at which the time module was initialized. */
+static long long int boot_time;
+
+/* True only when timeval_dummy_register() is called. */
+static bool timewarp_enabled;
+/* Reference to the seq struct. Threads other than main thread can
+ * wait on timewarp_seq and be waken up when time is warped. */
+static struct seq *timewarp_seq;
+/* Last value of 'timewarp_seq'. */
+DEFINE_STATIC_PER_THREAD_DATA(uint64_t, last_seq, 0);
+
+/* Monotonic time in milliseconds at which to die with SIGALRM (if not
+ * LLONG_MAX). */
+static long long int deadline = LLONG_MAX;
+
+/* Monotonic time, in milliseconds, at which the last call to time_poll() woke
+ * up. */
+DEFINE_STATIC_PER_THREAD_DATA(long long int, last_wakeup, 0);
+
+static void log_poll_interval(long long int last_wakeup);
+static struct rusage *get_recent_rusage(void);
+static int getrusage_thread(struct rusage *);
+static void refresh_rusage(void);
+static void timespec_add(struct timespec *sum,
+ const struct timespec *a, const struct timespec *b);