Back to home page

LXR

 
 

    


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

0001 /*  timer.c
0002  *
0003  *  This file manages the benchmark timer used by the RTEMS Timing
0004  *  Test Suite.  Each measured time period is demarcated by calls to
0005  *  benchmark_timer_initialize() and benchmark_timer_read().
0006  *  benchmark_timer_read() usually returns the number of microseconds
0007  *  since benchmark_timer_initialize() exitted.
0008  *
0009  *  NOTE: It is important that the timer start/stop overhead be
0010  *        determined when porting or modifying this code.
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  *  COPYRIGHT (c) Yann Sionneau <yann.sionneau@telecom-sudparis.eu> (GSoC 2010)
0017  *  Telecom SudParis
0018  */
0019 
0020 #include <rtems.h>
0021 #include <bsp.h>
0022 #include <rtems/btimer.h>
0023 #include <rtems/bspIo.h>
0024 #include "../include/system_conf.h"
0025 #include "../../shared/clock/clock.h"
0026 
0027 bool benchmark_timer_find_average_overhead;
0028 
0029 void benchmark_timer_initialize(void)
0030 {
0031   MM_WRITE(MM_TIMER1_COMPARE, 0xffffffff);
0032   MM_WRITE(MM_TIMER1_COUNTER, 0);
0033   MM_WRITE(MM_TIMER1_CONTROL, TIMER_ENABLE);
0034 }
0035 
0036 /*
0037  *  The following controls the behavior of benchmark_timer_read().
0038  *
0039  *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
0040  *  is usually deducted from the number returned.
0041  *
0042  *  LEAST_VALID is the lowest number this routine should trust.  Numbers
0043  *  below this are "noise" and zero is returned.
0044  */
0045 
0046 #define AVG_OVERHEAD      4  /* It typically takes X.X microseconds */
0047                              /* (Y countdowns) to start/stop the timer. */
0048                              /* This value is in microseconds. */
0049 #define LEAST_VALID       4  /* Don't trust a clicks value lower than this */
0050 
0051 benchmark_timer_t benchmark_timer_read(void)
0052 {
0053   uint32_t ticks;
0054   uint32_t total;
0055 
0056   ticks = MM_READ(MM_TIMER1_COUNTER);
0057   if (ticks == 0xffffffff)
0058     printk("Timer overflow!\n");
0059 
0060   total = ticks / (MM_READ(MM_FREQUENCY) / 1000000);
0061 
0062   if (benchmark_timer_find_average_overhead)
0063     return total;
0064   else
0065   {
0066     if (total < LEAST_VALID)
0067       return 0;
0068 
0069     return (total - AVG_OVERHEAD);
0070   }
0071 }
0072 
0073 void benchmark_timer_disable_subtracting_average_overhead(
0074   bool find_flag
0075 )
0076 {
0077   benchmark_timer_find_average_overhead = find_flag;
0078 }