From: Jan Kiszka <jan.kiszka@domain.hid>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-core] [PATCH v2 1/4] POSIX: Fix SCHED_RR thread creation
Date: Wed, 18 Feb 2009 08:51:49 +0100 [thread overview]
Message-ID: <499BBE15.3030605@domain.hid> (raw)
In-Reply-To: <499B4CC0.9000803@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 9990 bytes --]
Jan Kiszka wrote:
> I played with it, but raising a signal from xnshadow_map is no good
> idea: If we inject the signal before the migration, xnshadow_map fails
> due to the pending signal, we exit to user space, run the signal,
> restart the call, raise the signal, and so on. If we raise after
> migration, we immediately force the new thread into secondary mode
> again, definitely causing problems when the mode switch warning is
> active, but also risking other regressions for xnshadow_map users that
> expect to find themselves in primary mode on return.
>
Meditating over it again, I realized that there is actually no need to
raise the renice signal if we migrate in xnshadow_map. This case will be
handled automatically on next relax. That pattern seems to work and
allows indeed a few cleanups (just uitron still needs
pthread_setschedparam). This is just a first draft, needs more testing:
diff --git a/ksrc/nucleus/shadow.c b/ksrc/nucleus/shadow.c
index 8c679ad..f0f6801 100644
--- a/ksrc/nucleus/shadow.c
+++ b/ksrc/nucleus/shadow.c
@@ -1250,6 +1250,12 @@ int xnshadow_map(xnthread_t *thread, xncompletion_t __user *u_completion,
thread->u_mode = u_mode;
if (u_completion) {
+ /*
+ * Send the renice signal if we are not migrating so that user
+ * space will immediately align Linux sched policy and prio.
+ */
+ xnshadow_renice(thread);
+
/*
* We still have the XNDORMANT bit set, so we can't
* link to the RPI queue which only links _runnable_
diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c
index 99c2a16..16303b3 100644
--- a/ksrc/skins/posix/syscall.c
+++ b/ksrc/skins/posix/syscall.c
@@ -167,9 +167,9 @@ static int __pthread_create(struct pt_regs *regs)
calling context. */
pthread_attr_init(&attr);
- attr.policy = p->policy;
+ attr.policy = __xn_reg_arg2(regs);
attr.detachstate = PTHREAD_CREATE_DETACHED;
- attr.schedparam_ex.sched_priority = p->rt_priority;
+ attr.schedparam_ex.sched_priority = __xn_reg_arg3(regs);
attr.fp = 1;
attr.name = p->comm;
@@ -179,7 +179,7 @@ static int __pthread_create(struct pt_regs *regs)
return -err; /* Conventionally, our error codes are negative. */
err = xnshadow_map(&k_tid->threadbase, NULL,
- (unsigned long __user *)__xn_reg_arg2(regs));
+ (unsigned long __user *)__xn_reg_arg4(regs));
if (!err && !__pthread_hash(&hkey, k_tid))
err = -ENOMEM;
diff --git a/src/skins/native/task.c b/src/skins/native/task.c
index 7bcc49c..190dc4b 100644
--- a/src/skins/native/task.c
+++ b/src/skins/native/task.c
@@ -55,21 +55,10 @@ static void *rt_task_trampoline(void *cookie)
{
struct rt_task_iargs *iargs = (struct rt_task_iargs *)cookie;
void (*entry) (void *cookie);
- struct sched_param param;
struct rt_arg_bulk bulk;
RT_TASK *task;
long err;
- if (iargs->prio > 0) {
- /*
- * Re-apply sched params here as some libpthread
- * implementations fail doing this via pthread_create.
- */
- memset(¶m, 0, sizeof(param));
- param.sched_priority = iargs->prio;
- __real_pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
- }
-
/* rt_task_delete requires asynchronous cancellation */
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
@@ -178,7 +167,6 @@ int rt_task_start(RT_TASK *task, void (*entry) (void *cookie), void *cookie)
int rt_task_shadow(RT_TASK *task, const char *name, int prio, int mode)
{
- struct sched_param param;
struct rt_arg_bulk bulk;
RT_TASK task_desc;
int err;
@@ -190,13 +178,6 @@ int rt_task_shadow(RT_TASK *task, const char *name, int prio, int mode)
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
sigshadow_install_once();
- if (prio > 0) {
- /* Make sure the POSIX library caches the right priority. */
- memset(¶m, 0, sizeof(param));
- param.sched_priority = prio;
- __real_pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
- }
-
bulk.a1 = (u_long)task;
bulk.a2 = (u_long)name;
bulk.a3 = (u_long)prio;
diff --git a/src/skins/native/wrappers.c b/src/skins/native/wrappers.c
index 8421456..4463f6f 100644
--- a/src/skins/native/wrappers.c
+++ b/src/skins/native/wrappers.c
@@ -33,13 +33,6 @@
*/
__attribute__ ((weak))
-int __real_pthread_setschedparam(pthread_t thread,
- int policy, const struct sched_param *param)
-{
- return pthread_setschedparam(thread, policy, param);
-}
-
-__attribute__ ((weak))
int __real_pthread_create(pthread_t *tid,
const pthread_attr_t * attr,
void *(*start) (void *), void *arg)
diff --git a/src/skins/native/wrappers.h b/src/skins/native/wrappers.h
index f2125a4..99568a9 100644
--- a/src/skins/native/wrappers.h
+++ b/src/skins/native/wrappers.h
@@ -8,9 +8,6 @@ int __real_pthread_create(pthread_t *tid,
const pthread_attr_t * attr,
void *(*start) (void *), void *arg);
-int __real_pthread_setschedparam(pthread_t thread,
- int policy, const struct sched_param *param);
-
int __real_pthread_kill(pthread_t tid, int sig);
int __real_open(const char *path, int oflag, ...);
diff --git a/src/skins/posix/thread.c b/src/skins/posix/thread.c
index f32c7e1..e8c50bd 100644
--- a/src/skins/posix/thread.c
+++ b/src/skins/posix/thread.c
@@ -203,8 +203,8 @@ static void *__pthread_trampoline(void *arg)
/* Do _not_ inline the call to pthread_self() in the syscall
macro: this trashes the syscall regs on some archs. */
- err = XENOMAI_SKINCALL2(__pse51_muxid, __pse51_thread_create, tid,
- mode_buf);
+ err = XENOMAI_SKINCALL4(__pse51_muxid, __pse51_thread_create, tid,
+ iargs->policy, iargs->prio, mode_buf);
iargs->ret = -err;
/* We must save anything we'll need to use from *iargs on our own
@@ -221,11 +221,6 @@ static void *__pthread_trampoline(void *arg)
__real_sem_post(&iargs->sync);
if (!err) {
- /* Broken pthread libs ignore some of the thread attribute specs
- passed to pthread_create(3), so we force the scheduling policy
- once again here. */
- __real_pthread_setschedparam(tid, policy, ¶m);
-
/* If the thread running pthread_create runs with the same
priority as us, we should leave it running, as if there never
was a synchronization with a semaphore. */
diff --git a/src/skins/psos+/task.c b/src/skins/psos+/task.c
index 265eab2..1bf3565 100644
--- a/src/skins/psos+/task.c
+++ b/src/skins/psos+/task.c
@@ -63,13 +63,8 @@ static void *psos_task_trampoline(void *cookie)
void (*entry)(u_long, u_long, u_long, u_long);
u_long dummy_args[4] = { 0, 0, 0, 0 }, *targs;
struct psos_arg_bulk bulk;
- struct sched_param param;
- int policy;
long err;
- policy = psos_task_set_posix_priority(iargs->prio, ¶m);
- pthread_setschedparam(pthread_self(), policy, ¶m);
-
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
sigshadow_install_once();
diff --git a/src/skins/vrtx/task.c b/src/skins/vrtx/task.c
index 1b16f68..184c948 100644
--- a/src/skins/vrtx/task.c
+++ b/src/skins/vrtx/task.c
@@ -73,8 +73,6 @@ static void *vrtx_task_trampoline(void *cookie)
struct vrtx_task_iargs *iargs =
(struct vrtx_task_iargs *)cookie, _iargs;
struct vrtx_arg_bulk bulk;
- struct sched_param param;
- int policy;
long err;
#ifndef HAVE___THREAD
TCB *tcb;
@@ -83,13 +81,6 @@ static void *vrtx_task_trampoline(void *cookie)
/* Backup the arg struct, it might vanish after completion. */
memcpy(&_iargs, iargs, sizeof(_iargs));
- /*
- * Apply sched params here as some libpthread implementations
- * fail doing this properly via pthread_create.
- */
- policy = vrtx_task_set_posix_priority(iargs->prio, ¶m);
- pthread_setschedparam(pthread_self(), policy, ¶m);
-
/* vrtx_task_delete requires asynchronous cancellation */
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
diff --git a/src/skins/vxworks/taskLib.c b/src/skins/vxworks/taskLib.c
index 1ba193e..3249bfc 100644
--- a/src/skins/vxworks/taskLib.c
+++ b/src/skins/vxworks/taskLib.c
@@ -86,21 +86,12 @@ static void *wind_task_trampoline(void *cookie)
struct wind_task_iargs *iargs =
(struct wind_task_iargs *)cookie, _iargs;
struct wind_arg_bulk bulk;
- struct sched_param param;
WIND_TCB *pTcb;
- int policy;
long err;
/* Backup the arg struct, it might vanish after completion. */
memcpy(&_iargs, iargs, sizeof(_iargs));
- /*
- * Apply sched params here as some libpthread implementations
- * fail doing this properly via pthread_create.
- */
- policy = wind_task_set_posix_priority(iargs->prio, ¶m);
- __real_pthread_setschedparam(pthread_self(), policy, ¶m);
-
/* wind_task_delete requires asynchronous cancellation */
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
sigshadow_install_once();
diff --git a/src/skins/vxworks/wrappers.c b/src/skins/vxworks/wrappers.c
index 394ea51..ab50d77 100644
--- a/src/skins/vxworks/wrappers.c
+++ b/src/skins/vxworks/wrappers.c
@@ -33,13 +33,6 @@
*/
__attribute__ ((weak))
-int __real_pthread_setschedparam(pthread_t thread,
- int policy, const struct sched_param *param)
-{
- return pthread_setschedparam(thread, policy, param);
-}
-
-__attribute__ ((weak))
int __real_pthread_create(pthread_t *tid,
const pthread_attr_t * attr,
void *(*start) (void *), void *arg)
diff --git a/src/skins/vxworks/wrappers.h b/src/skins/vxworks/wrappers.h
index 919309a..e20da86 100644
--- a/src/skins/vxworks/wrappers.h
+++ b/src/skins/vxworks/wrappers.h
@@ -8,9 +8,6 @@ int __real_pthread_create(pthread_t *tid,
const pthread_attr_t * attr,
void *(*start) (void *), void *arg);
-int __real_pthread_setschedparam(pthread_t thread,
- int policy, const struct sched_param *param);
-
int __real_pthread_kill(pthread_t tid, int sig);
int __real_open(const char *path, int oflag, ...);
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]
next prev parent reply other threads:[~2009-02-18 7:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-17 17:04 [Xenomai-core] [PATCH v2 0/4] Various fixes and cleanups Jan Kiszka
2009-02-17 17:04 ` [Xenomai-core] [PATCH v2 2/4] Mark libs nodlopen on initial-exec TLS Jan Kiszka
2009-02-17 17:04 ` [Xenomai-core] [PATCH v2 3/4] Add --enable-dlopen-skins configure switch Jan Kiszka
2009-02-17 17:04 ` [Xenomai-core] [PATCH v2 1/4] POSIX: Fix SCHED_RR thread creation Jan Kiszka
2009-02-17 17:15 ` Gilles Chanteperdrix
2009-02-17 17:28 ` Jan Kiszka
2009-02-17 17:37 ` Gilles Chanteperdrix
2009-02-17 17:47 ` Jan Kiszka
2009-02-17 17:50 ` Gilles Chanteperdrix
2009-02-17 17:57 ` Jan Kiszka
2009-02-17 18:17 ` Gilles Chanteperdrix
2009-02-17 18:19 ` Jan Kiszka
2009-02-17 18:21 ` Gilles Chanteperdrix
2009-02-17 18:41 ` Jan Kiszka
2009-02-17 23:48 ` Jan Kiszka
2009-02-18 7:51 ` Jan Kiszka [this message]
2009-02-17 17:04 ` [Xenomai-core] [PATCH v2 4/4] POSIX: Do not auto-shadow main with dlopen enabled Jan Kiszka
2009-02-25 10:04 ` [Xenomai-core] [PATCH v2 0/4] Various fixes and cleanups Jan Kiszka
2009-02-25 11:19 ` Philippe Gerum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=499BBE15.3030605@domain.hid \
--to=jan.kiszka@domain.hid \
--cc=gilles.chanteperdrix@xenomai.org \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.