[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [XTF 5/6] time: Add cycles2{n,u,m}sec functions
In order to easily translate CPU cycles to time values add the following helpers: - cycles2nsec() - cycles2usec() - cycles2msec() Signed-off-by: Pawel Wieczorkiewicz <wipawel@xxxxxxxxx> --- common/time.c | 17 +++++++++++++++++ include/xtf/time.h | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/common/time.c b/common/time.c index 3db1f8f..8f73243 100644 --- a/common/time.c +++ b/common/time.c @@ -162,6 +162,23 @@ void msleep(uint64_t t) mspin_sleep(t); } +unsigned long cycles2nsec(uint64_t cycles) +{ + return scale_delta(cycles, + shared_info.vcpu_info[0].time.tsc_to_system_mul, + shared_info.vcpu_info[0].time.tsc_shift); +} + +unsigned long cycles2usec(uint64_t cycles) +{ + return cycles2nsec(cycles) / 1000; +} + +unsigned long cycles2msec(uint64_t cycles) +{ + return cycles2nsec(cycles) / 1000000; +} + /* * Local variables: * mode: C diff --git a/include/xtf/time.h b/include/xtf/time.h index 07fcae5..6aa1efc 100644 --- a/include/xtf/time.h +++ b/include/xtf/time.h @@ -43,10 +43,13 @@ void msleep(uint64_t f); int gettimeofday(struct timeval *tp); - /* This returns the current epoch time */ #define NOW() current_time() +unsigned long cycles2nsec(uint64_t cycles); +unsigned long cycles2usec(uint64_t cycles); +unsigned long cycles2msec(uint64_t cycles); + #endif /* XTF_TIME_H */ /* -- 2.16.6 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |