[6cc85032] | 1 | /* timer.c |
---|
| 2 | * |
---|
[d956ef7] | 3 | * This file manages the interval timer on a UNIX BSP. |
---|
[6cc85032] | 4 | * |
---|
| 5 | * NOTE: It is important that the timer start/stop overhead be |
---|
| 6 | * determined when porting or modifying this code. |
---|
| 7 | * |
---|
[d956ef7] | 8 | * COPYRIGHT (c) 1989-2003. |
---|
[6cc85032] | 9 | * On-Line Applications Research Corporation (OAR). |
---|
| 10 | * |
---|
[98e4ebf5] | 11 | * The license and distribution terms for this file may be |
---|
| 12 | * found in the file LICENSE in this distribution or at |
---|
[86d58c0] | 13 | * http://www.rtems.com/license/LICENSE. |
---|
[6cc85032] | 14 | * |
---|
| 15 | * $Id$ |
---|
| 16 | */ |
---|
| 17 | |
---|
[37f4c2d] | 18 | #include <bsp.h> |
---|
[6cc85032] | 19 | #include <time.h> |
---|
[3ea5288] | 20 | #include <sys/time.h> |
---|
[6cc85032] | 21 | |
---|
| 22 | struct timeval Timer_start; |
---|
| 23 | struct timeval Timer_stop; |
---|
| 24 | struct timezone Time_zone; |
---|
| 25 | |
---|
[424ee2ba] | 26 | rtems_boolean benchmark_timerfind_average_overhead; |
---|
[6cc85032] | 27 | |
---|
[424ee2ba] | 28 | void benchmark_timerinitialize() |
---|
[6cc85032] | 29 | { |
---|
| 30 | gettimeofday( &Timer_start, &Time_zone ); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | #define AVG_OVERHEAD 0 /* It typically takes xxx microseconds */ |
---|
| 34 | /* (XX countdowns) to start/stop the timer. */ |
---|
| 35 | #define LEAST_VALID 10 /* Don't trust a value lower than this */ |
---|
| 36 | |
---|
[424ee2ba] | 37 | int benchmark_timerread() |
---|
[6cc85032] | 38 | { |
---|
| 39 | int total; |
---|
| 40 | |
---|
| 41 | gettimeofday( &Timer_stop, &Time_zone ); |
---|
| 42 | |
---|
| 43 | if ( Timer_stop.tv_sec == Timer_start.tv_sec ) |
---|
| 44 | total = Timer_stop.tv_usec - Timer_start.tv_usec; |
---|
| 45 | else { |
---|
| 46 | total = 1000000 - Timer_start.tv_usec; |
---|
| 47 | total += (Timer_stop.tv_sec - Timer_start.tv_sec - 1) * 1000000; |
---|
| 48 | total += Timer_stop.tv_usec; |
---|
| 49 | } |
---|
| 50 | |
---|
[424ee2ba] | 51 | if ( benchmark_timerfind_average_overhead == 1 ) |
---|
[6cc85032] | 52 | return total; /* in countdown units */ |
---|
| 53 | else { |
---|
| 54 | if ( total < LEAST_VALID ) |
---|
| 55 | return 0; /* below timer resolution */ |
---|
| 56 | return total - AVG_OVERHEAD; |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
[424ee2ba] | 60 | rtems_status_code benchmark_timerempty_function( void ) |
---|
[6cc85032] | 61 | { |
---|
| 62 | return RTEMS_SUCCESSFUL; |
---|
| 63 | } |
---|
| 64 | |
---|
[424ee2ba] | 65 | void benchmark_timerdisable_subtracting_average_overhead( |
---|
[6cc85032] | 66 | rtems_boolean find_flag |
---|
| 67 | ) |
---|
| 68 | { |
---|
[424ee2ba] | 69 | benchmark_timerfind_average_overhead = find_flag; |
---|
[6cc85032] | 70 | } |
---|