[Xenomai-git] Philippe Gerum : copperplate/timerobj: clear sigevent upon creation ( valgrind)

2013-05-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 293355063c770236459352c84d4f5b2d8aaeee71
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=293355063c770236459352c84d4f5b2d8aaeee71

Author: Philippe Gerum 
Date:   Fri May 10 12:21:02 2013 +0200

copperplate/timerobj: clear sigevent upon creation (valgrind)

---

 lib/copperplate/timerobj.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/lib/copperplate/timerobj.c b/lib/copperplate/timerobj.c
index 91b483d..ce778d4 100644
--- a/lib/copperplate/timerobj.c
+++ b/lib/copperplate/timerobj.c
@@ -98,6 +98,7 @@ static inline int timerobj_init_corespec(struct timerobj 
*tmobj)
struct sigevent sev;
int ret;
 
+   memset(&sev, 0, sizeof(sev));
sev.sigev_notify = SIGEV_THREAD_ID;
sev.sigev_signo = SIGALRM;
sev.sigev_notify_thread_id = svpid;


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


[Xenomai-git] Philippe Gerum : copperplate/threadobj: cleanup former core specifics in shadow overlay

2013-05-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 735e9ca9169033f5e0d6ff4e6c4114eb979f08ed
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=735e9ca9169033f5e0d6ff4e6c4114eb979f08ed

Author: Philippe Gerum 
Date:   Fri May 10 12:19:42 2013 +0200

copperplate/threadobj: cleanup former core specifics in shadow overlay

---

 lib/copperplate/threadobj.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index bacdf5f..2515569 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -437,6 +437,7 @@ static inline int threadobj_setup_corespec(struct threadobj 
*thobj)
 * thread, and unlike with set_rr(), threadobj_current() ==
 * thobj is guaranteed in threadobj_setup_corespec().
 */
+   memset(&sev, 0, sizeof(sev));
sev.sigev_notify = SIGEV_SIGNAL|SIGEV_THREAD_ID;
sev.sigev_signo = SIGVTALRM;
sev.sigev_notify_thread_id = copperplate_get_tid();
@@ -915,6 +916,7 @@ int threadobj_prologue(struct threadobj *thobj, const char 
*name)
assert(current->magic == 0);
sysgroup_remove(thread, ¤t->memspec);
finalize_thread(current);
+   threadobj_cleanup_corespec(current);
threadobj_free(current);
} else
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);


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


[Xenomai-git] Philippe Gerum : copperplate/heapobj-malloc: enforce hard limit on pool size

2013-05-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 900e0c3f84b8e8374e64b2d6932cce9328713d80
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=900e0c3f84b8e8374e64b2d6932cce9328713d80

Author: Philippe Gerum 
Date:   Thu May  9 12:22:05 2013 +0200

copperplate/heapobj-malloc: enforce hard limit on pool size

Applications may rely on hard limits when creating memory pools, to
detect over-consumption. Since the global malloc heap is virtually
illimited, we do allocation size accounting for each malloc-based
heap and reject over budget requests.

---

 include/copperplate/heapobj.h|   55 -
 lib/copperplate/heapobj-malloc.c |  127 +-
 2 files changed, 139 insertions(+), 43 deletions(-)

diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index 2dad005..39b6b06 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -140,22 +140,10 @@ static inline char *pvstrdup(const char *ptr)
 
 #include 
 
-static inline
-void pvheapobj_destroy(struct heapobj *hobj)
-{
-}
-
-static inline
-int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
-{
-   return 0;
-}
-
-static inline
-void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+static inline void *pvmalloc(size_t size)
 {
/*
-* XXX: We don't want debug _nrt assertions to trigger when
+* NOTE: We don't want debug _nrt assertions to trigger when
 * running over Cobalt if the user picked this allocator, so
 * we make sure to call the glibc directly, not the Cobalt
 * wrappers.
@@ -163,44 +151,27 @@ void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
return __STD(malloc(size));
 }
 
-static inline
-void pvheapobj_free(struct heapobj *hobj, void *ptr)
+static inline void pvfree(void *ptr)
 {
__STD(free(ptr));
 }
 
-static inline
-size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+static inline char *pvstrdup(const char *ptr)
 {
-   /*
-* We will likely get hard validation here, i.e. crash or
-* abort if the pointer is wrong. TLSF is a bit smarter, and
-* pshared definitely does the right thing.
-*/
-   return malloc_usable_size(ptr);
+   return strdup(ptr);
 }
 
-static inline
-size_t pvheapobj_inquire(struct heapobj *hobj)
-{
-   struct mallinfo m = mallinfo();
-   return m.uordblks;
-}
+void pvheapobj_destroy(struct heapobj *hobj);
 
-static inline void *pvmalloc(size_t size)
-{
-   return __STD(malloc(size));
-}
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem);
 
-static inline void pvfree(void *ptr)
-{
-   __STD(free(ptr));
-}
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size);
 
-static inline char *pvstrdup(const char *ptr)
-{
-   return strdup(ptr);
-}
+void pvheapobj_free(struct heapobj *hobj, void *ptr);
+
+size_t pvheapobj_inquire(struct heapobj *hobj);
+
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr);
 
 #endif /* !CONFIG_XENO_TLSF */
 
diff --git a/lib/copperplate/heapobj-malloc.c b/lib/copperplate/heapobj-malloc.c
index 96814b9..14d624e 100644
--- a/lib/copperplate/heapobj-malloc.c
+++ b/lib/copperplate/heapobj-malloc.c
@@ -20,19 +20,51 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include "copperplate/lock.h"
 #include "copperplate/heapobj.h"
 #include "copperplate/debug.h"
 
+#define MALLOC_MAGIC 0xabbfcddc
+
+struct pool_header {
+   pthread_mutex_t lock;
+   size_t used;
+};
+
+struct block_header {
+   unsigned int magic;
+   size_t size;
+};
+
 int __heapobj_init_private(struct heapobj *hobj, const char *name,
   size_t size, void *mem)
 {
+   pthread_mutexattr_t mattr;
+   struct pool_header *ph;
+
/*
 * There is no local pool when working with malloc, we just
 * use the global process arena. This should not be an issue
 * since this mode is aimed at debugging, particularly to be
 * used along with Valgrind.
+*
+* However, we maintain a control header to track the amount
+* of memory currently consumed in each heap.
 */
-   hobj->pool = mem;   /* Never used. */
+   ph = malloc(sizeof(*ph));
+   if (ph == NULL)
+   return __bt(-ENOMEM);
+
+   __RT(pthread_mutexattr_init(&mattr));
+   __RT(pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT));
+   __RT(pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_PRIVATE));
+   __RT(pthread_mutex_init(&ph->lock, &mattr));
+   __RT(pthread_mutexattr_destroy(&mattr));
+   ph->used = 0;
+
+   hobj->pool = ph;
hobj->size = size;
if (name)
snprintf(hobj->name, sizeof(hobj->name), "%s", name);
@@ -48,6 +80,99 @@ int heapobj_init_array_private(struct heapobj *hobj, const 
char *name,
return __bt(__heapobj_init_private(hobj, name, size * elems, NULL));
 }
 
+void pvheapobj_destroy(st

[Xenomai-git] Philippe Gerum : alchemy/queue: account for message descriptor overhead

2013-05-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 5d75acc1a56fdf83f4018a81cbf5ee418eb9ed67
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=5d75acc1a56fdf83f4018a81cbf5ee418eb9ed67

Author: Philippe Gerum 
Date:   Thu May  9 12:21:38 2013 +0200

alchemy/queue: account for message descriptor overhead

---

 lib/alchemy/queue.c |   24 +---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 383b49e..6a69061 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -77,7 +77,7 @@ fnref_register(libalchemy, queue_finalize);
  * @param poolsize The size (in bytes) of the message buffer pool to
  * be pre-allocated for holding messages. Message buffers will be
  * claimed and released to this pool.  The buffer pool memory cannot
- * be extended.
+ * be extended. See note.
  *
  * @param mode The queue creation mode. The following flags can be
  * OR'ed into this bitmask, each of them affecting the new queue:
@@ -105,6 +105,17 @@ fnref_register(libalchemy, queue_finalize);
  *
  * @note Queues can be shared by multiple processes which belong to
  * the same Xenomai session.
+ *
+ * @note Each message pending into the queue consumes four long words
+ * plus the actual payload size, aligned to the next long word
+ * boundary. e.g. a 6 byte message on a 32 bit platform would require
+ * 24 bytes of storage into the pool.
+ *
+ * When @a qlimit is given (i.e. different from Q_UNLIMITED), this
+ * overhead is accounted for automatically, so that @a qlimit messages
+ * of @a poolsize / @a qlimit bytes can be stored into the pool
+ * concurrently. Otherwise, @a poolsize is increased by 5% internally
+ * to cope with such overhead.
  */
 int rt_queue_create(RT_QUEUE *queue, const char *name,
size_t poolsize, size_t qlimit, int mode)
@@ -130,12 +141,19 @@ int rt_queue_create(RT_QUEUE *queue, const char *name,
/*
 * The message pool has to be part of the main heap for proper
 * sharing between processes.
+*
+* We have the message descriptor overhead to cope with when
+* allocating the buffer pool. When the queue limit is not
+* known, assume 5% overhead.
 */
if (qlimit == Q_UNLIMITED)
-   ret = heapobj_init(&qcb->hobj, qcb->name, poolsize);
+   ret = heapobj_init(&qcb->hobj, qcb->name,
+  poolsize + (poolsize / 5));
else
ret = heapobj_init_array(&qcb->hobj, qcb->name,
-poolsize / qlimit, qlimit);
+(poolsize / qlimit) *
+sizeof(struct alchemy_queue_msg),
+qlimit);
if (ret) {
xnfree(qcb);
goto out;


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


[Xenomai-git] Philippe Gerum : copperplate/threadobj: threadobj_wait_period() implicitly applies to current

2013-05-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 71beacebda481d7ee49f7ecad16a5290eb54e789
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=71beacebda481d7ee49f7ecad16a5290eb54e789

Author: Philippe Gerum 
Date:   Wed May  8 18:48:58 2013 +0200

copperplate/threadobj: threadobj_wait_period() implicitly applies to current

---

 include/copperplate/threadobj.h |3 +--
 lib/alchemy/task.c  |2 +-
 lib/copperplate/threadobj.c |   18 +++---
 3 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index ac8d846..609826b 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -308,8 +308,7 @@ int threadobj_set_rr(struct threadobj *thobj, struct 
timespec *quantum);
 int threadobj_set_periodic(struct threadobj *thobj,
   struct timespec *idate, struct timespec *period);
 
-int threadobj_wait_period(struct threadobj *thobj,
- unsigned long *overruns_r);
+int threadobj_wait_period(unsigned long *overruns_r);
 
 void threadobj_spin(ticks_t ns);
 
diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index 9c59f38..1103cb8 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -812,7 +812,7 @@ int rt_task_wait_period(unsigned long *overruns_r)
if (tcb == NULL)
return -EPERM;
 
-   return threadobj_wait_period(&tcb->thobj, overruns_r);
+   return threadobj_wait_period(overruns_r);
 }
 
 /**
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 93373f4..bacdf5f 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -307,10 +307,8 @@ int threadobj_set_periodic(struct threadobj *thobj,
 CLOCK_COPPERPLATE, idate, period);
 }
 
-int threadobj_wait_period(struct threadobj *thobj,
- unsigned long *overruns_r)
+int threadobj_wait_period(unsigned long *overruns_r)
 {
-   assert(thobj == threadobj_current());
return -pthread_wait_np(overruns_r);
 }
 
@@ -667,21 +665,19 @@ int threadobj_set_periodic(struct threadobj *thobj,
return 0;
 }
 
-int threadobj_wait_period(struct threadobj *thobj,
- unsigned long *overruns_r)
+int threadobj_wait_period(unsigned long *overruns_r)
 {
+   struct threadobj *current = threadobj_current();
struct timespec now, delta, wakeup;
unsigned long overruns = 0;
ticks_t d, period;
int ret;
 
-   assert(thobj == threadobj_current());
-
-   period = thobj->core.period;
+   period = current->core.period;
if (period == 0)
return -EWOULDBLOCK;
 
-   wakeup = thobj->core.wakeup;
+   wakeup = current->core.wakeup;
ret = threadobj_sleep(&wakeup);
if (ret)
return ret;
@@ -694,10 +690,10 @@ int threadobj_wait_period(struct threadobj *thobj,
d = timespec_scalar(&delta);
if (d >= period) {
overruns = d / period;
-   timespec_adds(&thobj->core.wakeup, &wakeup,
+   timespec_adds(¤t->core.wakeup, &wakeup,
  overruns * (period + 1));
} else
-   timespec_adds(&thobj->core.wakeup, &wakeup, period);
+   timespec_adds(¤t->core.wakeup, &wakeup, period);
 
if (overruns)
ret = -ETIMEDOUT;


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


[Xenomai-git] Philippe Gerum : copperplate/heapobj-malloc: enforce hard limit on pool size

2013-05-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 5d3fae825a8b92dca86f4cdc4b6c4ccabe19d1ce
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=5d3fae825a8b92dca86f4cdc4b6c4ccabe19d1ce

Author: Philippe Gerum 
Date:   Thu May  9 12:22:05 2013 +0200

copperplate/heapobj-malloc: enforce hard limit on pool size

Applications may rely on hard limits when creating memory pools, to
detect over-consumption. Since the global malloc heap is virtually
illimited, we do allocation size accounting for each malloc-based
heap and reject over budget requests.

---

 include/copperplate/heapobj.h|   55 -
 lib/copperplate/heapobj-malloc.c |  127 +-
 2 files changed, 139 insertions(+), 43 deletions(-)

diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index 2dad005..39b6b06 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -140,22 +140,10 @@ static inline char *pvstrdup(const char *ptr)
 
 #include 
 
-static inline
-void pvheapobj_destroy(struct heapobj *hobj)
-{
-}
-
-static inline
-int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
-{
-   return 0;
-}
-
-static inline
-void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+static inline void *pvmalloc(size_t size)
 {
/*
-* XXX: We don't want debug _nrt assertions to trigger when
+* NOTE: We don't want debug _nrt assertions to trigger when
 * running over Cobalt if the user picked this allocator, so
 * we make sure to call the glibc directly, not the Cobalt
 * wrappers.
@@ -163,44 +151,27 @@ void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
return __STD(malloc(size));
 }
 
-static inline
-void pvheapobj_free(struct heapobj *hobj, void *ptr)
+static inline void pvfree(void *ptr)
 {
__STD(free(ptr));
 }
 
-static inline
-size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+static inline char *pvstrdup(const char *ptr)
 {
-   /*
-* We will likely get hard validation here, i.e. crash or
-* abort if the pointer is wrong. TLSF is a bit smarter, and
-* pshared definitely does the right thing.
-*/
-   return malloc_usable_size(ptr);
+   return strdup(ptr);
 }
 
-static inline
-size_t pvheapobj_inquire(struct heapobj *hobj)
-{
-   struct mallinfo m = mallinfo();
-   return m.uordblks;
-}
+void pvheapobj_destroy(struct heapobj *hobj);
 
-static inline void *pvmalloc(size_t size)
-{
-   return __STD(malloc(size));
-}
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem);
 
-static inline void pvfree(void *ptr)
-{
-   __STD(free(ptr));
-}
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size);
 
-static inline char *pvstrdup(const char *ptr)
-{
-   return strdup(ptr);
-}
+void pvheapobj_free(struct heapobj *hobj, void *ptr);
+
+size_t pvheapobj_inquire(struct heapobj *hobj);
+
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr);
 
 #endif /* !CONFIG_XENO_TLSF */
 
diff --git a/lib/copperplate/heapobj-malloc.c b/lib/copperplate/heapobj-malloc.c
index 96814b9..14d624e 100644
--- a/lib/copperplate/heapobj-malloc.c
+++ b/lib/copperplate/heapobj-malloc.c
@@ -20,19 +20,51 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include "copperplate/lock.h"
 #include "copperplate/heapobj.h"
 #include "copperplate/debug.h"
 
+#define MALLOC_MAGIC 0xabbfcddc
+
+struct pool_header {
+   pthread_mutex_t lock;
+   size_t used;
+};
+
+struct block_header {
+   unsigned int magic;
+   size_t size;
+};
+
 int __heapobj_init_private(struct heapobj *hobj, const char *name,
   size_t size, void *mem)
 {
+   pthread_mutexattr_t mattr;
+   struct pool_header *ph;
+
/*
 * There is no local pool when working with malloc, we just
 * use the global process arena. This should not be an issue
 * since this mode is aimed at debugging, particularly to be
 * used along with Valgrind.
+*
+* However, we maintain a control header to track the amount
+* of memory currently consumed in each heap.
 */
-   hobj->pool = mem;   /* Never used. */
+   ph = malloc(sizeof(*ph));
+   if (ph == NULL)
+   return __bt(-ENOMEM);
+
+   __RT(pthread_mutexattr_init(&mattr));
+   __RT(pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT));
+   __RT(pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_PRIVATE));
+   __RT(pthread_mutex_init(&ph->lock, &mattr));
+   __RT(pthread_mutexattr_destroy(&mattr));
+   ph->used = 0;
+
+   hobj->pool = ph;
hobj->size = size;
if (name)
snprintf(hobj->name, sizeof(hobj->name), "%s", name);
@@ -48,6 +80,99 @@ int heapobj_init_array_private(struct heapobj *hobj, const 
char *name,
return __bt(__heapobj_init_private(hobj, name, size * elems, NULL));
 }
 
+void pvheapobj_destroy(st

[Xenomai-git] Philippe Gerum : copperplate/threadobj: scheduler lock, unlock calls implicitly apply to current

2013-05-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 918d96842ead420df7b718d84882b8523a748ac3
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=918d96842ead420df7b718d84882b8523a748ac3

Author: Philippe Gerum 
Date:   Wed May  8 18:46:09 2013 +0200

copperplate/threadobj: scheduler lock, unlock calls implicitly apply to current

---

 include/copperplate/threadobj.h |   12 +++--
 lib/copperplate/threadobj.c |   79 ++-
 lib/psos/task.c |6 +-
 lib/vxworks/taskLib.c   |4 +-
 4 files changed, 48 insertions(+), 53 deletions(-)

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 7d8cb9f..ac8d846 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -295,9 +295,9 @@ int threadobj_resume(struct threadobj *thobj);
 
 int threadobj_unblock(struct threadobj *thobj);
 
-int threadobj_lock_sched(struct threadobj *thobj);
+int threadobj_lock_sched(void);
 
-int threadobj_unlock_sched(struct threadobj *thobj);
+int threadobj_unlock_sched(void);
 
 int threadobj_set_priority(struct threadobj *thobj, int prio);
 
@@ -397,10 +397,12 @@ static inline int threadobj_current_p(void)
return current && current != THREADOBJ_IRQCONTEXT;
 }
 
-static inline int threadobj_lock_sched_once(struct threadobj *thobj)
+static inline int threadobj_lock_sched_once(void)
 {
-   if (thobj->schedlock_depth == 0)
-   return threadobj_lock_sched(thobj);
+   struct threadobj *current = threadobj_current();
+
+   if (current->schedlock_depth == 0)
+   return threadobj_lock_sched();
 
return 0;
 }
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index fb05a13..93373f4 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -173,16 +173,16 @@ int threadobj_resume(struct threadobj *thobj) /* 
thobj->lock held */
return __bt(-ret);
 }
 
-int threadobj_lock_sched(struct threadobj *thobj) /* thobj->lock held */
+int threadobj_lock_sched(void) /* current->lock held */
 {
-   __threadobj_check_locked(thobj);
+   struct threadobj *current = threadobj_current();
 
-   assert(thobj == threadobj_current());
+   __threadobj_check_locked(current);
 
-   if (thobj->schedlock_depth++ > 0)
+   if (current->schedlock_depth++ > 0)
return 0;
 
-   thobj->status |= __THREAD_S_NOPREEMPT;
+   current->status |= __THREAD_S_NOPREEMPT;
/*
 * In essence, we can't be scheduled out as a result of
 * locking the scheduler, so no need to drop the thread lock
@@ -191,13 +191,11 @@ int threadobj_lock_sched(struct threadobj *thobj) /* 
thobj->lock held */
return __bt(-pthread_set_mode_np(0, PTHREAD_LOCK_SCHED, NULL));
 }
 
-int threadobj_unlock_sched(struct threadobj *thobj) /* thobj->lock held */
+int threadobj_unlock_sched(void) /* current->lock held */
 {
-   int ret;
-
-   __threadobj_check_locked(thobj);
+   struct threadobj *current = threadobj_current();
 
-   assert(thobj == threadobj_current());
+   __threadobj_check_locked(current);
 
/*
 * Higher layers may not know about the current locking level
@@ -205,18 +203,15 @@ int threadobj_unlock_sched(struct threadobj *thobj) /* 
thobj->lock held */
 * unbalanced calls here, and let them decide of the outcome
 * in case of error.
 */
-   if (thobj->schedlock_depth == 0)
+   if (current->schedlock_depth == 0)
return __bt(-EINVAL);
 
-   if (--thobj->schedlock_depth > 0)
+   if (--current->schedlock_depth > 0)
return 0;
 
-   thobj->status &= ~__THREAD_S_NOPREEMPT;
-   threadobj_unlock(thobj);
-   ret = pthread_set_mode_np(PTHREAD_LOCK_SCHED, 0, NULL);
-   threadobj_lock(thobj);
+   current->status &= ~__THREAD_S_NOPREEMPT;
 
-   return __bt(-ret);
+   return __bt(-pthread_set_mode_np(PTHREAD_LOCK_SCHED, 0, NULL));
 }
 
 int threadobj_set_priority(struct threadobj *thobj, int prio) /* thobj->lock 
held, dropped */
@@ -494,51 +489,49 @@ int threadobj_resume(struct threadobj *thobj) /* 
thobj->lock held */
return __bt(notifier_release(&thobj->core.notifier));
 }
 
-int threadobj_lock_sched(struct threadobj *thobj) /* thobj->lock held */
+int threadobj_lock_sched(void) /* current->lock held */
 {
-   pthread_t tid = thobj->tid;
+   struct threadobj *current = threadobj_current();
+   pthread_t tid = current->tid;
struct sched_param param;
 
-   __threadobj_check_locked(thobj);
-
-   assert(thobj == threadobj_current());
+   __threadobj_check_locked(current);
 
-   if (thobj->schedlock_depth++ > 0)
+   if (current->schedlock_depth++ > 0)
return 0;
 
-   thobj->core.prio_unlocked = thobj->priority;
-   thobj->core.policy_unlocked = thobj->policy;
-   thobj->status |= __THREAD_S_NOPREEMPT;
-   thobj->pr

[Xenomai-git] Philippe Gerum : copperplate/threadobj: cleanup former core specifics in shadow overlay

2013-05-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 507ebe32d9be465c341659f7168b0eda97401710
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=507ebe32d9be465c341659f7168b0eda97401710

Author: Philippe Gerum 
Date:   Fri May 10 12:19:42 2013 +0200

copperplate/threadobj: cleanup former core specifics in shadow overlay

---

 lib/copperplate/threadobj.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index bacdf5f..2515569 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -437,6 +437,7 @@ static inline int threadobj_setup_corespec(struct threadobj 
*thobj)
 * thread, and unlike with set_rr(), threadobj_current() ==
 * thobj is guaranteed in threadobj_setup_corespec().
 */
+   memset(&sev, 0, sizeof(sev));
sev.sigev_notify = SIGEV_SIGNAL|SIGEV_THREAD_ID;
sev.sigev_signo = SIGVTALRM;
sev.sigev_notify_thread_id = copperplate_get_tid();
@@ -915,6 +916,7 @@ int threadobj_prologue(struct threadobj *thobj, const char 
*name)
assert(current->magic == 0);
sysgroup_remove(thread, ¤t->memspec);
finalize_thread(current);
+   threadobj_cleanup_corespec(current);
threadobj_free(current);
} else
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);


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


[Xenomai-git] Philippe Gerum : copperplate/timerobj: clear sigevent upon creation ( valgrind)

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

Author: Philippe Gerum 
Date:   Fri May 10 12:21:02 2013 +0200

copperplate/timerobj: clear sigevent upon creation (valgrind)

---

 lib/copperplate/timerobj.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/lib/copperplate/timerobj.c b/lib/copperplate/timerobj.c
index 91b483d..ce778d4 100644
--- a/lib/copperplate/timerobj.c
+++ b/lib/copperplate/timerobj.c
@@ -98,6 +98,7 @@ static inline int timerobj_init_corespec(struct timerobj 
*tmobj)
struct sigevent sev;
int ret;
 
+   memset(&sev, 0, sizeof(sev));
sev.sigev_notify = SIGEV_THREAD_ID;
sev.sigev_signo = SIGALRM;
sev.sigev_notify_thread_id = svpid;


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


[Xenomai-git] Gilles Chanteperdrix : native: do not defer removing rt_heaps from list

2013-05-10 Thread git repository hosting
Module: xenomai-2.6
Branch: master
Commit: ee28ad6936964ebf4198dcfd77dec4b8c5e8623c
URL:
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=ee28ad6936964ebf4198dcfd77dec4b8c5e8623c

Author: Gilles Chanteperdrix 
Date:   Fri May 10 15:27:05 2013 +0200

native: do not defer removing rt_heaps from list

---

 ksrc/skins/native/heap.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/ksrc/skins/native/heap.c b/ksrc/skins/native/heap.c
index 4a39d07..61f6676 100644
--- a/ksrc/skins/native/heap.c
+++ b/ksrc/skins/native/heap.c
@@ -371,8 +371,6 @@ static void __heap_post_release(struct xnheap *h)
 
xnlock_get_irqsave(&nklock, s);
 
-   removeq(heap->rqueue, &heap->rlink);
-
if (heap->handle)
xnregistry_remove(heap->handle);
 
@@ -441,6 +439,7 @@ int rt_heap_delete_inner(RT_HEAP *heap, void __user 
*mapaddr)
}
 
xeno_mark_deleted(heap);
+   removeq(heap->rqueue, &heap->rlink);
 
/* Get out of the nklocked section before releasing the heap
   memory, since we are about to invoke Linux kernel


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


[Xenomai-git] Gilles Chanteperdrix : posix: avoid races in pthread_set_name_np

2013-05-10 Thread git repository hosting
Module: xenomai-2.6
Branch: master
Commit: a2a6d456b23b9960f46964505668619b90b69400
URL:
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=a2a6d456b23b9960f46964505668619b90b69400

Author: Gilles Chanteperdrix 
Date:   Fri May 10 15:26:04 2013 +0200

posix: avoid races in pthread_set_name_np

---

 ksrc/skins/posix/syscall.c |6 --
 ksrc/skins/posix/thread.c  |   11 +++
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c
index 49ed764..2093edb 100644
--- a/ksrc/skins/posix/syscall.c
+++ b/ksrc/skins/posix/syscall.c
@@ -422,7 +422,6 @@ static int __pthread_set_name_np(struct pt_regs *regs)
 {
char name[XNOBJECT_NAME_LEN];
struct pse51_hkey hkey;
-   struct task_struct *p;
pthread_t k_tid;
 
if (__xn_safe_strncpy_from_user(name,
@@ -435,11 +434,6 @@ static int __pthread_set_name_np(struct pt_regs *regs)
hkey.u_tid = __xn_reg_arg1(regs);
hkey.mm = current->mm;
k_tid = __pthread_find(&hkey);
-   if (k_tid) {
-   p = xnthread_user_task(&k_tid->threadbase);
-   strncpy(p->comm, name, sizeof(p->comm));
-   p->comm[sizeof(p->comm) - 1] = '\0';
-   }
 
return -pthread_set_name_np(k_tid, name);
 }
diff --git a/ksrc/skins/posix/thread.c b/ksrc/skins/posix/thread.c
index 01fc699..78f5634 100644
--- a/ksrc/skins/posix/thread.c
+++ b/ksrc/skins/posix/thread.c
@@ -715,6 +715,9 @@ int pthread_set_mode_np(int clrmask, int setmask)
  */
 int pthread_set_name_np(pthread_t thread, const char *name)
 {
+#ifdef CONFIG_XENO_OPT_PERVASIVE
+   struct task_struct *p;
+#endif /* CONFIG_XENO_OPT_PERVASIVE */
spl_t s;
 
xnlock_get_irqsave(&nklock, s);
@@ -727,6 +730,14 @@ int pthread_set_name_np(pthread_t thread, const char *name)
snprintf(xnthread_name(&thread->threadbase), XNOBJECT_NAME_LEN, "%s",
 name);
 
+#ifdef CONFIG_XENO_OPT_PERVASIVE
+   p = xnthread_user_task(&thread->threadbase);
+   if (p) {
+   strncpy(p->comm, name, sizeof(p->comm));
+   p->comm[sizeof(p->comm) - 1] = '\0';
+   }
+#endif /* CONFIG_XENO_OPT_PERVASIVE */
+
xnlock_put_irqrestore(&nklock, s);
 
return 0;


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


[Xenomai-git] Gilles Chanteperdrix : native: avoid calling copy_from_user with hard irqs off

2013-05-10 Thread git repository hosting
Module: xenomai-2.6
Branch: master
Commit: 9b645b0fbf5fe6068358f4bbc25469ebd24b822f
URL:
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=9b645b0fbf5fe6068358f4bbc25469ebd24b822f

Author: Gilles Chanteperdrix 
Date:   Fri May 10 15:27:38 2013 +0200

native: avoid calling copy_from_user with hard irqs off

---

 ksrc/skins/native/syscall.c |   32 ++--
 1 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/ksrc/skins/native/syscall.c b/ksrc/skins/native/syscall.c
index a88a517..b9862e7 100644
--- a/ksrc/skins/native/syscall.c
+++ b/ksrc/skins/native/syscall.c
@@ -2098,15 +2098,19 @@ static int __rt_queue_bind(struct pt_regs *regs)
int err;
spl_t s;
 
-   xnlock_get_irqsave(&nklock, s);
-
err =
__rt_bind_helper(p, regs, &ph.opaque, XENO_QUEUE_MAGIC,
 (void **)&q, 0);
 
if (err)
-   goto unlock_and_exit;
+   return err;
+
+   xnlock_get_irqsave(&nklock, s);
+   if (xeno_test_magic(q, XENO_QUEUE_MAGIC) == 0) {
+   xnlock_put_irqrestore(&nklock, s);
 
+   return -EACCES;
+   }
ph.opaque2 = &q->bufpool;
ph.mapsize = xnheap_extentsize(&q->bufpool);
ph.area = xnheap_base_memory(&q->bufpool);
@@ -2123,12 +2127,6 @@ static int __rt_queue_bind(struct pt_regs *regs)
xnshadow_relax(0, 0);
 
return 0;
-
-  unlock_and_exit:
-
-   xnlock_put_irqrestore(&nklock, s);
-
-   return err;
 }
 
 /*
@@ -2622,15 +2620,19 @@ static int __rt_heap_bind(struct pt_regs *regs)
int err;
spl_t s;
 
-   xnlock_get_irqsave(&nklock, s);
-
err =
__rt_bind_helper(p, regs, &ph.opaque, XENO_HEAP_MAGIC,
 (void **)&heap, 0);
 
if (err)
-   goto unlock_and_exit;
+   return err;
+
+   xnlock_get_irqsave(&nklock, s);
+   if (xeno_test_magic(heap, XENO_HEAP_MAGIC) == 0) {
+   xnlock_put_irqrestore(&nklock, s);
 
+   return -EACCES;
+   }
ph.opaque2 = &heap->heap_base;
ph.mapsize = xnheap_extentsize(&heap->heap_base);
ph.area = xnheap_base_memory(&heap->heap_base);
@@ -2648,12 +2650,6 @@ static int __rt_heap_bind(struct pt_regs *regs)
xnshadow_relax(0, 0);
 
return 0;
-
-  unlock_and_exit:
-
-   xnlock_put_irqrestore(&nklock, s);
-
-   return err;
 }
 
 /*


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


[Xenomai-git] Philippe Gerum : nucleus/sem, cond: allow reinitializing anon shared objects

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

Author: Philippe Gerum 
Date:   Fri May 10 15:48:23 2013 +0200

nucleus/sem, cond: allow reinitializing anon shared objects

We allow reinitializing shared anonymous semaphores and condvars.

Rationale: if the process creating such object exits, we may assume
that other processes sharing that object won't be able to keep on
running.

This avoids the requirement for applications running in pshared mode
to destroy these synchronization objects explicitly before exiting.

---

 kernel/cobalt/cond.c |   16 +---
 kernel/cobalt/sem.c  |   34 --
 2 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/kernel/cobalt/cond.c b/kernel/cobalt/cond.c
index 1cb2cc7..538bf4f 100644
--- a/kernel/cobalt/cond.c
+++ b/kernel/cobalt/cond.c
@@ -98,6 +98,7 @@ pthread_cond_init(struct __shadow_cond *cnd, const 
pthread_condattr_t *attr)
 {
xnflags_t synch_flags = XNSYNCH_PRIO | XNSYNCH_NOPIP;
struct xnsys_ppd *sys_ppd;
+   struct xnholder *holder;
cobalt_cond_t *cond;
xnqueue_t *condq;
spl_t s;
@@ -129,17 +130,26 @@ pthread_cond_init(struct __shadow_cond *cnd, const 
pthread_condattr_t *attr)
 
condq = &cobalt_kqueues(attr->pshared)->condq;
 
+   /*
+* We allow reinitializing a shared condvar. Rationale: since
+* a condvar is inherently anonymous, if the process creating
+* such condvar exits, we may assume that other processes
+* sharing that condvar won't be able to keep on running.
+*/
if (cnd->magic == COBALT_COND_MAGIC) {
-   xnholder_t *holder;
for (holder = getheadq(condq); holder;
 holder = nextq(condq, holder))
if (holder == &cnd->cond->link) {
-   /* cond is already in the queue. */
+   if (attr->pshared) {
+   cond_destroy_internal(cnd->cond,
+ 
cobalt_kqueues(1));
+   goto do_init;
+   }
err = -EBUSY;
goto err_free_pending_signals;
}
}
-
+do_init:
cnd->attr = *attr;
cnd->pending_signals_offset =
xnheap_mapped_offset(&sys_ppd->sem_heap,
diff --git a/kernel/cobalt/sem.c b/kernel/cobalt/sem.c
index 32edafe..ec4d983 100644
--- a/kernel/cobalt/sem.c
+++ b/kernel/cobalt/sem.c
@@ -135,19 +135,33 @@ static int do_sem_init(struct __shadow_sem *sm, int 
flags, unsigned int value)
 
xnlock_get_irqsave(&nklock, s);
 
+   if (sm->magic != COBALT_SEM_MAGIC &&
+   sm->magic != COBALT_NAMED_SEM_MAGIC &&
+   sm->magic == ~COBALT_NAMED_SEM_MAGIC)
+   goto do_init;
+
semq = &cobalt_kqueues(!!(flags & SEM_PSHARED))->semq;
 
-   if (sm->magic == COBALT_SEM_MAGIC
-   || sm->magic == COBALT_NAMED_SEM_MAGIC
-   || sm->magic == ~COBALT_NAMED_SEM_MAGIC) {
-   for (holder = getheadq(semq); holder;
-holder = nextq(semq, holder))
-   if (holder == &sm->sem->link) {
-   ret = -EBUSY;
-   goto err_lock_put;
+   /*
+* Make sure we are not reinitializing a valid semaphore. As a
+* special exception, we allow reinitializing a shared
+* anonymous semaphore. Rationale: if the process creating
+* such semaphore exits, we may assume that other processes
+* sharing that semaphore won't be able to keep on running.
+*/
+   for (holder = getheadq(semq); holder;
+holder = nextq(semq, holder))
+   if (holder == &sm->sem->link) {
+   if ((flags & SEM_PSHARED) &&
+   sm->magic == COBALT_SEM_MAGIC) {
+   sem_destroy_inner(sm->sem, sem_kqueue(sm->sem));
+   goto do_init;
}
-   }
+   ret = -EBUSY;
+   goto err_lock_put;
+   }
 
+do_init:
ret = sem_init_inner(sem, flags, value);
if (ret)
goto err_lock_put;
@@ -158,7 +172,7 @@ static int do_sem_init(struct __shadow_sem *sm, int flags, 
unsigned int value)
 
return 0;
 
-  err_lock_put:
+err_lock_put:
xnlock_put_irqrestore(&nklock, s);
xnfree(sem);
 


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


[Xenomai-git] Philippe Gerum : copperplate/timerobj: wrap all sema4 calls appropriately

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

Author: Philippe Gerum 
Date:   Fri May 10 15:48:13 2013 +0200

copperplate/timerobj: wrap all sema4 calls appropriately

---

 lib/copperplate/timerobj.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/lib/copperplate/timerobj.c b/lib/copperplate/timerobj.c
index ce778d4..efa0236 100644
--- a/lib/copperplate/timerobj.c
+++ b/lib/copperplate/timerobj.c
@@ -174,7 +174,7 @@ static void *timerobj_server(void *arg)
timersv_init_corespec("timer-internal");
threadobj_set_current(THREADOBJ_IRQCONTEXT);
/* Handshake with timerobj_spawn_server(). */
-   sem_post(&svsync);
+   __RT(sem_post(&svsync));
 
for (;;) {
ret = timersv_pend_corespec();
@@ -228,6 +228,8 @@ static int timerobj_spawn_server(void)
 PTHREAD_STACK_MIN * 16,
 PTHREAD_CREATE_DETACHED,
 &svthread));
+   if (ret)
+   return ret;
 
/* Wait for timer server to initialize. */
do


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