Skip to content

Commit dd7be31

Browse files
committed
sched/kconfig: add INITIAL_PID_LIMIT
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 4037a74 commit dd7be31

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

sched/Kconfig

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

1940+
config INITIAL_PID_LIMIT
1941+
int "Initial length of pid hash table"
1942+
default 4 if DEFAULT_SMALL
1943+
default 16 if !DEFAULT_SMALL
1944+
---help---
1945+
This specifies the initial length of pid table, it shall be
1946+
power of two. Note this doesn't prevent the system from
1947+
expanding it if more pids are needed. If the max number
1948+
of threads in your system is known by design, setting this
1949+
to it can avoid unnecessary reallocations of the table after
1950+
boot.

sched/init/nx_start.c

Lines changed: 4 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"
@@ -623,7 +624,9 @@ void nx_start(void)
623624

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

626-
nxsched_npidhash() = 4;
627+
static_assert(IS_POWER_OF_2(CONFIG_INITIAL_PID_LIMIT));
628+
629+
nxsched_npidhash() = CONFIG_INITIAL_PID_LIMIT;
627630
while (nxsched_npidhash() <= CONFIG_SMP_NCPUS)
628631
{
629632
nxsched_npidhash() <<= 1;

0 commit comments

Comments
 (0)