Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
cpu_load.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, Nordic Semiconductor ASA
3 * Copyright (c) 2025 Analog Devices, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef ZEPHYR_INCLUDE_SYS_CPU_LOAD_H_
9#define ZEPHYR_INCLUDE_SYS_CPU_LOAD_H_
10
11#include <stdbool.h>
12#include <stdint.h>
13#include <zephyr/toolchain.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
38
40#define CPU_LOAD_PERMILLE_TO_PERCENT(permille) ((permille) / 10)
41
50int cpu_load_get_cpu(unsigned int cpu_id, bool reset);
51
59int cpu_load_get(bool reset);
60
66
72
79void cpu_load_log_control(bool enable);
80
81/* Optional callback for cpu_load_cb_reg
82 *
83 * This will be called from the k_timer expiry_fn used for periodic logging.
84 * CONFIG_CPU_LOAD_LOG_PERIODICALLY must be configured to a positive value.
85 * Time spent in this callback must be kept to a minimum.
86 */
87typedef void (*cpu_load_cb_t)(uint8_t percent);
88
98int cpu_load_cb_reg(cpu_load_cb_t cb, uint8_t threshold_percent);
99
110__deprecated static inline int cpu_load_metric_get(int cpu_id)
111{
112 int load = cpu_load_get_cpu((unsigned int)cpu_id, true);
113
114 return (load < 0) ? load : CPU_LOAD_PERMILLE_TO_PERCENT(load);
115}
116
120
121#ifdef __cplusplus
122}
123#endif
124
125#endif /* ZEPHYR_INCLUDE_SYS_CPU_LOAD_H_ */
#define CPU_LOAD_PERMILLE_TO_PERCENT(permille)
Convert a per mille CPU load value to whole percent.
Definition cpu_load.h:40
void cpu_load_on_enter_idle(void)
Hook called on entering CPU idle.
static int cpu_load_metric_get(int cpu_id)
Get CPU load as a percentage for a specific CPU.
Definition cpu_load.h:110
void(* cpu_load_cb_t)(uint8_t percent)
Definition cpu_load.h:87
void cpu_load_on_exit_idle(void)
Hook called on exiting CPU idle.
int cpu_load_get_cpu(unsigned int cpu_id, bool reset)
Get CPU load for a specific CPU.
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.
int cpu_load_get(bool reset)
Get CPU load for the current CPU.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Macros to abstract toolchain specific capabilities.