Cygcpuloadget, Implementation details – Comtrol eCos User Manual

Page 650

Advertising
background image

Chapter 51. CPU Load Measurements

handle

should be the value returned by the create function.

cyg_cpuload_get

This function returns the latest measurements.

void cyg_cpuload_get(cyg_handle_t handle,

cyg_uint32 *average_point1s,

cyg_uint32 *average_1s,

cyg_uint32 *average_10s);

handle

should be the value returned by the create function. The load measurements for the last 100ms, 1s and

10s are returned in

*average_point1s

,

*average_1s

and

*average_10s

respectively.

Implementation details

This section gives a few details of how the measurements are made. This should help to understand what the results
mean.

When there are no other threads runnable, eCos will execute the idle thread. This thread is always runnable
and uses the lowest thread priority. The idle thread does little. It is an endless loop which increments the vari-
able,

idle_thread_loops

and executes the macro

HAL_IDLE_THREAD_ACTION

. The cpu load measurement code

makes use of the variable. It periodically examines the value of the variable and sees how much it has changed.
The idler the system, the more it will have incremented. From this it is simple to determine the load of the system.

The function

cyg_cpuload_calibrate

executes the idle thread for 100ms to determine how much

idle_thread_loops

is incremented on a system idle for 100ms.

cyg_cpuload_create

starts an alarm which

every 100ms calls an alarm function. This function looks at the difference in

idle_thread_loops

since the

last invocation of the alarm function and so calculated how idle or busy the system has been. The structure

cyg_cpuload

is updated during the alarm functions with the new results. The 100ms result is simply the result

from the last measurement period. A simple filter is used to average the load over a period of time, namely 1s and
10s. Due to rounding errors, the 1s and 10s value will probably never reach 100% on a fully loaded system, but
99% is often seen.

As stated above, clever power management code will interfere with these measurements. The basic assumption is
that the idle thread will be executed un-hindered and under the same conditions as when the calibration function
was executed. If the CPU clock rate is reduced, the idle thread counter will be incremented less and so the CPU
load measurements will give values too high. If the CPU is halted entirely, 100% cpu load will be measured.

546

Advertising