[Xenomai-git] Philippe Gerum : lib/cobalt: introduce sched_getconfig_np()

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: cab30346a84b0666e14cea6ed421b99d2d9ef408
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=cab30346a84b0666e14cea6ed421b99d2d9ef408

Author: Philippe Gerum r...@xenomai.org
Date:   Sun Dec 22 17:07:06 2013 +0100

lib/cobalt: introduce sched_getconfig_np()

---

 include/cobalt/sched.h|   11 +--
 include/cobalt/uapi/sched.h   |   13 -
 include/cobalt/uapi/syscall.h |1 +
 lib/cobalt/thread.c   |   18 +-
 testsuite/unit/sched-tp.c |   19 ++-
 5 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/include/cobalt/sched.h b/include/cobalt/sched.h
index ece501c..bfdff69 100644
--- a/include/cobalt/sched.h
+++ b/include/cobalt/sched.h
@@ -20,6 +20,7 @@
 
 #pragma GCC system_header
 #include_next sched.h
+#include sys/types.h
 #include cobalt/wrappers.h
 #include cobalt/uapi/sched.h
 
@@ -41,17 +42,15 @@ int __sched_cpucount(size_t __setsize, const cpu_set_t 
*__setp);
 void __sched_cpufill(size_t __setsize, cpu_set_t *__setp);
 #endif /* !CPU_COUNT */
 
-#define sched_tp_confsz(nr_win) \
-  (sizeof(struct __sched_config_tp) + nr_win * sizeof(struct sched_tp_window))
-
-#define sched_quota_confsz()  sizeof(struct __sched_config_quota)
-
 #ifdef __cplusplus
 extern C {
 #endif
 
 int sched_setconfig_np(int cpu, int policy,
-  union sched_config *config, size_t len);
+  const union sched_config *config, size_t len);
+
+ssize_t sched_getconfig_np(int cpu, int policy,
+  union sched_config *config, size_t *len_r);
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index d458376..11bbc1a 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -62,6 +62,9 @@ struct __sched_config_tp {
struct sched_tp_window windows[0];
 };
 
+#define sched_tp_confsz(nr_win) \
+  (sizeof(struct __sched_config_tp) + nr_win * sizeof(struct sched_tp_window))
+
 #ifndef SCHED_QUOTA
 #define SCHED_QUOTA12
 #define sched_quota_group  sched_u.quota.__sched_group
@@ -74,7 +77,8 @@ struct __sched_quota_param {
 enum {
sched_quota_add,
sched_quota_remove,
-   sched_quota_set
+   sched_quota_set,
+   sched_quota_get,
 };
 
 struct __sched_config_quota {
@@ -90,8 +94,15 @@ struct __sched_config_quota {
int quota;
int quota_peak;
} set;
+   struct {
+   int tgid;
+   int *quota_r;
+   int *quota_peak_r;
+   } get;
 };
 
+#define sched_quota_confsz()  sizeof(struct __sched_config_quota)
+
 struct sched_param_ex {
int sched_priority;
union {
diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index ed60c35..f8d1511 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -112,5 +112,6 @@
 #define sc_cobalt_event_sync91
 #define sc_cobalt_event_destroy 92
 #define sc_cobalt_sched_setconfig_np   93
+#define sc_cobalt_sched_getconfig_np   94
 
 #endif /* !_COBALT_UAPI_SYSCALL_H */
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index bf3c22b..5fabf9a 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -438,13 +438,29 @@ int pthread_probe_np(pid_t tid)
 }
 
 int sched_setconfig_np(int cpu, int policy,
-  union sched_config *config, size_t len)
+  const union sched_config *config, size_t len)
 {
return -XENOMAI_SKINCALL4(__cobalt_muxid,
  sc_cobalt_sched_setconfig_np,
  cpu, policy, config, len);
 }
 
+ssize_t sched_getconfig_np(int cpu, int policy,
+  union sched_config *config, size_t *len_r)
+{
+   ssize_t ret;
+
+   ret = XENOMAI_SKINCALL4(__cobalt_muxid,
+   sc_cobalt_sched_getconfig_np,
+   cpu, policy, config, *len_r);
+   if (ret  0)
+   return -ret;
+
+   *len_r = ret;
+
+   return 0;
+}
+
 COBALT_IMPL(int, pthread_kill, (pthread_t thread, int sig))
 {
int ret;
diff --git a/testsuite/unit/sched-tp.c b/testsuite/unit/sched-tp.c
index d051238..271a7ff 100644
--- a/testsuite/unit/sched-tp.c
+++ b/testsuite/unit/sched-tp.c
@@ -10,6 +10,7 @@
 #include stdio.h
 #include stdlib.h
 #include limits.h
+#include memory.h
 #include malloc.h
 #include unistd.h
 #include signal.h
@@ -94,7 +95,7 @@ int main(int argc, char **argv)
sigset_t mask, oldmask;
union sched_config *p;
size_t len;
-   int ret;
+   int ret, n;
 
mlockall(MCL_CURRENT | MCL_FUTURE);
 
@@ -150,6 +151,22 @@ int main(int argc, char **argv)
if (ret)
error(1, ret, sched_setconfig_np);
 
+   memset(p, 0xa5, len);
+
+   ret = sched_getconfig_np(0, SCHED_TP, p, len);
+   if (ret)
+   

[Xenomai-git] Philippe Gerum : lib/cobalt: enable SCHED_QUOTA policy

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 32664f7f1c30e7f23286307051ec45ed6c6af72f
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=32664f7f1c30e7f23286307051ec45ed6c6af72f

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Dec 19 15:55:58 2013 +0100

lib/cobalt: enable SCHED_QUOTA policy

---

 include/cobalt/sched.h |2 ++
 lib/cobalt/thread.c|3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/sched.h b/include/cobalt/sched.h
index fd53161..ece501c 100644
--- a/include/cobalt/sched.h
+++ b/include/cobalt/sched.h
@@ -44,6 +44,8 @@ void __sched_cpufill(size_t __setsize, cpu_set_t *__setp);
 #define sched_tp_confsz(nr_win) \
   (sizeof(struct __sched_config_tp) + nr_win * sizeof(struct sched_tp_window))
 
+#define sched_quota_confsz()  sizeof(struct __sched_config_quota)
+
 #ifdef __cplusplus
 extern C {
 #endif
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 89c1d46..bf3c22b 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -30,7 +30,7 @@
 #include internal.h
 #include boilerplate/ancillaries.h
 
-static pthread_attr_ex_t default_attr_ex;
+static pthread_attr_ex_t default_attr_ex; /* We want it zeroed at init. */
 
 static int linuxthreads;
 
@@ -59,6 +59,7 @@ static int libc_setschedparam(pthread_t thread,
case SCHED_COBALT:
case SCHED_TP:
case SCHED_SPORADIC:
+   case SCHED_QUOTA:
policy = SCHED_FIFO;
/*
 * Our priority range is larger than the regular


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/sched: introduce sched_kick() handler for policy modules

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: cee27b2945f92857308dcde619a3e64607b5327e
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=cee27b2945f92857308dcde619a3e64607b5327e

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Dec 17 19:07:57 2013 +0100

cobalt/sched: introduce sched_kick() handler for policy modules

Scheduling policies may prevent threads from running based on some
extra state, by not returning them from the sched_pick() handler,
without reflecting such state with any block bit. Those threads remain
in the ready state from the scheduler core point of view, although
they won't be elected for running.

This behavior is typical of policies enforcing a runtime budget for
instance.

However, we also have to honor the request to move a thread out of
primary mode (i.e. shadow kicking). Therefore we need a way to tell
the policy module to release such thread temporarily, until it
eventually relaxes (e.g. sigwake - kick - relax).

To this end, the sched_kick() handler can be defined by policy modules
for dealing with this specific case. It is called for kicked threads
bearing the XNREADY bit, once all block bits have been lifted.

---

 include/cobalt/kernel/sched.h  |   19 +++
 kernel/cobalt/sched-idle.c |1 +
 kernel/cobalt/sched-rt.c   |1 +
 kernel/cobalt/sched-sporadic.c |1 +
 kernel/cobalt/sched-tp.c   |6 --
 kernel/cobalt/sched-weak.c |1 +
 kernel/cobalt/shadow.c |   34 +-
 7 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index addfd0c..d32a404 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -147,6 +147,7 @@ struct xnsched_class {
int (*sched_declare)(struct xnthread *thread,
 const union xnsched_policy_param *p);
void (*sched_forget)(struct xnthread *thread);
+   void (*sched_kick)(struct xnthread *thread);
 #ifdef CONFIG_XENO_OPT_VFILE
int (*sched_init_vfile)(struct xnsched_class *schedclass,
struct xnvfile_directory *vfroot);
@@ -581,6 +582,18 @@ static inline void xnsched_forget(struct xnthread *thread)
sched_class-sched_forget(thread);
 }
 
+static inline void xnsched_kick(struct xnthread *thread)
+{
+   struct xnsched_class *sched_class = thread-base_class;
+
+   xnthread_set_info(thread, XNKICKED);
+
+   if (sched_class-sched_kick)
+   sched_class-sched_kick(thread);
+
+   xnsched_set_resched(thread-sched);
+}
+
 #else /* !CONFIG_XENO_OPT_SCHED_CLASSES */
 
 /*
@@ -655,6 +668,12 @@ static inline void xnsched_forget(struct xnthread *thread)
__xnsched_rt_forget(thread);
 }
 
+static inline void xnsched_kick(struct xnthread *thread)
+{
+   xnthread_set_info(thread, XNKICKED);
+   xnsched_set_resched(thread-sched);
+}
+
 #endif /* !CONFIG_XENO_OPT_SCHED_CLASSES */
 
 /*@}*/
diff --git a/kernel/cobalt/sched-idle.c b/kernel/cobalt/sched-idle.c
index 51ce963..5127798 100644
--- a/kernel/cobalt/sched-idle.c
+++ b/kernel/cobalt/sched-idle.c
@@ -49,6 +49,7 @@ struct xnsched_class xnsched_class_idle = {
.sched_tick =   NULL,
.sched_rotate   =   NULL,
.sched_forget   =   NULL,
+   .sched_kick =   NULL,
.sched_declare  =   NULL,
.sched_pick =   xnsched_idle_pick,
.sched_setparam =   xnsched_idle_setparam,
diff --git a/kernel/cobalt/sched-rt.c b/kernel/cobalt/sched-rt.c
index c92b0a0..c5001fc 100644
--- a/kernel/cobalt/sched-rt.c
+++ b/kernel/cobalt/sched-rt.c
@@ -244,6 +244,7 @@ struct xnsched_class xnsched_class_rt = {
.sched_tick =   xnsched_rt_tick,
.sched_rotate   =   xnsched_rt_rotate,
.sched_forget   =   NULL,
+   .sched_kick =   NULL,
.sched_declare  =   NULL,
.sched_setparam =   xnsched_rt_setparam,
.sched_trackprio=   xnsched_rt_trackprio,
diff --git a/kernel/cobalt/sched-sporadic.c b/kernel/cobalt/sched-sporadic.c
index 8f9d3b1..a523391 100644
--- a/kernel/cobalt/sched-sporadic.c
+++ b/kernel/cobalt/sched-sporadic.c
@@ -536,6 +536,7 @@ struct xnsched_class xnsched_class_sporadic = {
.sched_trackprio=   xnsched_sporadic_trackprio,
.sched_declare  =   xnsched_sporadic_declare,
.sched_forget   =   xnsched_sporadic_forget,
+   .sched_kick =   NULL,
 #ifdef CONFIG_XENO_OPT_VFILE
.sched_init_vfile   =   xnsched_sporadic_init_vfile,
.sched_cleanup_vfile=   xnsched_sporadic_cleanup_vfile,
diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c
index 03c6d67..bf30c7a 100644
--- a/kernel/cobalt/sched-tp.c
+++ 

[Xenomai-git] Gilles Chanteperdrix : cobalt/registry: add unlink service

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: f470bba259308633cdab24c257a522069767f7a8
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=f470bba259308633cdab24c257a522069767f7a8

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Mon Dec  9 22:04:38 2013 +0100

cobalt/registry: add unlink service

---

 include/cobalt/kernel/registry.h |2 ++
 kernel/cobalt/registry.c |   43 ++
 2 files changed, 45 insertions(+)

diff --git a/include/cobalt/kernel/registry.h b/include/cobalt/kernel/registry.h
index d2906db..6c25eee 100644
--- a/include/cobalt/kernel/registry.h
+++ b/include/cobalt/kernel/registry.h
@@ -184,6 +184,8 @@ void *xnregistry_fetch(xnhandle_t handle);
 
 unsigned long xnregistry_put(xnhandle_t handle);
 
+int xnregistry_unlink(const char *key);
+
 extern struct xnpnode_ops xnregistry_vfsnap_ops;
 
 extern struct xnpnode_ops xnregistry_vlink_ops;
diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index cebd5f0..004bc96 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -881,6 +881,49 @@ unlock_and_exit:
 EXPORT_SYMBOL_GPL(xnregistry_remove);
 
 /**
+ * Turn a named object into an anonymous object
+ */
+int xnregistry_unlink(const char *key)
+{
+   struct xnobject *object;
+   int ret = 0;
+   spl_t s;
+
+   xnlock_get_irqsave(nklock, s);
+
+   object = registry_hash_find(key);
+   if (object == NULL) {
+   ret = -ESRCH;
+   goto unlock_and_exit;
+   }
+   
+   ret = registry_hash_remove(object);
+   if (ret  0)
+   goto unlock_and_exit;
+
+#ifdef CONFIG_XENO_OPT_VFILE
+   if (object-pnode) {
+   registry_unexport_pnode(object);
+   /*
+* Leave the update of the object queues to
+* the work callback if it has been kicked.
+*/
+   if (object-pnode)
+   goto unlock_and_exit;
+   }
+#endif /* CONFIG_XENO_OPT_VFILE */
+
+   list_del(object-link);
+   
+   object-key = NULL;
+
+unlock_and_exit:
+   xnlock_put_irqrestore(nklock, s);
+
+   return ret;
+}
+
+/**
  * @fn int xnregistry_remove_safe(xnhandle_t handle,xnticks_t timeout)
  * @brief Unregister an idle real-time object.
  *


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/shadow: force runaway thread out of primary mode upon signal

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: fdd9004f642299d7351d8d69c4d26281fbf995ee
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=fdd9004f642299d7351d8d69c4d26281fbf995ee

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Dec 18 12:09:14 2013 +0100

cobalt/shadow: force runaway thread out of primary mode upon signal

---

 kernel/cobalt/shadow.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 1a9b519..0a40e83 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -2468,7 +2468,7 @@ static int handle_sigwake_event(struct task_struct *p)
if (p-state  (TASK_INTERRUPTIBLE|TASK_UNINTERRUPTIBLE))
set_task_state(p, p-state | TASK_NOWAKEUP);
 
-   force_wakeup(thread);
+   __xnshadow_kick(thread);
 
xnsched_run();
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Gilles Chanteperdrix : cobalt/mutex: export through registry

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 6d4f960c7f1e065c90129395c6ca47d64f6b6d72
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=6d4f960c7f1e065c90129395c6ca47d64f6b6d72

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Thu Dec  5 22:07:48 2013 +0100

cobalt/mutex: export through registry

---

 include/cobalt/uapi/mutex.h |2 +-
 kernel/cobalt/posix/mutex.c |  127 +--
 kernel/cobalt/posix/mutex.h |1 +
 3 files changed, 88 insertions(+), 42 deletions(-)

diff --git a/include/cobalt/uapi/mutex.h b/include/cobalt/uapi/mutex.h
index dec09e2..88c95e7 100644
--- a/include/cobalt/uapi/mutex.h
+++ b/include/cobalt/uapi/mutex.h
@@ -32,7 +32,7 @@ union cobalt_mutex_union {
struct __shadow_mutex {
unsigned int magic;
unsigned int lockcnt;
-   struct cobalt_mutex *mutex;
+   xnhandle_t handle;
union {
unsigned int dat_offset;
struct mutex_dat *dat;
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index 2b1c515..c94ed79 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -62,6 +62,7 @@ static int cobalt_mutex_init_inner(struct __shadow_mutex 
*shadow,
struct xnsys_ppd *sys_ppd;
struct cobalt_kqueues *kq;
spl_t s;
+   int err;
 
if (!attr)
attr = cobalt_default_mutex_attr;
@@ -71,9 +72,12 @@ static int cobalt_mutex_init_inner(struct __shadow_mutex 
*shadow,
 
kq = cobalt_kqueues(attr-pshared);
sys_ppd = xnsys_ppd_get(attr-pshared);
+   err = xnregistry_enter(, mutex, shadow-handle, NULL);
+   if (err  0)
+   return err;
 
+   mutex-handle = shadow-handle;
shadow-magic = COBALT_MUTEX_MAGIC;
-   shadow-mutex = mutex;
shadow-lockcnt = 0;
 
shadow-attr = *attr;
@@ -97,12 +101,21 @@ static int cobalt_mutex_init_inner(struct __shadow_mutex 
*shadow,
return 0;
 }
 
-static void cobalt_mutex_destroy_inner(struct cobalt_mutex *mutex,
-  struct cobalt_kqueues *q)
+static void 
+cobalt_mutex_destroy_inner(xnhandle_t handle, struct cobalt_kqueues *q)
 {
+   struct cobalt_mutex *mutex;
spl_t s;
 
xnlock_get_irqsave(nklock, s);
+   mutex = xnregistry_fetch(handle);
+   if (!cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, typeof(*mutex))) {
+   xnlock_put_irqrestore(nklock, s);
+   printk(mutex_destroy: invalid mutex %x\n, 
+   mutex ? mutex-magic : ~0);
+   return;
+   }
+   xnregistry_remove(handle);
list_del(mutex-link);
/*
 * synchbase wait queue may not be empty only when this
@@ -110,6 +123,7 @@ static void cobalt_mutex_destroy_inner(struct cobalt_mutex 
*mutex,
 * absence of xnsched_run().
 */
xnsynch_destroy(mutex-synchbase);
+   cobalt_mark_deleted(mutex);
xnlock_put_irqrestore(nklock, s);
 
xnheap_free(xnsys_ppd_get(mutex-attr.pshared)-sem_heap,
@@ -240,30 +254,23 @@ int cobalt_mutex_timedlock_break(struct cobalt_mutex 
*mutex,
 
 int cobalt_mutex_check_init(struct __shadow_mutex __user *u_mx)
 {
-   struct list_head *mutexq, *entry;
struct cobalt_mutex *mutex;
-   int qnr;
+   xnhandle_t handle;
+   int err;
spl_t s;
 
-   __xn_get_user(mutex, u_mx-mutex);
+   __xn_get_user(handle, u_mx-handle);
 
-   for (qnr = 0; qnr  2; qnr++) {
-   mutexq = cobalt_kqueues(qnr)-mutexq;
-   xnlock_get_irqsave(nklock, s);
-   if (!list_empty(mutexq)) {
-   list_for_each(entry, mutexq) {
-   if (entry == mutex-link)
-   goto busy;
-   }
-   }
-   xnlock_put_irqrestore(nklock, s);
-   }
+   xnlock_get_irqsave(nklock, s);
+   mutex = xnregistry_fetch(handle);
+   if (cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, typeof(*mutex)))
+   /* mutex is already in a queue. */
+   err = -EBUSY;
+   else
+   err = 0;
 
-   return 0;
-busy:
xnlock_put_irqrestore(nklock, s);
-   /* mutex is already in a queue. */
-   return -EBUSY;
+   return err;
 }
 
 int cobalt_mutex_init(struct __shadow_mutex __user *u_mx,
@@ -313,23 +320,39 @@ int cobalt_mutex_destroy(struct __shadow_mutex __user 
*u_mx)
 {
struct cobalt_mutex *mutex;
struct __shadow_mutex mx;
+   spl_t s;
+   int err;
 
if (__xn_safe_copy_from_user(mx, u_mx, sizeof(mx)))
return -EFAULT;
 
-   mutex = mx.mutex;
-   if (cobalt_kqueues(mutex-attr.pshared) != mutex-owningq)
-   return -EPERM;
+   xnlock_get_irqsave(nklock, s);
+   mutex = xnregistry_fetch(mx.handle);
+   

[Xenomai-git] Philippe Gerum : testsuite/unit: introduce SCHED_QUOTA policy test

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 9a4b509785eee57aa565bcd647a5fbd5e69accc8
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=9a4b509785eee57aa565bcd647a5fbd5e69accc8

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Dec 19 15:57:07 2013 +0100

testsuite/unit: introduce SCHED_QUOTA policy test

---

 config/libtool.m4|   12 +-
 configure|   12 +-
 testsuite/unit/Makefile.am   |   15 ++
 testsuite/unit/Makefile.in   |   50 ++-
 testsuite/unit/sched-quota.c |  312 ++
 5 files changed, 392 insertions(+), 9 deletions(-)

diff --git a/config/libtool.m4 b/config/libtool.m4
index 5f0..126202f 100644
--- a/config/libtool.m4
+++ b/config/libtool.m4
@@ -1312,7 +1312,7 @@ ia64-*-hpux*)
   rm -rf conftest*
   ;;
 
-x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \
 s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
   # Find out which ABI we are using.
   echo 'int i;'  conftest.$ac_ext
@@ -1326,7 +1326,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
  x86_64-*linux*)
LD=${LD-ld} -m elf_i386
;;
- ppc64-*linux*|powerpc64-*linux*)
+ powerpcle-*linux*)
+   LD=${LD-ld} -m elf32lppclinux
+   ;;
+ powerpc-*linux*)
LD=${LD-ld} -m elf32ppclinux
;;
  s390x-*linux*)
@@ -1345,7 +1348,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
  x86_64-*linux*)
LD=${LD-ld} -m elf_x86_64
;;
- ppc*-*linux*|powerpc*-*linux*)
+ powerpcle-*linux*)
+   LD=${LD-ld} -m elf64lppc
+   ;;
+ powerpc-*linux*)
LD=${LD-ld} -m elf64ppc
;;
  s390*-*linux*|s390*-*tpf*)
diff --git a/configure b/configure
index 50133f3..304e833 100755
--- a/configure
+++ b/configure
@@ -7736,7 +7736,7 @@ ia64-*-hpux*)
   rm -rf conftest*
   ;;
 
-x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \
 s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
   # Find out which ABI we are using.
   echo 'int i;'  conftest.$ac_ext
@@ -7754,7 +7754,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
  x86_64-*linux*)
LD=${LD-ld} -m elf_i386
;;
- ppc64-*linux*|powerpc64-*linux*)
+ powerpcle-*linux*)
+   LD=${LD-ld} -m elf32lppclinux
+   ;;
+ powerpc-*linux*)
LD=${LD-ld} -m elf32ppclinux
;;
  s390x-*linux*)
@@ -7773,7 +7776,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
  x86_64-*linux*)
LD=${LD-ld} -m elf_x86_64
;;
- ppc*-*linux*|powerpc*-*linux*)
+ powerpcle-*linux*)
+   LD=${LD-ld} -m elf64lppc
+   ;;
+ powerpc-*linux*)
LD=${LD-ld} -m elf64ppc
;;
  s390*-*linux*|s390*-*tpf*)
diff --git a/testsuite/unit/Makefile.am b/testsuite/unit/Makefile.am
index f292d48..a933d99 100644
--- a/testsuite/unit/Makefile.am
+++ b/testsuite/unit/Makefile.am
@@ -14,6 +14,7 @@ test_PROGRAMS += arith\
mutex-torture   \
cond-torture\
sched-tp\
+   sched-quota \
check-vdso
 
 arith_SOURCES = arith.c arith-noinline.c arith-noinline.h
@@ -76,6 +77,20 @@ sched_tp_LDADD = \
@XENO_USER_LDADD@   \
-lpthread -lrt -lm
 
+sched_quota_SOURCES = sched-quota.c
+
+sched_quota_CPPFLAGS = \
+   @XENO_USER_CFLAGS@  \
+   -I$(top_srcdir)/include
+
+sched_quota_LDFLAGS = $(XENO_POSIX_WRAPPERS)
+
+sched_quota_LDADD =\
+   ../../lib/copperplate/libcopperplate.la \
+   $(coredep_lib)  \
+   @XENO_USER_LDADD@   \
+   -lpthread -lrt -lm
+
 check_vdso_SOURCES = check-vdso.c
 
 check_vdso_CPPFLAGS =  \
diff --git a/testsuite/unit/Makefile.in b/testsuite/unit/Makefile.in
index 30868d9..80a9bab 100644
--- a/testsuite/unit/Makefile.in
+++ b/testsuite/unit/Makefile.in
@@ -84,6 +84,7 @@ test_PROGRAMS = wakeup-time$(EXEEXT) rtdm$(EXEEXT) 
$(am__EXEEXT_1)
 @XENO_COBALT_TRUE@ mutex-torture   \
 @XENO_COBALT_TRUE@ cond-torture\
 @XENO_COBALT_TRUE@ sched-tp\
+@XENO_COBALT_TRUE@ sched-quota \
 @XENO_COBALT_TRUE@ check-vdso
 
 subdir = testsuite/unit
@@ -106,7 +107,7 @@ CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
 @XENO_COBALT_TRUE@am__EXEEXT_1 = arith$(EXEEXT) mutex-torture$(EXEEXT) \
 @XENO_COBALT_TRUE@ cond-torture$(EXEEXT) sched-tp$(EXEEXT) \
-@XENO_COBALT_TRUE@ check-vdso$(EXEEXT)
+@XENO_COBALT_TRUE@ sched-quota$(EXEEXT) check-vdso$(EXEEXT)
 am__installdirs = $(DESTDIR)$(testdir)
 PROGRAMS = $(test_PROGRAMS)
 am__arith_SOURCES_DIST = arith.c arith-noinline.c 

[Xenomai-git] Philippe Gerum : cobalt/thread: allow changing thread priority from secondary mode

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 9b6513daf5fae678be8fb347c8c25a490e7210d9
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=9b6513daf5fae678be8fb347c8c25a490e7210d9

Author: Philippe Gerum r...@xenomai.org
Date:   Fri Dec 20 09:36:45 2013 +0100

cobalt/thread: allow changing thread priority from secondary mode

The former restriction on calling xnthread_set_schedparam() from
primary mode only is no more.

In addition, we introduce the inner __xnthread_set_schedparam()
routine for callers already running in atomic context.

---

 include/cobalt/kernel/thread.h |4 +++
 kernel/cobalt/sched-sporadic.c |4 +--
 kernel/cobalt/shadow.c |2 +-
 kernel/cobalt/thread.c |   69 +---
 4 files changed, 43 insertions(+), 36 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index aa2fd46..4223ddc 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -437,6 +437,10 @@ static inline void xnthread_migrate_passive(struct 
xnthread *thread,
 
 #endif
 
+int __xnthread_set_schedparam(struct xnthread *thread,
+ struct xnsched_class *sched_class,
+ const union xnsched_policy_param *sched_param);
+
 int xnthread_set_schedparam(struct xnthread *thread,
struct xnsched_class *sched_class,
const union xnsched_policy_param *sched_param);
diff --git a/kernel/cobalt/sched-sporadic.c b/kernel/cobalt/sched-sporadic.c
index 44438ab..8f9d3b1 100644
--- a/kernel/cobalt/sched-sporadic.c
+++ b/kernel/cobalt/sched-sporadic.c
@@ -86,7 +86,7 @@ static void sporadic_drop_handler(struct xntimer *timer)
p.pss.init_budget = 0;
p.pss.current_prio = pss-param.low_prio;
/* Move sporadic thread to the background. */
-   xnthread_set_schedparam(thread, 
xnsched_class_sporadic, p);
+   __xnthread_set_schedparam(thread, 
xnsched_class_sporadic, p);
}
}
 }
@@ -161,7 +161,7 @@ retry:
p.pss.init_budget = 0;
p.pss.current_prio = pss-param.normal_prio;
/* Move sporadic thread to the foreground. */
-   xnthread_set_schedparam(thread, xnsched_class_sporadic, p);
+   __xnthread_set_schedparam(thread, xnsched_class_sporadic, p);
}
 
/*
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 148bdc6..6105622 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -818,7 +818,7 @@ void __xnshadow_demote(struct xnthread *thread) /* nklock 
locked, irqs off */
param.rt.prio = 0;
sched_class = xnsched_class_rt;
 #endif
-   xnthread_set_schedparam(thread, sched_class, param);
+   __xnthread_set_schedparam(thread, sched_class, param);
 }
 
 void xnshadow_demote(struct xnthread *thread)
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 00d6c41..d05482f 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1780,11 +1780,7 @@ void xnthread_migrate_passive(struct xnthread *thread, 
struct xnsched *sched)
  * or ready thread moves it to the end of the runnable queue, thus
  * causing a manual round-robin.
  *
- * Environments:
- *
- * This service can be called from:
- *
- * - Primary mode only.
+ * Calling context: any.
  *
  * Rescheduling: never.
  *
@@ -1797,18 +1793,43 @@ int xnthread_set_schedparam(struct xnthread *thread,
struct xnsched_class *sched_class,
const union xnsched_policy_param *sched_param)
 {
-   int old_wprio, new_wprio, ret;
spl_t s;
-
-   primary_mode_only();
+   int ret;
 
xnlock_get_irqsave(nklock, s);
+   ret = __xnthread_set_schedparam(thread, sched_class, sched_param);
+   xnlock_put_irqrestore(nklock, s);
 
+   return ret;
+}
+EXPORT_SYMBOL_GPL(xnthread_set_schedparam);
+
+int __xnthread_set_schedparam(struct xnthread *thread,
+ struct xnsched_class *sched_class,
+ const union xnsched_policy_param *sched_param)
+{
+   int old_wprio, new_wprio, ret;
+
+   /*
+* NOTE: we do not prevent the caller from altering the
+* scheduling parameters of a thread that currently undergoes
+* a PIP boost.
+*
+* Rationale: Calling xnthread_set_schedparam() carelessly
+* with no consideration for resource management is a bug in
+* essence, and xnthread_set_schedparam() does not have to
+* paper over it, especially at the cost of more complexity
+* when dealing with multiple scheduling classes.
+*
+* In short, callers have to make sure that lowering a thread
+* priority is safe with respect to what their application
+* currently does.
+*/
 

[Xenomai-git] Gilles Chanteperdrix : cobalt/registry: export hash size function

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: b127b10822789ac8f69be62a605d9f941fec91f2
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=b127b10822789ac8f69be62a605d9f941fec91f2

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Fri Dec 20 00:27:44 2013 +0100

cobalt/registry: export hash size function

---

 include/cobalt/kernel/registry.h |2 ++
 kernel/cobalt/registry.c |   10 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/cobalt/kernel/registry.h b/include/cobalt/kernel/registry.h
index 7bbb99d..fea07ca 100644
--- a/include/cobalt/kernel/registry.h
+++ b/include/cobalt/kernel/registry.h
@@ -192,6 +192,8 @@ unsigned long xnregistry_put(xnhandle_t handle);
 
 int xnregistry_unlink(const char *key);
 
+unsigned xnregistry_hash_size(void);
+
 extern struct xnpnode_ops xnregistry_vfsnap_ops;
 
 extern struct xnpnode_ops xnregistry_vlink_ops;
diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 794a27e..7d5fe72 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -93,7 +93,7 @@ static struct xnvfile_regular usage_vfile = {
 
 #endif /* CONFIG_XENO_OPT_VFILE */
 
-int xnregistry_init(void)
+unsigned xnregistry_hash_size(void)
 {
static const int primes[] = {
101, 211, 307, 401, 503, 601,
@@ -104,6 +104,11 @@ int xnregistry_init(void)
 ((n)  sizeof(primes) / sizeof(int) ? \
  (n) : sizeof(primes) / sizeof(int) - 1)
 
+   return primes[obj_hash_max(CONFIG_XENO_OPT_REGISTRY_NRSLOTS / 100)];
+}
+
+int xnregistry_init(void)
+{
int n, ret __maybe_unused;
 
registry_obj_slots = kmalloc(CONFIG_XENO_OPT_REGISTRY_NRSLOTS *
@@ -143,8 +148,7 @@ int xnregistry_init(void)
list_get_entry(free_object_list, struct xnobject, link);
nr_active_objects = 1;
 
-   nr_object_entries =
-   primes[obj_hash_max(CONFIG_XENO_OPT_REGISTRY_NRSLOTS / 100)];
+   nr_object_entries = xnregistry_hash_size();
object_index = kmalloc(sizeof(*object_index) *
  nr_object_entries, GFP_KERNEL);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/sched-tp: set CPU affinity of the per-sched frame timer

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 1fe0a2f16746b82b9b0fcd163d3273ab33d1bd71
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1fe0a2f16746b82b9b0fcd163d3273ab33d1bd71

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Dec 10 16:21:25 2013 +0100

cobalt/sched-tp: set CPU affinity of the per-sched frame timer

---

 kernel/cobalt/sched-tp.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c
index 165ae1d..03c6d67 100644
--- a/kernel/cobalt/sched-tp.c
+++ b/kernel/cobalt/sched-tp.c
@@ -101,6 +101,7 @@ static void xnsched_tp_init(struct xnsched *sched)
tp-gps = NULL;
INIT_LIST_HEAD(tp-threads);
xntimer_init_noblock(tp-tf_timer, nkclock, tp_tick_handler, NULL);
+   xntimer_set_sched(tp-tf_timer, sched);
xntimer_set_name(tp-tf_timer, tp-tick);
 }
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/sched: always check policy settings

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 5d2c560b87a41c2bde8cb4a518fad1f5908b2473
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=5d2c560b87a41c2bde8cb4a518fad1f5908b2473

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Dec 21 16:00:08 2013 +0100

cobalt/sched: always check policy settings

---

 include/cobalt/kernel/sched.h |   17 +
 kernel/cobalt/sched.c |   11 +++
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index 065408f..870de29 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -538,6 +538,23 @@ static inline void xnsched_tick(struct xnsched *sched)
sched_class-sched_tick(sched);
 }
 
+static inline int xnsched_declare(struct xnsched_class *sched_class,
+ struct xnthread *thread,
+ const union xnsched_policy_param *p)
+{
+   int ret;
+
+   if (sched_class-sched_declare) {
+   ret = sched_class-sched_declare(thread, p);
+   if (ret)
+   return ret;
+   }
+   if (sched_class != thread-base_class)
+   sched_class-nthreads++;
+
+   return 0;
+}
+
 #ifdef CONFIG_XENO_OPT_SCHED_CLASSES
 
 static inline void xnsched_enqueue(struct xnthread *thread)
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index e8c012e..ffd50be 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -376,14 +376,9 @@ int xnsched_set_policy(struct xnthread *thread,
 * affect the previous class (such as touching thread-rlink
 * for instance).
 */
-   if (sched_class != thread-base_class) {
-   if (sched_class-sched_declare) {
-   ret = sched_class-sched_declare(thread, p);
-   if (ret)
-   return ret;
-   }
-   sched_class-nthreads++;
-   }
+   ret = xnsched_declare(sched_class, thread, p);
+   if (ret)
+   return ret;
 
/*
 * As a special case, we may be called from __xnthread_init()


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : copperplate/registry: detect SCHED_QUOTA policy for threads

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 1fb6de2c3d056850c8897625f27edb957ed4e2ff
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1fb6de2c3d056850c8897625f27edb957ed4e2ff

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Dec 19 15:56:37 2013 +0100

copperplate/registry: detect SCHED_QUOTA policy for threads

---

 lib/copperplate/regd/fs-common.c |5 +
 1 file changed, 5 insertions(+)

diff --git a/lib/copperplate/regd/fs-common.c b/lib/copperplate/regd/fs-common.c
index d4e2b78..96a4f87 100644
--- a/lib/copperplate/regd/fs-common.c
+++ b/lib/copperplate/regd/fs-common.c
@@ -158,6 +158,11 @@ ssize_t read_threads(struct fsobj *fsobj, char *buf,
sched_class = tp;
break;
 #endif
+#ifdef SCHED_QUOTA
+   case SCHED_QUOTA:
+   sched_class = quota;
+   break;
+#endif
default:
sched_class = other;
break;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/sched: tp: include CPU number in timer name (SMP)

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: fa76b0a190fe08d3f2f750434e61b4ec70e6efc8
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=fa76b0a190fe08d3f2f750434e61b4ec70e6efc8

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Dec 21 17:37:24 2013 +0100

cobalt/sched: tp: include CPU number in timer name (SMP)

---

 kernel/cobalt/sched-tp.c |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c
index bf30c7a..ce834df 100644
--- a/kernel/cobalt/sched-tp.c
+++ b/kernel/cobalt/sched-tp.c
@@ -85,6 +85,7 @@ static void tp_tick_handler(struct xntimer *timer)
 static void xnsched_tp_init(struct xnsched *sched)
 {
struct xnsched_tp *tp = sched-tp;
+   char timer_name[XNOBJECT_NAME_LEN];
int n;
 
/*
@@ -98,12 +99,17 @@ static void xnsched_tp_init(struct xnsched *sched)
xnsched_initq(tp-idle.runnable,
  XNSCHED_RT_MIN_PRIO, XNSCHED_RT_MAX_PRIO);
 
+#ifdef CONFIG_SMP
+   sprintf(timer_name, [tp-tick/%u], sched-cpu);
+#else
+   strcpy(timer_name, [tp-tick]);
+#endif
tp-tps = NULL;
tp-gps = NULL;
INIT_LIST_HEAD(tp-threads);
xntimer_init_noblock(tp-tf_timer, nkclock, tp_tick_handler, NULL);
xntimer_set_sched(tp-tf_timer, sched);
-   xntimer_set_name(tp-tf_timer, tp-tick);
+   xntimer_set_name(tp-tf_timer, timer_name);
 }
 
 static void xnsched_tp_setparam(struct xnthread *thread,


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/cond: export through registry

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 48718f9697e8e8ceca952dae6249a72f47ea23cf
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=48718f9697e8e8ceca952dae6249a72f47ea23cf

Author: Philippe Gerum r...@xenomai.org
Date:   Fri Dec 20 09:11:16 2013 +0100

cobalt/cond: export through registry

---

 include/cobalt/uapi/cond.h |2 +-
 kernel/cobalt/posix/cond.c |   72 +---
 kernel/cobalt/posix/cond.h |1 +
 3 files changed, 50 insertions(+), 25 deletions(-)

diff --git a/include/cobalt/uapi/cond.h b/include/cobalt/uapi/cond.h
index de37315..0c6157a 100644
--- a/include/cobalt/uapi/cond.h
+++ b/include/cobalt/uapi/cond.h
@@ -27,7 +27,7 @@ union cobalt_cond_union {
struct __shadow_cond {
unsigned int magic;
struct cobalt_condattr attr;
-   struct cobalt_cond *cond;
+   xnhandle_t handle;
union {
unsigned int pending_signals_offset;
unsigned long *pending_signals;
diff --git a/kernel/cobalt/posix/cond.c b/kernel/cobalt/posix/cond.c
index 571bdc7..87dd09d 100644
--- a/kernel/cobalt/posix/cond.c
+++ b/kernel/cobalt/posix/cond.c
@@ -54,16 +54,24 @@
 #include clock.h
 
 static inline void
-cond_destroy_internal(struct cobalt_cond *cond, struct cobalt_kqueues *q)
+cond_destroy_internal(xnhandle_t handle, struct cobalt_kqueues *q)
 {
+   struct cobalt_cond *cond;
spl_t s;
 
xnlock_get_irqsave(nklock, s);
+   cond = xnregistry_fetch(handle);
+   if (!cobalt_obj_active(cond, COBALT_COND_MAGIC, typeof(*cond))) {
+   xnlock_put_irqrestore(nklock, s);
+   return;
+   }
+   xnregistry_remove(handle);
list_del(cond-link);
/* synchbase wait queue may not be empty only when this function is
   called from cobalt_cond_pkg_cleanup, hence the absence of
   xnsched_run(). */
xnsynch_destroy(cond-synchbase);
+   cobalt_mark_deleted(cond);
xnlock_put_irqrestore(nklock, s);
xnheap_free(xnsys_ppd_get(cond-attr.pshared)-sem_heap,
cond-pending_signals);
@@ -99,9 +107,9 @@ static inline int
 pthread_cond_init(struct __shadow_cond *cnd, const pthread_condattr_t *attr)
 {
int synch_flags = XNSYNCH_PRIO | XNSYNCH_NOPIP, err;
-   struct list_head *condq, *entry;
+   struct cobalt_cond *cond, *old_cond;
+   struct list_head *condq;
struct xnsys_ppd *sys_ppd;
-   struct cobalt_cond *cond;
spl_t s;
 
if (attr == NULL)
@@ -139,18 +147,23 @@ pthread_cond_init(struct __shadow_cond *cnd, const 
pthread_condattr_t *attr)
if (cnd-magic != COBALT_COND_MAGIC || list_empty(condq))
goto do_init;
 
-   list_for_each(entry, condq) {
-   if (entry == cnd-cond-link) {
-   if (attr-pshared) {
-   cond_destroy_internal(cnd-cond,
- cobalt_kqueues(1));
-   goto do_init;
-   }
-   err = -EBUSY;
-   goto err_free_pending_signals;
-   }
+   old_cond = xnregistry_fetch(cnd-handle);
+   if (!cobalt_obj_active(old_cond, COBALT_COND_MAGIC, typeof(*old_cond)))
+   goto do_init;
+
+   if (attr-pshared == 0) {
+   err = -EBUSY;
+   goto err_free_pending_signals;
}
+   xnlock_put_irqrestore(nklock, s);
+   cond_destroy_internal(cnd-handle, cobalt_kqueues(1));
+   xnlock_get_irqsave(nklock, s);
 do_init:
+   err = xnregistry_enter(, cond, cond-handle, NULL);
+   if (err  0)
+   goto err_free_pending_signals;
+
+   cnd-handle = cond-handle;
cnd-attr = *attr;
cnd-pending_signals_offset =
xnheap_mapped_offset(sys_ppd-sem_heap,
@@ -158,7 +171,6 @@ do_init:
cnd-mutex_datp = (struct mutex_dat *)~0UL;
 
cnd-magic = COBALT_COND_MAGIC;
-   cnd-cond = cond;
 
cond-magic = COBALT_COND_MAGIC;
xnsynch_init(cond-synchbase, synch_flags, NULL);
@@ -205,11 +217,16 @@ do_init:
 static inline int pthread_cond_destroy(struct __shadow_cond *cnd)
 {
struct cobalt_cond *cond;
+   int pshared;
spl_t s;
 
xnlock_get_irqsave(nklock, s);
-
-   cond = cnd-cond;
+   cond = xnregistry_fetch(cnd-handle);
+   if (cond == NULL) {
+   xnlock_put_irqrestore(nklock, s);
+   return -EINVAL;
+   }
+   
if (!cobalt_obj_active(cnd, COBALT_COND_MAGIC, struct __shadow_cond)
|| !cobalt_obj_active(cond, COBALT_COND_MAGIC, struct cobalt_cond)) 
{
xnlock_put_irqrestore(nklock, s);
@@ -227,11 +244,10 @@ static inline int pthread_cond_destroy(struct 
__shadow_cond *cnd)
}
 
cobalt_mark_deleted(cnd);
-   cobalt_mark_deleted(cond);

[Xenomai-git] Philippe Gerum : lib/cobalt: introduce sched_getconfig_np()

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: cab30346a84b0666e14cea6ed421b99d2d9ef408
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=cab30346a84b0666e14cea6ed421b99d2d9ef408

Author: Philippe Gerum r...@xenomai.org
Date:   Sun Dec 22 17:07:06 2013 +0100

lib/cobalt: introduce sched_getconfig_np()

---

 include/cobalt/sched.h|   11 +--
 include/cobalt/uapi/sched.h   |   13 -
 include/cobalt/uapi/syscall.h |1 +
 lib/cobalt/thread.c   |   18 +-
 testsuite/unit/sched-tp.c |   19 ++-
 5 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/include/cobalt/sched.h b/include/cobalt/sched.h
index ece501c..bfdff69 100644
--- a/include/cobalt/sched.h
+++ b/include/cobalt/sched.h
@@ -20,6 +20,7 @@
 
 #pragma GCC system_header
 #include_next sched.h
+#include sys/types.h
 #include cobalt/wrappers.h
 #include cobalt/uapi/sched.h
 
@@ -41,17 +42,15 @@ int __sched_cpucount(size_t __setsize, const cpu_set_t 
*__setp);
 void __sched_cpufill(size_t __setsize, cpu_set_t *__setp);
 #endif /* !CPU_COUNT */
 
-#define sched_tp_confsz(nr_win) \
-  (sizeof(struct __sched_config_tp) + nr_win * sizeof(struct sched_tp_window))
-
-#define sched_quota_confsz()  sizeof(struct __sched_config_quota)
-
 #ifdef __cplusplus
 extern C {
 #endif
 
 int sched_setconfig_np(int cpu, int policy,
-  union sched_config *config, size_t len);
+  const union sched_config *config, size_t len);
+
+ssize_t sched_getconfig_np(int cpu, int policy,
+  union sched_config *config, size_t *len_r);
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index d458376..11bbc1a 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -62,6 +62,9 @@ struct __sched_config_tp {
struct sched_tp_window windows[0];
 };
 
+#define sched_tp_confsz(nr_win) \
+  (sizeof(struct __sched_config_tp) + nr_win * sizeof(struct sched_tp_window))
+
 #ifndef SCHED_QUOTA
 #define SCHED_QUOTA12
 #define sched_quota_group  sched_u.quota.__sched_group
@@ -74,7 +77,8 @@ struct __sched_quota_param {
 enum {
sched_quota_add,
sched_quota_remove,
-   sched_quota_set
+   sched_quota_set,
+   sched_quota_get,
 };
 
 struct __sched_config_quota {
@@ -90,8 +94,15 @@ struct __sched_config_quota {
int quota;
int quota_peak;
} set;
+   struct {
+   int tgid;
+   int *quota_r;
+   int *quota_peak_r;
+   } get;
 };
 
+#define sched_quota_confsz()  sizeof(struct __sched_config_quota)
+
 struct sched_param_ex {
int sched_priority;
union {
diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index ed60c35..f8d1511 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -112,5 +112,6 @@
 #define sc_cobalt_event_sync91
 #define sc_cobalt_event_destroy 92
 #define sc_cobalt_sched_setconfig_np   93
+#define sc_cobalt_sched_getconfig_np   94
 
 #endif /* !_COBALT_UAPI_SYSCALL_H */
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index bf3c22b..5fabf9a 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -438,13 +438,29 @@ int pthread_probe_np(pid_t tid)
 }
 
 int sched_setconfig_np(int cpu, int policy,
-  union sched_config *config, size_t len)
+  const union sched_config *config, size_t len)
 {
return -XENOMAI_SKINCALL4(__cobalt_muxid,
  sc_cobalt_sched_setconfig_np,
  cpu, policy, config, len);
 }
 
+ssize_t sched_getconfig_np(int cpu, int policy,
+  union sched_config *config, size_t *len_r)
+{
+   ssize_t ret;
+
+   ret = XENOMAI_SKINCALL4(__cobalt_muxid,
+   sc_cobalt_sched_getconfig_np,
+   cpu, policy, config, *len_r);
+   if (ret  0)
+   return -ret;
+
+   *len_r = ret;
+
+   return 0;
+}
+
 COBALT_IMPL(int, pthread_kill, (pthread_t thread, int sig))
 {
int ret;
diff --git a/testsuite/unit/sched-tp.c b/testsuite/unit/sched-tp.c
index d051238..271a7ff 100644
--- a/testsuite/unit/sched-tp.c
+++ b/testsuite/unit/sched-tp.c
@@ -10,6 +10,7 @@
 #include stdio.h
 #include stdlib.h
 #include limits.h
+#include memory.h
 #include malloc.h
 #include unistd.h
 #include signal.h
@@ -94,7 +95,7 @@ int main(int argc, char **argv)
sigset_t mask, oldmask;
union sched_config *p;
size_t len;
-   int ret;
+   int ret, n;
 
mlockall(MCL_CURRENT | MCL_FUTURE);
 
@@ -150,6 +151,22 @@ int main(int argc, char **argv)
if (ret)
error(1, ret, sched_setconfig_np);
 
+   memset(p, 0xa5, len);
+
+   ret = sched_getconfig_np(0, SCHED_TP, p, len);
+   if (ret)
+   

[Xenomai-git] Philippe Gerum : cobalt/posix: introduce sched_getconfig syscall

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 3dbaac04c94363c841b537099463918a682f550e
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=3dbaac04c94363c841b537099463918a682f550e

Author: Philippe Gerum r...@xenomai.org
Date:   Sun Dec 22 17:06:43 2013 +0100

cobalt/posix: introduce sched_getconfig syscall

This service retrieves the current scheduling parameters for a
particular policy on a given CPU (converse to sched_setconfig).

---

 include/cobalt/kernel/sched-quota.h |2 +
 include/cobalt/kernel/sched-tp.h|8 +-
 kernel/cobalt/posix/syscall.c   |1 +
 kernel/cobalt/posix/thread.c|  195 ---
 kernel/cobalt/posix/thread.h|7 +-
 kernel/cobalt/sched-quota.c |6 ++
 kernel/cobalt/sched-tp.c|   23 +
 7 files changed, 227 insertions(+), 15 deletions(-)

diff --git a/include/cobalt/kernel/sched-quota.h 
b/include/cobalt/kernel/sched-quota.h
index c3b44ba..d5e4bdd 100644
--- a/include/cobalt/kernel/sched-quota.h
+++ b/include/cobalt/kernel/sched-quota.h
@@ -40,6 +40,8 @@ struct xnsched_quota_group {
int nr_active;
int nr_threads;
int tgid;
+   int quota_percent;
+   int quota_peak_percent;
 };
 
 struct xnsched_quota {
diff --git a/include/cobalt/kernel/sched-tp.h b/include/cobalt/kernel/sched-tp.h
index 48da571..dad2f6d 100644
--- a/include/cobalt/kernel/sched-tp.h
+++ b/include/cobalt/kernel/sched-tp.h
@@ -36,6 +36,7 @@ struct xnsched_tp_window {
 struct xnsched_tp_schedule {
int pwin_nr;
xnticks_t tf_duration;
+   atomic_t refcount;
struct xnsched_tp_window pwins[0];
 };
 
@@ -77,6 +78,11 @@ void xnsched_tp_stop_schedule(struct xnsched *sched);
 
 int xnsched_tp_get_partition(struct xnsched *sched);
 
-#endif /* !CONFIG_XENO_OPT_SCHED_TP */
+struct xnsched_tp_schedule *
+xnsched_tp_get_schedule(struct xnsched *sched);
+
+void xnsched_tp_put_schedule(struct xnsched_tp_schedule *gps);
+
+#endif /* CONFIG_XENO_OPT_SCHED_TP */
 
 #endif /* !_COBALT_KERNEL_SCHED_TP_H */
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index e3a135d..374745f 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -169,6 +169,7 @@ static struct xnsyscall cobalt_syscalls[] = {
SKINCALL_DEF(sc_cobalt_event_wait, cobalt_event_wait, primary),
SKINCALL_DEF(sc_cobalt_event_sync, cobalt_event_sync, any),
SKINCALL_DEF(sc_cobalt_sched_setconfig_np, cobalt_sched_setconfig_np, 
any),
+   SKINCALL_DEF(sc_cobalt_sched_getconfig_np, cobalt_sched_getconfig_np, 
any),
 };
 
 struct xnpersonality cobalt_personality = {
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index bd15952..89f9640 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -1288,6 +1288,11 @@ int set_tp_config(int cpu, union sched_config *config, 
size_t len)
spl_t s;
int n;
 
+   if (config-tp.nr_windows == 0) {
+   gps = NULL;
+   goto set_schedule;
+   }
+
gps = xnmalloc(sizeof(*gps) + config-tp.nr_windows * sizeof(*w));
if (gps == NULL)
goto fail;
@@ -1316,17 +1321,18 @@ int set_tp_config(int cpu, union sched_config *config, 
size_t len)
next_offset += duration;
}
 
+   atomic_set(gps-refcount, 1);
gps-pwin_nr = n;
gps-tf_duration = next_offset;
+set_schedule:
sched = xnsched_struct(cpu);
-
xnlock_get_irqsave(nklock, s);
ogps = xnsched_tp_set_schedule(sched, gps);
xnsched_tp_start_schedule(sched);
xnlock_put_irqrestore(nklock, s);
 
if (ogps)
-   xnfree(ogps);
+   xnsched_tp_put_schedule(ogps);
 
return 0;
 
@@ -1336,10 +1342,68 @@ fail:
return -EINVAL;
 }
 
+static inline
+ssize_t get_tp_config(int cpu, union sched_config __user *u_config,
+ size_t len)
+{
+   struct xnsched_tp_window *pw, *w;
+   struct xnsched_tp_schedule *gps;
+   struct sched_tp_window *pp, *p;
+   union sched_config *config;
+   struct xnsched *sched;
+   ssize_t ret = 0, elen;
+   spl_t s;
+   int n;
+
+   xnlock_get_irqsave(nklock, s);
+
+   sched = xnsched_struct(cpu);
+   gps = xnsched_tp_get_schedule(sched);
+   if (gps == NULL) {
+   xnlock_put_irqrestore(nklock, s);
+   return 0;
+   }
+
+   xnlock_put_irqrestore(nklock, s);
+
+   elen = sched_tp_confsz(gps-pwin_nr);
+   if (elen  len) {
+   ret = -ENOSPC;
+   goto out;
+   }
+
+   config = xnmalloc(elen);
+   if (config == NULL) {
+   ret = -ENOMEM;
+   goto out;
+   }
+
+   config-tp.nr_windows = gps-pwin_nr;
+   for (n = 0, pp = p = config-tp.windows, pw = w = gps-pwins;
+n  gps-pwin_nr; pp = p, p++, pw = w, w++, n++) {
+   ns2ts(p-offset, 

[Xenomai-git] Philippe Gerum : copperplate/regd: detect SCHED_WEAK threads

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 433296d8fe12d296032af2db0335fee34cf56349
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=433296d8fe12d296032af2db0335fee34cf56349

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Dec 21 17:47:03 2013 +0100

copperplate/regd: detect SCHED_WEAK threads

---

 lib/copperplate/regd/fs-common.c |9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/lib/copperplate/regd/fs-common.c b/lib/copperplate/regd/fs-common.c
index 96a4f87..ea34148 100644
--- a/lib/copperplate/regd/fs-common.c
+++ b/lib/copperplate/regd/fs-common.c
@@ -148,21 +148,18 @@ ssize_t read_threads(struct fsobj *fsobj, char *buf,
case SCHED_RR:
sched_class = rr;
break;
-#ifdef SCHED_SPORADIC
case SCHED_SPORADIC:
sched_class = pss;
break;
-#endif
-#ifdef SCHED_TP
case SCHED_TP:
sched_class = tp;
break;
-#endif
-#ifdef SCHED_QUOTA
case SCHED_QUOTA:
sched_class = quota;
break;
-#endif
+   case SCHED_WEAK:
+   sched_class = weak;
+   break;
default:
sched_class = other;
break;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/assert: introduce XENO_WARNON, XENO_BUG

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: ed6f62c36fcbf4657f5e0ba74567e64edf288e9f
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=ed6f62c36fcbf4657f5e0ba74567e64edf288e9f

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Dec 19 15:36:49 2013 +0100

cobalt/assert: introduce XENO_WARNON, XENO_BUG

---

 include/cobalt/kernel/assert.h |9 +
 1 file changed, 9 insertions(+)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index 158d51f..63886a1 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -43,6 +43,15 @@
__FILE__, __LINE__, (#__cond)); \
} while (0)
 
+#define XENO_BUG(__subsys)  XENO_BUGON(__subsys, 1)
+
+#define XENO_WARNON(__subsys, __cond)  \
+   do {\
+   if (unlikely(XENO_DEBUG(__subsys)  (__cond))) \
+   printk(XENO_WARN assertion failed at %s:%d (%s), \
+   __FILE__, __LINE__, (#__cond)); \
+   } while (0)
+
 #ifndef CONFIG_XENO_OPT_DEBUG_NUCLEUS
 #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0
 #endif


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Gilles Chanteperdrix : testsuite: various improvements in leaks test

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 7a3c3d156a3fcaab52792dcb0c30d848cf1aadca
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=7a3c3d156a3fcaab52792dcb0c30d848cf1aadca

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Dec 15 19:54:36 2013 +0100

testsuite: various improvements in leaks test

Fix timer_create parameters to cope with timer_create API changes
(SIGEV_SIGNAL is no longer supported).  Add a fork test to verify
automatic objects destruction upon process termination.

---

 testsuite/regression/posix/leaks.c |   42 +++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/testsuite/regression/posix/leaks.c 
b/testsuite/regression/posix/leaks.c
index f368cae..4e8a769 100644
--- a/testsuite/regression/posix/leaks.c
+++ b/testsuite/regression/posix/leaks.c
@@ -9,6 +9,9 @@
 #include semaphore.h
 #include mqueue.h
 #include signal.h
+#include sys/types.h
+#include sys/wait.h
+#include linux/unistd.h
 #include cobalt/uapi/kernel/heap.h
 #include asm/xenomai/syscall.h
 
@@ -50,6 +53,28 @@ static void *empty(void *cookie)
return cookie;
 }
 
+static void subprocess_leak(void)
+{
+   struct sigevent sevt;
+   pthread_mutex_t mutex;
+   pthread_cond_t cond;
+   pthread_t thread;
+   sem_t sem, *psem;
+   timer_t tm;
+   int fd;
+
+   check_pthread(pthread_create(thread, NULL, empty, NULL));
+   check_pthread(pthread_mutex_init(mutex, NULL));
+   check_pthread(pthread_cond_init(cond, NULL));
+   check_unix(sem_init(sem, 0, 0));
+   check_unix(-!(psem = sem_open(SEM_NAME, O_CREAT, 0644, 1)));
+   sevt.sigev_notify = SIGEV_THREAD_ID;
+   sevt.sigev_signo = SIGALRM;
+   sevt.sigev_notify_thread_id = syscall(__NR_gettid);
+   check_unix(timer_create(CLOCK_MONOTONIC, sevt, tm));
+   check_unix(fd = mq_open(MQ_NAME, O_RDWR | O_CREAT, 0644, NULL));
+}
+
 int main(void)
 {
unsigned long long before;
@@ -60,6 +85,7 @@ int main(void)
pthread_t thread;
sem_t sem, *psem;
timer_t tm;
+   pid_t child;
 
mlockall(MCL_CURRENT|MCL_FUTURE);
 
@@ -93,8 +119,9 @@ int main(void)
check_used(named sem, before, failed);
 
before = get_used();
-   sevt.sigev_notify = SIGEV_SIGNAL;
+   sevt.sigev_notify = SIGEV_THREAD_ID;
sevt.sigev_signo = SIGALRM;
+   sevt.sigev_notify_thread_id = syscall(__NR_gettid);
check_unix(timer_create(CLOCK_MONOTONIC, sevt, tm));
check_unix(timer_delete(tm));
check_used(timer, before, failed);
@@ -105,5 +132,18 @@ int main(void)
check_unix(mq_unlink(MQ_NAME));
check_used(mq, before, failed);
 
+   before = get_used();
+   check_unix(child = fork());
+   if (!child) {
+   subprocess_leak();
+   return EXIT_SUCCESS;
+   }
+   while (waitpid(child, NULL, 0) == -1  errno == EINTR);
+   sleep(1);   /* Leave some time for xnheap
+* deferred free */
+   check_unix(sem_unlink(SEM_NAME));
+   check_unix(mq_unlink(MQ_NAME));
+   check_used(fork, before, failed);
+
return failed ? EXIT_FAILURE : EXIT_SUCCESS;
 }


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/powerpc: provide leave_root placeholder w/ fpu-less systems

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: d010f32f5c627f6ac2e4f80d4eb46fea499c5296
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=d010f32f5c627f6ac2e4f80d4eb46fea499c5296

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Nov 14 17:11:47 2013 +0100

cobalt/powerpc: provide leave_root placeholder w/ fpu-less systems

---

 kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h 
b/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h
index d93147d..10ccf2c 100644
--- a/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h
+++ b/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h
@@ -74,6 +74,7 @@ void xnarch_leave_root(struct xnthread *root);
 
 static inline void xnarch_init_root_tcb(struct xnthread *thread) { }
 static inline void xnarch_init_shadow_tcb(struct xnthread *thread) { }
+static inline void xnarch_leave_root(struct xnthread *root) { }
 
 #endif  /* !CONFIG_XENO_HW_FPU */
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Gilles Chanteperdrix : cobalt/semaphore: use semaphore count in user-space

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 8c1b69a6945fb70cfce579c517a1d534abb6fad8
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=8c1b69a6945fb70cfce579c517a1d534abb6fad8

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Dec  8 18:51:57 2013 +0100

cobalt/semaphore: use semaphore count in user-space

---

 lib/cobalt/semaphore.c |  141 ++--
 1 file changed, 102 insertions(+), 39 deletions(-)

diff --git a/lib/cobalt/semaphore.c b/lib/cobalt/semaphore.c
index c3a2668..fde4bfd 100644
--- a/lib/cobalt/semaphore.c
+++ b/lib/cobalt/semaphore.c
@@ -25,6 +25,18 @@
 #include asm/xenomai/syscall.h
 #include internal.h
 
+static inline struct sem_dat *sem_get_datp(struct __shadow_sem *shadow)
+{
+   unsigned pshared = shadow-datp_offset  0;
+   
+   if (pshared) 
+   return (struct sem_dat *)
+   (cobalt_sem_heap[1] - shadow-datp_offset);
+   else
+   return (struct sem_dat *)
+   (cobalt_sem_heap[0] + shadow-datp_offset);
+}
+
 COBALT_IMPL(int, sem_init, (sem_t *sem, int pshared, unsigned value))
 {
struct __shadow_sem *_sem = ((union cobalt_sem_union 
*)sem)-shadow_sem;
@@ -32,12 +44,13 @@ COBALT_IMPL(int, sem_init, (sem_t *sem, int pshared, 
unsigned value))
 
err = -XENOMAI_SKINCALL3(__cobalt_muxid,
 sc_cobalt_sem_init, _sem, pshared, value);
-   if (!err)
-   return 0;
-
-   errno = err;
-
-   return -1;
+   if (err  0) {
+   errno = err;
+   return -1;
+   }
+   
+   __cobalt_prefault(sem_get_datp(_sem));
+   return 0;
 }
 
 COBALT_IMPL(int, sem_destroy, (sem_t *sem))
@@ -62,6 +75,8 @@ COBALT_IMPL(int, sem_destroy, (sem_t *sem))
 COBALT_IMPL(int, sem_post, (sem_t *sem))
 {
struct __shadow_sem *_sem = ((union cobalt_sem_union 
*)sem)-shadow_sem;
+   struct sem_dat *datp;
+   long value;
int err;
 
if (_sem-magic != COBALT_SEM_MAGIC
@@ -70,6 +85,29 @@ COBALT_IMPL(int, sem_post, (sem_t *sem))
return -1;
}
 
+   datp = sem_get_datp(_sem);
+
+   value = atomic_long_read(datp-value);
+
+   if (value = 0) {
+   long old, new;
+   
+   if (datp-flags  SEM_PULSE)
+   return 0;
+
+   do {
+   old = value;
+   new = value + 1;
+
+   value = atomic_long_cmpxchg(datp-value, old, new);
+   if (value  0)
+   goto do_syscall;
+   } while (value != old);
+
+   return 0;
+   }   
+
+  do_syscall:
err = -XENOMAI_SKINCALL1(__cobalt_muxid, sc_cobalt_sem_post, _sem);
if (!err)
return 0;
@@ -78,10 +116,11 @@ COBALT_IMPL(int, sem_post, (sem_t *sem))
return -1;
 }
 
-COBALT_IMPL(int, sem_wait, (sem_t *sem))
+COBALT_IMPL(int, sem_trywait, (sem_t *sem))
 {
struct __shadow_sem *_sem = ((union cobalt_sem_union 
*)sem)-shadow_sem;
-   int err, oldtype;
+   struct sem_dat *datp;
+   long value;
 
if (_sem-magic != COBALT_SEM_MAGIC
 _sem-magic != COBALT_NAMED_SEM_MAGIC) {
@@ -89,56 +128,70 @@ COBALT_IMPL(int, sem_wait, (sem_t *sem))
return -1;
}
 
-   pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, oldtype);
+   datp = sem_get_datp(_sem);
 
-   err = -XENOMAI_SKINCALL1(__cobalt_muxid, sc_cobalt_sem_wait, _sem);
+   value = atomic_long_read(datp-value);
 
-   pthread_setcanceltype(oldtype, NULL);
+   if (value  0) {
+   long old, new;
 
-   if (!err)
+   do {
+   old = value;
+   new = value - 1;
+   
+   value = atomic_long_cmpxchg(datp-value, old, new);
+   if (value = 0)
+   goto eagain;
+   } while (value != old);
+   
return 0;
+   }
 
-   errno = err;
+  eagain:
+   errno = EAGAIN;
return -1;
 }
 
-COBALT_IMPL(int, sem_timedwait, (sem_t *sem, const struct timespec *ts))
+COBALT_IMPL(int, sem_wait, (sem_t *sem))
 {
struct __shadow_sem *_sem = ((union cobalt_sem_union 
*)sem)-shadow_sem;
int err, oldtype;
 
-   if (_sem-magic != COBALT_SEM_MAGIC
-_sem-magic != COBALT_NAMED_SEM_MAGIC) {
-   errno = EINVAL;
-   return -1;
-   }
-
+   err = __RT(sem_trywait(sem));
+   
+   if (err != -1 || errno != EAGAIN)
+   return err;
+   
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, oldtype);
 
-   err = -XENOMAI_SKINCALL2(__cobalt_muxid,
-sc_cobalt_sem_timedwait, _sem, ts);
+   err = -XENOMAI_SKINCALL1(__cobalt_muxid, 

[Xenomai-git] Philippe Gerum : lib/cobalt: catch unexpected sync errors with thread trampoline

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: b483819e7060346a2013751cfb572358399b68ce
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=b483819e7060346a2013751cfb572358399b68ce

Author: Philippe Gerum r...@xenomai.org
Date:   Mon Dec  9 12:33:07 2013 +0100

lib/cobalt: catch unexpected sync errors with thread trampoline

---

 lib/cobalt/thread.c |   23 ---
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 0063799..89c1d46 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -28,6 +28,7 @@
 #include asm/xenomai/syscall.h
 #include current.h
 #include internal.h
+#include boilerplate/ancillaries.h
 
 static pthread_attr_ex_t default_attr_ex;
 
@@ -349,15 +350,23 @@ int pthread_create_ex(pthread_t *tid,
if (ret)
goto fail;
 
-   while (__STD(sem_wait(iargs.sync))  errno == EINTR)
-   ;
+   for (;;) {
+   ret = __STD(sem_wait(iargs.sync));
+   if (ret  errno == EINTR)
+   continue;
+   if (ret == 0) {
+   ret = iargs.ret;
+   if (ret == 0)
+   *tid = ltid;
+   break;
+   }
+   ret = -errno;
+   if (detachstate == PTHREAD_CREATE_JOINABLE)
+   pthread_join(ltid, NULL);
+   panic(regular sem_wait() failed with %s, symerror(ret));
+   }
 
__cobalt_thread_harden(); /* May fail if regular thread. */
-   ret = iargs.ret;
-   if (ret == 0)
-   *tid = ltid;
-   else if (detachstate == PTHREAD_CREATE_JOINABLE)
-   pthread_join(ltid, NULL);
 fail:
__STD(sem_destroy(iargs.sync));
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Gilles Chanteperdrix : cobalt/init: check pthread_cond_t and sem_t structure sizes

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: abccf0399f39c7968fe8db14e466c610016a161c
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=abccf0399f39c7968fe8db14e466c610016a161c

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Dec  8 20:06:20 2013 +0100

cobalt/init: check pthread_cond_t and sem_t structure sizes

---

 lib/cobalt/init.c |   15 +++
 1 file changed, 15 insertions(+)

diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index 101a2bd..bc32a50 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -25,6 +25,7 @@
 #include signal.h
 #include limits.h
 #include unistd.h
+#include semaphore.h
 #include boilerplate/ancillaries.h
 #include cobalt/uapi/kernel/heap.h
 #include cobalt/uapi/rtdm/syscall.h
@@ -173,6 +174,20 @@ void __libcobalt_init(void)
 (int) sizeof(struct __shadow_mutex));
exit(EXIT_FAILURE);
}
+   if (sizeof(struct __shadow_cond)  sizeof(pthread_cond_t)) {
+   report_error(sizeof(pthread_cond_t): %d 
+ sizeof(shadow_cond): %d !,
+(int) sizeof(pthread_cond_t),
+(int) sizeof(struct __shadow_cond));
+   exit(EXIT_FAILURE);
+   }
+   if (sizeof(struct __shadow_sem)  sizeof(sem_t)) {
+   report_error(sizeof(sem_t): %d 
+ sizeof(shadow_sem): %d !,
+(int) sizeof(sem_t),
+(int) sizeof(struct __shadow_sem));
+   exit(EXIT_FAILURE);
+   }
 
cobalt_print_init();
boilerplate_init();


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/sched: properly handle side-effects of xnsched_pick() in debug mode

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 1958fd753b7970c95d0fff2ec9a838cf8a6ae21b
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1958fd753b7970c95d0fff2ec9a838cf8a6ae21b

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Dec 18 10:01:24 2013 +0100

cobalt/sched: properly handle side-effects of xnsched_pick() in debug mode

In debug mode, we unconditionally pick the next runnable thread in
order to check for consistency with XNRESCHED (i.e. XNRESCHED shall be
raised if the scheduler state has changed).

Since xnsched_pick() may change the scheduler state - either directly,
or indirectly via the policy module, we must collect need_resched
_after_ the new current thread was picked.

---

 kernel/cobalt/sched.c |   15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index a70151f..d26908c 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -252,6 +252,7 @@ struct xnthread *xnsched_pick_next(struct xnsched *sched)
if (!xnthread_test_state(curr, XNREADY)) {
xnsched_requeue(curr);
xnthread_set_state(curr, XNREADY);
+   xnsched_set_self_resched(sched);
}
}
 
@@ -770,12 +771,24 @@ int __xnsched_run(struct xnsched *sched)
xntrace_pid(xnthread_host_pid(curr), xnthread_current_priority(curr));
 reschedule:
switched = 0;
-   need_resched = test_resched(sched);
 #if !XENO_DEBUG(NUCLEUS)
+   need_resched = test_resched(sched);
if (!need_resched)
goto signal_unlock_and_exit;
 #endif /* !XENO_DEBUG(NUCLEUS) */
next = xnsched_pick_next(sched);
+#if XENO_DEBUG(NUCLEUS)
+   /*
+* CAUTION: in debug mode, we unconditionally pick the next
+* runnable thread in order to check for consistency with
+* XNRESCHED (i.e. XNRESCHED shall be raised if the scheduler
+* state has changed). Since xnsched_pick() may change the
+* scheduler state - either directly, or indirectly via the
+* policy plugin, we must collect need_resched _after_ the new
+* current thread was picked.
+*/
+   need_resched = test_resched(sched);
+#endif
if (next == curr) {
if (unlikely(xnthread_test_state(next, XNROOT))) {
if (sched-lflags  XNHTICK)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/powerpc: sanitize SPE handling

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: f42718f7d91df5f592f7a290467b3d7bc642
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=f42718f7d91df5f592f7a290467b3d7bc642

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Nov 19 10:28:40 2013 +0100

cobalt/powerpc: sanitize SPE handling

switchtest: we support SPE in user-space, but there is no point in
checking for fprs sanity between context switches since we have no
such registers in this case.

kernel handling: enabling SPE implicitly means disabling HW_FPU
handling in the Xenomai core, so tracking the SPE context for
real-time kthreads is unsupported. However, we do have proper SPE
save/restore code in our user context switching code, which enables it
for real-time threads in userland.

This patch is based on:
http://lists.debian.org/debian-powerpc/2011/07/msg00026.html

---

 kernel/cobalt/arch/powerpc/Kconfig   |2 +-
 .../arch/powerpc/include/asm/xenomai/uapi/fptest.h   |   14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/arch/powerpc/Kconfig 
b/kernel/cobalt/arch/powerpc/Kconfig
index d0cc003..433751b 100644
--- a/kernel/cobalt/arch/powerpc/Kconfig
+++ b/kernel/cobalt/arch/powerpc/Kconfig
@@ -1,6 +1,6 @@
 config XENO_HW_MATH_EMU
 bool
-   default y if MATH_EMU || 8XX_MINIMAL_FPEMU
+   default y if MATH_EMU || MATH_EMULATION
 
 menu Hardware options
 
diff --git a/kernel/cobalt/arch/powerpc/include/asm/xenomai/uapi/fptest.h 
b/kernel/cobalt/arch/powerpc/include/asm/xenomai/uapi/fptest.h
index cd85411..e6f89c9 100644
--- a/kernel/cobalt/arch/powerpc/include/asm/xenomai/uapi/fptest.h
+++ b/kernel/cobalt/arch/powerpc/include/asm/xenomai/uapi/fptest.h
@@ -18,6 +18,8 @@
 #ifndef _COBALT_POWERPC_ASM_UAPI_FPTEST_H
 #define _COBALT_POWERPC_ASM_UAPI_FPTEST_H
 
+#ifndef __NO_FPRS__/* i.e. has FPU, not SPE */
+
 static inline void fp_regs_set(int features, unsigned int val)
 {
unsigned long long fpval = val;
@@ -110,4 +112,16 @@ static inline unsigned int fp_regs_check(int features, 
unsigned int val,
return result;
 }
 
+#else  /* __NO_FPRS__ */
+
+static inline void fp_regs_set(int features, unsigned int val) { }
+
+static inline unsigned int fp_regs_check(int features, unsigned int val,
+int (*report)(const char *fmt, ...))
+{
+   return val;
+}
+
+#endif /* __NO_FPRS__ */
+
 #endif /* !_COBALT_POWERPC_ASM_UAPI_FPTEST_H */


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Gilles Chanteperdrix : cobalt/semaphores: move semaphore counter to sem_heap

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 028fe53140fb023bccb9282fc1ed6c926ee49637
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=028fe53140fb023bccb9282fc1ed6c926ee49637

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Dec  8 17:51:54 2013 +0100

cobalt/semaphores: move semaphore counter to sem_heap

in order to prepare for user-space access.

---

 include/cobalt/semaphore.h |1 +
 include/cobalt/uapi/sem.h  |6 +++
 kernel/cobalt/posix/sem.c  |  120 ++--
 lib/cobalt/semaphore.c |1 -
 4 files changed, 79 insertions(+), 49 deletions(-)

diff --git a/include/cobalt/semaphore.h b/include/cobalt/semaphore.h
index ac1729e..284131c 100644
--- a/include/cobalt/semaphore.h
+++ b/include/cobalt/semaphore.h
@@ -20,6 +20,7 @@
 
 #pragma GCC system_header
 #include_next semaphore.h
+#include nocore/atomic.h
 #include cobalt/wrappers.h
 #include cobalt/uapi/sem.h
 
diff --git a/include/cobalt/uapi/sem.h b/include/cobalt/uapi/sem.h
index 7206446..a1a9526 100644
--- a/include/cobalt/uapi/sem.h
+++ b/include/cobalt/uapi/sem.h
@@ -23,11 +23,17 @@
 
 struct cobalt_sem;
 
+struct sem_dat {
+   atomic_long_t value;
+   unsigned long flags;
+};
+
 union cobalt_sem_union {
sem_t native_sem;
struct __shadow_sem {
unsigned int magic;
struct cobalt_sem *sem;
+   int datp_offset;
} shadow_sem;
 };
 
diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index 60906fd..9c31fbf 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -46,9 +46,8 @@ struct cobalt_sem {
struct xnsynch synchbase;
/** semq */
struct list_head link;
-   unsigned int value;
+   struct sem_dat *datp;
int flags;
-   int nwaiters;
struct cobalt_kqueues *owningq;
 };
 
@@ -88,6 +87,9 @@ static int sem_destroy_inner(struct cobalt_sem *sem, struct 
cobalt_kqueues *q)
 
xnlock_put_irqrestore(nklock, s);
 
+   xnheap_free(xnsys_ppd_get(!!(sem-flags  SEM_PSHARED))-sem_heap,
+   sem-datp);
+
if (sem-flags  SEM_NAMED)
xnfree(sem2named_sem(sem));
else
@@ -97,23 +99,30 @@ static int sem_destroy_inner(struct cobalt_sem *sem, struct 
cobalt_kqueues *q)
 }
 
 /* Called with nklock locked, irq off. */
-static int sem_init_inner(struct cobalt_sem *sem, int flags, unsigned int 
value)
+static int sem_init_inner(struct cobalt_sem *sem, int flags, 
+   struct sem_dat *datp, unsigned int value)
 {
+   struct cobalt_kqueues *kq;
int pshared, sflags;
 
if (value  (unsigned)SEM_VALUE_MAX)
return -EINVAL;
 
pshared = !!(flags  SEM_PSHARED);
+
sflags = flags  SEM_FIFO ? 0 : XNSYNCH_PRIO;
 
sem-magic = COBALT_SEM_MAGIC;
-   list_add_tail(sem-link, cobalt_kqueues(pshared)-semq);
+
+   kq = cobalt_kqueues(pshared);
+   list_add_tail(sem-link, kq-semq);
xnsynch_init(sem-synchbase, sflags, NULL);
-   sem-value = value;
+
+   sem-datp = datp;
+   atomic_long_set(datp-value, value);
+   datp-flags = flags;
sem-flags = flags;
-   sem-nwaiters = 0;
-   sem-owningq = cobalt_kqueues(pshared);
+   sem-owningq = kq;
 
return 0;
 }
@@ -121,7 +130,9 @@ static int sem_init_inner(struct cobalt_sem *sem, int 
flags, unsigned int value)
 static int do_sem_init(struct __shadow_sem *sm, int flags, unsigned int value)
 {
struct list_head *semq, *entry;
+   struct xnsys_ppd *sys_ppd;
struct cobalt_sem *sem;
+   struct sem_dat *datp;
int ret;
spl_t s;
 
@@ -132,6 +143,13 @@ static int do_sem_init(struct __shadow_sem *sm, int flags, 
unsigned int value)
if (sem == NULL)
return -ENOSPC;
 
+   sys_ppd = xnsys_ppd_get(!!(flags  SEM_PSHARED));
+   datp = xnheap_alloc(sys_ppd-sem_heap, sizeof(*datp));
+   if (datp == NULL) {
+   ret = -EAGAIN;
+   goto err_free_sem;
+   }
+
xnlock_get_irqsave(nklock, s);
 
if (sm-magic != COBALT_SEM_MAGIC 
@@ -161,19 +179,24 @@ static int do_sem_init(struct __shadow_sem *sm, int 
flags, unsigned int value)
goto err_lock_put;
}
}
-do_init:
-   ret = sem_init_inner(sem, flags, value);
+  do_init:
+   ret = sem_init_inner(sem, flags, datp, value);
if (ret)
goto err_lock_put;
 
sm-magic = COBALT_SEM_MAGIC;
sm-sem = sem;
+   sm-datp_offset = xnheap_mapped_offset(sys_ppd-sem_heap, datp);
+   if (flags  SEM_PSHARED)
+   sm-datp_offset = -sm-datp_offset;
xnlock_put_irqrestore(nklock, s);
 
return 0;
 
-err_lock_put:
+  err_lock_put:
xnlock_put_irqrestore(nklock, s);
+   xnheap_free(sys_ppd-sem_heap, sem-datp);
+  err_free_sem:
xnfree(sem);
 
return ret;
@@ 

[Xenomai-git] Gilles Chanteperdrix : cobalt/registry: allow to retrieve an object key from its handle

2013-12-22 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 0ba78c15f892e5fab25b8a83521fbbb26b0749b9
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=0ba78c15f892e5fab25b8a83521fbbb26b0749b9

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Dec 15 17:08:54 2013 +0100

cobalt/registry: allow to retrieve an object key from its handle

---

 include/cobalt/kernel/registry.h |6 ++
 1 file changed, 6 insertions(+)

diff --git a/include/cobalt/kernel/registry.h b/include/cobalt/kernel/registry.h
index 6c25eee..5197542 100644
--- a/include/cobalt/kernel/registry.h
+++ b/include/cobalt/kernel/registry.h
@@ -163,6 +163,12 @@ static inline void *xnregistry_lookup(xnhandle_t handle)
return object ? object-objaddr : NULL;
 }
 
+static inline const char *xnregistry_key(xnhandle_t handle)
+{
+   struct xnobject *object = xnregistry_validate(handle);
+   return object ? object-key : NULL;
+}
+
 int xnregistry_enter(const char *key,
 void *objaddr,
 xnhandle_t *phandle,


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git