fs/procfs: Supports any number of thread displays
After the number of threads exceeds the array size, it will not be displayed. Any number of threads can be displayed using dynamic adaptation Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
parent
efbf43cdfa
commit
263f8955da
@ -34,7 +34,6 @@ CONFIG_DEV_GPIO=y
|
|||||||
CONFIG_ETH0_PHY_LAN8742A=y
|
CONFIG_ETH0_PHY_LAN8742A=y
|
||||||
CONFIG_FS_PROCFS=y
|
CONFIG_FS_PROCFS=y
|
||||||
CONFIG_FS_PROCFS_EXCLUDE_ENVIRON=y
|
CONFIG_FS_PROCFS_EXCLUDE_ENVIRON=y
|
||||||
CONFIG_FS_PROCFS_MAX_TASKS=16
|
|
||||||
CONFIG_FS_PROCFS_REGISTER=y
|
CONFIG_FS_PROCFS_REGISTER=y
|
||||||
CONFIG_HAVE_CXX=y
|
CONFIG_HAVE_CXX=y
|
||||||
CONFIG_HAVE_CXXINITIALIZE=y
|
CONFIG_HAVE_CXXINITIALIZE=y
|
||||||
|
@ -21,12 +21,6 @@ config FS_PROCFS_REGISTER
|
|||||||
Support run-time registration of the new entries in the procfs file
|
Support run-time registration of the new entries in the procfs file
|
||||||
system.
|
system.
|
||||||
|
|
||||||
config FS_PROCFS_MAX_TASKS
|
|
||||||
int "The maximum number of active tasks for procfs snapshot"
|
|
||||||
default 128
|
|
||||||
---help---
|
|
||||||
The maximum number of active tasks for procfs snapshot.
|
|
||||||
|
|
||||||
menu "Exclude individual procfs entries"
|
menu "Exclude individual procfs entries"
|
||||||
|
|
||||||
config FS_PROCFS_EXCLUDE_BLOCKS
|
config FS_PROCFS_EXCLUDE_BLOCKS
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include <nuttx/fs/procfs.h>
|
#include <nuttx/fs/procfs.h>
|
||||||
|
|
||||||
#include "mount/mount.h"
|
#include "mount/mount.h"
|
||||||
|
#include "sched/sched.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* External Definitions
|
* External Definitions
|
||||||
@ -315,8 +316,8 @@ struct procfs_level0_s
|
|||||||
/* Our private data */
|
/* Our private data */
|
||||||
|
|
||||||
uint8_t lastlen; /* length of last reported static dir */
|
uint8_t lastlen; /* length of last reported static dir */
|
||||||
pid_t pid[CONFIG_FS_PROCFS_MAX_TASKS]; /* Snapshot of all active task IDs */
|
|
||||||
FAR const char *lastread; /* Pointer to last static dir read */
|
FAR const char *lastread; /* Pointer to last static dir read */
|
||||||
|
pid_t pid[1]; /* Snapshot of all active task IDs */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Level 1 is an internal virtual directory (such as /proc/fs) which
|
/* Level 1 is an internal virtual directory (such as /proc/fs) which
|
||||||
@ -355,14 +356,14 @@ static void procfs_enum(FAR struct tcb_s *tcb, FAR void *arg)
|
|||||||
|
|
||||||
/* Add the PID to the list */
|
/* Add the PID to the list */
|
||||||
|
|
||||||
index = dir->base.nentries;
|
if (dir->base.index >= dir->base.nentries)
|
||||||
if (index >= CONFIG_FS_PROCFS_MAX_TASKS)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
index = dir->base.index;
|
||||||
dir->pid[index] = tcb->pid;
|
dir->pid[index] = tcb->pid;
|
||||||
dir->base.nentries = index + 1;
|
dir->base.index = index + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -633,12 +634,18 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
|
|||||||
|
|
||||||
if (!relpath || relpath[0] == '\0')
|
if (!relpath || relpath[0] == '\0')
|
||||||
{
|
{
|
||||||
|
size_t num = 0;
|
||||||
|
|
||||||
/* The path refers to the top level directory. Allocate the level0
|
/* The path refers to the top level directory. Allocate the level0
|
||||||
* dirent structure.
|
* dirent structure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
|
||||||
|
num = g_npidhash;
|
||||||
|
#endif
|
||||||
|
|
||||||
level0 = (FAR struct procfs_level0_s *)
|
level0 = (FAR struct procfs_level0_s *)
|
||||||
kmm_zalloc(sizeof(struct procfs_level0_s));
|
kmm_zalloc(sizeof(struct procfs_level0_s) + sizeof(pid_t) * num) ;
|
||||||
if (!level0)
|
if (!level0)
|
||||||
{
|
{
|
||||||
ferr("ERROR: Failed to allocate the level0 directory structure\n");
|
ferr("ERROR: Failed to allocate the level0 directory structure\n");
|
||||||
@ -653,7 +660,11 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
|
#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
|
||||||
|
level0->base.index = 0;
|
||||||
|
level0->base.nentries = num;
|
||||||
nxsched_foreach(procfs_enum, level0);
|
nxsched_foreach(procfs_enum, level0);
|
||||||
|
level0->base.nentries = level0->base.index;
|
||||||
|
level0->base.index = 0;
|
||||||
procfs_sort_pid(level0);
|
procfs_sort_pid(level0);
|
||||||
#else
|
#else
|
||||||
level0->base.index = 0;
|
level0->base.index = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user