Commit 73ce0324 authored by Eric Hay's avatar Eric Hay Committed by Henrik Brix Andersen
Browse files

cpu_load: Add CPU Load subsystem



Implement CPU load measurement subsystem. The statistics
used to calcualte the load are taken from the scheduler.
Specifically, the number of cycles used by the idle thread.

Co-authored-by: default avatarSean Kyer <Sean.Kyer@analog.com>
Signed-off-by: default avatarEric Hay <Eric.Hay@analog.com>
parent c7578b00
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
.. _cpu_load_subsys:

CPU Load
########

The CPU Load subsystem returns the CPU load as a percentage for the current CPU, since the last time
it was called.

For an example of the CPU Load subsystem refer to :zephyr:code-sample:`cpu_freq_on_demand` sample.
+1 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ OS Services

   binary_descriptors/index.rst
   console.rst
   cpu_load/index.rst
   crypto/index
   debugging/index.rst
   device_mgmt/index
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2025 Analog Devices, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef ZEPHYR_SUBSYS_CPU_LOAD_H_
#define ZEPHYR_SUBSYS_CPU_LOAD_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief CPU Load Monitoring
 * @defgroup subsys_cpu_load CPU Load
 * @since 4.3
 * @version 0.1.0
 * @ingroup os_services
 * @{
 */

/**
 * @brief Get the CPU load as a percentage.
 *
 * Return the percent that the CPU has spent in the active (non-idle) state between calls to this
 * function.
 *
 * @param cpu_id The ID of the CPU for which to get the load.
 *
 * @retval CPU load in percent (0-100) in case of success
 * @retval -errno code in case of failure.
 *
 */
int cpu_load_get(int cpu_id);

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_SUBSYS_CPU_LOAD_H_ */
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ add_subdirectory_ifdef(CONFIG_ARM_SIP_SVC_SUBSYS sip_svc)
add_subdirectory_ifdef(CONFIG_BINDESC bindesc)
add_subdirectory_ifdef(CONFIG_BT bluetooth)
add_subdirectory_ifdef(CONFIG_CONSOLE_SUBSYS console)
add_subdirectory_ifdef(CONFIG_CPU_LOAD_METRIC cpu_load)
add_subdirectory_ifdef(CONFIG_DAP dap)
add_subdirectory_ifdef(CONFIG_DEMAND_PAGING demand_paging)
add_subdirectory_ifdef(CONFIG_DISK_ACCESS disk)
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ source "subsys/bindesc/Kconfig"
source "subsys/bluetooth/Kconfig"
source "subsys/canbus/Kconfig"
source "subsys/console/Kconfig"
source "subsys/cpu_load/Kconfig"
source "subsys/dap/Kconfig"
source "subsys/debug/Kconfig"
source "subsys/demand_paging/Kconfig"
Loading