L4Re - L4 Runtime Environment
Timestamp Counter
+ Collaboration diagram for Timestamp Counter:

Files

file  rdtsc.h
 time stamp counter related functions
 
file  rdtsc.h
 time stamp counter related functions
 

Macros

#define L4_TSC_INIT_AUTO   0
 Automatic init.
 
#define L4_TSC_INIT_KERNEL   1
 Initialized by kernel.
 
#define L4_TSC_INIT_CALIBRATE   2
 Initialized by user-level.
 
#define L4_TSC_INIT_AUTO   0
 Automatic init.
 
#define L4_TSC_INIT_KERNEL   1
 Initialized by kernel.
 
#define L4_TSC_INIT_CALIBRATE   2
 Initialized by user-level.
 

Functions

l4_cpu_time_t l4_rdtsc (void)
 Read current value of CPU-internal time stamp counter. More...
 
l4_uint32_t l4_rdtsc_32 (void)
 Read the lest significant 32 bit of the TSC. More...
 
l4_cpu_time_t l4_rdpmc (int nr)
 Return current value of CPU-internal performance measurement counter. More...
 
l4_uint32_t l4_rdpmc_32 (int nr)
 Return the least significant 32 bit of a performance counter. More...
 
l4_uint64_t l4_tsc_to_ns (l4_cpu_time_t tsc)
 Convert time stamp to ns value. More...
 
l4_uint64_t l4_tsc_to_us (l4_cpu_time_t tsc)
 Convert time stamp into micro seconds value. More...
 
void l4_tsc_to_s_and_ns (l4_cpu_time_t tsc, l4_uint32_t *s, l4_uint32_t *ns)
 Convert time stamp to s.ns value. More...
 
l4_cpu_time_t l4_ns_to_tsc (l4_uint64_t ns)
 Convert nano seconds into CPU ticks. More...
 
void l4_busy_wait_ns (l4_uint64_t ns)
 Wait busy for a small amount of time. More...
 
void l4_busy_wait_us (l4_uint64_t us)
 Wait busy for a small amount of time. More...
 
l4_uint32_t l4_calibrate_tsc (l4_kernel_info_t *kip)
 Calibrate scalers for time stamp calculations. More...
 
l4_uint32_t l4_tsc_init (int constraint, l4_kernel_info_t *kip)
 Initialitze scaler for TSC calicaltions. More...
 
l4_uint32_t l4_get_hz (void)
 Get CPU frequency in Hz. More...
 

Detailed Description

Function Documentation

◆ l4_busy_wait_ns()

void l4_busy_wait_ns ( l4_uint64_t  ns)
inline

Wait busy for a small amount of time.

Parameters
nsnano seconds to wait
Attention
Not intendet for any use!

Definition at line 317 of file rdtsc.h.

References l4_ns_to_tsc(), and l4_rdtsc().

+ Here is the call graph for this function:

◆ l4_busy_wait_us()

void l4_busy_wait_us ( l4_uint64_t  us)
inline

Wait busy for a small amount of time.

Parameters
usmicro seconds to wait
Attention
Not intendet for any use!

Definition at line 327 of file rdtsc.h.

References EXTERN_C_END, l4_ns_to_tsc(), and l4_rdtsc().

+ Here is the call graph for this function:

◆ l4_calibrate_tsc()

l4_uint32_t l4_calibrate_tsc ( l4_kernel_info_t kip)
inline

Calibrate scalers for time stamp calculations.

Determine some scalers to be able to convert between real time and CPU ticks. This test uses channel 0 of the PIT (i8254) or the kernel KIP, depending on availability. Just calls l4_tsc_init(L4_TSC_INIT_AUTO).

Examples:
examples/sys/aliens/main.c.

Definition at line 179 of file rdtsc.h.

References l4_tsc_init(), and L4_TSC_INIT_AUTO.

+ Here is the call graph for this function:

◆ l4_get_hz()

l4_uint32_t l4_get_hz ( void  )

Get CPU frequency in Hz.

Returns
frequency in Hz

◆ l4_ns_to_tsc()

l4_cpu_time_t l4_ns_to_tsc ( l4_uint64_t  ns)
inline

Convert nano seconds into CPU ticks.

Parameters
nsnano seconds
Returns
CPU ticks

Definition at line 303 of file rdtsc.h.

Referenced by l4_busy_wait_ns(), and l4_busy_wait_us().

+ Here is the caller graph for this function:

◆ l4_rdpmc()

l4_cpu_time_t l4_rdpmc ( int  nr)
inline

Return current value of CPU-internal performance measurement counter.

Parameters
nrNumber of counter (0 or 1)
Returns
64-bit PMC

Definition at line 205 of file rdtsc.h.

◆ l4_rdpmc_32()

l4_uint32_t l4_rdpmc_32 ( int  nr)
inline

Return the least significant 32 bit of a performance counter.

Useful for smaller differences, needs less cycles.

Definition at line 227 of file rdtsc.h.

◆ l4_rdtsc()

l4_cpu_time_t l4_rdtsc ( void  )
inline

Read current value of CPU-internal time stamp counter.

Returns
64-bit time stamp
Examples:
examples/sys/aliens/main.c.

Definition at line 185 of file rdtsc.h.

Referenced by l4_busy_wait_ns(), and l4_busy_wait_us().

+ Here is the caller graph for this function:

◆ l4_rdtsc_32()

l4_uint32_t l4_rdtsc_32 ( void  )
inline

Read the lest significant 32 bit of the TSC.

Useful for smaller differences, needs less cycles.

Definition at line 246 of file rdtsc.h.

◆ l4_tsc_init()

l4_uint32_t l4_tsc_init ( int  constraint,
l4_kernel_info_t kip 
)

Initialitze scaler for TSC calicaltions.

Initialize the scalers needed by l4_tsc_to_ns()/l4_ns_to_tsc() and so on. Current versions of Fiasco export these scalers from kernel into userland. The programmer may decide whether he allows to use these scalers or if an calibration should be performed.

Parameters
constraintprogrammers constraint:
  • L4_TSC_INIT_AUTO if the kernel exports the scalers then use them. If not, perform calibration using channel 0 of the PIT (i8254). The latter case may lead into short (unpredictable) periods where interrupts are disabled.
  • L4_TSC_INIT_KERNEL depend on retrieving the scalers from kernel. If the scalers are not available, return 0.
  • L4_TSC_INIT_CALIBRATE Ignore possible scalers exported by the scaler, instead insist on calibration using the PIT.
kipKIP pointer
Returns
0 on error (no scalers exported by kernel, calibrating failed ...) otherwise returns (2^32 / (tsc per ┬Ásec)). This value has the same semantics as the value returned by the calibrate_delay_loop() function of the Linux kernel.

Referenced by l4_calibrate_tsc().

+ Here is the caller graph for this function:

◆ l4_tsc_to_ns()

l4_uint64_t l4_tsc_to_ns ( l4_cpu_time_t  tsc)
inline

Convert time stamp to ns value.

Parameters
tsctime value in CPU ticks
Returns
time value in ns
Examples:
examples/sys/aliens/main.c.

Definition at line 260 of file rdtsc.h.

◆ l4_tsc_to_s_and_ns()

void l4_tsc_to_s_and_ns ( l4_cpu_time_t  tsc,
l4_uint32_t s,
l4_uint32_t ns 
)
inline

Convert time stamp to s.ns value.

Parameters
tsctime value in CPU ticks
Return values
sseconds
nsnano seconds

Definition at line 288 of file rdtsc.h.

◆ l4_tsc_to_us()

l4_uint64_t l4_tsc_to_us ( l4_cpu_time_t  tsc)
inline

Convert time stamp into micro seconds value.

Parameters
tsctime value in CPU ticks
Returns
time value in micro seconds

Definition at line 274 of file rdtsc.h.