Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
CPU load monitor

Module for monitoring CPU load. More...

Macros

#define CPU_LOAD_PERMILLE_TO_PERCENT(permille)
 Convert a per mille CPU load value to whole percent.

Typedefs

typedef void(* cpu_load_cb_t) (uint8_t percent)

Functions

int cpu_load_get_cpu (unsigned int cpu_id, bool reset)
 Get CPU load for a specific CPU.
int cpu_load_get (bool reset)
 Get CPU load for the current CPU.
void cpu_load_on_enter_idle (void)
 Hook called on entering CPU idle.
void cpu_load_on_exit_idle (void)
 Hook called on exiting CPU idle.
void cpu_load_log_control (bool enable)
 Control periodic CPU load report.
int cpu_load_cb_reg (cpu_load_cb_t cb, uint8_t threshold_percent)
 Optional registration of callback when load is greater or equal to the threshold.
static int cpu_load_metric_get (int cpu_id)
 Get CPU load as a percentage for a specific CPU.

Detailed Description

Module for monitoring CPU load.

The CPU load is the fraction of time the CPU spends outside of the idle state. Two measurement backends are available and selected through Kconfig:

  • CONFIG_CPU_LOAD_BACKEND_RUNTIME_STATS 
    derives the load from the scheduler per-CPU runtime statistics. It is portable across architectures and supports multiple CPUs.
  • CONFIG_CPU_LOAD_BACKEND_IDLE_HOOK 
    measures the load using the architecture idle hooks. It has lower overhead and can optionally use a hardware counter for higher precision (the counter path is single-CPU only). Available on any architecture that emits the idle hooks (
    CONFIG_ARCH_HAS_CPU_IDLE_HOOKS 
    ).

Regardless of the backend, the load is reported in per mille (0...1000).

Macro Definition Documentation

◆ CPU_LOAD_PERMILLE_TO_PERCENT

#define CPU_LOAD_PERMILLE_TO_PERCENT ( permille)

#include <cpu_load.h>

Value:
((permille) / 10)

Convert a per mille CPU load value to whole percent.

Typedef Documentation

◆ cpu_load_cb_t

typedef void(* cpu_load_cb_t) (uint8_t percent)

#include <cpu_load.h>

Function Documentation

◆ cpu_load_cb_reg()

int cpu_load_cb_reg ( cpu_load_cb_t cb,
uint8_t threshold_percent )

#include <cpu_load.h>

Optional registration of callback when load is greater or equal to the threshold.

Parameters
cbPointer to the callback function. NULL will cancel the callback.
threshold_percentThreshold [0...100]. CPU load equal or greater that this will trigger the callback.
Return values
0- Callback registered/cancelled.
-EINVALif the threshold is invalid.

◆ cpu_load_get()

int cpu_load_get ( bool reset)

#include <cpu_load.h>

Get CPU load for the current CPU.

Parameters
resetReset the measurement window after reading.
Return values
>=0CPU load in per mille (0...1000).
<0Negative errno code on failure.

◆ cpu_load_get_cpu()

int cpu_load_get_cpu ( unsigned int cpu_id,
bool reset )

#include <cpu_load.h>

Get CPU load for a specific CPU.

Parameters
cpu_idCPU index for which to get the load.
resetReset the measurement window after reading.
Return values
>=0CPU load in per mille (0...1000).
<0Negative errno code on failure.

◆ cpu_load_log_control()

void cpu_load_log_control ( bool enable)

#include <cpu_load.h>

Control periodic CPU load report.

Report logging is by default enabled.

Parameters
enabletrue to enable report logging and false to disable.

◆ cpu_load_metric_get()

int cpu_load_metric_get ( int cpu_id)
inlinestatic

#include <cpu_load.h>

Get CPU load as a percentage for a specific CPU.

Deprecated
Use cpu_load_get_cpu() instead. Note that cpu_load_get_cpu() returns the load in per mille rather than percent.
Parameters
cpu_idCPU index for which to get the load.
Return values
>=0CPU load in percent (0...100).
<0Negative errno code on failure.

◆ cpu_load_on_enter_idle()

void cpu_load_on_enter_idle ( void )

#include <cpu_load.h>

Hook called on entering CPU idle.

Only used by the idle-hook backend; called from the architecture idle path.

◆ cpu_load_on_exit_idle()

void cpu_load_on_exit_idle ( void )

#include <cpu_load.h>

Hook called on exiting CPU idle.

Only used by the idle-hook backend; called from the architecture idle path.