Skip to content

Commit

Permalink
sched/kconfig: add INITIAL_PID_LIMIT
Browse files Browse the repository at this point in the history
This adds a config for initial pid table length so that to reduce
reallocations when num of threads are known by design.

Signed-off-by: Yanfeng Liu <[email protected]>
  • Loading branch information
yf13 committed Jun 1, 2024
1 parent 4037a74 commit dd7be31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions sched/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1937,3 +1937,14 @@ config GROUP_KILL_CHILDREN_TIMEOUT_MS
> 0 means wait timeout
= 0 means don't do kill signal

config INITIAL_PID_LIMIT
int "Initial length of pid hash table"
default 4 if DEFAULT_SMALL
default 16 if !DEFAULT_SMALL
---help---
This specifies the initial length of pid table, it shall be
power of two. Note this doesn't prevent the system from
expanding it if more pids are needed. If the max number
of threads in your system is known by design, setting this
to it can avoid unnecessary reallocations of the table after
boot.
5 changes: 4 additions & 1 deletion sched/init/nx_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <nuttx/binfmt/binfmt.h>
#include <nuttx/drivers/drivers.h>
#include <nuttx/init.h>
#include <nuttx/lib/math32.h>

#include "task/task.h"
#include "sched/sched.h"
Expand Down Expand Up @@ -623,7 +624,9 @@ void nx_start(void)

/* Initialize the logic that determine unique process IDs. */

nxsched_npidhash() = 4;
static_assert(IS_POWER_OF_2(CONFIG_INITIAL_PID_LIMIT));

nxsched_npidhash() = CONFIG_INITIAL_PID_LIMIT;
while (nxsched_npidhash() <= CONFIG_SMP_NCPUS)
{
nxsched_npidhash() <<= 1;
Expand Down

0 comments on commit dd7be31

Please sign in to comment.