[f198c63] | 1 | /* timer.c |
---|
| 2 | * |
---|
| 3 | * This file contains the initialization code for the IDT 4650 timer driver. |
---|
| 4 | * |
---|
| 5 | * Author: Craig Lebakken <craigl@transition.com> |
---|
| 6 | * |
---|
| 7 | * COPYRIGHT (c) 1996 by Transition Networks Inc. |
---|
| 8 | * |
---|
| 9 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 10 | * without any express or implied warranty: |
---|
| 11 | * permission to use, copy, modify, and distribute this file |
---|
| 12 | * for any purpose is hereby granted without fee, provided that |
---|
| 13 | * the above copyright notice and this notice appears in all |
---|
| 14 | * copies, and that the name of Transition Networks not be used in |
---|
| 15 | * advertising or publicity pertaining to distribution of the |
---|
| 16 | * software without specific, written prior permission. |
---|
| 17 | * Transition Networks makes no representations about the suitability |
---|
| 18 | * of this software for any purpose. |
---|
| 19 | * |
---|
| 20 | * derived from src/lib/libbsp/no_cpu/no_bsp/timer/timer.c |
---|
| 21 | * |
---|
| 22 | * This file manages the benchmark timer used by the RTEMS Timing Test |
---|
| 23 | * Suite. Each measured time period is demarcated by calls to |
---|
[a903b7b] | 24 | * benchmark_timer_initialize() and benchmark_timer_read(). benchmark_timer_read() usually returns |
---|
| 25 | * the number of microseconds since benchmark_timer_initialize() exitted. |
---|
[f198c63] | 26 | * |
---|
| 27 | * NOTE: It is important that the timer start/stop overhead be |
---|
| 28 | * determined when porting or modifying this code. |
---|
| 29 | * |
---|
[08311cc3] | 30 | * COPYRIGHT (c) 1989-1999. |
---|
[f198c63] | 31 | * On-Line Applications Research Corporation (OAR). |
---|
| 32 | * |
---|
[98e4ebf5] | 33 | * The license and distribution terms for this file may be |
---|
| 34 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 35 | * http://www.rtems.org/license/LICENSE. |
---|
[f198c63] | 36 | */ |
---|
| 37 | |
---|
[82478528] | 38 | /* |
---|
| 39 | * Rather than deleting this, it is commented out to (hopefully) help |
---|
| 40 | * the submitter send updates. |
---|
| 41 | * |
---|
| 42 | * static char _sccsid[] = "@(#)timer.c 08/20/96 1.5\n"; |
---|
| 43 | */ |
---|
| 44 | |
---|
[f198c63] | 45 | |
---|
| 46 | #include <rtems.h> |
---|
| 47 | |
---|
| 48 | #define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ ) |
---|
| 49 | #define TIMER_MAX_VALUE 0xffffffff |
---|
| 50 | |
---|
[35f97010] | 51 | extern uint32_t mips_read_timer( void ); |
---|
[f198c63] | 52 | |
---|
[63e23b6e] | 53 | static bool benchmark_timer_find_average_overhead; |
---|
[290da88f] | 54 | static uint32_t benchmark_timer_initial_value = 0; |
---|
[f198c63] | 55 | |
---|
[a903b7b] | 56 | void benchmark_timer_initialize( void ) |
---|
[f198c63] | 57 | { |
---|
[290da88f] | 58 | benchmark_timer_initial_value = mips_read_timer(); |
---|
[f198c63] | 59 | /* |
---|
| 60 | * Somehow start the timer |
---|
| 61 | */ |
---|
| 62 | |
---|
| 63 | /* Timer on 4650 is always running */ |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /* |
---|
[a903b7b] | 67 | * The following controls the behavior of benchmark_timer_read(). |
---|
[f198c63] | 68 | * |
---|
| 69 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
| 70 | * is usually deducted from the number returned. |
---|
| 71 | * |
---|
| 72 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
| 73 | * below this are "noise" and zero is returned. |
---|
| 74 | */ |
---|
| 75 | |
---|
| 76 | #define AVG_OVERHEAD 8 /* It typically takes X.X microseconds */ |
---|
| 77 | /* (Y countdowns) to start/stop the timer. */ |
---|
| 78 | /* This value is in cycles. */ |
---|
| 79 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
| 80 | |
---|
[a903b7b] | 81 | int benchmark_timer_read( void ) |
---|
[f198c63] | 82 | { |
---|
[35f97010] | 83 | uint64_t clicks; |
---|
| 84 | uint32_t total; |
---|
[f198c63] | 85 | |
---|
| 86 | /* |
---|
| 87 | * Read the timer and see how many clicks it has been since we started. |
---|
| 88 | */ |
---|
| 89 | |
---|
| 90 | clicks = mips_read_timer(); /* XXX: read some HW here */ |
---|
[290da88f] | 91 | if (clicks < benchmark_timer_initial_value) |
---|
[f198c63] | 92 | { |
---|
| 93 | clicks += TIMER_MAX_VALUE; |
---|
| 94 | } |
---|
[290da88f] | 95 | clicks -= benchmark_timer_initial_value; |
---|
[f198c63] | 96 | |
---|
| 97 | /* |
---|
| 98 | * Total is calculated by taking into account the number of timer overflow |
---|
| 99 | * interrupts since the timer was initialized and clicks since the last |
---|
| 100 | * interrupts. |
---|
| 101 | */ |
---|
| 102 | #if 0 /* leave total in number of cycles */ |
---|
| 103 | total = clicks / CLOCKS_PER_MICROSECOND; |
---|
| 104 | #else |
---|
| 105 | total = clicks; |
---|
| 106 | #endif |
---|
| 107 | |
---|
[a903b7b] | 108 | if ( benchmark_timer_find_average_overhead == 1 ) |
---|
[f198c63] | 109 | return total; /* in # cycles units */ |
---|
| 110 | else { |
---|
| 111 | if ( total < LEAST_VALID ) |
---|
| 112 | return 0; /* below timer resolution */ |
---|
| 113 | /* |
---|
| 114 | * leave total in cycles |
---|
| 115 | */ |
---|
| 116 | return (total - AVG_OVERHEAD); |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
[63e23b6e] | 120 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
[f198c63] | 121 | { |
---|
[a903b7b] | 122 | benchmark_timer_find_average_overhead = find_flag; |
---|
[f198c63] | 123 | } |
---|