[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2017-07-27 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 4892e0a3520b02dab3591653f81762f64410b4e5
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=4892e0a3520b02dab3591653f81762f64410b4e5

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   43 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 86 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 49744c4..ebc3624 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -516,6 +516,49 @@ int cobalt_sched_weighted_prio(int policy,
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
 
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
 
 /*
  * Temporary compatibility aliases which should be phased out at next
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index f58e341..fc8adf6 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -57,6 +57,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving 

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2017-06-03 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 25156eae5a5f4672a451ff34205d69d482e6d7b8
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=25156eae5a5f4672a451ff34205d69d482e6d7b8

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   43 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 86 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 49744c4..ebc3624 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -516,6 +516,49 @@ int cobalt_sched_weighted_prio(int policy,
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
 
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
 
 /*
  * Temporary compatibility aliases which should be phased out at next
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index f58e341..fc8adf6 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -57,6 +57,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving 

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2017-04-17 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: ddd37928976b8b5ef9679afcfbbd41caa78a3693
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=ddd37928976b8b5ef9679afcfbbd41caa78a3693

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   43 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 86 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 49744c4..ebc3624 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -516,6 +516,49 @@ int cobalt_sched_weighted_prio(int policy,
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
 
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
 
 /*
  * Temporary compatibility aliases which should be phased out at next
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index f58e341..fc8adf6 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -57,6 +57,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving 

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2017-03-15 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 72e49fcdc6c15e14e774511bf0be7a4f0c3b5fb0
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=72e49fcdc6c15e14e774511bf0be7a4f0c3b5fb0

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   43 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 86 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 49744c4..ebc3624 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -516,6 +516,49 @@ int cobalt_sched_weighted_prio(int policy,
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
 
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
 
 /*
  * Temporary compatibility aliases which should be phased out at next
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving 

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2017-03-05 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: cc0ecd118f0a7676312f52361076ee0a1a448394
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=cc0ecd118f0a7676312f52361076ee0a1a448394

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2017-02-15 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 350f327863fe17e5b2fe76a4a086aa472bcacf6d
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=350f327863fe17e5b2fe76a4a086aa472bcacf6d

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2017-01-26 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 56eea84e15049204f9c3cb04cd83efe5916793a4
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=56eea84e15049204f9c3cb04cd83efe5916793a4

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-12-09 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 73ac1d8f11238b913aad00acddc4e0a897050bfa
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=73ac1d8f11238b913aad00acddc4e0a897050bfa

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-11-28 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 4c72a7cdc7623a4efb672e0e49e2b2ad13fb
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=4c72a7cdc7623a4efb672e0e49e2b2ad13fb

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-11-21 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 693774829978464af7bc5e10f824708b9726b286
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=693774829978464af7bc5e10f824708b9726b286

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-11-15 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 320adc782322f91bb88a691a23781d7c29b30266
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=320adc782322f91bb88a691a23781d7c29b30266

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-10-17 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: b2963147965e495edf307cd53d5b5c591203b426
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=b2963147965e495edf307cd53d5b5c591203b426

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-09-22 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 7b7d6b2ac8214ab4d9a77e9128e1434cf46a3f85
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7b7d6b2ac8214ab4d9a77e9128e1434cf46a3f85

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-04-12 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 3fbb01e1e0bbf0dd479f8905912fdf4bcc770dd2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3fbb01e1e0bbf0dd479f8905912fdf4bcc770dd2

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-03-20 Thread git repository hosting
Module: xenomai-3
Branch: wip/setsched-norelax
Commit: 3941766a289a7bbcf6a85989e37474859c7bb6b2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3941766a289a7bbcf6a85989e37474859c7bb6b2

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-03-19 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 3fbb01e1e0bbf0dd479f8905912fdf4bcc770dd2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3fbb01e1e0bbf0dd479f8905912fdf4bcc770dd2

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+*/
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: use lazy schedparam propagation

2016-03-19 Thread git repository hosting
Module: xenomai-3
Branch: wip/setsched-norelax
Commit: 543545735d384a7b9e9e0dcc39a372225c5700b2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=543545735d384a7b9e9e0dcc39a372225c5700b2

Author: Philippe Gerum 
Date:   Fri Mar 18 12:12:27 2016 +0100

lib/cobalt: use lazy schedparam propagation

Do not switch to secondary mode upon schedparam updates for
propagating changes to the regular kernel, if the caller runs in
primary mode when entering pthread_setschedparam*() or
sched_setscheduler(). In such a case, the update request to the
regular kernel is left pending until the target thread resumes
execution in relaxed mode, at which point it is committed.

CAUTION: This mechanism won't update the schedparams cached by the
glibc for the caller in user-space, but this is the deal: we don't
relax threads which issue pthread_setschedparam[_ex]() from primary
mode anymore, but then only the kernel side (Cobalt and the host
kernel) will be aware of the change, and glibc might cache obsolete
information.

If the caller already runs in relaxed mode on entry to these services,
the update request takes place immediately, via the regular (g)libc
calls.

In any case, the new scheduling parameters for the target thread are
immediately applied by Cobalt, regardless of the update path followed
for the regular kernel.

---

 lib/cobalt/internal.c  |   44 ++
 lib/cobalt/sched.c |   13 
 lib/cobalt/sigshadow.c |8 +
 lib/cobalt/thread.c|   80 +---
 4 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b89db5..cb1d53b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -514,3 +514,47 @@ int cobalt_sched_weighted_prio(int policy,
 {
return XENOMAI_SYSCALL2(sc_cobalt_sched_weightprio, policy, param_ex);
 }
+
+int cobalt_xlate_schedparam(int policy,
+   const struct sched_param_ex *param_ex,
+   struct sched_param *param)
+{
+   int std_policy, priority;
+
+   /*
+* Translates Cobalt scheduling parameters to native ones,
+* based on a best approximation for Cobalt policies which are
+* not available from the host kernel.
+*/
+   std_policy = policy;
+   priority = param_ex->sched_priority;
+
+   switch (policy) {
+   case SCHED_WEAK:
+   std_policy = priority ? SCHED_FIFO : SCHED_OTHER;
+   break;
+   default:
+   std_policy = SCHED_FIFO;
+   /* falldown wanted. */
+   case SCHED_OTHER:
+   case SCHED_FIFO:
+   case SCHED_RR:
+   /*
+* The Cobalt priority range is larger than those of
+* the native SCHED_FIFO/RR classes, so we have to cap
+* the priority value accordingly.  We also remap
+* "weak" (negative) priorities - which are only
+* meaningful for the Cobalt core - to regular values.
+*/
+   if (priority > __cobalt_std_fifo_maxpri)
+   priority = __cobalt_std_fifo_maxpri;
+   }
+
+   if (priority < 0)
+   priority = -priority;
+   
+   memset(param, 0, sizeof(*param));
+   param->sched_priority = priority;
+
+   return std_policy;
+}
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index b0292b5..87b9235 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include "current.h"
 #include "internal.h"
 
 /**
@@ -297,11 +296,13 @@ int sched_setscheduler_ex(pid_t pid,
return EINVAL;
 
/* See pthread_setschedparam_ex(). */
-   
-   std_policy = cobalt_xlate_schedparam(policy, param_ex, _param);
-   ret = __STD(sched_setscheduler(pid, std_policy, _param));
-   if (ret)
-   return errno;
+
+   if (cobalt_is_relaxed()) {
+   std_policy = cobalt_xlate_schedparam(policy, param_ex, 
_param);
+   ret = __STD(sched_setscheduler(pid, std_policy, _param));
+   if (ret)
+   return errno;
+   }
 
ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
pid, policy, param_ex,
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 3f4e9c5..48d5a81 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -59,6 +59,14 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si, void 
*ctxt)
skip = nr > 3 ? 3 : 0;
XENOMAI_SYSCALL3(sc_cobalt_backtrace, nr - skip, frames + skip, 
arg);
break;
+   case SIGSHADOW_ACTION_HOME:
+   /*
+* We have been asked to call home from the current
+* context: sending a query for retrieving our handle
+* will just do this.
+