|
|
CPU load measurements
|
CPU load measurements
|
|
|
|
|
The cpuload package provides a way to estimate the cpuload. It gives
|
The cpuload package provides a way to estimate the cpuload. It gives
|
an estimated percentage load for the last 100 milliseconds, 1 second
|
an estimated percentage load for the last 100 milliseconds, 1 second
|
and 10 seconds.
|
and 10 seconds.
|
|
|
|
|
|
|
CPU Load Measurements
|
CPU Load Measurements
|
|
|
CPU Load API
|
CPU Load API
|
|
|
The package allows the CPU load to be estimated. The measurement code
|
The package allows the CPU load to be estimated. The measurement code
|
must first be calibrated to the target it is running on. Once this
|
must first be calibrated to the target it is running on. Once this
|
has been performed the measurement process can be started. This is a
|
has been performed the measurement process can be started. This is a
|
continuous process, so always providing the most up to data
|
continuous process, so always providing the most up to data
|
measurements. The process can be stopped at any time if required. Once
|
measurements. The process can be stopped at any time if required. Once
|
the process is active, the results can be retrieved.
|
the process is active, the results can be retrieved.
|
|
|
|
|
Note that if the target/processor performs any power saving actions,
|
Note that if the target/processor performs any power saving actions,
|
such as reducing the clock speed, or halting until the next interrupt
|
such as reducing the clock speed, or halting until the next interrupt
|
etc, these will interfere with the CPU load measurement. Under these
|
etc, these will interfere with the CPU load measurement. Under these
|
conditions the measurement results are undefined. The synthetic target
|
conditions the measurement results are undefined. The synthetic target
|
is one such system. See the implementation details at the foot of this
|
is one such system. See the implementation details at the foot of this
|
page for further information.
|
page for further information.
|
|
|
SMP systems are not supported, only uniprocessor system.
|
SMP systems are not supported, only uniprocessor system.
|
|
|
The API for load measuring functions can be
|
The API for load measuring functions can be
|
found in the file cyg/cpuload/cpuload.h.
|
found in the file cyg/cpuload/cpuload.h.
|
|
|
|
|
cyg_cpuload_calibrate
|
cyg_cpuload_calibrate
|
|
|
This function is used to calibrate the cpu load measurement code. It
|
This function is used to calibrate the cpu load measurement code. It
|
makes a measurement to determine the CPU properties while idle.
|
makes a measurement to determine the CPU properties while idle.
|
|
|
|
|
void cyg_cpuload_calibrate(cyg_uint32 *calibration);
|
void cyg_cpuload_calibrate(cyg_uint32 *calibration);
|
|
|
|
|
The function returns the calibration value at the location pointed to
|
The function returns the calibration value at the location pointed to
|
by calibration.
|
by calibration.
|
|
|
|
|
This function is quite unusual. For it to work correctly a few
|
This function is quite unusual. For it to work correctly a few
|
conditions must be met. The function makes use of the two highest
|
conditions must be met. The function makes use of the two highest
|
thread priorities. No other threads must be using these priorities
|
thread priorities. No other threads must be using these priorities
|
while the function is being used. The kernel scheduler must be started
|
while the function is being used. The kernel scheduler must be started
|
and not disabled. The function takes 100ms to complete during which
|
and not disabled. The function takes 100ms to complete during which
|
time no other threads will be run.
|
time no other threads will be run.
|
|
|
|
|
|
|
cyg_cpuload_create
|
cyg_cpuload_create
|
|
|
This function starts the CPU load measurments.
|
This function starts the CPU load measurments.
|
|
|
|
|
void cyg_cpuload_create(cyg_cpuload_t *cpuload,
|
void cyg_cpuload_create(cyg_cpuload_t *cpuload,
|
cyg_uint32 calibrate,
|
cyg_uint32 calibrate,
|
cyg_handle_t *handle);
|
cyg_handle_t *handle);
|
|
|
|
|
The measurement process is started and a handle to it is returned in
|
The measurement process is started and a handle to it is returned in
|
*handle. This handle is used to access the
|
*handle. This handle is used to access the
|
results and the stop the measurement process.
|
results and the stop the measurement process.
|
|
|
|
|
|
|
cyg_cpuload_delete
|
cyg_cpuload_delete
|
|
|
This function stops the measurement process.
|
This function stops the measurement process.
|
|
|
|
|
void cyg_cpuload_delete(cyg_handle_t handle);
|
void cyg_cpuload_delete(cyg_handle_t handle);
|
|
|
|
|
handle should be the value returned by the create function.
|
handle should be the value returned by the create function.
|
|
|
|
|
|
|
cyg_cpuload_get
|
cyg_cpuload_get
|
|
|
This function returns the latest measurements.
|
This function returns the latest measurements.
|
|
|
|
|
void cyg_cpuload_get(cyg_handle_t handle,
|
void cyg_cpuload_get(cyg_handle_t handle,
|
cyg_uint32 *average_point1s,
|
cyg_uint32 *average_point1s,
|
cyg_uint32 *average_1s,
|
cyg_uint32 *average_1s,
|
cyg_uint32 *average_10s);
|
cyg_uint32 *average_10s);
|
|
|
|
|
handle should be the value returned by the
|
handle should be the value returned by the
|
create function. The load measurements for the last 100ms, 1s and 10s
|
create function. The load measurements for the last 100ms, 1s and 10s
|
are returned in
|
are returned in
|
*average_point1s,*average_1s
|
*average_point1s,*average_1s
|
and *average_10s respectively.
|
and *average_10s respectively.
|
|
|
|
|
|
|
Implementation details
|
Implementation details
|
|
|
This section gives a few details of how the measurements are
|
This section gives a few details of how the measurements are
|
made. This should help to understand what the results mean.
|
made. This should help to understand what the results mean.
|
|
|
|
|
When there are no other threads runnable, eCos will execute the idle
|
When there are no other threads runnable, eCos will execute the idle
|
thread. This thread is always runnable and uses the lowest thread
|
thread. This thread is always runnable and uses the lowest thread
|
priority. The idle thread does little. It is an endless loop which
|
priority. The idle thread does little. It is an endless loop which
|
increments the variable, idle_thread_loops and
|
increments the variable, idle_thread_loops and
|
executes the macro HAL_IDLE_THREAD_ACTION. The cpu
|
executes the macro HAL_IDLE_THREAD_ACTION. The cpu
|
load measurement code makes use of the variable. It periodically
|
load measurement code makes use of the variable. It periodically
|
examines the value of the variable and sees how much it has
|
examines the value of the variable and sees how much it has
|
changed. The idler the system, the more it will have incremented. From
|
changed. The idler the system, the more it will have incremented. From
|
this it is simple to determine the load of the system.
|
this it is simple to determine the load of the system.
|
|
|
|
|
The function cyg_cpuload_calibrate executes the
|
The function cyg_cpuload_calibrate executes the
|
idle thread for 100ms to determine how much
|
idle thread for 100ms to determine how much
|
idle_thread_loops is incremented on a system idle
|
idle_thread_loops is incremented on a system idle
|
for 100ms. cyg_cpuload_create starts an alarm which
|
for 100ms. cyg_cpuload_create starts an alarm which
|
every 100ms calls an alarm function. This function looks at the
|
every 100ms calls an alarm function. This function looks at the
|
difference in idle_thread_loops since the last
|
difference in idle_thread_loops since the last
|
invocation of the alarm function and so calculated how idle or busy
|
invocation of the alarm function and so calculated how idle or busy
|
the system has been. The structure cyg_cpuload is
|
the system has been. The structure cyg_cpuload is
|
updated during the alarm functions with the new results. The 100ms
|
updated during the alarm functions with the new results. The 100ms
|
result is simply the result from the last measurement period. A simple
|
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
|
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
|
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.
|
never reach 100% on a fully loaded system, but 99% is often seen.
|
|
|
|
|
As stated above, clever power management code will interfere with
|
As stated above, clever power management code will interfere with
|
these measurements. The basic assumption is that the idle thread will
|
these measurements. The basic assumption is that the idle thread will
|
be executed un-hindered and under the same conditions as when the
|
be executed un-hindered and under the same conditions as when the
|
calibration function was executed. If the CPU clock rate is reduced,
|
calibration function was executed. If the CPU clock rate is reduced,
|
the idle thread counter will be incremented less and so the CPU load
|
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,
|
measurements will give values too high. If the CPU is halted entirely,
|
100% cpu load will be measured.
|
100% cpu load will be measured.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|