1 #ifndef ROS_KERN_TIME_H
2 #define ROS_KERN_TIME_H
4 #include <ros/common.h>
7 /* (newlib) Time Value Specification Structures, P1003.1b-1993, p. 261 */
11 time_t tv_sec; /* Seconds */
12 long tv_nsec; /* Nanoseconds */
16 struct timespec it_interval; /* Timer period */
17 struct timespec it_value; /* Timer expiration */
21 time_t tv_sec; /* seconds */
22 time_t tv_usec; /* microseconds */
26 void udelay(uint64_t usec); /* done in arch-specific files */
27 void udelay_sched(uint64_t usec);
28 uint64_t tsc2sec(uint64_t tsc_time);
29 uint64_t tsc2msec(uint64_t tsc_time);
30 uint64_t tsc2usec(uint64_t tsc_time);
31 uint64_t tsc2nsec(uint64_t tsc_time);
32 uint64_t sec2tsc(uint64_t sec);
33 uint64_t msec2tsc(uint64_t msec);
34 uint64_t usec2tsc(uint64_t usec);
35 uint64_t nsec2tsc(uint64_t nsec);
37 /* Just takes a time measurement. Meant to be paired with stop_timing. Use
38 * this if you don't want to muck with overheads or subtraction. */
39 static inline __attribute__((always_inline))
40 uint64_t start_timing(void)
42 return read_tsc_serialized();
45 /* Takes a time measurement and subtracts the start time and timing overhead,
46 * to return the detected elapsed time. Use this if you don't want to muck
47 * with overheads or subtraction. */
48 static inline __attribute__((always_inline))
49 uint64_t stop_timing(uint64_t start_time)
51 uint64_t diff = read_tsc_serialized();
53 diff -= system_timing.timing_overhead;
54 if ((int64_t) diff < 0) {
60 /* Ancient measurement crap below. TODO: use or lose it */
66 #define TIMER_TAG_SIZE 20
69 * This struct is used to keep track of counter values as they are spread
70 * throughput code and timing measurements are made calling TAGGED_TIMING_BEGIN
71 * and TAGGED_TIMING_END
76 char label[TIMER_TAG_SIZE];
79 #define TAGGED_TIMING_BEGIN(tag) \
80 static timer_t* _timer_##tag = NULL; \
81 if (_timer_##tag == NULL) { \
82 _timer_##tag = POOL_GET(&timer_pool); \
83 strcpy((_timer_##tag->label), #tag); \
84 _timer_##tag->aggr_run = 0; \
86 _timer_##tag->curr_run = start_timing();
87 #define TAGGED_TIMING_END(tag) \
89 _timer_##tag->curr_run = stop_timing(_timer_##tag->curr_run); \
90 _timer_##tag->aggr_run += _timer_##tag->curr_run; \
94 #endif /* ROS_KERN_TIME_H */