source: rtems/bsps/mips/csb350/btimer/btimer.c @ e0dd8a5a

5
Last change on this file since e0dd8a5a was e0dd8a5a, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 10:08:42

bsps: Move benchmark timer to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • 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.