summaryrefslogtreecommitdiffstats
path: root/src/os_time.h
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-05-11 17:03:17 +0300
committerHanoh Haim <hhaim@cisco.com>2016-05-11 17:03:17 +0300
commitfa7a837fb19af1c1fe4365de3f71467b79c2c865 (patch)
tree2407b27bcfb2123b3a849745a5d0b925ca8b41c1 /src/os_time.h
parent5fe90f4366284608c00c59fab4a2cf19c8058c2e (diff)
another minor optimization - better for low cpu%
Diffstat (limited to 'src/os_time.h')
-rwxr-xr-xsrc/os_time.h39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/os_time.h b/src/os_time.h
index 42be576f..b1d44c03 100755
--- a/src/os_time.h
+++ b/src/os_time.h
@@ -24,19 +24,26 @@ limitations under the License.
#include <stdint.h>
#include <time.h>
-typedef uint64_t hr_time_t; // time in high res tick
-typedef uint32_t hr_time_32_t; // time in high res tick
-typedef double dsec_t; //time in sec double
uint32_t os_get_time_msec();
uint32_t os_get_time_freq();
-static inline double
-usec_to_sec(double usec) {
+static inline double usec_to_sec(double usec) {
return (usec / (1000 * 1000));
}
+typedef uint64_t hr_time_t; // time in high res tick
+typedef uint32_t hr_time_32_t; // time in high res tick
+typedef double dsec_t; //time in sec double
+
+struct COsTimeGlobalData {
+
+ hr_time_t m_start_time;
+ double m_1_div_freq;
+ double m_freq;
+} __attribute__((__aligned__(128)));
+
#ifdef LINUX
@@ -111,26 +118,30 @@ hr_time_t os_get_hr_freq(void);
#endif
+
+extern COsTimeGlobalData timer_gd;
+
+static inline void time_init(){
+ timer_gd.m_start_time = os_get_hr_tick_64();
+ timer_gd.m_freq = (double)os_get_hr_freq();
+ timer_gd.m_1_div_freq = 1.0/(double)os_get_hr_freq();
+}
+
+
/* convert delta time */
static inline hr_time_t ptime_convert_dsec_hr(dsec_t dsec){
- return((hr_time_t)(dsec*(double)os_get_hr_freq()) );
+ return((hr_time_t)(dsec* timer_gd.m_freq) );
}
/* convert delta time */
static inline dsec_t ptime_convert_hr_dsec(hr_time_t hrt){
- return ((dsec_t)((double)hrt/(double)os_get_hr_freq() ));
+ return ((dsec_t)((double)hrt * timer_gd.m_1_div_freq ));
}
-extern hr_time_t start_time;
-
-static inline void time_init(){
- start_time=os_get_hr_tick_64();
-}
-
/* should be fixed , need to move to high rez tick */
static inline dsec_t now_sec(void){
- hr_time_t d=os_get_hr_tick_64() - start_time;
+ hr_time_t d=os_get_hr_tick_64() - timer_gd.m_start_time;
return ( ptime_convert_hr_dsec(d) );
}