1 | /** |
---|
2 | * @file |
---|
3 | * @brief |
---|
4 | * |
---|
5 | * This file implements a benchmark timer using the PPC Timebase Register. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may in |
---|
13 | * the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #include <bsp.h> |
---|
18 | #include <rtems.h> |
---|
19 | #include <rtems/btimer.h> |
---|
20 | #include <assert.h> |
---|
21 | #include <libcpu/powerpc-utility.h> |
---|
22 | |
---|
23 | #ifndef BSP_Convert_decrementer |
---|
24 | #define BSP_Convert_decrementer(value) (value) |
---|
25 | #endif |
---|
26 | |
---|
27 | uint64_t Timer_driver_Start_time; |
---|
28 | |
---|
29 | bool benchmark_timer_find_average_overhead = false; |
---|
30 | unsigned clicks_overhead = 0; |
---|
31 | |
---|
32 | /* |
---|
33 | * Timer Get overhead |
---|
34 | */ |
---|
35 | static int Timer_get_clicks_overhead(void) |
---|
36 | { |
---|
37 | uint64_t clicks; |
---|
38 | |
---|
39 | PPC_Set_timebase_register((uint64_t) 0); |
---|
40 | clicks = PPC_Get_timebase_register(); |
---|
41 | assert(clicks <= 0xffffffff); |
---|
42 | clicks_overhead = (unsigned) clicks; |
---|
43 | return clicks_overhead; |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | * benchmark_timer_initialize |
---|
48 | */ |
---|
49 | void benchmark_timer_initialize(void) |
---|
50 | { |
---|
51 | |
---|
52 | /* |
---|
53 | * Timer runs long and accurate enough not to require an interrupt. |
---|
54 | */ |
---|
55 | |
---|
56 | if (clicks_overhead == 0) clicks_overhead = Timer_get_clicks_overhead(); |
---|
57 | PPC_Set_timebase_register((uint64_t) 0); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | /* |
---|
62 | * benchmark_timer_read |
---|
63 | */ |
---|
64 | |
---|
65 | benchmark_timer_t benchmark_timer_read(void) |
---|
66 | { |
---|
67 | uint64_t total64; |
---|
68 | uint32_t total; |
---|
69 | |
---|
70 | /* approximately CLOCK_SPEED clicks per microsecond */ |
---|
71 | |
---|
72 | total64 = PPC_Get_timebase_register(); |
---|
73 | |
---|
74 | assert( total64 <= 0xffffffff ); /* fits into a uint32_t */ |
---|
75 | |
---|
76 | total = (uint32_t) total64; |
---|
77 | |
---|
78 | if ( benchmark_timer_find_average_overhead == true ) |
---|
79 | return total; /* in "clicks" of the decrementer units */ |
---|
80 | |
---|
81 | return (int) BSP_Convert_decrementer(total - clicks_overhead); |
---|
82 | } |
---|
83 | |
---|
84 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
85 | { |
---|
86 | benchmark_timer_find_average_overhead = find_flag; |
---|
87 | } |
---|