Skip to content

Commit

Permalink
fs/procfs: Supports any number of thread displays
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Gary-Hobson authored and xiaoxiang781216 committed Aug 28, 2024
1 parent efbf43c commit 263f895
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 0 additions & 1 deletion boards/arm/stm32f7/nucleo-144/configs/f746-pysim/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ CONFIG_DEV_GPIO=y
CONFIG_ETH0_PHY_LAN8742A=y
CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_EXCLUDE_ENVIRON=y
CONFIG_FS_PROCFS_MAX_TASKS=16
CONFIG_FS_PROCFS_REGISTER=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
Expand Down
6 changes: 0 additions & 6 deletions fs/procfs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ config FS_PROCFS_REGISTER
Support run-time registration of the new entries in the procfs file
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"

config FS_PROCFS_EXCLUDE_BLOCKS
Expand Down
21 changes: 16 additions & 5 deletions fs/procfs/fs_procfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <nuttx/fs/procfs.h>

#include "mount/mount.h"
#include "sched/sched.h"

/****************************************************************************
* External Definitions
Expand Down Expand Up @@ -315,8 +316,8 @@ struct procfs_level0_s
/* Our private data */

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 */
pid_t pid[1]; /* Snapshot of all active task IDs */
};

/* Level 1 is an internal virtual directory (such as /proc/fs) which
Expand Down Expand Up @@ -355,14 +356,14 @@ static void procfs_enum(FAR struct tcb_s *tcb, FAR void *arg)

/* Add the PID to the list */

index = dir->base.nentries;
if (index >= CONFIG_FS_PROCFS_MAX_TASKS)
if (dir->base.index >= dir->base.nentries)
{
return;
}

index = dir->base.index;
dir->pid[index] = tcb->pid;
dir->base.nentries = index + 1;
dir->base.index = index + 1;
}

/****************************************************************************
Expand Down Expand Up @@ -633,12 +634,18 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,

if (!relpath || relpath[0] == '\0')
{
size_t num = 0;

/* The path refers to the top level directory. Allocate the level0
* dirent structure.
*/

#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
num = g_npidhash;
#endif

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)
{
ferr("ERROR: Failed to allocate the level0 directory structure\n");
Expand All @@ -653,7 +660,11 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
*/

#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
level0->base.index = 0;
level0->base.nentries = num;
nxsched_foreach(procfs_enum, level0);
level0->base.nentries = level0->base.index;
level0->base.index = 0;
procfs_sort_pid(level0);
#else
level0->base.index = 0;
Expand Down

0 comments on commit 263f895

Please sign in to comment.