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 |
---|
5 | * benchmark_timer_initialize() and benchmark_timer_read(). benchmark_timer_read() usually returns |
---|
6 | * the number of microseconds since benchmark_timer_initialize() exitted. |
---|
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 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #include <rtems.h> |
---|
18 | |
---|
19 | bool benchmark_timer_find_average_overhead; |
---|
20 | |
---|
21 | static unsigned int volatile lastInitValue; |
---|
22 | |
---|
23 | void benchmark_timer_initialize( void ) |
---|
24 | { |
---|
25 | __asm__ volatile( " mftb %0": "=r" (lastInitValue) ); |
---|
26 | } |
---|
27 | |
---|
28 | /* |
---|
29 | * The following controls the behavior of benchmark_timer_read(). |
---|
30 | * |
---|
31 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
32 | * is usually deducted from the number returned. |
---|
33 | * |
---|
34 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
35 | * below this are "noise" and zero is returned. |
---|
36 | */ |
---|
37 | |
---|
38 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
39 | /* (Y countdowns) to start/stop the timer. */ |
---|
40 | /* This value is in microseconds. */ |
---|
41 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
42 | |
---|
43 | int benchmark_timer_read( void ) |
---|
44 | { |
---|
45 | uint32_t value; |
---|
46 | __asm__ volatile ( " mftb %0": "=r" (value) ); |
---|
47 | return value - lastInitValue; |
---|
48 | } |
---|
49 | |
---|
50 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
51 | { |
---|
52 | benchmark_timer_find_average_overhead = find_flag; |
---|
53 | } |
---|