1 | .. COMMENT: COPYRIGHT (c) 1988-2008. |
---|
2 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
3 | .. COMMENT: All rights reserved. |
---|
4 | |
---|
5 | CPU Usage Statistics |
---|
6 | #################### |
---|
7 | |
---|
8 | Introduction |
---|
9 | ============ |
---|
10 | |
---|
11 | The CPU usage statistics manager is an RTEMS support component that provides a |
---|
12 | convenient way to manipulate the CPU usage information associated with each |
---|
13 | task The routines provided by the CPU usage statistics manager are: |
---|
14 | |
---|
15 | - rtems_cpu_usage_report_ - Report CPU Usage Statistics |
---|
16 | |
---|
17 | - rtems_cpu_usage_reset_ - Reset CPU Usage Statistics |
---|
18 | |
---|
19 | Background |
---|
20 | ========== |
---|
21 | |
---|
22 | When analyzing and debugging real-time applications, it is important to be able |
---|
23 | to know how much CPU time each task in the system consumes. This support |
---|
24 | component provides a mechanism to easily obtain this information with little |
---|
25 | burden placed on the target. |
---|
26 | |
---|
27 | The raw data is gathered as part of performing a context switch. RTEMS keeps |
---|
28 | track of how many clock ticks have occurred which the task being switched out |
---|
29 | has been executing. If the task has been running less than 1 clock tick, then |
---|
30 | for the purposes of the statistics, it is assumed to have executed 1 clock |
---|
31 | tick. This results in some inaccuracy but the alternative is for the task to |
---|
32 | have appeared to execute 0 clock ticks. |
---|
33 | |
---|
34 | RTEMS versions newer than the 4.7 release series, support the ability to obtain |
---|
35 | timestamps with nanosecond granularity if the BSP provides support. It is a |
---|
36 | desirable enhancement to change the way the usage data is gathered to take |
---|
37 | advantage of this recently added capability. Please consider sponsoring the |
---|
38 | core RTEMS development team to add this capability. |
---|
39 | |
---|
40 | Operations |
---|
41 | ========== |
---|
42 | |
---|
43 | Report CPU Usage Statistics |
---|
44 | --------------------------- |
---|
45 | |
---|
46 | The application may dynamically report the CPU usage for every task in the |
---|
47 | system by calling the ``rtems_cpu_usage_report`` routine. This routine prints |
---|
48 | a table with the following information per task: |
---|
49 | |
---|
50 | - task id |
---|
51 | |
---|
52 | - task name |
---|
53 | |
---|
54 | - number of clock ticks executed |
---|
55 | |
---|
56 | - percentage of time consumed by this task |
---|
57 | |
---|
58 | The following is an example of the report generated: |
---|
59 | |
---|
60 | .. code:: c |
---|
61 | |
---|
62 | +------------------------------------------------------------------------------+ |
---|
63 | |CPU USAGE BY THREAD | |
---|
64 | +-----------+----------------------------------------+-------------------------+ |
---|
65 | |ID | NAME | SECONDS | PERCENT | |
---|
66 | +-----------+----------------------------------------+---------------+---------+ |
---|
67 | |0x04010001 | IDLE | 0 | 0.000 | |
---|
68 | +-----------+----------------------------------------+---------------+---------+ |
---|
69 | |0x08010002 | TA1 | 1203 | 0.748 | |
---|
70 | +-----------+----------------------------------------+---------------+---------+ |
---|
71 | |0x08010003 | TA2 | 203 | 0.126 | |
---|
72 | +-----------+----------------------------------------+---------------+---------+ |
---|
73 | |0x08010004 | TA3 | 202 | 0.126 | |
---|
74 | +-----------+----------------------------------------+---------------+---------+ |
---|
75 | |TICKS SINCE LAST SYSTEM RESET: 1600 | |
---|
76 | |TOTAL UNITS: 1608 | |
---|
77 | +------------------------------------------------------------------------------+ |
---|
78 | |
---|
79 | Notice that the ``TOTAL UNITS`` is greater than the ticks per reset. This is |
---|
80 | an artifact of the way in which RTEMS keeps track of CPU usage. When a task is |
---|
81 | context switched into the CPU, the number of clock ticks it has executed is |
---|
82 | incremented. While the task is executing, this number is incremented on each |
---|
83 | clock tick. Otherwise, if a task begins and completes execution between |
---|
84 | successive clock ticks, there would be no way to tell that it executed at all. |
---|
85 | |
---|
86 | Another thing to keep in mind when looking at idle time, is that many systems - |
---|
87 | especially during debug - have a task providing some type of debug interface. |
---|
88 | It is usually fine to think of the total idle time as being the sum of the |
---|
89 | ``IDLE`` task and a debug task that will not be included in a production build |
---|
90 | of an application. |
---|
91 | |
---|
92 | Reset CPU Usage Statistics |
---|
93 | -------------------------- |
---|
94 | |
---|
95 | Invoking the ``rtems_cpu_usage_reset`` routine resets the CPU usage statistics |
---|
96 | for all tasks in the system. |
---|
97 | |
---|
98 | Directives |
---|
99 | ========== |
---|
100 | |
---|
101 | This section details the CPU usage statistics manager's directives. A |
---|
102 | subsection is dedicated to each of this manager's directives and describes the |
---|
103 | calling sequence, related constants, usage, and status codes. |
---|
104 | |
---|
105 | .. _rtems_cpu_usage_report: |
---|
106 | |
---|
107 | cpu_usage_report - Report CPU Usage Statistics |
---|
108 | ---------------------------------------------- |
---|
109 | |
---|
110 | **CALLING SEQUENCE:** |
---|
111 | |
---|
112 | .. code:: c |
---|
113 | |
---|
114 | void rtems_cpu_usage_report( void ); |
---|
115 | |
---|
116 | **STATUS CODES:** |
---|
117 | |
---|
118 | NONE |
---|
119 | |
---|
120 | **DESCRIPTION:** |
---|
121 | |
---|
122 | This routine prints out a table detailing the CPU usage statistics for all |
---|
123 | tasks in the system. |
---|
124 | |
---|
125 | **NOTES:** |
---|
126 | |
---|
127 | The table is printed using the ``printk`` routine. |
---|
128 | |
---|
129 | .. _rtems_cpu_usage_reset: |
---|
130 | |
---|
131 | cpu_usage_reset - Reset CPU Usage Statistics |
---|
132 | -------------------------------------------- |
---|
133 | |
---|
134 | **CALLING SEQUENCE:** |
---|
135 | |
---|
136 | .. code:: c |
---|
137 | |
---|
138 | void rtems_cpu_usage_reset( void ); |
---|
139 | |
---|
140 | **STATUS CODES:** |
---|
141 | |
---|
142 | NONE |
---|
143 | |
---|
144 | **DESCRIPTION:** |
---|
145 | |
---|
146 | This routine re-initializes the CPU usage statistics for all tasks in the |
---|
147 | system to their initial state. The initial state is that a task has not |
---|
148 | executed and thus has consumed no CPU time. default state which is when zero |
---|
149 | period executions have occurred. |
---|
150 | |
---|
151 | **NOTES:** |
---|
152 | |
---|
153 | NONE |
---|