[Xenomai] [PATCH 5/6] lib/cobalt: Pass setsched requests for unknown threads to glibc

Jan Kiszka jan.kiszka at siemens.com
Mon Jul 16 18:37:53 CEST 2018


From: Jan Kiszka <jan.kiszka at siemens.com>

This aligns the implementation with the documentation: If we get an
error from the kernel that suggests the thread is unknown to it, let
glibc deal with it.

Note that pthread_setschedparam_ex currently returns an invalid error
code, EINVAL rather than ESRCH, so that we try to detect the remote
thread case with some heuristic.

Signed-off-by: Jan Kiszka <jan.kiszka at siemens.com>
---
 lib/cobalt/sched.c  | 10 ++++++++++
 lib/cobalt/thread.c | 11 +++++++++++
 2 files changed, 21 insertions(+)

diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index 94f33231c4..bdb8603dad 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -308,6 +308,16 @@ int sched_setscheduler_ex(pid_t pid,
 				pid, policy, param_ex,
 				&u_winoff, &promoted);
 
+	/*
+	 * If the kernel has no reference to the target thread, let glibc
+	 * handle the call.
+	 */
+	if (ret == ESRCH) {
+		std_policy = cobalt_xlate_schedparam(policy, param_ex,
+						     &std_param);
+		return __STD(sched_setscheduler(pid, std_policy, &std_param));
+	}
+
 	if (ret == 0 && promoted) {
 		cobalt_sigshadow_install_once();
 		cobalt_set_tsd(u_winoff);
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index fac23109c1..b3c11abbb7 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -644,6 +644,17 @@ int pthread_setschedparam_ex(pthread_t thread,
 				thread, policy, param_ex,
 				u_winoff_ptr, &promoted);
 
+	/*
+	 * If the kernel has no reference to the target thread. let glibc
+	 * handle the call.
+	 */
+	if (!u_winoff_ptr && ret == EINVAL) {
+		std_policy = cobalt_xlate_schedparam(policy, param_ex,
+						     &std_param);
+		return __STD(pthread_setschedparam(thread, std_policy,
+						   &std_param));
+	}
+
 	if (ret == 0 && promoted) {
 		cobalt_sigshadow_install_once();
 		cobalt_set_tsd(u_winoff);
-- 
2.16.4




More information about the Xenomai mailing list