[96284fd8] | 1 | /* timer.c |
---|
| 2 | * |
---|
| 3 | * This file manages the benchmark timer used by the RTEMS Timing Test |
---|
| 4 | * Suite. Each measured time period is demarcated by calls to |
---|
[6427f1a] | 5 | * benchmark_timer_initialize() and benchmark_timer_read(). benchmark_timer_read() usually returns |
---|
| 6 | * the number of microseconds since benchmark_timer_initialize() exitted. |
---|
[96284fd8] | 7 | * |
---|
| 8 | * NOTE: It is important that the timer start/stop overhead be |
---|
| 9 | * determined when porting or modifying this code. |
---|
| 10 | * |
---|
| 11 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 12 | * On-Line Applications Research Corporation (OAR). |
---|
| 13 | */ |
---|
| 14 | |
---|
[a982e0c6] | 15 | #include <rtems.h> |
---|
[96284fd8] | 16 | |
---|
[3942cce] | 17 | bool benchmark_timer_find_average_overhead; |
---|
[96284fd8] | 18 | |
---|
| 19 | static unsigned int volatile lastInitValue; |
---|
| 20 | |
---|
[6427f1a] | 21 | void benchmark_timer_initialize( void ) |
---|
[96284fd8] | 22 | { |
---|
[f9acc33] | 23 | __asm__ volatile( " mftb %0": "=r" (lastInitValue) ); |
---|
[96284fd8] | 24 | } |
---|
| 25 | |
---|
| 26 | /* |
---|
[6427f1a] | 27 | * The following controls the behavior of benchmark_timer_read(). |
---|
[96284fd8] | 28 | * |
---|
| 29 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
| 30 | * is usually deducted from the number returned. |
---|
| 31 | * |
---|
| 32 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
| 33 | * below this are "noise" and zero is returned. |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
| 37 | /* (Y countdowns) to start/stop the timer. */ |
---|
| 38 | /* This value is in microseconds. */ |
---|
| 39 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
| 40 | |
---|
[6427f1a] | 41 | int benchmark_timer_read( void ) |
---|
[96284fd8] | 42 | { |
---|
[66c373bf] | 43 | uint32_t value; |
---|
[f9acc33] | 44 | __asm__ volatile ( " mftb %0": "=r" (value) ); |
---|
[96284fd8] | 45 | return value - lastInitValue; |
---|
| 46 | } |
---|
| 47 | |
---|
[3942cce] | 48 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
[96284fd8] | 49 | { |
---|
[6427f1a] | 50 | benchmark_timer_find_average_overhead = find_flag; |
---|
[96284fd8] | 51 | } |
---|