user/vmm: print RIP and hexdump of RIP[0:16] on failed vmexit handling.
[akaros.git] / kern / include / time.h
index 909742c..ee88e30 100644 (file)
@@ -5,22 +5,66 @@
 #include <arch/time.h>
 #include <ros/procinfo.h>
 
-void train_timing();
+/* Conversion factors */
+#define NSEC_PER_SEC   1000000000L
+#define NSEC_PER_MSEC  1000000L
+#define NSEC_PER_USEC  1000L
+
+void time_init(void);
 void udelay(uint64_t usec);    /* done in arch-specific files */
-uint64_t tsc2sec(uint64_t tsc_time);
-uint64_t tsc2msec(uint64_t tsc_time);
-uint64_t tsc2usec(uint64_t tsc_time);
+
+uint64_t read_persistent_clock(void);  /* arch-specific */
+
 uint64_t tsc2nsec(uint64_t tsc_time);
-uint64_t sec2tsc(uint64_t sec);
-uint64_t msec2tsc(uint64_t msec);
-uint64_t usec2tsc(uint64_t usec);
+static inline uint64_t tsc2usec(uint64_t tsc_time)
+{
+       return tsc2nsec(tsc_time) / NSEC_PER_USEC;
+}
+static inline uint64_t tsc2msec(uint64_t tsc_time)
+{
+       return tsc2nsec(tsc_time) / NSEC_PER_MSEC;
+}
+static inline uint64_t tsc2sec(uint64_t tsc_time)
+{
+       return tsc2nsec(tsc_time) / NSEC_PER_SEC;
+}
+
 uint64_t nsec2tsc(uint64_t nsec);
-uint64_t epoch_tsc(void);
-uint64_t epoch_sec(void);
-uint64_t epoch_msec(void);
-uint64_t epoch_usec(void);
+static inline uint64_t usec2tsc(uint64_t usec)
+{
+       return nsec2tsc(usec * NSEC_PER_USEC);
+}
+static inline uint64_t msec2tsc(uint64_t msec)
+{
+       return nsec2tsc(msec * NSEC_PER_MSEC);
+}
+static inline uint64_t sec2tsc(uint64_t sec)
+{
+       return nsec2tsc(sec * NSEC_PER_SEC);
+}
+
 uint64_t epoch_nsec(void);
-void tsc2timespec(uint64_t tsc_time, struct timespec *ts);
+
+static inline struct timespec nsec2timespec(uint64_t ns)
+{
+       return (struct timespec) {
+               .tv_sec = ns / NSEC_PER_SEC,
+               .tv_nsec = ns % NSEC_PER_SEC
+       };
+}
+
+static inline struct timeval nsec2timeval(uint64_t ns)
+{
+       return (struct timeval) {
+               .tv_sec = ns / NSEC_PER_SEC,
+               .tv_usec = (ns % NSEC_PER_SEC) / NSEC_PER_USEC
+       };
+}
+
+static inline struct timespec tsc2timespec(uint64_t tsc_time)
+{
+       return nsec2timespec(tsc2nsec(tsc_time));
+}
 
 /* Just takes a time measurement.  Meant to be paired with stop_timing.  Use
  * this if you don't want to muck with overheads or subtraction. */