6 * To use the Pentium RDTSC timer
7 * define TIMING_USE_RDTSC when including
9 #define TIMING_USE_RDTSC
15 /* define GNU macro for processor affinity stuff if on linux */
16 #if defined __linux__ && !defined __USE_GNU
22 #ifdef _POSIX_PRIORITY_SCHEDULING
23 struct sched_param params;
31 /* only use rdtsc on GNU C with x86 */
32 #if defined TIMING_USE_RDTSC && defined __GNUC__ && defined __i386__
34 typedef unsigned long long timing_ticks_t;
35 #define timing_ticks(t) __asm__ __volatile__ ("rdtsc" : "=A" (t))
36 #define timing_ticks_init(t) ((t) = 0)
37 #define timing_ticks_cmp(a, b, cmp) ((a) cmp (b))
38 #define timing_ticks_sub(r, a) ((r) = (r) - (a))
39 #define timing_ticks_add(r, a) ((r) = (r) + (a))
40 #define timing_ticks_ulong(t) ((unsigned long) (t))
41 #define timing_ticks_dbl(t) ((double) (t))
45 typedef struct timeval timing_ticks_t;
46 #define timing_ticks(t) (gettimeofday(&(t), NULL))
47 #define timing_ticks_init(t) ((t).tv_sec = 0, (t).tv_usec = 0)
50 * This shamelessly stolen and modified from glibc's
51 * /usr/include/sys/time.h
53 #define timing_ticks_cmp(a, b, CMP) \
54 (((a).tv_sec == (b).tv_sec) ? \
55 ((a).tv_usec CMP (b).tv_usec) : \
56 ((a).tv_sec CMP (b).tv_sec))
58 #define timing_ticks_add(r, a) \
60 (r).tv_sec = (r).tv_sec + (a).tv_sec; \
61 (r).tv_usec = (r).tv_usec + (a).tv_usec; \
62 if ((r).tv_usec >= 1000000) { \
64 (r).tv_usec -= 1000000; \
68 #define timing_ticks_sub(r, a) \
70 (r).tv_sec = (r).tv_sec - (a).tv_sec; \
71 (r).tv_usec = (r).tv_usec - (a).tv_usec; \
72 if ((r).tv_usec < 0) { \
74 (r).tv_usec += 1000000; \
78 #define timing_ticks_ulong(t) ((unsigned long) ((t).tv_usec + 1000000 * (t).tv_sec))
79 #define timing_ticks_dbl(t) (((t).tv_usec + 1000000.0 * (t).tv_sec))
81 #endif /* TIMING_USE_RDTSC ... */
84 * Set the current schedule parameters.
85 * @return 1, if succeeded, 0 if not (see errno, for details).
87 int timing_sched_set(const timing_sched_env_t *env);
90 * Get the schedule parameters.
91 * @return 1, if succeeded, 0 if not (see errno, for details).
93 timing_sched_env_t *timing_sched_get(timing_sched_env_t *env);
96 * Prepare schedule parameters which limit the process on one CPU
97 * and set the maximum task priority.
98 * @return The paramter @p env.
100 timing_sched_env_t *timing_sched_prepare_max_prio(timing_sched_env_t *env);
102 #endif /* _TICKS_H */