From 7198c274c300c0ada39811baa83d94b7f1b02b9c Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Mon, 3 Jul 2023 15:15:35 -0400 Subject: [PATCH] posix: split supported features into separate Kconfig files This change is setting up for switching over to proper POSIX option requirements, feature test macros, and a dependency structure that is reflective of the standard. Signed-off-by: Christopher Friedt --- lib/posix/Kconfig | 183 +++------------------ lib/posix/Kconfig.barrier | 24 +++ lib/posix/Kconfig.clock | 10 ++ lib/posix/Kconfig.cond | 9 + lib/posix/Kconfig.eventfd | 21 +++ lib/posix/Kconfig.fnmatch | 10 ++ lib/posix/Kconfig.fs | 18 ++ lib/posix/Kconfig.getopt | 5 + lib/posix/Kconfig.key | 9 + lib/posix/Kconfig.mqueue | 33 ++++ lib/posix/Kconfig.mutex | 9 + lib/posix/Kconfig.pthread | 9 + lib/posix/Kconfig.semaphore | 10 ++ lib/posix/Kconfig.spinlock | 8 + lib/posix/Kconfig.template.pooled_ipc_type | 23 +++ lib/posix/Kconfig.template.pooled_type | 19 +++ lib/posix/Kconfig.template.with_url | 5 + lib/posix/Kconfig.timer | 16 ++ 18 files changed, 260 insertions(+), 161 deletions(-) create mode 100644 lib/posix/Kconfig.barrier create mode 100644 lib/posix/Kconfig.clock create mode 100644 lib/posix/Kconfig.cond create mode 100644 lib/posix/Kconfig.eventfd create mode 100644 lib/posix/Kconfig.fnmatch create mode 100644 lib/posix/Kconfig.fs create mode 100644 lib/posix/Kconfig.getopt create mode 100644 lib/posix/Kconfig.key create mode 100644 lib/posix/Kconfig.mqueue create mode 100644 lib/posix/Kconfig.mutex create mode 100644 lib/posix/Kconfig.pthread create mode 100644 lib/posix/Kconfig.semaphore create mode 100644 lib/posix/Kconfig.spinlock create mode 100644 lib/posix/Kconfig.template.pooled_ipc_type create mode 100644 lib/posix/Kconfig.template.pooled_type create mode 100644 lib/posix/Kconfig.template.with_url create mode 100644 lib/posix/Kconfig.timer diff --git a/lib/posix/Kconfig b/lib/posix/Kconfig index e6d22d90c4af37e..2fcad705d903ed0 100644 --- a/lib/posix/Kconfig +++ b/lib/posix/Kconfig @@ -1,8 +1,8 @@ # Copyright (c) 2018 Intel Corporation +# Copyright (c) 2023 Meta +# # SPDX-License-Identifier: Apache-2.0 -source "lib/posix/getopt/Kconfig" - config POSIX_MAX_FDS int "Maximum number of open file descriptors" default 16 if POSIX_API @@ -18,144 +18,6 @@ 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_CLOCK - help - This enables a mostly-standards-compliant implementation of - the pthread mutex, condition variable and barrier IPC - mechanisms. - -if PTHREAD_IPC -config MAX_PTHREAD_COUNT - int "Maximum simultaneously active pthread count in POSIX application" - default 5 - range 0 255 - help - Maximum number of simultaneously active threads in a POSIX application. - -config PTHREAD_CREATE_BARRIER - bool "Use a pthread_barrier_t to serialize pthread_create()" - help - When running several SMP applications in parallel instances of Qemu, - e.g. via twister, explicit serialization may be required between - pthread_create() and zephyr_thread_wrapper() when spawning and joining - many pthreads concurrently. - - On such systems, say Y here to introduce explicit serialization - via pthread_barrier_wait(). - -config MAX_PTHREAD_MUTEX_COUNT - int "Maximum simultaneously active mutex count in POSIX application" - default 5 - range 0 255 - help - Maximum number of simultaneously active mutexes in a POSIX application. - -config MAX_PTHREAD_COND_COUNT - int "Maximum simultaneously active condition variables in a POSIX application" - default 5 - range 0 255 - help - Maximum number of simultaneously active condition variables in a POSIX application. - -config MAX_PTHREAD_KEY_COUNT - int "Maximum simultaneously active keys in a POSIX application" - default 5 - range 0 255 - help - Maximum number of simultaneously active keys in a POSIX application. - -config MAX_PTHREAD_BARRIER_COUNT - int "Maximum simultaneously active barriers in a POSIX application" - default 5 - range 0 255 - help - Maximum number of simultaneously active keys in a POSIX application. - -config MAX_PTHREAD_SPINLOCK_COUNT - int "Maximum simultaneously active spinlocks in a POSIX application" - default 5 - range 0 255 - help - Maximum number of simultaneously active spinlocks in a POSIX application. - -config SEM_VALUE_MAX - int "Maximum semaphore limit" - default 32767 - range 1 32767 - help - Maximum semaphore count in POSIX compliant Application. - -endif # PTHREAD_IPC - -config POSIX_CLOCK - bool "POSIX clock, timer, and sleep APIs" - default y if POSIX_API - help - This enables POSIX clock\_\*(), timer\_\*(), and \*sleep() - functions. - -config MAX_TIMER_COUNT - int "Maximum timer count in POSIX application" - default 5 - range 0 255 - help - Mention maximum number of timers in POSIX compliant application. - -config TIMER_CREATE_WAIT - int "Time to wait for timer availability (in msec) in POSIX application" - default 100 - range 0 1000 - help - This controls how long to wait for resources to come available to create - a new timer in POSIX compliant application - -config POSIX_MQUEUE - bool "POSIX message queue" - default y if POSIX_API - help - This enabled POSIX message queue related APIs. - -if POSIX_MQUEUE -config MSG_COUNT_MAX - int "Maximum number of messages in message queue" - default 16 - help - Mention maximum number of messages in message queue in POSIX compliant - application. - -config MSG_SIZE_MAX - int "Maximum size of a message" - default 16 - help - Mention maximum size of message in bytes. - -config MQUEUE_NAMELEN_MAX - int "Maximum size of a name length" - default 16 - range 2 255 - help - Mention length of message queue name in number of characters. - -endif - -config POSIX_FS - bool "POSIX file system API support" - default y if POSIX_API - depends on FILE_SYSTEM - help - This enables POSIX style file system related APIs. - -config POSIX_MAX_OPEN_FILES - int "Maximum number of open file descriptors" - default 16 - depends on POSIX_FS - help - Maximum number of open files. Note that this setting - is additionally bounded by CONFIG_POSIX_MAX_FDS. - # The name of this option is mandated by zephyr_interface_library_named # cmake directive. config APP_LINK_WITH_POSIX_SUBSYS @@ -165,27 +27,26 @@ config APP_LINK_WITH_POSIX_SUBSYS help Add POSIX subsystem header files to the 'app' include path. -config EVENTFD - bool "Support for eventfd" - depends on !NATIVE_APPLICATION - select POLL +config PTHREAD_IPC + bool "POSIX pthread IPC API" default y if POSIX_API + depends on POSIX_CLOCK help - Enable support for event file descriptors, eventfd. An eventfd can - be used as an event wait/notify mechanism together with POSIX calls - like read, write and poll. - -config EVENTFD_MAX - int "Maximum number of eventfd's" - depends on EVENTFD - default 1 - range 1 4096 - help - The maximum number of supported event file descriptors. + This enables a mostly-standards-compliant implementation of + the pthread mutex, condition variable and barrier IPC + mechanisms. -config FNMATCH - bool "Support for fnmatch" - default y if POSIX_API - help - Match filenames using the the fnmatch function. For example, the pattern - "*.c" matches the filename "hello.c". +source "lib/posix/Kconfig.barrier" +source "lib/posix/Kconfig.clock" +source "lib/posix/Kconfig.cond" +source "lib/posix/Kconfig.eventfd" +source "lib/posix/Kconfig.fnmatch" +source "lib/posix/Kconfig.fs" +source "lib/posix/Kconfig.getopt" +source "lib/posix/Kconfig.key" +source "lib/posix/Kconfig.mqueue" +source "lib/posix/Kconfig.mutex" +source "lib/posix/Kconfig.pthread" +source "lib/posix/Kconfig.semaphore" +source "lib/posix/Kconfig.spinlock" +source "lib/posix/Kconfig.timer" diff --git a/lib/posix/Kconfig.barrier b/lib/posix/Kconfig.barrier new file mode 100644 index 000000000000000..e14b39c5b08e9cd --- /dev/null +++ b/lib/posix/Kconfig.barrier @@ -0,0 +1,24 @@ +# Copyright (c) 2017 Intel Corporation +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +TYPE = PTHREAD_BARRIER +type = pthread_barrier_t +type-function = pthread_barrier_wait +source "lib/posix/Kconfig.template.pooled_ipc_type" + +if PTHREAD_BARRIER + +config PTHREAD_CREATE_BARRIER + bool "Use a pthread_barrier_t to serialize pthread_create()" + help + When running several SMP applications in parallel instances of Qemu, + e.g. via twister, explicit serialization may be required between + pthread_create() and zephyr_thread_wrapper() when spawning and joining + many pthreads concurrently. + + On such systems, say Y here to introduce explicit serialization + via pthread_barrier_wait(). + +endif diff --git a/lib/posix/Kconfig.clock b/lib/posix/Kconfig.clock new file mode 100644 index 000000000000000..d9767bb391040c6 --- /dev/null +++ b/lib/posix/Kconfig.clock @@ -0,0 +1,10 @@ +# Copyright (c) 2018 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_CLOCK + bool "POSIX clock, timer, and sleep APIs" + default y if POSIX_API + help + This enables POSIX clock\_\*(), timer\_\*(), and \*sleep() + functions. diff --git a/lib/posix/Kconfig.cond b/lib/posix/Kconfig.cond new file mode 100644 index 000000000000000..fcdf842a6027da6 --- /dev/null +++ b/lib/posix/Kconfig.cond @@ -0,0 +1,9 @@ +# 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 +source "lib/posix/Kconfig.template.pooled_ipc_type" diff --git a/lib/posix/Kconfig.eventfd b/lib/posix/Kconfig.eventfd new file mode 100644 index 000000000000000..409f0ba89f670bc --- /dev/null +++ b/lib/posix/Kconfig.eventfd @@ -0,0 +1,21 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +config EVENTFD + bool "Support for eventfd" + depends on !NATIVE_APPLICATION + select POLL + default y if POSIX_API + help + Enable support for event file descriptors, eventfd. An eventfd can + be used as an event wait/notify mechanism together with POSIX calls + like read, write and poll. + +config EVENTFD_MAX + int "Maximum number of eventfd's" + depends on EVENTFD + default 1 + range 1 4096 + help + The maximum number of supported event file descriptors. diff --git a/lib/posix/Kconfig.fnmatch b/lib/posix/Kconfig.fnmatch new file mode 100644 index 000000000000000..81f1a00938f3a46 --- /dev/null +++ b/lib/posix/Kconfig.fnmatch @@ -0,0 +1,10 @@ +# Copyright (c) 2018 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +config FNMATCH + bool "Support for fnmatch" + default y if POSIX_API + help + Match filenames using the the fnmatch function. For example, the pattern + "*.c" matches the filename "hello.c". diff --git a/lib/posix/Kconfig.fs b/lib/posix/Kconfig.fs new file mode 100644 index 000000000000000..6ad72fbcff57750 --- /dev/null +++ b/lib/posix/Kconfig.fs @@ -0,0 +1,18 @@ +# Copyright (c) 2018 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_FS + bool "POSIX file system API support" + default y if POSIX_API + depends on FILE_SYSTEM + help + This enables POSIX style file system related APIs. + +config POSIX_MAX_OPEN_FILES + int "Maximum number of open file descriptors" + default 16 + depends on POSIX_FS + help + Maximum number of open files. Note that this setting + is additionally bounded by CONFIG_POSIX_MAX_FDS. diff --git a/lib/posix/Kconfig.getopt b/lib/posix/Kconfig.getopt new file mode 100644 index 000000000000000..ccd2c37ed56ae9e --- /dev/null +++ b/lib/posix/Kconfig.getopt @@ -0,0 +1,5 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +source "lib/posix/getopt/Kconfig" diff --git a/lib/posix/Kconfig.key b/lib/posix/Kconfig.key new file mode 100644 index 000000000000000..6e8538233eb445a --- /dev/null +++ b/lib/posix/Kconfig.key @@ -0,0 +1,9 @@ +# 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 +source "lib/posix/Kconfig.template.pooled_ipc_type" diff --git a/lib/posix/Kconfig.mqueue b/lib/posix/Kconfig.mqueue new file mode 100644 index 000000000000000..58e04d21fafb50a --- /dev/null +++ b/lib/posix/Kconfig.mqueue @@ -0,0 +1,33 @@ +# Copyright (c) 2017 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_MQUEUE + bool "POSIX message queue" + default y if POSIX_API + help + This enabled POSIX message queue related APIs. + +if POSIX_MQUEUE + +config MSG_COUNT_MAX + int "Maximum number of messages in message queue" + default 16 + help + Mention maximum number of messages in message queue in POSIX compliant + application. + +config MSG_SIZE_MAX + int "Maximum size of a message" + default 16 + help + Mention maximum size of message in bytes. + +config MQUEUE_NAMELEN_MAX + int "Maximum size of a name length" + default 16 + range 2 255 + help + Mention length of message queue name in number of characters. + +endif diff --git a/lib/posix/Kconfig.mutex b/lib/posix/Kconfig.mutex new file mode 100644 index 000000000000000..c34881017e54d16 --- /dev/null +++ b/lib/posix/Kconfig.mutex @@ -0,0 +1,9 @@ +# 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 +source "lib/posix/Kconfig.template.pooled_ipc_type" diff --git a/lib/posix/Kconfig.pthread b/lib/posix/Kconfig.pthread new file mode 100644 index 000000000000000..9b2541c6631bf7f --- /dev/null +++ b/lib/posix/Kconfig.pthread @@ -0,0 +1,9 @@ +# Copyright (c) 2017 Intel Corporation +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +TYPE = PTHREAD +type = pthread_t +type-function = pthread_create +source "lib/posix/Kconfig.template.pooled_ipc_type" diff --git a/lib/posix/Kconfig.semaphore b/lib/posix/Kconfig.semaphore new file mode 100644 index 000000000000000..d9b9b47a5089f8f --- /dev/null +++ b/lib/posix/Kconfig.semaphore @@ -0,0 +1,10 @@ +# Copyright (c) 2018 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +config SEM_VALUE_MAX + int "Maximum semaphore limit" + default 32767 + range 1 32767 + help + Maximum semaphore count in POSIX compliant Application. diff --git a/lib/posix/Kconfig.spinlock b/lib/posix/Kconfig.spinlock new file mode 100644 index 000000000000000..83a95d77ed0b2f3 --- /dev/null +++ b/lib/posix/Kconfig.spinlock @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +TYPE = PTHREAD_SPINLOCK +type = pthread_spinlock_t +type-function = pthread_spin_lock +source "lib/posix/Kconfig.template.pooled_ipc_type" diff --git a/lib/posix/Kconfig.template.pooled_ipc_type b/lib/posix/Kconfig.template.pooled_ipc_type new file mode 100644 index 000000000000000..ad0bf5bc9b04077 --- /dev/null +++ b/lib/posix/Kconfig.template.pooled_ipc_type @@ -0,0 +1,23 @@ +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +source "lib/posix/Kconfig.template.with_url" + +# Not user configurable (i.e. private for now) +config $(TYPE) + bool + default y + depends on PTHREAD_IPC + help + Support for $(TYPE) + For more info, see + $(posix-url-base)/$(type-function).html + +# eventually, this size should be defaulted to 0 +config MAX_$(TYPE)_COUNT + int "Maximum simultaneously active $(type) in POSIX application" + default 5 + depends on $(TYPE) + help + Maximum simultaneously active $(type) in a POSIX application. diff --git a/lib/posix/Kconfig.template.pooled_type b/lib/posix/Kconfig.template.pooled_type new file mode 100644 index 000000000000000..d2699e2f17cd1c9 --- /dev/null +++ b/lib/posix/Kconfig.template.pooled_type @@ -0,0 +1,19 @@ +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +source "lib/posix/Kconfig.template.with_url" + +# This is mainly for TIMER currently. +config $(TYPE) + bool "POSIX $(type) support" + help + For more info, see + $(posix-url-base)/$(type-function).html + +# eventually, this size should be defaulted to 0 as a safe value +config MAX_$(TYPE)_COUNT + int "Maximum simultaneously active $(type) in POSIX application" + default 5 + help + Maximum simultaneously active $(type) in a POSIX application. diff --git a/lib/posix/Kconfig.template.with_url b/lib/posix/Kconfig.template.with_url new file mode 100644 index 000000000000000..33e34756ee71e96 --- /dev/null +++ b/lib/posix/Kconfig.template.with_url @@ -0,0 +1,5 @@ +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +posix-url-base = https://pubs.opengroup.org/onlinepubs/9699919799 diff --git a/lib/posix/Kconfig.timer b/lib/posix/Kconfig.timer new file mode 100644 index 000000000000000..c738064bb106640 --- /dev/null +++ b/lib/posix/Kconfig.timer @@ -0,0 +1,16 @@ +# Copyright (c) 2018 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +TYPE = TIMER +type = timer_t +type-function = timer_create +source "lib/posix/Kconfig.template.pooled_type" + +config TIMER_CREATE_WAIT + int "Time to wait for timer availability (in msec) in POSIX application" + default 100 + range 0 1000 + help + This controls how long to wait for resources to come available to create + a new timer in POSIX compliant application