source: rtems/c/src/lib/libbsp/unix/posix/timer/timer.c @ 424ee2ba

4.104.114.9
Last change on this file since 424ee2ba was 424ee2ba, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 31, 2008 at 4:47:17 PM

2008-08-31 Joel Sherrill <joel.sherrill@…>

  • timer/timer.c: Rename timer driver methods to follow RTEMS programming conventions.
  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*  timer.c
2 *
3 *  This file manages the interval timer on a UNIX BSP.
4 *
5 *  NOTE: It is important that the timer start/stop overhead be
6 *        determined when porting or modifying this code.
7 *
8 *  COPYRIGHT (c) 1989-2003.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#include <bsp.h>
19#include <time.h>
20#include <sys/time.h>
21
22struct timeval  Timer_start;
23struct timeval  Timer_stop;
24struct timezone Time_zone;
25
26rtems_boolean   benchmark_timerfind_average_overhead;
27
28void benchmark_timerinitialize()
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
37int benchmark_timerread()
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
51  if ( benchmark_timerfind_average_overhead == 1 )
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
60rtems_status_code benchmark_timerempty_function( void )
61{
62  return RTEMS_SUCCESSFUL;
63}
64
65void benchmark_timerdisable_subtracting_average_overhead(
66  rtems_boolean find_flag
67)
68{
69  benchmark_timerfind_average_overhead = find_flag;
70}
Note: See TracBrowser for help on using the repository browser.