xref: /kernel/liteos_m/components/cpup/los_cpup.h (revision 3d8536b4)
13d8536b4Sopenharmony_ci/*
23d8536b4Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
33d8536b4Sopenharmony_ci * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
43d8536b4Sopenharmony_ci *
53d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
63d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met:
73d8536b4Sopenharmony_ci *
83d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
93d8536b4Sopenharmony_ci *    conditions and the following disclaimer.
103d8536b4Sopenharmony_ci *
113d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
123d8536b4Sopenharmony_ci *    of conditions and the following disclaimer in the documentation and/or other materials
133d8536b4Sopenharmony_ci *    provided with the distribution.
143d8536b4Sopenharmony_ci *
153d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
163d8536b4Sopenharmony_ci *    to endorse or promote products derived from this software without specific prior written
173d8536b4Sopenharmony_ci *    permission.
183d8536b4Sopenharmony_ci *
193d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
203d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
213d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
233d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
243d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
253d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
263d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
273d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
283d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
293d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
303d8536b4Sopenharmony_ci */
313d8536b4Sopenharmony_ci
323d8536b4Sopenharmony_ci/**
333d8536b4Sopenharmony_ci * @defgroup los_cpup CPU usage
343d8536b4Sopenharmony_ci * @ingroup kernel
353d8536b4Sopenharmony_ci */
363d8536b4Sopenharmony_ci
373d8536b4Sopenharmony_ci#ifndef _LOS_CPUP_H
383d8536b4Sopenharmony_ci#define _LOS_CPUP_H
393d8536b4Sopenharmony_ci
403d8536b4Sopenharmony_ci#include "los_interrupt.h"
413d8536b4Sopenharmony_ci#include "los_task.h"
423d8536b4Sopenharmony_ci
433d8536b4Sopenharmony_ci#ifdef __cplusplus
443d8536b4Sopenharmony_ci#if __cplusplus
453d8536b4Sopenharmony_ciextern "C" {
463d8536b4Sopenharmony_ci#endif /* __cplusplus */
473d8536b4Sopenharmony_ci#endif /* __cplusplus */
483d8536b4Sopenharmony_ci
493d8536b4Sopenharmony_ci
503d8536b4Sopenharmony_ci/**
513d8536b4Sopenharmony_ci* @ingroup los_cpup
523d8536b4Sopenharmony_ci* CPU usage error code: The request for memory fails.
533d8536b4Sopenharmony_ci*
543d8536b4Sopenharmony_ci* Value: 0x02001e00
553d8536b4Sopenharmony_ci*
563d8536b4Sopenharmony_ci* Solution: Decrease the maximum number of tasks.
573d8536b4Sopenharmony_ci*/
583d8536b4Sopenharmony_ci#define LOS_ERRNO_CPUP_NO_MEMORY             LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x00)
593d8536b4Sopenharmony_ci
603d8536b4Sopenharmony_ci/**
613d8536b4Sopenharmony_ci* @ingroup los_cpup
623d8536b4Sopenharmony_ci* CPU usage error code: The pointer to an input parameter is NULL.
633d8536b4Sopenharmony_ci*
643d8536b4Sopenharmony_ci* Value: 0x02001e01
653d8536b4Sopenharmony_ci*
663d8536b4Sopenharmony_ci* Solution: Check whether the pointer to the input parameter is usable.
673d8536b4Sopenharmony_ci*/
683d8536b4Sopenharmony_ci#define LOS_ERRNO_CPUP_TASK_PTR_NULL         LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x01)
693d8536b4Sopenharmony_ci
703d8536b4Sopenharmony_ci/**
713d8536b4Sopenharmony_ci* @ingroup los_cpup
723d8536b4Sopenharmony_ci* CPU usage error code: The CPU usage is not initialized.
733d8536b4Sopenharmony_ci*
743d8536b4Sopenharmony_ci* Value: 0x02001e02
753d8536b4Sopenharmony_ci*
763d8536b4Sopenharmony_ci* Solution: Check whether the CPU usage is initialized.
773d8536b4Sopenharmony_ci*/
783d8536b4Sopenharmony_ci#define LOS_ERRNO_CPUP_NO_INIT               LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x02)
793d8536b4Sopenharmony_ci
803d8536b4Sopenharmony_ci/**
813d8536b4Sopenharmony_ci* @ingroup los_cpup
823d8536b4Sopenharmony_ci* CPU usage error code: The number of threads is invalid.
833d8536b4Sopenharmony_ci*
843d8536b4Sopenharmony_ci* Value: 0x02001e03
853d8536b4Sopenharmony_ci*
863d8536b4Sopenharmony_ci* Solution: Check whether the number of threads is applicable for the current operation.
873d8536b4Sopenharmony_ci*/
883d8536b4Sopenharmony_ci#define LOS_ERRNO_CPUP_MAXNUM_INVALID        LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x03)
893d8536b4Sopenharmony_ci
903d8536b4Sopenharmony_ci/**
913d8536b4Sopenharmony_ci* @ingroup los_cpup
923d8536b4Sopenharmony_ci* CPU usage error code: The target thread is not created.
933d8536b4Sopenharmony_ci*
943d8536b4Sopenharmony_ci* Value: 0x02001e04
953d8536b4Sopenharmony_ci*
963d8536b4Sopenharmony_ci* Solution: Check whether the target thread is created.
973d8536b4Sopenharmony_ci*/
983d8536b4Sopenharmony_ci#define LOS_ERRNO_CPUP_THREAD_NO_CREATED     LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x04)
993d8536b4Sopenharmony_ci
1003d8536b4Sopenharmony_ci/**
1013d8536b4Sopenharmony_ci* @ingroup los_cpup
1023d8536b4Sopenharmony_ci* CPU usage error code: The target task ID is invalid.
1033d8536b4Sopenharmony_ci*
1043d8536b4Sopenharmony_ci* Value: 0x02001e05
1053d8536b4Sopenharmony_ci*
1063d8536b4Sopenharmony_ci* Solution: Check whether the target task ID is applicable for the current operation.
1073d8536b4Sopenharmony_ci*/
1083d8536b4Sopenharmony_ci#define LOS_ERRNO_CPUP_TSK_ID_INVALID        LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x05)
1093d8536b4Sopenharmony_ci
1103d8536b4Sopenharmony_ci/**
1113d8536b4Sopenharmony_ci* @ingroup los_cpup
1123d8536b4Sopenharmony_ci* Sum of cpup with all tasks. It means the value of cpup is a permillage.
1133d8536b4Sopenharmony_ci*/
1143d8536b4Sopenharmony_ci#define LOS_CPUP_PRECISION                   1000
1153d8536b4Sopenharmony_ci
1163d8536b4Sopenharmony_ci/**
1173d8536b4Sopenharmony_ci* @ingroup los_cpup
1183d8536b4Sopenharmony_ci* Multiple of current cpup precision change to percent.
1193d8536b4Sopenharmony_ci*/
1203d8536b4Sopenharmony_ci#define LOS_CPUP_PRECISION_MULT              (LOS_CPUP_PRECISION / 100)
1213d8536b4Sopenharmony_ci
1223d8536b4Sopenharmony_ci/**
1233d8536b4Sopenharmony_ci * @ingroup los_cpup
1243d8536b4Sopenharmony_ci * Number of historical running time records
1253d8536b4Sopenharmony_ci */
1263d8536b4Sopenharmony_ci#define OS_CPUP_HISTORY_RECORD_NUM   10
1273d8536b4Sopenharmony_ci
1283d8536b4Sopenharmony_ci/**
1293d8536b4Sopenharmony_ci * @ingroup los_cpup
1303d8536b4Sopenharmony_ci * Count the CPU usage structures of a task.
1313d8536b4Sopenharmony_ci */
1323d8536b4Sopenharmony_citypedef struct {
1333d8536b4Sopenharmony_ci    UINT32 cpupID;                                        /**< Task ID */
1343d8536b4Sopenharmony_ci    UINT16 status;                                        /**< Task status */
1353d8536b4Sopenharmony_ci    UINT64 allTime;                                       /**< Total running time */
1363d8536b4Sopenharmony_ci    UINT64 startTime;                                     /**< Time before a task is invoked */
1373d8536b4Sopenharmony_ci    UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM];       /**< Historical running time */
1383d8536b4Sopenharmony_ci} OsCpupCB;
1393d8536b4Sopenharmony_ci
1403d8536b4Sopenharmony_ciextern OsCpupCB    *g_cpup;
1413d8536b4Sopenharmony_ci
1423d8536b4Sopenharmony_ci#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
1433d8536b4Sopenharmony_citypedef struct {
1443d8536b4Sopenharmony_ci    UINT32 cpupID;                                        /**< Irq ID */
1453d8536b4Sopenharmony_ci    UINT16 status;                                        /**< Irq status */
1463d8536b4Sopenharmony_ci    UINT64 allTime;                                       /**< Total running time */
1473d8536b4Sopenharmony_ci    UINT64 startTime;                                     /**< Time before a task is invoked */
1483d8536b4Sopenharmony_ci    UINT64 timeMax;                                       /**< Irq samples count */
1493d8536b4Sopenharmony_ci    UINT64 count;                                         /**< Irq samples count */
1503d8536b4Sopenharmony_ci    UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM];       /**< Historical running time */
1513d8536b4Sopenharmony_ci} OsIrqCpupCB;
1523d8536b4Sopenharmony_ci#endif
1533d8536b4Sopenharmony_ci
1543d8536b4Sopenharmony_ci/**
1553d8536b4Sopenharmony_ci * @ingroup los_cpup
1563d8536b4Sopenharmony_ci * @brief Initialization cpup.
1573d8536b4Sopenharmony_ci *
1583d8536b4Sopenharmony_ci * @par Description:
1593d8536b4Sopenharmony_ci * This API is used to initialization cpup.
1603d8536b4Sopenharmony_ci * @attention
1613d8536b4Sopenharmony_ci * <ul>
1623d8536b4Sopenharmony_ci * <li>None.</li>
1633d8536b4Sopenharmony_ci * </ul>
1643d8536b4Sopenharmony_ci *
1653d8536b4Sopenharmony_ci * @param None.
1663d8536b4Sopenharmony_ci *
1673d8536b4Sopenharmony_ci * @retval UINT32   Initialization result.
1683d8536b4Sopenharmony_ci * @par Dependency:
1693d8536b4Sopenharmony_ci * <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
1703d8536b4Sopenharmony_ci * @see None.
1713d8536b4Sopenharmony_ci */
1723d8536b4Sopenharmony_ciextern UINT32 OsCpupInit(VOID);
1733d8536b4Sopenharmony_ci
1743d8536b4Sopenharmony_ciextern UINT32 OsCpupDaemonInit(VOID);
1753d8536b4Sopenharmony_ci/**
1763d8536b4Sopenharmony_ci * @ingroup los_cpup
1773d8536b4Sopenharmony_ci * @brief Start task to get cycles count in current task ending.
1783d8536b4Sopenharmony_ci *
1793d8536b4Sopenharmony_ci * @par Description:
1803d8536b4Sopenharmony_ci * This API is used to start task to get cycles count in current task ending.
1813d8536b4Sopenharmony_ci * @attention
1823d8536b4Sopenharmony_ci * <ul>
1833d8536b4Sopenharmony_ci * <li>None.</li>
1843d8536b4Sopenharmony_ci * </ul>
1853d8536b4Sopenharmony_ci *
1863d8536b4Sopenharmony_ci * @param None.
1873d8536b4Sopenharmony_ci *
1883d8536b4Sopenharmony_ci * @retval None.
1893d8536b4Sopenharmony_ci * @par Dependency:
1903d8536b4Sopenharmony_ci * <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
1913d8536b4Sopenharmony_ci * @see None.
1923d8536b4Sopenharmony_ci */
1933d8536b4Sopenharmony_ciextern VOID OsTskCycleEndStart(VOID);
1943d8536b4Sopenharmony_ci
1953d8536b4Sopenharmony_ci/**
1963d8536b4Sopenharmony_ci * @ingroup los_cpup
1973d8536b4Sopenharmony_ci * Count the CPU usage structures of all tasks.
1983d8536b4Sopenharmony_ci */
1993d8536b4Sopenharmony_citypedef struct tagCpupInfo {
2003d8536b4Sopenharmony_ci    UINT16 usStatus;            /**< save the cur task status     */
2013d8536b4Sopenharmony_ci    UINT32 uwUsage;             /**< Usage. The value range is [0,1000].   */
2023d8536b4Sopenharmony_ci} CPUP_INFO_S;
2033d8536b4Sopenharmony_ci
2043d8536b4Sopenharmony_ci/**
2053d8536b4Sopenharmony_ci * @ingroup los_monitor
2063d8536b4Sopenharmony_ci * Type of the CPU usage query.
2073d8536b4Sopenharmony_ci */
2083d8536b4Sopenharmony_citypedef enum {
2093d8536b4Sopenharmony_ci    SYS_CPU_USAGE = 0,   /* system cpu occupancy rate */
2103d8536b4Sopenharmony_ci    TASK_CPU_USAGE,      /* task cpu occupancy rate */
2113d8536b4Sopenharmony_ci} CPUP_TYPE_E;
2123d8536b4Sopenharmony_ci
2133d8536b4Sopenharmony_ci/**
2143d8536b4Sopenharmony_ci * @ingroup los_monitor
2153d8536b4Sopenharmony_ci * Mode of the CPU usage query.
2163d8536b4Sopenharmony_ci */
2173d8536b4Sopenharmony_citypedef enum {
2183d8536b4Sopenharmony_ci    CPUP_IN_10S = 0,     /* cpu occupancy rate in 10s */
2193d8536b4Sopenharmony_ci    CPUP_IN_1S,          /* cpu occupancy rate in 1s */
2203d8536b4Sopenharmony_ci    CPUP_LESS_THAN_1S,   /* cpu occupancy rate less than 1s, if the input mode is none of them, it will be this. */
2213d8536b4Sopenharmony_ci} CPUP_MODE_E;
2223d8536b4Sopenharmony_ci
2233d8536b4Sopenharmony_ci/**
2243d8536b4Sopenharmony_ci * @ingroup los_cpup
2253d8536b4Sopenharmony_ci * @brief Obtain the current CPU usage.
2263d8536b4Sopenharmony_ci *
2273d8536b4Sopenharmony_ci * @par Description:
2283d8536b4Sopenharmony_ci * This API is used to obtain the current CPU usage.
2293d8536b4Sopenharmony_ci * @attention
2303d8536b4Sopenharmony_ci * <ul>
2313d8536b4Sopenharmony_ci * <li>This API can be called only after the CPU usage is initialized. Otherwise, error codes will be returned.</li>
2323d8536b4Sopenharmony_ci * <li> The precision of the CPU usage can be adjusted by changing the value of the CPUP_PRECISION macro.</li>
2333d8536b4Sopenharmony_ci * </ul>
2343d8536b4Sopenharmony_ci *
2353d8536b4Sopenharmony_ci * @param None.
2363d8536b4Sopenharmony_ci *
2373d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_NO_INIT           0x02001e02: The CPU usage is not initialized.
2383d8536b4Sopenharmony_ci * @retval #cpup                            [0,1000], current CPU usage, of which the precision is adjustable.
2393d8536b4Sopenharmony_ci * @par Dependency:
2403d8536b4Sopenharmony_ci * <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
2413d8536b4Sopenharmony_ci * @see LOS_SysCpuUsage
2423d8536b4Sopenharmony_ci */
2433d8536b4Sopenharmony_ciextern UINT32 LOS_SysCpuUsage(VOID);
2443d8536b4Sopenharmony_ci
2453d8536b4Sopenharmony_ci/**
2463d8536b4Sopenharmony_ci * @ingroup los_cpup
2473d8536b4Sopenharmony_ci * @brief Obtain the historical CPU usage.
2483d8536b4Sopenharmony_ci *
2493d8536b4Sopenharmony_ci * @par Description:
2503d8536b4Sopenharmony_ci * This API is used to obtain the historical CPU usage.
2513d8536b4Sopenharmony_ci * @attention
2523d8536b4Sopenharmony_ci * <ul>
2533d8536b4Sopenharmony_ci * <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails
2543d8536b4Sopenharmony_ci * to be obtained.</li>
2553d8536b4Sopenharmony_ci * </ul>
2563d8536b4Sopenharmony_ci *
2573d8536b4Sopenharmony_ci * @param  mode     [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s will be
2583d8536b4Sopenharmony_ci * obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained. Other values
2593d8536b4Sopenharmony_ci * indicate that the CPU usage in the period that is less than 1s will be obtained.
2603d8536b4Sopenharmony_ci *
2613d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_NO_INIT           0x02001e02: The CPU usage is not initialized.
2623d8536b4Sopenharmony_ci * @retval #cpup                            [0,1000], historical CPU usage, of which the precision is adjustable.
2633d8536b4Sopenharmony_ci * @par Dependency:
2643d8536b4Sopenharmony_ci * <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
2653d8536b4Sopenharmony_ci * @see LOS_HistoryTaskCpuUsage
2663d8536b4Sopenharmony_ci */
2673d8536b4Sopenharmony_ciextern UINT32 LOS_HistorySysCpuUsage(UINT16 mode);
2683d8536b4Sopenharmony_ci
2693d8536b4Sopenharmony_ci/**
2703d8536b4Sopenharmony_ci * @ingroup los_cpup
2713d8536b4Sopenharmony_ci * @brief Obtain the CPU usage of a specified task.
2723d8536b4Sopenharmony_ci *
2733d8536b4Sopenharmony_ci * @par Description:
2743d8536b4Sopenharmony_ci * This API is used to obtain the CPU usage of a task specified by a passed-in task ID.
2753d8536b4Sopenharmony_ci * @attention
2763d8536b4Sopenharmony_ci * <ul>
2773d8536b4Sopenharmony_ci * <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails
2783d8536b4Sopenharmony_ci * to be obtained.</li>
2793d8536b4Sopenharmony_ci * <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
2803d8536b4Sopenharmony_ci * the CPU usage fails to be obtained.</li>
2813d8536b4Sopenharmony_ci * </ul>
2823d8536b4Sopenharmony_ci *
2833d8536b4Sopenharmony_ci * @param taskID   [IN] UINT32. Task ID.
2843d8536b4Sopenharmony_ci *
2853d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_NO_INIT             0x02001e02: The CPU usage is not initialized.
2863d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_TSK_ID_INVALID      0x02001e05: The target task ID is invalid.
2873d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED   0x02001e04: The target thread is not created.
2883d8536b4Sopenharmony_ci * @retval #cpup                              [0,1000], CPU usage of the specified task.
2893d8536b4Sopenharmony_ci * @par Dependency:
2903d8536b4Sopenharmony_ci * <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
2913d8536b4Sopenharmony_ci * @see LOS_HistoryTaskCpuUsage
2923d8536b4Sopenharmony_ci */
2933d8536b4Sopenharmony_ciextern UINT32 LOS_TaskCpuUsage(UINT32 taskID);
2943d8536b4Sopenharmony_ci
2953d8536b4Sopenharmony_ci/**
2963d8536b4Sopenharmony_ci * @ingroup los_cpup
2973d8536b4Sopenharmony_ci * @brief  Obtain the historical CPU usage of a specified task.
2983d8536b4Sopenharmony_ci *
2993d8536b4Sopenharmony_ci * @par Description:
3003d8536b4Sopenharmony_ci * This API is used to obtain the historical CPU usage of a task specified by a passed-in task ID.
3013d8536b4Sopenharmony_ci * @attention
3023d8536b4Sopenharmony_ci * <ul>
3033d8536b4Sopenharmony_ci * <li>This API can be called only after the CPU usage is initialized. Otherwise,
3043d8536b4Sopenharmony_ci * the CPU usage fails to be obtained.</li>
3053d8536b4Sopenharmony_ci * <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
3063d8536b4Sopenharmony_ci * the CPU usage fails to be obtained.</li>
3073d8536b4Sopenharmony_ci * </ul>
3083d8536b4Sopenharmony_ci *
3093d8536b4Sopenharmony_ci * @param taskID   [IN] UINT32. Task ID.
3103d8536b4Sopenharmony_ci * @param mode     [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
3113d8536b4Sopenharmony_ci * will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
3123d8536b4Sopenharmony_ci * Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
3133d8536b4Sopenharmony_ci *
3143d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_NO_INIT             0x02001e02: The CPU usage is not initialized.
3153d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_TSK_ID_INVALID      0x02001e05: The target task ID is invalid.
3163d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED   0x02001e04: The target thread is not created.
3173d8536b4Sopenharmony_ci * @retval #cpup                              [0,1000], CPU usage of the specified task.
3183d8536b4Sopenharmony_ci * @par Dependency:
3193d8536b4Sopenharmony_ci * <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
3203d8536b4Sopenharmony_ci * @see LOS_HistorySysCpuUsage
3213d8536b4Sopenharmony_ci */
3223d8536b4Sopenharmony_ciextern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode);
3233d8536b4Sopenharmony_ci
3243d8536b4Sopenharmony_ci/**
3253d8536b4Sopenharmony_ci * @ingroup los_cpup
3263d8536b4Sopenharmony_ci * @brief Obtain the CPU usage of all tasks.
3273d8536b4Sopenharmony_ci *
3283d8536b4Sopenharmony_ci * @par Description:
3293d8536b4Sopenharmony_ci * This API is used to obtain the CPU usage of all tasks according to maximum number of threads.
3303d8536b4Sopenharmony_ci * @attention
3313d8536b4Sopenharmony_ci * <ul>
3323d8536b4Sopenharmony_ci * <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails
3333d8536b4Sopenharmony_ci * to be obtained.</li>
3343d8536b4Sopenharmony_ci * <li>The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.</li>
3353d8536b4Sopenharmony_ci * </ul>
3363d8536b4Sopenharmony_ci *
3373d8536b4Sopenharmony_ci * @param cpupInfo    [OUT]Type.   CPUP_INFO_S* Pointer to the task CPUP information structure to be obtained.
3383d8536b4Sopenharmony_ci * @param mode        [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
3393d8536b4Sopenharmony_ci * will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
3403d8536b4Sopenharmony_ci * Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
3413d8536b4Sopenharmony_ci *
3423d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_NO_INIT           0x02001e02: The CPU usage is not initialized.
3433d8536b4Sopenharmony_ci * @retval #OS_ERRNO_CPUP_TASK_PTR_NULL     0x02001e01: The input parameter pointer is NULL.
3443d8536b4Sopenharmony_ci * @retval #LOS_OK                          0x00000000: The CPU usage of all tasks is successfully obtained.
3453d8536b4Sopenharmony_ci * @par Dependency:
3463d8536b4Sopenharmony_ci * <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
3473d8536b4Sopenharmony_ci * @see LOS_SysCpuUsage
3483d8536b4Sopenharmony_ci */
3493d8536b4Sopenharmony_ciextern UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode);
3503d8536b4Sopenharmony_ci
3513d8536b4Sopenharmony_ci/**
3523d8536b4Sopenharmony_ci * @ingroup los_monitor
3533d8536b4Sopenharmony_ci * @brief Obtain CPU usage history of certain task.
3543d8536b4Sopenharmony_ci *
3553d8536b4Sopenharmony_ci * @par Description:
3563d8536b4Sopenharmony_ci * This API is used to obtain CPU usage history of certain task.
3573d8536b4Sopenharmony_ci * @attention
3583d8536b4Sopenharmony_ci * <ul>
3593d8536b4Sopenharmony_ci * <li>This API can be called only after the CPU usage is initialized. Otherwise, -1 will be returned.</li>
3603d8536b4Sopenharmony_ci * <li> Only in SYS_CPU_USAGE type, uwTaskID is invalid.</li>
3613d8536b4Sopenharmony_ci * </ul>
3623d8536b4Sopenharmony_ci *
3633d8536b4Sopenharmony_ci * @param type        [IN] cpup type, SYS_CPU_USAGE and TASK_CPU_USAGE
3643d8536b4Sopenharmony_ci * @param mode        [IN] mode,CPUP_IN_10S = usage in 10s,CPUP_IN_1S = usage in last 1s,
3653d8536b4Sopenharmony_ci * CPUP_LESS_THAN_1S = less than 1s, if the input mode is none of them, it will be as CPUP_LESS_THAN_1S.
3663d8536b4Sopenharmony_ci * @param taskID      [IN] task ID, Only in SYS_CPU_USAGE type, taskID is invalid
3673d8536b4Sopenharmony_ci *
3683d8536b4Sopenharmony_ci * @retval #OS_ERROR           -1:CPU usage info obtain failed.
3693d8536b4Sopenharmony_ci * @retval #LOS_OK              0:CPU usage info is successfully obtained.
3703d8536b4Sopenharmony_ci * @par Dependency:
3713d8536b4Sopenharmony_ci * <ul><li>los_monitor.h: the header file that contains the API declaration.</li></ul>
3723d8536b4Sopenharmony_ci * @see LOS_CpupUsageMonitor
3733d8536b4Sopenharmony_ci */
3743d8536b4Sopenharmony_ciextern UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E mode, UINT32 taskID);
3753d8536b4Sopenharmony_ci
3763d8536b4Sopenharmony_ci#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
3773d8536b4Sopenharmony_ciextern VOID OsCpupIrqStart(UINT32 intNum);
3783d8536b4Sopenharmony_ciextern VOID OsCpupIrqEnd(UINT32 intNum);
3793d8536b4Sopenharmony_ciextern OsIrqCpupCB *OsGetIrqCpupArrayBase(VOID);
3803d8536b4Sopenharmony_ciextern UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cpupInfo);
3813d8536b4Sopenharmony_ci#endif
3823d8536b4Sopenharmony_ci
3833d8536b4Sopenharmony_ci#ifdef __cplusplus
3843d8536b4Sopenharmony_ci#if __cplusplus
3853d8536b4Sopenharmony_ci}
3863d8536b4Sopenharmony_ci#endif /* __cplusplus */
3873d8536b4Sopenharmony_ci#endif /* __cplusplus */
3883d8536b4Sopenharmony_ci
3893d8536b4Sopenharmony_ci#endif /* _LOS_CPUP_H */
390