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