[Xenomai-git] Philippe Gerum : cobalt/rtdm: convert legacy trace markers to kernel tracepoints

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 738f8dfec584e06c2ca370d6235769f7979804b1
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=738f8dfec584e06c2ca370d6235769f7979804b1

Author: Philippe Gerum r...@xenomai.org
Date:   Fri Apr 18 11:57:02 2014 +0200

cobalt/rtdm: convert legacy trace markers to kernel tracepoints

---

 include/cobalt/kernel/rtdm/driver.h |   17 +-
 include/cobalt/kernel/trace.h   |4 -
 kernel/cobalt/rtdm/core.c   |   73 +++---
 kernel/cobalt/rtdm/device.c |   25 +-
 kernel/cobalt/rtdm/drvlib.c |   27 +--
 kernel/cobalt/trace/cobalt-rtdm.h   |  451 +++
 6 files changed, 501 insertions(+), 96 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 50d6e02..9c432c4 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -44,6 +44,7 @@
 
 /* debug support */
 #include cobalt/kernel/assert.h
+#include trace/events/cobalt-rtdm.h
 #ifdef CONFIG_PCI
 #include asm-generic/xenomai/pci_ids.h
 #endif /* CONFIG_PCI */
@@ -1165,7 +1166,7 @@ void rtdm_toseq_init(rtdm_toseq_t *timeout_seq, 
nanosecs_rel_t timeout);
 
 /* --- event services --- */
 
-typedef struct {
+typedef struct rtdm_event {
struct xnsynch synch_base;
DECLARE_XNSELECT(select_block);
 } rtdm_event_t;
@@ -1187,13 +1188,13 @@ void __rtdm_synch_flush(struct xnsynch *synch, unsigned 
long reason);
 
 static inline void rtdm_event_pulse(rtdm_event_t *event)
 {
-   trace_mark(xn_rtdm, event_pulse, event %p, event);
+   trace_cobalt_driver_event_pulse(event);
__rtdm_synch_flush(event-synch_base, 0);
 }
 
 static inline void rtdm_event_destroy(rtdm_event_t *event)
 {
-   trace_mark(xn_rtdm, event_destroy, event %p, event);
+   trace_cobalt_driver_event_destroy(event);
__rtdm_synch_flush(event-synch_base, XNRMID);
xnselect_destroy(event-select_block);
 }
@@ -1201,7 +1202,7 @@ static inline void rtdm_event_destroy(rtdm_event_t *event)
 
 /* --- semaphore services --- */
 
-typedef struct {
+typedef struct rtdm_sem {
unsigned long value;
struct xnsynch synch_base;
DECLARE_XNSELECT(select_block);
@@ -1218,7 +1219,7 @@ void rtdm_sem_up(rtdm_sem_t *sem);
 #ifndef DOXYGEN_CPP /* Avoid static inline tags for RTDM in doxygen */
 static inline void rtdm_sem_destroy(rtdm_sem_t *sem)
 {
-   trace_mark(xn_rtdm, sem_destroy, sem %p, sem);
+   trace_cobalt_driver_sem_destroy(sem);
__rtdm_synch_flush(sem-synch_base, XNRMID);
xnselect_destroy(sem-select_block);
 }
@@ -1226,7 +1227,7 @@ static inline void rtdm_sem_destroy(rtdm_sem_t *sem)
 
 /* --- mutex services --- */
 
-typedef struct {
+typedef struct rtdm_mutex {
struct xnsynch synch_base;
 } rtdm_mutex_t;
 
@@ -1241,7 +1242,7 @@ static inline void rtdm_mutex_unlock(rtdm_mutex_t *mutex)
if (!XENO_ASSERT(RTDM, !xnsched_interrupt_p()))
return;
 
-   trace_mark(xn_rtdm, mutex_unlock, mutex %p, mutex);
+   trace_cobalt_driver_mutex_release(mutex);
 
if (unlikely(xnsynch_release(mutex-synch_base,
 xnsched_current_thread()) != NULL))
@@ -1250,7 +1251,7 @@ static inline void rtdm_mutex_unlock(rtdm_mutex_t *mutex)
 
 static inline void rtdm_mutex_destroy(rtdm_mutex_t *mutex)
 {
-   trace_mark(xn_rtdm, mutex_destroy, mutex %p, mutex);
+   trace_cobalt_driver_mutex_destroy(mutex);
 
__rtdm_synch_flush(mutex-synch_base, XNRMID);
 }
diff --git a/include/cobalt/kernel/trace.h b/include/cobalt/kernel/trace.h
index d143e3a..5f2b6ca 100644
--- a/include/cobalt/kernel/trace.h
+++ b/include/cobalt/kernel/trace.h
@@ -23,10 +23,6 @@
 #include linux/ipipe_trace.h
 #include cobalt/uapi/kernel/trace.h
 
-/* TEMP */
-#undef trace_mark
-#define trace_mark(channel, ev, fmt, args...)  do { } while (0)
-
 static inline int xntrace_max_begin(unsigned long v)
 {
ipipe_trace_begin(v);
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 71f6d08..5c3af51 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -26,13 +26,14 @@
  * @{
  */
 
+#include linux/workqueue.h
 #include cobalt/kernel/ppd.h
 #include cobalt/kernel/heap.h
 #include cobalt/kernel/apc.h
 #include rtdm/syscall.h
 #include rtdm/internal.h
-
-#include linux/workqueue.h
+#define CREATE_TRACE_POINTS
+#include trace/events/cobalt-rtdm.h
 
 #define CLOSURE_RETRY_PERIOD_MS100
 
@@ -229,7 +230,7 @@ static void close_callback(struct work_struct *work)
if (err == -EAGAIN)
reschedule = 1;
} else {
-   trace_mark(xn_rtdm, fd_closed, fd %d, context-fd);
+   trace_cobalt_fd_closed(context);
 
cleanup_instance(context-device, context,
 test_bit(RTDM_CREATED_IN_NRT,
@@ -263,8 +264,6 @@ 

[Xenomai-git] Philippe Gerum : cobalt/kernel: bump ABI revision level

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 164059a20d6c7451800452912787053ea1787c0b
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=164059a20d6c7451800452912787053ea1787c0b

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 24 16:10:43 2014 +0200

cobalt/kernel: bump ABI revision level

---

 kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h  |2 +-
 kernel/cobalt/arch/blackfin/include/asm/xenomai/uapi/features.h |2 +-
 kernel/cobalt/arch/nios2/include/asm/xenomai/uapi/features.h|2 +-
 kernel/cobalt/arch/powerpc/include/asm/xenomai/uapi/features.h  |2 +-
 kernel/cobalt/arch/sh/include/asm/xenomai/uapi/features.h   |2 +-
 kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h  |2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h 
b/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
index 28bfecc..2570664 100644
--- a/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
+++ b/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
@@ -29,7 +29,7 @@
 #define __XN_TSC_TYPE_FREERUNNING_COUNTDOWN 5
 
 /* The ABI revision level we use on this arch. */
-#define XENOMAI_ABI_REV   5UL
+#define XENOMAI_ABI_REV   6UL
 
 #define XENOMAI_FEAT_DEP (__xn_feat_generic_mask)
 
diff --git a/kernel/cobalt/arch/blackfin/include/asm/xenomai/uapi/features.h 
b/kernel/cobalt/arch/blackfin/include/asm/xenomai/uapi/features.h
index fa1b46f..9eedd29 100644
--- a/kernel/cobalt/arch/blackfin/include/asm/xenomai/uapi/features.h
+++ b/kernel/cobalt/arch/blackfin/include/asm/xenomai/uapi/features.h
@@ -19,7 +19,7 @@
 #define _COBALT_BLACKFIN_ASM_UAPI_FEATURES_H
 
 /* The ABI revision level we use on this arch. */
-#define XENOMAI_ABI_REV   5UL
+#define XENOMAI_ABI_REV   6UL
 
 #define XENOMAI_FEAT_DEP  __xn_feat_generic_mask
 
diff --git a/kernel/cobalt/arch/nios2/include/asm/xenomai/uapi/features.h 
b/kernel/cobalt/arch/nios2/include/asm/xenomai/uapi/features.h
index 09017f9..b168993 100644
--- a/kernel/cobalt/arch/nios2/include/asm/xenomai/uapi/features.h
+++ b/kernel/cobalt/arch/nios2/include/asm/xenomai/uapi/features.h
@@ -19,7 +19,7 @@
 #define _COBALT_NIOS2_ASM_UAPI_FEATURES_H
 
 /* The ABI revision level we use on this arch. */
-#define XENOMAI_ABI_REV   4UL
+#define XENOMAI_ABI_REV   5UL
 
 #define XENOMAI_FEAT_DEP  __xn_feat_generic_mask
 
diff --git a/kernel/cobalt/arch/powerpc/include/asm/xenomai/uapi/features.h 
b/kernel/cobalt/arch/powerpc/include/asm/xenomai/uapi/features.h
index 8d404a2..46e51c2 100644
--- a/kernel/cobalt/arch/powerpc/include/asm/xenomai/uapi/features.h
+++ b/kernel/cobalt/arch/powerpc/include/asm/xenomai/uapi/features.h
@@ -19,7 +19,7 @@
 #define _COBALT_POWERPC_ASM_UAPI_FEATURES_H
 
 /* The ABI revision level we use on this arch. */
-#define XENOMAI_ABI_REV   5UL
+#define XENOMAI_ABI_REV   6UL
 
 #define XENOMAI_FEAT_DEP  __xn_feat_generic_mask
 
diff --git a/kernel/cobalt/arch/sh/include/asm/xenomai/uapi/features.h 
b/kernel/cobalt/arch/sh/include/asm/xenomai/uapi/features.h
index 2559ac1..4be9417 100644
--- a/kernel/cobalt/arch/sh/include/asm/xenomai/uapi/features.h
+++ b/kernel/cobalt/arch/sh/include/asm/xenomai/uapi/features.h
@@ -19,7 +19,7 @@
 #define _COBALT_SH_ASM_FEATURES_H
 
 /* The ABI revision level we use on this arch. */
-#define XENOMAI_ABI_REV   2UL
+#define XENOMAI_ABI_REV   3UL
 
 #define XENOMAI_FEAT_DEP  __xn_feat_generic_mask
 
diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h 
b/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
index 68f88c0..3884c5a 100644
--- a/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
+++ b/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
@@ -19,7 +19,7 @@
 #define _COBALT_X86_ASM_UAPI_FEATURES_H
 
 /* The ABI revision level we use on this arch. */
-#define XENOMAI_ABI_REV   5UL
+#define XENOMAI_ABI_REV   6UL
 
 #define XENOMAI_FEAT_DEP  __xn_feat_generic_mask
 


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


[Xenomai-git] Philippe Gerum : alchemy/task: export kernel tid to RT_TASK_INFO

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: b41ecb043b44b3a0df185ec9d6d812f40d25d6af
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=b41ecb043b44b3a0df185ec9d6d812f40d25d6af

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Apr 23 12:31:25 2014 +0200

alchemy/task: export kernel tid to RT_TASK_INFO

---

 doc/asciidoc/MIGRATION.adoc |2 ++
 include/alchemy/task.h  |4 
 lib/alchemy/task.c  |1 +
 3 files changed, 7 insertions(+)

diff --git a/doc/asciidoc/MIGRATION.adoc b/doc/asciidoc/MIGRATION.adoc
index a013447..b7a5787 100644
--- a/doc/asciidoc/MIGRATION.adoc
+++ b/doc/asciidoc/MIGRATION.adoc
@@ -724,6 +724,8 @@ Rationale: This behavior can be achieved by not calling
  corresponding information is too short-lived to be valuable to
  the caller. The task's base priority is still available from
  the +prio+ field.
+   * new field +pid+ represents the Linux kernel task identifier for
+ the Alchemy task, as obtained from syscall(__NR_gettid).
* other fields which represent runtime statistics are now avail
  from a core-specific +stat+ field sub-structure.
 
diff --git a/include/alchemy/task.h b/include/alchemy/task.h
index 7a2eb1c..0387e57 100644
--- a/include/alchemy/task.h
+++ b/include/alchemy/task.h
@@ -76,6 +76,10 @@ struct RT_TASK_INFO {
 * Name of task.
 */
char name[XNOBJECT_NAME_LEN];
+   /**
+* Host pid.
+*/
+   pid_t pid;
 };
 
 typedef struct RT_TASK_INFO RT_TASK_INFO;
diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index 8d106fc..254aa5f 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -1480,6 +1480,7 @@ int rt_task_inquire(RT_TASK *task, RT_TASK_INFO *info)
 
strcpy(info-name, tcb-name);
info-prio = threadobj_get_priority(tcb-thobj);
+   info-pid = threadobj_get_pid(tcb-thobj);
 
put_alchemy_task(tcb);
 out:


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


[Xenomai-git] Philippe Gerum : include/rtdm: fix rt_dev API wrappers

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 1562a3f9811a22a9d7ea7d16c658a10e13d7e781
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1562a3f9811a22a9d7ea7d16c658a10e13d7e781

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 24 17:21:35 2014 +0200

include/rtdm: fix rt_dev API wrappers

---

 include/rtdm/rtdm.h |   26 +-
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/include/rtdm/rtdm.h b/include/rtdm/rtdm.h
index 92b228f..88deee6 100644
--- a/include/rtdm/rtdm.h
+++ b/include/rtdm/rtdm.h
@@ -41,6 +41,7 @@
 #include fcntl.h
 #include stddef.h
 #include stdint.h
+#include errno.h
 #include unistd.h
 #include sys/ioctl.h
 #include sys/socket.h
@@ -51,15 +52,22 @@
  */
 #ifndef RTDM_NO_DEFAULT_USER_API
 
-#define rt_dev_open__RT(open)
-#define rt_dev_socket  __RT(socket)
-#define rt_dev_close   __RT(close)
-#define rt_dev_ioctl   __RT(ioctl)
-#define rt_dev_read__RT(read)
-#define rt_dev_write   __RT(write)
-#define rt_dev_recvmsg __RT(recvmsg)
-#define rt_dev_sendmsg __RT(sendmsg)
-#define rt_dev_recvfrom __RT(recvfrom)
+#define rt_dev_call(__call, __args...) \
+({ \
+   int __ret;  \
+   __ret = __RT(__call(__args));   \
+   __ret  0 ? -errno : __ret; \
+})
+
+#define rt_dev_open(__args...) rt_dev_call(open, __args)
+#define rt_dev_socket(__args...)   rt_dev_call(socket, __args)
+#define rt_dev_close(__args...)rt_dev_call(close, __args)
+#define rt_dev_ioctl(__args...)rt_dev_call(ioctl, __args)
+#define rt_dev_read(__args...) rt_dev_call(read, __args)
+#define rt_dev_write(__args...)rt_dev_call(write, __args)
+#define rt_dev_recvmsg(__args...)  rt_dev_call(recvmsg, __args)
+#define rt_dev_sendmsg(__args...)  rt_dev_call(sendmsg, __args)
+#define rt_dev_recvfrom(__args...) rt_dev_call(recvfrom, __args)
 
 #endif /* !RTDM_NO_DEFAULT_USER_API */
 


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


[Xenomai-git] Philippe Gerum : copperplate/threadobj: protect threadobj_sleep() against spurious wakeups

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: e11e248a57127d5020d7e6d18e894e792e9b59c3
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=e11e248a57127d5020d7e6d18e894e792e9b59c3

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Apr 22 18:57:18 2014 +0200

copperplate/threadobj: protect threadobj_sleep() against spurious wakeups

threadobj_sleep() should return upon wait completion or
threadobj_unblock() request, whichever comes first. However, receiving
a regular linux signal should not abort this call.

---

 include/copperplate/clockobj.h   |2 +
 include/copperplate/threadobj.h  |4 +
 include/mercury/boilerplate/signal.h |1 +
 lib/copperplate/syncobj.c|6 +-
 lib/copperplate/threadobj.c  |  173 ++
 5 files changed, 143 insertions(+), 43 deletions(-)

diff --git a/include/copperplate/clockobj.h b/include/copperplate/clockobj.h
index 58dbbf9..bbc2cf2 100644
--- a/include/copperplate/clockobj.h
+++ b/include/copperplate/clockobj.h
@@ -51,6 +51,8 @@ struct clockobj {
const char *name;   /* __ref FIXME */
 };
 
+#define zero_time  ((struct timespec){ .tv_sec = 0, .tv_nsec = 0 })
+
 #ifdef __cplusplus
 extern C {
 #endif
diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 2c6794f..5438790 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -22,6 +22,7 @@
 #include time.h
 #include sched.h
 #include semaphore.h
+#include signal.h
 #include pthread.h
 #include boilerplate/list.h
 #include boilerplate/lock.h
@@ -88,6 +89,9 @@ struct threadobj_corespec {
ticks_t period;
/** Timeout reported by sysregd. */
struct timespec timeout;
+   /** Timer data for threadobj_sleep() */
+   struct sigevent sleep_sev;
+   timer_t sleep_timer;
 };
 
 struct threadobj_stat {
diff --git a/include/mercury/boilerplate/signal.h 
b/include/mercury/boilerplate/signal.h
index 14523cd..996711f 100644
--- a/include/mercury/boilerplate/signal.h
+++ b/include/mercury/boilerplate/signal.h
@@ -26,6 +26,7 @@
 
 #define SIGNOTIFY  (SIGRTMIN + 8) /* Internal notification */
 #define SIGRELS(SIGRTMIN + 9) /* Syscall abort */
+#define SIGWAKEUP  (SIGRTMIN + 10) /* Sleep abort */
 
 #define SIGSAFE_LOCK_ENTRY(__safelock) \
do {\
diff --git a/lib/copperplate/syncobj.c b/lib/copperplate/syncobj.c
index 7834f86..5aee1a2 100644
--- a/lib/copperplate/syncobj.c
+++ b/lib/copperplate/syncobj.c
@@ -50,9 +50,9 @@
  * emulated via a mutex and two condition variables over Mercury (one
  * of which being hosted by the thread object implementation).
  *
- * NOTE: we do no do error backtracing in this file, since error
- * returns when locking, pending or deleting sync objects express
- * normal runtime conditions.
+ * NOTE: we don't do error backtracing in this file, since error
+ * returns when locking, pending or deleting sync objects usually
+ * express normal runtime conditions.
  */
 
 #ifdef CONFIG_XENO_COBALT
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index a2a9dcd..9901a54 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -178,6 +178,43 @@ int threadobj_resume(struct threadobj *thobj) /* 
thobj-lock held */
return __bt(-ret);
 }
 
+int threadobj_sleep(struct timespec *ts)
+{
+   struct threadobj *current = threadobj_current();
+   sigset_t set;
+   int sig, ret;
+
+   /*
+* threadobj_sleep() shall return -EINTR immediately upon
+* threadobj_unblock(), to honor forced wakeup semantics for
+* RTOS personalities.
+*
+* Otherwise, the sleep should be silently restarted until
+* completion after a Linux signal is handled.
+*/
+   current-run_state = __THREAD_S_DELAYED;
+   threadobj_save_timeout(current-core, ts);
+
+   do {
+   /*
+* Waiting on a null signal set causes an infinite
+* delay, so that only threadobj_unblock() or a linux
+* signal can unblock us.
+*/
+   if (ts-tv_sec == 0  ts-tv_nsec == 0) {
+   sigemptyset(set);
+   ret = -__RT(sigwait(set, sig));
+   } else
+   ret = -__RT(clock_nanosleep(CLOCK_COPPERPLATE,
+   TIMER_ABSTIME, ts, NULL));
+   } while (ret == -EINTR 
+(current-core.u_window-info  XNBREAK) == 0);
+
+   current-run_state = __THREAD_S_RUNNING;
+
+   return ret;
+}
+
 int __threadobj_lock_sched(struct threadobj *current)
 {
smp_rmb();
@@ -405,6 +442,7 @@ static inline void pkg_init_corespec(void)
memset(sa, 0, sizeof(sa));
sa.sa_handler = unblock_sighandler;
sigaction(SIGRELS, sa, NULL);
+   

[Xenomai-git] Philippe Gerum : boilerplate/debug: handle NULL name thread gracefully

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 269dae0054e428680f20f52e7366bc3a69a83838
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=269dae0054e428680f20f52e7366bc3a69a83838

Author: Philippe Gerum r...@xenomai.org
Date:   Sun Apr 20 11:59:06 2014 +0200

boilerplate/debug: handle NULL name thread gracefully

---

 lib/boilerplate/debug.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/boilerplate/debug.c b/lib/boilerplate/debug.c
index 37de802..d77b1d9 100644
--- a/lib/boilerplate/debug.c
+++ b/lib/boilerplate/debug.c
@@ -106,7 +106,7 @@ void backtrace_init_context(struct backtrace_data *btd,
 {
__RT(pthread_mutex_init(btd-lock, NULL));
btd-inner = NULL;
-   btd-name = name;
+   btd-name = name ?: anonymous;
pthread_setspecific(btkey, btd);
 }
 


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


[Xenomai-git] Philippe Gerum : copperplate/clockobj: drop useless locking in clockobj_ticks_to_timespec()

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 57afcb16fd9c5bc3feeea5544ef0f5f6c072619e
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=57afcb16fd9c5bc3feeea5544ef0f5f6c072619e

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 24 16:54:27 2014 +0200

copperplate/clockobj: drop useless locking in clockobj_ticks_to_timespec()

---

 include/copperplate/clockobj.h |2 --
 1 file changed, 2 deletions(-)

diff --git a/include/copperplate/clockobj.h b/include/copperplate/clockobj.h
index bbc2cf2..28709ae 100644
--- a/include/copperplate/clockobj.h
+++ b/include/copperplate/clockobj.h
@@ -206,9 +206,7 @@ static inline
 void clockobj_ticks_to_timespec(struct clockobj *clkobj,
ticks_t ticks, struct timespec *ts)
 {
-   read_lock_nocancel(clkobj-lock);
__clockobj_ticks_to_timespec(clkobj, ticks, ts);
-   read_unlock(clkobj-lock);
 }
 
 static inline


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


[Xenomai-git] Philippe Gerum : copperplate/registry: protect locked sections traversing cancellation points

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 53e104fbc6b262dd1d8bb093e36cf7f5c711e9d3
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=53e104fbc6b262dd1d8bb093e36cf7f5c711e9d3

Author: Philippe Gerum r...@xenomai.org
Date:   Mon Apr 21 16:37:19 2014 +0200

copperplate/registry: protect locked sections traversing cancellation points

All fs methods invoking user-defined handlers may reach cancellation
points indirectly, so protect all locks held across those calls
against asynchronous cancellation of the registry thread (although
this should never happen under normal circumstances).

---

 lib/copperplate/registry.c |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/copperplate/registry.c b/lib/copperplate/registry.c
index b3ef2ed..1606cd7 100644
--- a/lib/copperplate/registry.c
+++ b/lib/copperplate/registry.c
@@ -367,7 +367,8 @@ static int regfs_open(const char *path, struct 
fuse_file_info *fi)
int ret = 0;
void *priv;
 
-   read_lock_nocancel(p-lock);
+   push_cleanup_lock(p-lock);
+   read_lock(p-lock);
 
hobj = pvhash_search(p-files, path, strlen(path));
if (hobj == NULL) {
@@ -395,6 +396,7 @@ static int regfs_open(const char *path, struct 
fuse_file_info *fi)
ret = __bt(fsobj-ops-open(fsobj, priv));
 done:
read_unlock(p-lock);
+   pop_cleanup_lock(p-lock);
 
return __bt(ret);
 }
@@ -407,7 +409,8 @@ static int regfs_release(const char *path, struct 
fuse_file_info *fi)
int ret = 0;
void *priv;
 
-   read_lock_nocancel(p-lock);
+   push_cleanup_lock(p-lock);
+   read_lock(p-lock);
 
hobj = pvhash_search(p-files, path, strlen(path));
if (hobj == NULL) {
@@ -423,6 +426,7 @@ static int regfs_release(const char *path, struct 
fuse_file_info *fi)
__STD(free(priv));
 done:
read_unlock(p-lock);
+   pop_cleanup_lock(p-lock);
 
return __bt(ret);
 }


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


[Xenomai-git] Philippe Gerum : copperplate/threadobj: fix cancel state upon start failure

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 2dcd9cd1e38cfb41dc57e30555732a208214b7b7
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=2dcd9cd1e38cfb41dc57e30555732a208214b7b7

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Apr 23 15:41:38 2014 +0200

copperplate/threadobj: fix cancel state upon start failure

---

 lib/copperplate/threadobj.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 5429876..a17870c 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -1082,6 +1082,8 @@ int threadobj_start(struct threadobj *thobj)  /* 
thobj-lock held. */
 * caller to forget about it as well.
 */
if (thobj-run_state == __THREAD_S_DORMANT) {
+   /* Keep cancel-safe after unlock. */
+   thobj-cancel_state = PTHREAD_CANCEL_DISABLE;
threadobj_unlock(thobj);
destroy_thread(thobj);
threadobj_free(thobj);


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


[Xenomai-git] Philippe Gerum : cobalt/sched-tp: only warn on partition crossing ( do not panic)

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: a30ea084cb9889a2138593286e87da086838a7bb
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=a30ea084cb9889a2138593286e87da086838a7bb

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 24 16:46:42 2014 +0200

cobalt/sched-tp: only warn on partition crossing (do not panic)

---

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

diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c
index 794f4c9..13c4416 100644
--- a/kernel/cobalt/sched-tp.c
+++ b/kernel/cobalt/sched-tp.c
@@ -152,7 +152,7 @@ static void xnsched_tp_trackprio(struct xnthread *thread,
 */
if (p) {
/* We should never cross partition boundaries. */
-   XENO_BUGON(NUCLEUS,
+   XENO_WARNON(NUCLEUS,
   thread-base_class == xnsched_class_tp 
   thread-tps - thread-sched-tp.partitions != 
p-tp.ptid);
thread-cprio = p-tp.prio;


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


[Xenomai-git] Philippe Gerum : cobalt/rtdm: introduce wait queue API

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: c5166b879f28592d258a93c4d1e84d4cc9b934bf
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=c5166b879f28592d258a93c4d1e84d4cc9b934bf

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 10 11:40:15 2014 +0200

cobalt/rtdm: introduce wait queue API

---

 include/cobalt/kernel/rtdm/driver.h |  490 ++-
 1 file changed, 483 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 9c432c4..b9d7649 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -605,6 +605,12 @@ static inline nanosecs_abs_t 
rtdm_clock_read_monotonic(void)
 }
 #endif /* !DOXYGEN_CPP */
 
+/* --- timeout sequences */
+
+typedef nanosecs_abs_t rtdm_toseq_t;
+
+void rtdm_toseq_init(rtdm_toseq_t *timeout_seq, nanosecs_rel_t timeout);
+
 /*!
  * @addtogroup rtdmsync
  * @{
@@ -620,7 +626,7 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector,
  */
 
 /**
- * @brief Execute code block atomically
+ * @brief Execute code block atomically (DEPRECATED)
  *
  * Generally, it is illegal to suspend the current task by calling
  * rtdm_task_sleep(), rtdm_event_wait(), etc. while holding a spinlock. In
@@ -650,6 +656,9 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector,
  * - User-space task (RT, non-RT)
  *
  * Rescheduling: possible, depends on functions called within @a code_block.
+ *
+ * @warning This construct is deprecated and will be phased out in
+ * Xenomai 3.0. Please use rtdm_waitqueue services instead.
  */
 #ifdef DOXYGEN_CPP /* Beautify doxygen output */
 #define RTDM_EXECUTE_ATOMICALLY(code_block)\
@@ -659,10 +668,14 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector,
LEAVE_ATOMIC_SECTION  \
 }
 #else /* This is how it really works */
+static inline __attribute__((deprecated)) void
+rtdm_execute_atomically(void) { }
+
 #define RTDM_EXECUTE_ATOMICALLY(code_block)\
 {  \
spl_t __rtdm_s; \
\
+   rtdm_execute_atomically();  \
xnlock_get_irqsave(nklock, __rtdm_s);  \
__xnsched_lock();   \
code_block; \
@@ -670,6 +683,7 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector,
xnlock_put_irqrestore(nklock, __rtdm_s);   \
 }
 #endif
+
 /** @} Global Lock across Scheduler Invocation */
 
 /*!
@@ -845,8 +859,476 @@ void rtdm_lock_put_irqrestore(rtdm_lock_t *lock, 
rtdm_lockctx_t s)
  */
 #define rtdm_lock_irqrestore(context)  \
splexit(context)
+
+/**
+ * @brief Enter atomic section (dual kernel only)
+ *
+ * This call opens a fully atomic section, serializing execution with
+ * respect to all interrupt handlers (including for real-time IRQs)
+ * and Xenomai threads running on all CPUs.
+ *
+ * @param context name of local variable to store the context in. This
+ * variable updated by the real-time core will hold the information
+ * required to leave the atomic section properly.
+ *
+ * @note Atomic sections may be nested.
+ *
+ * @note Since the strongest lock is acquired by this service, it can
+ * be used to synchronize real-time and non-real-time contexts.
+ *
+ * @warning This service is not portable to the Mercury core, and
+ * should be restricted to Cobalt-specific use cases.
+ */
+#define cobalt_atomic_enter(context)   \
+   do {\
+   xnlock_get_irqsave(nklock, (context)); \
+   __xnsched_lock();   \
+   } while (0)
+
+/**
+ * @brief Leave atomic section (dual kernel only)
+ *
+ * This call closes an atomic section previously opened by a call to
+ * cobalt_atomic_enter(), restoring the preemption and interrupt state
+ * which prevailed prior to entering the exited section.
+ *
+ * @param context name of local variable which stored the context.
+ *
+ * @warning This service is not portable to the Mercury core, and
+ * should be restricted to Cobalt-specific use cases.
+ */
+#define cobalt_atomic_leave(context)   \
+   do {\
+   __xnsched_unlock(); \
+   xnlock_put_irqrestore(nklock, (context));  \
+   } while (0)
+
 /** @} Spinlock with Preemption Deactivation */
 
+/*!
+ * @name Signal, test and wait for a condition atomically
+ * @{
+ */
+struct rtdm_waitqueue {
+   struct xnsynch wait;
+};
+typedef struct rtdm_waitqueue rtdm_waitqueue_t;
+
+#define RTDM_WAITQUEUE_INITIALIZER(__name) {\
+   .wait = XNSYNCH_WAITQUEUE_INITIALIZER((__name).wait), \
+   }
+
+#define DEFINE_RTDM_WAITQUEUE(__name)  \
+

[Xenomai-git] Philippe Gerum : vxworks/testsuite: add VALGRIND prefix to test commands

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: af9a7be02c59582c8bde4c08300391f1ab3c197e
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=af9a7be02c59582c8bde4c08300391f1ab3c197e

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Apr 29 11:19:54 2014 +0200

vxworks/testsuite: add VALGRIND prefix to test commands

---

 lib/vxworks/testsuite/Makefile |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/vxworks/testsuite/Makefile b/lib/vxworks/testsuite/Makefile
index ef325e7..6719c81 100644
--- a/lib/vxworks/testsuite/Makefile
+++ b/lib/vxworks/testsuite/Makefile
@@ -30,10 +30,10 @@ clean:
 test: all
@for t in $(TESTS); do \
echo -n $$t...; \
-   sudo LD_LIBRARY_PATH=$(solibs) ./$$t --cpu-affinity=0 --silent 
 echo ok || echo BAD; \
+   sudo LD_LIBRARY_PATH=$(solibs) $(VALGRIND) ./$$t 
--cpu-affinity=0 --silent  echo ok || echo BAD; \
done
 
 test/%: %
-   sudo LD_LIBRARY_PATH=$(solibs) ./$(@F) --cpu-affinity=0 --silent  
echo ok || echo BAD
+   sudo LD_LIBRARY_PATH=$(solibs) $(VALGRIND) ./$(@F) --cpu-affinity=0 
--silent  echo ok || echo BAD
 
 .PHONY: clean test


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


[Xenomai-git] Philippe Gerum : build: automate Valgrind API detection

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: e3745af185e4d3ae5bf690c18d4f61a686d9e9b7
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=e3745af185e4d3ae5bf690c18d4f61a686d9e9b7

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Apr 30 10:54:11 2014 +0200

build: automate Valgrind API detection

When the Valgrind API is available to the application process, the
configuration symbol CONFIG_XENO_VALGRIND_API is defined at build
time, and may be tested for existence by the application code. See the
tool documentation at this address:
http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq/

The autoconf script will detect the Valgrind core header on the build
system automatically, and define this symbol accordingly
(i.e. /usr/include/valgrind/valgrind.h).

---

 configure |9 +
 configure.ac  |2 ++
 doc/asciidoc/README.APPLICATIONS.adoc |   20 
 include/xeno_config.h.in  |3 +++
 4 files changed, 34 insertions(+)

diff --git a/configure b/configure
index 8cb3f17..cfd9c60 100755
--- a/configure
+++ b/configure
@@ -13882,6 +13882,15 @@ fi
 
 done
 
+ac_fn_c_check_header_mongrel $LINENO valgrind/valgrind.h 
ac_cv_header_valgrind_valgrind_h $ac_includes_default
+if test x$ac_cv_header_valgrind_valgrind_h = xyes; then :
+  CONFIG_XENO_VALGRIND_API=y
+fi
+
+
+test x$CONFIG_XENO_VALGRIND_API = xy 
+$as_echo #define CONFIG_XENO_VALGRIND_API 1 confdefs.h
+
 
 save_LIBS=$LIBS
 LIBS=$LIBS -lrt -lpthread
diff --git a/configure.ac b/configure.ac
index 837477f..73b9542 100644
--- a/configure.ac
+++ b/configure.ac
@@ -499,6 +499,8 @@ fi
 
 dnl Determine whether some specific headers are present on this system.
 AC_CHECK_HEADERS(mqueue.h)
+AC_CHECK_HEADER(valgrind/valgrind.h,CONFIG_XENO_VALGRIND_API=y)
+test x$CONFIG_XENO_VALGRIND_API = xy  
AC_DEFINE(CONFIG_XENO_VALGRIND_API,1,[config])
 
 dnl Check for presence of some routines we need
 save_LIBS=$LIBS
diff --git a/doc/asciidoc/README.APPLICATIONS.adoc 
b/doc/asciidoc/README.APPLICATIONS.adoc
index b9ebea1..e665745 100644
--- a/doc/asciidoc/README.APPLICATIONS.adoc
+++ b/doc/asciidoc/README.APPLICATIONS.adoc
@@ -162,6 +162,26 @@ switch]).
defined as a result of running the configure script. The
program immediately exits with a success code afterwards.
 
+Valgrind support
+
+
+Running Xenomai applications over _Valgrind_ is currently available to
+the _Mercury_ core only.
+
+When the Valgrind API is available to the application process, the
+configuration symbol CONFIG_XENO_VALGRIND_API is defined at build
+time, and may be tested for existence by the application code. See the
+tool documentation at
+http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq/[this
 address].
+
+The Xenomai autoconf script will detect the Valgrind core header on
+the build system automatically, and define this symbol accordingly
+(i.e. /usr/include/valgrind/valgrind.h).
+
+NOTE: You may need to install the Valgrind development package on your
+build system to provide for the core header files. For instance, such
+package is called _valgrind-devel_ on Fedora.
+
 Available real-time APIs
 
 
diff --git a/include/xeno_config.h.in b/include/xeno_config.h.in
index fe9e02c..b712cc8 100644
--- a/include/xeno_config.h.in
+++ b/include/xeno_config.h.in
@@ -76,6 +76,9 @@
 #undef CONFIG_XENO_UAPI_LEVEL
 
 /* config */
+#undef CONFIG_XENO_VALGRIND_API
+
+/* config */
 #undef CONFIG_XENO_VERSION_MAJOR
 
 /* config */


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


[Xenomai-git] Philippe Gerum : psos/testsuite: add VALGRIND prefix to test commands

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 048b128a6c0abfc122651325d15ce171789acd33
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=048b128a6c0abfc122651325d15ce171789acd33

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Apr 29 11:19:50 2014 +0200

psos/testsuite: add VALGRIND prefix to test commands

---

 lib/psos/testsuite/Makefile |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/psos/testsuite/Makefile b/lib/psos/testsuite/Makefile
index f396bc9..79e1b79 100644
--- a/lib/psos/testsuite/Makefile
+++ b/lib/psos/testsuite/Makefile
@@ -36,10 +36,10 @@ clean:
 test: all
@for t in $(TESTS); do \
echo -n $$t...; \
-   sudo LD_LIBRARY_PATH=$(solibs) ./$$t --cpu-affinity=0 --silent 
 echo ok || echo BAD; \
+   sudo LD_LIBRARY_PATH=$(solibs) $(VALGRIND) ./$$t 
--cpu-affinity=0 --silent  echo ok || echo BAD; \
done
 
 test/%: %
-   sudo LD_LIBRARY_PATH=$(solibs) ./$(@F) --cpu-affinity=0 --silent  
echo ok || echo BAD
+   sudo LD_LIBRARY_PATH=$(solibs) $(VALGRIND) ./$(@F) --cpu-affinity=0 
--silent  echo ok || echo BAD
 
 .PHONY: clean test


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


[Xenomai-git] Matthias Schneider : copperplate/notifier: drop pointless select() loop from sighandler

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 2f73e419575f23566613c97b7fa0279519e558a4
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=2f73e419575f23566613c97b7fa0279519e558a4

Author: Matthias Schneider ma30002...@yahoo.de
Date:   Wed Apr 23 15:44:53 2014 +0200

copperplate/notifier: drop pointless select() loop from sighandler

---

 lib/copperplate/notifier.c |   24 +---
 1 file changed, 1 insertion(+), 23 deletions(-)

diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index d069a66..7fa48f3 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -34,41 +34,21 @@ static pthread_mutex_t notifier_lock;
 
 static struct sigaction notifier_old_sa;
 
-static fd_set notifier_rset;
-
 static void notifier_sighandler(int sig, siginfo_t *siginfo, void *uc)
 {
-   static struct timeval tv = { .tv_sec = 0, .tv_usec = 0 };
int ret, matched = 0;
struct notifier *nf;
-   fd_set rfds;
pid_t tid;
char c;
 
tid = copperplate_get_tid();
 
-   if (siginfo-si_code == SI_SIGIO) {
-   FD_ZERO(rfds);
-   FD_SET(siginfo-si_fd, rfds);
-   } else {
-   /*
-* We will have to find out by ourselves which fd was
-* notified.
-*/
-   rfds = notifier_rset;
-   do
-   ret = __STD(select(FD_SETSIZE, rfds, NULL, NULL, tv));
-   while (ret == -1  errno == EINTR);
-   if (ret = 0)
-   goto hand_over;
-   }
-
if (pvlist_empty(notifier_list))
goto hand_over;
 
/* We may NOT alter the notifier list, but only scan it. */
pvlist_for_each_entry(nf, notifier_list, link) {
-   if (!FD_ISSET(nf-psfd[0], rfds))
+   if (nf-psfd[0] != siginfo-si_fd)
continue;
/*
 * Ignore misdirected notifications. We want those to
@@ -173,7 +153,6 @@ int notifier_init(struct notifier *nf,
push_cleanup_lock(notifier_lock);
lock_notifier_list(oset);
pvlist_append(nf-link, notifier_list);
-   FD_SET(nf-psfd[0], notifier_rset);
unlock_notifier_list(oset);
pop_cleanup_lock(notifier_lock);
 
@@ -208,7 +187,6 @@ void notifier_destroy(struct notifier *nf)
push_cleanup_lock(notifier_lock);
lock_notifier_list(oset);
pvlist_remove(nf-link);
-   FD_CLR(nf-psfd[0], notifier_rset);
unlock_notifier_list(oset);
pop_cleanup_lock(notifier_lock);
__STD(close(nf-psfd[0]));


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


[Xenomai-git] Philippe Gerum : copperplate/traceobj: suppress sequence mismatch report over Valgrind

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 4da1cc38cb4e5d19e1526aab2cc3dd5b747b789b
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=4da1cc38cb4e5d19e1526aab2cc3dd5b747b789b

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Apr 30 10:55:46 2014 +0200

copperplate/traceobj: suppress sequence mismatch report over Valgrind

The normal scheduling order of an application is significantly
affected by running over Valgrind. For this reason, reports of
execution sequence mismatches are meaningless in such context.

---

 lib/copperplate/traceobj.c |   19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/lib/copperplate/traceobj.c b/lib/copperplate/traceobj.c
index 6bec5dc..1a01cd0 100644
--- a/lib/copperplate/traceobj.c
+++ b/lib/copperplate/traceobj.c
@@ -23,6 +23,18 @@
 #include copperplate/heapobj.h
 #include copperplate/init.h
 #include internal.h
+#ifdef CONFIG_XENO_VALGRIND_API
+#include valgrind/valgrind.h
+static inline int valgrind_detected(void)
+{
+   return RUNNING_ON_VALGRIND;
+}
+#else
+static inline int valgrind_detected(void)
+{
+   return 0;
+}
+#endif
 
 struct tracemark {
const char *file;
@@ -110,11 +122,16 @@ void traceobj_verify(struct traceobj *trobj, int tseq[], 
int nr_seq)
if (trobj-marks[mark].mark != tseq[mark])
goto fail;
}
-
+out:
read_unlock_safe(trobj-lock, state);
return;
 
 fail:
+   if (valgrind_detected()) {
+   warning(valgrind detected: ignoring sequence mismatch);
+   goto out;
+   }
+   
warning(mismatching execution sequence detected);
compare_marks(trobj, tseq, nr_seq);
read_unlock_safe(trobj-lock, state);


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


[Xenomai-git] Philippe Gerum : alchemy: do not publish half-baked objects

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: bdfcfe58150ceee57efb4bef702a912760a65b3d
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=bdfcfe58150ceee57efb4bef702a912760a65b3d

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Apr 29 18:25:42 2014 +0200

alchemy: do not publish half-baked objects

Object control blocks must be fully built and sane before indexed by
their respective clusters. Otherwise, binding operations from remote
threads may succeed too early, which open windows for referring to
partly initialized objects, which would be quite unfortunate.

---

 lib/alchemy/alarm.c  |   13 +++--
 lib/alchemy/buffer.c |   14 --
 lib/alchemy/cond.c   |   12 +++-
 lib/alchemy/event.c  |   14 --
 lib/alchemy/heap.c   |   14 --
 lib/alchemy/mutex.c  |   12 +++-
 lib/alchemy/queue.c  |   14 --
 lib/alchemy/sem.c|   12 +++-
 lib/alchemy/task.c   |   16 
 9 files changed, 68 insertions(+), 53 deletions(-)

diff --git a/lib/alchemy/alarm.c b/lib/alchemy/alarm.c
index 16475d4..4e38941 100644
--- a/lib/alchemy/alarm.c
+++ b/lib/alchemy/alarm.c
@@ -189,22 +189,23 @@ int rt_alarm_create(RT_ALARM *alarm, const char *name,
acb-arg = arg;
acb-expiries = 0;
memset(acb-itmspec, 0, sizeof(acb-itmspec));
-   acb-magic = alarm_magic;
+   registry_init_file_obstack(acb-fsobj, registry_ops);
+
alarm-handle = (uintptr_t)acb;
+   acb-magic = alarm_magic;
 
if (pvcluster_addobj(alchemy_alarm_table, acb-name, acb-cobj)) {
+   registry_destroy_file(acb-fsobj);
timerobj_destroy(acb-tmobj);
ret = -EEXIST;
goto fail;
}
 
-   registry_init_file_obstack(acb-fsobj, registry_ops);
ret = __bt(registry_add_file(acb-fsobj, O_RDONLY,
-/alchemy/alarms/%s,
-acb-name));
+/alchemy/alarms/%s, acb-name));
if (ret)
-   warning(failed to export alarm %s to registry,
-   acb-name);
+   warning(failed to export alarm %s to registry, %s,
+   acb-name, symerror(ret));
 
CANCEL_RESTORE(svc);
 
diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c
index f77a4c7..f648114 100644
--- a/lib/alchemy/buffer.c
+++ b/lib/alchemy/buffer.c
@@ -240,7 +240,6 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name,
}
 
generate_name(bcb-name, name, buffer_namegen);
-   bcb-magic = buffer_magic;
bcb-mode = mode;
bcb-bufsz = bufsz;
bcb-rdoff = 0;
@@ -249,9 +248,13 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name,
if (mode  B_PRIO)
sobj_flags = SYNCOBJ_PRIO;
 
+   registry_init_file_obstack(bcb-fsobj, registry_ops);
+
syncobj_init(bcb-sobj, CLOCK_COPPERPLATE, sobj_flags,
 fnref_put(libalchemy, buffer_finalize));
 
+   bcb-magic = buffer_magic;
+
if (syncluster_addobj(alchemy_buffer_table, bcb-name, bcb-cobj)) {
ret = -EEXIST;
goto fail_register;
@@ -259,19 +262,18 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name,
 
bf-handle = mainheap_ref(bcb, uintptr_t);
 
-   registry_init_file_obstack(bcb-fsobj, registry_ops);
ret = __bt(registry_add_file(bcb-fsobj, O_RDONLY,
-/alchemy/buffers/%s,
-bcb-name));
+/alchemy/buffers/%s, bcb-name));
if (ret)
-   warning(failed to export buffer %s to registry,
-   bcb-name);
+   warning(failed to export buffer %s to registry, %s,
+   bcb-name, symerror(ret));
 
CANCEL_RESTORE(svc);
 
return 0;
 
 fail_register:
+   registry_destroy_file(bcb-fsobj);
syncobj_uninit(bcb-sobj);
xnfree(bcb-buf);
 fail_bufalloc:
diff --git a/lib/alchemy/cond.c b/lib/alchemy/cond.c
index 7b95636..e5db4a4 100644
--- a/lib/alchemy/cond.c
+++ b/lib/alchemy/cond.c
@@ -132,21 +132,23 @@ int rt_cond_create(RT_COND *cond, const char *name)
__RT(pthread_condattr_setclock(cattr, CLOCK_COPPERPLATE));
__RT(pthread_cond_init(ccb-cond, cattr));
__RT(pthread_condattr_destroy(cattr));
+
+   registry_init_file(ccb-fsobj, registry_ops, 0);
+
ccb-magic = cond_magic;
 
if (syncluster_addobj(alchemy_cond_table, ccb-name, ccb-cobj)) {
+   registry_destroy_file(ccb-fsobj);
__RT(pthread_cond_destroy(ccb-cond));
xnfree(ccb);
ret = -EEXIST;
} else {
cond-handle = mainheap_ref(ccb, uintptr_t);
-   registry_init_file(ccb-fsobj, registry_ops, 0);
ret = __bt(registry_add_file(ccb-fsobj, O_RDONLY,
- 

[Xenomai-git] Philippe Gerum : alchemy/task: use builtin specifier for infinite delay

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 1b75855ecf3bfc79d0b7ce1b3eaf026fb505646f
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1b75855ecf3bfc79d0b7ce1b3eaf026fb505646f

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Apr 23 12:25:54 2014 +0200

alchemy/task: use builtin specifier for infinite delay

---

 lib/alchemy/task.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index bd238c3..8d106fc 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -880,7 +880,10 @@ int rt_task_wait_period(unsigned long *overruns_r)
  * time in such a state.
  *
  * @param date An absolute date expressed in clock ticks, specifying a
- * wakeup date (see note).
+ * wakeup date (see note). As a special case, TM_INFINITE is an
+ * acceptable value that causes the caller to block indefinitely,
+ * until rt_task_unblock() is called against it. Otherwise, any wake
+ * up date in the past causes the task to return immediately.
  *
  * @return Zero is returned upon success. Otherwise:
  *
@@ -908,10 +911,9 @@ int rt_task_sleep_until(RTIME date)
if (!threadobj_current_p())
return -EPERM;
 
-   if (date == TM_INFINITE) {
-   ts.tv_sec = (time_t)-1  1;
-   ts.tv_nsec = 9;
-   } else {
+   if (date == TM_INFINITE)
+   ts = zero_time;
+   else {
clockobj_get_time(alchemy_clock, now, NULL);
if (date = now)
return -ETIMEDOUT;


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


[Xenomai-git] Philippe Gerum : cobalt/posix/syscall: fixup exec bits for non-restartable calls

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 9c13dedb9a74af610fdaa9e5de7f044ea87cc160
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=9c13dedb9a74af610fdaa9e5de7f044ea87cc160

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Apr 22 18:24:32 2014 +0200

cobalt/posix/syscall: fixup exec bits for non-restartable calls

---

 kernel/cobalt/posix/syscall.c |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index c70922a..4bec72b 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -132,8 +132,8 @@ static struct xnsyscall cobalt_syscalls[] = {
SKINCALL_DEF(sc_cobalt_mq_timedreceive, cobalt_mq_timedreceive, 
primary),
SKINCALL_DEF(sc_cobalt_mq_notify, cobalt_mq_notify, primary),
SKINCALL_DEF(sc_cobalt_sigwait, cobalt_sigwait, primary),
-   SKINCALL_DEF(sc_cobalt_sigwaitinfo, cobalt_sigwaitinfo, primary),
-   SKINCALL_DEF(sc_cobalt_sigtimedwait, cobalt_sigtimedwait, primary),
+   SKINCALL_DEF(sc_cobalt_sigwaitinfo, cobalt_sigwaitinfo, nonrestartable),
+   SKINCALL_DEF(sc_cobalt_sigtimedwait, cobalt_sigtimedwait, 
nonrestartable),
SKINCALL_DEF(sc_cobalt_sigpending, cobalt_sigpending, primary),
SKINCALL_DEF(sc_cobalt_kill, cobalt_kill, conforming),
SKINCALL_DEF(sc_cobalt_timer_create, cobalt_timer_create, any),
@@ -155,7 +155,7 @@ static struct xnsyscall cobalt_syscalls[] = {
SKINCALL_DEF(sc_cobalt_condattr_setclock, cobalt_condattr_setclock, 
any),
SKINCALL_DEF(sc_cobalt_condattr_getpshared, cobalt_condattr_getpshared, 
any),
SKINCALL_DEF(sc_cobalt_condattr_setpshared, cobalt_condattr_setpshared, 
any),
-   SKINCALL_DEF(sc_cobalt_select, cobalt_select, primary),
+   SKINCALL_DEF(sc_cobalt_select, cobalt_select, nonrestartable),
SKINCALL_DEF(sc_cobalt_sched_minprio, cobalt_sched_min_prio, any),
SKINCALL_DEF(sc_cobalt_sched_maxprio, cobalt_sched_max_prio, any),
SKINCALL_DEF(sc_cobalt_monitor_init, cobalt_monitor_init, any),


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


[Xenomai-git] Gilles Chanteperdrix : cobalt/shadow: optimize access to process hash

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 1e5cd6f033901335f339fd48aa5472dbb7f77c6b
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1e5cd6f033901335f339fd48aa5472dbb7f77c6b

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Fri Apr 25 21:32:33 2014 +0200

cobalt/shadow: optimize access to process hash

---

 kernel/cobalt/shadow.c |   42 +++---
 1 file changed, 15 insertions(+), 27 deletions(-)

diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 04652bf..d128209 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -82,6 +82,7 @@ static void *mayday_page;
 static struct xnsynch yield_sync;
 
 static struct hlist_head *process_hash;
+DEFINE_PRIVATE_XNLOCK(process_hash_lock);
 #define PROCESS_HASH_SIZE 13
 
 static int enter_personality(struct xnshadow_process *process,
@@ -116,7 +117,7 @@ static struct xnshadow_process 
*__process_hash_search(struct mm_struct *mm)
 {
unsigned bucket = process_hash_crunch(mm);
struct xnshadow_process *p;
-   
+
atomic_only();
 
hlist_for_each_entry(p, process_hash[bucket], hlink)
@@ -131,9 +132,9 @@ static struct xnshadow_process *process_hash_search(struct 
mm_struct *mm)
struct xnshadow_process *process;
spl_t s;

-   xnlock_get_irqsave(nklock, s);
+   xnlock_get_irqsave(process_hash_lock, s);
process = __process_hash_search(mm);
-   xnlock_put_irqrestore(nklock, s);
+   xnlock_put_irqrestore(process_hash_lock, s);

return process;
 }
@@ -145,7 +146,7 @@ static int process_hash_enter(struct xnshadow_process *p)
int err;
spl_t s;
 
-   xnlock_get_irqsave(nklock, s);
+   xnlock_get_irqsave(process_hash_lock, s);
if (__process_hash_search(mm)) {
err = -EBUSY;
goto out;
@@ -155,7 +156,7 @@ static int process_hash_enter(struct xnshadow_process *p)
hlist_add_head(p-hlink, process_hash[bucket]);
err = 0;
   out:
-   xnlock_put_irqrestore(nklock, s);
+   xnlock_put_irqrestore(process_hash_lock, s);
return err;
 }
 
@@ -163,10 +164,10 @@ static void process_hash_remove(struct xnshadow_process 
*p)
 {
spl_t s;
 
-   xnlock_get_irqsave(nklock, s);
+   xnlock_get_irqsave(process_hash_lock, s);
if (p-mm)
hlist_del(p-hlink);
-   xnlock_put_irqrestore(nklock, s);
+   xnlock_put_irqrestore(process_hash_lock, s);
 }
 
 /* nklock locked, irqs off. */
@@ -174,11 +175,10 @@ static void *private_lookup(unsigned int muxid)
 {
struct xnshadow_process *p = xnshadow_current_process();
 
-   if (p == NULL) {
-   p = __process_hash_search(current-mm);
-   if (p == NULL)
-   return NULL;
-   }
+   if (p == NULL  current-mm)
+   p = process_hash_search(current-mm);
+   if (p == NULL)
+   return NULL;
 
return p-priv[muxid];
 }
@@ -1327,10 +1327,10 @@ static int xnshadow_sys_bind(unsigned int magic,
 
return -ESRCH;
 do_bind:
-   xnlock_get_irqsave(nklock, s);
+   xnlock_get_irqsave(process_hash_lock, s);
process = __process_hash_search(current-mm);
priv = private_lookup(muxid);
-   xnlock_put_irqrestore(nklock, s);
+   xnlock_put_irqrestore(process_hash_lock, s);
 
/*
 * Protect from the same process binding to the same interface
@@ -1753,19 +1753,7 @@ EXPORT_SYMBOL_GPL(xnshadow_unregister_personality);
  */
 void *xnshadow_get_context(unsigned int muxid)
 {
-   struct xnthread *curr;
-   void *context = NULL;
-   spl_t s;
-
-   xnlock_get_irqsave(nklock, s);
-
-   curr = xnsched_current_thread();
-   if (likely(xnthread_test_state(curr, XNROOT|XNUSER)))
-   context = private_lookup(muxid);
-
-   xnlock_put_irqrestore(nklock, s);
-
-   return context;
+   return private_lookup(muxid);
 }
 EXPORT_SYMBOL_GPL(xnshadow_get_context);
 


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


[Xenomai-git] Philippe Gerum : cobalt/posix/sem: move copy_from_user out of atomic section

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 8612fc3bc85ff56eb86404d850d94189054b5e21
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=8612fc3bc85ff56eb86404d850d94189054b5e21

Author: Philippe Gerum r...@xenomai.org
Date:   Mon Apr 28 13:29:22 2014 +0200

cobalt/posix/sem: move copy_from_user out of atomic section

---

 kernel/cobalt/posix/sem.c |   51 -
 1 file changed, 32 insertions(+), 19 deletions(-)

diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index 9bca743..5865b5c 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -402,32 +402,41 @@ static inline int
 sem_wait_inner(xnhandle_t handle, int timed,
   const struct timespec __user *u_ts)
 {
+   int pull_ts = 1, ret, info;
struct cobalt_sem *sem;
struct timespec ts;
xntmode_t tmode;
-   int ret, info;
spl_t s;
 
xnlock_get_irqsave(nklock, s);
-
+redo:
sem = xnregistry_lookup(handle, NULL);
 
ret = sem_trywait_inner(sem);
-   if (ret != -EAGAIN) {
-   xnlock_put_irqrestore(nklock, s);
-   return ret;
-   }
+   if (ret != -EAGAIN)
+   goto out;
 
if (timed) {
-   if (u_ts == NULL ||
-   __xn_safe_copy_from_user(ts, u_ts, sizeof(ts))) {
-   ret = -EFAULT;
-   goto fail;
-   }
-
-   if (ts.tv_nsec = ONE_BILLION) {
-   ret = -EINVAL;
-   goto fail;
+   /*
+* POSIX states that the validity of the timeout spec
+* _need_ not be checked if the semaphore can be
+* locked immediately, we show this behavior despite
+* it's actually more complex, to keep some
+* applications ported to Linux happy.
+*/
+   if (pull_ts) {
+   atomic_long_inc(sem-datp-value);
+   if (u_ts == NULL)
+   goto efault;
+   xnlock_put_irqrestore(nklock, s);
+   ret =__xn_safe_copy_from_user(ts, u_ts, sizeof(ts));
+   xnlock_get_irqsave(nklock, s);
+   if (ret)
+   goto efault;
+   if (ts.tv_nsec = ONE_BILLION)
+   goto einval;
+   pull_ts = 0;
+   goto redo;
}
 
tmode = sem-flags  SEM_RAWCLOCK ? XN_ABSOLUTE : XN_REALTIME;
@@ -435,10 +444,8 @@ sem_wait_inner(xnhandle_t handle, int timed,
} else
info = xnsynch_sleep_on(sem-synchbase, 
XN_INFINITE, XN_RELATIVE);
-   if (info  XNRMID) {
-   ret = -EINVAL;
-   goto out;
-   }
+   if (info  XNRMID)
+   goto einval;
if (info  (XNBREAK|XNTIMEO)) {
ret = (info  XNBREAK) ? -EINTR : -ETIMEDOUT;
goto fail;
@@ -451,6 +458,12 @@ out:
 fail:
atomic_long_inc(sem-datp-value);
goto out;
+efault:
+   ret = -EFAULT;
+   goto out;
+einval:
+   ret = -EINVAL;
+   goto out;
 }
 
 /**


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


[Xenomai-git] Philippe Gerum : boilerplate/ancillaries: define ONE_BILLION

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 5d897f07a2a292eaa4755be07cec0262251e390e
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=5d897f07a2a292eaa4755be07cec0262251e390e

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 24 17:30:15 2014 +0200

boilerplate/ancillaries: define ONE_BILLION

---

 include/boilerplate/ancillaries.h |2 ++
 testsuite/latency/latency.c   |1 -
 testsuite/unit/sched-quota.c  |2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/boilerplate/ancillaries.h 
b/include/boilerplate/ancillaries.h
index c8b4ec7..9d5818f 100644
--- a/include/boilerplate/ancillaries.h
+++ b/include/boilerplate/ancillaries.h
@@ -43,6 +43,8 @@ struct name_generator {
.serial = 1,\
}
 
+#define ONE_BILLION  10
+
 #ifdef __cplusplus
 extern C {
 #endif
diff --git a/testsuite/latency/latency.c b/testsuite/latency/latency.c
index 12b90a9..5efc344 100644
--- a/testsuite/latency/latency.c
+++ b/testsuite/latency/latency.c
@@ -19,7 +19,6 @@ RT_TASK latency_task, display_task;
 
 RT_SEM display_sem;
 
-#define ONE_BILLION  10
 #define TEN_MILLION1000
 
 unsigned max_relaxed;
diff --git a/testsuite/unit/sched-quota.c b/testsuite/unit/sched-quota.c
index 1347bf7..fef6880 100644
--- a/testsuite/unit/sched-quota.c
+++ b/testsuite/unit/sched-quota.c
@@ -36,10 +36,10 @@
 #include errno.h
 #include error.h
 #include boilerplate/time.h
+#include boilerplate/ancillaries.h
 
 #define MAX_THREADS 8
 #define TEST_SECS   1
-#define ONE_BILLION 10UL
 
 static unsigned long long crunch_per_sec, loops_per_sec;
 


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


[Xenomai-git] Philippe Gerum : copperplate/notifier: sanitize and simplify - again

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: ea7bc8d0b55759744a72f1e1b80ad0eed0c5b113
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=ea7bc8d0b55759744a72f1e1b80ad0eed0c5b113

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Apr 26 15:07:41 2014 +0200

copperplate/notifier: sanitize and simplify - again

Those changes build on the fact that the notification support is there
exclusively for implementing the thread suspend/resume mechanism over
Mercury. Therefore we may drop any code which is not directly aimed at
supporting this feature.

Assuming this, locking may now be handled directly from the call
sites, all located in the threadobj implementation.

As a bonus, this change set also fixes the issue discussed there:
http://www.xenomai.org/pipermail/xenomai/2014-April/030804.html

---

 include/copperplate/notifier.h  |   16 ++--
 include/copperplate/threadobj.h |1 -
 lib/copperplate/notifier.c  |  169 ---
 lib/copperplate/threadobj.c |   69 +++-
 4 files changed, 86 insertions(+), 169 deletions(-)

diff --git a/include/copperplate/notifier.h b/include/copperplate/notifier.h
index 536782d..13bf588 100644
--- a/include/copperplate/notifier.h
+++ b/include/copperplate/notifier.h
@@ -19,16 +19,12 @@
 #ifndef _COPPERPLATE_NOTIFIER_H
 #define _COPPERPLATE_NOTIFIER_H
 
-#include pthread.h
 #include boilerplate/list.h
 
 struct notifier {
-   pthread_mutex_t lock;
-   int notified;
pid_t owner;
int psfd[2];
int pwfd[2];
-   void (*callback)(const struct notifier *nf);
struct pvholder link;
 };
 
@@ -36,17 +32,17 @@ struct notifier {
 extern C {
 #endif
 
-int notifier_init(struct notifier *nf,
- void (*callback)(const struct notifier *nf),
- int owned);
+int notifier_init(struct notifier *nf, pid_t pid);
 
 void notifier_destroy(struct notifier *nf);
 
-int notifier_signal(struct notifier *nf);
+void notifier_signal(struct notifier *nf);
 
-int notifier_wait(const struct notifier *nf);
+void notifier_wait(const struct notifier *nf);
 
-int notifier_release(struct notifier *nf);
+void notifier_disable(struct notifier *nf);
+
+void notifier_release(struct notifier *nf);
 
 void notifier_pkg_init(void);
 
diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 5438790..bc5be99 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -128,7 +128,6 @@ void threadobj_save_timeout(struct threadobj_corespec 
*corespec,
 #define __THREAD_S_ACTIVE  (1  5)/* Running user code. */
 #define __THREAD_S_SUSPENDED   (1  6)/* Suspended via 
threadobj_suspend(). */
 #define __THREAD_S_SAFE(1  7)/* TCB release 
deferred. */
-#define __THREAD_S_ZOMBIE  (1  8)/* Deletion process ongoing. */
 #define __THREAD_S_DEBUG   (1  31)   /* Debug mode enabled. */
 /*
  * threadobj-run_state, locklessly updated by current, merged
diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index 7fa48f3..4b3988a 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -50,25 +50,20 @@ static void notifier_sighandler(int sig, siginfo_t 
*siginfo, void *uc)
pvlist_for_each_entry(nf, notifier_list, link) {
if (nf-psfd[0] != siginfo-si_fd)
continue;
+
+   matched = 1;
/*
-* Ignore misdirected notifications. We want those to
-* hit the thread owning the notification object, but
-* it may happen that the kernel picks another thread
-* for receiving a subsequent signal while we are
-* blocked in the callback code. In such a case, we
-* just dismiss the notification, and expect the
-* actual owner to detect the pending notification
-* once the callback returns to the read() loop.
+* Paranoid: misdirected notifications should never
+* happen with F_SETOWN_EX invoked for the
+* notification fildes.
 */
-   matched = 1;
-   if (nf-owner  nf-owner != tid)
+   if (nf-owner != tid)
continue;
 
for (;;) {
-   ret = __STD(read(nf-psfd[0], c, 1)); 
+   ret = read(nf-psfd[0], c, 1); 
if (ret  0)
-   /* Callee must run async-safe code only. */
-   nf-callback(nf);
+   notifier_wait(nf);
else if (ret == 0 || errno != EINTR)
break;
}
@@ -77,9 +72,9 @@ static void notifier_sighandler(int sig, siginfo_t *siginfo, 
void *uc)
}
 
/*
-* We may have received a valid notification on the wrong
-

[Xenomai-git] Philippe Gerum : rtdm: introduce lock name as RTDM_LOCK_UNLOCK() argument

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 36678cb34af79f577cba4d9d66514fccdcaeb749
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=36678cb34af79f577cba4d9d66514fccdcaeb749

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Apr 12 17:35:51 2014 +0200

rtdm: introduce lock name as RTDM_LOCK_UNLOCK() argument

Mapping RTDM locks over native spinlocks will require to pass the lock
name to the native spinlock initializer, so make sure we receive it
from the RTDM client code.

This change is propagated to all driver stacks concerned (i.e. analogy
and CAN).

---

 include/analogy/os_facilities.h   |5 -
 include/cobalt/kernel/rtdm/driver.h   |7 +--
 kernel/drivers/analogy/testing/fake.c |2 +-
 kernel/drivers/can/rtcan_dev.c|2 +-
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/include/analogy/os_facilities.h b/include/analogy/os_facilities.h
index 0f99cbf..35f4155 100644
--- a/include/analogy/os_facilities.h
+++ b/include/analogy/os_facilities.h
@@ -85,7 +85,10 @@
 
 typedef rtdm_lock_t a4l_lock_t;
 
-#define A4L_LOCK_UNLOCKED RTDM_LOCK_UNLOCKED
+#define A4L_LOCK_UNLOCKED(__name) RTDM_LOCK_UNLOCKED(__name)
+
+#define DEFINE_A4L_LOCK(__name)\
+   a4l_lock_t __name = A4L_LOCK_UNLOCKED(__name)
 
 #define a4l_lock_init(lock) rtdm_lock_init(lock)
 #define a4l_lock(lock) rtdm_lock_get(lock)
diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index b9d7649..4e335f7 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -694,7 +694,10 @@ rtdm_execute_atomically(void) { }
 /**
  * Static lock initialisation
  */
-#define RTDM_LOCK_UNLOCKED IPIPE_SPIN_LOCK_UNLOCKED
+#define RTDM_LOCK_UNLOCKED(__name) IPIPE_SPIN_LOCK_UNLOCKED
+
+#define DEFINE_RTDM_LOCK(__name)   \
+   rtdm_lock_t __name = RTDM_LOCK_UNLOCKED(__name)
 
 /** Lock variable */
 typedef ipipe_spinlock_t rtdm_lock_t;
@@ -1750,7 +1753,7 @@ int rtdm_ratelimit(struct rtdm_ratelimit_state *rs, const 
char *func);
 
 #define DEFINE_RTDM_RATELIMIT_STATE(name, interval_init, burst_init)   \
struct rtdm_ratelimit_state name = {\
-   .lock   = RTDM_LOCK_UNLOCKED,   \
+   .lock   = RTDM_LOCK_UNLOCKED((name).lock),  \
.interval   = interval_init,\
.burst  = burst_init,   \
}
diff --git a/kernel/drivers/analogy/testing/fake.c 
b/kernel/drivers/analogy/testing/fake.c
index 3871cc5..a2390aa 100644
--- a/kernel/drivers/analogy/testing/fake.c
+++ b/kernel/drivers/analogy/testing/fake.c
@@ -116,7 +116,7 @@ static inline uint16_t ai_value_output(struct ai_priv *priv)
0x8000, 0xa000, 0xc000, 0x
};
static unsigned int output_idx;
-   static a4l_lock_t output_lock = A4L_LOCK_UNLOCKED;
+   static DEFINE_A4L_LOCK(output_lock);
 
unsigned long flags;
unsigned int idx;
diff --git a/kernel/drivers/can/rtcan_dev.c b/kernel/drivers/can/rtcan_dev.c
index 3280587..5caea3a 100644
--- a/kernel/drivers/can/rtcan_dev.c
+++ b/kernel/drivers/can/rtcan_dev.c
@@ -34,7 +34,7 @@
 
 
 static struct rtcan_device *rtcan_devices[RTCAN_MAX_DEVICES];
-static rtdm_lock_t rtcan_devices_rt_lock = RTDM_LOCK_UNLOCKED;
+static DEFINE_RTDM_LOCK(rtcan_devices_rt_lock);
 
 static int rtcan_global_init_done;
 


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


[Xenomai-git] Philippe Gerum : cobalt/shadow: expose XNBREAK to userland

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 591bac8cc47f09dc8b881c54f560b78d6157bfb8
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=591bac8cc47f09dc8b881c54f560b78d6157bfb8

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Apr 22 18:52:50 2014 +0200

cobalt/shadow: expose XNBREAK to userland

---

 include/cobalt/kernel/thread.h  |   20 +---
 include/cobalt/uapi/kernel/thread.h |1 +
 kernel/cobalt/shadow.c  |1 +
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index e053845..d235d9c 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -283,22 +283,28 @@ struct xnthread *xnthread_lookup(xnhandle_t threadh)
 
 static inline void xnthread_sync_window(struct xnthread *thread)
 {
-   if (thread-u_window)
+   if (thread-u_window) {
thread-u_window-state = thread-state;
+   thread-u_window-info = thread-info;
+   }
 }
 
 static inline
-void xnthread_clear_sync_window(struct xnthread *thread, int bits)
+void xnthread_clear_sync_window(struct xnthread *thread, int state_bits)
 {
-   if (thread-u_window)
-   thread-u_window-state = thread-state  ~bits;
+   if (thread-u_window) {
+   thread-u_window-state = thread-state  ~state_bits;
+   thread-u_window-info = thread-info;
+   }
 }
 
 static inline
-void xnthread_set_sync_window(struct xnthread *thread, int bits)
+void xnthread_set_sync_window(struct xnthread *thread, int state_bits)
 {
-   if (thread-u_window)
-   thread-u_window-state = thread-state | bits;
+   if (thread-u_window) {
+   thread-u_window-state = thread-state | state_bits;
+   thread-u_window-info = thread-info;
+   }
 }
 
 static inline int xnthread_try_grab(struct xnthread *thread,
diff --git a/include/cobalt/uapi/kernel/thread.h 
b/include/cobalt/uapi/kernel/thread.h
index 439e636..1c01654 100644
--- a/include/cobalt/uapi/kernel/thread.h
+++ b/include/cobalt/uapi/kernel/thread.h
@@ -97,6 +97,7 @@
 
 struct xnthread_user_window {
unsigned long state;
+   unsigned long info;
unsigned long grant_value;
 };
 
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 9da7c22..4115362 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -223,6 +223,7 @@ static void request_syscall_restart(struct xnthread *thread,
  (sysflags  __xn_exec_norestart) ?
  -EINTR : -ERESTARTSYS);
notify = !xnthread_test_state(thread, XNDEBUG);
+   xnthread_clear_info(thread, XNBREAK);
}
xnthread_clear_info(thread, XNKICKED);
}


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


[Xenomai-git] Philippe Gerum : cobalt/kernel: introduce knamecpy()

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: af26a4d96ab2885a380eacbb61ddba496e811bf9
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=af26a4d96ab2885a380eacbb61ddba496e811bf9

Author: Philippe Gerum r...@xenomai.org
Date:   Sun Apr 20 11:22:29 2014 +0200

cobalt/kernel: introduce knamecpy()

---

 include/cobalt/kernel/ancillaries.h |   13 +
 include/cobalt/kernel/registry.h|6 --
 kernel/cobalt/clock.c   |4 ++--
 kernel/cobalt/heap.c|2 +-
 kernel/cobalt/posix/thread.c|3 +--
 kernel/cobalt/sched.c   |4 ++--
 kernel/cobalt/timer.c   |9 ++---
 7 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/include/cobalt/kernel/ancillaries.h 
b/include/cobalt/kernel/ancillaries.h
index 88c0afb..312c181 100644
--- a/include/cobalt/kernel/ancillaries.h
+++ b/include/cobalt/kernel/ancillaries.h
@@ -20,6 +20,8 @@
 #define _COBALT_KERNEL_ANCILLARIES_H
 
 #include linux/kernel.h
+#include linux/string.h
+#include cobalt/uapi/kernel/limits.h
 
 #define ksformat(__dst, __len, __fmt, __args...)   \
({  \
@@ -49,4 +51,15 @@
kvasprintf(GFP_KERNEL, __fmt, __ap);\
})
 
+void __knamecpy_requires_character_array_as_destination(void);
+
+#define knamecpy(__dst, __src) \
+   ({  \
+   if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
+   __knamecpy_requires_character_array_as_destination();   
\
+   strncpy((__dst), __src, sizeof(__dst) - 1); \
+   __dst[sizeof(__dst) - 1] = '\0';\
+   __dst;  \
+})
+   
 #endif /* !_COBALT_KERNEL_ANCILLARIES_H */
diff --git a/include/cobalt/kernel/registry.h b/include/cobalt/kernel/registry.h
index 9c80352..d0109c5 100644
--- a/include/cobalt/kernel/registry.h
+++ b/include/cobalt/kernel/registry.h
@@ -50,12 +50,6 @@ struct xnobject {
struct list_head link;
 };
 
-static inline void xnobject_copy_name(char *dst, const char *src)
-{
-   strncpy(dst, src ?: , XNOBJECT_NAME_LEN-1);
-   dst[XNOBJECT_NAME_LEN-1] = '\0';
-}
-
 int xnregistry_init(void);
 
 void xnregistry_cleanup(void);
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 71fae16..a2553d1 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -385,8 +385,8 @@ static int clock_vfile_next(struct 
xnvfile_snapshot_iterator *it, void *data)
p-timeout = xntimer_get_timeout(timer);
p-interval = xntimer_get_interval(timer);
p-status = timer-status;
-   strncpy(p-handler, timer-handler_name, 16)[16] = '\0';
-   xnobject_copy_name(p-name, timer-name);
+   knamecpy(p-handler, timer-handler_name);
+   knamecpy(p-name, timer-name);
 
return 1;
 }
diff --git a/kernel/cobalt/heap.c b/kernel/cobalt/heap.c
index dcc7129..f267976 100644
--- a/kernel/cobalt/heap.c
+++ b/kernel/cobalt/heap.c
@@ -142,7 +142,7 @@ static int vfile_next(struct xnvfile_snapshot_iterator *it, 
void *data)
p-usable_mem = xnheap_usable_mem(heap);
p-used_mem = xnheap_used_mem(heap);
p-page_size = xnheap_page_size(heap);
-   strncpy(p-label, heap-label, sizeof(p-label));
+   knamecpy(p-label, heap-label);
 
return 1;
 }
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 1d547cf..cd5376b 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -1056,8 +1056,7 @@ int cobalt_thread_set_name_np(unsigned long pth, const 
char __user *u_name)
 
xnlock_put_irqrestore(nklock, s);
 
-   strncpy(p-comm, name, sizeof(p-comm));
-   p-comm[sizeof(p-comm) - 1] = '\0';
+   knamecpy(p-comm, name);
put_task_struct(p);
 
return 0;
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index 61d0580..41aed20 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -908,8 +908,8 @@ static int vfile_schedlist_next(struct 
xnvfile_snapshot_iterator *it,
memcpy(p-name, thread-name, sizeof(p-name));
p-cprio = thread-cprio;
p-state = xnthread_state_flags(thread);
-   xnobject_copy_name(p-sched_class, thread-sched_class-name);
-   xnobject_copy_name(p-personality, thread-personality-name);
+   knamecpy(p-sched_class, thread-sched_class-name);
+   knamecpy(p-personality, thread-personality-name);
period = xnthread_get_period(thread);
timeout = xnthread_get_timeout(thread, priv-start_time);
/*
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index e493ac6..ac3aa9f 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -347,13 +347,8 @@ void __xntimer_init(struct xntimer 

[Xenomai-git] Philippe Gerum : drivers/testing: move to new-style atomic sections

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: c8e09bd0421ba2a143342f9436adf3d306c17c06
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=c8e09bd0421ba2a143342f9436adf3d306c17c06

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 10 11:41:22 2014 +0200

drivers/testing: move to new-style atomic sections

---

 kernel/drivers/testing/timerbench.c |   33 +++--
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/kernel/drivers/testing/timerbench.c 
b/kernel/drivers/testing/timerbench.c
index 7d056d4..af75d56 100644
--- a/kernel/drivers/testing/timerbench.c
+++ b/kernel/drivers/testing/timerbench.c
@@ -141,22 +141,19 @@ static void eval_outer_loop(struct rt_tmbench_context 
*ctx)
 static void timer_task_proc(void *arg)
 {
struct rt_tmbench_context *ctx = arg;
-   int count;
+   int count, err;
+   spl_t s;
 
/* first event: one millisecond from now. */
ctx-date = rtdm_clock_read_monotonic() + 100;
 
while (1) {
-   int err;
-
for (count = 0; count  ctx-samples_per_sec; count++) {
-   RTDM_EXECUTE_ATOMICALLY(
-   ctx-start_time = rtdm_clock_read_monotonic();
-   err =
-   rtdm_task_sleep_abs(ctx-date,
-   
RTDM_TIMERMODE_ABSOLUTE);
-   );
-
+   cobalt_atomic_enter(s);
+   ctx-start_time = rtdm_clock_read_monotonic();
+   err = rtdm_task_sleep_abs(ctx-date,
+ RTDM_TIMERMODE_ABSOLUTE);
+   cobalt_atomic_leave(s);
if (err)
return;
 
@@ -237,6 +234,7 @@ static int rt_tmbench_start(struct rtdm_dev_context 
*context,
struct rttst_tmbench_config __user *user_config)
 {
int err = 0;
+   spl_t s;
 
struct rttst_tmbench_config config_buf;
struct rttst_tmbench_config *config =
@@ -311,16 +309,15 @@ static int rt_tmbench_start(struct rtdm_dev_context 
*context,
if (!test_bit(RTDM_CLOSING, context-context_flags)) {
ctx-mode = RTTST_TMBENCH_HANDLER;
 
-   RTDM_EXECUTE_ATOMICALLY(
-   ctx-start_time = rtdm_clock_read_monotonic();
+   cobalt_atomic_enter(s);
+   ctx-start_time = rtdm_clock_read_monotonic();
 
-   /* first event: one millisecond from now. */
-   ctx-date = ctx-start_time + 100;
+   /* first event: one millisecond from now. */
+   ctx-date = ctx-start_time + 100;
 
-   err =
-   rtdm_timer_start(ctx-timer, ctx-date, 0,
-RTDM_TIMERMODE_ABSOLUTE);
-   );
+   err = rtdm_timer_start(ctx-timer, ctx-date, 0,
+  RTDM_TIMERMODE_ABSOLUTE);
+   cobalt_atomic_leave(s);
}
}
 


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


[Xenomai-git] Philippe Gerum : copperplate/threadobj: constify timespec args in API

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: b3ee9d776869d2d7019aead01f4be3d162c44a55
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=b3ee9d776869d2d7019aead01f4be3d162c44a55

Author: Philippe Gerum r...@xenomai.org
Date:   Mon Apr 28 10:52:18 2014 +0200

copperplate/threadobj: constify timespec args in API

---

 include/copperplate/threadobj.h |8 +---
 lib/copperplate/threadobj.c |   14 --
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 0ad24c3..754de3d 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -325,10 +325,12 @@ int threadobj_set_priority(struct threadobj *thobj, int 
prio);
 
 int threadobj_set_mode(int clrmask, int setmask, int *mode_r);
 
-int threadobj_set_rr(struct threadobj *thobj, struct timespec *quantum);
+int threadobj_set_rr(struct threadobj *thobj,
+const struct timespec *quantum);
 
 int threadobj_set_periodic(struct threadobj *thobj,
-  struct timespec *idate, struct timespec *period);
+  const struct timespec *__restrict__ idate,
+  const struct timespec *__restrict__ period);
 
 int threadobj_wait_period(unsigned long *overruns_r);
 
@@ -337,7 +339,7 @@ void threadobj_spin(ticks_t ns);
 int threadobj_stat(struct threadobj *thobj,
   struct threadobj_stat *stat);
 
-int threadobj_sleep(struct timespec *ts);
+int threadobj_sleep(const struct timespec *ts);
 
 #ifdef CONFIG_XENO_PSHARED
 
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 96694b0..9a4cf0b 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -304,7 +304,7 @@ int threadobj_set_mode(int clrmask, int setmask, int 
*mode_r) /* current-lock h
return 0;
 }
 
-static int set_rr(struct threadobj *thobj, struct timespec *quantum)
+static int set_rr(struct threadobj *thobj, const struct timespec *quantum)
 {
struct sched_param_ex xparam;
pthread_t tid = thobj-tid;
@@ -332,7 +332,8 @@ static int set_rr(struct threadobj *thobj, struct timespec 
*quantum)
 }
 
 int threadobj_set_periodic(struct threadobj *thobj,
-  struct timespec *idate, struct timespec *period)
+  const struct timespec *__restrict__ idate,
+  const struct timespec *__restrict__ period)
 {
return -pthread_make_periodic_np(thobj-tid,
 CLOCK_COPPERPLATE, idate, period);
@@ -678,7 +679,7 @@ int threadobj_set_mode(int clrmask, int setmask, int 
*mode_r) /* current-lock h
return __bt(ret);
 }
 
-static inline int set_rr(struct threadobj *thobj, struct timespec *quantum)
+static int set_rr(struct threadobj *thobj, const struct timespec *quantum)
 {
pthread_t tid = thobj-tid;
struct sched_param param;
@@ -731,7 +732,8 @@ static inline int set_rr(struct threadobj *thobj, struct 
timespec *quantum)
 }
 
 int threadobj_set_periodic(struct threadobj *thobj,
-  struct timespec *idate, struct timespec *period)
+  const struct timespec *__restrict__ idate,
+  const struct timespec *__restrict__ period)
 {
struct timespec now, wakeup;
 
@@ -1256,7 +1258,7 @@ int threadobj_unblock(struct threadobj *thobj) /* 
thobj-lock held */
return __bt(-__RT(pthread_kill(thobj-tid, SIGRELS)));
 }
 
-int threadobj_sleep(struct timespec *ts)
+int threadobj_sleep(const struct timespec *ts)
 {
struct threadobj *current = threadobj_current();
sigset_t set;
@@ -1301,7 +1303,7 @@ void threadobj_spin(ticks_t ns)
cpu_relax();
 }
 
-int threadobj_set_rr(struct threadobj *thobj, struct timespec *quantum)
+int threadobj_set_rr(struct threadobj *thobj, const struct timespec *quantum)
 {  /* thobj-lock held */
__threadobj_check_locked(thobj);
 


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


[Xenomai-git] Philippe Gerum : cobalt/shadow: check for signal receipt unambiguously

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 83af3cb4b1610a467dfe1311cda7e3fd254d98f5
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=83af3cb4b1610a467dfe1311cda7e3fd254d98f5

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Apr 23 15:08:57 2014 +0200

cobalt/shadow: check for signal receipt unambiguously

---

 kernel/cobalt/shadow.c |   61 ++--
 1 file changed, 33 insertions(+), 28 deletions(-)

diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 4115362..1603aad 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -211,28 +211,6 @@ static inline void process_remove(struct xnshadow_process 
*p)
xnshadow_set_process(NULL);
 }
 
-static void request_syscall_restart(struct xnthread *thread,
-   struct pt_regs *regs,
-   int sysflags)
-{
-   int notify = 0;
-
-   if (xnthread_test_info(thread, XNKICKED)) {
-   if (__xn_interrupted_p(regs)) {
-   __xn_error_return(regs,
- (sysflags  __xn_exec_norestart) ?
- -EINTR : -ERESTARTSYS);
-   notify = !xnthread_test_state(thread, XNDEBUG);
-   xnthread_clear_info(thread, XNBREAK);
-   }
-   xnthread_clear_info(thread, XNKICKED);
-   }
-
-   xnthread_test_cancel();
-
-   xnshadow_relax(notify, SIGDEBUG_MIGRATE_SIGNAL);
-}
-
 static inline void lock_timers(void)
 {
smp_mb__before_atomic_inc();
@@ -1851,6 +1829,29 @@ void xnshadow_pop_personality(struct xnpersonality *prev)
 }
 EXPORT_SYMBOL_GPL(xnshadow_pop_personality);
 
+static void prepare_for_signal(struct task_struct *p,
+  struct xnthread *thread,
+  struct pt_regs *regs,
+  int sysflags)
+{
+   int notify = 0;
+
+   if (xnthread_test_info(thread, XNKICKED)) {
+   if (signal_pending(p)) {
+   __xn_error_return(regs,
+ (sysflags  __xn_exec_norestart) ?
+ -EINTR : -ERESTARTSYS);
+   notify = !xnthread_test_state(thread, XNDEBUG);
+   xnthread_clear_info(thread, XNBREAK);
+   }
+   xnthread_clear_info(thread, XNKICKED);
+   }
+
+   xnthread_test_cancel();
+
+   xnshadow_relax(notify, SIGDEBUG_MIGRATE_SIGNAL);
+}
+
 static int handle_head_syscall(struct ipipe_domain *ipd, struct pt_regs *regs)
 {
int muxid, muxop, switched, ret, sigs;
@@ -1858,6 +1859,7 @@ static int handle_head_syscall(struct ipipe_domain *ipd, 
struct pt_regs *regs)
struct xnshadow_process *process;
struct xnthread *thread;
unsigned long sysflags;
+   struct task_struct *p;
struct xnsyscall *sc;
 
thread = xnshadow_current();
@@ -1991,10 +1993,11 @@ done:
__xn_status_return(regs, ret);
sigs = 0;
if (!xnsched_root_p()) {
-   if (signal_pending(current) ||
+   p = current;
+   if (signal_pending(p) ||
xnthread_test_info(thread, XNKICKED)) {
sigs = 1;
-   request_syscall_restart(thread, regs, sysflags);
+   prepare_for_signal(p, thread, regs, sysflags);
} else if (xnthread_test_state(thread, XNWEAK) 
   xnthread_get_rescnt(thread) == 0) {
if (switched)
@@ -2053,13 +2056,14 @@ static int handle_root_syscall(struct ipipe_domain 
*ipd, struct pt_regs *regs)
 {
int muxid, muxop, sysflags, switched, ret, sigs;
struct xnthread *thread;
+   struct task_struct *p;
struct xnsyscall *sc;
 
/*
 * Catch cancellation requests pending for user shadows
 * running mostly in secondary mode, i.e. XNWEAK. In that
-* case, we won't run request_syscall_restart() that
-* frequently, so check for cancellation here.
+* case, we won't run prepare_for_signal() that frequently, so
+* check for cancellation here.
 */
xnthread_test_cancel();
 
@@ -2132,9 +2136,10 @@ restart:
 * just invoked, so make sure to fetch it.
 */
thread = xnshadow_current();
-   if (signal_pending(current)) {
+   p = current;
+   if (signal_pending(p)) {
sigs = 1;
-   request_syscall_restart(thread, regs, sysflags);
+   prepare_for_signal(p, thread, regs, sysflags);
} else if (xnthread_test_state(thread, XNWEAK) 
   xnthread_get_rescnt(thread) == 0)
sysflags |= __xn_exec_switchback;



[Xenomai-git] Philippe Gerum : boilerplate: introduce get_static_cpu_count()

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 06c690f8db5f13dbae3b7ec81dabde74b3884ae5
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=06c690f8db5f13dbae3b7ec81dabde74b3884ae5

Author: Philippe Gerum r...@xenomai.org
Date:   Mon Apr 21 11:21:25 2014 +0200

boilerplate: introduce get_static_cpu_count()

---

 include/boilerplate/ancillaries.h |2 ++
 lib/boilerplate/ancillaries.c |   23 +++
 2 files changed, 25 insertions(+)

diff --git a/include/boilerplate/ancillaries.h 
b/include/boilerplate/ancillaries.h
index b2c5b44..f1b4118 100644
--- a/include/boilerplate/ancillaries.h
+++ b/include/boilerplate/ancillaries.h
@@ -75,6 +75,8 @@ void error_hook(struct error_frame *ef);
 
 void boilerplate_init(void);
 
+int get_static_cpu_count(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/boilerplate/ancillaries.c b/lib/boilerplate/ancillaries.c
index 390369c..688aeee 100644
--- a/lib/boilerplate/ancillaries.c
+++ b/lib/boilerplate/ancillaries.c
@@ -224,6 +224,29 @@ int __check_cancel_type(const char *locktype)
 
 #endif /* CONFIG_XENO_DEBUG */
 
+int get_static_cpu_count(void)
+{
+   char buf[BUFSIZ];
+   int count = 0;
+   FILE *fp;
+
+   /*
+* We want the maximum # of CPU the running kernel was
+* configured for, not the current online/present/possible
+* count of CPU devices.
+*/
+   fp = fopen(/sys/devices/system/cpu/kernel_max, r);
+   if (fp == NULL)
+   return -1;
+
+   if (fgets(buf, sizeof(buf), fp))
+   count = atoi(buf);
+
+   fclose(fp);
+
+   return count;
+}
+
 static void __boilerplate_init(void)
 {
__RT(clock_gettime(CLOCK_MONOTONIC, __init_date));


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


[Xenomai-git] Philippe Gerum : cobalt/bufd: drop obsolete sanity checks

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 978da9cd100befa2e09b63143c32234c94d5844e
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=978da9cd100befa2e09b63143c32234c94d5844e

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 24 14:51:24 2014 +0200

cobalt/bufd: drop obsolete sanity checks

With kernel-based Xenomai threads now underlaid by regular kernel task
contexts, those checks have become useless/redundant.

---

 kernel/cobalt/bufd.c |8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/kernel/cobalt/bufd.c b/kernel/cobalt/bufd.c
index d05b238..cea140f 100644
--- a/kernel/cobalt/bufd.c
+++ b/kernel/cobalt/bufd.c
@@ -235,8 +235,6 @@ EXPORT_SYMBOL_GPL(xnbufd_map_kmem);
 
 void xnbufd_map_umem(struct xnbufd *bufd, void __user *ptr, size_t len)
 {
-   XENO_BUGON(NUCLEUS, !xnthread_test_state(xnsched_current_thread(),
-XNROOT|XNUSER));
bufd-b_ptr = ptr;
bufd-b_len = len;
bufd-b_mm = current-mm;
@@ -330,8 +328,7 @@ ssize_t xnbufd_copy_to_kmem(void *to, struct xnbufd *bufd, 
size_t len)
 * here, since the source buffer would live in kernel space in
 * such a case.
 */
-   if (xnthread_test_state(xnsched_current_thread(), XNROOT|XNUSER) 
-   !xnsched_interrupt_p()  current-mm == bufd-b_mm) {
+   if (!xnsched_interrupt_p()  current-mm == bufd-b_mm) {
preemptible_only();
if (__xn_safe_copy_from_user(to, (void __user *)from, len))
return -EFAULT;
@@ -436,8 +433,7 @@ ssize_t xnbufd_copy_from_kmem(struct xnbufd *bufd, void 
*from, size_t len)
 * here: feeding a RT activity with data from a non-RT context
 * is wrong in the first place, so never mind.
 */
-   if (xnthread_test_state(xnsched_current_thread(), XNROOT|XNUSER) 
-   !xnsched_interrupt_p()  current-mm == bufd-b_mm) {
+   if (!xnsched_interrupt_p()  current-mm == bufd-b_mm) {
preemptible_only();
if (__xn_safe_copy_to_user((void __user *)to, from, len))
return -EFAULT;


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


[Xenomai-git] Philippe Gerum : drivers/ipc: move to new-style atomic sections

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 68f86dcf0da24e06643b4c08d26a4689b9e89068
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=68f86dcf0da24e06643b4c08d26a4689b9e89068

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 10 11:41:43 2014 +0200

drivers/ipc: move to new-style atomic sections

---

 kernel/drivers/ipc/bufp.c |  105 ++-
 kernel/drivers/ipc/iddp.c |  245 +++--
 kernel/drivers/ipc/xddp.c |   92 +
 3 files changed, 227 insertions(+), 215 deletions(-)

diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index 37884f8..99e1a1e 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -658,6 +658,7 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
 {
struct bufp_socket *sk = priv-state;
int ret = 0, port, fd;
+   spl_t s;
 
if (sa-sipc_family != AF_RTIPC)
return -EINVAL;
@@ -666,11 +667,12 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
sa-sipc_port = CONFIG_XENO_OPT_BUFP_NRPORT)
return -EINVAL;
 
-   RTDM_EXECUTE_ATOMICALLY(
-   if (test_bit(_BUFP_BOUND, sk-status) ||
-   __test_and_set_bit(_BUFP_BINDING, sk-status))
-   ret = -EADDRINUSE;
-   );
+   cobalt_atomic_enter(s);
+   if (test_bit(_BUFP_BOUND, sk-status) ||
+   __test_and_set_bit(_BUFP_BINDING, sk-status))
+   ret = -EADDRINUSE;
+   cobalt_atomic_leave(s);
+   
if (ret)
return ret;
 
@@ -710,10 +712,10 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
}
}
 
-   RTDM_EXECUTE_ATOMICALLY(
-   __clear_bit(_BUFP_BINDING, sk-status);
-   __set_bit(_BUFP_BOUND, sk-status);
-   );
+   cobalt_atomic_enter(s);
+   __clear_bit(_BUFP_BINDING, sk-status);
+   __set_bit(_BUFP_BOUND, sk-status);
+   cobalt_atomic_leave(s);
 
return 0;
 fail:
@@ -729,6 +731,7 @@ static int __bufp_connect_socket(struct bufp_socket *sk,
struct bufp_socket *rsk;
xnhandle_t h;
int ret;
+   spl_t s;
 
if (sa == NULL) {
sa = nullsa;
@@ -764,26 +767,26 @@ static int __bufp_connect_socket(struct bufp_socket *sk,
if (ret)
return ret;
 
-   RTDM_EXECUTE_ATOMICALLY(
-   rsk = xnregistry_lookup(h, NULL);
-   if (rsk == NULL || rsk-magic != BUFP_SOCKET_MAGIC)
-   ret = -EINVAL;
-   else
-   /* Fetch labeled port number. */
-   sa-sipc_port = rsk-name.sipc_port;
-   );
+   cobalt_atomic_enter(s);
+   rsk = xnregistry_lookup(h, NULL);
+   if (rsk == NULL || rsk-magic != BUFP_SOCKET_MAGIC)
+   ret = -EINVAL;
+   else
+   /* Fetch labeled port number. */
+   sa-sipc_port = rsk-name.sipc_port;
+   cobalt_atomic_leave(s);
if (ret)
return ret;
}
 
 set_assoc:
-   RTDM_EXECUTE_ATOMICALLY(
-   if (!test_bit(_BUFP_BOUND, sk-status))
-   /* Set default name. */
-   sk-name = *sa;
-   /* Set default destination. */
-   sk-peer = *sa;
-   );
+   cobalt_atomic_enter(s);
+   if (!test_bit(_BUFP_BOUND, sk-status))
+   /* Set default name. */
+   sk-name = *sa;
+   /* Set default destination. */
+   sk-peer = *sa;
+   cobalt_atomic_leave(s);
 
return 0;
 }
@@ -797,6 +800,7 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
struct timeval tv;
int ret = 0;
size_t len;
+   spl_t s;
 
if (rtipc_get_arg(user_info, sopt, arg, sizeof(sopt)))
return -EFAULT;
@@ -842,17 +846,17 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
return -EFAULT;
if (len == 0)
return -EINVAL;
-   RTDM_EXECUTE_ATOMICALLY(
-   /*
-* We may not do this more than once, and we
-* have to do this before the first binding.
-*/
-   if (test_bit(_BUFP_BOUND, sk-status) ||
-   test_bit(_BUFP_BINDING, sk-status))
-   ret = -EALREADY;
-   else
-   sk-bufsz = len;
-   );
+   cobalt_atomic_enter(s);
+   /*
+* We may not do this more than once, and we have to
+* do this before the first binding.
+*/
+   if (test_bit(_BUFP_BOUND, 

[Xenomai-git] Philippe Gerum : cobalt/timer: fix debug assertion

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: e882e0b7bf8128e0ed4bb6b701ed6b962d2b2782
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=e882e0b7bf8128e0ed4bb6b701ed6b962d2b2782

Author: Philippe Gerum r...@xenomai.org
Date:   Fri Apr 18 18:06:17 2014 +0200

cobalt/timer: fix debug assertion

---

 include/cobalt/kernel/bheap.h |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/cobalt/kernel/bheap.h b/include/cobalt/kernel/bheap.h
index a97701c..dcd0247 100644
--- a/include/cobalt/kernel/bheap.h
+++ b/include/cobalt/kernel/bheap.h
@@ -64,7 +64,7 @@ static inline int bheap_ordered(bheap_t *heap)
 }
 
 #define BHEAP_CHECK(heap)  \
-   XENO_BUGON(TIMERS, ((heap)-sz == 0) || !bheap_ordered(heap))
+   XENO_BUGON(NUCLEUS, ((heap)-sz == 0) || !bheap_ordered(heap))
 
 #define bheap_gethead(heap)\
({  \


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


[Xenomai-git] Philippe Gerum : cobalt/kernel: retrieve current TCB using xnshadow_current() when unambiguous

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: c927e1f8896ae0a121a6c78fe9a8743afa141c52
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=c927e1f8896ae0a121a6c78fe9a8743afa141c52

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 24 14:39:27 2014 +0200

cobalt/kernel: retrieve current TCB using xnshadow_current() when unambiguous

Unlike xnsched_current_thread(), xnshadow_current() does not involve
accessing protected per-cpu data on SMP. So prefer it when the context
is obviously primary, which guarantees that xnsched_current_thread()
== xnshadow_current().

---

 kernel/cobalt/posix/clock.c   |2 +-
 kernel/cobalt/posix/monitor.c |   29 +
 kernel/cobalt/posix/mutex.c   |   24 +---
 kernel/cobalt/posix/select.c  |   12 +---
 kernel/cobalt/posix/signal.c  |2 +-
 kernel/cobalt/posix/thread.c  |4 ++--
 kernel/cobalt/registry.c  |3 +--
 kernel/cobalt/rtdm/drvlib.c   |   20 +++-
 kernel/cobalt/select.c|   15 ++-
 kernel/cobalt/shadow.c|   26 +-
 kernel/cobalt/synch.c |   18 ++
 kernel/cobalt/thread.c|8 
 12 files changed, 92 insertions(+), 71 deletions(-)

diff --git a/kernel/cobalt/posix/clock.c b/kernel/cobalt/posix/clock.c
index f98592c..68383a7 100644
--- a/kernel/cobalt/posix/clock.c
+++ b/kernel/cobalt/posix/clock.c
@@ -270,7 +270,7 @@ int cobalt_clock_nanosleep(clockid_t clock_id, int flags,
if (flags  ~TIMER_ABSTIME)
return -EINVAL;
 
-   cur = xnsched_current_thread();
+   cur = xnshadow_current();
 
xnlock_get_irqsave(nklock, s);
 
diff --git a/kernel/cobalt/posix/monitor.c b/kernel/cobalt/posix/monitor.c
index c6b982e..5507829 100644
--- a/kernel/cobalt/posix/monitor.c
+++ b/kernel/cobalt/posix/monitor.c
@@ -114,9 +114,8 @@ int cobalt_monitor_init(struct cobalt_monitor_shadow __user 
*u_mon,
 }
 
 /* nklock held, irqs off */
-static int cobalt_monitor_enter_inner(xnhandle_t handle)
+static int cobalt_monitor_enter_inner(xnhandle_t handle, struct xnthread *curr)
 {
-   struct xnthread *cur = xnsched_current_thread();
struct cobalt_monitor *mon;
int ret = 0, info;
 
@@ -131,11 +130,11 @@ static int cobalt_monitor_enter_inner(xnhandle_t handle)
 *
 * NOTE: monitors do not support recursive entries.
 */
-   ret = xnsynch_fast_acquire(mon-gate.fastlock, xnthread_handle(cur));
+   ret = xnsynch_fast_acquire(mon-gate.fastlock, xnthread_handle(curr));
switch(ret) {
case 0:
-   if (xnthread_test_state(cur, XNWEAK))
-   xnthread_inc_rescnt(cur);
+   if (xnthread_test_state(curr, XNWEAK))
+   xnthread_inc_rescnt(curr);
break;
default:
/* Nah, we really have to wait. */
@@ -154,6 +153,7 @@ static int cobalt_monitor_enter_inner(xnhandle_t handle)
 
 int cobalt_monitor_enter(struct cobalt_monitor_shadow __user *u_mon)
 {
+   struct xnthread *curr = xnshadow_current();
xnhandle_t handle;
int ret;
spl_t s;
@@ -161,7 +161,7 @@ int cobalt_monitor_enter(struct cobalt_monitor_shadow 
__user *u_mon)
handle = cobalt_get_handle_from_user(u_mon-handle);
 
xnlock_get_irqsave(nklock, s);
-   ret = cobalt_monitor_enter_inner(handle);
+   ret = cobalt_monitor_enter_inner(handle, curr);
xnlock_put_irqrestore(nklock, s);
 
return ret;
@@ -301,7 +301,7 @@ int cobalt_monitor_wait(struct cobalt_monitor_shadow __user 
*u_mon,
opret = -ETIMEDOUT;
}
 
-   ret = cobalt_monitor_enter_inner(handle);
+   ret = cobalt_monitor_enter_inner(handle, curr-threadbase);
 out:
xnlock_put_irqrestore(nklock, s);
 
@@ -313,11 +313,13 @@ out:
 int cobalt_monitor_sync(struct cobalt_monitor_shadow __user *u_mon)
 {
struct cobalt_monitor *mon;
+   struct xnthread *curr;
xnhandle_t handle;
int ret = 0;
spl_t s;
 
handle = cobalt_get_handle_from_user(u_mon-handle);
+   curr = xnshadow_current();
 
xnlock_get_irqsave(nklock, s);
 
@@ -326,9 +328,9 @@ int cobalt_monitor_sync(struct cobalt_monitor_shadow __user 
*u_mon)
ret = -EINVAL;
else if (mon-data-flags  COBALT_MONITOR_SIGNALED) {
cobalt_monitor_wakeup(mon);
-   xnsynch_release(mon-gate, xnsched_current_thread());
+   xnsynch_release(mon-gate, curr);
xnsched_run();
-   ret = cobalt_monitor_enter_inner(handle);
+   ret = cobalt_monitor_enter_inner(handle, curr);
}
 
xnlock_put_irqrestore(nklock, s);
@@ -339,11 +341,13 @@ int cobalt_monitor_sync(struct cobalt_monitor_shadow 
__user *u_mon)
 int cobalt_monitor_exit(struct cobalt_monitor_shadow __user *u_mon)
 {
struct cobalt_monitor *mon;
+   struct 

[Xenomai-git] Philippe Gerum : drivers/ipc: move to new-style atomic sections

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: de8226b400403d36bcc72ac30545e661a8e5083f
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=de8226b400403d36bcc72ac30545e661a8e5083f

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 10 11:41:43 2014 +0200

drivers/ipc: move to new-style atomic sections

---

 kernel/drivers/ipc/bufp.c |  105 ++-
 kernel/drivers/ipc/iddp.c |  245 +++--
 kernel/drivers/ipc/xddp.c |   92 +
 3 files changed, 227 insertions(+), 215 deletions(-)

diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index 37884f8..99e1a1e 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -658,6 +658,7 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
 {
struct bufp_socket *sk = priv-state;
int ret = 0, port, fd;
+   spl_t s;
 
if (sa-sipc_family != AF_RTIPC)
return -EINVAL;
@@ -666,11 +667,12 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
sa-sipc_port = CONFIG_XENO_OPT_BUFP_NRPORT)
return -EINVAL;
 
-   RTDM_EXECUTE_ATOMICALLY(
-   if (test_bit(_BUFP_BOUND, sk-status) ||
-   __test_and_set_bit(_BUFP_BINDING, sk-status))
-   ret = -EADDRINUSE;
-   );
+   cobalt_atomic_enter(s);
+   if (test_bit(_BUFP_BOUND, sk-status) ||
+   __test_and_set_bit(_BUFP_BINDING, sk-status))
+   ret = -EADDRINUSE;
+   cobalt_atomic_leave(s);
+   
if (ret)
return ret;
 
@@ -710,10 +712,10 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
}
}
 
-   RTDM_EXECUTE_ATOMICALLY(
-   __clear_bit(_BUFP_BINDING, sk-status);
-   __set_bit(_BUFP_BOUND, sk-status);
-   );
+   cobalt_atomic_enter(s);
+   __clear_bit(_BUFP_BINDING, sk-status);
+   __set_bit(_BUFP_BOUND, sk-status);
+   cobalt_atomic_leave(s);
 
return 0;
 fail:
@@ -729,6 +731,7 @@ static int __bufp_connect_socket(struct bufp_socket *sk,
struct bufp_socket *rsk;
xnhandle_t h;
int ret;
+   spl_t s;
 
if (sa == NULL) {
sa = nullsa;
@@ -764,26 +767,26 @@ static int __bufp_connect_socket(struct bufp_socket *sk,
if (ret)
return ret;
 
-   RTDM_EXECUTE_ATOMICALLY(
-   rsk = xnregistry_lookup(h, NULL);
-   if (rsk == NULL || rsk-magic != BUFP_SOCKET_MAGIC)
-   ret = -EINVAL;
-   else
-   /* Fetch labeled port number. */
-   sa-sipc_port = rsk-name.sipc_port;
-   );
+   cobalt_atomic_enter(s);
+   rsk = xnregistry_lookup(h, NULL);
+   if (rsk == NULL || rsk-magic != BUFP_SOCKET_MAGIC)
+   ret = -EINVAL;
+   else
+   /* Fetch labeled port number. */
+   sa-sipc_port = rsk-name.sipc_port;
+   cobalt_atomic_leave(s);
if (ret)
return ret;
}
 
 set_assoc:
-   RTDM_EXECUTE_ATOMICALLY(
-   if (!test_bit(_BUFP_BOUND, sk-status))
-   /* Set default name. */
-   sk-name = *sa;
-   /* Set default destination. */
-   sk-peer = *sa;
-   );
+   cobalt_atomic_enter(s);
+   if (!test_bit(_BUFP_BOUND, sk-status))
+   /* Set default name. */
+   sk-name = *sa;
+   /* Set default destination. */
+   sk-peer = *sa;
+   cobalt_atomic_leave(s);
 
return 0;
 }
@@ -797,6 +800,7 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
struct timeval tv;
int ret = 0;
size_t len;
+   spl_t s;
 
if (rtipc_get_arg(user_info, sopt, arg, sizeof(sopt)))
return -EFAULT;
@@ -842,17 +846,17 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
return -EFAULT;
if (len == 0)
return -EINVAL;
-   RTDM_EXECUTE_ATOMICALLY(
-   /*
-* We may not do this more than once, and we
-* have to do this before the first binding.
-*/
-   if (test_bit(_BUFP_BOUND, sk-status) ||
-   test_bit(_BUFP_BINDING, sk-status))
-   ret = -EALREADY;
-   else
-   sk-bufsz = len;
-   );
+   cobalt_atomic_enter(s);
+   /*
+* We may not do this more than once, and we have to
+* do this before the first binding.
+*/
+   if (test_bit(_BUFP_BOUND, 

[Xenomai-git] Philippe Gerum : drivers/testing: move to new-style atomic sections

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 2d9042c298493a2f5b76d1edd5a67f85081cf076
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=2d9042c298493a2f5b76d1edd5a67f85081cf076

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 10 11:41:22 2014 +0200

drivers/testing: move to new-style atomic sections

---

 kernel/drivers/testing/timerbench.c |   33 +++--
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/kernel/drivers/testing/timerbench.c 
b/kernel/drivers/testing/timerbench.c
index 7d056d4..af75d56 100644
--- a/kernel/drivers/testing/timerbench.c
+++ b/kernel/drivers/testing/timerbench.c
@@ -141,22 +141,19 @@ static void eval_outer_loop(struct rt_tmbench_context 
*ctx)
 static void timer_task_proc(void *arg)
 {
struct rt_tmbench_context *ctx = arg;
-   int count;
+   int count, err;
+   spl_t s;
 
/* first event: one millisecond from now. */
ctx-date = rtdm_clock_read_monotonic() + 100;
 
while (1) {
-   int err;
-
for (count = 0; count  ctx-samples_per_sec; count++) {
-   RTDM_EXECUTE_ATOMICALLY(
-   ctx-start_time = rtdm_clock_read_monotonic();
-   err =
-   rtdm_task_sleep_abs(ctx-date,
-   
RTDM_TIMERMODE_ABSOLUTE);
-   );
-
+   cobalt_atomic_enter(s);
+   ctx-start_time = rtdm_clock_read_monotonic();
+   err = rtdm_task_sleep_abs(ctx-date,
+ RTDM_TIMERMODE_ABSOLUTE);
+   cobalt_atomic_leave(s);
if (err)
return;
 
@@ -237,6 +234,7 @@ static int rt_tmbench_start(struct rtdm_dev_context 
*context,
struct rttst_tmbench_config __user *user_config)
 {
int err = 0;
+   spl_t s;
 
struct rttst_tmbench_config config_buf;
struct rttst_tmbench_config *config =
@@ -311,16 +309,15 @@ static int rt_tmbench_start(struct rtdm_dev_context 
*context,
if (!test_bit(RTDM_CLOSING, context-context_flags)) {
ctx-mode = RTTST_TMBENCH_HANDLER;
 
-   RTDM_EXECUTE_ATOMICALLY(
-   ctx-start_time = rtdm_clock_read_monotonic();
+   cobalt_atomic_enter(s);
+   ctx-start_time = rtdm_clock_read_monotonic();
 
-   /* first event: one millisecond from now. */
-   ctx-date = ctx-start_time + 100;
+   /* first event: one millisecond from now. */
+   ctx-date = ctx-start_time + 100;
 
-   err =
-   rtdm_timer_start(ctx-timer, ctx-date, 0,
-RTDM_TIMERMODE_ABSOLUTE);
-   );
+   err = rtdm_timer_start(ctx-timer, ctx-date, 0,
+  RTDM_TIMERMODE_ABSOLUTE);
+   cobalt_atomic_leave(s);
}
}
 


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


[Xenomai-git] Philippe Gerum : cobalt/posix: introduce kernel tracepoints (WIP)

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 338d69f5578bc6a560fe9de20d1340f6922e12af
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=338d69f5578bc6a560fe9de20d1340f6922e12af

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Apr 26 15:09:17 2014 +0200

cobalt/posix: introduce kernel tracepoints (WIP)

---

 kernel/cobalt/posix/nsem.c |   16 +-
 kernel/cobalt/posix/sem.c  |   38 ++-
 kernel/cobalt/posix/thread.c   |   95 --
 kernel/cobalt/trace/cobalt-posix.h |  578 
 4 files changed, 696 insertions(+), 31 deletions(-)

diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
index e719560..f771ca5 100644
--- a/kernel/cobalt/posix/nsem.c
+++ b/kernel/cobalt/posix/nsem.c
@@ -24,13 +24,15 @@
 #include cobalt/kernel/tree.h
 #include internal.h
 #include sem.h
+#include thread.h
+#include trace/events/cobalt-posix.h
 
 DEFINE_XNLOCK(nsem_lock);
 
 struct nsem {
struct cobalt_sem *sem;
struct cobalt_sem_shadow __user *usem;
-   unsigned refs;
+   unsigned int refs;
struct xnid id;
 };
 
@@ -47,7 +49,7 @@ static struct nsem *nsem_search(struct cobalt_process *cc, 
xnhandle_t handle)
 
 static struct cobalt_sem_shadow __user *
 nsem_open(struct cobalt_process *cc, struct cobalt_sem_shadow __user *ushadow, 
-   const char *name, int oflags, mode_t mode, unsigned value)
+   const char *name, int oflags, mode_t mode, unsigned int value)
 {
struct cobalt_sem_shadow shadow;
struct cobalt_sem *sem;
@@ -142,6 +144,8 @@ nsem_open(struct cobalt_process *cc, struct 
cobalt_sem_shadow __user *ushadow,
xnlock_put_irqrestore(nsem_lock, s);
}
 
+   trace_cobalt_psem_open(name, handle, oflags, mode, value);
+
return u-usem;
 }
 
@@ -206,8 +210,11 @@ int cobalt_sem_open(struct cobalt_sem_shadow __user 
*__user *u_addr,
return -EINVAL;
 
usm = nsem_open(cc, usm, name, oflags, mode, value);
-   if (IS_ERR(usm))
+   if (IS_ERR(usm)) {
+   trace_cobalt_psem_open_failed(name, oflags, mode,
+ value, PTR_ERR(usm));
return PTR_ERR(usm);
+   }
 
__xn_put_user(usm, u_addr);
 
@@ -224,6 +231,7 @@ int cobalt_sem_close(struct cobalt_sem_shadow __user *usm)
return -EPERM;
 
handle = cobalt_get_handle_from_user(usm-handle);
+   trace_cobalt_psem_close(handle);
 
return nsem_close(cc, handle);
 }
@@ -241,6 +249,8 @@ int cobalt_sem_unlink(const char __user *u_name)
if (len = sizeof(name))
return -ENAMETOOLONG;
 
+   trace_cobalt_psem_unlink(name);
+
if (name[0] != '/')
return -EINVAL;
 
diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index 5865b5c..8d6b4ed 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -37,6 +37,7 @@
 #include thread.h
 #include clock.h
 #include sem.h
+#include trace/events/cobalt-posix.h
 
 #define SEM_NAMED0x8000
 
@@ -94,12 +95,16 @@ cobalt_sem_init_inner(const char *name, struct 
cobalt_sem_shadow *sm,
int ret, sflags;
spl_t s;
 
-   if ((flags  SEM_PULSE) != 0  value  0)
-   return ERR_PTR(-EINVAL);
+   if ((flags  SEM_PULSE) != 0  value  0) {
+   ret = -EINVAL;
+   goto out;
+   }
 
sem = xnmalloc(sizeof(*sem));
-   if (sem == NULL)
-   return ERR_PTR(-ENOSPC);
+   if (sem == NULL) {
+   ret = -ENOSPC;
+   goto out;
+   }
 
ksformat(sem-name, sizeof(sem-name), %s, name);
 
@@ -168,13 +173,17 @@ cobalt_sem_init_inner(const char *name, struct 
cobalt_sem_shadow *sm,
sm-datp_offset = -sm-datp_offset;
xnlock_put_irqrestore(nklock, s);
 
+   trace_cobalt_psem_init(sem-name, sem-handle, flags, value);
+
return sem;
 
-  err_lock_put:
+err_lock_put:
xnlock_put_irqrestore(nklock, s);
xnheap_free(sys_ppd-sem_heap, datp);
-  err_free_sem:
+err_free_sem:
xnfree(sem);
+out:
+   trace_cobalt_psem_init_failed(name, flags, value, ret);
 
return ERR_PTR(ret);
 }
@@ -689,6 +698,7 @@ int cobalt_sem_post(struct cobalt_sem_shadow __user *u_sem)
xnhandle_t handle;
 
handle = cobalt_get_handle_from_user(u_sem-handle);
+   trace_cobalt_psem_post(handle);
 
return sem_post(handle);
 }
@@ -698,6 +708,7 @@ int cobalt_sem_wait(struct cobalt_sem_shadow __user *u_sem)
xnhandle_t handle;
 
handle = cobalt_get_handle_from_user(u_sem-handle);
+   trace_cobalt_psem_wait(handle);
 
return sem_wait(handle);
 }
@@ -708,6 +719,7 @@ int cobalt_sem_timedwait(struct cobalt_sem_shadow __user 
*u_sem,
xnhandle_t handle;
 
handle = cobalt_get_handle_from_user(u_sem-handle);
+   trace_cobalt_psem_timedwait(handle);
 
return sem_timedwait(handle, u_ts);
 }

[Xenomai-git] Philippe Gerum : cobalt/rtdm: introduce wait queue API

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: e29ee96807b58ea4c22f5112bb03cd06fe901494
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=e29ee96807b58ea4c22f5112bb03cd06fe901494

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 10 11:40:15 2014 +0200

cobalt/rtdm: introduce wait queue API

---

 include/cobalt/kernel/rtdm/driver.h |  517 ++-
 1 file changed, 510 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 9c432c4..5234b22 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -605,6 +605,12 @@ static inline nanosecs_abs_t 
rtdm_clock_read_monotonic(void)
 }
 #endif /* !DOXYGEN_CPP */
 
+/* --- timeout sequences */
+
+typedef nanosecs_abs_t rtdm_toseq_t;
+
+void rtdm_toseq_init(rtdm_toseq_t *timeout_seq, nanosecs_rel_t timeout);
+
 /*!
  * @addtogroup rtdmsync
  * @{
@@ -620,7 +626,7 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector,
  */
 
 /**
- * @brief Execute code block atomically
+ * @brief Execute code block atomically (DEPRECATED)
  *
  * Generally, it is illegal to suspend the current task by calling
  * rtdm_task_sleep(), rtdm_event_wait(), etc. while holding a spinlock. In
@@ -650,6 +656,9 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector,
  * - User-space task (RT, non-RT)
  *
  * Rescheduling: possible, depends on functions called within @a code_block.
+ *
+ * @warning This construct is deprecated and will be phased out in
+ * Xenomai 3.0. Please use rtdm_waitqueue services instead.
  */
 #ifdef DOXYGEN_CPP /* Beautify doxygen output */
 #define RTDM_EXECUTE_ATOMICALLY(code_block)\
@@ -659,10 +668,14 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector,
LEAVE_ATOMIC_SECTION  \
 }
 #else /* This is how it really works */
+static inline __attribute__((deprecated)) void
+rtdm_execute_atomically(void) { }
+
 #define RTDM_EXECUTE_ATOMICALLY(code_block)\
 {  \
spl_t __rtdm_s; \
\
+   rtdm_execute_atomically();  \
xnlock_get_irqsave(nklock, __rtdm_s);  \
__xnsched_lock();   \
code_block; \
@@ -670,6 +683,7 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector,
xnlock_put_irqrestore(nklock, __rtdm_s);   \
 }
 #endif
+
 /** @} Global Lock across Scheduler Invocation */
 
 /*!
@@ -845,8 +859,503 @@ void rtdm_lock_put_irqrestore(rtdm_lock_t *lock, 
rtdm_lockctx_t s)
  */
 #define rtdm_lock_irqrestore(context)  \
splexit(context)
+
+/**
+ * @brief Enter atomic section (dual kernel only)
+ *
+ * This call opens a fully atomic section, serializing execution with
+ * respect to all interrupt handlers (including for real-time IRQs)
+ * and Xenomai threads running on all CPUs.
+ *
+ * @param context name of local variable to store the context in. This
+ * variable updated by the real-time core will hold the information
+ * required to leave the atomic section properly.
+ *
+ * @note Atomic sections may be nested.
+ *
+ * @note Since the strongest lock is acquired by this service, it can
+ * be used to synchronize real-time and non-real-time contexts.
+ *
+ * @warning This service is not portable to the Mercury core, and
+ * should be restricted to Cobalt-specific use cases.
+ */
+#define cobalt_atomic_enter(context)   \
+   do {\
+   xnlock_get_irqsave(nklock, (context)); \
+   __xnsched_lock();   \
+   } while (0)
+
+/**
+ * @brief Leave atomic section (dual kernel only)
+ *
+ * This call closes an atomic section previously opened by a call to
+ * cobalt_atomic_enter(), restoring the preemption and interrupt state
+ * which prevailed prior to entering the exited section.
+ *
+ * @param context name of local variable which stored the context.
+ *
+ * @warning This service is not portable to the Mercury core, and
+ * should be restricted to Cobalt-specific use cases.
+ */
+#define cobalt_atomic_leave(context)   \
+   do {\
+   __xnsched_unlock(); \
+   xnlock_put_irqrestore(nklock, (context));  \
+   } while (0)
+
 /** @} Spinlock with Preemption Deactivation */
 
+/*!
+ * @name Signal, test and wait for a condition atomically
+ * @{
+ */
+struct rtdm_waitqueue {
+   struct xnsynch wait;
+};
+typedef struct rtdm_waitqueue rtdm_waitqueue_t;
+
+#define RTDM_WAITQUEUE_INITIALIZER(__name) {\
+   .wait = XNSYNCH_WAITQUEUE_INITIALIZER((__name).wait), \
+   }
+
+#define DEFINE_RTDM_WAITQUEUE(__name)  \
+

[Xenomai-git] Philippe Gerum : drivers/can: move to new-style atomic sections

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: a892f4f587ffcbf06ec507dfad4bffefa8d470c3
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=a892f4f587ffcbf06ec507dfad4bffefa8d470c3

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Apr 10 11:41:15 2014 +0200

drivers/can: move to new-style atomic sections

---

 kernel/drivers/can/rtcan_raw.c|   13 -
 kernel/drivers/can/rtcan_socket.c |   13 ++---
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/kernel/drivers/can/rtcan_raw.c b/kernel/drivers/can/rtcan_raw.c
index 960b7a6..d3cb88a 100644
--- a/kernel/drivers/can/rtcan_raw.c
+++ b/kernel/drivers/can/rtcan_raw.c
@@ -800,6 +800,7 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_dev_context *context,
 struct rtcan_device *dev;
 int ifindex = 0;
 int ret  = 0;
+spl_t s;
 
 
 if (flags  MSG_OOB)   /* Mirror BSD error message compatibility */
@@ -912,8 +913,9 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_dev_context *context,
 /* If socket was not closed recently, register the task at the
  * socket's TX wait queue and decrement the TX semaphore. This must be
  * atomic. Finally, the task must be deregistered again (also atomic). */
-RTDM_EXECUTE_ATOMICALLY(
-   if (likely(!test_bit(RTDM_CLOSING, context-context_flags))) {
+cobalt_atomic_enter(s);
+
+if (likely(!test_bit(RTDM_CLOSING, context-context_flags))) {
 
list_add(tx_wait.tx_wait_list, sock-tx_wait_head);
 
@@ -929,10 +931,11 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_dev_context 
*context,
/* The socket was closed. */
ret = -EBADF;
 
-   } else
+} else
/* The socket was closed. */
-   ret = -EBADF;
-   );
+   ret = -EBADF;
+
+cobalt_atomic_leave(s);
 
 /* Error code returned? */
 if (ret != 0) {
diff --git a/kernel/drivers/can/rtcan_socket.c 
b/kernel/drivers/can/rtcan_socket.c
index d78d1f6..141a8bf 100644
--- a/kernel/drivers/can/rtcan_socket.c
+++ b/kernel/drivers/can/rtcan_socket.c
@@ -74,12 +74,11 @@ void rtcan_socket_cleanup(struct rtdm_dev_context *context)
 
 /* Wake up sleeping senders. This is re-entrant-safe. */
 do {
-   RTDM_EXECUTE_ATOMICALLY(
-   /* Is someone there? */
-   if (list_empty(sock-tx_wait_head))
+   cobalt_atomic_enter(lock_ctx);
+   /* Is someone there? */
+   if (list_empty(sock-tx_wait_head))
tx_list_empty = 1;
-
-   else {
+   else {
tx_list_empty = 0;
 
/* Get next entry pointing to a waiting task */
@@ -91,8 +90,8 @@ void rtcan_socket_cleanup(struct rtdm_dev_context *context)
 
/* Wake task up (atomic section is left implicitly) */
rtdm_task_unblock(tx_waiting-rt_task);
-   }
-   );
+   }
+   cobalt_atomic_leave(lock_ctx);
 } while (!tx_list_empty);
 
 rtdm_sem_destroy(sock-recv_sem);


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