source: rtems/c/src/lib/libbsp/powerpc/mvme2307/timer/timer.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 2.5 KB
Line 
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 *  Timer_initialize() and Read_timer().  Read_timer() usually returns
6 *  the number of microseconds since Timer_initialize() exitted.
7 *
8 *  This version returns the number of nanoseconds since Timer_initialize()
9 *  exited, since the '604 is very fast at 300MHz.  Actual resolution is
10 *  60 nsec.
11 *
12 *  NOTE: It is important that the timer start/stop overhead be
13 *        determined when porting or modifying this code.
14 *
15 *  COPYRIGHT (c) 1989-1999.
16 *  On-Line Applications Research Corporation (OAR).
17 *
18 *  The license and distribution terms for this file may be
19 *  found in the file LICENSE in this distribution or at
20 *  http://www.OARcorp.com/rtems/license.html.
21 *
22 *  $Id$
23 */
24
25#include <rtems.h>
26#include <bsp.h>
27
28rtems_unsigned32 Timer_start;
29rtems_boolean Timer_driver_Find_average_overhead;
30
31void Timer_initialize( void )
32{
33    rtems_unsigned32 clicks;
34
35    asm volatile ("mfspr %0,268" : "=r" (clicks) :);
36    Timer_start = clicks;
37}
38
39/*
40 *  The following controls the behavior of Read_timer().
41 *
42 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
43 *  is usually deducted from the number returned.
44 *
45 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
46 *  below this are "noise" and zero is returned.
47 */
48
49#define AVG_OVERHEAD      7  /* On average, it takes 7.4 nanoseconds */
50                             /* (Y countdowns) to start/stop the timer. */
51
52#define NSEC_PER_TICK    60 
53
54int Read_timer( void )
55{
56    rtems_unsigned32 clicks;
57    rtems_unsigned32 total;
58
59    /*
60     *  Read the timer and see how many clicks it has been since we started.
61     *  Timer overflows every 257 seconds, so multiple overflows are deemed
62     *  impossible.
63     */
64
65    asm volatile ("mfspr %0,268" : "=r" (clicks) :);
66    total = (clicks - Timer_start);
67
68    if ( Timer_driver_Find_average_overhead == 1 ) {
69        return total * NSEC_PER_TICK;          /* in nanoseconds */
70    } else {
71        /*
72        *   convert total into nanoseconds
73        */
74        return total * NSEC_PER_TICK - AVG_OVERHEAD;
75    }
76}
77
78/*
79 *  Empty function call used in loops to measure basic cost of looping
80 *  in Timing Test Suite.
81 */
82
83rtems_status_code Empty_function( void ) {
84    return RTEMS_SUCCESSFUL;
85}
86
87void Set_find_average_overhead(rtems_boolean find_flag) {
88    Timer_driver_Find_average_overhead = find_flag;
89}
90
Note: See TracBrowser for help on using the repository browser.