Skip to content

Commit 6786f11

Browse files
committed
sched/kconfig: add PIDHASH_INITIAL_LENGTH
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]>
1 parent 6d13cac commit 6786f11

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sched/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,3 +1937,10 @@ config GROUP_KILL_CHILDREN_TIMEOUT_MS
19371937
> 0 means wait timeout
19381938
= 0 means don't do kill signal
19391939

1940+
config PIDHASH_INITIAL_LENGTH
1941+
int "Initial length of pid hash table"
1942+
default 4 if DEFAULT_SMALL
1943+
default 8 if !DEFAULT_SMALL
1944+
---help---
1945+
This specifies the initial length of pid table, it shall be
1946+
power of two.

sched/init/nx_start.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <nuttx/binfmt/binfmt.h>
4646
#include <nuttx/drivers/drivers.h>
4747
#include <nuttx/init.h>
48+
#include <nuttx/lib/math32.h>
4849

4950
#include "task/task.h"
5051
#include "sched/sched.h"
@@ -68,6 +69,10 @@
6869

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

72+
#if !POWER_OF_TWO(CONFIG_PIDHASH_INITIAL_LENGTH)
73+
# error "CONFIG_PIDHASH_INITIAL_LENGTH shall be power of two!"
74+
#endif
75+
7176
/****************************************************************************
7277
* Public Data
7378
****************************************************************************/
@@ -623,7 +628,7 @@ void nx_start(void)
623628

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

626-
nxsched_npidhash() = 4;
631+
nxsched_npidhash() = CONFIG_PIDHASH_INITIAL_LENGTH;
627632
while (nxsched_npidhash() <= CONFIG_SMP_NCPUS)
628633
{
629634
nxsched_npidhash() <<= 1;

0 commit comments

Comments
 (0)