From 4a5c4e5f73b7e4e71674c63c6018d02762c52855 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Mon, 20 May 2024 12:23:58 -0400 Subject: [PATCH] posix: timers: deprecate CONFIG_POSIX_CLOCK and TIMER The POSIX_CLOCK option does not correspond to any standard option. It was used to active features of several distinct POSIX Options and Option Groups, which complicated API and application configuration as a result. POSIX_CLOCK is being deprecated in order to ensure that Zephyr's POSIX Kconfig variables correspond to those defined in the specification, as of IEEE 1003.1-2017. Additionally, CONFIG_TIMER is being deprecated because it does not match the corresponding POSIX Option (_POSIX_TIMERS). With this deprecation, we introduce the following Kconfig options that map directly to standard POSIX Option Groups by simply removing "CONFIG_": * CONFIG_POSIX_TIMERS Similarly, we introduce the following Kconfig options that map directly to standard POSIX Options by simply removing "CONFIG": * CONFIG_POSIX_CLOCK_SELECTION * CONFIG_POSIX_CPUTIME * CONFIG_POSIX_DELAYTIMER_MAX * CONFIG_POSIX_MONOTONIC_CLOCK * CONFIG_POSIX_TIMEOUTS * CONFIG_POSIX_TIMER_MAX In order to maintain parity with the current feature set, we introduce the following Kconfig options that map directly to standard POSIX Option Groups by simply removing "CONFIG_": * CONFIG_POSIX_MULTI_PROCESS - sleep() Similarly, in order to maintain parity with the current feature set, we introduce the following additional Kconfig options that map directly to standard POSIX Options by simply removing "CONFIG": * CONFIG_XSI_SINGLE_PROCESS - gettimeofday() Signed-off-by: Chris Friedt --- cmake/toolchain/armclang/Kconfig | 2 +- doc/connectivity/networking/api/lwm2m.rst | 2 +- doc/services/portability/posix/aep/index.rst | 6 +- .../portability/posix/conformance/index.rst | 12 +- .../portability/posix/kconfig/index.rst | 4 +- .../portability/posix/option_groups/index.rst | 11 ++ include/zephyr/posix/posix_features.h | 17 +-- include/zephyr/posix/sys/sysconf.h | 118 ++++++++++-------- include/zephyr/posix/time.h | 4 + lib/libc/minimal/Kconfig | 4 +- lib/libc/newlib/libc-hooks.c | 2 +- lib/posix/options/CMakeLists.txt | 13 +- lib/posix/options/Kconfig | 8 +- lib/posix/options/Kconfig.clock | 11 -- lib/posix/options/Kconfig.deprecated | 40 ++++++ lib/posix/options/Kconfig.procN | 16 +++ lib/posix/options/Kconfig.timer | 99 +++++++++++++-- lib/posix/options/Kconfig.xsi | 16 +++ lib/posix/options/_common.c | 4 +- lib/posix/options/clock.c | 45 ++++++- lib/posix/options/nanosleep.c | 24 ---- lib/posix/options/sleep.c | 24 ---- lib/posix/options/timer.c | 8 +- modules/Kconfig.simplelink | 2 +- modules/hostap/Kconfig | 2 +- samples/net/cloud/aws_iot_mqtt/prj.conf | 1 - .../shell/shell_module/overlay-usb.conf | 6 +- samples/subsys/shell/shell_module/prj.conf | 2 +- .../subsys/shell/shell_module/prj_getopt.conf | 2 +- .../subsys/shell/shell_module/prj_login.conf | 2 +- subsys/logging/Kconfig.processing | 2 +- subsys/net/lib/lwm2m/Kconfig | 2 +- subsys/shell/modules/Kconfig | 2 +- tests/lib/time/prj.conf | 2 +- tests/posix/common/src/uname.c | 4 +- tests/posix/headers/prj.conf | 2 +- 36 files changed, 343 insertions(+), 178 deletions(-) delete mode 100644 lib/posix/options/Kconfig.clock create mode 100644 lib/posix/options/Kconfig.procN create mode 100644 lib/posix/options/Kconfig.xsi delete mode 100644 lib/posix/options/nanosleep.c diff --git a/cmake/toolchain/armclang/Kconfig b/cmake/toolchain/armclang/Kconfig index 27be295057c..70b9b2bd152 100644 --- a/cmake/toolchain/armclang/Kconfig +++ b/cmake/toolchain/armclang/Kconfig @@ -16,7 +16,7 @@ choice LIBC_IMPLEMENTATION config ARMCLANG_STD_LIBC bool "ARM Compiler C library" select COMMON_LIBC_STRNLEN - select COMMON_LIBC_TIME if POSIX_CLOCK + select COMMON_LIBC_TIME if POSIX_TIMERS help Use the full Arm Compiler runtime libraries. A reduced Zephyr minimal libc will be used for library functionality diff --git a/doc/connectivity/networking/api/lwm2m.rst b/doc/connectivity/networking/api/lwm2m.rst index 8aab68e54ca..b340166fbff 100644 --- a/doc/connectivity/networking/api/lwm2m.rst +++ b/doc/connectivity/networking/api/lwm2m.rst @@ -521,7 +521,7 @@ engine. Data caches depends on one of the SenML data formats :kconfig:option:`CONFIG_LWM2M_RW_SENML_CBOR_SUPPORT` or -:kconfig:option:`CONFIG_LWM2M_RW_SENML_JSON_SUPPORT` and needs :kconfig:option:`CONFIG_POSIX_CLOCK` +:kconfig:option:`CONFIG_LWM2M_RW_SENML_JSON_SUPPORT` and needs :kconfig:option:`CONFIG_POSIX_TIMERS` so it can request a timestamp from the system and :kconfig:option:`CONFIG_RING_BUFFER` for ring buffer. diff --git a/doc/services/portability/posix/aep/index.rst b/doc/services/portability/posix/aep/index.rst index a8f214ef2aa..e1f9859e263 100644 --- a/doc/services/portability/posix/aep/index.rst +++ b/doc/services/portability/posix/aep/index.rst @@ -63,12 +63,12 @@ The *Minimal Realtime System Profile* (PSE51) includes all of the :ref:`_POSIX_FSYNC `, 200809L, :kconfig:option:`CONFIG_POSIX_FSYNC` :ref:`_POSIX_MEMLOCK `, -1, :ref:`_POSIX_MEMLOCK_RANGE `, -1, - :ref:`_POSIX_MONOTONIC_CLOCK `, 200809L, :kconfig:option:`CONFIG_POSIX_CLOCK` + :ref:`_POSIX_MONOTONIC_CLOCK `, 200809L, :kconfig:option:`CONFIG_POSIX_MONOTONIC_CLOCK` :ref:`_POSIX_SHARED_MEMORY_OBJECTS `, -1, :ref:`_POSIX_SYNCHRONIZED_IO `, -1, :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_PTHREAD` - :ref:`_POSIX_THREAD_CPUTIME `, -1, + :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` @@ -150,7 +150,7 @@ The *Dedicated Realtime System Profile* (PSE53) includes all features from PSE52 :header: Symbol, Support, Remarks :widths: 50, 10, 50 - _POSIX_CPUTIME, -1, + :ref:`_POSIX_CPUTIME `, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` _POSIX_PRIORITIZED_IO, -1, :ref:`_POSIX_PRIORITY_SCHEDULING `, -1, _POSIX_RAW_SOCKETS, 200809L, :kconfig:option:`CONFIG_NET_SOCKETS_PACKET` diff --git a/doc/services/portability/posix/conformance/index.rst b/doc/services/portability/posix/conformance/index.rst index 69e77eed89c..dffc1c5ec07 100644 --- a/doc/services/portability/posix/conformance/index.rst +++ b/doc/services/portability/posix/conformance/index.rst @@ -63,7 +63,7 @@ POSIX System Interfaces _POSIX_VERSION, 200809L, :ref:`_POSIX_ASYNCHRONOUS_IO`, 200809L, :ref:`†` :ref:`_POSIX_BARRIERS`, 200809L, :kconfig:option:`CONFIG_PTHREAD_BARRIER` - :ref:`_POSIX_CLOCK_SELECTION`, 200809L, :kconfig:option:`CONFIG_POSIX_CLOCK` + :ref:`_POSIX_CLOCK_SELECTION`, 200809L, :kconfig:option:`CONFIG_POSIX_CLOCK_SELECTION` _POSIX_MAPPED_FILES, -1, :ref:`†` _POSIX_MEMORY_PROTECTION, -1, :ref:`†` :ref:`_POSIX_READER_WRITER_LOCKS`, 200809L, :kconfig:option:`CONFIG_PTHREAD_IPC` @@ -72,8 +72,8 @@ POSIX System Interfaces :ref:`_POSIX_SPIN_LOCKS`, 200809L, :kconfig:option:`CONFIG_PTHREAD_SPINLOCK` :ref:`_POSIX_THREAD_SAFE_FUNCTIONS`, -1, :ref:`_POSIX_THREADS`, -1, :kconfig:option:`CONFIG_PTHREAD_IPC` - :ref:`_POSIX_TIMEOUTS`, 200809L, :kconfig:option:`CONFIG_PTHREAD_IPC` - :ref:`_POSIX_TIMERS`, 200809L, :kconfig:option:`CONFIG_POSIX_CLOCK` + :ref:`_POSIX_TIMEOUTS`, 200809L, :kconfig:option:`CONFIG_POSIX_TIMEOUTS` + :ref:`_POSIX_TIMERS`, 200809L, :kconfig:option:`CONFIG_POSIX_TIMERS` _POSIX2_C_BIND, 200809L, .. csv-table:: POSIX System Interfaces (Optional) @@ -81,13 +81,13 @@ POSIX System Interfaces :widths: 50, 10, 50 _POSIX_ADVISORY_INFO, -1, - _POSIX_CPUTIME, 200809L, :kconfig:option:`CONFIG_POSIX_CLOCK` + :ref:`_POSIX_CPUTIME`, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` :ref:`_POSIX_FSYNC`, 200809L, :kconfig:option:`CONFIG_POSIX_FSYNC` _POSIX_IPV6, 200809L, :kconfig:option:`CONFIG_NET_IPV6` _POSIX_MEMLOCK, -1, _POSIX_MEMLOCK_RANGE, -1, :ref:`_POSIX_MESSAGE_PASSING`, 200809L, :kconfig:option:`CONFIG_POSIX_MQUEUE` - :ref:`_POSIX_MONOTONIC_CLOCK`, 200809L, :kconfig:option:`CONFIG_POSIX_CLOCK` + :ref:`_POSIX_MONOTONIC_CLOCK`, 200809L, :kconfig:option:`CONFIG_POSIX_MONOTONIC_CLOCK` _POSIX_PRIORITIZED_IO, -1, :ref:`_POSIX_PRIORITY_SCHEDULING`, 200809L, :kconfig:option:`CONFIG_POSIX_PRIORITY_SCHEDULING` _POSIX_RAW_SOCKETS, 200809L, :kconfig:option:`CONFIG_NET_SOCKETS_PACKET` @@ -97,7 +97,7 @@ POSIX System Interfaces _POSIX_SYNCHRONIZED_IO, -1, :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_PTHREAD` - _POSIX_THREAD_CPUTIME, -1, + :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` diff --git a/doc/services/portability/posix/kconfig/index.rst b/doc/services/portability/posix/kconfig/index.rst index 9263ba0bd6b..1864070fd78 100644 --- a/doc/services/portability/posix/kconfig/index.rst +++ b/doc/services/portability/posix/kconfig/index.rst @@ -17,7 +17,6 @@ implementation of the POSIX API. * :kconfig:option:`CONFIG_MAX_PTHREAD_KEY_COUNT` * :kconfig:option:`CONFIG_MAX_PTHREAD_MUTEX_COUNT` * :kconfig:option:`CONFIG_MAX_PTHREAD_SPINLOCK_COUNT` -* :kconfig:option:`CONFIG_MAX_TIMER_COUNT` * :kconfig:option:`CONFIG_MQUEUE_NAMELEN_MAX` * :kconfig:option:`CONFIG_MSG_COUNT_MAX` * :kconfig:option:`CONFIG_MSG_SIZE_MAX` @@ -25,7 +24,6 @@ implementation of the POSIX API. * :kconfig:option:`CONFIG_NET_SOCKETS` * :kconfig:option:`CONFIG_NET_SOCKETS_POLL_MAX` * :kconfig:option:`CONFIG_POSIX_API` -* :kconfig:option:`CONFIG_POSIX_CLOCK` * :kconfig:option:`CONFIG_POSIX_FS` * :kconfig:option:`CONFIG_POSIX_MAX_FDS` * :kconfig:option:`CONFIG_POSIX_MAX_OPEN_FILES` @@ -46,4 +44,4 @@ implementation of the POSIX API. * :kconfig:option:`CONFIG_PTHREAD_RECYCLER_DELAY_MS` * :kconfig:option:`CONFIG_PTHREAD_SPINLOCK` * :kconfig:option:`CONFIG_SEM_VALUE_MAX` -* :kconfig:option:`CONFIG_TIMER` +* :kconfig:option:`CONFIG_TIMER_CREATE_WAIT` diff --git a/doc/services/portability/posix/option_groups/index.rst b/doc/services/portability/posix/option_groups/index.rst index e284af76d02..00a5c34ad4f 100644 --- a/doc/services/portability/posix/option_groups/index.rst +++ b/doc/services/portability/posix/option_groups/index.rst @@ -543,6 +543,17 @@ _POSIX_ASYNCHRONOUS_IO aio_write(),yes (will fail with ``ENOSYS``:ref:`†`) lio_listio(),yes (will fail with ``ENOSYS``:ref:`†`) +.. _posix_option_cputime: + +_POSIX_CPUTIME +++++++++++++++ + +.. csv-table:: _POSIX_CPUTIME + :header: API, Supported + :widths: 50,10 + + CLOCK_PROCESS_CPUTIME_ID,yes + .. _posix_option_fsync: _POSIX_FSYNC diff --git a/include/zephyr/posix/posix_features.h b/include/zephyr/posix/posix_features.h index 09af5d3e6c5..1b47289e2e4 100644 --- a/include/zephyr/posix/posix_features.h +++ b/include/zephyr/posix/posix_features.h @@ -31,11 +31,13 @@ #define _POSIX_BARRIERS _POSIX_VERSION #endif -#ifdef CONFIG_POSIX_CLOCK +#ifdef CONFIG_POSIX_CLOCK_SELECTION #define _POSIX_CLOCK_SELECTION _POSIX_VERSION #endif -/* #define _POSIX_CPUTIME (-1L) */ +#ifdef CONFIG_POSIX_CPUTIME +#define _POSIX_CPUTIME _POSIX_VERSION +#endif #ifdef CONFIG_POSIX_FSYNC #define _POSIX_FSYNC _POSIX_VERSION @@ -55,7 +57,7 @@ #define _POSIX_MESSAGE_PASSING _POSIX_VERSION #endif -#ifdef CONFIG_POSIX_CLOCK +#ifdef CONFIG_POSIX_MONOTONIC_CLOCK #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION #endif @@ -100,7 +102,9 @@ #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION #endif -/* #define _POSIX_THREAD_CPUTIME (-1L) */ +#ifdef CONFIG_POSIX_THREAD_CPUTIME +#define _POSIX_THREAD_CPUTIME _POSIX_VERSION +#endif #ifdef CONFIG_PTHREAD_IPC #define _POSIX_THREAD_PRIO_INHERIT _POSIX_VERSION @@ -124,11 +128,11 @@ #endif #endif -#ifdef CONFIG_POSIX_CLOCK +#ifdef CONFIG_POSIX_TIMEOUTS #define _POSIX_TIMEOUTS _POSIX_VERSION #endif -#ifdef CONFIG_POSIX_CLOCK +#ifdef CONFIG_POSIX_TIMERS #define _POSIX_TIMERS _POSIX_VERSION #endif @@ -161,7 +165,6 @@ #define _POSIX2_C_BIND _POSIX2_VERSION #define _POSIX2_C_DEV _POSIX2_VERSION /* #define _POSIX2_CHAR_TERM (-1L) */ -/* #define _POSIX2_DELAYTIMER_MAX (-1L) */ /* #define _POSIX2_FORT_DEV (-1L) */ /* #define _POSIX2_FORT_RUN (-1L) */ /* #define _POSIX2_LOCALEDEF (-1L) */ diff --git a/include/zephyr/posix/sys/sysconf.h b/include/zephyr/posix/sys/sysconf.h index b96e3b4da4d..37f7ba2386b 100644 --- a/include/zephyr/posix/sys/sysconf.h +++ b/include/zephyr/posix/sys/sysconf.h @@ -141,55 +141,73 @@ enum { _SC_TZNAME_MAX, }; -#define __z_posix_sysconf_SC_ADVISORY_INFO _POSIX_ADVISORY_INFO -#define __z_posix_sysconf_SC_ASYNCHRONOUS_IO _POSIX_ASYNCHRONOUS_IO -#define __z_posix_sysconf_SC_BARRIERS _POSIX_BARRIERS -#define __z_posix_sysconf_SC_CLOCK_SELECTION _POSIX_CLOCK_SELECTION -#define __z_posix_sysconf_SC_CPUTIME _POSIX_CPUTIME -#define __z_posix_sysconf_SC_FSYNC _POSIX_FSYNC -#define __z_posix_sysconf_SC_IPV6 _POSIX_IPV6 -#define __z_posix_sysconf_SC_JOB_CONTROL _POSIX_JOB_CONTROL -#define __z_posix_sysconf_SC_MAPPED_FILES _POSIX_MAPPED_FILES -#define __z_posix_sysconf_SC_MEMLOCK _POSIX_MEMLOCK -#define __z_posix_sysconf_SC_MEMLOCK_RANGE _POSIX_MEMLOCK_RANGE -#define __z_posix_sysconf_SC_MEMORY_PROTECTION _POSIX_MEMORY_PROTECTION -#define __z_posix_sysconf_SC_MESSAGE_PASSING _POSIX_MESSAGE_PASSING -#define __z_posix_sysconf_SC_MONOTONIC_CLOCK _POSIX_MONOTONIC_CLOCK -#define __z_posix_sysconf_SC_PRIORITIZED_IO _POSIX_PRIORITIZED_IO -#define __z_posix_sysconf_SC_PRIORITY_SCHEDULING _POSIX_PRIORITY_SCHEDULING -#define __z_posix_sysconf_SC_RAW_SOCKETS _POSIX_RAW_SOCKETS -#define __z_posix_sysconf_SC_RE_DUP_MAX _POSIX_RE_DUP_MAX -#define __z_posix_sysconf_SC_READER_WRITER_LOCKS _POSIX_READER_WRITER_LOCKS -#define __z_posix_sysconf_SC_REALTIME_SIGNALS _POSIX_REALTIME_SIGNALS -#define __z_posix_sysconf_SC_REGEXP _POSIX_REGEXP -#define __z_posix_sysconf_SC_SAVED_IDS _POSIX_SAVED_IDS -#define __z_posix_sysconf_SC_SEMAPHORES _POSIX_SEMAPHORES -#define __z_posix_sysconf_SC_SHARED_MEMORY_OBJECTS _POSIX_SHARED_MEMORY_OBJECTS -#define __z_posix_sysconf_SC_SHELL _POSIX_SHELL -#define __z_posix_sysconf_SC_SPAWN _POSIX_SPAWN -#define __z_posix_sysconf_SC_SPIN_LOCKS _POSIX_SPIN_LOCKS -#define __z_posix_sysconf_SC_SPORADIC_SERVER _POSIX_SPORADIC_SERVER -#define __z_posix_sysconf_SC_SS_REPL_MAX _POSIX_SS_REPL_MAX -#define __z_posix_sysconf_SC_SYNCHRONIZED_IO _POSIX_SYNCHRONIZED_IO -#define __z_posix_sysconf_SC_THREAD_ATTR_STACKADDR _POSIX_THREAD_ATTR_STACKADDR -#define __z_posix_sysconf_SC_THREAD_ATTR_STACKSIZE _POSIX_THREAD_ATTR_STACKSIZE -#define __z_posix_sysconf_SC_THREAD_CPUTIME _POSIX_THREAD_CPUTIME -#define __z_posix_sysconf_SC_THREAD_PRIO_INHERIT _POSIX_THREAD_PRIO_INHERIT -#define __z_posix_sysconf_SC_THREAD_PRIO_PROTECT _POSIX_THREAD_PRIO_PROTECT -#define __z_posix_sysconf_SC_THREAD_PRIORITY_SCHEDULING _POSIX_THREAD_PRIORITY_SCHEDULING -#define __z_posix_sysconf_SC_THREAD_PROCESS_SHARED _POSIX_THREAD_PROCESS_SHARED -#define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_INHERIT _POSIX_THREAD_ROBUST_PRIO_INHERIT -#define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_PROTECT _POSIX_THREAD_ROBUST_PRIO_PROTECT -#define __z_posix_sysconf_SC_THREAD_SAFE_FUNCTIONS _POSIX_THREAD_SAFE_FUNCTIONS -#define __z_posix_sysconf_SC_THREAD_SPORADIC_SERVER _POSIX_THREAD_SPORADIC_SERVER -#define __z_posix_sysconf_SC_THREADS _POSIX_THREADS -#define __z_posix_sysconf_SC_TIMEOUTS _POSIX_TIMEOUTS -#define __z_posix_sysconf_SC_TIMERS _POSIX_TIMERS -#define __z_posix_sysconf_SC_TRACE _POSIX_TRACE -#define __z_posix_sysconf_SC_TRACE_EVENT_FILTER _POSIX_TRACE_EVENT_FILTER -#define __z_posix_sysconf_SC_TRACE_EVENT_NAME_MAX _POSIX_TRACE_EVENT_NAME_MAX -#define __z_posix_sysconf_SC_TRACE_INHERIT _POSIX_TRACE_INHERIT -#define __z_posix_sysconf_SC_TRACE_LOG _POSIX_TRACE_LOG +#define __z_posix_sysconf_SC_ADVISORY_INFO (-1L) +#define __z_posix_sysconf_SC_ASYNCHRONOUS_IO \ + COND_CODE_1(CONFIG_POSIX_ASYNCHRONOUS_IO, (_POSIX_ASYNCHRONOUS_IO), (-1L)) +#define __z_posix_sysconf_SC_BARRIERS COND_CODE_1(CONFIG_PTHREAD_BARRIER, (_POSIX_BARRIERS), (-1L)) +#define __z_posix_sysconf_SC_CLOCK_SELECTION \ + COND_CODE_1(CONFIG_POSIX_CLOCK_SELECTION, (_POSIX_CLOCK_SELECTION), (-1L)) +#define __z_posix_sysconf_SC_CPUTIME \ + COND_CODE_1(CONFIG_POSIX_CPUTIME, (_POSIX_CPUTIME), (-1L)) +#define __z_posix_sysconf_SC_FSYNC \ + COND_CODE_1(CONFIG_POSIX_FSYNC, (_POSIX_FSYNC), (-1L)) +#define __z_posix_sysconf_SC_IPV6 COND_CODE_1(CONFIG_NET_IPV6, (_POSIX_IPV6), (-1L)) +#define __z_posix_sysconf_SC_JOB_CONTROL (-1L) +#define __z_posix_sysconf_SC_MAPPED_FILES (-1L) +#define __z_posix_sysconf_SC_MEMLOCK (-1L) +#define __z_posix_sysconf_SC_MEMLOCK_RANGE (-1L) +#define __z_posix_sysconf_SC_MEMORY_PROTECTION (-1L) +#define __z_posix_sysconf_SC_MESSAGE_PASSING \ + COND_CODE_1(CONFIG_POSIX_MQUEUE, (_POSIX_MESSAGE_PASSING), (-1L)) +#define __z_posix_sysconf_SC_MONOTONIC_CLOCK \ + COND_CODE_1(CONFIG_POSIX_MONOTONIC_CLOCK, (_POSIX_MONOTONIC_CLOCK), (-1L)) +#define __z_posix_sysconf_SC_PRIORITIZED_IO (-1L) +#define __z_posix_sysconf_SC_PRIORITY_SCHEDULING \ + COND_CODE_1(CONFIG_POSIX_PRIORITY_SCHEDULING, (_POSIX_PRIORITY_SCHEDULING), (-1L)) +#define __z_posix_sysconf_SC_RAW_SOCKETS \ + COND_CODE_1(CONFIG_NET_SOCKETS_PACKET, (_POSIX_RAW_SOCKETS), (-1L)) +#define __z_posix_sysconf_SC_RE_DUP_MAX _POSIX_RE_DUP_MAX +#define __z_posix_sysconf_SC_READER_WRITER_LOCKS \ + COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_READER_WRITER_LOCKS), (-1L)) +#define __z_posix_sysconf_SC_REALTIME_SIGNALS (-1L) +#define __z_posix_sysconf_SC_REGEXP (-1L) +#define __z_posix_sysconf_SC_SAVED_IDS (-1L) +#define __z_posix_sysconf_SC_SEMAPHORES \ + COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_SEMAPHORES), (-1L)) +#define __z_posix_sysconf_SC_SHARED_MEMORY_OBJECTS (-1L) +#define __z_posix_sysconf_SC_SHELL (-1L) +#define __z_posix_sysconf_SC_SPAWN (-1L) +#define __z_posix_sysconf_SC_SPIN_LOCKS \ + COND_CODE_1(CONFIG_PTHREAD_SPINLOCK, (_POSIX_SPIN_LOCKS), (-1L)) +#define __z_posix_sysconf_SC_SPORADIC_SERVER (-1L) +#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)) +#define __z_posix_sysconf_SC_THREAD_ATTR_STACKSIZE \ + COND_CODE_1(CONFIG_PTHREAD_IPC, (_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)) +#define __z_posix_sysconf_SC_THREAD_PRIO_PROTECT (-1L) +#define __z_posix_sysconf_SC_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)) +#define __z_posix_sysconf_SC_THREAD_SPORADIC_SERVER (-1L) +#define __z_posix_sysconf_SC_THREADS \ + COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREADS), (-1L)) +#define __z_posix_sysconf_SC_TIMEOUTS \ + COND_CODE_1(CONFIG_POSIX_TIMEOUTS, (_POSIX_TIMEOUTS), (-1L)) +#define __z_posix_sysconf_SC_TIMERS \ + COND_CODE_1(CONFIG_POSIX_TIMEOUTS, (_POSIX_TIMERS), (-1)) +#define __z_posix_sysconf_SC_TRACE (-1L) +#define __z_posix_sysconf_SC_TRACE_EVENT_FILTER (-1L) +#define __z_posix_sysconf_SC_TRACE_EVENT_NAME_MAX _POSIX_TRACE_NAME_MAX +#define __z_posix_sysconf_SC_TRACE_INHERIT (-1L) +#define __z_posix_sysconf_SC_TRACE_LOG (-1L) #define __z_posix_sysconf_SC_TRACE_NAME_MAX _POSIX_TRACE_NAME_MAX #define __z_posix_sysconf_SC_TRACE_SYS_MAX _POSIX_TRACE_SYS_MAX #define __z_posix_sysconf_SC_TRACE_USER_EVENT_MAX _POSIX_TRACE_USER_EVENT_MAX @@ -211,7 +229,7 @@ enum { #define __z_posix_sysconf_SC_2_C_DEV _POSIX2_C_DEV #define __z_posix_sysconf_SC_2_CHAR_TERM (-1L) #define __z_posix_sysconf_SC_COLL_WEIGHTS_MAX _POSIX2_COLL_WEIGHTS_MAX -#define __z_posix_sysconf_SC_DELAYTIMER_MAX _POSIX2_DELAYTIMER_MAX +#define __z_posix_sysconf_SC_DELAYTIMER_MAX _POSIX_DELAYTIMER_MAX #define __z_posix_sysconf_SC_EXPR_NEST_MAX _POSIX2_EXPR_NEST_MAX #define __z_posix_sysconf_SC_2_FORT_DEV (-1L) #define __z_posix_sysconf_SC_2_FORT_RUN (-1L) diff --git a/include/zephyr/posix/time.h b/include/zephyr/posix/time.h index 8038e783030..7ab60987757 100644 --- a/include/zephyr/posix/time.h +++ b/include/zephyr/posix/time.h @@ -73,6 +73,10 @@ extern "C" { #define CLOCK_PROCESS_CPUTIME_ID 2 #endif +#ifndef CLOCK_THREAD_CPUTIME_ID +#define CLOCK_THREAD_CPUTIME_ID 3 +#endif + #ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC 4 #endif diff --git a/lib/libc/minimal/Kconfig b/lib/libc/minimal/Kconfig index d7bc50c4157..a55bf7a87b2 100644 --- a/lib/libc/minimal/Kconfig +++ b/lib/libc/minimal/Kconfig @@ -78,13 +78,13 @@ config MINIMAL_LIBC_RAND config MINIMAL_LIBC_TIME bool "Time functions" - select COMMON_LIBC_TIME if POSIX_CLOCK + select COMMON_LIBC_TIME if POSIX_TIMERS select COMMON_LIBC_GMTIME_R default y help Enable time() and gmtime_r() for the minimal libc. - time() requires CONFIG_POSIX_CLOCK=y because it relies on the POSIX + time() requires CONFIG_POSIX_TIMERS=y because it relies on the POSIX clock_gettime() function. In order to make use of the non-reentrant gmtime(), it is necessary diff --git a/lib/libc/newlib/libc-hooks.c b/lib/libc/newlib/libc-hooks.c index 75a2859fb42..73137d8e4f7 100644 --- a/lib/libc/newlib/libc-hooks.c +++ b/lib/libc/newlib/libc-hooks.c @@ -565,7 +565,7 @@ void *_sbrk_r(struct _reent *r, int count) int _gettimeofday(struct timeval *__tp, void *__tzp) { -#ifdef CONFIG_POSIX_CLOCK +#ifdef CONFIG_XSI_SINGLE_PROCESS return gettimeofday(__tp, __tzp); #else /* Non-posix systems should not call gettimeofday() here as it will diff --git a/lib/posix/options/CMakeLists.txt b/lib/posix/options/CMakeLists.txt index 96995cbeebb..2c8ebe8f202 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_CLOCK OR +if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_TIMERS OR CONFIG_POSIX_MQUEUE OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_GETOPT) # This is a temporary workaround so that Newlib declares the appropriate # types for us. POSIX features to be formalized as part of #51211 @@ -39,18 +39,22 @@ zephyr_library_sources_ifdef(CONFIG_FNMATCH fnmatch.c) zephyr_library_sources_ifdef(CONFIG_GETENTROPY getentropy.c) zephyr_library_sources_ifdef(CONFIG_POSIX_API perror.c) zephyr_library_sources_ifdef(CONFIG_POSIX_ASYNCHRONOUS_IO aio.c) -zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK clock.c) -zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK nanosleep.c) -zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK sleep.c) zephyr_library_sources_ifdef(CONFIG_POSIX_CONFSTR confstr.c) zephyr_library_sources_ifdef(CONFIG_POSIX_ENV env.c) zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c) zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_MULTI_PROCESS + sleep.c +) zephyr_library_sources_ifdef(CONFIG_POSIX_NETWORKING net.c) zephyr_library_sources_ifdef(CONFIG_POSIX_PUTMSG stropts.c) zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNAL signal.c ${STRSIGNAL_TABLE_H}) zephyr_library_sources_ifdef(CONFIG_POSIX_SYSCONF_IMPL_FULL sysconf.c) zephyr_library_sources_ifdef(CONFIG_POSIX_SYSLOG syslog.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS + clock.c + timer.c +) zephyr_library_sources_ifdef(CONFIG_POSIX_UNAME uname.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC _common.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_BARRIER barrier.c) @@ -62,7 +66,6 @@ zephyr_library_sources_ifdef(CONFIG_PTHREAD_RWLOCK rwlock.c) zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_SPINLOCK spinlock.c) -zephyr_library_sources_ifdef(CONFIG_TIMER timer.c) zephyr_library_include_directories( ${ZEPHYR_BASE}/kernel/include diff --git a/lib/posix/options/Kconfig b/lib/posix/options/Kconfig index 8c49debe2a8..60993872f3d 100644 --- a/lib/posix/options/Kconfig +++ b/lib/posix/options/Kconfig @@ -14,21 +14,17 @@ config POSIX_API Enable mostly-standards-compliant implementations of various POSIX (IEEE 1003.1) APIs. -if POSIX_CLOCK - 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. -endif # POSIX_CLOCK - rsource "Kconfig.aio" rsource "Kconfig.barrier" -rsource "Kconfig.clock" rsource "Kconfig.cond" rsource "Kconfig.confstr" rsource "Kconfig.env" @@ -42,6 +38,7 @@ rsource "Kconfig.key" rsource "Kconfig.mqueue" rsource "Kconfig.mutex" rsource "Kconfig.net" +rsource "Kconfig.procN" rsource "Kconfig.pthread" rsource "Kconfig.rwlock" rsource "Kconfig.sched" @@ -53,6 +50,7 @@ rsource "Kconfig.sysconf" rsource "Kconfig.syslog" rsource "Kconfig.timer" rsource "Kconfig.uname" +rsource "Kconfig.xsi" rsource "Kconfig.deprecated" diff --git a/lib/posix/options/Kconfig.clock b/lib/posix/options/Kconfig.clock deleted file mode 100644 index 0d541c9f32f..00000000000 --- a/lib/posix/options/Kconfig.clock +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) 2018 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -config POSIX_CLOCK - bool "clock and sleep APIs" - default y if POSIX_API - imply TIMER - depends on !NATIVE_LIBC - help - This enables POSIX clock\_\*() and \*sleep() functions. diff --git a/lib/posix/options/Kconfig.deprecated b/lib/posix/options/Kconfig.deprecated index 126d14f5aae..50c294ac183 100644 --- a/lib/posix/options/Kconfig.deprecated +++ b/lib/posix/options/Kconfig.deprecated @@ -6,6 +6,28 @@ menu "Deprecated POSIX options" +config MAX_TIMER_COUNT + int "Maximum number of timer_t [DEPRECATED]" + default POSIX_TIMER_MAX if POSIX_TIMERS + default 0 + help + This option is deprecated. + + Please use CONFIG_POSIX_TIMER_MAX instead. + +config POSIX_CLOCK + bool "clock and sleep APIs [DEPRECATED]" + select DEPRECATED + select POSIX_CLOCK_SELECTION + select POSIX_CPUTIME + select POSIX_MONOTONIC_CLOCK + select POSIX_TIMERS + select POSIX_TIMEOUTS + help + This option is deprecated. + + Please use CONFIG_POSIX_TIMERS instead. + config POSIX_LIMITS_RTSIG_MAX int "_POSIX_RTSIG_MAX value in limits.h [DEPRECATED]" default POSIX_RTSIG_MAX if POSIX_REALTIME_SIGNALS @@ -15,4 +37,22 @@ config POSIX_LIMITS_RTSIG_MAX Please use CONFIG_POSIX_RTSIG_MAX instead. +config TIMER + bool "Timer support [DEPRECATED]" + select DEPRECATED + select POSIX_TIMERS + help + This option is deprecated. + + Please use CONFIG_POSIX_TIMERS instead. + +config TIMER_DELAYTIMER_MAX + int "Maximum count returned my timer_getoverrun() in POSIX application [DEPRECATED]" + default POSIX_DELAYTIMER_MAX if POSIX_TIMERS + default 0 + help + This option is deprecated. + + Please use CONFIG_POSIX_DELAYTIMER_MAX instead. + endmenu diff --git a/lib/posix/options/Kconfig.procN b/lib/posix/options/Kconfig.procN new file mode 100644 index 00000000000..3e22fcf1371 --- /dev/null +++ b/lib/posix/options/Kconfig.procN @@ -0,0 +1,16 @@ +# Copyright (c) 2024 Tenstorrent AI ULC +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_MULTI_PROCESS + bool "POSIX multi-process support [EXPERIMENTAL]" + default y if POSIX_API + select EXPERIMENTAL + help + Support for multi-processing. + + Note: Currently Zephyr does not support multiple processes and therefore much of this option + group is not implemented and is considered undefined behaviour. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html diff --git a/lib/posix/options/Kconfig.timer b/lib/posix/options/Kconfig.timer index 10905e9c21d..cd53379716a 100644 --- a/lib/posix/options/Kconfig.timer +++ b/lib/posix/options/Kconfig.timer @@ -1,13 +1,91 @@ # Copyright (c) 2018 Intel Corporation +# Copyright (c) 2024 Tenstorrent AI ULC # # SPDX-License-Identifier: Apache-2.0 -TYPE = TIMER -type = timer_t -type-function = timer_create -rsource "Kconfig.template.pooled_type" +menuconfig POSIX_TIMERS + bool "POSIX timers, clocks, and sleep functions" + default y if POSIX_API + help + Select 'y' here and Zephyr will provide implementations of clock_getres(), clock_gettime(), + clock_settime(), nanosleep(), timer_create(), timer_delete(), timer_getoverrun(), + timer_settime(), and timer_gettime(). -if TIMER + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html + +if POSIX_TIMERS + +config POSIX_THREAD_CPUTIME + bool "POSIX per-thread CPU-time clocks" + default y + help + This enables CLOCK_THREAD_CPUTIME_ID. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_port.html + https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_118 + https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_08_05_04 + +config POSIX_MONOTONIC_CLOCK + bool "POSIX Monotonic clock support" + default y + help + This enables CLOCK_MONOTONIC. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_port.html + https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_08_05_03 + +config POSIX_CPUTIME + bool "POSIX per-process CPU-time clocks" + default y + help + This enables CLOCK_PROCESS_CPUTIME_ID. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_port.html + https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_118 + https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_08_05_04 + +config POSIX_CLOCK_SELECTION + bool "POSIX Clock selection" + default y + help + This enables POSIX clock selection. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_port.html + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_port.html#tag_24_03_04 + +config POSIX_DELAYTIMER_MAX + int "Maximum count returned my timer_getoverrun() in POSIX application" + default 32 + help + This controls the maximum number of times a timer can overrun before + timer_getoverrun() in POSIX compliant application. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html + +config POSIX_TIMER_MAX + int "Maximum number of POSIX timers per process" + default 32 + help + Maximum simultaneously active timer_t in a POSIX application. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html + +config POSIX_TIMEOUTS + bool "Support timeouts for some blocking POSIX services" + default y + help + Enable mandatory timeouts for some blocking operations. + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_port.html + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap02.html config TIMER_CREATE_WAIT int "Time to wait for timer availability (in msec) in POSIX application" @@ -17,11 +95,8 @@ config TIMER_CREATE_WAIT This controls how long to wait for resources to come available to create a new timer in POSIX compliant application -config TIMER_DELAYTIMER_MAX - int "Maximum count returned my timer_getoverrun() in POSIX application" - default 20 - help - This controls the maximum number of times a timer can overrun before - timer_getoverrun() in POSIX compliant application. +module = TIMER +module-str = POSIX Timers +source "subsys/logging/Kconfig.template.log_config" -endif # TIMER +endif # POSIX_TIMERS diff --git a/lib/posix/options/Kconfig.xsi b/lib/posix/options/Kconfig.xsi new file mode 100644 index 00000000000..6cc2bf58509 --- /dev/null +++ b/lib/posix/options/Kconfig.xsi @@ -0,0 +1,16 @@ +# Copyright (c) 2024 Tenstorrent AI ULC +# +# SPDX-License-Identifier: Apache-2.0 + +config XSI_SINGLE_PROCESS + bool "X/Open single process" + default y if POSIX_API + depends on POSIX_ENV + depends on POSIX_UNAME + depends on POSIX_CLOCK_SELECTION + help + Select 'y' here and Zephyr will provide implementations of + gethostid(), gettimeofday(), and putenv(). + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html diff --git a/lib/posix/options/_common.c b/lib/posix/options/_common.c index 85a8e7cae66..8125570f26e 100644 --- a/lib/posix/options/_common.c +++ b/lib/posix/options/_common.c @@ -8,7 +8,7 @@ #include #include -#ifdef CONFIG_POSIX_CLOCK +#ifdef CONFIG_POSIX_TIMERS int64_t timespec_to_timeoutms(const struct timespec *abstime) { int64_t milli_secs, secs, nsecs; @@ -30,4 +30,4 @@ int64_t timespec_to_timeoutms(const struct timespec *abstime) return milli_secs; } -#endif /* CONFIG_POSIX_CLOCK */ +#endif /* CONFIG_POSIX_TIMERS */ diff --git a/lib/posix/options/clock.c b/lib/posix/options/clock.c index 68692b5ecd6..5fa09daaae6 100644 --- a/lib/posix/options/clock.c +++ b/lib/posix/options/clock.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2018 Intel Corporation + * Copyright (c) 2018 Friedt Professional Engineering Services, Inc * * SPDX-License-Identifier: Apache-2.0 */ @@ -156,14 +157,43 @@ int clock_settime(clockid_t clock_id, const struct timespec *tp) return 0; } +/* + * Note: usleep() was removed in Issue 7. + * + * It is kept here for compatibility purposes. + * + * For more information, please see + * https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap01.html + * https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html + */ +int usleep(useconds_t useconds) +{ + int32_t rem; + + if (useconds >= USEC_PER_SEC) { + errno = EINVAL; + return -1; + } + + rem = k_usleep(useconds); + __ASSERT_NO_MSG(rem >= 0); + if (rem > 0) { + /* sleep was interrupted by a call to k_wakeup() */ + errno = EINTR; + return -1; + } + + return 0; +} + /** * @brief Suspend execution for a nanosecond interval, or * until some absolute time relative to the specified clock. * * See IEEE 1003.1 */ -int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, - struct timespec *rmtp) +static int __z_clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, + struct timespec *rmtp) { uint64_t ns; uint64_t us; @@ -225,6 +255,17 @@ do_rmtp_update: return 0; } +int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) +{ + return __z_clock_nanosleep(CLOCK_MONOTONIC, 0, rqtp, rmtp); +} + +int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, + struct timespec *rmtp) +{ + return __z_clock_nanosleep(clock_id, flags, rqtp, rmtp); +} + /** * @brief Get current real time. * diff --git a/lib/posix/options/nanosleep.c b/lib/posix/options/nanosleep.c deleted file mode 100644 index aafb9dbeb79..00000000000 --- a/lib/posix/options/nanosleep.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2018 Friedt Professional Engineering Services, Inc - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -/* required for struct timespec */ -#include -#include -#include - -/** - * @brief Suspend execution for nanosecond intervals. - * - * See IEEE 1003.1 - */ -int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) -{ - return clock_nanosleep(CLOCK_MONOTONIC, 0, rqtp, rmtp); -} diff --git a/lib/posix/options/sleep.c b/lib/posix/options/sleep.c index 98fff715dda..dd739322c75 100644 --- a/lib/posix/options/sleep.c +++ b/lib/posix/options/sleep.c @@ -23,27 +23,3 @@ unsigned sleep(unsigned int seconds) return rem / MSEC_PER_SEC; } -/** - * @brief Suspend execution for microsecond intervals. - * - * See IEEE 1003.1 - */ -int usleep(useconds_t useconds) -{ - int32_t rem; - - if (useconds >= USEC_PER_SEC) { - errno = EINVAL; - return -1; - } - - rem = k_usleep(useconds); - __ASSERT_NO_MSG(rem >= 0); - if (rem > 0) { - /* sleep was interrupted by a call to k_wakeup() */ - errno = EINTR; - return -1; - } - - return 0; -} diff --git a/lib/posix/options/timer.c b/lib/posix/options/timer.c index 7caecc180a1..d556c781331 100644 --- a/lib/posix/options/timer.c +++ b/lib/posix/options/timer.c @@ -29,8 +29,8 @@ struct timer_obj { uint32_t status; }; -K_MEM_SLAB_DEFINE(posix_timer_slab, sizeof(struct timer_obj), - CONFIG_MAX_TIMER_COUNT, __alignof__(struct timer_obj)); +K_MEM_SLAB_DEFINE(posix_timer_slab, sizeof(struct timer_obj), CONFIG_POSIX_TIMER_MAX, + __alignof__(struct timer_obj)); static void zephyr_timer_wrapper(struct k_timer *ztimer) { @@ -306,8 +306,8 @@ int timer_getoverrun(timer_t timerid) int overruns = k_timer_status_get(&timer->ztimer) - 1; - if (overruns > CONFIG_TIMER_DELAYTIMER_MAX) { - overruns = CONFIG_TIMER_DELAYTIMER_MAX; + if (overruns > CONFIG_POSIX_DELAYTIMER_MAX) { + overruns = CONFIG_POSIX_DELAYTIMER_MAX; } return overruns; diff --git a/modules/Kconfig.simplelink b/modules/Kconfig.simplelink index cbcf1766d6b..843f95c36fa 100644 --- a/modules/Kconfig.simplelink +++ b/modules/Kconfig.simplelink @@ -15,7 +15,7 @@ config SIMPLELINK_HOST_DRIVER select REQUIRES_FULL_LIBC select ERRNO select PTHREAD_IPC - select POSIX_CLOCK + select POSIX_TIMERS help Build the SimpleLink host driver diff --git a/modules/hostap/Kconfig b/modules/hostap/Kconfig index 490e70c0c7d..9f1ba54995c 100644 --- a/modules/hostap/Kconfig +++ b/modules/hostap/Kconfig @@ -7,7 +7,7 @@ config WIFI_NM_WPA_SUPPLICANT bool "WPA Suplicant from hostap project [EXPERIMENTAL]" - select POSIX_CLOCK + select POSIX_TIMERS select POSIX_SIGNAL select POSIX_API select NET_SOCKETS diff --git a/samples/net/cloud/aws_iot_mqtt/prj.conf b/samples/net/cloud/aws_iot_mqtt/prj.conf index 30277ffb18c..fbede2f3bf9 100644 --- a/samples/net/cloud/aws_iot_mqtt/prj.conf +++ b/samples/net/cloud/aws_iot_mqtt/prj.conf @@ -13,7 +13,6 @@ CONFIG_HW_STACK_PROTECTION=y CONFIG_REQUIRES_FULL_LIBC=y CONFIG_SNTP=y CONFIG_JSON_LIBRARY=y -CONFIG_POSIX_CLOCK=y CONFIG_POSIX_API=y # DNS diff --git a/samples/subsys/shell/shell_module/overlay-usb.conf b/samples/subsys/shell/shell_module/overlay-usb.conf index 692287e23a1..a9afb6499cf 100644 --- a/samples/subsys/shell/shell_module/overlay-usb.conf +++ b/samples/subsys/shell/shell_module/overlay-usb.conf @@ -4,8 +4,8 @@ CONFIG_SHELL_BACKEND_SERIAL_CHECK_DTR=y CONFIG_UART_LINE_CTRL=y CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n -# POSIX_CLOCK requires an embedded C library while the native USB driver is incompatible with it. +# POSIX_TIMERS requires an embedded C library while the native USB driver is incompatible with it. # So let's disable it. Once USB_NATIVE_POSIX supports embedded C libraries this can be removed. -CONFIG_POSIX_CLOCK=n -# DATE_SHELL requires POSIX_CLOCK +CONFIG_POSIX_TIMERS=n +# DATE_SHELL requires POSIX_TIMERS CONFIG_DATE_SHELL=n diff --git a/samples/subsys/shell/shell_module/prj.conf b/samples/subsys/shell/shell_module/prj.conf index 41d51f8e22a..c6cc76bca40 100644 --- a/samples/subsys/shell/shell_module/prj.conf +++ b/samples/subsys/shell/shell_module/prj.conf @@ -9,7 +9,7 @@ CONFIG_THREAD_MONITOR=y CONFIG_BOOT_BANNER=n CONFIG_THREAD_NAME=y CONFIG_DEVICE_SHELL=y -CONFIG_POSIX_CLOCK=y +CONFIG_POSIX_TIMERS=y CONFIG_DATE_SHELL=y CONFIG_THREAD_RUNTIME_STATS=y CONFIG_THREAD_RUNTIME_STATS_USE_TIMING_FUNCTIONS=y diff --git a/samples/subsys/shell/shell_module/prj_getopt.conf b/samples/subsys/shell/shell_module/prj_getopt.conf index 6bfeb3dec41..e3c8ecbc805 100644 --- a/samples/subsys/shell/shell_module/prj_getopt.conf +++ b/samples/subsys/shell/shell_module/prj_getopt.conf @@ -9,6 +9,6 @@ CONFIG_THREAD_MONITOR=y CONFIG_BOOT_BANNER=n CONFIG_THREAD_NAME=y CONFIG_DEVICE_SHELL=y -CONFIG_POSIX_CLOCK=y +CONFIG_POSIX_TIMERS=y CONFIG_DATE_SHELL=y CONFIG_THREAD_RUNTIME_STATS=y diff --git a/samples/subsys/shell/shell_module/prj_login.conf b/samples/subsys/shell/shell_module/prj_login.conf index d84acc15622..ff8e8a06c0d 100644 --- a/samples/subsys/shell/shell_module/prj_login.conf +++ b/samples/subsys/shell/shell_module/prj_login.conf @@ -8,7 +8,7 @@ CONFIG_THREAD_MONITOR=y CONFIG_BOOT_BANNER=n CONFIG_THREAD_NAME=y CONFIG_DEVICE_SHELL=y -CONFIG_POSIX_CLOCK=y +CONFIG_POSIX_TIMERS=y CONFIG_DATE_SHELL=y CONFIG_THREAD_RUNTIME_STATS=y diff --git a/subsys/logging/Kconfig.processing b/subsys/logging/Kconfig.processing index 3cf9259c96d..da0a90b8126 100644 --- a/subsys/logging/Kconfig.processing +++ b/subsys/logging/Kconfig.processing @@ -161,7 +161,7 @@ config LOG_TIMESTAMP_64BIT config LOG_TIMESTAMP_USE_REALTIME bool "Use real time clock for timestamp" select LOG_TIMESTAMP_64BIT - depends on POSIX_CLOCK + depends on POSIX_TIMERS help When enabled, real time clock is used for timestamping. diff --git a/subsys/net/lib/lwm2m/Kconfig b/subsys/net/lib/lwm2m/Kconfig index 4fdd7228f70..79323b165ad 100644 --- a/subsys/net/lib/lwm2m/Kconfig +++ b/subsys/net/lib/lwm2m/Kconfig @@ -227,7 +227,7 @@ config LWM2M_RD_CLIENT_MAX_RETRIES config LWM2M_RESOURCE_DATA_CACHE_SUPPORT bool "Resource Time series data cache support" depends on (LWM2M_RW_SENML_JSON_SUPPORT || LWM2M_RW_SENML_CBOR_SUPPORT) - depends on (POSIX_CLOCK && RING_BUFFER) + depends on (POSIX_TIMERS && RING_BUFFER) help Enable time series data storage. Requires time() to provide current Unix timestamp. diff --git a/subsys/shell/modules/Kconfig b/subsys/shell/modules/Kconfig index cb7aedaa79e..c57704ee2ae 100644 --- a/subsys/shell/modules/Kconfig +++ b/subsys/shell/modules/Kconfig @@ -34,7 +34,7 @@ config DEVICE_SHELL config DATE_SHELL bool "Date shell" - depends on POSIX_CLOCK + depends on POSIX_TIMERS default y if !SHELL_MINIMAL help This shell provides access to date and time based on Unix time. diff --git a/tests/lib/time/prj.conf b/tests/lib/time/prj.conf index aac2e48e364..ce932c79220 100644 --- a/tests/lib/time/prj.conf +++ b/tests/lib/time/prj.conf @@ -1,3 +1,3 @@ CONFIG_ZTEST=y -CONFIG_POSIX_CLOCK=y +CONFIG_POSIX_TIMERS=y CONFIG_PICOLIBC=y diff --git a/tests/posix/common/src/uname.c b/tests/posix/common/src/uname.c index d41ab8306a1..9b1e76d6b53 100644 --- a/tests/posix/common/src/uname.c +++ b/tests/posix/common/src/uname.c @@ -4,8 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include +#include + +#include ZTEST(uname, test_uname) { diff --git a/tests/posix/headers/prj.conf b/tests/posix/headers/prj.conf index 950a7d510ef..7161e4b3115 100644 --- a/tests/posix/headers/prj.conf +++ b/tests/posix/headers/prj.conf @@ -16,7 +16,7 @@ CONFIG_NET_SOCKETPAIR=y # for when CONFIG_POSIX_API is not selected CONFIG_PTHREAD_IPC=y CONFIG_POSIX_FS=y -CONFIG_POSIX_CLOCK=y +CONFIG_POSIX_TIMERS=y CONFIG_POSIX_MQUEUE=y CONFIG_EVENTFD=y CONFIG_GETOPT=y