1 #ifndef ROS_KERN_TIME_H
2 #define ROS_KERN_TIME_H
4 #include <ros/common.h>
9 void udelay(uint64_t usec); /* done in arch-specific files */
10 void udelay_sched(uint64_t usec);
11 uint64_t tsc2sec(uint64_t tsc_time);
12 uint64_t tsc2msec(uint64_t tsc_time);
13 uint64_t tsc2usec(uint64_t tsc_time);
14 uint64_t tsc2nsec(uint64_t tsc_time);
15 uint64_t sec2tsc(uint64_t sec);
16 uint64_t msec2tsc(uint64_t msec);
17 uint64_t usec2tsc(uint64_t usec);
18 uint64_t nsec2tsc(uint64_t nsec);
19 uint64_t epoch_tsc(void);
20 uint64_t epoch_sec(void);
21 uint64_t epoch_msec(void);
22 uint64_t epoch_usec(void);
23 uint64_t epoch_nsec(void);
24 void tsc2timespec(uint64_t tsc_time, struct timespec *ts);
26 /* Just takes a time measurement. Meant to be paired with stop_timing. Use
27 * this if you don't want to muck with overheads or subtraction. */
28 static inline __attribute__((always_inline))
29 uint64_t start_timing(void)
31 return read_tsc_serialized();
34 /* Takes a time measurement and subtracts the start time and timing overhead,
35 * to return the detected elapsed time. Use this if you don't want to muck
36 * with overheads or subtraction. */
37 static inline __attribute__((always_inline))
38 uint64_t stop_timing(uint64_t start_time)
40 uint64_t diff = read_tsc_serialized();
42 diff -= system_timing.timing_overhead;
43 if ((int64_t) diff < 0) {
49 static inline __attribute__((always_inline))
52 return tsc2nsec(read_tsc());
56 /* Ancient measurement crap below. TODO: use or lose it */
62 #define TIMER_TAG_SIZE 20
65 * This struct is used to keep track of counter values as they are spread
66 * throughput code and timing measurements are made calling TAGGED_TIMING_BEGIN
67 * and TAGGED_TIMING_END
72 char label[TIMER_TAG_SIZE];
75 #define TAGGED_TIMING_BEGIN(tag) \
76 static timer_t* _timer_##tag = NULL; \
77 if (_timer_##tag == NULL) { \
78 _timer_##tag = POOL_GET(&timer_pool); \
79 strcpy((_timer_##tag->label), #tag); \
80 _timer_##tag->aggr_run = 0; \
82 _timer_##tag->curr_run = start_timing();
83 #define TAGGED_TIMING_END(tag) \
85 _timer_##tag->curr_run = stop_timing(_timer_##tag->curr_run); \
86 _timer_##tag->aggr_run += _timer_##tag->curr_run; \
90 #endif /* ROS_KERN_TIME_H */