6 * To use the Pentium RDTSC timer
7 * define TIMING_USE_RDTSC when including
9 #define TIMING_USE_RDTSC
13 #ifdef TIMING_USE_RDTSC
15 typedef unsigned __int64 timing_ticks_t;
17 __inline timing_ticks_t __timing_ticks(void) { __asm { rdtsc } }
19 #define timing_ticks(t) ((t) = __timing_ticks())
20 #define timing_ticks_init(t) ((t) = 0)
21 #define timing_ticks_cmp(a, b, cmp) ((a) cmp (b))
22 #define timing_ticks_sub(r, a) ((r) = (r) - (a))
23 #define timing_ticks_add(r, a) ((r) = (r) + (a))
24 #define timing_ticks_ulong(t) ((unsigned long) (t))
25 #define timing_ticks_dbl(t) ((double) (t))
28 #error NOT IMPLEMENTED YET
29 #endif /* TIMING_USE_RDTSC */
35 #else /* POSIX/Linux stuff */
41 /* define GNU macro for processor affinity stuff if on linux */
42 #if defined __linux__ && !defined __USE_GNU
48 #ifdef _POSIX_PRIORITY_SCHEDULING
49 struct sched_param params;
57 /* only use rdtsc on GNU C with x86 */
58 #if defined TIMING_USE_RDTSC && defined __GNUC__ && defined __i386__
60 typedef unsigned long long timing_ticks_t;
61 #define timing_ticks(t) __asm__ __volatile__ ("rdtsc" : "=A" (t))
62 #define timing_ticks_init(t) ((t) = 0)
63 #define timing_ticks_cmp(a, b, cmp) ((a) cmp (b))
64 #define timing_ticks_sub(r, a) ((r) = (r) - (a))
65 #define timing_ticks_add(r, a) ((r) = (r) + (a))
66 #define timing_ticks_ulong(t) ((unsigned long) (t))
67 #define timing_ticks_dbl(t) ((double) (t))
71 typedef struct timeval timing_ticks_t;
72 #define timing_ticks(t) (gettimeofday(&(t), NULL))
73 #define timing_ticks_init(t) ((t).tv_sec = 0, (t).tv_usec = 0)
76 * This shamelessly stolen and modified from glibc's
77 * /usr/include/sys/time.h
79 #define timing_ticks_cmp(a, b, CMP) \
80 (((a).tv_sec == (b).tv_sec) ? \
81 ((a).tv_usec CMP (b).tv_usec) : \
82 ((a).tv_sec CMP (b).tv_sec))
84 #define timing_ticks_add(r, a) \
86 (r).tv_sec = (r).tv_sec + (a).tv_sec; \
87 (r).tv_usec = (r).tv_usec + (a).tv_usec; \
88 if ((r).tv_usec >= 1000000) { \
90 (r).tv_usec -= 1000000; \
94 #define timing_ticks_sub(r, a) \
96 (r).tv_sec = (r).tv_sec - (a).tv_sec; \
97 (r).tv_usec = (r).tv_usec - (a).tv_usec; \
98 if ((r).tv_usec < 0) { \
100 (r).tv_usec += 1000000; \
104 #define timing_ticks_ulong(t) ((unsigned long) ((t).tv_usec + 1000000 * (t).tv_sec))
105 #define timing_ticks_dbl(t) (((t).tv_usec + 1000000.0 * (t).tv_sec))
107 #endif /* TIMING_USE_RDTSC ... */
112 * Set the current schedule parameters.
113 * @return 1, if succeeded, 0 if not (see errno, for details).
115 int timing_sched_set(const timing_sched_env_t *env);
118 * Get the schedule parameters.
119 * @return 1, if succeeded, 0 if not (see errno, for details).
121 timing_sched_env_t *timing_sched_get(timing_sched_env_t *env);
124 * Prepare schedule parameters which limit the process on one CPU
125 * and set the maximum task priority.
126 * @return The paramter @p env.
128 timing_sched_env_t *timing_sched_prepare_max_prio(timing_sched_env_t *env);
130 #endif /* _TICKS_H */