summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-06-03 11:17:31 (GMT)
committer Hanhui <sylixos@gmail.com>2019-04-18 15:53:15 (GMT)
commit41b399fa2e7b23a8f03a11b30555bfb99ee9ba52 (patch)
treebce0277f30cc2dd23cda9f582f0c31bd224cccdf
parent000d1d34254f2c4020edebd1d0d15b35d5972cf6 (diff)
downloadAIC-OS-41b399fa2e7b23a8f03a11b30555bfb99ee9ba52.zip
Add some process statistics information.
-rw-r--r--SylixOS/include/sys/vproc.h3
-rw-r--r--SylixOS/kernel/include/k_class.h4
-rw-r--r--SylixOS/kernel/include/k_kernel.h4
-rw-r--r--SylixOS/kernel/interface/ThreadDesc.c17
-rw-r--r--SylixOS/kernel/interface/ThreadGetCPUUsage.c12
-rw-r--r--SylixOS/kernel/show/CPUUsageShow.c17
-rw-r--r--SylixOS/kernel/show/ThreadShow.c30
-rw-r--r--SylixOS/loader/include/loader_vppatch.h8
-rw-r--r--SylixOS/loader/src/loader_proc.c69
-rw-r--r--SylixOS/loader/src/loader_shell.c143
-rw-r--r--SylixOS/loader/src/loader_vppatch.c26
-rw-r--r--SylixOS/loader/src/loader_vpstat.c193
-rw-r--r--SylixOS/posix/pthread/pthread.c3
-rw-r--r--libsylixos.mk1
14 files changed, 260 insertions, 270 deletions
diff --git a/SylixOS/include/sys/vproc.h b/SylixOS/include/sys/vproc.h
index 56ebf01..c824695 100644
--- a/SylixOS/include/sys/vproc.h
+++ b/SylixOS/include/sys/vproc.h
@@ -53,6 +53,9 @@ LW_API INT vprocDebugFlagsGet(pid_t pid, INT *piFlags);
LW_API INT vprocDebugFlagsSet(pid_t pid, INT piFlags);
#endif /* LW_CFG_GDB_EN > 0 */
+LW_API INT vprocListGet(pid_t pidTable[], UINT uiMaxCnt);
+LW_API INT vprocMemInfo(pid_t pid, size_t *pstStatic, size_t *pstHeap, size_t *pstMmap);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/SylixOS/kernel/include/k_class.h b/SylixOS/kernel/include/k_class.h
index 517f019..03c9966 100644
--- a/SylixOS/kernel/include/k_class.h
+++ b/SylixOS/kernel/include/k_class.h
@@ -807,11 +807,9 @@ typedef struct __lw_tcb_desc {
ULONG TCBD_ulThreadSafeCounter; /* 线程安全模式标志 */
UINT8 TCBD_ucStackAutoAllocFlag; /* 堆栈是否有系统在堆中开辟 */
-
CHAR TCBD_cThreadName[LW_CFG_OBJECT_NAME_SIZE]; /* 线程名 */
- PVOID TCBD_pvVProcessContext; /* 进程上下文 */
-
+ LONG TCBD_lPid; /* PID */
INT64 TCBD_i64PageFailCounter; /* 缺页中断次数 */
uid_t TCBD_uid; /* 用户 */
diff --git a/SylixOS/kernel/include/k_kernel.h b/SylixOS/kernel/include/k_kernel.h
index 0865ec8..7582a18 100644
--- a/SylixOS/kernel/include/k_kernel.h
+++ b/SylixOS/kernel/include/k_kernel.h
@@ -50,8 +50,8 @@
#define __SYLIXOS_MAJOR_VER 1
#define __SYLIXOS_MINOR_VER 9
-#define __SYLIXOS_PATCH_VER 9
-#define __SYLIXOS_PATCH_PAD 10
+#define __SYLIXOS_PATCH_VER 10
+#define __SYLIXOS_PATCH_PAD 0
/*********************************************************************************************************
版本格式
diff --git a/SylixOS/kernel/interface/ThreadDesc.c b/SylixOS/kernel/interface/ThreadDesc.c
index 8cf5a71..21fac4d 100644
--- a/SylixOS/kernel/interface/ThreadDesc.c
+++ b/SylixOS/kernel/interface/ThreadDesc.c
@@ -21,6 +21,12 @@
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
/*********************************************************************************************************
+ 进程相关
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_EN > 0
+#include "../SylixOS/loader/include/loader_vppatch.h"
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+/*********************************************************************************************************
** 函数名称: API_ThreadDesc
** 功能描述: 获得线程基本信息
** 输 入 : ulId 线程句柄
@@ -37,6 +43,10 @@ ULONG API_ThreadDesc (LW_OBJECT_HANDLE ulId, PLW_CLASS_TCB_DESC ptcbdesc)
REGISTER UINT16 usIndex;
REGISTER PLW_CLASS_TCB ptcb;
INT i;
+
+#if LW_CFG_MODULELOADER_EN > 0
+ LW_LD_VPROC *pvproc;
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
usIndex = _ObjectGetIndex(ulId);
@@ -144,7 +154,12 @@ ULONG API_ThreadDesc (LW_OBJECT_HANDLE ulId, PLW_CLASS_TCB_DESC ptcbdesc)
lib_strcpy(ptcbdesc->TCBD_cThreadName, ptcb->TCB_cThreadName);
- ptcbdesc->TCBD_pvVProcessContext = ptcb->TCB_pvVProcessContext;
+#if LW_CFG_MODULELOADER_EN > 0
+ pvproc = __LW_VP_GET_TCB_PROC(ptcb);
+ ptcbdesc->TCBD_lPid = (LONG)((pvproc) ? pvproc->VP_pid : 0);
+#else
+ ptcbdesc->TCBD_lPid = 0;
+#endif
ptcbdesc->TCBD_i64PageFailCounter = ptcb->TCB_i64PageFailCounter;
diff --git a/SylixOS/kernel/interface/ThreadGetCPUUsage.c b/SylixOS/kernel/interface/ThreadGetCPUUsage.c
index 0c696f9..4ea2516 100644
--- a/SylixOS/kernel/interface/ThreadGetCPUUsage.c
+++ b/SylixOS/kernel/interface/ThreadGetCPUUsage.c
@@ -215,9 +215,15 @@ INT API_ThreadGetCPUUsageAll (LW_OBJECT_HANDLE ulId[],
uiUsageKernel = (uiUsageKernel / 10); /* 四舍 */
}
- ulId[iIndex] = ptcb->TCB_ulId;
- uiThreadUsage[iIndex] = uiUsage;
- uiKernelUsage[iIndex] = uiUsageKernel;
+ if (ulId) {
+ ulId[iIndex] = ptcb->TCB_ulId;
+ }
+ if (uiThreadUsage) {
+ uiThreadUsage[iIndex] = uiUsage;
+ }
+ if (uiKernelUsage) {
+ uiKernelUsage[iIndex] = uiUsageKernel;
+ }
iIndex++;
if (iIndex >= iSize) {
diff --git a/SylixOS/kernel/show/CPUUsageShow.c b/SylixOS/kernel/show/CPUUsageShow.c
index f4cd803..05814be 100644
--- a/SylixOS/kernel/show/CPUUsageShow.c
+++ b/SylixOS/kernel/show/CPUUsageShow.c
@@ -36,12 +36,6 @@
#if LW_CFG_FIO_LIB_EN > 0 && LW_CFG_THREAD_CPU_USAGE_CHK_EN > 0
#include "../SylixOS/shell/include/ttiny_shell.h"
/*********************************************************************************************************
- 进程相关
-*********************************************************************************************************/
-#if LW_CFG_MODULELOADER_EN > 0
-#include "../SylixOS/loader/include/loader_vppatch.h"
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
-/*********************************************************************************************************
全局变量
*********************************************************************************************************/
static const CHAR _G_cCPUUsageInfoHdr[] = "\n\
@@ -80,7 +74,6 @@ VOID API_CPUUsageShow (INT iWaitSec, INT iTimes)
INT iOption;
LW_CLASS_TCB_DESC tcbdesc;
- pid_t pidGet;
if (LW_CPU_GET_CUR_NESTING()) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
@@ -136,16 +129,10 @@ VOID API_CPUUsageShow (INT iWaitSec, INT iTimes)
} else if (uiThreadUsage[i] > ulLitePercent) {
API_TShellColorStart2(LW_TSHELL_COLOR_GREEN, STD_OUT);
}
-
-#if LW_CFG_MODULELOADER_EN > 0
- pidGet = vprocGetPidByTcbdesc(&tcbdesc);
-#else
- pidGet = 0;
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
- printf("%-16s %7lx %5d %3d %3d.%d%% %3d.%d%%\n",
+ printf("%-16s %7lx %5ld %3d %3d.%d%% %3d.%d%%\n",
tcbdesc.TCBD_cThreadName, ulId[i],
- pidGet, tcbdesc.TCBD_ucPriority,
+ tcbdesc.TCBD_lPid, tcbdesc.TCBD_ucPriority,
uiThreadUsage[i] / 10, uiThreadUsage[i] % 10,
uiThreadKernel[i] / 10, uiThreadKernel[i] % 10);
diff --git a/SylixOS/kernel/show/ThreadShow.c b/SylixOS/kernel/show/ThreadShow.c
index 31a3c4a..d9143bf 100644
--- a/SylixOS/kernel/show/ThreadShow.c
+++ b/SylixOS/kernel/show/ThreadShow.c
@@ -84,7 +84,6 @@ VOID API_ThreadShowEx (pid_t pid)
PCHAR pcPendType = LW_NULL;
PCHAR pcFpu = LW_NULL;
- pid_t pidGet;
if (LW_CPU_GET_CUR_NESTING()) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
@@ -105,13 +104,7 @@ VOID API_ThreadShowEx (pid_t pid)
continue;
}
-#if LW_CFG_MODULELOADER_EN > 0
- pidGet = vprocGetPidByTcbdesc(&tcbdesc);
-#else
- pidGet = 0;
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
-
- if ((pidGet != pid) && (pid != -1)) {
+ if (((pid_t)tcbdesc.TCBD_lPid != pid) && (pid != -1)) {
continue;
}
@@ -164,10 +157,10 @@ VOID API_ThreadShowEx (pid_t pid)
pcFpu = "";
}
- printf("%-16s %7lx %5d %3d %-4s %4ld %-4s %10s %9llu %-3s %3ld\n",
+ printf("%-16s %7lx %5ld %3d %-4s %4ld %-4s %10s %9llu %-3s %3ld\n",
tcbdesc.TCBD_cThreadName, /* 线程名 */
tcbdesc.TCBD_ulId, /* ID 号 */
- pidGet, /* 所属进程 ID */
+ tcbdesc.TCBD_lPid, /* 所属进程 ID */
tcbdesc.TCBD_ucPriority, /* 优先级 */
pcPendType, /* 状态 */
tcbdesc.TCBD_ulThreadLockCounter, /* 线程锁 */
@@ -210,7 +203,6 @@ VOID API_ThreadPendShowEx (pid_t pid)
/* (LW_CFG_MAX_EVENTSETS > 0) */
CHAR cWakeupLeft[11];
PCHAR pcPendType = LW_NULL;
- pid_t pidGet;
CHAR cEventName[LW_CFG_OBJECT_NAME_SIZE + 2];
LW_OBJECT_HANDLE ulEvent;
LW_OBJECT_HANDLE ulOwner;
@@ -321,13 +313,7 @@ VOID API_ThreadPendShowEx (pid_t pid)
continue;
}
-#if LW_CFG_MODULELOADER_EN > 0
- pidGet = vprocGetPidByTcbdesc(&tcbdesc);
-#else
- pidGet = 0;
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
-
- if ((pidGet != pid) && (pid != -1)) {
+ if (((pid_t)tcbdesc.TCBD_lPid != pid) && (pid != -1)) {
continue;
}
@@ -375,20 +361,20 @@ VOID API_ThreadPendShowEx (pid_t pid)
}
if (ulOwner) {
- printf("%-16s %7lx %5d %-4s %10s %8lx:%-14s %7lx\n",
+ printf("%-16s %7lx %5ld %-4s %10s %8lx:%-14s %7lx\n",
tcbdesc.TCBD_cThreadName, /* 线程名 */
tcbdesc.TCBD_ulId, /* ID 号 */
- pidGet, /* 所属进程 ID */
+ tcbdesc.TCBD_lPid, /* 所属进程 ID */
pcPendType, /* 状态 */
cWakeupLeft, /* 等待计数器 */
ulEvent,
cEventName,
ulOwner);
} else {
- printf("%-16s %7lx %5d %-4s %10s %8lx:%-14s\n",
+ printf("%-16s %7lx %5ld %-4s %10s %8lx:%-14s\n",
tcbdesc.TCBD_cThreadName, /* 线程名 */
tcbdesc.TCBD_ulId, /* ID 号 */
- pidGet, /* 所属进程 ID */
+ tcbdesc.TCBD_lPid, /* 所属进程 ID */
pcPendType, /* 状态 */
cWakeupLeft, /* 等待计数器 */
ulEvent,
diff --git a/SylixOS/loader/include/loader_vppatch.h b/SylixOS/loader/include/loader_vppatch.h
index c7b2aff..a5d57e2 100644
--- a/SylixOS/loader/include/loader_vppatch.h
+++ b/SylixOS/loader/include/loader_vppatch.h
@@ -163,7 +163,6 @@ LW_LD_VPROC *vprocGetCur(VOID);
VOID vprocSetCur(LW_LD_VPROC *pvproc);
pid_t vprocGetPidByTcb(PLW_CLASS_TCB ptcb);
pid_t vprocGetPidByTcbNoLock(PLW_CLASS_TCB ptcb);
-pid_t vprocGetPidByTcbdesc(PLW_CLASS_TCB_DESC ptcbdesc);
pid_t vprocGetPidByThread(LW_OBJECT_HANDLE ulId);
VOID vprocKillPrepare(pid_t pid, LW_OBJECT_HANDLE ulId);
LW_OBJECT_HANDLE vprocMainThread(pid_t pid);
@@ -195,6 +194,13 @@ ssize_t vprocGetModsSvr4Info(pid_t pid, PCHAR pcBuff, size_t stMax
#endif /* LW_CFG_GDB_EN > 0 */
/*********************************************************************************************************
+ 进程内存信息
+*********************************************************************************************************/
+
+INT vprocMemInfoNoLock(LW_LD_VPROC *pvproc,
+ size_t *pstStatic, size_t *pstHeap, size_t *pstMmap);
+
+/*********************************************************************************************************
进程内部线程操作
*********************************************************************************************************/
diff --git a/SylixOS/loader/src/loader_proc.c b/SylixOS/loader/src/loader_proc.c
index 2e26c3d..616869c 100644
--- a/SylixOS/loader/src/loader_proc.c
+++ b/SylixOS/loader/src/loader_proc.c
@@ -31,7 +31,6 @@
*********************************************************************************************************/
#if (LW_CFG_MODULELOADER_EN > 0) && (LW_CFG_PROCFS_EN > 0)
#include "../include/loader_lib.h"
-#include "../include/loader_symbol.h"
/*********************************************************************************************************
对应文件信息
*********************************************************************************************************/
@@ -188,21 +187,9 @@ static ssize_t __procFsProcMemRead (PLW_PROCFS_NODE p_pfsn,
stRealSize = API_ProcFsNodeGetRealFileSize(p_pfsn);
if (stRealSize == 0) { /* 需要生成文件 */
- INT i, iNum;
- ULONG ulPages;
- size_t stTotalMem;
- size_t stMmapSize = 0;
size_t stStatic;
- BOOL bStart;
-
- LW_LIST_RING *pringTemp;
- LW_LD_EXEC_MODULE *pmodTemp;
-
-#if LW_CFG_VMM_EN == 0
- PLW_CLASS_HEAP pheapVpPatch;
-#endif /* LW_CFG_VMM_EN == 0 */
-
- PVOID pvVmem[LW_LD_VMEM_MAX];
+ size_t stHeapMem;
+ size_t stMmap;
LW_LD_LOCK();
pvproc = (LW_LD_VPROC *)p_pfsn->PFSN_pvValue;
@@ -211,53 +198,7 @@ static ssize_t __procFsProcMemRead (PLW_PROCFS_NODE p_pfsn,
return (PX_ERROR);
}
- LW_VP_LOCK(pvproc);
- stTotalMem = 0;
- for (pringTemp = pvproc->VP_ringModules, bStart = LW_TRUE;
- pringTemp && (pringTemp != pvproc->VP_ringModules || bStart);
- pringTemp = _list_ring_get_next(pringTemp), bStart = LW_FALSE) {
-
- pmodTemp = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
-
-#if LW_CFG_VMM_EN > 0
- ulPages = 0;
- if (API_VmmPCountInArea(pmodTemp->EMOD_pvBaseAddr, &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
- }
-#else
- stTotalMem += pmodTemp->EMOD_stLen;
-#endif /* LW_CFG_VMM_EN > 0 */
- stTotalMem += __moduleSymbolBufferSize(pmodTemp);
- }
- stStatic = stTotalMem;
-
- if (stTotalMem) { /* 至少存在一个模块 */
- pmodTemp = _LIST_ENTRY(pvproc->VP_ringModules, LW_LD_EXEC_MODULE, EMOD_ringModules);
- ulPages = 0;
-
-#if LW_CFG_VMM_EN > 0
- iNum = __moduleVpPatchVmem(pmodTemp, pvVmem, LW_LD_VMEM_MAX);
- if (iNum > 0) {
- for (i = 0; i < iNum; i++) {
- if (API_VmmPCountInArea(pvVmem[i],
- &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages
- << LW_CFG_VMM_PAGE_SHIFT);
- }
- }
- }
-#else
- pheapVpPatch = (PLW_CLASS_HEAP)__moduleVpPatchHeap(pmodTemp);
- if (pheapVpPatch) { /* 获得 vp 进程私有 heap */
- stTotalMem += (size_t)(pheapVpPatch->HEAP_stTotalByteSize);
- }
-#endif /* LW_CFG_VMM_EN > 0 */
- }
- LW_VP_UNLOCK(pvproc);
-
-#if LW_CFG_VMM_EN > 0
- API_VmmMmapPCount(pvproc->VP_pid, &stMmapSize); /* 计算 mmap 内存实际消耗量 */
-#endif /* LW_CFG_VMM_EN > 0 */
+ vprocMemInfoNoLock(pvproc, &stStatic, &stHeapMem, &stMmap);
LW_LD_UNLOCK();
stRealSize = bnprintf(pcFileBuffer,
@@ -266,8 +207,8 @@ static ssize_t __procFsProcMemRead (PLW_PROCFS_NODE p_pfsn,
"heap memory : %zu Bytes\n"
"mmap memory : %zu Bytes\n"
"total memory : %zu Bytes",
- stStatic, (stTotalMem - stStatic),
- stMmapSize, (stTotalMem + stMmapSize));
+ stStatic, stHeapMem, stMmap,
+ stStatic + stHeapMem + stMmap);
API_ProcFsNodeSetRealFileSize(p_pfsn, stRealSize);
}
diff --git a/SylixOS/loader/src/loader_shell.c b/SylixOS/loader/src/loader_shell.c
index 773e52d..2f5400b 100644
--- a/SylixOS/loader/src/loader_shell.c
+++ b/SylixOS/loader/src/loader_shell.c
@@ -62,7 +62,6 @@
#if LW_CFG_MODULELOADER_EN > 0
#include "pwd.h"
#include "../include/loader_lib.h"
-#include "../include/loader_symbol.h"
/*********************************************************************************************************
进程列表
*********************************************************************************************************/
@@ -720,17 +719,12 @@ static INT __tshellModuleShow (INT iArgC, PCHAR *ppcArgV)
LW_LD_VPROC *pvproc;
LW_LD_EXEC_MODULE *pmodTemp;
-#if LW_CFG_VMM_EN == 0
- PLW_CLASS_HEAP pheapVpPatch;
-#endif /* LW_CFG_VMM_EN == 0 */
-
+ size_t stStatic;
+ size_t stHeapMem;
+ size_t stMmapMem;
+
CHAR cVpVersion[128] = "";
- INT i, iNum;
- ULONG ulPages;
- size_t stTotalMem;
- PVOID pvVmem[LW_LD_VMEM_MAX];
-
if (iArgC < 2) {
pcFileName = LW_NULL;
} else {
@@ -753,66 +747,12 @@ static INT __tshellModuleShow (INT iArgC, PCHAR *ppcArgV)
}
}
- /*
- * 计算 vp 进程总内存消耗.
- */
- LW_VP_LOCK(pvproc);
- stTotalMem = 0;
- for (pringTemp = pvproc->VP_ringModules, bStart = LW_TRUE;
- pringTemp && (pringTemp != pvproc->VP_ringModules || bStart);
- pringTemp = _list_ring_get_next(pringTemp), bStart = LW_FALSE) {
-
- pmodTemp = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
-
-#if LW_CFG_VMM_EN > 0
- ulPages = 0;
- if (API_VmmPCountInArea(pmodTemp->EMOD_pvBaseAddr, &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
- }
-#else
- stTotalMem += pmodTemp->EMOD_stLen;
-#endif /* LW_CFG_VMM_EN > 0 */
- stTotalMem += __moduleSymbolBufferSize(pmodTemp);
- }
-
- if (stTotalMem) { /* 至少存在一个模块 */
- pmodTemp = _LIST_ENTRY(pvproc->VP_ringModules, LW_LD_EXEC_MODULE, EMOD_ringModules);
- ulPages = 0;
-
-#if LW_CFG_VMM_EN > 0
- iNum = __moduleVpPatchVmem(pmodTemp, pvVmem, LW_LD_VMEM_MAX);
- if (iNum > 0) {
- for (i = 0; i < iNum; i++) {
- if (API_VmmPCountInArea(pvVmem[i],
- &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages
- << LW_CFG_VMM_PAGE_SHIFT);
- }
- }
- lib_strlcpy(cVpVersion, __moduleVpPatchVersion(pmodTemp), sizeof(cVpVersion));
- }
-#else
- pheapVpPatch = (PLW_CLASS_HEAP)__moduleVpPatchHeap(pmodTemp);
- if (pheapVpPatch) { /* 获得 vp 进程私有 heap */
- stTotalMem += (size_t)(pheapVpPatch->HEAP_stTotalByteSize);
- lib_strlcpy(cVpVersion, __moduleVpPatchVersion(pmodTemp), sizeof(cVpVersion));
- }
-#endif /* LW_CFG_VMM_EN > 0 */
- }
- LW_VP_UNLOCK(pvproc);
-
-#if LW_CFG_VMM_EN > 0
- {
- size_t stMmapSize = 0;
- API_VmmMmapPCount(pvproc->VP_pid, &stMmapSize); /* 计算 mmap 内存实际消耗量 */
- stTotalMem += stMmapSize;
- }
-#endif /* LW_CFG_VMM_EN > 0 */
+ vprocMemInfoNoLock(pvproc, &stStatic, &stHeapMem, &stMmapMem);
printf("VPROC: %-18s pid:%4d TOTAL MEM: %zu ",
pcProcessName,
pvproc->VP_pid,
- stTotalMem);
+ stStatic + stHeapMem + stMmapMem);
if (cVpVersion[0] != PX_EOS) {
printf("<vp ver:%s>\n", cVpVersion);
@@ -870,23 +810,14 @@ static INT __tshellVProcShow (INT iArgC, PCHAR *ppcArgV)
INT iCnt = 0;
PCHAR pcProcessName;
PCHAR pcFatherName;
- BOOL bStart;
-
CHAR cVprocStat; /* 进程状态 */
LW_LIST_LINE *plineTemp;
- LW_LIST_RING *pringTemp;
LW_LD_VPROC *pvproc;
- LW_LD_EXEC_MODULE *pmodTemp;
-
-#if LW_CFG_VMM_EN == 0
- PLW_CLASS_HEAP pheapVpPatch;
-#endif /* LW_CFG_VMM_EN == 0 */
- INT i, iNum;
- ULONG ulPages;
- size_t stTotalMem;
- PVOID pvVmem[LW_LD_VMEM_MAX];
+ size_t stStatic;
+ size_t stHeapMem;
+ size_t stMmapMem;
struct passwd passwd;
struct passwd *ppasswd = LW_NULL;
@@ -939,60 +870,8 @@ static INT __tshellVProcShow (INT iArgC, PCHAR *ppcArgV)
cVprocStat = 'R';
}
}
-
- /*
- * 计算 vp 进程总内存消耗.
- */
- LW_VP_LOCK(pvproc);
- stTotalMem = 0;
- for (pringTemp = pvproc->VP_ringModules, bStart = LW_TRUE;
- pringTemp && (pringTemp != pvproc->VP_ringModules || bStart);
- pringTemp = _list_ring_get_next(pringTemp), bStart = LW_FALSE) {
-
- pmodTemp = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
-
-#if LW_CFG_VMM_EN > 0
- ulPages = 0;
- if (API_VmmPCountInArea(pmodTemp->EMOD_pvBaseAddr, &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
- }
-#else
- stTotalMem += pmodTemp->EMOD_stLen;
-#endif /* LW_CFG_VMM_EN > 0 */
- stTotalMem += __moduleSymbolBufferSize(pmodTemp);
- }
-
- if (stTotalMem) { /* 至少存在一个模块 */
- pmodTemp = _LIST_ENTRY(pvproc->VP_ringModules, LW_LD_EXEC_MODULE, EMOD_ringModules);
- ulPages = 0;
-
-#if LW_CFG_VMM_EN > 0
- iNum = __moduleVpPatchVmem(pmodTemp, pvVmem, LW_LD_VMEM_MAX);
- if (iNum > 0) {
- for (i = 0; i < iNum; i++) {
- if (API_VmmPCountInArea(pvVmem[i],
- &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages
- << LW_CFG_VMM_PAGE_SHIFT);
- }
- }
- }
-#else
- pheapVpPatch = (PLW_CLASS_HEAP)__moduleVpPatchHeap(pmodTemp);
- if (pheapVpPatch) { /* 获得 vp 进程私有 heap */
- stTotalMem += (size_t)(pheapVpPatch->HEAP_stTotalByteSize);
- }
-#endif /* LW_CFG_VMM_EN > 0 */
- }
- LW_VP_UNLOCK(pvproc);
-#if LW_CFG_VMM_EN > 0
- {
- size_t stMmapSize = 0;
- API_VmmMmapPCount(pvproc->VP_pid, &stMmapSize); /* 计算 mmap 内存实际消耗量 */
- stTotalMem += stMmapSize;
- }
-#endif /* LW_CFG_VMM_EN > 0 */
+ vprocMemInfoNoLock(pvproc, &stStatic, &stHeapMem, &stMmapMem);
uid = 0;
gid = 0;
@@ -1009,7 +888,7 @@ static INT __tshellVProcShow (INT iArgC, PCHAR *ppcArgV)
printf("%-16s %-16s %-4c %5d %5d %8zuKB %5d %5d %s\n",
pcProcessName, pcFatherName, cVprocStat, pvproc->VP_pid, pvproc->VP_pidGroup,
- stTotalMem / LW_CFG_KB_SIZE, uid, gid, pcUser);
+ (stStatic + stHeapMem + stMmapMem) / LW_CFG_KB_SIZE, uid, gid, pcUser);
iCnt++;
}
diff --git a/SylixOS/loader/src/loader_vppatch.c b/SylixOS/loader/src/loader_vppatch.c
index 950e55a..4bb300b 100644
--- a/SylixOS/loader/src/loader_vppatch.c
+++ b/SylixOS/loader/src/loader_vppatch.c
@@ -82,7 +82,7 @@
LW_LIST_LINE_HEADER _G_plineVProcHeader = LW_NULL;
LW_OBJECT_HANDLE _G_ulVProcMutex = LW_OBJECT_HANDLE_INVALID;
/*********************************************************************************************************
- 内核进程控制卡
+ 进程控制块
*********************************************************************************************************/
LW_LD_VPROC _G_vprocKernel;
LW_LD_VPROC *_G_pvprocTable[LW_CFG_MAX_THREADS];
@@ -698,30 +698,6 @@ pid_t vprocGetPidByTcbNoLock (PLW_CLASS_TCB ptcb)
return (pid);
}
/*********************************************************************************************************
-** 函数名称: vprocGetPidByTcbdesc
-** 功能描述: 通过 tcbdesc 获得进程 id
-** 输 入 : ptcbdesc 任务信息描述
-** 输 出 : 进程 pid
-** 全局变量:
-** 调用模块:
-*********************************************************************************************************/
-pid_t vprocGetPidByTcbdesc (PLW_CLASS_TCB_DESC ptcbdesc)
-{
- pid_t pid = 0;
- LW_LD_VPROC *pvproc;
-
- if (ptcbdesc) {
- LW_LD_LOCK();
- pvproc = (LW_LD_VPROC *)ptcbdesc->TCBD_pvVProcessContext;
- if (pvproc) {
- pid = pvproc->VP_pid;
- }
- LW_LD_UNLOCK();
- }
-
- return (pid);
-}
-/*********************************************************************************************************
** 函数名称: vprocGetPidByThread
** 功能描述: 通过线程 ID 获得进程 id
** 输 入 : ulId 线程 ID
diff --git a/SylixOS/loader/src/loader_vpstat.c b/SylixOS/loader/src/loader_vpstat.c
new file mode 100644
index 0000000..0d05136
--- /dev/null
+++ b/SylixOS/loader/src/loader_vpstat.c
@@ -0,0 +1,193 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: loader_vpstat.c
+**
+** 创 建 人: Han.hui (韩辉)
+**
+** 文件创建日期: 2019 年 06 月 03 日
+**
+** 描 述: 进程数据统计.
+*********************************************************************************************************/
+#define __SYLIXOS_KERNEL
+#include "SylixOS.h"
+/*********************************************************************************************************
+ 裁剪支持
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_EN > 0
+#include "../include/loader_lib.h"
+#include "../include/loader_symbol.h"
+/*********************************************************************************************************
+ 进程控制块
+*********************************************************************************************************/
+extern LW_LD_VPROC *_G_pvprocTable[LW_CFG_MAX_THREADS];
+/*********************************************************************************************************
+** 函数名称: vprocMemInfo
+** 功能描述: 获得进程内存使用情况
+** 输 入 : pid 进程号
+** pstStatic 静态内存大小
+** pstHeap 内存堆消耗
+** pstMmap mmap 大小
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT vprocMemInfoNoLock (LW_LD_VPROC *pvproc, size_t *pstStatic, size_t *pstHeap, size_t *pstMmap)
+{
+ size_t stStatic = 0;
+ size_t stHeap = 0;
+ size_t stMmap = 0;
+
+ INT i, iNum;
+ ULONG ulPages;
+ BOOL bStart;
+ LW_LIST_RING *pringTemp;
+ LW_LD_EXEC_MODULE *pmodTemp;
+ PVOID pvVmem[LW_LD_VMEM_MAX];
+
+#if LW_CFG_VMM_EN == 0
+ PLW_CLASS_HEAP pheapVpPatch;
+#endif /* LW_CFG_VMM_EN == 0 */
+
+ if (!pvproc) {
+ _ErrorHandle(ESRCH);
+ return (PX_ERROR);
+ }
+
+ LW_VP_LOCK(pvproc);
+ for (pringTemp = pvproc->VP_ringModules, bStart = LW_TRUE;
+ pringTemp && (pringTemp != pvproc->VP_ringModules || bStart);
+ pringTemp = _list_ring_get_next(pringTemp), bStart = LW_FALSE) {
+
+ pmodTemp = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
+
+#if LW_CFG_VMM_EN > 0
+ ulPages = 0;
+ if (API_VmmPCountInArea(pmodTemp->EMOD_pvBaseAddr, &ulPages) == ERROR_NONE) {
+ stStatic += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
+ }
+#else
+ stStatic += pmodTemp->EMOD_stLen;
+#endif /* LW_CFG_VMM_EN > 0 */
+ stStatic += __moduleSymbolBufferSize(pmodTemp);
+ }
+
+ if (stStatic) { /* 至少存在一个模块 */
+ pmodTemp = _LIST_ENTRY(pvproc->VP_ringModules, LW_LD_EXEC_MODULE, EMOD_ringModules);
+ ulPages = 0;
+
+#if LW_CFG_VMM_EN > 0
+ iNum = __moduleVpPatchVmem(pmodTemp, pvVmem, LW_LD_VMEM_MAX);
+ if (iNum > 0) {
+ for (i = 0; i < iNum; i++) {
+ if (API_VmmPCountInArea(pvVmem[i],
+ &ulPages) == ERROR_NONE) {
+ stHeap += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
+ }
+ }
+ }
+#else
+ pheapVpPatch = (PLW_CLASS_HEAP)__moduleVpPatchHeap(pmodTemp);
+ if (pheapVpPatch) { /* 获得 vp 进程私有 heap */
+ stHeap += (size_t)(pheapVpPatch->HEAP_stTotalByteSize);
+ }
+#endif /* LW_CFG_VMM_EN > 0 */
+ }
+ LW_VP_UNLOCK(pvproc);
+
+#if LW_CFG_VMM_EN > 0
+ API_VmmMmapPCount(pvproc->VP_pid, &stMmap); /* 计算 mmap 内存实际消耗量 */
+#endif /* LW_CFG_VMM_EN > 0 */
+
+ if (pstStatic) {
+ *pstStatic = stStatic;
+ }
+
+ if (pstHeap) {
+ *pstHeap = stHeap;
+ }
+
+ if (pstMmap) {
+ *pstMmap = stMmap;
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: vprocMemInfo
+** 功能描述: 获得进程内存使用情况
+** 输 入 : pid 进程号
+** pstStatic 静态内存大小
+** pstHeap 内存堆消耗
+** pstMmap mmap 大小
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+INT vprocMemInfo (pid_t pid, size_t *pstStatic, size_t *pstHeap, size_t *pstMmap)
+{
+ INT iRet;
+ LW_LD_VPROC *pvproc;
+
+ LW_LD_LOCK();
+ pvproc = vprocGet(pid);
+ if (!pvproc) {
+ LW_LD_UNLOCK();
+ return (PX_ERROR);
+ }
+
+ iRet = vprocMemInfoNoLock(pvproc, pstStatic, pstHeap, pstMmap);
+ LW_LD_UNLOCK();
+
+ return (iRet);
+}
+/*********************************************************************************************************
+** 函数名称: vprocListGet
+** 功能描述: 获得进程列表
+** 输 入 : pidTable 进程号表
+** uiMaxCnt 缓存个数
+** 输 出 : 获取的进程个数
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+INT vprocListGet (pid_t pidTable[], UINT uiMaxCnt)
+{
+ INT i, iNum = 0;
+
+ if (!pidTable || !uiMaxCnt) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ LW_LD_LOCK();
+ for (i = 0; i < LW_CFG_MAX_THREADS; i++) {
+ if (_G_pvprocTable[i]) {
+ pidTable[iNum] = _G_pvprocTable[i]->VP_pid;
+ iNum++;
+ if (iNum >= uiMaxCnt) {
+ break;
+ }
+ }
+ }
+ LW_LD_UNLOCK();
+
+ return (iNum);
+}
+
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/posix/pthread/pthread.c b/SylixOS/posix/pthread/pthread.c
index 0f1e7e3..15da09e 100644
--- a/SylixOS/posix/pthread/pthread.c
+++ b/SylixOS/posix/pthread/pthread.c
@@ -51,7 +51,6 @@
#if LW_CFG_POSIX_EN > 0
#if (LW_CFG_GJB7714_EN > 0) && (LW_CFG_MODULELOADER_EN > 0)
#include "unistd.h"
-#include "../SylixOS/loader/include/loader_vppatch.h"
#endif
/*********************************************************************************************************
** 函数名称: pthread_atfork
@@ -1052,7 +1051,7 @@ int pthread_getid (const char *name, pthread_t *pthread)
}
#if LW_CFG_MODULELOADER_EN > 0
- if (pid != vprocGetPidByTcbdesc(&tcbdesc)) {
+ if (pid != (pid_t)tcbdesc.TCBD_lPid) {
continue;
}
#endif /* LW_CFG_MODULELOADER_EN > 0 */
diff --git a/libsylixos.mk b/libsylixos.mk
index df073a5..d90540b 100644
--- a/libsylixos.mk
+++ b/libsylixos.mk
@@ -1388,6 +1388,7 @@ SylixOS/loader/src/loader_symbol.c \
SylixOS/loader/src/loader_vpdebug.c \
SylixOS/loader/src/loader_vppatch.c \
SylixOS/loader/src/loader_vpstack.c \
+SylixOS/loader/src/loader_vpstat.c \
SylixOS/loader/src/loader_vpthread.c \
SylixOS/loader/src/loader_vptimer.c \
SylixOS/loader/src/loader_wait.c