Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:51

0001 /**
0002  * @file
0003  *
0004  * @ingroup RTEMSBSPsOR1K
0005  *
0006  * @brief Benchmark timer support.
0007  */
0008 
0009 /*
0010  * Copyright (c) 2014-2015 by Hesham ALMatary
0011  *
0012  *  The license and distribution terms for this file may be
0013  *  found in the file LICENSE in this distribution or at
0014  *  http://www.rtems.org/license/LICENSE
0015  */
0016 
0017 #include <rtems.h>
0018 #include <rtems/btimer.h>
0019 #include <bsp/generic_or1k.h>
0020 #include <rtems/score/or1k-utility.h>
0021 
0022 #define OR1K_NANOSECONDS_PER_CLK_CYCLE 10
0023 
0024 static bool benchmark_timer_find_average_overhead = false;
0025 static uint64_t benchmark_timer_base;
0026 
0027 void benchmark_timer_initialize(void)
0028 {
0029   benchmark_timer_base = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
0030 }
0031 
0032 #define AVG_OVERHEAD  0
0033 #define LEAST_VALID   1
0034 
0035 benchmark_timer_t benchmark_timer_read( void )
0036 {
0037   uint64_t         clicks;
0038   uint64_t         total;
0039   uint64_t         delta;
0040   /*
0041    *  Read the timer and see how many clicks (clock cycles)
0042    *  has passed since timer initialization.
0043    */
0044   clicks = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
0045 
0046   delta = clicks - benchmark_timer_base;
0047 
0048   /* total in nanoseconds */
0049   total = OR1K_NANOSECONDS_PER_CLK_CYCLE * (delta);
0050 
0051   if ( benchmark_timer_find_average_overhead == true )
0052     return total;          /* in nanoseconds microsecond units */
0053   else {
0054     if ( total < LEAST_VALID )
0055       return 0;            /* below timer resolution */
0056 
0057       return (total - AVG_OVERHEAD);
0058   }
0059 }
0060 
0061 void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
0062 {
0063   benchmark_timer_find_average_overhead = find_flag;
0064 }