Module: xenomai-3 Branch: next Commit: 178eb4fc18c16d84b8ad46f4d0d0559eb2893888 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=178eb4fc18c16d84b8ad46f4d0d0559eb2893888
Author: Philippe Gerum <r...@xenomai.org> Date: Tue Sep 22 10:02:05 2015 +0200 lib/cobalt: wrap sched_getscheduler(2) --- include/cobalt/sched.h | 5 +++ lib/cobalt/cobalt.wrappers | 1 + lib/cobalt/sched.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ lib/cobalt/wrappers.c | 6 ++++ 4 files changed, 91 insertions(+) diff --git a/include/cobalt/sched.h b/include/cobalt/sched.h index 12c33e6..7c5b26e 100644 --- a/include/cobalt/sched.h +++ b/include/cobalt/sched.h @@ -38,6 +38,8 @@ COBALT_DECL(int, sched_get_priority_max(int policy)); COBALT_DECL(int, sched_setscheduler(pid_t pid, int policy, const struct sched_param *param)); +COBALT_DECL(int, sched_getscheduler(pid_t pid)); + int sched_get_priority_min_ex(int policy); int sched_get_priority_max_ex(int policy); @@ -45,6 +47,9 @@ int sched_get_priority_max_ex(int policy); int sched_setscheduler_ex(pid_t pid, int policy, const struct sched_param_ex *param_ex); +int sched_getscheduler_ex(pid_t pid, int *policy_r, + struct sched_param_ex *param_ex); + int sched_setconfig_np(int cpu, int policy, const union sched_config *config, size_t len); diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers index c8e24cb..9480f34 100644 --- a/lib/cobalt/cobalt.wrappers +++ b/lib/cobalt/cobalt.wrappers @@ -7,6 +7,7 @@ --wrap sched_get_priority_min --wrap sched_get_priority_max --wrap sched_setscheduler +--wrap sched_getscheduler --wrap pthread_kill --wrap pthread_join --wrap pthread_setname_np diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c index d1abed8..7886a8e 100644 --- a/lib/cobalt/sched.c +++ b/lib/cobalt/sched.c @@ -329,6 +329,85 @@ int sched_setscheduler_ex(pid_t pid, } /** + * Get the scheduling policy of the specified process. + * + * This service retrieves the scheduling policy of the Xenomai process + * identified by @a pid. + * + * If @a pid does not identify an existing Xenomai thread/process, this + * service falls back to the regular sched_getscheduler() service. + * + * @param pid target process/thread; + * + * @return 0 on success; + * @return an error number if: + * - ESRCH, @a pid is not found; + * - EINVAL, @a pid is negative + * - EFAULT, @a param_ex is an invalid address; + * + * @see + * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/sched_getscheduler.html"> + * Specification.</a> + */ +COBALT_IMPL(int, sched_getscheduler, (pid_t pid)) +{ + struct sched_param_ex param_ex; + int ret, policy; + + if (pid < 0) { + errno = EINVAL; + return -1; + } + + ret = XENOMAI_SYSCALL3(sc_cobalt_sched_getscheduler_ex, + pid, &policy, ¶m_ex); + if (ret == -ESRCH) + return __STD(sched_getscheduler(pid)); + + if (ret) { + errno = -ret; + return -1; + } + + return policy; +} + +/** + * Get extended scheduling policy of a process + * + * This service is an extended version of the sched_getscheduler() + * service, which supports Xenomai-specific and/or additional + * scheduling policies, not available with the host Linux environment. + * It retrieves the scheduling policy of the Xenomai process/thread + * identified by @a pid, and the associated scheduling parameters + * (e.g. the priority). + * + * @param pid queried process/thread. If zero, the current thread is + * assumed. + * + * @param policy_r a pointer to a variable receiving the current + * scheduling policy of @a pid. + * + * @param param_ex a pointer to a structure receiving the current + * scheduling parameters of @a pid. + * + * @return 0 on success; + * @return an error number if: + * - ESRCH, @a pid is not a Cobalt thread; + * - EINVAL, @a pid is negative or @a param_ex is NULL; + * - EFAULT, @a param_ex is an invalid address; + */ +int sched_getscheduler_ex(pid_t pid, int *policy_r, + struct sched_param_ex *param_ex) +{ + if (pid < 0 || param_ex == NULL) + return EINVAL; + + return -XENOMAI_SYSCALL3(sc_cobalt_sched_getscheduler_ex, + pid, policy_r, param_ex); +} + +/** * Get extended maximum priority of the specified scheduling policy. * * This service returns the maximum priority of the scheduling policy diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c index e5c9d2f..09c74e5 100644 --- a/lib/cobalt/wrappers.c +++ b/lib/cobalt/wrappers.c @@ -84,6 +84,12 @@ int __real_sched_setscheduler(pid_t pid, int policy, return sched_setscheduler(pid, policy, param); } +__weak +int __real_sched_getscheduler(pid_t pid) +{ + return sched_getscheduler(pid); +} + /* pthread */ __weak int __real_pthread_create(pthread_t *ptid_r, _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://xenomai.org/mailman/listinfo/xenomai-git