+ t.tv_nsec = (usec % 1000000) * 1000;
+ t.tv_sec = usec / 1000000;
+ return TIME_CHECK(t);
+}
+
+/**
+ * time_from_nsec - convert nanoseconds to a timespec
+ * @nsec: time in nanoseconds
+ *
+ * Example:
+ * // 1/2 second timeout
+ * #define TIMEOUT time_from_nsec(500000000)
+ */
+static inline struct timespec time_from_nsec(uint64_t nsec)
+{
+ struct timespec t;
+
+ t.tv_nsec = nsec % 1000000000;
+ t.tv_sec = nsec / 1000000000;
+ return TIME_CHECK(t);
+}
+
+/**
+ * timespec_to_timeval - convert a timespec to a timeval.
+ * @ts: a timespec.
+ *
+ * Example:
+ * struct timeval tv;
+ *
+ * tv = timespec_to_timeval(time_now());
+ * printf("time = %lu.%06u\n", (long)tv.tv_sec, (int)tv.tv_usec);
+ */
+static inline struct timeval timespec_to_timeval(struct timespec ts)
+{
+ struct timeval tv;
+ tv.tv_sec = ts.tv_sec;
+ tv.tv_usec = ts.tv_nsec / 1000;
+ return tv;
+}
+
+/**
+ * timeval_to_timespec - convert a timeval to a timespec.
+ * @tv: a timeval.
+ *
+ * Example:
+ * struct timeval tv = { 0, 500 };
+ * struct timespec ts;
+ *
+ * ts = timeval_to_timespec(tv);
+ * printf("timespec = %lu.%09lu\n", (long)ts.tv_sec, (long)ts.tv_nsec);
+ */
+static inline struct timespec timeval_to_timespec(struct timeval tv)
+{
+ struct timespec ts;
+ ts.tv_sec = tv.tv_sec;
+ ts.tv_nsec = tv.tv_usec * 1000;
+ return ts;
+}