commit
d4794ebc38
|
@ -34,7 +34,9 @@ module_name = get_path_info(rebase_path("."), "name")
|
|||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"os_adapt/fd_proc.c",
|
||||
"os_adapt/file_sys.c",
|
||||
"os_adapt/fs_cache_proc.c",
|
||||
"os_adapt/mem_info.c",
|
||||
"os_adapt/mounts_proc.c",
|
||||
"os_adapt/power_proc.c",
|
||||
"os_adapt/proc_init.c",
|
||||
|
|
|
@ -49,6 +49,10 @@ extern bool procfsInit;
|
|||
int ProcCreateProcessDir(UINT32 pid, uintptr_t process);
|
||||
|
||||
void ProcFreeProcessDir(struct ProcDirEntry *processDir);
|
||||
|
||||
void ProcSysMemInfoInit(void);
|
||||
|
||||
void ProcFileSysInit(void);
|
||||
#endif
|
||||
|
||||
void ProcPmInit(void);
|
||||
|
@ -63,15 +67,15 @@ struct ProcDirEntry *ProcFindEntry(const char *path);
|
|||
|
||||
void ProcFreeEntry(struct ProcDirEntry *pde);
|
||||
|
||||
extern int ProcStat(const char *file, struct ProcStat *buf);
|
||||
int ProcStat(const char *file, struct ProcStat *buf);
|
||||
|
||||
extern void ProcMountsInit(void);
|
||||
void ProcMountsInit(void);
|
||||
|
||||
extern void ProcUptimeInit(void);
|
||||
void ProcUptimeInit(void);
|
||||
|
||||
extern void ProcFsCacheInit(void);
|
||||
void ProcFsCacheInit(void);
|
||||
|
||||
extern void ProcFdInit(void);
|
||||
void ProcFdInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fs/fs.h"
|
||||
#include "proc_fs.h"
|
||||
#include "proc_file.h"
|
||||
#include "errno.h"
|
||||
#include "sys/mount.h"
|
||||
|
||||
extern struct fsmap_t g_fsmap[];
|
||||
extern struct fsmap_t g_fsmap_end;
|
||||
|
||||
static int FsFileSysProcRead(struct SeqBuf *seqBuf, void *buf)
|
||||
{
|
||||
(void)buf;
|
||||
|
||||
struct fsmap_t *m = NULL;
|
||||
for (m = &g_fsmap[0]; m != &g_fsmap_end; ++m) {
|
||||
if (m->fs_filesystemtype) {
|
||||
if (m->is_bdfs == true) {
|
||||
(void)LosBufPrintf(seqBuf, "\n %s\n", m->fs_filesystemtype);
|
||||
} else {
|
||||
(void)LosBufPrintf(seqBuf, "%s %s\n", "nodev", m->fs_filesystemtype);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations FILESYS_PROC_FOPS = {
|
||||
.read = FsFileSysProcRead,
|
||||
};
|
||||
|
||||
void ProcFileSysInit(void)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry("filesystems", 0, NULL);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("creat /proc/filesystems error!\n");
|
||||
return;
|
||||
}
|
||||
pde->procFileOps = &FILESYS_PROC_FOPS;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "proc_fs.h"
|
||||
#include "vnode.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_vm_filemap.h"
|
||||
#include "los_memory_pri.h"
|
||||
|
||||
static int SysMemInfoFill(struct SeqBuf *seqBuf, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
LOS_MEM_POOL_STATUS mem = {0};
|
||||
if (LOS_MemInfoGet(m_aucSysMem0, &mem) == LOS_NOK) {
|
||||
return -EBADF;
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "\nUsedSize:%25u KB\n", mem.totalUsedSize);
|
||||
(void)LosBufPrintf(seqBuf, "FreeSize:%25u KB\n", mem.totalFreeSize);
|
||||
(void)LosBufPrintf(seqBuf, "MaxFreeNodeSize:%18u KB\n", mem.maxFreeNodeSize);
|
||||
(void)LosBufPrintf(seqBuf, "UsedNodeNum:%22u KB\n", mem.usedNodeNum);
|
||||
(void)LosBufPrintf(seqBuf, "FreeNodeNum:%22u KB\n", mem.freeNodeNum);
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
(void)LosBufPrintf(seqBuf, "UsageWaterLine:%19u KB\n", mem.freeNodeNum);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations SYS_MEMINFO_PROC_FOPS = {
|
||||
.read = SysMemInfoFill,
|
||||
};
|
||||
|
||||
void ProcSysMemInfoInit(void)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry("meminfo", 0, NULL);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("create mem_info error!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pde->procFileOps = &SYS_MEMINFO_PROC_FOPS;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
|
@ -68,6 +68,10 @@ void ProcFsInit(void)
|
|||
#ifdef LOSCFG_KERNEL_PM
|
||||
ProcPmInit();
|
||||
#endif
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
ProcSysMemInfoInit();
|
||||
ProcFileSysInit();
|
||||
#endif
|
||||
}
|
||||
|
||||
LOS_MODULE_INIT(ProcFsInit, LOS_INIT_LEVEL_KMOD_EXTENDED);
|
||||
|
|
|
@ -36,8 +36,14 @@
|
|||
#include "los_process_pri.h"
|
||||
|
||||
#ifdef LOSCFG_PROC_PROCESS_DIR
|
||||
#include "los_vm_dump.h"
|
||||
|
||||
typedef enum {
|
||||
PROC_PID,
|
||||
PROC_PID_MEM,
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROC_PID_CPUP,
|
||||
#endif
|
||||
} ProcessDataType;
|
||||
|
||||
struct ProcProcess {
|
||||
|
@ -100,10 +106,86 @@ static const struct ProcFileOperations PID_CONTAINER_FOPS = {
|
|||
};
|
||||
#endif /* LOSCFG_KERNEL_CONTAINER */
|
||||
|
||||
static int ProcessMemInfoRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
|
||||
{
|
||||
unsigned int intSave;
|
||||
unsigned int size = sizeof(LosVmSpace) + sizeof(LosVmMapRegion);
|
||||
LosVmSpace *vmSpace = (LosVmSpace *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (vmSpace == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
(void)memset_s(vmSpace, size, 0, size);
|
||||
LosVmMapRegion *heap = (LosVmMapRegion *)((char *)vmSpace + sizeof(LosVmSpace));
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (OsProcessIsInactive(pcb)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(void)LOS_MemFree(m_aucSysMem1, vmSpace);
|
||||
return -EINVAL;
|
||||
}
|
||||
(void)memcpy_s(vmSpace, sizeof(LosVmSpace), pcb->vmSpace, sizeof(LosVmSpace));
|
||||
(void)memcpy_s(heap, sizeof(LosVmMapRegion), pcb->vmSpace->heap, sizeof(LosVmMapRegion));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "\nVMSpaceSize: %u KB\n", vmSpace->size);
|
||||
(void)LosBufPrintf(seqBuf, "VMRegionSize: %u KB\n", heap->range.size);
|
||||
(void)LosBufPrintf(seqBuf, "RegionFlags: %s\n", OsGetRegionNameOrFilePath(heap));
|
||||
(void)LosBufPrintf(seqBuf, "ShmidAboutSharedRegion: %u\n", heap->shmid);
|
||||
(void)LosBufPrintf(seqBuf, "VMSpaceRorkFlags: 0x%x\n", heap->forkFlags);
|
||||
(void)LosBufPrintf(seqBuf, "VMRegionRype: 0x%x\n", heap->regionType);
|
||||
(void)LosBufPrintf(seqBuf, "VMSpaceMappingAreaSize: %u KB\n", vmSpace->mapSize);
|
||||
(void)LosBufPrintf(seqBuf, "TLB Asid: %u\n", vmSpace->archMmu.asid);
|
||||
(void)LOS_MemFree(m_aucSysMem1, vmSpace);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
static int ProcessCpupRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
|
||||
{
|
||||
unsigned int intSave;
|
||||
OsCpupBase *processCpup = (OsCpupBase *)LOS_MemAlloc(m_aucSysMem1, sizeof(OsCpupBase));
|
||||
if (processCpup == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
(void)memset_s(processCpup, sizeof(OsCpupBase), 0, sizeof(OsCpupBase));
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (OsProcessIsInactive(pcb)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, processCpup);
|
||||
return -EINVAL;
|
||||
}
|
||||
(void)memcpy_s(processCpup, sizeof(OsCpupBase), pcb->processCpup, sizeof(OsCpupBase));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "\nTotalRunningTime: %lu\n", processCpup->allTime);
|
||||
(void)LosBufPrintf(seqBuf, "StartTime: %lu\n", processCpup->startTime);
|
||||
(void)LosBufPrintf(seqBuf, "HistoricalRunningTime: ");
|
||||
for (UINT32 i = 0; i < OS_CPUP_HISTORY_RECORD_NUM + 1; i++) {
|
||||
(void)LosBufPrintf(seqBuf, "%lu ", processCpup->historyTime[i]);
|
||||
}
|
||||
(void)LosBufPrintf(seqBuf, "\n");
|
||||
(void)LOS_MemFree(m_aucSysMem1, processCpup);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int ProcProcessRead(struct SeqBuf *m, void *v)
|
||||
{
|
||||
(void)m;
|
||||
(void)v;
|
||||
if ((m == NULL) || (v == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
struct ProcessData *data = (struct ProcessData *)v;
|
||||
switch (data->type) {
|
||||
case PROC_PID_MEM:
|
||||
return ProcessMemInfoRead(m, (LosProcessCB *)data->process);
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
case PROC_PID_CPUP:
|
||||
return ProcessCpupRead(m, (LosProcessCB *)data->process);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -119,6 +201,21 @@ static struct ProcProcess g_procProcess[] = {
|
|||
.fileOps = &PID_FOPS
|
||||
|
||||
},
|
||||
{
|
||||
.name = "meminfo",
|
||||
.mode = 0,
|
||||
.type = PROC_PID_MEM,
|
||||
.fileOps = &PID_FOPS
|
||||
},
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
{
|
||||
.name = "cpup",
|
||||
.mode = 0,
|
||||
.type = PROC_PID_CPUP,
|
||||
.fileOps = &PID_FOPS
|
||||
|
||||
},
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_CONTAINER
|
||||
{
|
||||
.name = "container",
|
||||
|
|
|
@ -80,6 +80,55 @@ HWTEST_F(ProcessFsTest, ItProcessFs001, TestSize.Level0)
|
|||
ItProcessFs001();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_002
|
||||
* @tc.desc: System memory information acquisition test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AMVG
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs002, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs002();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_003
|
||||
* @tc.desc: Get the file system type information supported by the system test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AMVG
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs003, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs003();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_004
|
||||
* @tc.desc: Process memory information acquisition test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AMVG
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs004, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs004();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_005
|
||||
* @tc.desc: Process cpup information acquisition test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6AMVG
|
||||
* @tc.author:
|
||||
*/
|
||||
|
||||
HWTEST_F(ProcessFsTest, ItProcessFs005, TestSize.Level0)
|
||||
{
|
||||
ItProcessFs005();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Process_fs_Test_007
|
||||
* @tc.desc: Process mount directory test
|
||||
|
|
Loading…
Reference in New Issue