Skip to content

Commit f3f0be3

Browse files
committed
posix: sched: Implement get APIs for scheduling parameters
Initial implementation of `sched_getparam()` and `sched_getscheduler()` POSIX APIs as a part of PSE53 `_POSIX_PRIORITY_SCHEDULING` option group. Both functions are actually placeholders and just return `ENOSYS` since Zephyr does not yet support processes or process scheduling. Signed-off-by: Dmitrii Golovanov <[email protected]>
1 parent e67bea5 commit f3f0be3

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

arch/posix/include/posix_cheats.h

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ extern "C" int _posix_zephyr_main(void);
151151
#define sched_yield(...) zap_sched_yield(__VA_ARGS__)
152152
#define sched_get_priority_min(...) zap_sched_get_priority_min(__VA_ARGS__)
153153
#define sched_get_priority_max(...) zap_sched_get_priority_max(__VA_ARGS__)
154+
#define sched_getparam(...) zap_sched_getparam(__VA_ARGS__)
155+
#define sched_getscheduler(...) zap_sched_getscheduler(__VA_ARGS__)
154156

155157
/* Sleep */
156158
#define sleep(...) zap_sleep(__VA_ARGS__)

include/zephyr/posix/sched.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 Intel Corporation
2+
* Copyright (c) 2018-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -8,6 +8,8 @@
88

99
#include <zephyr/kernel.h>
1010

11+
#include "posix_types.h"
12+
1113
#ifdef __cplusplus
1214
extern "C" {
1315
#endif
@@ -46,6 +48,9 @@ static inline int sched_yield(void)
4648
int sched_get_priority_min(int policy);
4749
int sched_get_priority_max(int policy);
4850

51+
int sched_getparam(pid_t pid, struct sched_param *param);
52+
int sched_getscheduler(pid_t pid);
53+
4954
#ifdef __cplusplus
5055
}
5156
#endif

lib/posix/sched.c

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 Intel Corporation
2+
* Copyright (c) 2018-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -41,3 +41,32 @@ int sched_get_priority_max(int policy)
4141
errno = EINVAL;
4242
return -1;
4343
}
44+
45+
/**
46+
* @brief Get scheduling parameters
47+
*
48+
* See IEEE 1003.1
49+
*/
50+
int sched_getparam(pid_t pid, struct sched_param *param)
51+
{
52+
ARG_UNUSED(pid);
53+
ARG_UNUSED(param);
54+
55+
errno = ENOSYS;
56+
57+
return -1;
58+
}
59+
60+
/**
61+
* @brief Get scheduling policy
62+
*
63+
* See IEEE 1003.1
64+
*/
65+
int sched_getscheduler(pid_t pid)
66+
{
67+
ARG_UNUSED(pid);
68+
69+
errno = ENOSYS;
70+
71+
return -1;
72+
}

tests/posix/common/src/pthread.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 Intel Corporation
2+
* Copyright (c) 2018-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -644,6 +644,23 @@ ZTEST(posix_apis, test_pthread_descriptor_leak)
644644
}
645645
}
646646

647+
ZTEST(posix_apis, test_sched_getparam)
648+
{
649+
struct sched_param param;
650+
int rc = sched_getparam(0, &param);
651+
int err = errno;
652+
653+
zassert_true((rc == -1 && err == ENOSYS));
654+
}
655+
656+
ZTEST(posix_apis, test_sched_getscheduler)
657+
{
658+
int rc = sched_getscheduler(0);
659+
int err = errno;
660+
661+
zassert_true((rc == -1 && err == ENOSYS));
662+
}
663+
647664
ZTEST(posix_apis, test_sched_policy)
648665
{
649666
/*

tests/posix/headers/src/sched_h.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ ZTEST(posix_headers, test_sched_h)
3030
zassert_not_null(sched_get_priority_max);
3131
zassert_not_null(sched_get_priority_min);
3232

33-
/* zassert_not_null(sched_getparam); */ /* not implemented */
34-
/* zassert_not_null(sched_getscheduler); */ /* not implemented */
33+
zassert_not_null(sched_getparam);
34+
zassert_not_null(sched_getscheduler);
3535

3636
/* zassert_not_null(sched_rr_get_interval); */ /* not implemented */
3737

0 commit comments

Comments
 (0)