1 | .. comment SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. COMMENT: COPYRIGHT (c) 1988-2002. |
---|
4 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
5 | .. COMMENT: All rights reserved. |
---|
6 | |
---|
7 | Timer Driver |
---|
8 | ############ |
---|
9 | |
---|
10 | The timer driver is primarily used by the RTEMS Timing Tests. This driver |
---|
11 | provides as accurate a benchmark timer as possible. It typically reports its |
---|
12 | time in microseconds, CPU cycles, or bus cycles. This information can be very |
---|
13 | useful for determining precisely what pieces of code require optimization and |
---|
14 | to measure the impact of specific minor changes. |
---|
15 | |
---|
16 | The gen68340 BSP also uses the Timer Driver to support a high performance mode |
---|
17 | of the on-CPU UART. |
---|
18 | |
---|
19 | Benchmark Timer |
---|
20 | =============== |
---|
21 | |
---|
22 | The RTEMS Timing Test Suite requires a benchmark timer. The RTEMS Timing Test |
---|
23 | Suite is very helpful for determining the performance of target hardware and |
---|
24 | comparing its performance to that of other RTEMS targets. |
---|
25 | |
---|
26 | This section describes the routines which are assumed to exist by the RTEMS |
---|
27 | Timing Test Suite. The names used are *EXACTLY* what is used in the RTEMS |
---|
28 | Timing Test Suite so follow the naming convention. |
---|
29 | |
---|
30 | benchmark_timer_initialize |
---|
31 | -------------------------- |
---|
32 | |
---|
33 | Initialize the timer source. |
---|
34 | |
---|
35 | .. code-block:: c |
---|
36 | |
---|
37 | void benchmark_timer_initialize(void) |
---|
38 | { |
---|
39 | initialize the benchmark timer |
---|
40 | } |
---|
41 | |
---|
42 | Read_timer |
---|
43 | ---------- |
---|
44 | |
---|
45 | The ``benchmark_timer_read`` routine returns the number of benchmark time units |
---|
46 | (typically microseconds) that have elapsed since the last call to |
---|
47 | ``benchmark_timer_initialize``. |
---|
48 | |
---|
49 | .. code-block:: c |
---|
50 | |
---|
51 | benchmark_timer_t benchmark_timer_read(void) |
---|
52 | { |
---|
53 | stop time = read the hardware timer |
---|
54 | if the subtract overhead feature is enabled |
---|
55 | subtract overhead from stop time |
---|
56 | return the stop time |
---|
57 | } |
---|
58 | |
---|
59 | Many implementations of this routine subtract the overhead required to |
---|
60 | initialize and read the benchmark timer. This makes the times reported more |
---|
61 | accurate. |
---|
62 | |
---|
63 | Some implementations report 0 if the harware timer value change is sufficiently |
---|
64 | small. This is intended to indicate that the execution time is below the |
---|
65 | resolution of the timer. |
---|
66 | |
---|
67 | benchmark_timer_disable_subtracting_average_overhead |
---|
68 | ---------------------------------------------------- |
---|
69 | |
---|
70 | This routine is invoked by the "Check Timer" (``tmck``) test in the RTEMS |
---|
71 | Timing Test Suite. It makes the ``benchmark_timer_read`` routine NOT subtract |
---|
72 | the overhead required to initialize and read the benchmark timer. This is used |
---|
73 | by the ``tmoverhd`` test to determine the overhead required to initialize and |
---|
74 | read the timer. |
---|
75 | |
---|
76 | .. code:: c |
---|
77 | |
---|
78 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
79 | { |
---|
80 | disable the subtract overhead feature |
---|
81 | } |
---|
82 | |
---|
83 | The ``benchmark_timer_find_average_overhead`` variable is used to indicate the |
---|
84 | state of the "subtract overhead feature". |
---|
85 | |
---|
86 | gen68340 UART FIFO Full Mode |
---|
87 | ============================ |
---|
88 | |
---|
89 | The gen68340 BSP is an example of the use of the timer to support the UART |
---|
90 | input FIFO full mode (FIFO means First In First Out and roughly means |
---|
91 | buffer). This mode consists in the UART raising an interrupt when n characters |
---|
92 | have been received (*n* is the UART's FIFO length). It results in a lower |
---|
93 | interrupt processing time, but the problem is that a scanf primitive will block |
---|
94 | on a receipt of less than *n* characters. The solution is to set a timer that |
---|
95 | will check whether there are some characters waiting in the UART's input |
---|
96 | FIFO. The delay time has to be set carefully otherwise high rates will be |
---|
97 | broken: |
---|
98 | |
---|
99 | - if no character was received last time the interrupt subroutine was entered, |
---|
100 | set a long delay, |
---|
101 | |
---|
102 | - otherwise set the delay to the delay needed for ``n`` characters receipt. |
---|