4.104.114.84.95
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.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #include <assert.h> |
---|
16 | |
---|
17 | #include <bsp.h> |
---|
18 | |
---|
19 | rtems_boolean Timer_driver_Find_average_overhead; |
---|
20 | uint32_t tstart; |
---|
21 | |
---|
22 | void Timer_initialize() |
---|
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 | |
---|
33 | int Read_timer() |
---|
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 ( Timer_driver_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 | |
---|
53 | rtems_status_code Empty_function( void ) |
---|
54 | { |
---|
55 | return RTEMS_SUCCESSFUL; |
---|
56 | } |
---|
57 | |
---|
58 | void Set_find_average_overhead( |
---|
59 | rtems_boolean find_flag |
---|
60 | ) |
---|
61 | { |
---|
62 | Timer_driver_Find_average_overhead = find_flag; |
---|
63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.