Skip to content

Commit 263f895

Browse files
Gary-Hobsonxiaoxiang781216
authored andcommitted
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 <[email protected]>
1 parent efbf43c commit 263f895

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

boards/arm/stm32f7/nucleo-144/configs/f746-pysim/defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ CONFIG_DEV_GPIO=y
3434
CONFIG_ETH0_PHY_LAN8742A=y
3535
CONFIG_FS_PROCFS=y
3636
CONFIG_FS_PROCFS_EXCLUDE_ENVIRON=y
37-
CONFIG_FS_PROCFS_MAX_TASKS=16
3837
CONFIG_FS_PROCFS_REGISTER=y
3938
CONFIG_HAVE_CXX=y
4039
CONFIG_HAVE_CXXINITIALIZE=y

fs/procfs/Kconfig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ config FS_PROCFS_REGISTER
2121
Support run-time registration of the new entries in the procfs file
2222
system.
2323

24-
config FS_PROCFS_MAX_TASKS
25-
int "The maximum number of active tasks for procfs snapshot"
26-
default 128
27-
---help---
28-
The maximum number of active tasks for procfs snapshot.
29-
3024
menu "Exclude individual procfs entries"
3125

3226
config FS_PROCFS_EXCLUDE_BLOCKS

fs/procfs/fs_procfs.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <nuttx/fs/procfs.h>
4848

4949
#include "mount/mount.h"
50+
#include "sched/sched.h"
5051

5152
/****************************************************************************
5253
* External Definitions
@@ -315,8 +316,8 @@ struct procfs_level0_s
315316
/* Our private data */
316317

317318
uint8_t lastlen; /* length of last reported static dir */
318-
pid_t pid[CONFIG_FS_PROCFS_MAX_TASKS]; /* Snapshot of all active task IDs */
319319
FAR const char *lastread; /* Pointer to last static dir read */
320+
pid_t pid[1]; /* Snapshot of all active task IDs */
320321
};
321322

322323
/* 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)
355356

356357
/* Add the PID to the list */
357358

358-
index = dir->base.nentries;
359-
if (index >= CONFIG_FS_PROCFS_MAX_TASKS)
359+
if (dir->base.index >= dir->base.nentries)
360360
{
361361
return;
362362
}
363363

364+
index = dir->base.index;
364365
dir->pid[index] = tcb->pid;
365-
dir->base.nentries = index + 1;
366+
dir->base.index = index + 1;
366367
}
367368

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

634635
if (!relpath || relpath[0] == '\0')
635636
{
637+
size_t num = 0;
638+
636639
/* The path refers to the top level directory. Allocate the level0
637640
* dirent structure.
638641
*/
639642

643+
#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
644+
num = g_npidhash;
645+
#endif
646+
640647
level0 = (FAR struct procfs_level0_s *)
641-
kmm_zalloc(sizeof(struct procfs_level0_s));
648+
kmm_zalloc(sizeof(struct procfs_level0_s) + sizeof(pid_t) * num) ;
642649
if (!level0)
643650
{
644651
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,
653660
*/
654661

655662
#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
663+
level0->base.index = 0;
664+
level0->base.nentries = num;
656665
nxsched_foreach(procfs_enum, level0);
666+
level0->base.nentries = level0->base.index;
667+
level0->base.index = 0;
657668
procfs_sort_pid(level0);
658669
#else
659670
level0->base.index = 0;

0 commit comments

Comments
 (0)