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#ifndef _LOS_LMK_H 333d8536b4Sopenharmony_ci#define _LOS_LMK_H 343d8536b4Sopenharmony_ci 353d8536b4Sopenharmony_ci#include "los_config.h" 363d8536b4Sopenharmony_ci#include "los_compiler.h" 373d8536b4Sopenharmony_ci#include "los_list.h" 383d8536b4Sopenharmony_ci#include "los_error.h" 393d8536b4Sopenharmony_ci 403d8536b4Sopenharmony_citypedef UINT32 (*FreeMemByKillingTask)(VOID); 413d8536b4Sopenharmony_citypedef UINT32 (*RestoreKilledTask)(VOID); 423d8536b4Sopenharmony_ci 433d8536b4Sopenharmony_ci/** 443d8536b4Sopenharmony_ci * @ingroup los_lmk 453d8536b4Sopenharmony_ci * Lmk error code: Invalid parameter. 463d8536b4Sopenharmony_ci * 473d8536b4Sopenharmony_ci * Value: 0x02002101 483d8536b4Sopenharmony_ci * 493d8536b4Sopenharmony_ci */ 503d8536b4Sopenharmony_ci#define LOS_ERRNO_LMK_INVALID_PARAMETER LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x01) 513d8536b4Sopenharmony_ci 523d8536b4Sopenharmony_ci/** 533d8536b4Sopenharmony_ci * @ingroup los_lmk 543d8536b4Sopenharmony_ci * Lmk error code: LosLmkOpsNode already registered. 553d8536b4Sopenharmony_ci * 563d8536b4Sopenharmony_ci * Value: 0x02002102 573d8536b4Sopenharmony_ci * 583d8536b4Sopenharmony_ci */ 593d8536b4Sopenharmony_ci#define LOS_ERRNO_LMK_ALREADY_REGISTERED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x02) 603d8536b4Sopenharmony_ci 613d8536b4Sopenharmony_ci/** 623d8536b4Sopenharmony_ci * @ingroup los_lmk 633d8536b4Sopenharmony_ci * Lmk error code: LosLmkOpsNode not yet registered. 643d8536b4Sopenharmony_ci * 653d8536b4Sopenharmony_ci * Value: 0x02002103 663d8536b4Sopenharmony_ci * 673d8536b4Sopenharmony_ci */ 683d8536b4Sopenharmony_ci#define LOS_ERRNO_LMK_NOT_REGISTERED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x03) 693d8536b4Sopenharmony_ci 703d8536b4Sopenharmony_ci/** 713d8536b4Sopenharmony_ci * @ingroup los_lmk 723d8536b4Sopenharmony_ci * Lmk error code: Failed to free memory by invoking the registered functions. 733d8536b4Sopenharmony_ci * 743d8536b4Sopenharmony_ci * Value: 0x02002104 753d8536b4Sopenharmony_ci * 763d8536b4Sopenharmony_ci */ 773d8536b4Sopenharmony_ci#define LOS_ERRNO_LMK_FREE_MEMORY_FAILURE LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x04) 783d8536b4Sopenharmony_ci 793d8536b4Sopenharmony_ci/** 803d8536b4Sopenharmony_ci * @ingroup los_lmk 813d8536b4Sopenharmony_ci * Lmk error code: The registered free memory functions have been invoked. 823d8536b4Sopenharmony_ci * 833d8536b4Sopenharmony_ci * Value: 0x02002105 843d8536b4Sopenharmony_ci * 853d8536b4Sopenharmony_ci */ 863d8536b4Sopenharmony_ci#define LOS_ERRNO_LMK_MEMORY_ALREADY_FREED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x05) 873d8536b4Sopenharmony_ci 883d8536b4Sopenharmony_ci/** 893d8536b4Sopenharmony_ci * @ingroup los_lmk 903d8536b4Sopenharmony_ci * Lmk error code: Failed to restore the killed tasks by invoking the registered functions. 913d8536b4Sopenharmony_ci * 923d8536b4Sopenharmony_ci * Value: 0x02002106 933d8536b4Sopenharmony_ci * 943d8536b4Sopenharmony_ci */ 953d8536b4Sopenharmony_ci#define LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x06) 963d8536b4Sopenharmony_ci 973d8536b4Sopenharmony_ci/** 983d8536b4Sopenharmony_ci * @ingroup los_lmk 993d8536b4Sopenharmony_ci * Lmk error code: No need to restore when no free memory functions have been invoked. 1003d8536b4Sopenharmony_ci * 1013d8536b4Sopenharmony_ci * Value: 0x02002107 1023d8536b4Sopenharmony_ci * 1033d8536b4Sopenharmony_ci */ 1043d8536b4Sopenharmony_ci#define LOS_ERRNO_LMK_RESTORE_NOT_NEEDED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x07) 1053d8536b4Sopenharmony_ci 1063d8536b4Sopenharmony_citypedef struct { 1073d8536b4Sopenharmony_ci UINT32 priority; /**< The priority in the LMK list, the higher priority with a smaller number. */ 1083d8536b4Sopenharmony_ci UINT32 (*freeMem)(VOID); /**< Release the memory of tasks in the LMK list. Return LOS_OK for a successful release. */ 1093d8536b4Sopenharmony_ci UINT32 (*restoreTask)(VOID); /**< Restore the tasks killed by freeMem(). Return LOS_OK for a successful restore. */ 1103d8536b4Sopenharmony_ci LOS_DL_LIST node; /**< LosLmkOpsNode node. */ 1113d8536b4Sopenharmony_ci} LosLmkOpsNode; 1123d8536b4Sopenharmony_ci 1133d8536b4Sopenharmony_citypedef struct { 1143d8536b4Sopenharmony_ci LOS_DL_LIST lmkOpsList; /**< The registered LosLmkOpsNode will be inserted in this list. */ 1153d8536b4Sopenharmony_ci BOOL isMemFreed; /**< Flag that if LOS_LmkTasksKill has been invoked. */ 1163d8536b4Sopenharmony_ci} LosLmkOps; 1173d8536b4Sopenharmony_ci 1183d8536b4Sopenharmony_ci/** 1193d8536b4Sopenharmony_ci * @ingroup los_lmk 1203d8536b4Sopenharmony_ci * @brief Register a low memory killer node. 1213d8536b4Sopenharmony_ci * 1223d8536b4Sopenharmony_ci * @par Description: 1233d8536b4Sopenharmony_ci * This API is used to register a low memory killer node. A LosLmkOpsNode node 1243d8536b4Sopenharmony_ci * can be registered only once. 1253d8536b4Sopenharmony_ci * 1263d8536b4Sopenharmony_ci * @attention None. 1273d8536b4Sopenharmony_ci * 1283d8536b4Sopenharmony_ci * @param lmkNode [IN] The LosLmkOpsNode node to be registered. 1293d8536b4Sopenharmony_ci * 1303d8536b4Sopenharmony_ci * @retval LOS_OK The LosLmkOpsNode node is registered successfully. 1313d8536b4Sopenharmony_ci * @retval LOS_ERRNO_LMK_INVALID_PARAMETER The parameter is invalid. 1323d8536b4Sopenharmony_ci * @retval LOS_ERRNO_LMK_ALREADY_REGISTERED The LosLmkOpsNode node already registered. 1333d8536b4Sopenharmony_ci * @par Dependency: 1343d8536b4Sopenharmony_ci * <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul> 1353d8536b4Sopenharmony_ci * @see 1363d8536b4Sopenharmony_ci */ 1373d8536b4Sopenharmony_ciUINT32 LOS_LmkOpsNodeRegister(LosLmkOpsNode *lmkNode); 1383d8536b4Sopenharmony_ci 1393d8536b4Sopenharmony_ci/** 1403d8536b4Sopenharmony_ci * @ingroup los_lmk 1413d8536b4Sopenharmony_ci * @brief Unregister a low memory killer node. 1423d8536b4Sopenharmony_ci * 1433d8536b4Sopenharmony_ci * @par Description: 1443d8536b4Sopenharmony_ci * This API is used to unregister a low memory killer node. 1453d8536b4Sopenharmony_ci * 1463d8536b4Sopenharmony_ci * @attention None. 1473d8536b4Sopenharmony_ci * 1483d8536b4Sopenharmony_ci * @param lmkNode [IN] The LosLmkOpsNode node to be registered. 1493d8536b4Sopenharmony_ci * 1503d8536b4Sopenharmony_ci * @retval LOS_OK The LosLmkOpsNode node is unregistered successfully. 1513d8536b4Sopenharmony_ci * @retval LOS_ERRNO_LMK_NOT_REGISTERED The LosLmkOpsNode node is not yet registered. 1523d8536b4Sopenharmony_ci * @par Dependency: 1533d8536b4Sopenharmony_ci * <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul> 1543d8536b4Sopenharmony_ci * @see 1553d8536b4Sopenharmony_ci */ 1563d8536b4Sopenharmony_ciUINT32 LOS_LmkOpsNodeUnregister(LosLmkOpsNode *lmkNode); 1573d8536b4Sopenharmony_ci 1583d8536b4Sopenharmony_ci/** 1593d8536b4Sopenharmony_ci * @ingroup los_lmk 1603d8536b4Sopenharmony_ci * @brief Initialize low memory killer framework. 1613d8536b4Sopenharmony_ci * 1623d8536b4Sopenharmony_ci * @par Description: 1633d8536b4Sopenharmony_ci * This API is used to initialize the low memory killer framework. 1643d8536b4Sopenharmony_ci * 1653d8536b4Sopenharmony_ci * @attention None. 1663d8536b4Sopenharmony_ci * 1673d8536b4Sopenharmony_ci * @param None. 1683d8536b4Sopenharmony_ci * 1693d8536b4Sopenharmony_ci * @retval None. 1703d8536b4Sopenharmony_ci * @par Dependency: 1713d8536b4Sopenharmony_ci * <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul> 1723d8536b4Sopenharmony_ci * @see 1733d8536b4Sopenharmony_ci */ 1743d8536b4Sopenharmony_ciVOID OsLmkInit(VOID); 1753d8536b4Sopenharmony_ci 1763d8536b4Sopenharmony_ci/** 1773d8536b4Sopenharmony_ci * @ingroup los_lmk 1783d8536b4Sopenharmony_ci * @brief Restore the tasks killed by the task which triggers low memory killer. 1793d8536b4Sopenharmony_ci * 1803d8536b4Sopenharmony_ci * @par Description: 1813d8536b4Sopenharmony_ci * This API is used to restore the tasks killed by the task which triggers low memory killer. 1823d8536b4Sopenharmony_ci * This function will be invoked by the developer as needed. 1833d8536b4Sopenharmony_ci * 1843d8536b4Sopenharmony_ci * @attention None. 1853d8536b4Sopenharmony_ci * 1863d8536b4Sopenharmony_ci * @param None. 1873d8536b4Sopenharmony_ci * 1883d8536b4Sopenharmony_ci * @retval LOS_OK All the restore killed tasks functions are invoked successfully. 1893d8536b4Sopenharmony_ci * @retval LOS_ERRNO_LMK_RESTORE_NOT_NEEDED No need to restore since no tasks killed to free memory. 1903d8536b4Sopenharmony_ci * @retval LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE Failed to restore the killed tasks by invoking the registered functions. 1913d8536b4Sopenharmony_ci * @par Dependency: 1923d8536b4Sopenharmony_ci * <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul> 1933d8536b4Sopenharmony_ci * @see 1943d8536b4Sopenharmony_ci */ 1953d8536b4Sopenharmony_ciUINT32 LOS_LmkTasksRestore(VOID); 1963d8536b4Sopenharmony_ci 1973d8536b4Sopenharmony_ci/** 1983d8536b4Sopenharmony_ci * @ingroup los_lmk 1993d8536b4Sopenharmony_ci * @brief Kill the tasks to release the used memory. 2003d8536b4Sopenharmony_ci * 2013d8536b4Sopenharmony_ci * @par Description: 2023d8536b4Sopenharmony_ci * This API is used to kill the tasks to release the used memory when low memory killer is triggered. 2033d8536b4Sopenharmony_ci * 2043d8536b4Sopenharmony_ci * @attention None. 2053d8536b4Sopenharmony_ci * 2063d8536b4Sopenharmony_ci * @param None. 2073d8536b4Sopenharmony_ci * 2083d8536b4Sopenharmony_ci * @retval LOS_OK All the free memory functions are invoked successfully. 2093d8536b4Sopenharmony_ci * @retval LOS_ERRNO_LMK_MEMORY_ALREADY_FREED The registered free memory functions have been invoked. 2103d8536b4Sopenharmony_ci * @retval LOS_ERRNO_LMK_FREE_MEMORY_FAILURE Failed to free memory by invoking the registered functions. 2113d8536b4Sopenharmony_ci * @par Dependency: 2123d8536b4Sopenharmony_ci * <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul> 2133d8536b4Sopenharmony_ci * @see 2143d8536b4Sopenharmony_ci */ 2153d8536b4Sopenharmony_ciUINT32 LOS_LmkTasksKill(VOID); 2163d8536b4Sopenharmony_ci 2173d8536b4Sopenharmony_ci#if (LOSCFG_KERNEL_LMK_DEBUG == 1) 2183d8536b4Sopenharmony_ci/** 2193d8536b4Sopenharmony_ci * @ingroup los_lmk 2203d8536b4Sopenharmony_ci * @brief Output the low memory killer node priorities. 2213d8536b4Sopenharmony_ci * 2223d8536b4Sopenharmony_ci * @par Description: 2233d8536b4Sopenharmony_ci * This API is used to output the low memory killer node priorities. 2243d8536b4Sopenharmony_ci * 2253d8536b4Sopenharmony_ci * @attention None. 2263d8536b4Sopenharmony_ci * 2273d8536b4Sopenharmony_ci * @param None. 2283d8536b4Sopenharmony_ci * 2293d8536b4Sopenharmony_ci * @retval None. 2303d8536b4Sopenharmony_ci * @par Dependency: 2313d8536b4Sopenharmony_ci * <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul> 2323d8536b4Sopenharmony_ci * @see 2333d8536b4Sopenharmony_ci */ 2343d8536b4Sopenharmony_ciVOID LOS_LmkOpsNodeInfoShow(VOID); 2353d8536b4Sopenharmony_ci#endif 2363d8536b4Sopenharmony_ci#endif 237