[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v4 2/7] add current_time function to time manager
this function returns the "epoch" time Signed-off-by: Paul Semel <phentex@xxxxxxxxx> --- Notes: v4: - new patch version common/time.c | 39 +++++++++++++++++++++++++++++++++++++++ include/xtf/time.h | 5 +++++ 2 files changed, 44 insertions(+) diff --git a/common/time.c b/common/time.c index 79abc7e..c1b7cd1 100644 --- a/common/time.c +++ b/common/time.c @@ -4,6 +4,7 @@ #include <arch/barrier.h> #include <arch/lib.h> +#include <arch/div.h> /* This function was taken from mini-os source code */ /* It returns ((delta << shift) * mul_frac) >> 32 */ @@ -70,6 +71,44 @@ uint64_t since_boot_time(void) return system_time; } +static void get_time_info(uint64_t *boot_time, uint64_t *sec, uint32_t *nsec) +{ + uint32_t ver1, ver2; + do { + ver1 = ACCESS_ONCE(shared_info.wc_version); + smp_rmb(); + *boot_time = since_boot_time(); +#if defined(__i386__) + *sec = (uint64_t)ACCESS_ONCE(shared_info.wc_sec); +#else + *sec = ((uint64_t)ACCESS_ONCE(shared_info.wc_sec_hi) << 32) + | ACCESS_ONCE(shared_info.wc_sec); +#endif + *nsec = (uint64_t)ACCESS_ONCE(shared_info.wc_nsec); + smp_rmb(); + ver2 = ACCESS_ONCE(shared_info.wc_version); + smp_rmb(); + } while ( (ver1 & 1) != 0 && ver1 != ver2 ); +} + +/* This function return the epoch time (number of seconds elapsed + * since Juanary 1, 1970) */ +uint64_t current_time(void) +{ + uint32_t nsec; + uint64_t boot_time, sec; + + get_time_info(&boot_time, &sec, &nsec); + +#if defined(__i386__) + divmod64(&boot_time, SEC_TO_NSEC(1)); +#else + boot_time /= SEC_TO_NSEC(1); +#endif + + return sec + boot_time; +} + /* * Local variables: * mode: C diff --git a/include/xtf/time.h b/include/xtf/time.h index 8180e07..e33dc8a 100644 --- a/include/xtf/time.h +++ b/include/xtf/time.h @@ -8,9 +8,14 @@ #include <xtf/types.h> +#define SEC_TO_NSEC(x) ((x) * 1000000000ul) + + /* Time from boot in nanoseconds */ uint64_t since_boot_time(void); +uint64_t current_time(void); + #endif /* XTF_TIME_H */ /* -- 2.16.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |