diff --git a/arch/posix/include/posix_cheats.h b/arch/posix/include/posix_cheats.h index 88a68b9fd490..770dab9aac60 100644 --- a/arch/posix/include/posix_cheats.h +++ b/arch/posix/include/posix_cheats.h @@ -151,6 +151,8 @@ extern "C" int _posix_zephyr_main(void); #define sched_yield(...) zap_sched_yield(__VA_ARGS__) #define sched_get_priority_min(...) zap_sched_get_priority_min(__VA_ARGS__) #define sched_get_priority_max(...) zap_sched_get_priority_max(__VA_ARGS__) +#define sched_getparam(...) zap_sched_getparam(__VA_ARGS__) +#define sched_getscheduler(...) zap_sched_getscheduler(__VA_ARGS__) /* Sleep */ #define sleep(...) zap_sleep(__VA_ARGS__) diff --git a/doc/services/portability/posix/aep/index.rst b/doc/services/portability/posix/aep/index.rst index 55a841dd565d..5e28fa10397d 100644 --- a/doc/services/portability/posix/aep/index.rst +++ b/doc/services/portability/posix/aep/index.rst @@ -52,7 +52,7 @@ Minimal Realtime System Profile (PSE51) _POSIX_THREAD_CPUTIME, -1, _POSIX_THREAD_PRIO_INHERIT, 200809L, :kconfig:option:`CONFIG_PTHREAD_MUTEX` _POSIX_THREAD_PRIO_PROTECT, -1, - _POSIX_THREAD_PRIORITY_SCHEDULING, -1, + _POSIX_THREAD_PRIORITY_SCHEDULING, -1, :kconfig:option:`CONFIG_POSIX_PRIORITY_SCHEDULING` (will fail with ``ENOSYS``:ref:`†`) _POSIX_THREAD_SPORADIC_SERVER, -1, _POSIX_TIMEOUTS, 200809L, :kconfig:option:`CONFIG_PTHREAD_IPC` _POSIX_TIMERS, 200809L, :kconfig:option:`CONFIG_POSIX_CLOCK` diff --git a/doc/services/portability/posix/conformance/index.rst b/doc/services/portability/posix/conformance/index.rst index 53f3113ca68f..0c38955337ee 100644 --- a/doc/services/portability/posix/conformance/index.rst +++ b/doc/services/portability/posix/conformance/index.rst @@ -87,7 +87,7 @@ POSIX System Interfaces :ref:`_POSIX_MESSAGE_PASSING`, 200809L, :kconfig:option:`CONFIG_POSIX_MQUEUE` _POSIX_MONOTONIC_CLOCK, 200809L, :kconfig:option:`CONFIG_POSIX_CLOCK` _POSIX_PRIORITIZED_IO, -1, - :ref:`_POSIX_PRIORITY_SCHEDULING`, -1, :kconfig:option:`CONFIG_PTHREAD` + :ref:`_POSIX_PRIORITY_SCHEDULING`, -1, :kconfig:option:`CONFIG_POSIX_PRIORITY_SCHEDULING` (will fail with ``ENOSYS``:ref:`†`) _POSIX_RAW_SOCKETS, 200809L, :kconfig:option:`CONFIG_NET_SOCKETS` _POSIX_SHARED_MEMORY_OBJECTS, -1, _POSIX_SPAWN, -1, diff --git a/include/zephyr/posix/sched.h b/include/zephyr/posix/sched.h index 10cfc666c66d..b7431fc33422 100644 --- a/include/zephyr/posix/sched.h +++ b/include/zephyr/posix/sched.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Intel Corporation + * Copyright (c) 2018-2023 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,8 @@ #include +#include "posix_types.h" + #ifdef __cplusplus extern "C" { #endif @@ -46,6 +48,9 @@ static inline int sched_yield(void) int sched_get_priority_min(int policy); int sched_get_priority_max(int policy); +int sched_getparam(pid_t pid, struct sched_param *param); +int sched_getscheduler(pid_t pid); + #ifdef __cplusplus } #endif diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt index e73c78d40e42..21d25580aacd 100644 --- a/lib/posix/CMakeLists.txt +++ b/lib/posix/CMakeLists.txt @@ -54,7 +54,7 @@ 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_PTHREAD_IPC rwlock.c) -zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC sched.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) diff --git a/lib/posix/Kconfig b/lib/posix/Kconfig index 3fd013134742..3202c13b7dd8 100644 --- a/lib/posix/Kconfig +++ b/lib/posix/Kconfig @@ -49,6 +49,7 @@ source "lib/posix/Kconfig.limits" source "lib/posix/Kconfig.mqueue" source "lib/posix/Kconfig.mutex" source "lib/posix/Kconfig.pthread" +source "lib/posix/Kconfig.sched" source "lib/posix/Kconfig.semaphore" source "lib/posix/Kconfig.signal" source "lib/posix/Kconfig.spinlock" diff --git a/lib/posix/Kconfig.sched b/lib/posix/Kconfig.sched new file mode 100644 index 000000000000..62e7541c8e1f --- /dev/null +++ b/lib/posix/Kconfig.sched @@ -0,0 +1,11 @@ +# Copyright (c) 2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_PRIORITY_SCHEDULING + bool "_POSIX_PRIORITY_SCHEDULING API support" + default y if PTHREAD + default y if POSIX_API + depends on PTHREAD + help + This enables POSIX scheduling APIs (_POSIX_PRIORITY_SCHEDULING). diff --git a/lib/posix/sched.c b/lib/posix/sched.c index 4f71badded98..d5fa1d81ad41 100644 --- a/lib/posix/sched.c +++ b/lib/posix/sched.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Intel Corporation + * Copyright (c) 2018-2023 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ @@ -41,3 +41,32 @@ int sched_get_priority_max(int policy) errno = EINVAL; return -1; } + +/** + * @brief Get scheduling parameters + * + * See IEEE 1003.1 + */ +int sched_getparam(pid_t pid, struct sched_param *param) +{ + ARG_UNUSED(pid); + ARG_UNUSED(param); + + errno = ENOSYS; + + return -1; +} + +/** + * @brief Get scheduling policy + * + * See IEEE 1003.1 + */ +int sched_getscheduler(pid_t pid) +{ + ARG_UNUSED(pid); + + errno = ENOSYS; + + return -1; +} diff --git a/tests/posix/common/prj.conf b/tests/posix/common/prj.conf index 6c0b9153b6ac..67dab816dc79 100644 --- a/tests/posix/common/prj.conf +++ b/tests/posix/common/prj.conf @@ -4,6 +4,7 @@ CONFIG_MAX_PTHREAD_COUNT=10 CONFIG_ZTEST=y CONFIG_SEM_VALUE_MAX=32767 CONFIG_POSIX_MQUEUE=y +CONFIG_POSIX_PRIORITY_SCHEDULING=y CONFIG_HEAP_MEM_POOL_SIZE=4096 CONFIG_MAX_THREAD_BYTES=4 CONFIG_THREAD_NAME=y diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index 7cf2405c2b44..6210da0a0200 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Intel Corporation + * Copyright (c) 2018-2023 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ @@ -644,6 +644,23 @@ ZTEST(posix_apis, test_pthread_descriptor_leak) } } +ZTEST(posix_apis, test_sched_getparam) +{ + struct sched_param param; + int rc = sched_getparam(0, ¶m); + int err = errno; + + zassert_true((rc == -1 && err == ENOSYS)); +} + +ZTEST(posix_apis, test_sched_getscheduler) +{ + int rc = sched_getscheduler(0); + int err = errno; + + zassert_true((rc == -1 && err == ENOSYS)); +} + ZTEST(posix_apis, test_sched_policy) { /* diff --git a/tests/posix/headers/src/sched_h.c b/tests/posix/headers/src/sched_h.c index fb4f2de26883..fba7d17704c7 100644 --- a/tests/posix/headers/src/sched_h.c +++ b/tests/posix/headers/src/sched_h.c @@ -30,8 +30,8 @@ ZTEST(posix_headers, test_sched_h) zassert_not_null(sched_get_priority_max); zassert_not_null(sched_get_priority_min); - /* zassert_not_null(sched_getparam); */ /* not implemented */ - /* zassert_not_null(sched_getscheduler); */ /* not implemented */ + zassert_not_null(sched_getparam); + zassert_not_null(sched_getscheduler); /* zassert_not_null(sched_rr_get_interval); */ /* not implemented */