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 | |
---|
19 | rtems_boolean benchmark_timer_find_average_overhead; |
---|
20 | uint32_t tstart; |
---|
21 | |
---|
22 | void 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 | |
---|
33 | int 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 | |
---|
53 | void benchmark_timer_disable_subtracting_average_overhead( |
---|
54 | rtems_boolean find_flag |
---|
55 | ) |
---|
56 | { |
---|
57 | benchmark_timer_find_average_overhead = find_flag; |
---|
58 | } |
---|