litl  0.1.9
Macros | Functions | Variables
litl_timer.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include "litl_timer.h"

Go to the source code of this file.

Macros

#define ERROR_TIMER_NOT_AVAILABLE()
 
#define TIMER_DEFAULT   litl_get_time_monotonic
 
#define RUN_BENCHMARK(_func_)
 
#define ticks(val)
 

Functions

litl_time_t litl_get_time_none ()
 Ultra-fast measurement function. More...
 
void litl_time_initialize ()
 Initializes the timing mechanism. More...
 
int litl_set_timing_method (litl_timing_method_t callback)
 Selects the timing function to use. More...
 
litl_time_t litl_get_time_monotonic_raw ()
 Uses clock_gettime(CLOCK_MONOTONIC_RAW) More...
 
litl_time_t litl_get_time_monotonic ()
 Uses clock_gettime(CLOCK_MONOTONIC) More...
 
litl_time_t litl_get_time_realtime ()
 Uses clock_gettime(CLOCK_REALTIME) More...
 
litl_time_t litl_get_time_process_cputime ()
 Uses clock_gettime(CLOCK_PROCESS_CPUTIME) More...
 
litl_time_t litl_get_time_thread_cputime ()
 Uses clock_gettime(CLOCK_THREAD_CPUTIME) More...
 
litl_time_t litl_get_time_ticks ()
 Uses CPU-specific register (for instance, rdtsc for X86* processors) More...
 

Variables

litl_timing_method_t litl_get_time = TIMER_DEFAULT
 Calls the selected timing method and get the current time in ns. More...
 

Macro Definition Documentation

◆ ERROR_TIMER_NOT_AVAILABLE

#define ERROR_TIMER_NOT_AVAILABLE ( )
Value:
do { \
fprintf(stderr, "Trying to use timer function %s, but it is not available on this platform\n",__FUNCTION__); \
abort(); \
} while(0)

Definition at line 19 of file litl_timer.c.

◆ RUN_BENCHMARK

#define RUN_BENCHMARK (   _func_)
Value:
do { \
cur_score = __litl_time_benchmark_generic(_func_); \
if(cur_score > best_score) { \
best_score = cur_score; \
litl_set_timing_method(_func_); \
} \
}while(0)

◆ ticks

#define ticks (   val)
Value:
do { \
uint32_t __a,__d; \
asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \
(val) = ((litl_time_t)__a) | (((litl_time_t)__d)<<32); \
} while(0)
uint64_t litl_time_t
A data type for storing time stamps.
Definition: litl_types.h:114

◆ TIMER_DEFAULT

#define TIMER_DEFAULT   litl_get_time_monotonic

Definition at line 29 of file litl_timer.c.