From fcebe600909a61723dc0478abc429a926e1bc8fe Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Wed, 22 May 2024 23:48:17 -0400 Subject: [PATCH] posix: deprecate PTHREAD_IPC _MUTEX _COND and _KEY Zephyr's POSIX API is moving toward using the standard nomenclature from IEEE 1003.1-2017 for as much as possible. In particular, we want to have consistent naming between Zephyr's POSIX API Kconfig options and the naming for POSIX Options and Option Groups. The Kconfig option CONFIG_PTHREAD_IPC has been (ab)used for a very long time for a variety of different purposes. However, the standard Option / feature test macro for POSIX Threads is, intuitively _POSIX_THREADS. There is a corresponding sysconf() key named _SC_POSIX_THREADS. Annoyingly, the POSIX Option Group that corresponds to the Option is POSIX_THREADS_BASE, which is a minor inconsistency in the standard. The _POSIX_THREADS Option already includes mutexes, condition variables, and thread-specific storage (keys). So with this change, we also deprecate the redundant Kconfig variables that do not have a corresponding match in the standard. - CONFIG_PTHREAD_IPC - CONFIG_PTHREAD - CONFIG_PTHREAD_COND - CONFIG_PTHREAD_MUTEX - CONFIG_PTHREAD_KEY Additionally, create Kconfig variables for those configurables which we are lacking: - CONFIG_POSIX_THREADS_EXT - CONFIG_POSIX_THREAD_ATTR_STACKSIZE - CONFIG_POSIX_THREAD_ATTR_STACKADDR - CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING - CONFIG_POSIX_THREAD_PRIO_INHERIT - CONFIG_POSIX_THREAD_PRIO_PROTECT - CONFIG_POSIX_THREAD_SAFE_FUNCTIONS Some Kconfig variables were renamed to more properly match the spec: - CONFIG_MAX_PTHREAD_COUNT -> CONFIG_POSIX_THREAD_THREADS_MAX - CONFIG_MAX_PTHREAD_KEY_COUNT -> CONFIG_POSIX_THREAD_KEYS_MAX Signed-off-by: Chris Friedt --- doc/services/portability/posix/aep/index.rst | 13 +- .../portability/posix/conformance/index.rst | 18 +-- .../portability/posix/kconfig/index.rst | 13 +- .../portability/posix/option_groups/index.rst | 28 ++++ .../portability/posix/overview/index.rst | 3 +- include/zephyr/posix/posix_features.h | 24 +-- include/zephyr/posix/pthread.h | 4 +- include/zephyr/posix/sys/sysconf.h | 14 +- lib/posix/options/CMakeLists.txt | 14 +- lib/posix/options/Kconfig | 12 -- lib/posix/options/Kconfig.cond | 9 -- lib/posix/options/Kconfig.deprecated | 64 ++++++++ lib/posix/options/Kconfig.key | 9 -- lib/posix/options/Kconfig.mutex | 9 -- lib/posix/options/Kconfig.pthread | 142 +++++++++++++++++- lib/posix/options/Kconfig.sched | 4 +- .../options/Kconfig.template.pooled_ipc_type | 29 ---- .../options/Kconfig.template.pooled_type | 25 --- .../options/Kconfig.template.with_logging | 7 - lib/posix/options/Kconfig.template.with_url | 5 - lib/posix/options/Kconfig.xsi | 10 ++ lib/posix/options/key.c | 6 +- lib/posix/options/pthread.c | 24 ++- lib/posix/options/pthread_sched.h | 24 +++ lib/posix/options/rwlock.c | 2 +- lib/posix/options/sched.c | 17 +-- .../{_common.c => timespec_to_timeout.c} | 2 - modules/Kconfig.simplelink | 4 +- samples/posix/philosophers/prj.conf | 2 +- samples/posix/philosophers/src/main.c | 6 +- tests/posix/common/prj.conf | 3 +- tests/posix/common/src/key.c | 6 +- tests/posix/common/src/pthread.c | 2 +- tests/posix/common/src/sysconf.c | 2 +- tests/posix/headers/prj.conf | 2 +- tests/posix/pthread_pressure/src/main.c | 2 +- 36 files changed, 349 insertions(+), 211 deletions(-) delete mode 100644 lib/posix/options/Kconfig.cond delete mode 100644 lib/posix/options/Kconfig.key delete mode 100644 lib/posix/options/Kconfig.mutex delete mode 100644 lib/posix/options/Kconfig.template.pooled_ipc_type delete mode 100644 lib/posix/options/Kconfig.template.pooled_type delete mode 100644 lib/posix/options/Kconfig.template.with_logging delete mode 100644 lib/posix/options/Kconfig.template.with_url rename lib/posix/options/{_common.c => timespec_to_timeout.c} (92%) diff --git a/doc/services/portability/posix/aep/index.rst b/doc/services/portability/posix/aep/index.rst index 83ff41c5a21..6c7ff33de68 100644 --- a/doc/services/portability/posix/aep/index.rst +++ b/doc/services/portability/posix/aep/index.rst @@ -53,8 +53,7 @@ The *Minimal Realtime System Profile* (PSE51) includes all of the :ref:`POSIX_DEVICE_IO `,, :kconfig:option:`CONFIG_POSIX_DEVICE_IO` :ref:`POSIX_SIGNALS `,, :ref:`POSIX_SINGLE_PROCESS `, yes, :kconfig:option:`CONFIG_POSIX_SINGLE_PROCESS` - :ref:`POSIX_THREADS_BASE `, yes, - :ref:`XSI_THREADS_EXT `, yes, + :ref:`XSI_THREADS_EXT `, yes, :kconfig:option:`CONFIG_XSI_THREADS_EXT` .. csv-table:: PSE51 Option Requirements :header: Symbol, Support, Remarks @@ -66,12 +65,12 @@ The *Minimal Realtime System Profile* (PSE51) includes all of the :ref:`_POSIX_MONOTONIC_CLOCK `, 200809L, :kconfig:option:`CONFIG_POSIX_MONOTONIC_CLOCK` :ref:`_POSIX_SHARED_MEMORY_OBJECTS `, -1, :ref:`_POSIX_SYNCHRONIZED_IO `, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` - :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_PTHREAD` - :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_PTHREAD` + :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKADDR` + :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKSIZE` :ref:`_POSIX_THREAD_CPUTIME `, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` - _POSIX_THREAD_PRIO_INHERIT, 200809L, :kconfig:option:`CONFIG_PTHREAD_MUTEX` - _POSIX_THREAD_PRIO_PROTECT, -1, - :ref:`_POSIX_THREAD_PRIORITY_SCHEDULING`, 200809L, :kconfig:option:`CONFIG_POSIX_PRIORITY_SCHEDULING` + :ref:`_POSIX_THREAD_PRIO_INHERIT `, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_PRIO_INHERIT` + :ref:`_POSIX_THREAD_PRIO_PROTECT `, -1, :kconfig:option:`CONFIG_POSIX_THREAD_PRIO_PROTECT` + :ref:`_POSIX_THREAD_PRIORITY_SCHEDULING `, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING` _POSIX_THREAD_SPORADIC_SERVER, -1, .. _posix_aep_pse52: diff --git a/doc/services/portability/posix/conformance/index.rst b/doc/services/portability/posix/conformance/index.rst index 6a11f4d9172..81a2dfc90e4 100644 --- a/doc/services/portability/posix/conformance/index.rst +++ b/doc/services/portability/posix/conformance/index.rst @@ -70,8 +70,8 @@ POSIX System Interfaces :ref:`_POSIX_REALTIME_SIGNALS`, -1, :ref:`_POSIX_SEMAPHORES`, 200809L, :kconfig:option:`CONFIG_POSIX_SEMAPHORES` :ref:`_POSIX_SPIN_LOCKS`, 200809L, :kconfig:option:`CONFIG_POSIX_SPIN_LOCKS` - :ref:`_POSIX_THREAD_SAFE_FUNCTIONS`, -1, - :ref:`_POSIX_THREADS`, -1, :kconfig:option:`CONFIG_PTHREAD_IPC` + :ref:`_POSIX_THREAD_SAFE_FUNCTIONS`, -1, :kconfig:option:`CONFIG_POSIX_THREAD_SAFE_FUNCTIONS` + :ref:`_POSIX_THREADS`, -1, :kconfig:option:`CONFIG_POSIX_THREADS` :ref:`_POSIX_TIMEOUTS`, 200809L, :kconfig:option:`CONFIG_POSIX_TIMEOUTS` :ref:`_POSIX_TIMERS`, 200809L, :kconfig:option:`CONFIG_POSIX_TIMERS` _POSIX2_C_BIND, 200809L, @@ -95,12 +95,12 @@ POSIX System Interfaces _POSIX_SPAWN, -1, :ref:`†` _POSIX_SPORADIC_SERVER, -1, :ref:`†` :ref:`_POSIX_SYNCHRONIZED_IO `, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` - :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_PTHREAD` - :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_PTHREAD` + :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKADDR` + :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKSIZE` :ref:`_POSIX_THREAD_CPUTIME `, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` - _POSIX_THREAD_PRIO_INHERIT, 200809L, :kconfig:option:`CONFIG_PTHREAD_MUTEX` - _POSIX_THREAD_PRIO_PROTECT, -1, - :ref:`_POSIX_THREAD_PRIORITY_SCHEDULING`, 200809L, :kconfig:option:`CONFIG_PTHREAD` + :ref:`_POSIX_THREAD_PRIO_INHERIT `, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_PRIO_INHERIT` + :ref:`_POSIX_THREAD_PRIO_PROTECT `, -1, :kconfig:option:`CONFIG_POSIX_THREAD_PRIO_PROTECT` + :ref:`_POSIX_THREAD_PRIORITY_SCHEDULING `, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING` _POSIX_THREAD_PROCESS_SHARED, -1, _POSIX_THREAD_SPORADIC_SERVER, -1, _POSIX_TRACE, -1, @@ -149,8 +149,8 @@ XSI System Interfaces :widths: 50, 10, 50 :ref:`_POSIX_FSYNC`, 200809L, :kconfig:option:`CONFIG_POSIX_FSYNC` - :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_PTHREAD` - :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_PTHREAD` + :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKADDR` + :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKSIZE` _POSIX_THREAD_PROCESS_SHARED, -1, .. _CX: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap01.html diff --git a/doc/services/portability/posix/kconfig/index.rst b/doc/services/portability/posix/kconfig/index.rst index be5b2b4e8c7..6c0f6d672a3 100644 --- a/doc/services/portability/posix/kconfig/index.rst +++ b/doc/services/portability/posix/kconfig/index.rst @@ -10,9 +10,6 @@ implementation of the POSIX API. * :kconfig:option:`CONFIG_EVENTFD_MAX` * :kconfig:option:`CONFIG_FDTABLE` * :kconfig:option:`CONFIG_GETOPT_LONG` -* :kconfig:option:`CONFIG_MAX_PTHREAD_COUNT` -* :kconfig:option:`CONFIG_MAX_PTHREAD_KEY_COUNT` -* :kconfig:option:`CONFIG_MAX_PTHREAD_MUTEX_COUNT` * :kconfig:option:`CONFIG_MAX_PTHREAD_SPINLOCK_COUNT` * :kconfig:option:`CONFIG_MQUEUE_NAMELEN_MAX` * :kconfig:option:`CONFIG_POSIX_MQ_OPEN_MAX` @@ -23,17 +20,17 @@ implementation of the POSIX API. * :kconfig:option:`CONFIG_POSIX_API` * :kconfig:option:`CONFIG_ZVFS_OPEN_MAX` * :kconfig:option:`CONFIG_POSIX_OPEN_MAX` +* :kconfig:option:`CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS` +* :kconfig:option:`CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT` +* :kconfig:option:`CONFIG_POSIX_PTHREAD_ATTR_STACKSIZE_BITS` * :kconfig:option:`CONFIG_POSIX_RTSIG_MAX` * :kconfig:option:`CONFIG_POSIX_SIGNAL` * :kconfig:option:`CONFIG_POSIX_SIGNAL_STRING_DESC` +* :kconfig:option:`CONFIG_POSIX_THREAD_KEYS_MAX` +* :kconfig:option:`CONFIG_POSIX_THREAD_THREADS_MAX` * :kconfig:option:`CONFIG_POSIX_UNAME_NODENAME_LEN` * :kconfig:option:`CONFIG_POSIX_UNAME_VERSION_LEN` -* :kconfig:option:`CONFIG_PTHREAD` -* :kconfig:option:`CONFIG_PTHREAD_COND` * :kconfig:option:`CONFIG_PTHREAD_CREATE_BARRIER` -* :kconfig:option:`CONFIG_PTHREAD_IPC` -* :kconfig:option:`CONFIG_PTHREAD_KEY` -* :kconfig:option:`CONFIG_PTHREAD_MUTEX` * :kconfig:option:`CONFIG_PTHREAD_RECYCLER_DELAY_MS` * :kconfig:option:`CONFIG_POSIX_SEM_NAMELEN_MAX` * :kconfig:option:`CONFIG_POSIX_SEM_NSEMS_MAX` diff --git a/doc/services/portability/posix/option_groups/index.rst b/doc/services/portability/posix/option_groups/index.rst index 29c129868be..a71d753204c 100644 --- a/doc/services/portability/posix/option_groups/index.rst +++ b/doc/services/portability/posix/option_groups/index.rst @@ -778,6 +778,34 @@ _POSIX_THREAD_PRIORITY_SCHEDULING pthread_setschedparam(),yes pthread_setschedprio(),yes +.. _posix_option_thread_prio_inherit: + +_POSIX_THREAD_PRIO_INHERIT +++++++++++++++++++++++++++ + +.. csv-table:: _POSIX_THREAD_PRIO_INHERIT + :header: API, Supported + :widths: 50,10 + + pthread_mutexattr_getprotocol(),yes + pthread_mutexattr_setprotocol(),yes + +.. _posix_option_thread_prio_protect: + +_POSIX_THREAD_PRIO_PROTECT +++++++++++++++++++++++++++ + +.. csv-table:: _POSIX_THREAD_PRIO_PROTECT + :header: API, Supported + :widths: 50,10 + + pthread_mutex_getprioceiling(), + pthread_mutex_setprioceiling(), + pthread_mutexattr_getprioceiling(), + pthread_mutexattr_getprotocol(),yes + pthread_mutexattr_setprioceiling(), + pthread_mutexattr_setprotocol(),yes + .. _posix_thread_safe_functions: _POSIX_THREAD_SAFE_FUNCTIONS diff --git a/doc/services/portability/posix/overview/index.rst b/doc/services/portability/posix/overview/index.rst index cd00b68b1a7..2df6d39bbf5 100644 --- a/doc/services/portability/posix/overview/index.rst +++ b/doc/services/portability/posix/overview/index.rst @@ -129,8 +129,7 @@ feature selection at various levels of granularity. Alternatively, users may enable one of the Kconfig options below as a shortcut to enable multiple :ref:`Option Groups`. -* :kconfig:option:`CONFIG_POSIX_API` -* :kconfig:option:`CONFIG_PTHREAD_IPC` +* :kconfig:option:`CONFIG_POSIX_API` - Enables all implemented POSIX API Options and Option Groups .. note:: Since the POSIX environment in Zephyr is fully configurable via :ref:`Kconfig`, diff --git a/include/zephyr/posix/posix_features.h b/include/zephyr/posix/posix_features.h index d95ebf54948..0ff2f371582 100644 --- a/include/zephyr/posix/posix_features.h +++ b/include/zephyr/posix/posix_features.h @@ -94,11 +94,11 @@ /* #define _POSIX_SPORADIC_SERVER (-1L) */ /* #define _POSIX_SYNCHRONIZED_IO (-1L) */ -#ifdef CONFIG_PTHREAD_IPC +#ifdef CONFIG_POSIX_THREAD_ATTR_STACKADDR #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION #endif -#ifdef CONFIG_PTHREAD_IPC +#ifdef CONFIG_POSIX_THREAD_ATTR_STACKSIZE #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION #endif @@ -106,23 +106,29 @@ #define _POSIX_THREAD_CPUTIME _POSIX_VERSION #endif -#ifdef CONFIG_PTHREAD_IPC +#ifdef CONFIG_POSIX_THREAD_PRIO_INHERIT #define _POSIX_THREAD_PRIO_INHERIT _POSIX_VERSION #endif -/* #define _POSIX_THREAD_PRIO_PROTECT (-1L) */ -/* #define _POSIX_THREAD_PRIORITY_SCHEDULING (-1L) */ +#ifdef CONFIG_POSIX_THREAD_PRIO_PROTECT +#define _POSIX_THREAD_PRIO_PROTECT _POSIX_VERSION +#endif + +#ifdef CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING +#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION +#endif + /* #define _POSIX_THREAD_PROCESS_SHARED (-1L) */ /* #define _POSIX_THREAD_ROBUST_PRIO_INHERIT (-1L) */ /* #define _POSIX_THREAD_ROBUST_PRIO_PROTECT (-1L) */ -#ifdef CONFIG_PTHREAD_IPC +#ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION #endif /* #define _POSIX_THREAD_SPORADIC_SERVER (-1L) */ -#ifdef CONFIG_PTHREAD_IPC +#ifdef CONFIG_POSIX_THREADS #ifndef _POSIX_THREADS #define _POSIX_THREADS _POSIX_VERSION #endif @@ -229,9 +235,9 @@ #define _POSIX_SYMLOOP_MAX (8) #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS (4) #define _POSIX_THREAD_KEYS_MAX \ - COND_CODE_1(CONFIG_PTHREAD_IPC, (CONFIG_MAX_PTHREAD_KEY_COUNT), (0)) + COND_CODE_1(CONFIG_POSIX_THREADS, (CONFIG_POSIX_THREAD_KEYS_MAX), (0)) #define _POSIX_THREAD_THREADS_MAX \ - COND_CODE_1(CONFIG_PTHREAD_IPC, (CONFIG_MAX_PTHREAD_COUNT), (0)) + COND_CODE_1(CONFIG_POSIX_THREADS, (CONFIG_POSIX_THREAD_THREADS_MAX), (0)) #define _POSIX_TIMER_MAX \ COND_CODE_1(CONFIG_POSIX_TIMERS, (CONFIG_POSIX_TIMER_MAX), (0)) #define _POSIX_TRACE_EVENT_NAME_MAX (30) diff --git a/include/zephyr/posix/pthread.h b/include/zephyr/posix/pthread.h index 0a721f58be2..33288d7d755 100644 --- a/include/zephyr/posix/pthread.h +++ b/include/zephyr/posix/pthread.h @@ -417,7 +417,7 @@ int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope); int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope); int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched); int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched); -#ifdef CONFIG_PTHREAD_IPC +#ifdef CONFIG_POSIX_THREADS int pthread_once(pthread_once_t *once, void (*initFunc)(void)); #endif FUNC_NORETURN void pthread_exit(void *retval); @@ -502,7 +502,7 @@ int pthread_setname_np(pthread_t thread, const char *name); */ int pthread_getname_np(pthread_t thread, char *name, size_t len); -#ifdef CONFIG_PTHREAD_IPC +#ifdef CONFIG_POSIX_THREADS /** * @brief Destroy a pthread_spinlock_t. diff --git a/include/zephyr/posix/sys/sysconf.h b/include/zephyr/posix/sys/sysconf.h index 812f3bf8c71..f53d598ac0b 100644 --- a/include/zephyr/posix/sys/sysconf.h +++ b/include/zephyr/posix/sys/sysconf.h @@ -183,22 +183,24 @@ enum { #define __z_posix_sysconf_SC_SS_REPL_MAX _POSIX_SS_REPL_MAX #define __z_posix_sysconf_SC_SYNCHRONIZED_IO (-1L) #define __z_posix_sysconf_SC_THREAD_ATTR_STACKADDR \ - COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREAD_ATTR_STACKADDR), (-1)) + COND_CODE_1(CONFIG_POSIX_THREAD_ATTR_STACKADDR, (_POSIX_THREAD_ATTR_STACKADDR), (-1)) #define __z_posix_sysconf_SC_THREAD_ATTR_STACKSIZE \ - COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREAD_ATTR_STACKSIZE), (-1L)) + COND_CODE_1(CONFIG_POSIX_THREAD_ATTR_STACKSIZE, (_POSIX_THREAD_ATTR_STACKSIZE), (-1L)) #define __z_posix_sysconf_SC_THREAD_CPUTIME (-1L) #define __z_posix_sysconf_SC_THREAD_PRIO_INHERIT \ - COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREAD_PRIO_INHERIT), (-1L)) + COND_CODE_1(CONFIG_POSIX_THREAD_PRIO_INHERIT, (_POSIX_THREAD_PRIO_INHERIT), (-1L)) #define __z_posix_sysconf_SC_THREAD_PRIO_PROTECT (-1L) -#define __z_posix_sysconf_SC_THREAD_PRIORITY_SCHEDULING (-1L) +#define __z_posix_sysconf_SC_THREAD_PRIORITY_SCHEDULING \ + COND_CODE_1(CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING, (_POSIX_THREAD_PRIORITY_SCHEDULING), \ + (-1L)) #define __z_posix_sysconf_SC_THREAD_PROCESS_SHARED (-1L) #define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_INHERIT (-1L) #define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_PROTECT (-1L) #define __z_posix_sysconf_SC_THREAD_SAFE_FUNCTIONS \ - COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREAD_SAFE_FUNCTIONS), (-1L)) + COND_CODE_1(CONFIG_POSIX_THREAD_SAFE_FUNCTIONS, (_POSIX_THREAD_SAFE_FUNCTIONS), (-1L)) #define __z_posix_sysconf_SC_THREAD_SPORADIC_SERVER (-1L) #define __z_posix_sysconf_SC_THREADS \ - COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREADS), (-1L)) + COND_CODE_1(CONFIG_POSIX_THREADS, (_POSIX_THREADS), (-1L)) #define __z_posix_sysconf_SC_TIMEOUTS \ COND_CODE_1(CONFIG_POSIX_TIMEOUTS, (_POSIX_TIMEOUTS), (-1L)) #define __z_posix_sysconf_SC_TIMERS \ diff --git a/lib/posix/options/CMakeLists.txt b/lib/posix/options/CMakeLists.txt index 443c0ad0182..1da0e64f99a 100644 --- a/lib/posix/options/CMakeLists.txt +++ b/lib/posix/options/CMakeLists.txt @@ -24,7 +24,7 @@ if(CONFIG_POSIX_SIGNAL) ) endif() -if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_TIMERS OR +if(CONFIG_POSIX_API OR CONFIG_POSIX_THREADS OR CONFIG_POSIX_TIMERS OR CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FILE_SYSTEM OR CONFIG_EVENTFD OR CONFIG_POSIX_C_LIB_EXT OR CONFIG_POSIX_SINGLE_PROCESS) # This is a temporary workaround so that Newlib declares the appropriate @@ -70,15 +70,17 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_SYSLOG syslog.c) zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS clock.c timer.c + timespec_to_timeout.c ) -zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC _common.c) -zephyr_library_sources_ifdef(CONFIG_PTHREAD_COND cond.c) -zephyr_library_sources_ifdef(CONFIG_PTHREAD_KEY key.c) -zephyr_library_sources_ifdef(CONFIG_PTHREAD_MUTEX mutex.c) -zephyr_library_sources_ifdef(CONFIG_PTHREAD pthread.c) zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c) zephyr_library_sources_ifdef(CONFIG_POSIX_READER_WRITER_LOCKS rwlock.c) zephyr_library_sources_ifdef(CONFIG_POSIX_SEMAPHORES semaphore.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_THREADS + cond.c + key.c + mutex.c + pthread.c +) zephyr_library_sources_ifdef(CONFIG_XOPEN_STREAMS stropts.c) zephyr_library_sources_ifdef(CONFIG_XSI_SYSTEM_LOGGING syslog.c) diff --git a/lib/posix/options/Kconfig b/lib/posix/options/Kconfig index 43c93305567..0157c8d884c 100644 --- a/lib/posix/options/Kconfig +++ b/lib/posix/options/Kconfig @@ -14,26 +14,14 @@ config POSIX_API Enable mostly-standards-compliant implementations of various POSIX (IEEE 1003.1) APIs. -config PTHREAD_IPC - bool "POSIX pthread IPC API" - default y if POSIX_API - depends on POSIX_TIMERS - help - This enables a mostly-standards-compliant implementation of - the pthread mutex, condition variable and barrier IPC - mechanisms. - rsource "Kconfig.aio" rsource "Kconfig.barrier" -rsource "Kconfig.cond" rsource "Kconfig.c_lib_ext" rsource "Kconfig.device_io" rsource "Kconfig.fd_mgmt" rsource "Kconfig.fs" -rsource "Kconfig.key" rsource "Kconfig.mem" rsource "Kconfig.mqueue" -rsource "Kconfig.mutex" rsource "Kconfig.net" rsource "Kconfig.proc1" rsource "Kconfig.procN" diff --git a/lib/posix/options/Kconfig.cond b/lib/posix/options/Kconfig.cond deleted file mode 100644 index b69b35dece6..00000000000 --- a/lib/posix/options/Kconfig.cond +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2017 Intel Corporation -# Copyright (c) 2023 Meta -# -# SPDX-License-Identifier: Apache-2.0 - -TYPE = PTHREAD_COND -type = pthread_cond_t -type-function = pthread_cond_wait -rsource "Kconfig.template.pooled_ipc_type" diff --git a/lib/posix/options/Kconfig.deprecated b/lib/posix/options/Kconfig.deprecated index 54564d7891f..83dc737bc3c 100644 --- a/lib/posix/options/Kconfig.deprecated +++ b/lib/posix/options/Kconfig.deprecated @@ -33,6 +33,24 @@ config GETOPT Please use CONFIG_POSIX_C_LIB_EXT instead. +config MAX_PTHREAD_COUNT + int "Maximum number of pthread_t [DEPRECATED]" + default POSIX_THREAD_THREADS_MAX if POSIX_THREADS + default 0 + help + This option is deprecated. + + Please use CONFIG_POSIX_THREAD_THREADS_MAX instead. + +config MAX_PTHREAD_KEY_COUNT + int "Maximum number of pthread_key_t [DEPRECATED]" + default POSIX_THREAD_KEYS_MAX if POSIX_THREADS + default 0 + help + This option is deprecated. + + Please use CONFIG_POSIX_THREAD_KEYS_MAX instead. + config MAX_TIMER_COUNT int "Maximum number of timer_t [DEPRECATED]" default POSIX_TIMER_MAX if POSIX_TIMERS @@ -165,6 +183,15 @@ config POSIX_UNAME Please use CONFIG_POSIX_SINGLE_PROCESS instead. +config PTHREAD + bool "pthread_t support [DEPRECATED]" + select DEPRECATED + select POSIX_THREADS + help + This option is deprecated. + + Please use CONFIG_POSIX_THREADS instead. + config PTHREAD_BARRIER bool "pthread_barrier_t support [DEPRECATED]" select DEPRECATED @@ -174,6 +201,43 @@ config PTHREAD_BARRIER Please use CONFIG_POSIX_BARRIERS instead. +config PTHREAD_COND + bool "pthread_cond_t support [DEPRECATED]" + select DEPRECATED + select POSIX_THREADS + help + This option is deprecated. + + Please use CONFIG_POSIX_THREADS instead. + + +config PTHREAD_IPC + bool "POSIX pthread IPC API [DEPRECATED]" + select DEPRECATED + select POSIX_THREADS + help + This option is deprecated. + + Please use CONFIG_POSIX_THREADS instead. + +config PTHREAD_KEY + bool "pthread_key_t support [DEPRECATED]" + select DEPRECATED + select POSIX_THREADS + help + This option is deprecated. + + Please use CONFIG_POSIX_THREADS instead. + +config PTHREAD_MUTEX + bool "pthread_mutex_t support [DEPRECATED]" + select DEPRECATED + select POSIX_THREADS + help + This option is deprecated. + + Please use CONFIG_POSIX_THREADS instead. + config PTHREAD_RWLOCK bool "pthread_spinlock_t support [DEPRECATED]" select DEPRECATED diff --git a/lib/posix/options/Kconfig.key b/lib/posix/options/Kconfig.key deleted file mode 100644 index 671cce10373..00000000000 --- a/lib/posix/options/Kconfig.key +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2018 Intel Corporation -# Copyright (c) 2023 Meta -# -# SPDX-License-Identifier: Apache-2.0 - -TYPE = PTHREAD_KEY -type = pthread_key_t -type-function = pthread_setspecific -rsource "Kconfig.template.pooled_ipc_type" diff --git a/lib/posix/options/Kconfig.mutex b/lib/posix/options/Kconfig.mutex deleted file mode 100644 index 6d5729e80aa..00000000000 --- a/lib/posix/options/Kconfig.mutex +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2017 Intel Corporation -# Copyright (c) 2023 Meta -# -# SPDX-License-Identifier: Apache-2.0 - -TYPE = PTHREAD_MUTEX -type = pthread_mutex_t -type-function = pthread_mutex_lock -rsource "Kconfig.template.pooled_ipc_type" diff --git a/lib/posix/options/Kconfig.pthread b/lib/posix/options/Kconfig.pthread index f0c65836b60..8c1b813c872 100644 --- a/lib/posix/options/Kconfig.pthread +++ b/lib/posix/options/Kconfig.pthread @@ -1,14 +1,50 @@ # Copyright (c) 2017 Intel Corporation # Copyright (c) 2023 Meta +# Copyright (c) 2024 Tenstorrent AI ULC # # SPDX-License-Identifier: Apache-2.0 -TYPE = PTHREAD -type = pthread_t -type-function = pthread_create -rsource "Kconfig.template.pooled_ipc_type" +menuconfig POSIX_THREADS + bool "POSIX thread support" + default y if POSIX_API + help + Select 'y' here to enable POSIX threads, mutexes, condition variables, and thread-specific + storage. -if PTHREAD + For more information please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html + +if POSIX_THREADS + +config POSIX_THREAD_THREADS_MAX + int "Maximum number of POSIX threads" + default 5 + help + Maximum simultaneously active threads in a POSIX application. + + For more information, see + https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html + +config MAX_PTHREAD_MUTEX_COUNT + int "Maximum number of POSIX mutexes" + default 5 + help + Maximum simultaneously active mutexes in a POSIX application. + +config MAX_PTHREAD_COND_COUNT + int "Maximum number of POSIX condition variables" + default 5 + help + Maximum simultaneously active condition variables in a POSIX application. + +config POSIX_THREAD_KEYS_MAX + int "Maximum number of POSIX thread-specific-storage keys" + default 5 + help + Maximum simultaneously active thread-specific-storage keys in a POSIX application. + + For more information, see + https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html config PTHREAD_RECYCLER_DELAY_MS int "Delay for reclaiming dynamic pthread stacks (ms)" @@ -27,6 +63,54 @@ config PTHREAD_RECYCLER_DELAY_MS Note: this option should be considered temporary and will likely be removed once a more synchronous solution is available. +config POSIX_THREAD_ATTR_STACKADDR + bool "Support getting and setting POSIX thread stack addresses" + default y + help + Enable this option to use pthread_attr_getstackaddr() and + pthread_attr_setstackaddr(). + + This option was removed in IEEE 1003.1-2017 in favour of + pthread_attr_getstack() and pthread_attr_setstack(). + + For more information, please see + https://pubs.opengroup.org/onlinepubs/009696799/functions/pthread_attr_getstackaddr.html + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html + https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_08 + +config POSIX_THREAD_ATTR_STACKSIZE + bool "Support getting and setting POSIX thread stack sizes" + default y + help + Enable this option to use pthread_attr_getstacksize() or + pthread_attr_setstacksize(). + + For more information, please see + https://pubs.opengroup.org/onlinepubs/009696699/functions/pthread_attr_getstacksize.html + +config POSIX_THREADS_EXT + bool "Extended POSIX thread support" + default y + help + Enable this option to use pthread_attr_getguardsize(), pthread_attr_setguardsize(), + pthread_mutexattr_gettype(), or pthread_mutexattr_settype(). + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html + +config POSIX_THREAD_PRIORITY_SCHEDULING + bool "Run POSIX threads with different priorities and schedulers" + default y + help + Enabling this option allows the application to configure different priorities and + scheduling algorithms for different threads via functions such as pthread_setschedparam() + and pthread_setschedprio(). This is required for Realtime Threads and Advanced Realtime + Threads. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html#tag_02_01_06 + https://man7.org/linux/man-pages/man7/posixoptions.7.html + config POSIX_PTHREAD_ATTR_STACKSIZE_BITS int "Significant bits for pthread_attr_t stacksize" range 8 31 @@ -59,4 +143,50 @@ config POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT facilitate a more dynamic approach to guard areas (via software or hardware) but for now it simply increases the size of thread stacks. -endif +config POSIX_THREAD_PRIO_INHERIT + bool "POSIX mutex priority inheritance" + default y + help + Select 'y' here to enable POSIX mutex priority inheritance. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html + +config POSIX_THREAD_PRIO_PROTECT + bool "POSIX mutex priority protection" + default y + help + Select 'y' here to enable POSIX mutex priority protection. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html + +config POSIX_THREAD_SAFE_FUNCTIONS + bool "POSIX thread-safe functions" + default y + help + Select 'y' here to enable POSIX thread-safe functions including asctime_r(), ctime_r(), + flockfile(), ftrylockfile(), funlockfile(), getc_unlocked(), getchar_unlocked(), + getgrgid_r(), getgrnam_r(), getpwnam_r(), getpwuid_r(), gmtime_r(), localtime_r(), + putc_unlocked(), putchar_unlocked(), rand_r(), readdir_r(), strerror_r(), and strtok_r(). + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html#tag_22_02_09_07 + +module = PTHREAD +module-str = POSIX thread +source "subsys/logging/Kconfig.template.log_config" + +module = PTHREAD_MUTEX +module-str = POSIX mutex +source "subsys/logging/Kconfig.template.log_config" + +module = PTHREAD_COND +module-str = POSIX condition variable +source "subsys/logging/Kconfig.template.log_config" + +module = PTHREAD_KEY +module-str = POSIX thread-specific data +source "subsys/logging/Kconfig.template.log_config" + +endif # POSIX_THREADS diff --git a/lib/posix/options/Kconfig.sched b/lib/posix/options/Kconfig.sched index b5fb3a5dcb1..c6ea53be8f1 100644 --- a/lib/posix/options/Kconfig.sched +++ b/lib/posix/options/Kconfig.sched @@ -4,8 +4,8 @@ config POSIX_PRIORITY_SCHEDULING bool "Priority scheduling" - default y if PTHREAD + default y if POSIX_THREADS default y if POSIX_API - depends on PTHREAD + depends on POSIX_THREADS help This enables POSIX scheduling APIs (_POSIX_PRIORITY_SCHEDULING). diff --git a/lib/posix/options/Kconfig.template.pooled_ipc_type b/lib/posix/options/Kconfig.template.pooled_ipc_type deleted file mode 100644 index 08d804382e8..00000000000 --- a/lib/posix/options/Kconfig.template.pooled_ipc_type +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2023 Meta -# -# SPDX-License-Identifier: Apache-2.0 - -rsource "Kconfig.template.with_url" - -# Not user configurable (i.e. private for now) -menuconfig $(TYPE) - bool "$(type) support" - depends on PTHREAD_IPC - default y - help - Support for $(TYPE) - For more info, see - $(posix-url-base)/$(type-function).html - -if $(TYPE) - -# eventually, this size should be defaulted to 0 -config MAX_$(TYPE)_COUNT - int "Maximum number of $(type)" - default 5 - depends on $(TYPE) - help - Maximum simultaneously active $(type) in a POSIX application. - -rsource "Kconfig.template.with_logging" - -endif # $(TYPE) diff --git a/lib/posix/options/Kconfig.template.pooled_type b/lib/posix/options/Kconfig.template.pooled_type deleted file mode 100644 index 5a75c2ee890..00000000000 --- a/lib/posix/options/Kconfig.template.pooled_type +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2023 Meta -# -# SPDX-License-Identifier: Apache-2.0 - -rsource "Kconfig.template.with_url" - -# This is mainly for TIMER currently. -menuconfig $(TYPE) - bool "$(type) support" - help - For more info, see - $(posix-url-base)/$(type-function).html - -if $(TYPE) - -# eventually, this size should be defaulted to 0 as a safe value -config MAX_$(TYPE)_COUNT - int "Maximum number of $(type)" - default 5 - help - Maximum simultaneously active $(type) in a POSIX application. - -rsource "Kconfig.template.with_logging" - -endif # $(TYPE) diff --git a/lib/posix/options/Kconfig.template.with_logging b/lib/posix/options/Kconfig.template.with_logging deleted file mode 100644 index f1fc5141e7c..00000000000 --- a/lib/posix/options/Kconfig.template.with_logging +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2023 Meta -# -# SPDX-License-Identifier: Apache-2.0 - -module = $(TYPE) -module-str = $(TYPE) logging -source "subsys/logging/Kconfig.template.log_config" diff --git a/lib/posix/options/Kconfig.template.with_url b/lib/posix/options/Kconfig.template.with_url deleted file mode 100644 index 33e34756ee7..00000000000 --- a/lib/posix/options/Kconfig.template.with_url +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright (c) 2023 Meta -# -# SPDX-License-Identifier: Apache-2.0 - -posix-url-base = https://pubs.opengroup.org/onlinepubs/9699919799 diff --git a/lib/posix/options/Kconfig.xsi b/lib/posix/options/Kconfig.xsi index 9de3628a31f..ac66838b892 100644 --- a/lib/posix/options/Kconfig.xsi +++ b/lib/posix/options/Kconfig.xsi @@ -36,4 +36,14 @@ config XSI_SYSTEM_LOGGING For more information, please see https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html +config XSI_THREADS_EXT + bool "X/Open threads extensions" + default y if POSIX_API + help + This option provides support for pthread_attr_getstack(), pthread_attr_setstack(), + pthread_getconcurrency(), and pthread_setconcurrency(). + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html + endmenu diff --git a/lib/posix/options/key.c b/lib/posix/options/key.c index 5e68381c53b..a7906b8d9f7 100644 --- a/lib/posix/options/key.c +++ b/lib/posix/options/key.c @@ -29,11 +29,11 @@ static struct k_spinlock pthread_key_lock; * perspective of the application). With a linear space, this means that * the theoretical pthread_key_t range is [0,2147483647]. */ -BUILD_ASSERT(CONFIG_MAX_PTHREAD_KEY_COUNT < PTHREAD_OBJ_MASK_INIT, +BUILD_ASSERT(CONFIG_POSIX_THREAD_KEYS_MAX < PTHREAD_OBJ_MASK_INIT, "CONFIG_MAX_PTHREAD_KEY_COUNT is too high"); -static pthread_key_obj posix_key_pool[CONFIG_MAX_PTHREAD_KEY_COUNT]; -SYS_BITARRAY_DEFINE_STATIC(posix_key_bitarray, CONFIG_MAX_PTHREAD_KEY_COUNT); +static pthread_key_obj posix_key_pool[CONFIG_POSIX_THREAD_KEYS_MAX]; +SYS_BITARRAY_DEFINE_STATIC(posix_key_bitarray, CONFIG_POSIX_THREAD_KEYS_MAX); static inline size_t posix_key_to_offset(pthread_key_obj *k) { diff --git a/lib/posix/options/pthread.c b/lib/posix/options/pthread.c index a46cde7614c..8e9e33ad861 100644 --- a/lib/posix/options/pthread.c +++ b/lib/posix/options/pthread.c @@ -86,7 +86,7 @@ static sys_dlist_t posix_thread_q[] = { SYS_DLIST_STATIC_INIT(&posix_thread_q[POSIX_THREAD_RUN_Q]), SYS_DLIST_STATIC_INIT(&posix_thread_q[POSIX_THREAD_DONE_Q]), }; -static struct posix_thread posix_thread_pool[CONFIG_MAX_PTHREAD_COUNT]; +static struct posix_thread posix_thread_pool[CONFIG_POSIX_THREAD_THREADS_MAX]; static struct k_spinlock pthread_pool_lock; static int pthread_concurrency; @@ -123,8 +123,8 @@ static inline enum posix_thread_qid posix_thread_q_get(struct posix_thread *t) * perspective of the application). With a linear space, this means that * the theoretical pthread_t range is [0,2147483647]. */ -BUILD_ASSERT(CONFIG_MAX_PTHREAD_COUNT < PTHREAD_OBJ_MASK_INIT, - "CONFIG_MAX_PTHREAD_COUNT is too high"); +BUILD_ASSERT(CONFIG_POSIX_THREAD_THREADS_MAX < PTHREAD_OBJ_MASK_INIT, + "CONFIG_POSIX_THREAD_THREADS_MAX is too high"); static inline size_t posix_thread_to_offset(struct posix_thread *t) { @@ -148,7 +148,7 @@ struct posix_thread *to_posix_thread(pthread_t pthread) return NULL; } - if (bit >= CONFIG_MAX_PTHREAD_COUNT) { + if (bit >= ARRAY_SIZE(posix_thread_pool)) { LOG_DBG("Invalid pthread (%x)", pthread); return NULL; } @@ -252,8 +252,8 @@ void __z_pthread_cleanup_pop(int execute) static bool is_posix_policy_prio_valid(int priority, int policy) { - if (priority >= sched_get_priority_min(policy) && - priority <= sched_get_priority_max(policy)) { + if (priority >= posix_sched_priority_min(policy) && + priority <= posix_sched_priority_max(policy)) { return true; } @@ -879,7 +879,7 @@ int pthread_setschedprio(pthread_t thread, int prio) int ret; int new_prio = K_LOWEST_APPLICATION_THREAD_PRIO; struct posix_thread *t = NULL; - int policy; + int policy = -1; struct sched_param param; ret = pthread_getschedparam(thread, &policy, ¶m); @@ -1375,7 +1375,7 @@ int pthread_setname_np(pthread_t thread, const char *name) k_tid_t kthread; thread = get_posix_thread_idx(thread); - if (thread >= CONFIG_MAX_PTHREAD_COUNT) { + if (thread >= ARRAY_SIZE(posix_thread_pool)) { return ESRCH; } @@ -1399,7 +1399,7 @@ int pthread_getname_np(pthread_t thread, char *name, size_t len) k_tid_t kthread; thread = get_posix_thread_idx(thread); - if (thread >= CONFIG_MAX_PTHREAD_COUNT) { + if (thread >= ARRAY_SIZE(posix_thread_pool)) { return ESRCH; } @@ -1474,10 +1474,8 @@ int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT static int posix_thread_pool_init(void) { - size_t i; - - for (i = 0; i < CONFIG_MAX_PTHREAD_COUNT; ++i) { - posix_thread_q_set(&posix_thread_pool[i], POSIX_THREAD_READY_Q); + ARRAY_FOR_EACH_PTR(posix_thread_pool, th) { + posix_thread_q_set(th, POSIX_THREAD_READY_Q); } return 0; diff --git a/lib/posix/options/pthread_sched.h b/lib/posix/options/pthread_sched.h index 4a70d081f84..f51d05a985f 100644 --- a/lib/posix/options/pthread_sched.h +++ b/lib/posix/options/pthread_sched.h @@ -7,6 +7,7 @@ #ifndef ZEPHYR_LIB_POSIX_POSIX_PTHREAD_SCHED_H_ #define ZEPHYR_LIB_POSIX_POSIX_PTHREAD_SCHED_H_ +#include #include #include @@ -16,4 +17,27 @@ static inline bool valid_posix_policy(int policy) return policy == SCHED_FIFO || policy == SCHED_RR || policy == SCHED_OTHER; } +static inline int posix_sched_priority_min(int policy) +{ + if (!valid_posix_policy(policy)) { + errno = EINVAL; + return -1; + } + + return 0; +} + +static inline int posix_sched_priority_max(int policy) +{ + if (IS_ENABLED(CONFIG_COOP_ENABLED) && policy == SCHED_FIFO) { + return CONFIG_NUM_COOP_PRIORITIES - 1; + } else if (IS_ENABLED(CONFIG_PREEMPT_ENABLED) && + (policy == SCHED_RR || policy == SCHED_OTHER)) { + return CONFIG_NUM_PREEMPT_PRIORITIES - 1; + } + + errno = EINVAL; + return -1; +} + #endif diff --git a/lib/posix/options/rwlock.c b/lib/posix/options/rwlock.c index c4143a79acb..ef14867b028 100644 --- a/lib/posix/options/rwlock.c +++ b/lib/posix/options/rwlock.c @@ -12,7 +12,7 @@ #include #include -#define CONCURRENT_READER_LIMIT (CONFIG_MAX_PTHREAD_COUNT + 1) +#define CONCURRENT_READER_LIMIT (CONFIG_POSIX_THREAD_THREADS_MAX + 1) struct posix_rwlock { struct k_sem rd_sem; diff --git a/lib/posix/options/sched.c b/lib/posix/options/sched.c index be174d92cd6..a37b01d0106 100644 --- a/lib/posix/options/sched.c +++ b/lib/posix/options/sched.c @@ -16,12 +16,7 @@ */ int sched_get_priority_min(int policy) { - if (!valid_posix_policy(policy)) { - errno = EINVAL; - return -1; - } - - return 0; + return posix_sched_priority_min(policy); } /** @@ -31,15 +26,7 @@ int sched_get_priority_min(int policy) */ int sched_get_priority_max(int policy) { - if (IS_ENABLED(CONFIG_COOP_ENABLED) && policy == SCHED_FIFO) { - return CONFIG_NUM_COOP_PRIORITIES - 1; - } else if (IS_ENABLED(CONFIG_PREEMPT_ENABLED) && - (policy == SCHED_RR || policy == SCHED_OTHER)) { - return CONFIG_NUM_PREEMPT_PRIORITIES - 1; - } - - errno = EINVAL; - return -1; + return posix_sched_priority_max(policy); } /** diff --git a/lib/posix/options/_common.c b/lib/posix/options/timespec_to_timeout.c similarity index 92% rename from lib/posix/options/_common.c rename to lib/posix/options/timespec_to_timeout.c index 8125570f26e..e72956e6e3e 100644 --- a/lib/posix/options/_common.c +++ b/lib/posix/options/timespec_to_timeout.c @@ -8,7 +8,6 @@ #include #include -#ifdef CONFIG_POSIX_TIMERS int64_t timespec_to_timeoutms(const struct timespec *abstime) { int64_t milli_secs, secs, nsecs; @@ -30,4 +29,3 @@ int64_t timespec_to_timeoutms(const struct timespec *abstime) return milli_secs; } -#endif /* CONFIG_POSIX_TIMERS */ diff --git a/modules/Kconfig.simplelink b/modules/Kconfig.simplelink index 843f95c36fa..13b26b1ca1a 100644 --- a/modules/Kconfig.simplelink +++ b/modules/Kconfig.simplelink @@ -7,14 +7,14 @@ config HAS_CC3220SDK # SimpleLink drivers require types (stdint.h) from c library which is not # provided by minimal lbc # Selecting ERRNO lets host driver use Zephyr's __errno -# Selecting PTHREAD_IPC and POSIX_API are needed to build the host driver +# Selecting POSIX_THREADS and POSIX_API are needed to build the host driver config SIMPLELINK_HOST_DRIVER bool "Build the SimpleLink WiFi Host Driver" depends on HAS_CC3220SDK depends on MULTITHREADING select REQUIRES_FULL_LIBC select ERRNO - select PTHREAD_IPC + select POSIX_THREADS select POSIX_TIMERS help Build the SimpleLink host driver diff --git a/samples/posix/philosophers/prj.conf b/samples/posix/philosophers/prj.conf index 0934325aea6..2f8c3da16c3 100644 --- a/samples/posix/philosophers/prj.conf +++ b/samples/posix/philosophers/prj.conf @@ -6,7 +6,7 @@ CONFIG_THREAD_STACK_INFO=y CONFIG_DYNAMIC_THREAD=y CONFIG_DYNAMIC_THREAD_POOL_SIZE=6 -CONFIG_MAX_PTHREAD_COUNT=6 +CONFIG_POSIX_THREAD_THREADS_MAX=6 CONFIG_MAX_PTHREAD_MUTEX_COUNT=6 #Enable thread awareness for debugging tools supporting it diff --git a/samples/posix/philosophers/src/main.c b/samples/posix/philosophers/src/main.c index 29861803aab..bfac15861fd 100644 --- a/samples/posix/philosophers/src/main.c +++ b/samples/posix/philosophers/src/main.c @@ -21,12 +21,12 @@ #define MAX_NAME_LEN 1 #endif -#define NUM_PHIL CONFIG_MAX_PTHREAD_COUNT +#define NUM_PHIL CONFIG_POSIX_THREAD_THREADS_MAX #define obj_init_type "POSIX" #define fork_type_str "mutexes" -BUILD_ASSERT(CONFIG_MAX_PTHREAD_COUNT == CONFIG_MAX_PTHREAD_MUTEX_COUNT); -BUILD_ASSERT(CONFIG_DYNAMIC_THREAD_POOL_SIZE == CONFIG_MAX_PTHREAD_COUNT); +BUILD_ASSERT(CONFIG_POSIX_THREAD_THREADS_MAX == CONFIG_MAX_PTHREAD_MUTEX_COUNT); +BUILD_ASSERT(CONFIG_DYNAMIC_THREAD_POOL_SIZE == CONFIG_POSIX_THREAD_THREADS_MAX); typedef pthread_mutex_t *fork_t; diff --git a/tests/posix/common/prj.conf b/tests/posix/common/prj.conf index 1c99d64cf5a..ff61f29c7b5 100644 --- a/tests/posix/common/prj.conf +++ b/tests/posix/common/prj.conf @@ -1,6 +1,5 @@ -CONFIG_PTHREAD_IPC=y CONFIG_POSIX_API=y -CONFIG_MAX_PTHREAD_COUNT=6 +CONFIG_POSIX_THREAD_THREADS_MAX=6 CONFIG_ZTEST=y CONFIG_POSIX_SEM_VALUE_MAX=32767 CONFIG_POSIX_MESSAGE_PASSING=y diff --git a/tests/posix/common/src/key.c b/tests/posix/common/src/key.c index e7486c5327c..e90f4862ff7 100644 --- a/tests/posix/common/src/key.c +++ b/tests/posix/common/src/key.c @@ -117,7 +117,7 @@ ZTEST(key, test_key_resource_leak) { pthread_key_t key; - for (size_t i = 0; i < CONFIG_MAX_PTHREAD_KEY_COUNT; ++i) { + for (size_t i = 0; i < CONFIG_POSIX_THREAD_KEYS_MAX; ++i) { zassert_ok(pthread_key_create(&key, NULL), "failed to create key %zu", i); zassert_ok(pthread_key_delete(key), "failed to delete key %zu", i); } @@ -126,8 +126,8 @@ ZTEST(key, test_key_resource_leak) ZTEST(key, test_correct_key_is_deleted) { pthread_key_t key; - size_t j = CONFIG_MAX_PTHREAD_KEY_COUNT - 1; - pthread_key_t keys[CONFIG_MAX_PTHREAD_KEY_COUNT]; + size_t j = CONFIG_POSIX_THREAD_KEYS_MAX - 1; + pthread_key_t keys[CONFIG_POSIX_THREAD_KEYS_MAX]; for (size_t i = 0; i < ARRAY_SIZE(keys); ++i) { zassert_ok(pthread_key_create(&keys[i], NULL), "failed to create key %zu", i); diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index 109bcb4e5c8..4fea9ed60ca 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -382,7 +382,7 @@ ZTEST(pthread, test_pthread_descriptor_leak) pthread_t pthread1; /* If we are leaking descriptors, then this loop will never complete */ - for (size_t i = 0; i < CONFIG_MAX_PTHREAD_COUNT * 2; ++i) { + for (size_t i = 0; i < CONFIG_POSIX_THREAD_THREADS_MAX * 2; ++i) { zassert_ok(pthread_create(&pthread1, NULL, create_thread1, NULL), "unable to create thread %zu", i); zassert_ok(pthread_join(pthread1, NULL), "unable to join thread %zu", i); diff --git a/tests/posix/common/src/sysconf.c b/tests/posix/common/src/sysconf.c index 67929759925..363d93be365 100644 --- a/tests/posix/common/src/sysconf.c +++ b/tests/posix/common/src/sysconf.c @@ -22,7 +22,7 @@ ZTEST(posix_apis, test_posix_sysconf) /* SC that value depends on target's configuration */ ret = sysconf(_SC_SEMAPHORES); - if (IS_ENABLED(CONFIG_PTHREAD_IPC)) { + if (IS_ENABLED(CONFIG_POSIX_THREADS)) { zassert_equal(ret, _POSIX_VERSION, "sysconf returned unexpected value %d", diff --git a/tests/posix/headers/prj.conf b/tests/posix/headers/prj.conf index 4a75f1ac46f..cfad8467f38 100644 --- a/tests/posix/headers/prj.conf +++ b/tests/posix/headers/prj.conf @@ -14,7 +14,7 @@ CONFIG_NETWORKING=y CONFIG_NET_SOCKETPAIR=y # for when CONFIG_POSIX_API is not selected -CONFIG_PTHREAD_IPC=y +CONFIG_POSIX_THREADS=y CONFIG_POSIX_FILE_SYSTEM=y CONFIG_POSIX_TIMERS=y CONFIG_POSIX_MESSAGE_PASSING=y diff --git a/tests/posix/pthread_pressure/src/main.c b/tests/posix/pthread_pressure/src/main.c index c7881de4e6f..93484c30234 100644 --- a/tests/posix/pthread_pressure/src/main.c +++ b/tests/posix/pthread_pressure/src/main.c @@ -21,7 +21,7 @@ #endif /* 32 threads is mainly a limitation of find_lsb_set() */ -#define NUM_THREADS MIN(32, MIN(CONFIG_TEST_NUM_CPUS, CONFIG_MAX_PTHREAD_COUNT)) +#define NUM_THREADS MIN(32, MIN(CONFIG_TEST_NUM_CPUS, CONFIG_POSIX_THREAD_THREADS_MAX)) typedef int (*create_fn)(int i); typedef int (*join_fn)(int i);