1# Copyright (c) 2017 Intel Corporation
2# Copyright (c) 2023 Meta
3# Copyright (c) 2024 Tenstorrent AI ULC
4#
5# SPDX-License-Identifier: Apache-2.0
6
7menuconfig POSIX_THREADS
8	bool "POSIX thread support"
9	help
10	  Select 'y' here to enable POSIX threads, mutexes, condition variables, and thread-specific
11	  storage.
12
13	  For more information please see
14	  https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
15
16if POSIX_THREADS
17
18config HEAP_MEM_POOL_ADD_SIZE_POSIX_THREADS
19	def_int 256
20
21config POSIX_THREAD_THREADS_MAX
22	int "Maximum number of POSIX threads"
23	default 5
24	help
25	  Maximum simultaneously active threads in a POSIX application.
26
27	  For more information, see
28	  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
29
30config MAX_PTHREAD_MUTEX_COUNT
31	int "Maximum number of POSIX mutexes"
32	default 5
33	help
34	  Maximum simultaneously active mutexes in a POSIX application.
35
36config MAX_PTHREAD_COND_COUNT
37	int "Maximum number of POSIX condition variables"
38	default 5
39	help
40	  Maximum simultaneously active condition variables in a POSIX application.
41
42config POSIX_THREAD_KEYS_MAX
43	int "Maximum number of POSIX thread-specific-storage keys"
44	default 5
45	help
46	  Maximum simultaneously active thread-specific-storage keys in a POSIX application.
47
48	  For more information, see
49	  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
50
51config PTHREAD_RECYCLER_DELAY_MS
52	int "Delay for reclaiming dynamic pthread stacks (ms)"
53	default 100
54	help
55	  Prior to a POSIX thread terminating via k_thread_abort(), scheduled
56	  work is added to the system workqueue (SWQ) so that any resources
57	  allocated by the thread (e.g. thread stack from a pool or the heap)
58	  can be released back to the system. Because resources are also freed
59	  on calls to pthread_create() there is no need to worry about resource
60	  starvation.
61
62	  This option sets the number of milliseconds by which to defer
63	  scheduled work.
64
65	  Note: this option should be considered temporary and will likely be
66	  removed once a more synchronous solution is available.
67
68config POSIX_THREAD_ATTR_STACKADDR
69	bool "Support getting and setting POSIX thread stack addresses"
70	help
71	  Enable this option to use pthread_attr_getstackaddr() and
72	  pthread_attr_setstackaddr().
73
74	  This option was removed in IEEE 1003.1-2017 in favour of
75	  pthread_attr_getstack() and pthread_attr_setstack().
76
77	  For more information, please see
78	  https://pubs.opengroup.org/onlinepubs/009696799/functions/pthread_attr_getstackaddr.html
79	  https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html
80	  https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_08
81
82config POSIX_THREAD_ATTR_STACKSIZE
83	bool "Support getting and setting POSIX thread stack sizes"
84	help
85	  Enable this option to use pthread_attr_getstacksize() or
86	  pthread_attr_setstacksize().
87
88	  For more information, please see
89	  https://pubs.opengroup.org/onlinepubs/009696699/functions/pthread_attr_getstacksize.html
90
91config POSIX_THREADS_EXT
92	bool "Extended POSIX thread support"
93	help
94	  Enable this option to use pthread_attr_getguardsize(), pthread_attr_setguardsize(),
95	  pthread_mutexattr_gettype(), or pthread_mutexattr_settype().
96
97	  For more information, please see
98	  https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
99
100config POSIX_THREAD_PRIORITY_SCHEDULING
101	bool "Run POSIX threads with different priorities and schedulers"
102	help
103	  Enabling this option allows the application to configure different priorities and
104	  scheduling algorithms for different threads via functions such as pthread_setschedparam()
105	  and pthread_setschedprio(). This is required for Realtime Threads and Advanced Realtime
106	  Threads.
107
108	  For more information, please see
109	  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html#tag_02_01_06
110	  https://man7.org/linux/man-pages/man7/posixoptions.7.html
111
112config POSIX_PTHREAD_ATTR_STACKSIZE_BITS
113	int "Significant bits for pthread_attr_t stacksize"
114	range 8 31
115	default 23
116	help
117	  This value plays a part in determining the maximum supported
118	  pthread_attr_t stacksize. Valid stacksizes are in the range
119	  [1, N], where N = 1 << M, and M is this configuration value.
120
121config POSIX_PTHREAD_ATTR_GUARDSIZE_BITS
122	int "Significant bits for pthread_attr_t guardsize"
123	range 1 31
124	default 9
125	help
126	  This value plays a part in determining the maximum supported
127	  pthread_attr_t guardsize. Valid guardsizes are in the range
128	  [0, N-1], where N = 1 << M, and M is this configuration value.
129
130	  Actual guardsize values may be rounded-up.
131
132config POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT
133	int "Default size of stack guard area"
134	default 0
135	help
136	  This is the default amount of space to reserve at the overflow end of a
137	  pthread stack. Since Zephyr already supports both software-based stack
138	  protection (canaries) and hardware-based stack protection (MMU or MPU),
139	  this is set to 0 by default. However, a conforming application would be
140	  required to set this to PAGESIZE. Eventually, this option might
141	  facilitate a more dynamic approach to guard areas (via software or
142	  hardware) but for now it simply increases the size of thread stacks.
143
144config POSIX_THREAD_PRIO_INHERIT
145	bool "POSIX mutex priority inheritance"
146	help
147	  Select 'y' here to enable POSIX mutex priority inheritance.
148
149	  For more information, please see
150	  https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html
151
152config POSIX_THREAD_PRIO_PROTECT
153	bool "POSIX mutex priority protection"
154	help
155	  Select 'y' here to enable POSIX mutex priority protection.
156
157	  For more information, please see
158	  https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html
159
160config POSIX_THREAD_SAFE_FUNCTIONS
161	bool "POSIX thread-safe functions"
162	select POSIX_FILE_SYSTEM_R
163	select POSIX_C_LANG_SUPPORT_R
164	help
165	  Select 'y' here to enable POSIX thread-safe functions including asctime_r(), ctime_r(),
166	  flockfile(), ftrylockfile(), funlockfile(), getc_unlocked(), getchar_unlocked(),
167	  getgrgid_r(), getgrnam_r(), getpwnam_r(), getpwuid_r(), gmtime_r(), localtime_r(),
168	  putc_unlocked(), putchar_unlocked(), rand_r(), readdir_r(), strerror_r(), and strtok_r().
169
170	  For more information, please see
171	  https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html#tag_22_02_09_07
172
173module = PTHREAD
174module-str = POSIX thread
175source "subsys/logging/Kconfig.template.log_config"
176
177module = PTHREAD_MUTEX
178module-str = POSIX mutex
179source "subsys/logging/Kconfig.template.log_config"
180
181module = PTHREAD_COND
182module-str = POSIX condition variable
183source "subsys/logging/Kconfig.template.log_config"
184
185module = PTHREAD_KEY
186module-str = POSIX thread-specific data
187source "subsys/logging/Kconfig.template.log_config"
188
189endif # POSIX_THREADS
190