Skip to content

Commit

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

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

config PIDHASH_INITIAL_LENGTH
int "Initial length of pid hash table"
default 4 if DEFAULT_SMALL
default 8 if !DEFAULT_SMALL
---help---
This specifies the initial length of pid table, it shall be
power of two.
7 changes: 6 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 All @@ -68,6 +69,10 @@

#define SCHED_ALL_CPUS ((1 << CONFIG_SMP_NCPUS) - 1)

#if !POWER_OF_TWO(CONFIG_PIDHASH_INITIAL_LENGTH)
# error "CONFIG_PIDHASH_INITIAL_LENGTH shall be power of two!"
#endif

/****************************************************************************
* Public Data
****************************************************************************/
Expand Down Expand Up @@ -623,7 +628,7 @@ void nx_start(void)

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

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

0 comments on commit 69ee5a2

Please sign in to comment.