File indexing completed on 2025-05-11 08:23:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <assert.h>
0014
0015 #include <bsp.h>
0016 #include <rtems/btimer.h>
0017
0018 bool benchmark_timer_find_average_overhead;
0019 uint32_t tstart;
0020
0021 void benchmark_timer_initialize(void)
0022 {
0023 __asm__ volatile ("mfc0 %0, $9\n" : "=r" (tstart));
0024
0025 }
0026
0027 #define AVG_OVERHEAD 0
0028
0029 #define LEAST_VALID 1
0030
0031
0032 benchmark_timer_t benchmark_timer_read(void)
0033 {
0034 uint32_t total;
0035 uint32_t cnt;
0036
0037 __asm__ volatile ("mfc0 %0, $9\n" : "=r" (cnt));
0038
0039 total = cnt - tstart;
0040 total = (total * 1000) / 396;
0041
0042
0043 if ( benchmark_timer_find_average_overhead == true )
0044 return total;
0045
0046 if ( total < LEAST_VALID )
0047 return 0;
0048
0049 return total - AVG_OVERHEAD;
0050 }
0051
0052 void benchmark_timer_disable_subtracting_average_overhead(
0053 bool find_flag
0054 )
0055 {
0056 benchmark_timer_find_average_overhead = find_flag;
0057 }