source: rtems/c/src/lib/libbsp/mips/csb350/timer/timer.c @ 25c62b0

4.104.114.95
Last change on this file since 25c62b0 was 25c62b0, checked in by Joel Sherrill <joel.sherrill@…>, on 08/31/08 at 18:18:17

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

  • timer/timer.c: Eliminate empty function from every benchmark timer driver. Fix spelling.
  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 *  This file implements a benchmark timer using the count/compare
3 *  CP0 registers.
4 *
5 *  Copyright (c) 2005 by Cogent Computer Systems
6 *  Written by Jay Monkman <jtm@lopingdog.com>
7 *     
8 *  The license and distribution terms for this file may be
9 *  found in found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#include <assert.h>
16
17#include <bsp.h>
18
19rtems_boolean benchmark_timer_find_average_overhead;
20uint32_t tstart;
21
22void benchmark_timer_initialize(void)
23{
24    asm volatile ("mfc0 %0, $9\n" : "=r" (tstart));
25    /* tick time in picooseconds */
26}
27
28#define AVG_OVERHEAD      0  /* It typically takes N instructions */
29                             /*     to start/stop the timer. */
30#define LEAST_VALID       1  /* Don't trust a value lower than this */
31                             /* tx39 simulator can count instructions. :) */
32
33int benchmark_timer_read(void)
34{
35  uint32_t  total;
36  uint32_t  cnt;
37
38  asm volatile ("mfc0 %0, $9\n" : "=r" (cnt));
39
40  total = cnt - tstart;
41  total = (total * 1000) / 396; /* convert to nanoseconds */
42
43
44  if ( benchmark_timer_find_average_overhead == 1 )
45    return total;          /* in one microsecond units */
46
47  if ( total < LEAST_VALID )
48    return 0;            /* below timer resolution */
49
50  return total - AVG_OVERHEAD;
51}
52
53void benchmark_timer_disable_subtracting_average_overhead(
54  rtems_boolean find_flag
55)
56{
57  benchmark_timer_find_average_overhead = find_flag;
58}
Note: See TracBrowser for help on using the repository browser.