![]() |
|
|||
File indexing completed on 2025-05-11 08:23:51
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /* timer.c 0004 * 0005 * This file manages the benchmark timer used by the RTEMS Timing Test 0006 * Suite. Each measured time period is demarcated by calls to 0007 * benchmark_timer_initialize() and benchmark_timer_read(). benchmark_timer_read() usually returns 0008 * the number of microseconds since benchmark_timer_initialize() exitted. 0009 * 0010 * NOTE: It is important that the timer start/stop overhead be 0011 * determined when porting or modifying this code. 0012 * 0013 * COPYRIGHT (c) 1989-1999. 0014 * On-Line Applications Research Corporation (OAR). 0015 * 0016 * Redistribution and use in source and binary forms, with or without 0017 * modification, are permitted provided that the following conditions 0018 * are met: 0019 * 1. Redistributions of source code must retain the above copyright 0020 * notice, this list of conditions and the following disclaimer. 0021 * 2. Redistributions in binary form must reproduce the above copyright 0022 * notice, this list of conditions and the following disclaimer in the 0023 * documentation and/or other materials provided with the distribution. 0024 * 0025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0028 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0029 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0030 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0031 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0032 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0033 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0034 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0035 * POSSIBILITY OF SUCH DAMAGE. 0036 */ 0037 0038 #include <rtems.h> 0039 #include <rtems/btimer.h> 0040 #include <bsp.h> 0041 0042 uint32_t Timer_interrupts; 0043 bool benchmark_timer_find_average_overhead; 0044 0045 void benchmark_timer_initialize( void ) 0046 { 0047 0048 /* 0049 * Timer has never overflowed. This may not be necessary on some 0050 * implemenations of timer but .... 0051 */ 0052 0053 Timer_interrupts = 0; 0054 0055 /* 0056 * Somehow start the timer 0057 */ 0058 } 0059 0060 /* 0061 * The following controls the behavior of benchmark_timer_read(). 0062 * 0063 * AVG_OVEREHAD is the overhead for starting and stopping the timer. It 0064 * is usually deducted from the number returned. 0065 * 0066 * LEAST_VALID is the lowest number this routine should trust. Numbers 0067 * below this are "noise" and zero is returned. 0068 */ 0069 0070 #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ 0071 /* (Y countdowns) to start/stop the timer. */ 0072 /* This value is in microseconds. */ 0073 #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ 0074 0075 benchmark_timer_t benchmark_timer_read( void ) 0076 { 0077 uint32_t clicks; 0078 uint32_t total; 0079 0080 /* 0081 * Read the timer and see how many clicks it has been since we started. 0082 */ 0083 0084 clicks = 0; /* XXX: read some HW here */ 0085 0086 /* 0087 * Total is calculated by taking into account the number of timer overflow 0088 * interrupts since the timer was initialized and clicks since the last 0089 * interrupts. 0090 */ 0091 0092 total = clicks * 0; 0093 0094 if ( benchmark_timer_find_average_overhead == true ) 0095 return total; /* in XXX microsecond units */ 0096 else { 0097 if ( total < LEAST_VALID ) 0098 return 0; /* below timer resolution */ 0099 /* 0100 * Somehow convert total into microseconds 0101 */ 0102 return (total - AVG_OVERHEAD); 0103 } 0104 } 0105 0106 void benchmark_timer_disable_subtracting_average_overhead( 0107 bool find_flag 0108 ) 0109 { 0110 benchmark_timer_find_average_overhead = find_flag; 0111 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |