[fd57015] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @ingroup or1ksim |
---|
| 5 | * |
---|
| 6 | * @brief Benchmark timer support. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | * Copyright (c) 2014 by Hesham ALMatary |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
| 14 | * http://www.rtems.org/license/LICENSE |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include <rtems.h> |
---|
| 18 | #include <rtems/btimer.h> |
---|
| 19 | #include <bsp/or1ksim.h> |
---|
| 20 | #include <rtems/score/or1k-utility.h> |
---|
| 21 | |
---|
| 22 | #define OR1KSIM_NANOSECONDS_PER_CLK_CYCLE 10 |
---|
| 23 | |
---|
| 24 | static bool benchmark_timer_find_average_overhead = false; |
---|
| 25 | static uint64_t benchmark_timer_base; |
---|
| 26 | |
---|
| 27 | void benchmark_timer_initialize(void) |
---|
| 28 | { |
---|
| 29 | benchmark_timer_base = _OR1K_mfspr(CPU_OR1K_SPR_TTCR); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | #define AVG_OVERHEAD 0 |
---|
| 33 | #define LEAST_VALID 1 |
---|
| 34 | |
---|
[8fbe2e6] | 35 | benchmark_timer_t benchmark_timer_read( void ) |
---|
[fd57015] | 36 | { |
---|
| 37 | uint64_t clicks; |
---|
| 38 | uint64_t total; |
---|
| 39 | uint64_t delta; |
---|
| 40 | /* |
---|
| 41 | * Read the timer and see how many clicks (clock cycles) |
---|
| 42 | * has passed since timer initialization. |
---|
| 43 | */ |
---|
| 44 | clicks = _OR1K_mfspr(CPU_OR1K_SPR_TTCR); |
---|
| 45 | |
---|
| 46 | delta = clicks - benchmark_timer_base; |
---|
| 47 | |
---|
| 48 | /* total in nanoseconds */ |
---|
| 49 | total = OR1KSIM_NANOSECONDS_PER_CLK_CYCLE * (delta); |
---|
| 50 | |
---|
| 51 | if ( benchmark_timer_find_average_overhead == true ) |
---|
| 52 | return total; /* in nanoseconds microsecond units */ |
---|
| 53 | else { |
---|
| 54 | if ( total < LEAST_VALID ) |
---|
| 55 | return 0; /* below timer resolution */ |
---|
| 56 | |
---|
| 57 | return (total - AVG_OVERHEAD); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
| 62 | { |
---|
| 63 | benchmark_timer_find_average_overhead = find_flag; |
---|
| 64 | } |
---|