Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Timer.h
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 
25 #ifndef TIMER_H
26 #define TIMER_H
27 
28 #ifdef __cplusplus
29  extern "C"
30  {
31 #endif
32 
33 
34 
35 #include <stdint.h>
36 #include <stdio.h>
37 #include <sys/time.h>
38 
42 void Timer_set_origin();
43 
48 void Timer_set_offset(long long int offset );
49 
53 void Timer_Init_scale( unsigned int (*real_sleep)(unsigned int) );
54 
58 extern long long int Process_Sync_Offset;
59 
63 extern uint64_t Process_time_origin;
64 
68 extern double Process_timer_second;
69 
74 static inline double Timer_second()
75 {
76  return Process_timer_second;
77 }
78 
79 #if (defined(__GNUC__) || defined(__ICC))
80 
81 static inline void sctk_rdtsc_barrier(void)
82 {
83  asm("mfence");
84  asm("lfence");
85 }
86 
87 #if defined(__ia64__)
88 static inline uint64_t Timer_tsc (void)
89 {
90  //if( Process_Sync_Offset )
91  //printf("\n\nOFF : %d \n",Process_Sync_Offset);
92  unsigned long t;
93  __asm__ volatile ("mov %0=ar%1":"=r" (t):"i" (44));
94  return (uint64_t) t + Process_Sync_Offset - Process_time_origin;
95 }
96 #elif defined(__i686__)
97 static inline uint64_t Timer_tsc (void)
98 {
99 
100 
101  unsigned long long t;
102  sctk_rdtsc_barrier();
103  __asm__ volatile ("rdtsc":"=A" (t));
104  return (uint64_t) t + Process_Sync_Offset - Process_time_origin;
105 }
106 
107 
108 
109 #elif defined(__x86_64__)
110 static inline uint64_t Timer_tsc (void)
111 {
112 
113  unsigned int a;
114  unsigned int d;
115  unsigned long t;
116  sctk_rdtsc_barrier();
117  __asm__ volatile ("rdtsc":"=a" (a), "=d" (d));
118  t = ((unsigned long) a) | (((unsigned long) d) << 32);
119  uint64_t ret = (uint64_t) t + Process_Sync_Offset - Process_time_origin;
120 
121  return ret;
122 }
123 #else
124 #warning "Use get time of day for profiling, interprocess sync will not work !"
125 
126 #include<sys/time.h>
127 
128 static inline uint64_t Timer_tsc (void)
129 {
130  struct timeval tp;
131  gettimeofday (&tp, NULL);
132  return tp.tv_usec + tp.tv_sec * 1000000;
133 }
134 #endif
135 
136 #else
137 #error Compile with GCC or ICC
138 
139 #endif
140 
141 #ifdef __cplusplus
142  }
143 #endif
144 
145 
146 
147 
148 #endif
149 
uint64_t Process_time_origin
The origin of the timer.
Definition: Timer.c:23
void Timer_Init_scale(unsigned int(*real_sleep)(unsigned int))
Timer_Init_scale.
Definition: Timer.c:37
long long int Process_Sync_Offset
The offset of the timer.
Definition: Timer.c:22
double Process_timer_second
A second in the timer scale.
Definition: Timer.c:24
void Timer_set_origin()
Initializes the timer (save current processor timer counter)
Definition: Timer.c:26
void Timer_set_offset(long long int offset)
Sets the offset to apply to timer.
Definition: Timer.c:31
static double Timer_second()
Getter on the current timer scale second.
Definition: Timer.h:74