feat: 添加cgroups测试用例
Close #I6H2AR Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: I31a432b69ea5fbad137aa1bb947fff4b6fc307df
This commit is contained in:
@@ -58,7 +58,6 @@ VOID *OsDevLimitAlloc(VOID)
|
||||
(VOID)memset_s(plimit, sizeof(ProcDevLimit), 0, sizeof(ProcDevLimit));
|
||||
LOS_ListInit(&(plimit->accessList));
|
||||
plimit->behavior = DEVLIMIT_DEFAULT_NONE;
|
||||
LOS_AtomicSet(&plimit->rc, 1);
|
||||
return (VOID *)plimit;
|
||||
}
|
||||
|
||||
@@ -79,11 +78,8 @@ VOID OsDevLimitFree(UINTPTR limit)
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&devLimit->rc);
|
||||
if (LOS_AtomicRead(&devLimit->rc) <= 0) {
|
||||
DevAccessListDelete(devLimit);
|
||||
LOS_KernelFree(devLimit);
|
||||
}
|
||||
DevAccessListDelete(devLimit);
|
||||
LOS_KernelFree(devLimit);
|
||||
}
|
||||
|
||||
STATIC UINT32 DevLimitCopyAccess(ProcDevLimit *devLimitDest, ProcDevLimit *devLimitSrc)
|
||||
@@ -110,16 +106,6 @@ VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src)
|
||||
devLimitDest->parent = (ProcDevLimit *)src;
|
||||
}
|
||||
|
||||
VOID OsDevLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process)
|
||||
{
|
||||
(VOID)currLimit;
|
||||
ProcDevLimit *parentDevLimit = (ProcDevLimit *)parentLimit;
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
if (pcb == NULL) {
|
||||
LOS_AtomicInc(&parentDevLimit->rc);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 IsSpace(INT32 c)
|
||||
{
|
||||
return (c == ' ' || (unsigned)c - '\t' < BUF_SEPARATOR);
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#define _LOS_DEVICELIMIT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_atomic.h"
|
||||
#include "los_list.h"
|
||||
#include "vfs_config.h"
|
||||
|
||||
@@ -74,7 +73,6 @@ typedef struct DevAccessItem {
|
||||
|
||||
typedef struct ProcDevLimit {
|
||||
struct ProcDevLimit *parent;
|
||||
Atomic rc;
|
||||
UINT8 allowFile;
|
||||
UINT8 denyFile;
|
||||
LOS_DL_LIST accessList; // device belong to devicelimite
|
||||
@@ -85,7 +83,6 @@ VOID OsDevLimitInit(UINTPTR limit);
|
||||
VOID *OsDevLimitAlloc(VOID);
|
||||
VOID OsDevLimitFree(UINTPTR limit);
|
||||
VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src);
|
||||
VOID OsDevLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process);
|
||||
UINT32 OsDevLimitWriteAllow(ProcLimitSet *plimit, const CHAR *buf, UINT32 size);
|
||||
UINT32 OsDevLimitWriteDeny(ProcLimitSet *plimit, const CHAR *buf, UINT32 size);
|
||||
UINT32 OsDevLimitShow(ProcDevLimit *devLimit, struct SeqBuf *seqBuf);
|
||||
|
||||
@@ -50,7 +50,6 @@ VOID *OsIPCLimitAlloc(VOID)
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(plimite, sizeof(ProcIPCLimit), 0, sizeof(ProcIPCLimit));
|
||||
LOS_AtomicSet(&plimite->rc, 1);
|
||||
return (VOID *)plimite;
|
||||
}
|
||||
|
||||
@@ -61,10 +60,7 @@ VOID OsIPCLimitFree(UINTPTR limite)
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&plimite->rc);
|
||||
if (LOS_AtomicRead(&plimite->rc) <= 0) {
|
||||
LOS_KernelFree((VOID *)plimite);
|
||||
}
|
||||
LOS_KernelFree((VOID *)plimite);
|
||||
}
|
||||
|
||||
VOID OsIPCLimitCopy(UINTPTR dest, UINTPTR src)
|
||||
@@ -101,7 +97,6 @@ VOID OsIPCLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process)
|
||||
parentIpcLimit->mqFailedCount += currIpcLimit->mqFailedCount;
|
||||
parentIpcLimit->shmSize += currIpcLimit->shmSize;
|
||||
parentIpcLimit->shmFailedCount += currIpcLimit->shmFailedCount;
|
||||
LOS_AtomicInc(&parentIpcLimit->rc);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#define _LOS_IPCLIMIT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -41,7 +40,6 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct ProcIPCLimit {
|
||||
Atomic rc;
|
||||
UINT32 mqCount;
|
||||
UINT32 mqFailedCount;
|
||||
UINT32 mqCountLimit;
|
||||
|
||||
@@ -57,7 +57,6 @@ VOID *OsMemLimiterAlloc(VOID)
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(plimite, sizeof(ProcMemLimiter), 0, sizeof(ProcMemLimiter));
|
||||
LOS_AtomicSet(&plimite->rc, 1);
|
||||
return (VOID *)plimite;
|
||||
}
|
||||
|
||||
@@ -68,10 +67,7 @@ VOID OsMemLimiterFree(UINTPTR limite)
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&plimite->rc);
|
||||
if (LOS_AtomicRead(&plimite->rc) <= 0) {
|
||||
LOS_KernelFree((VOID *)limite);
|
||||
}
|
||||
LOS_KernelFree((VOID *)limite);
|
||||
}
|
||||
|
||||
VOID OsMemLimiterCopy(UINTPTR dest, UINTPTR src)
|
||||
@@ -104,7 +100,6 @@ VOID OsMemLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process
|
||||
if (parentMemLimit->peak < parentMemLimit->usage) {
|
||||
parentMemLimit->peak = parentMemLimit->usage;
|
||||
}
|
||||
LOS_AtomicInc(&parentMemLimit->rc);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#define _LOS_MEMLIMIT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -41,7 +40,6 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct ProcMemLimiter {
|
||||
Atomic rc;
|
||||
UINT64 usage;
|
||||
UINT64 limit;
|
||||
UINT64 peak;
|
||||
|
||||
@@ -56,7 +56,7 @@ static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = {
|
||||
.LimiterAddProcess = OsPidLimitAddProcess,
|
||||
.LimiterDelProcess = OsPidLimitDelProcess,
|
||||
.LimiterMigrateCheck = PidLimitMigrateCheck,
|
||||
.LimiterMigrate = OsPidLimiterMigrate,
|
||||
.LimiterMigrate = NULL,
|
||||
},
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
[PROCESS_LIMITER_ID_MEM] = {
|
||||
@@ -81,7 +81,7 @@ static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = {
|
||||
.LimiterAddProcess = NULL,
|
||||
.LimiterDelProcess = NULL,
|
||||
.LimiterMigrateCheck = NULL,
|
||||
.LimiterMigrate = OsSchedLimitMigrate,
|
||||
.LimiterMigrate = NULL,
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
|
||||
@@ -94,7 +94,7 @@ static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = {
|
||||
.LimiterAddProcess = NULL,
|
||||
.LimiterDelProcess = NULL,
|
||||
.LimiterMigrateCheck = NULL,
|
||||
.LimiterMigrate = OsDevLimitMigrate,
|
||||
.LimiterMigrate = NULL,
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
|
||||
@@ -360,79 +360,6 @@ ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentPLimits)
|
||||
return newPLimits;
|
||||
}
|
||||
|
||||
UINT32 OsPLimitsAddLimiters(ProcLimiterSet *procLimiterSet, enum ProcLimiterID plimiteID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 mask = BIT(plimiteID);
|
||||
if ((procLimiterSet == NULL) || (plimiteID > PROCESS_LIMITER_COUNT)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (procLimiterSet->level == 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
if (procLimiterSet->mask & mask) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
UINTPTR currLimit = procLimiterSet->limitsList[plimiteID];
|
||||
UINTPTR parentPLimit = procLimiterSet->parent->limitsList[plimiteID];
|
||||
procLimiterSet->limitsList[plimiteID] = (UINTPTR)g_limiteOps[plimiteID].LimiterAlloc();
|
||||
if (procLimiterSet->limitsList[plimiteID] == (UINTPTR)NULL) {
|
||||
procLimiterSet->limitsList[plimiteID] = parentPLimit;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
g_limiteOps[plimiteID].LimiterCopy(procLimiterSet->limitsList[plimiteID], parentPLimit);
|
||||
g_limiteOps[plimiteID].LimiterMigrate(procLimiterSet->limitsList[plimiteID],
|
||||
parentPLimit, (UINTPTR)OsCurrProcessGet());
|
||||
g_limiteOps[plimiteID].LimiterFree(currLimit);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsPLimitsDeleteLimiters(ProcLimiterSet *procLimiterSet, enum ProcLimiterID plimiteID, UINT32 *mask)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if ((procLimiterSet == NULL) || (plimiteID > PROCESS_LIMITER_COUNT) || (mask == NULL)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (!(procLimiterSet->mask & BIT(plimiteID))) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (procLimiterSet->level == 0) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
UINTPTR currLimit = procLimiterSet->limitsList[plimiteID];
|
||||
UINTPTR parentPLimit = procLimiterSet->parent->limitsList[plimiteID];
|
||||
if ((g_limiteOps[plimiteID].LimiterMigrateCheck != NULL) &&
|
||||
!g_limiteOps[plimiteID].LimiterMigrateCheck(currLimit, parentPLimit)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
g_limiteOps[plimiteID].LimiterMigrate(currLimit, parentPLimit, 0);
|
||||
procLimiterSet->limitsList[plimiteID] = parentPLimit;
|
||||
g_limiteOps[plimiteID].LimiterFree(currLimit);
|
||||
|
||||
procLimiterSet->mask &= (~BIT(plimiteID));
|
||||
*mask = procLimiterSet->mask;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
|
||||
UINT32 OsPLimitsMemUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size)
|
||||
{
|
||||
|
||||
@@ -101,9 +101,6 @@ UINT32 OsPLimitsFree(ProcLimiterSet *currPLimits);
|
||||
ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentProcLimiterSet);
|
||||
UINT32 OsProcLimiterSetInit(VOID);
|
||||
|
||||
UINT32 OsPLimitsAddLimiters(ProcLimiterSet *procLimiterSet, enum ProcLimiterID plimiteID);
|
||||
UINT32 OsPLimitsDeleteLimiters(ProcLimiterSet *procLimiterSet, enum ProcLimiterID plimiteID, UINT32 *mask);
|
||||
|
||||
UINT32 OsPLimitsMemUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size);
|
||||
UINT32 OsPLimitsIPCStatGet(ProcLimiterSet *plimits, ProcIPCLimit *ipc, UINT32 size);
|
||||
UINT32 OsPLimitsSchedUsageGet(ProcLimiterSet *plimits, UINT64 *usage, UINT32 size);
|
||||
|
||||
@@ -57,7 +57,6 @@ VOID *PidLimiterAlloc(VOID)
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(plimite, sizeof(PidLimit), 0, sizeof(PidLimit));
|
||||
LOS_AtomicSet(&plimite->rc, 1);
|
||||
return (VOID *)plimite;
|
||||
}
|
||||
|
||||
@@ -68,10 +67,7 @@ VOID PidLimterFree(UINTPTR limit)
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&pidLimit->rc);
|
||||
if (LOS_AtomicRead(&pidLimit->rc) <= 0) {
|
||||
LOS_KernelFree((VOID *)limit);
|
||||
}
|
||||
LOS_KernelFree((VOID *)limit);
|
||||
}
|
||||
|
||||
BOOL PidLimitMigrateCheck(UINTPTR curr, UINTPTR parent)
|
||||
@@ -88,18 +84,6 @@ BOOL PidLimitMigrateCheck(UINTPTR curr, UINTPTR parent)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VOID OsPidLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process)
|
||||
{
|
||||
(VOID)currLimit;
|
||||
|
||||
PidLimit *parentPidLimit = (PidLimit *)parentLimit;
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
|
||||
if (pcb == NULL) {
|
||||
LOS_AtomicInc(&parentPidLimit->rc);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL OsPidLimitAddProcessCheck(UINTPTR limit, UINTPTR process)
|
||||
{
|
||||
(VOID)process;
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
|
||||
#include "los_list.h"
|
||||
#include "los_typedef.h"
|
||||
#include "los_atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -42,7 +41,6 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct PidLimit {
|
||||
Atomic rc;
|
||||
UINT32 pidLimit;
|
||||
UINT32 priorityLimit;
|
||||
UINT32 pidCount;
|
||||
@@ -53,7 +51,6 @@ VOID *PidLimiterAlloc(VOID);
|
||||
VOID PidLimterFree(UINTPTR limit);
|
||||
VOID PidLimiterCopy(UINTPTR curr, UINTPTR parent);
|
||||
BOOL PidLimitMigrateCheck(UINTPTR curr, UINTPTR parent);
|
||||
VOID OsPidLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process);
|
||||
BOOL OsPidLimitAddProcessCheck(UINTPTR limit, UINTPTR process);
|
||||
VOID OsPidLimitAddProcess(UINTPTR limit, UINTPTR process);
|
||||
VOID OsPidLimitDelProcess(UINTPTR limit, UINTPTR process);
|
||||
|
||||
@@ -49,7 +49,6 @@ VOID *OsSchedLimitAlloc(VOID)
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(plimit, sizeof(ProcSchedLimiter), 0, sizeof(ProcSchedLimiter));
|
||||
LOS_AtomicSet(&plimit->rc, 1);
|
||||
return (VOID *)plimit;
|
||||
}
|
||||
|
||||
@@ -60,10 +59,7 @@ VOID OsSchedLimitFree(UINTPTR limit)
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_AtomicDec(&schedLimit->rc);
|
||||
if (LOS_AtomicRead(&schedLimit->rc) <= 0) {
|
||||
LOS_KernelFree((VOID *)limit);
|
||||
}
|
||||
LOS_KernelFree((VOID *)limit);
|
||||
}
|
||||
|
||||
VOID OsSchedLimitCopy(UINTPTR dest, UINTPTR src)
|
||||
@@ -75,16 +71,6 @@ VOID OsSchedLimitCopy(UINTPTR dest, UINTPTR src)
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsSchedLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process)
|
||||
{
|
||||
(VOID)currLimit;
|
||||
ProcSchedLimiter *parentSchedLimit = (ProcSchedLimiter *)parentLimit;
|
||||
LosProcessCB *pcb = (LosProcessCB *)process;
|
||||
if (pcb == NULL) {
|
||||
LOS_AtomicInc(&parentSchedLimit->rc);
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsSchedLimitUpdateRuntime(LosTaskCB *runTask, UINT64 currTime, INT32 incTime)
|
||||
{
|
||||
LosProcessCB *run = (LosProcessCB *)runTask->processCB;
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#define _LOS_SCHEDLIMIT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -44,7 +43,6 @@ extern "C" {
|
||||
typedef struct TagTaskCB LosTaskCB;
|
||||
|
||||
typedef struct ProcSchedLimiter {
|
||||
Atomic rc;
|
||||
UINT64 startTime;
|
||||
UINT64 endTime;
|
||||
UINT64 period;
|
||||
@@ -58,7 +56,6 @@ VOID OsSchedLimitInit(UINTPTR limit);
|
||||
VOID *OsSchedLimitAlloc(VOID);
|
||||
VOID OsSchedLimitFree(UINTPTR limit);
|
||||
VOID OsSchedLimitCopy(UINTPTR dest, UINTPTR src);
|
||||
VOID OsSchedLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process);
|
||||
VOID OsSchedLimitUpdateRuntime(LosTaskCB *runTask, UINT64 currTime, INT32 incTime);
|
||||
UINT32 OsSchedLimitSetPeriod(ProcSchedLimiter *schedLimit, UINT64 value);
|
||||
UINT32 OsSchedLimitSetQuota(ProcSchedLimiter *schedLimit, UINT64 value);
|
||||
|
||||
Reference in New Issue
Block a user