1 /* 2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef _LOS_PLIMITS_H 32 #define _LOS_PLIMITS_H 33 34 #include "los_list.h" 35 #include "los_typedef.h" 36 #include "los_processlimit.h" 37 #include "los_memlimit.h" 38 #include "los_ipclimit.h" 39 #include "los_devicelimit.h" 40 #include "los_schedlimit.h" 41 42 #ifdef __cplusplus 43 #if __cplusplus 44 extern "C" { 45 #endif /* __cplusplus */ 46 #endif /* __cplusplus */ 47 48 /* proc limit set lock */ 49 #define PLIMITS_MIN_PERIOD_IN_US 1000000 50 #define PLIMITS_MIN_QUOTA_IN_US 1 51 #define PLIMITS_DELETE_WAIT_TIME 1000 52 typedef struct ProcessCB LosProcessCB; 53 54 enum ProcLimiterID { 55 PROCESS_LIMITER_ID_PIDS = 0, 56 #ifdef LOSCFG_KERNEL_MEM_PLIMIT 57 PROCESS_LIMITER_ID_MEM, 58 #endif 59 #ifdef LOSCFG_KERNEL_SCHED_PLIMIT 60 PROCESS_LIMITER_ID_SCHED, 61 #endif 62 #ifdef LOSCFG_KERNEL_DEV_PLIMIT 63 PROCESS_LIMITER_ID_DEV, 64 #endif 65 #ifdef LOSCFG_KERNEL_IPC_PLIMIT 66 PROCESS_LIMITER_ID_IPC, 67 #endif 68 PROCESS_LIMITER_COUNT, 69 }; 70 71 typedef struct { 72 #ifdef LOSCFG_KERNEL_MEM_PLIMIT 73 UINT64 memUsed; 74 #endif 75 #ifdef LOSCFG_KERNEL_IPC_PLIMIT 76 UINT32 mqCount; 77 UINT32 shmSize; 78 #endif 79 #ifdef LOSCFG_KERNEL_SCHED_PLIMIT 80 UINT64 allRuntime; 81 #endif 82 } PLimitsData; 83 84 typedef struct TagPLimiterSet { 85 struct TagPLimiterSet *parent; /* plimite parent */ 86 LOS_DL_LIST childList; /* plimite childList */ 87 LOS_DL_LIST processList; 88 UINT32 pidCount; 89 UINTPTR limitsList[PROCESS_LIMITER_COUNT]; /* plimite list */ 90 UINT32 mask; /* each bit indicates that a limite exists */ 91 UINT8 level; /* plimits hierarchy level */ 92 } ProcLimiterSet; 93 94 typedef struct ProcessCB LosProcessCB; 95 ProcLimiterSet *OsRootPLimitsGet(VOID); 96 UINT32 OsPLimitsAddProcess(ProcLimiterSet *plimits, LosProcessCB *processCB); 97 UINT32 OsPLimitsAddPid(ProcLimiterSet *plimits, UINT32 pid); 98 VOID OsPLimitsDeleteProcess(LosProcessCB *processCB); 99 UINT32 OsPLimitsPidsGet(const ProcLimiterSet *plimits, UINT32 *pids, UINT32 size); 100 UINT32 OsPLimitsFree(ProcLimiterSet *currPLimits); 101 ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentProcLimiterSet); 102 UINT32 OsProcLimiterSetInit(VOID); 103 104 UINT32 OsPLimitsMemUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size); 105 UINT32 OsPLimitsIPCStatGet(ProcLimiterSet *plimits, ProcIPCLimit *ipc, UINT32 size); 106 UINT32 OsPLimitsSchedUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size); 107 108 #ifdef __cplusplus 109 #if __cplusplus 110 } 111 #endif /* __cplusplus */ 112 #endif /* __cplusplus */ 113 114 #endif /* _LOS_PLIMITS_H */ 115