source: rtems/c/src/lib/libbsp/mips/csb350/timer/timer.c @ 8fbe2e6

4.11
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2014 at 1:59:49 PM

Use correct prototype of benchmark_timer_read()

This change starts with removing the effectively empty file
timerdrv.h. The prototypes for benchmark_timer_XXX() were in
btimer.h which was not universally used. Thus every use of
timerdrv.h had to be changed to btimer.h. Then the prototypes
for benchmark_timer_read() had to be adjusted to return
benchmark_timer_t rather than int or uint32_t.

I took this opportunity to also correct the file headers to
separate the copyright from the file description comments which
is needed to ensure the copyright isn't propagated into Doxygen
output.

  • Property mode set to 100644
File size: 1.5 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 the file LICENSE in this distribution or at
10 *  http://www.rtems.org/license/LICENSE.
11 */
12
13#include <assert.h>
14
15#include <bsp.h>
16#include <rtems/btimer.h>
17
18bool benchmark_timer_find_average_overhead;
19uint32_t tstart;
20
21void benchmark_timer_initialize(void)
22{
23    __asm__ volatile ("mfc0 %0, $9\n" : "=r" (tstart));
24    /* tick time in picooseconds */
25}
26
27#define AVG_OVERHEAD      0  /* It typically takes N instructions */
28                             /*     to start/stop the timer. */
29#define LEAST_VALID       1  /* Don't trust a value lower than this */
30                             /* tx39 simulator can count instructions. :) */
31
32benchmark_timer_t benchmark_timer_read(void)
33{
34  uint32_t  total;
35  uint32_t  cnt;
36
37  __asm__ volatile ("mfc0 %0, $9\n" : "=r" (cnt));
38
39  total = cnt - tstart;
40  total = (total * 1000) / 396; /* convert to nanoseconds */
41
42
43  if ( benchmark_timer_find_average_overhead == true )
44    return total;          /* in one microsecond units */
45
46  if ( total < LEAST_VALID )
47    return 0;            /* below timer resolution */
48
49  return total - AVG_OVERHEAD;
50}
51
52void benchmark_timer_disable_subtracting_average_overhead(
53  bool find_flag
54)
55{
56  benchmark_timer_find_average_overhead = find_flag;
57}
Note: See TracBrowser for help on using the repository browser.