1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
12 >CPU Load Measurements</TITLE
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="CPU load measurements"
23 HREF="services-cpuload.html"><LINK
25 TITLE="CPU load measurements"
26 HREF="services-cpuload.html"><LINK
28 TITLE="Application profiling"
29 HREF="services-profile-gprof.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="services-cpuload.html"
71 HREF="services-profile-gprof.html"
84 NAME="CPULOAD-FUNCTIONS">Chapter 51. CPU Load Measurements</H1
90 NAME="SERVICES-CPULOAD-API">CPU Load API</H1
92 >The package allows the CPU load to be estimated. The measurement code
93 must first be calibrated to the target it is running on. Once this
94 has been performed the measurement process can be started. This is a
95 continuous process, so always providing the most up to data
96 measurements. The process can be stopped at any time if required. Once
97 the process is active, the results can be retrieved.</P
99 >Note that if the target/processor performs any power saving actions,
100 such as reducing the clock speed, or halting until the next interrupt
101 etc, these will interfere with the CPU load measurement. Under these
102 conditions the measurement results are undefined. The synthetic target
103 is one such system. See the implementation details at the foot of this
104 page for further information. </P
106 >SMP systems are not supported, only uniprocessor system.</P
108 > The API for load measuring functions can be
109 found in the file <TT
111 >cyg/cpuload/cpuload.h</TT
118 NAME="SERVICES-CPULOAD-API-CYG-CPULOAD-CALIBRATE">cyg_cpuload_calibrate</H2
120 >This function is used to calibrate the cpu load measurement code. It
121 makes a measurement to determine the CPU properties while idle.</P
129 CLASS="PROGRAMLISTING"
130 >void cyg_cpuload_calibrate(cyg_uint32 *calibration);</PRE
135 >The function returns the calibration value at the location pointed to
143 >This function is quite unusual. For it to work correctly a few
144 conditions must be met. The function makes use of the two highest
145 thread priorities. No other threads must be using these priorities
146 while the function is being used. The kernel scheduler must be started
147 and not disabled. The function takes 100ms to complete during which
148 time no other threads will be run.</P
155 NAME="SERVICES-CPULOAD-API-CYG-CPULOAD-CREATE">cyg_cpuload_create</H2
157 >This function starts the CPU load measurments.</P
165 CLASS="PROGRAMLISTING"
166 >void cyg_cpuload_create(cyg_cpuload_t *cpuload,
167 cyg_uint32 calibrate,
168 cyg_handle_t *handle);</PRE
173 >The measurement process is started and a handle to it is returned in
179 >. This handle is used to access the
180 results and the stop the measurement process. </P
187 NAME="SERVICES-CPULOAD-API-CYG-CPULOAD-DELETE">cyg_cpuload_delete</H2
189 >This function stops the measurement process. </P
197 CLASS="PROGRAMLISTING"
198 >void cyg_cpuload_delete(cyg_handle_t handle);</PRE
208 > should be the value returned by the create function.</P
215 NAME="SERVICES-CPULOAD-API-CYG-CPULOAD-GET">cyg_cpuload_get</H2
217 >This function returns the latest measurements.</P
225 CLASS="PROGRAMLISTING"
226 >void cyg_cpuload_get(cyg_handle_t handle,
227 cyg_uint32 *average_point1s,
228 cyg_uint32 *average_1s,
229 cyg_uint32 *average_10s);</PRE
239 > should be the value returned by the
240 create function. The load measurements for the last 100ms, 1s and 10s
265 NAME="SERVICES-CPULOAD-API-IMPLEMENTATION">Implementation details</H2
267 >This section gives a few details of how the measurements are
268 made. This should help to understand what the results mean.</P
270 >When there are no other threads runnable, eCos will execute the idle
271 thread. This thread is always runnable and uses the lowest thread
272 priority. The idle thread does little. It is an endless loop which
273 increments the variable, <TT
275 >idle_thread_loops</TT
277 executes the macro <TT
279 >HAL_IDLE_THREAD_ACTION</TT
281 load measurement code makes use of the variable. It periodically
282 examines the value of the variable and sees how much it has
283 changed. The idler the system, the more it will have incremented. From
284 this it is simple to determine the load of the system.</P
288 >cyg_cpuload_calibrate</TT
290 idle thread for 100ms to determine how much
293 >idle_thread_loops</TT
294 > is incremented on a system idle
297 >cyg_cpuload_create</TT
298 > starts an alarm which
299 every 100ms calls an alarm function. This function looks at the
302 >idle_thread_loops</TT
304 invocation of the alarm function and so calculated how idle or busy
305 the system has been. The structure <TT
309 updated during the alarm functions with the new results. The 100ms
310 result is simply the result from the last measurement period. A simple
311 filter is used to average the load over a period of time, namely 1s
312 and 10s. Due to rounding errors, the 1s and 10s value will probably
313 never reach 100% on a fully loaded system, but 99% is often seen.</P
315 >As stated above, clever power management code will interfere with
316 these measurements. The basic assumption is that the idle thread will
317 be executed un-hindered and under the same conditions as when the
318 calibration function was executed. If the CPU clock rate is reduced,
319 the idle thread counter will be incremented less and so the CPU load
320 measurements will give values too high. If the CPU is halted entirely,
321 100% cpu load will be measured.</P
330 SUMMARY="Footer navigation table"
341 HREF="services-cpuload.html"
359 HREF="services-profile-gprof.html"
369 >CPU load measurements</TD
375 HREF="services-cpuload.html"
383 >Application profiling</TD