L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
rdtsc.h
Go to the documentation of this file.
1
9/*
10 * (c) 2003-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
11 * Alexander Warg <warg@os.inf.tu-dresden.de>,
12 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
13 * economic rights: Technische Universität Dresden (Germany)
14 * This file is part of TUD:OS and distributed under the terms of the
15 * GNU Lesser General Public License 2.1.
16 * Please see the COPYING-LGPL-2.1 file for details.
17 */
18
19#ifndef __l4_rdtsc_h
20#define __l4_rdtsc_h
21
27#include <l4/sys/compiler.h>
28#include <l4/sys/l4int.h>
29#include <l4/sys/kip.h>
30
32
33/* interface */
39extern l4_uint32_t l4_scaler_tsc_to_ns;
40extern l4_uint32_t l4_scaler_tsc_to_us;
41extern l4_uint32_t l4_scaler_ns_to_tsc;
42extern l4_uint32_t l4_scaler_tsc_linux;
43
49l4_rdtsc (void);
50
58
66l4_rdpmc (int ecx);
67
75
82
89
95L4_INLINE void
97
105
111L4_INLINE void
113
119L4_INLINE void
121
130
146
153
157
158/* implementation */
159
162{
163 return l4_tsc_init(kip);
164}
165
168{
169 l4_umword_t lo, hi;
170
171 __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
172
173 return ((l4_cpu_time_t)hi << 32) | lo;
174}
175
177l4_rdpmc (int ecx)
178{
179 l4_umword_t lo, hi;
180
181 __asm__ __volatile__ ("rdpmc" : "=a"(lo), "=d"(hi) : "c"(ecx));
182
183 return ((l4_cpu_time_t)hi << 32) | lo;
184}
185
188{
189 l4_umword_t lo, hi;
190
191 __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
192
193 return lo;
194}
195
198{
199 l4_umword_t lo, hi;
200
201 __asm__ __volatile__ ("rdpmc" : "=a"(lo), "=d"(hi) : "c"(ecx));
202
203 return lo;
204}
205
208{
209 l4_uint64_t ns, dummy;
210 __asm__
211 (" \n\t"
212 "mulq %3 \n\t"
213 "shrd $27, %%rdx, %%rax \n\t"
214 :"=a" (ns), "=d"(dummy)
215 :"a" (tsc), "r" ((l4_uint64_t)l4_scaler_tsc_to_ns)
216 );
217 return ns;
218}
219
222{
223 l4_uint64_t ns, dummy;
224 __asm__
225 (" \n\t"
226 "mulq %3 \n\t"
227 "shrd $32, %%rdx, %%rax \n\t"
228 :"=a" (ns), "=d" (dummy)
229 :"a" (tsc), "r" ((l4_uint64_t)l4_scaler_tsc_to_us)
230 );
231 return ns;
232}
233
234L4_INLINE void
236{
237 __asm__
238 (" \n\t"
239 "mulq %3 \n\t"
240 "shrd $27, %%rdx, %%rax \n\t"
241 "xorq %%rdx, %%rdx \n\t"
242 "divq %4 \n\t"
243 :"=a" (*s), "=&d" (*ns)
244 : "a" (tsc), "r" ((l4_uint64_t)l4_scaler_tsc_to_ns),
245 "rm"(1000000000ULL)
246 );
247}
248
251{
252 l4_uint64_t tsc, dummy;
253 __asm__
254 (" \n\t"
255 "mulq %3 \n\t"
256 "shrd $27, %%rdx, %%rax \n\t"
257 :"=a" (tsc), "=d" (dummy)
258 :"a" (ns), "r" ((l4_uint64_t)l4_scaler_ns_to_tsc)
259 );
260 return tsc;
261}
262
263L4_INLINE void
265{
266 l4_cpu_time_t stop = l4_rdtsc();
267 stop += l4_ns_to_tsc(ns);
268
269 while (l4_rdtsc() < stop)
270 ;
271}
272
273L4_INLINE void
275{
276 l4_cpu_time_t stop = l4_rdtsc ();
277 stop += l4_ns_to_tsc(us*1000ULL);
278
279 while (l4_rdtsc() < stop)
280 ;
281}
282
283#endif /* __l4_rdtsc_h */
284
L4 compiler related defines.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
l4_uint64_t l4_cpu_time_t
CPU clock type.
Definition l4int.h:58
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:40
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:42
#define L4_CV
Define calling convention.
Definition linkage.h:44
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition compiler.h:192
#define EXTERN_C_END
End section with C types and functions.
Definition compiler.h:193
void l4_tsc_to_s_and_ns(l4_cpu_time_t tsc, l4_uint32_t *s, l4_uint32_t *ns)
Convert timestamp to s.ns value.
Definition rdtsc.h:235
l4_uint32_t l4_get_hz(void)
Get CPU frequency in Hz.
l4_uint32_t l4_tsc_init(l4_kernel_info_t const *kip)
Initialize scaler for TSC calibrations from the kernel.
l4_uint64_t l4_tsc_to_ns(l4_cpu_time_t tsc)
Convert timestamp to ns value.
Definition rdtsc.h:207
l4_uint64_t l4_tsc_to_us(l4_cpu_time_t tsc)
Convert timestamp into micro seconds value.
Definition rdtsc.h:221
l4_uint32_t l4_calibrate_tsc(l4_kernel_info_t const *kip)
Determine scalers for timestamp calculations.
Definition rdtsc.h:161
l4_cpu_time_t l4_rdtsc(void)
Read current value of CPU-internal timestamp counter.
Definition rdtsc.h:167
l4_cpu_time_t l4_ns_to_tsc(l4_uint64_t ns)
Convert nano seconds into CPU ticks.
Definition rdtsc.h:250
void l4_busy_wait_us(l4_uint64_t us)
Wait busy for a small amount of time.
Definition rdtsc.h:274
l4_uint32_t l4_rdpmc_32(int ecx)
Return the least significant 32 bit of a performance counter.
Definition rdtsc.h:197
l4_uint64_t l4_rdpmc(int ecx)
Return current value of CPU-internal performance measurement counter.
Definition rdtsc.h:177
void l4_busy_wait_ns(l4_uint64_t ns)
Wait busy for a small amount of time.
Definition rdtsc.h:264
l4_uint32_t l4_rdtsc_32(void)
Read the lest significant 32 bit of the TSC.
Definition rdtsc.h:187
L4 Kernel Interface Page.
Definition __kip-32bit.h:39
Kernel Info Page access functions.