[Xenomai-git] Philippe Gerum : cobalt/signal: export missing symbols

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

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Jul 30 16:04:53 2013 +0200

cobalt/signal: export missing symbols

---

 kernel/cobalt/posix/signal.c |5 +
 kernel/cobalt/posix/thread.c |1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index 29bca16..a3d443d 100644
--- a/kernel/cobalt/posix/signal.c
+++ b/kernel/cobalt/posix/signal.c
@@ -64,6 +64,7 @@ int cobalt_signal_deliver(struct cobalt_thread *thread,
 
return 1;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_deliver);
 
 int cobalt_signal_send(struct cobalt_thread *thread,
   struct cobalt_sigpending *sigp)
@@ -103,6 +104,7 @@ int cobalt_signal_send(struct cobalt_thread *thread,
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_send);
 
 int cobalt_signal_send_pid(pid_t pid, struct cobalt_sigpending *sigp)
 {  /* nklocked, IRQs off */
@@ -114,6 +116,7 @@ int cobalt_signal_send_pid(pid_t pid, struct 
cobalt_sigpending *sigp)
 
return -ESRCH;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_send_pid);
 
 int cobalt_signal_deliver_pid(pid_t pid, struct cobalt_sigpending *sigp)
 {  /* nklocked, IRQs off */
@@ -125,6 +128,7 @@ int cobalt_signal_deliver_pid(pid_t pid, struct 
cobalt_sigpending *sigp)
 
return -ESRCH;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_deliver_pid);
 
 struct cobalt_sigpending *cobalt_signal_alloc(void)
 {  /* nklocked, IRQs off */
@@ -138,6 +142,7 @@ struct cobalt_sigpending *cobalt_signal_alloc(void)
 
return sigp;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_alloc);
 
 void cobalt_signal_flush(struct cobalt_thread *thread)
 {
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 7dead4b..bd6f3f1 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -203,6 +203,7 @@ struct cobalt_thread *cobalt_thread_find(pid_t pid) /* 
nklocked, IRQs off */
 
return gslot ? gslot-thread : NULL;
 }
+EXPORT_SYMBOL_GPL(cobalt_thread_find);
 
 struct xnpersonality *cobalt_thread_exit(struct xnthread *curr)
 {


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


[Xenomai-git] Philippe Gerum : cobalt/sched: turn scheduler slot into a per-cpu variable

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

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Jul 30 16:42:09 2013 +0200

cobalt/sched: turn scheduler slot into a per-cpu variable

---

 include/cobalt/kernel/pod.h   |   10 --
 include/cobalt/kernel/sched.h |3 +++
 kernel/cobalt/pod.c   |2 +-
 kernel/cobalt/sched.c |3 +++
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/pod.h b/include/cobalt/kernel/pod.h
index e8f69e4..5b8af19 100644
--- a/include/cobalt/kernel/pod.h
+++ b/include/cobalt/kernel/pod.h
@@ -59,8 +59,7 @@ struct xnsynch;
 
 struct xnpod {
unsigned long status; /*! Status bitmask. */
-   xnsched_t sched[NR_CPUS];   /*! Per-cpu scheduler slots. */
-   struct list_head threadq;   /*! All existing threads. */
+   struct list_head threadq; /*! All existing threads. */
int nrthreads;
 #ifdef CONFIG_XENO_OPT_VFILE
struct xnvfile_rev_tag threadlist_tag;
@@ -92,16 +91,15 @@ void __xnpod_schedule(struct xnsched *sched);
 
 void __xnpod_schedule_handler(void);
 
-   /* -- Beginning of the exported interface */
-
 static inline struct xnsched *xnpod_sched_slot(int cpu)
 {
-   return nkpod-sched + cpu;
+   return per_cpu(nksched, cpu);
 }
 
 static inline struct xnsched *xnpod_current_sched(void)
 {
-   return xnpod_sched_slot(ipipe_processor_id());
+   /* IRQs off */
+   return __this_cpu_ptr(nksched);
 }
 
 static inline int xnpod_active_p(void)
diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index a5acc16..be3f2c5 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -28,6 +28,7 @@
 /*! \addtogroup sched
  *@{*/
 
+#include linux/percpu.h
 #include cobalt/kernel/thread.h
 #include cobalt/kernel/schedqueue.h
 #include cobalt/kernel/sched-tp.h
@@ -93,6 +94,8 @@ typedef struct xnsched {
 #endif
 } xnsched_t;
 
+DECLARE_PER_CPU(struct xnsched, nksched);
+
 union xnsched_policy_param;
 
 struct xnsched_class {
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index c4c8ea3..bb79139 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -260,7 +260,7 @@ int xnpod_init(void)
xnheap_set_label(kheap, main heap);
 
for_each_online_cpu(cpu) {
-   sched = pod-sched[cpu];
+   sched = per_cpu(nksched, cpu);
xnsched_init(sched, cpu);
if (xnarch_cpu_supported(cpu)) {
list_add_tail(sched-rootcb.glink, pod-threadq);
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index 1769586..c353674 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -30,6 +30,9 @@
 #include cobalt/kernel/arith.h
 #include asm/xenomai/thread.h
 
+DEFINE_PER_CPU(struct xnsched, nksched);
+EXPORT_PER_CPU_SYMBOL(nksched);
+
 static struct xnsched_class *xnsched_class_highest;
 
 #define for_each_xnsched_class(p) \


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


[Xenomai-git] Philippe Gerum : cobalt/kernel: remove pod abstraction entirely

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 19:03:46 2013 +0200

cobalt/kernel: remove pod abstraction entirely

We don't have full-fledged in-kernel APIs going in and out selectively
anymore, we now have a stable set of API services (i.e. core, POSIX
and RTDM), with optional limited extensions through Xenomai
personalities.

For this reason, the former pod abstraction, as a mean to group
multiple API siblings in a common generic container is not much
relevant anymore.

The ongoing design simplification now allows to drop the pod-related
services, dispatching them to the other existing abstractions.

The renaming involved are fairly straightforward for the most part,
i.e.:

* Former thread-directed ops:
  xnpod_action_thread() = xnthread_action()

* Former scheduler-related ops:
  xnpod_action() = xnsched_action()

Hint: xnpod_schedule() became xnsched_run() (although xnsched_ule()
would have been delighting).

---

 include/cobalt/kernel/Makefile.am  |2 +-
 include/cobalt/kernel/Makefile.in  |2 +-
 include/cobalt/kernel/assert.h |4 +-
 include/cobalt/kernel/clock.h  |4 +
 include/cobalt/kernel/lock.h   |   14 +-
 include/cobalt/kernel/pod.h|  310 ---
 include/cobalt/kernel/sched-tp.h   |5 +-
 include/cobalt/kernel/sched-weak.h |6 +-
 include/cobalt/kernel/sched.h  |  198 ++-
 include/cobalt/kernel/shadow.h |   17 +-
 include/cobalt/kernel/sys.h|   83 +
 include/cobalt/kernel/thread.h |   91 +-
 include/cobalt/kernel/timer.h  |2 +-
 include/cobalt/kernel/vdso.h   |1 -
 include/rtdm/rtdm_driver.h |   42 +-
 kernel/cobalt/Makefile |2 +-
 kernel/cobalt/arch/blackfin/machine.c  |   14 +-
 .../cobalt/arch/x86/include/asm/xenomai/thread.h   |3 +-
 kernel/cobalt/arch/x86/thread.c|3 +-
 kernel/cobalt/bufd.c   |   12 +-
 kernel/cobalt/clock.c  |   34 +-
 kernel/cobalt/debug.c  |   19 +-
 kernel/cobalt/heap.c   |   26 +-
 .../cobalt/include/asm-generic/xenomai/machine.h   |   16 -
 kernel/cobalt/init.c   |   16 +-
 kernel/cobalt/intr.c   |   59 +-
 kernel/cobalt/lock.c   |   15 +-
 kernel/cobalt/map.c|3 +-
 kernel/cobalt/pipe.c   |   10 +-
 kernel/cobalt/pod.c| 2161 
 kernel/cobalt/posix/clock.c|6 +-
 kernel/cobalt/posix/cond.c |2 +-
 kernel/cobalt/posix/event.c|4 +-
 kernel/cobalt/posix/internal.h |2 +-
 kernel/cobalt/posix/monitor.c  |   14 +-
 kernel/cobalt/posix/mqueue.c   |   12 +-
 kernel/cobalt/posix/mutex.c|   10 +-
 kernel/cobalt/posix/sem.c  |6 +-
 kernel/cobalt/posix/syscall.c  |2 +-
 kernel/cobalt/posix/thread.c   |   61 +-
 kernel/cobalt/posix/timer.c|2 +-
 kernel/cobalt/procfs.c |7 +-
 kernel/cobalt/registry.c   |   30 +-
 kernel/cobalt/rtdm/core.c  |1 -
 kernel/cobalt/rtdm/drvlib.c|   50 +-
 kernel/cobalt/rtdm/internal.h  |2 +-
 kernel/cobalt/sched-idle.c |8 +-
 kernel/cobalt/sched-rt.c   |   13 +-
 kernel/cobalt/sched-sporadic.c |   32 +-
 kernel/cobalt/sched-tp.c   |   16 +-
 kernel/cobalt/sched-weak.c |   16 +-
 kernel/cobalt/sched.c  |  339 +++-
 kernel/cobalt/select.c |   17 +-
 kernel/cobalt/shadow.c |  168 +-
 kernel/cobalt/synch.c  |   52 +-
 kernel/cobalt/sys.c|  332 +++
 kernel/cobalt/thread.c | 1506 ++-
 kernel/cobalt/timer.c  |   20 +-
 kernel/cobalt/vfile.c  |3 +-
 kernel/drivers/testing/switchtest.c|   24 +-
 60 files changed, 2869 insertions(+), 3062 deletions(-)

Diff:   

[Xenomai-git] Philippe Gerum : cobalt/registry: drop debug knob

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

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Aug  1 16:05:29 2013 +0200

cobalt/registry: drop debug knob

We don't get any useful information from the registry-specific debug
messages these days.

---

 kernel/cobalt/Kconfig|8 
 kernel/cobalt/registry.c |   22 --
 2 files changed, 0 insertions(+), 30 deletions(-)

diff --git a/kernel/cobalt/Kconfig b/kernel/cobalt/Kconfig
index e11b897..2aac57f 100644
--- a/kernel/cobalt/Kconfig
+++ b/kernel/cobalt/Kconfig
@@ -345,14 +345,6 @@ config XENO_OPT_DEBUG_XNLOCK
sections. Statistics about the longest masking section may be
found in /proc/xenomai/lock.
 
-config XENO_OPT_DEBUG_REGISTRY
-   bool Registry monitoring
-   help
-
-   This option activates debugging output for key registry
-   operations performed by the Xenomai core. This option is
-   useful to detect the source of object naming conflicts.
-
 config XENO_OPT_DEBUG_TIMERS
bool Timer monitoring
help
diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 4d86196..5f2deb6 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -42,10 +42,6 @@
 #include cobalt/kernel/apc.h
 #include cobalt/kernel/assert.h
 
-#ifndef CONFIG_XENO_OPT_DEBUG_REGISTRY
-#define CONFIG_XENO_OPT_DEBUG_REGISTRY  0
-#endif
-
 struct xnobject *registry_obj_slots;
 EXPORT_SYMBOL_GPL(registry_obj_slots);
 
@@ -696,15 +692,6 @@ unlock_and_exit:
 
xnlock_put_irqrestore(nklock, s);
 
-#if XENO_DEBUG(REGISTRY)
-   if (ret)
-   printk(XENO_ERR FAILED to register object %s (%s), status 
%d\n,
-  key, pnode ? pnode-dirname : unknown type, ret);
-   else if (pnode)
-   printk(XENO_INFO registered exported object %s (%s)\n,
-  key, pnode-dirname);
-#endif
-
return ret;
 }
 EXPORT_SYMBOL_GPL(xnregistry_enter);
@@ -863,15 +850,6 @@ int xnregistry_remove(xnhandle_t handle)
goto unlock_and_exit;
}
 
-#if XENO_DEBUG(REGISTRY)
-   /* We must keep the lock and report early, when the object
-* slot is still valid. Note: we only report about exported
-* objects. */
-   if (object-pnode)
-   printk(XENO_INFO unregistered exported object %s (%s)\n,
-  object-key, object-pnode-dirname);
-#endif
-
object-objaddr = NULL;
object-cstamp = 0;
 


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


[Xenomai-git] Philippe Gerum : cobalt/debug: introduce canned checks for calling context/ domain

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

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Aug  1 16:54:56 2013 +0200

cobalt/debug: introduce canned checks for calling context/domain

---

 include/cobalt/kernel/assert.h |7 +++
 kernel/cobalt/Kconfig  |   17 +++--
 kernel/cobalt/clock.c  |4 
 kernel/cobalt/heap.c   |3 +++
 kernel/cobalt/intr.c   |   14 +-
 kernel/cobalt/registry.c   |2 --
 kernel/cobalt/shadow.c |3 +--
 kernel/cobalt/thread.c |9 +++--
 8 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index dbca076..4d4cf9f 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -47,6 +47,10 @@
 #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0
 #endif
 
+#ifndef CONFIG_XENO_OPT_DEBUG_CONTEXT
+#define CONFIG_XENO_OPT_DEBUG_CONTEXT 0
+#endif
+
 #ifndef CONFIG_XENO_OPT_DEBUG_XNLOCK
 #define CONFIG_XENO_OPT_DEBUG_XNLOCK 0
 #endif
@@ -67,6 +71,9 @@
 #define CONFIG_XENO_OPT_DEBUG_COBALT 0
 #endif
 
+#define primary_mode_only()XENO_BUGON(CONTEXT, ipipe_root_p)
+#define secondary_mode_only()  XENO_BUGON(CONTEXT, !ipipe_root_p)
+
 void __xnsys_assert_failed(const char *file, int line, const char *msg);
 
 void __xnsys_fatal(const char *format, ...);
diff --git a/kernel/cobalt/Kconfig b/kernel/cobalt/Kconfig
index 0b1d53b..fb13b8f 100644
--- a/kernel/cobalt/Kconfig
+++ b/kernel/cobalt/Kconfig
@@ -325,14 +325,19 @@ menuconfig XENO_OPT_DEBUG
 if XENO_OPT_DEBUG
 
 config XENO_OPT_DEBUG_NUCLEUS
-   bool Nucleus runtime checks
+   bool Nucleus runtime assertions
help
 
-   This option activates various debugging checks inside the core
-   system. Doing so adds a significant runtime overhead,
-   worsening the latency figures especially on SMP kernels.  Do
-   not switch this option on unless you really know what you are
-   doing.
+   This option activates various assertions inside the core
+   system. This option has limited overhead.
+
+config XENO_OPT_DEBUG_CONTEXT
+   bool Check for calling context
+   help
+
+   This option enables checks for the calling context in the
+   Xenomai code, aimed at detecting when regular linux code is
+   entered from a real-time context, and conversely.
 
 config XENO_OPT_DEBUG_XNLOCK
bool Spinlock latency measurement
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 15aad23..bd06a96 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -489,6 +489,8 @@ int xnclock_register(struct xnclock *clock)
struct xntimerdata *tmd;
int cpu;
 
+   secondary_mode_only();
+
trace_mark(xn_nucleus, clock_register, clock %s, clock-name);
 
/* Allocate the percpu timer queue slot. */
@@ -536,6 +538,8 @@ void xnclock_deregister(struct xnclock *clock)
struct xntimerdata *tmd;
int cpu;
 
+   secondary_mode_only();
+
trace_mark(xn_nucleus, clock_deregister, clock %s, clock-name);
 
cleanup_clock_proc(clock);
diff --git a/kernel/cobalt/heap.c b/kernel/cobalt/heap.c
index 3db83be..af2d6c7 100644
--- a/kernel/cobalt/heap.c
+++ b/kernel/cobalt/heap.c
@@ -1283,6 +1283,8 @@ int xnheap_init_mapped(struct xnheap *heap, unsigned long 
heapsize, int memflags
void *heapbase;
int err;
 
+   secondary_mode_only();
+
/* Caller must have accounted for internal overhead. */
heapsize = xnheap_align(heapsize, PAGE_SIZE);
 
@@ -1317,6 +1319,7 @@ void xnheap_destroy_mapped(struct xnheap *heap,
unsigned long len;
spl_t s;
 
+   secondary_mode_only();
/*
 * Trying to unmap user memory without providing a release
 * handler for deferred cleanup is a bug.
diff --git a/kernel/cobalt/intr.c b/kernel/cobalt/intr.c
index 36bf647..d315b25 100644
--- a/kernel/cobalt/intr.c
+++ b/kernel/cobalt/intr.c
@@ -624,7 +624,7 @@ int xnintr_init(xnintr_t *intr, const char *name,
unsigned int irq, xnisr_t isr, xniack_t iack,
int flags)
 {
-   XENO_BUGON(NUCLEUS, !ipipe_root_p);
+   secondary_mode_only();
 
if (irq = IPIPE_NR_IRQS)
return -EINVAL;
@@ -669,7 +669,7 @@ EXPORT_SYMBOL_GPL(xnintr_init);
  */
 void xnintr_destroy(xnintr_t *intr)
 {
-   XENO_BUGON(NUCLEUS, !ipipe_root_p);
+   secondary_mode_only();
xnintr_detach(intr);
free_percpu(intr-stats);
 }
@@ -713,12 +713,13 @@ EXPORT_SYMBOL_GPL(xnintr_destroy);
  * @note Attaching an interrupt resets the tracked number of receipts
  * to zero.
  */
-
 int xnintr_attach(xnintr_t *intr, void *cookie)
 {
int ret;
spl_t s;
 
+   secondary_mode_only();
+
trace_mark(xn_nucleus, 

[Xenomai-git] Philippe Gerum : cobalt/sched: drop delayed thread cleanup via zombie state transition

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 11:59:30 2013 +0200

cobalt/sched: drop delayed thread cleanup via zombie state transition

Since Xenomai thread deletion now always involves a self-exit from
secondary mode, possibly after a pending cancellation request is
noticed, there is no way a thread could self-delete from primary mode
anymore.

For this reason, delaying resource cleanup until the exiting thread
schedules out from xnpod_schedule() becomes pointless, since it must
have done so earlier, when leaving primary mode prior to running
do_exit() and the taskexit handler. At this point, the exiting thread
runs in mere linux context, and may release any Xenomai-specific
resource.

We drop the mechanism for delaying thread finalization upon
self-deletion, removing all zombie state hooks in the same move.

---

 include/cobalt/kernel/sched.h |   68 +---
 kernel/cobalt/lock.c  |2 +-
 kernel/cobalt/pod.c   |   26 ---
 kernel/cobalt/sched.c |   44 +--
 kernel/cobalt/shadow.c|1 -
 5 files changed, 45 insertions(+), 96 deletions(-)

diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index be3f2c5..402c385 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -55,51 +55,65 @@ struct xnsched_rt {
  * \brief Scheduling information structure.
  */
 
-typedef struct xnsched {
-
-   unsigned long status;   /*! Scheduler specific status bitmask. 
*/
-   unsigned long lflags;   /*! Scheduler specific local flags 
bitmask. */
-   struct xnthread *curr;  /*! Current thread. */
+struct xnsched {
+   /*! Scheduler specific status bitmask. */
+   unsigned long status;
+   /*! Scheduler specific local flags bitmask. */
+   unsigned long lflags;
+   /*! Current thread. */
+   struct xnthread *curr;
 #ifdef CONFIG_SMP
+   /*! Owner CPU id. */
int cpu;
-   cpumask_t resched;  /*! Mask of CPUs needing rescheduling. 
*/
+   /*! Mask of CPUs needing rescheduling. */
+   cpumask_t resched;
 #endif
-   struct xnsched_rt rt;   /*! Context of built-in real-time 
class. */
+   /*! Context of built-in real-time class. */
+   struct xnsched_rt rt;
 #ifdef CONFIG_XENO_OPT_SCHED_WEAK
-   struct xnsched_weak weak;   /*! Context of weak scheduling class. 
*/
+   /*! Context of weak scheduling class. */
+   struct xnsched_weak weak;
 #endif
 #ifdef CONFIG_XENO_OPT_SCHED_TP
-   struct xnsched_tp tp;   /*! Context of TP class. */
+   /*! Context of TP class. */
+   struct xnsched_tp tp;
 #endif
 #ifdef CONFIG_XENO_OPT_SCHED_SPORADIC
-   struct xnsched_sporadic pss;/*! Context of sporadic scheduling 
class. */
+   /*! Context of sporadic scheduling class. */
+   struct xnsched_sporadic pss;
 #endif
-   volatile unsigned inesting; /*! Interrupt nesting level. */
-   struct xntimer htimer;  /*! Host timer. */
-   struct xnthread *zombie;
-   struct xnthread rootcb; /*! Root thread control block. */
+   /*! Interrupt nesting level. */
+   volatile unsigned inesting;
+   /*! Host timer. */
+   struct xntimer htimer;
+   /*! Root thread control block. */
+   struct xnthread rootcb;
 #ifdef CONFIG_XENO_HW_UNLOCKED_SWITCH
struct xnthread *last;
 #endif
 #ifdef CONFIG_XENO_HW_FPU
-   struct xnthread *fpuholder; /*! Thread owning the current FPU 
context. */
+   /*! Thread owning the current FPU context. */
+   struct xnthread *fpuholder;
 #endif
 #ifdef CONFIG_XENO_OPT_WATCHDOG
-   struct xntimer wdtimer; /*! Watchdog timer object. */
-   int wdcount;/*! Watchdog tick count. */
+   /*! Watchdog timer object. */
+   struct xntimer wdtimer;
+   /*! Watchdog tick count. */
+   int wdcount;
 #endif
 #ifdef CONFIG_XENO_OPT_STATS
-   xnticks_t last_account_switch;  /*! Last account switch date (ticks). 
*/
-   xnstat_exectime_t *current_account; /*! Currently active account */
+   /*! Last account switch date (ticks). */
+   xnticks_t last_account_switch;
+   /*! Currently active account */
+   xnstat_exectime_t *current_account;
 #endif
-} xnsched_t;
+};
 
 DECLARE_PER_CPU(struct xnsched, nksched);
 
 union xnsched_policy_param;
 
 struct xnsched_class {
-
void (*sched_init)(struct xnsched *sched);
void (*sched_enqueue)(struct xnthread *thread);
void (*sched_dequeue)(struct xnthread *thread);
@@ -156,7 +170,7 @@ static inline int xnsched_resched_p(struct xnsched *sched)
 /* Set resched flag for the given scheduler. */
 #ifdef CONFIG_SMP
 

[Xenomai-git] Philippe Gerum : cobalt/assert: move failed assertion handler out of line

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

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Aug  1 15:36:17 2013 +0200

cobalt/assert: move failed assertion handler out of line

In the same move, the former action argument disappears from
XENO_ASSERT(), which now returns the boolean result for the asserted
condition.

formerly:
XENO_ASSERT(subsystem, condition, action);

should now be written:
if (!XENO_ASSERT(subsystem, condition))
action;

---

 include/cobalt/kernel/assert.h |   39 ---
 include/cobalt/kernel/heap.h   |1 -
 include/cobalt/kernel/misc.h   |   27 --
 include/cobalt/kernel/sched.h  |   26 ++
 include/rtdm/rtdm_driver.h |   20 +---
 kernel/cobalt/Makefile |1 +
 kernel/cobalt/assert.c |  105 
 kernel/cobalt/heap.c   |   16 ++
 kernel/cobalt/intr.c   |2 +-
 kernel/cobalt/rtdm/core.c  |   23 -
 kernel/cobalt/rtdm/device.c|   32 +++-
 kernel/cobalt/rtdm/drvlib.c|   38 ++-
 kernel/cobalt/sched.c  |   18 ++-
 kernel/cobalt/sys.c|   89 +++---
 kernel/cobalt/thread.c |   18 ++-
 15 files changed, 234 insertions(+), 221 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index 4cf421c..cad72d0 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -16,38 +16,43 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  * 02111-1307, USA.
  */
-
 #ifndef _COBALT_KERNEL_ASSERT_H
 #define _COBALT_KERNEL_ASSERT_H
 
 #include cobalt/kernel/trace.h
 
-#define XENO_DEBUG(subsystem)  \
-   (CONFIG_XENO_OPT_DEBUG_##subsystem  0)
+#define XENO_INFO KERN_INFO[Xenomai] 
+#define XENO_WARN KERN_WARNING [Xenomai] 
+#define XENO_ERR  KERN_ERR [Xenomai] 
+
+#define XENO_DEBUG(__subsys)   \
+   (CONFIG_XENO_OPT_DEBUG_##__subsys  0)
 
-#define XENO_ASSERT(subsystem,cond,action)  do {   \
-   if (unlikely(XENO_DEBUG(subsystem)  !(cond))) {   \
-   xntrace_panic_freeze(); \
-   printk(XENO_ERR assertion failed at %s:%d (%s)\n, 
\
-__FILE__, __LINE__, (#cond));  \
-   xntrace_panic_dump();   \
-   action; \
-   }   \
-   } while(0)
+#define XENO_ASSERT(__subsys, __cond)  
\
+   ({  
\
+   int __ret = !XENO_DEBUG(__subsys) || (__cond);  
\
+   if (unlikely(!__ret))   
\
+   __xnsys_assert_failed(__FILE__, __LINE__, (#__cond));   
\
+   __ret;  
\
+   })
 
-#define XENO_BUGON(subsystem,cond) \
+#define XENO_BUGON(__subsys, __cond)   \
do {\
-   if (unlikely(XENO_DEBUG(subsystem)  (cond)))  \
+   if (unlikely(XENO_DEBUG(__subsys)  (__cond))) \
xnsys_fatal(bug at %s:%d (%s),\
-   __FILE__, __LINE__, (#cond));   \
-   } while(0)
+   __FILE__, __LINE__, (#__cond)); \
+   } while (0)
 
 #ifndef CONFIG_XENO_OPT_DEBUG_NUCLEUS
 #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0
 #endif /* CONFIG_XENO_OPT_DEBUG_NUCLEUS */
 
-extern void (*nkpanic)(const char *format, ...);
+void __xnsys_assert_failed(const char *file, int line, const char *msg);
+
+void __xnsys_fatal(const char *format, ...);
 
 #define xnsys_fatal(__fmt, __args...) nkpanic(__fmt, ##__args)
 
+extern void (*nkpanic)(const char *format, ...);
+
 #endif /* !_COBALT_KERNEL_ASSERT_H */
diff --git a/include/cobalt/kernel/heap.h b/include/cobalt/kernel/heap.h
index 263dd6a..83874ff 100644
--- a/include/cobalt/kernel/heap.h
+++ b/include/cobalt/kernel/heap.h
@@ -26,7 +26,6 @@
 #include cobalt/kernel/lock.h
 #include cobalt/kernel/list.h
 #include cobalt/kernel/trace.h
-#include cobalt/kernel/misc.h
 #include cobalt/uapi/kernel/types.h
 #include cobalt/uapi/kernel/heap.h
 
diff --git a/include/cobalt/kernel/misc.h b/include/cobalt/kernel/misc.h
deleted file mode 100644
index a2c723a..000
--- a/include/cobalt/kernel/misc.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2013 Philippe Gerum 

[Xenomai-git] Philippe Gerum : cobalt/kernel: drop sys features file

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Aug  7 16:40:26 2013 +0200

cobalt/kernel: drop sys features file

This file used to be a kitchen sink although its contents could be
dispatched to better feature-specific places. Move them there instead,
and plug that sink.

---

 include/cobalt/kernel/Makefile.am   |1 -
 include/cobalt/kernel/Makefile.in   |1 -
 include/cobalt/kernel/sched.h   |   25 
 include/cobalt/kernel/shadow.h  |   19 +++-
 include/cobalt/kernel/sys.h |   83 ---
 kernel/cobalt/Makefile  |1 -
 kernel/cobalt/init.c|  177 +++-
 kernel/cobalt/intr.c|2 +-
 kernel/cobalt/rtdm/internal.h   |6 +-
 kernel/cobalt/sched.c   |6 +-
 kernel/cobalt/shadow.c  |8 +-
 kernel/cobalt/sys.c |  259 ---
 kernel/cobalt/thread.c  |1 -
 kernel/drivers/testing/switchtest.c |1 -
 14 files changed, 230 insertions(+), 360 deletions(-)

diff --git a/include/cobalt/kernel/Makefile.am 
b/include/cobalt/kernel/Makefile.am
index 65824ba..e1653da 100644
--- a/include/cobalt/kernel/Makefile.am
+++ b/include/cobalt/kernel/Makefile.am
@@ -26,7 +26,6 @@ noinst_HEADERS =  \
shadow.h\
stat.h  \
synch.h \
-   sys.h   \
thread.h\
timer.h \
trace.h \
diff --git a/include/cobalt/kernel/Makefile.in 
b/include/cobalt/kernel/Makefile.in
index e9d3ed0..e0ed379 100644
--- a/include/cobalt/kernel/Makefile.in
+++ b/include/cobalt/kernel/Makefile.in
@@ -272,7 +272,6 @@ noinst_HEADERS = \
shadow.h\
stat.h  \
synch.h \
-   sys.h   \
thread.h\
timer.h \
trace.h \
diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index e6751c4..2606b6c 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -36,6 +36,7 @@
 #include cobalt/kernel/sched-sporadic.h
 #include cobalt/kernel/vfile.h
 #include cobalt/kernel/assert.h
+#include asm/xenomai/machine.h
 
 /* Sched status flags */
 #define XNRESCHED  0x1000  /* Needs rescheduling */
@@ -112,6 +113,8 @@ struct xnsched {
 
 DECLARE_PER_CPU(struct xnsched, nksched);
 
+extern cpumask_t nkaffinity;
+
 extern struct list_head nkthreadq;
 
 extern int nknrthreads;
@@ -200,6 +203,7 @@ static inline void xnsched_set_self_resched(struct xnsched 
*sched)
 
 /* Set resched flag for the given scheduler. */
 #ifdef CONFIG_SMP
+
 static inline void xnsched_set_resched(struct xnsched *sched)
 {
struct xnsched *current_sched = xnsched_current();
@@ -212,13 +216,34 @@ static inline void xnsched_set_resched(struct xnsched 
*sched)
current_sched-status |= XNRESCHED;
}
 }
+
+#define xnsched_cpus xnarch_machdata.supported_cpus
+
+static inline int xnsched_supported_cpu(int cpu)
+{
+   return cpu_isset(cpu, xnsched_cpus);
+}
+
 #else /* !CONFIG_SMP */
+
 static inline void xnsched_set_resched(struct xnsched *sched)
 {
xnsched_set_self_resched(sched);
 }
+
+#define xnsched_cpus CPU_MASK_ALL
+
+static inline int xnsched_supported_cpu(int cpu)
+{
+   return 1;
+}
+
 #endif /* !CONFIG_SMP */
 
+#define for_each_realtime_cpu(cpu) \
+   for_each_online_cpu(cpu)\
+   if (xnsched_supported_cpu(cpu)) \
+
 void __xnsched_run(struct xnsched *sched);
 
 void __xnsched_run_handler(void);
diff --git a/include/cobalt/kernel/shadow.h b/include/cobalt/kernel/shadow.h
index 6d3a90f..8f5b4cb 100644
--- a/include/cobalt/kernel/shadow.h
+++ b/include/cobalt/kernel/shadow.h
@@ -20,7 +20,6 @@
 #ifndef _COBALT_KERNEL_SHADOW_H
 #define _COBALT_KERNEL_SHADOW_H
 
-#include cobalt/kernel/sys.h
 #include asm/xenomai/syscall.h
 
 struct xnthread;
@@ -32,6 +31,22 @@ struct completion;
 struct module;
 struct xnshadow_ppd;
 
+struct xnpersonality {
+   const char *name;
+   unsigned int magic;
+   int nrcalls;
+   struct xnsyscall *syscalls;
+   atomic_t refcnt;
+   struct {
+   struct xnshadow_ppd *(*attach_process)(void);
+   void (*detach_process)(struct xnshadow_ppd *ppd);
+   struct xnpersonality *(*map_thread)(struct xnthread *thread);
+   struct xnpersonality *(*exit_thread)(struct xnthread *thread);
+   struct xnpersonality *(*finalize_thread)(struct xnthread 
*thread);
+   } ops;
+   struct module *module;
+};
+
 static inline struct xnthread *xnshadow_current(void)
 {
return ipipe_current_threadinfo()-thread;
@@ -107,4 +122,6 @@ xnshadow_push_personality(struct xnthread *thread,

[Xenomai-git] Philippe Gerum : cobalt/kernel: restrict CPU enumerations to Xenomai-enabled ones

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

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Aug  1 15:45:11 2013 +0200

cobalt/kernel: restrict CPU enumerations to Xenomai-enabled ones

Since we only initialize scheduler slots for Xenomai-enabled CPUs,
we'd better consider only those from Xenomai's cpu_supported mask,
which may be a subset of the cpu_online mask.

We define for_each_realtime_cpu() for enumerating these
Xenomai-enabled CPUs.

---

 include/cobalt/kernel/sys.h |2 +-
 kernel/cobalt/assert.c  |2 +-
 kernel/cobalt/clock.c   |6 +++---
 kernel/cobalt/intr.c|   12 ++--
 kernel/cobalt/procfs.c  |   13 ++---
 kernel/cobalt/sys.c |8 
 6 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/include/cobalt/kernel/sys.h b/include/cobalt/kernel/sys.h
index 00c63e9..c95f9d9 100644
--- a/include/cobalt/kernel/sys.h
+++ b/include/cobalt/kernel/sys.h
@@ -66,7 +66,7 @@ static inline int xnsys_supported_cpu(int cpu)
 
 #endif /* !CONFIG_SMP */
 
-#define for_each_xenomai_cpu(cpu)  \
+#define for_each_realtime_cpu(cpu) \
for_each_online_cpu(cpu)\
if (xnsys_supported_cpu(cpu))   \
 
diff --git a/kernel/cobalt/assert.c b/kernel/cobalt/assert.c
index 8032c02..b346b8d 100644
--- a/kernel/cobalt/assert.c
+++ b/kernel/cobalt/assert.c
@@ -62,7 +62,7 @@ void __xnsys_fatal(const char *format, ...)
 * NOTE: nkthreadq can't be empty, we have the root thread(s)
 * linked there at least.
 */
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
sched = xnsched_struct(cpu);
list_for_each_entry(thread, nkthreadq, glink) {
if (thread-sched != sched)
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 4386812..15aad23 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -252,7 +252,7 @@ static void adjust_clock_timers(struct xnclock *clock, 
xnsticks_t delta)
INIT_LIST_HEAD(adjq);
delta = xnclock_ns_to_ticks(clock, delta);
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
sched = xnsched_struct(cpu);
q = xnclock_percpu_timerdata(clock, cpu)-q;
 
@@ -496,7 +496,7 @@ int xnclock_register(struct xnclock *clock)
if (clock-timerdata == NULL)
return -ENOMEM;
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
tmd = xnclock_percpu_timerdata(clock, cpu);
xntimerq_init(tmd-q);
}
@@ -540,7 +540,7 @@ void xnclock_deregister(struct xnclock *clock)
 
cleanup_clock_proc(clock);
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
tmd = xnclock_percpu_timerdata(clock, cpu);
XENO_BUGON(NUCLEUS, !xntimerq_empty(tmd-q));
xntimerq_destroy(tmd-q);
diff --git a/kernel/cobalt/intr.c b/kernel/cobalt/intr.c
index cb5761b..36bf647 100644
--- a/kernel/cobalt/intr.c
+++ b/kernel/cobalt/intr.c
@@ -62,7 +62,7 @@ static inline void sync_stat_references(struct xnintr *intr)
struct xnsched *sched;
int cpu;
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
sched = xnsched_struct(cpu);
statp = per_cpu_ptr(intr-stats, cpu);
/* Synchronize on all dangling references to go away. */
@@ -511,7 +511,7 @@ static void clear_irqstats(struct xnintr *intr)
struct xnirqstat *p;
int cpu;
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
p = per_cpu_ptr(intr-stats, cpu);
memset(p, 0, sizeof(*p));
}
@@ -882,7 +882,7 @@ static inline int xnintr_is_timer_irq(int irq)
 {
int cpu;
 
-   for_each_online_cpu(cpu)
+   for_each_realtime_cpu(cpu)
if (irq == per_cpu(ipipe_percpu.hrtimer_irq, cpu))
return 1;
 
@@ -986,7 +986,7 @@ static inline int format_irq_proc(unsigned int irq,
spl_t s;
int cpu;
 
-   for_each_online_cpu(cpu)
+   for_each_realtime_cpu(cpu)
if (xnintr_is_timer_irq(irq)) {
xnvfile_printf(it,  [timer/%d], cpu);
return 0;
@@ -1038,7 +1038,7 @@ static int irq_vfile_show(struct xnvfile_regular_iterator 
*it,
 
xnvfile_puts(it,   IRQ );
 
-   for_each_online_cpu(cpu)
+   for_each_realtime_cpu(cpu)
xnvfile_printf(it, CPU%d, cpu);
 
for (irq = 0; irq  IPIPE_NR_IRQS; irq++) {
@@ -1047,7 +1047,7 @@ static int irq_vfile_show(struct xnvfile_regular_iterator 
*it,
 
xnvfile_printf(it, \n%5d:, irq);
 
-   for_each_online_cpu(cpu) {
+   

[Xenomai-git] Philippe Gerum : cobalt/intr: calling xnintr_detach() may lead to nop

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

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Aug  1 14:29:15 2013 +0200

cobalt/intr: calling xnintr_detach() may lead to nop

---

 include/cobalt/kernel/intr.h |4 +-
 include/rtdm/rtdm_driver.h   |3 +-
 kernel/cobalt/intr.c |   55 +++--
 3 files changed, 19 insertions(+), 43 deletions(-)

diff --git a/include/cobalt/kernel/intr.h b/include/cobalt/kernel/intr.h
index 835f7fd..7c29b97 100644
--- a/include/cobalt/kernel/intr.h
+++ b/include/cobalt/kernel/intr.h
@@ -117,12 +117,12 @@ int xnintr_init(xnintr_t *intr,
xniack_t iack,
int flags);
 
-int xnintr_destroy(xnintr_t *intr);
+void xnintr_destroy(xnintr_t *intr);
 
 int xnintr_attach(xnintr_t *intr,
  void *cookie);
 
-int xnintr_detach(xnintr_t *intr);
+void xnintr_detach(xnintr_t *intr);
 
 void xnintr_enable(xnintr_t *intr);
 
diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h
index 61706a8..801dbdd 100644
--- a/include/rtdm/rtdm_driver.h
+++ b/include/rtdm/rtdm_driver.h
@@ -924,7 +924,8 @@ int rtdm_irq_request(rtdm_irq_t *irq_handle, unsigned int 
irq_no,
 static inline int rtdm_irq_free(rtdm_irq_t *irq_handle)
 {
XENO_ASSERT(RTDM, xnsched_root_p(), return -EPERM;);
-   return xnintr_detach(irq_handle);
+   xnintr_detach(irq_handle);
+   return 0;
 }
 
 static inline int rtdm_irq_enable(rtdm_irq_t *irq_handle)
diff --git a/kernel/cobalt/intr.c b/kernel/cobalt/intr.c
index a57c1e6..6973a46 100644
--- a/kernel/cobalt/intr.c
+++ b/kernel/cobalt/intr.c
@@ -646,9 +646,9 @@ int xnintr_init(xnintr_t *intr, const char *name,
 }
 EXPORT_SYMBOL_GPL(xnintr_init);
 
-/*!
- * \fn int xnintr_destroy (xnintr_t *intr)
- * \brief Destroy an interrupt object.
+/**
+ * @fn void xnintr_destroy(xnintr_t *intr)
+ * @brief Destroy an interrupt object.
  *
  * Destroys an interrupt object previously initialized by
  * xnintr_init(). The interrupt object is automatically detached by a
@@ -658,10 +658,6 @@ EXPORT_SYMBOL_GPL(xnintr_init);
  * @param intr The descriptor address of the interrupt object to
  * destroy.
  *
- * @return 0 is returned on success. Otherwise, -EINVAL is returned if
- * an error occurred while detaching the interrupt (see
- * xnintr_detach()).
- *
  * Environments:
  *
  * This service can be called from:
@@ -671,20 +667,11 @@ EXPORT_SYMBOL_GPL(xnintr_init);
  *
  * Rescheduling: never.
  */
-
-int xnintr_destroy(xnintr_t *intr)
+void xnintr_destroy(xnintr_t *intr)
 {
-   int ret;
-
XENO_BUGON(NUCLEUS, !ipipe_root_p);
-
-   ret = xnintr_detach(intr);
-   if (ret)
-   return ret;
-
+   xnintr_detach(intr);
free_percpu(intr-stats);
-
-   return 0;
 }
 EXPORT_SYMBOL_GPL(xnintr_destroy);
 
@@ -762,9 +749,9 @@ out:
 }
 EXPORT_SYMBOL_GPL(xnintr_attach);
 
-/*!
- * \fn int xnintr_detach (xnintr_t *intr)
- * \brief Detach an interrupt object.
+/**
+ * @fn int xnintr_detach(xnintr_t *intr)
+ * @brief Detach an interrupt object.
  *
  * Detach an interrupt object previously attached by
  * xnintr_attach(). After this operation is completed, no more IRQs
@@ -775,14 +762,8 @@ EXPORT_SYMBOL_GPL(xnintr_attach);
  * @param intr The descriptor address of the interrupt object to
  * detach.
  *
- * @return 0 is returned on success. Otherwise:
- *
- * - -EINVAL is returned if a low-level error occurred while detaching
- * the interrupt, or if the interrupt object was not attached. In both
- * cases, no action is performed.
- *
- * @note The caller bmust not/b hold nklock when invoking this service,
- * this would cause deadlocks.
+ * @note The caller bmust not/b hold nklock when invoking this
+ * service, this would cause deadlocks.
  *
  * Environments:
  *
@@ -793,27 +774,21 @@ EXPORT_SYMBOL_GPL(xnintr_attach);
  *
  * Rescheduling: never.
  */
-int xnintr_detach(xnintr_t *intr)
+void xnintr_detach(xnintr_t *intr)
 {
-   int ret;
spl_t s;
 
trace_mark(xn_nucleus, irq_detach, irq %u, intr-irq);
 
xnlock_get_irqsave(intrlock, s);
 
-   if ((intr-flags  XN_ISR_ATTACHED) == 0) {
-   ret = -EINVAL;
-   goto out;
+   if (intr-flags  XN_ISR_ATTACHED) {
+   intr-flags = ~XN_ISR_ATTACHED;
+   xnintr_irq_detach(intr);
+   stat_counter_dec();
}
 
-   intr-flags = ~XN_ISR_ATTACHED;
-   xnintr_irq_detach(intr);
-   stat_counter_dec();
-out:
xnlock_put_irqrestore(intrlock, s);
-
-   return ret;
 }
 EXPORT_SYMBOL_GPL(xnintr_detach);
 


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


[Xenomai-git] Philippe Gerum : cobalt/pod: drop the XNSTARTED bit from the thread state mask

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 11:36:22 2013 +0200

cobalt/pod: drop the XNSTARTED bit from the thread state mask

Since XNDORMANT now exclusively means never started, we don't need
the XNSTARTED bit anymore.

Strictly speaking, XNDORMANT == !XNSTARTED and conversely.

---

 include/cobalt/uapi/kernel/thread.h |   29 ++---
 kernel/cobalt/pod.c |2 +-
 kernel/cobalt/sched.c   |4 ++--
 kernel/cobalt/shadow.c  |4 ++--
 4 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/include/cobalt/uapi/kernel/thread.h 
b/include/cobalt/uapi/kernel/thread.h
index 7913d82..069507b 100644
--- a/include/cobalt/uapi/kernel/thread.h
+++ b/include/cobalt/uapi/kernel/thread.h
@@ -35,21 +35,20 @@
 #define XNREADY   0x0008 /** Linked to the ready queue. */
 #define XNDORMANT 0x0010 /** Not started yet */
 #define XNZOMBIE  0x0020 /** Zombie thread in deletion process */
-#define XNSTARTED 0x0040 /** Thread has been started */
-#define XNMAPPED  0x0080 /** Thread is mapped to a linux task */
-#define XNRELAX   0x0100 /** Relaxed shadow thread (blocking bit) */
-#define XNMIGRATE 0x0200 /** Thread is currently migrating to another 
CPU. */
-#define XNHELD0x0400 /** Thread is held to process emergency. */
+#define XNMAPPED  0x0040 /** Thread is mapped to a linux task */
+#define XNRELAX   0x0080 /** Relaxed shadow thread (blocking bit) */
+#define XNMIGRATE 0x0100 /** Thread is currently migrating to another 
CPU. */
+#define XNHELD0x0200 /** Thread is held to process emergency. */
 
-#define XNBOOST   0x0800 /** Undergoes a PIP boost */
-#define XNDEBUG   0x1000 /** Hit a debugger breakpoint */
-#define XNLOCK0x2000 /** Holds the scheduler lock (i.e. not 
preemptible) */
-#define XNRRB 0x4000 /** Undergoes a round-robin scheduling */
-#define XNTRAPSW  0x8000 /** Trap execution mode switches */
-#define XNFPU 0x0001 /** Thread uses FPU */
-#define XNROOT0x0002 /** Root thread (that is, Linux/IDLE) */
-#define XNWEAK0x0004 /** Non real-time shadow (from the WEAK class) */
-#define XNUSER0x0008 /** Shadow thread running in userland */
+#define XNBOOST   0x0400 /** Undergoes a PIP boost */
+#define XNDEBUG   0x0800 /** Hit a debugger breakpoint */
+#define XNLOCK0x1000 /** Holds the scheduler lock (i.e. not 
preemptible) */
+#define XNRRB 0x2000 /** Undergoes a round-robin scheduling */
+#define XNTRAPSW  0x4000 /** Trap execution mode switches */
+#define XNFPU 0x8000 /** Thread uses FPU */
+#define XNROOT0x0001 /** Root thread (that is, Linux/IDLE) */
+#define XNWEAK0x0002 /** Non real-time shadow (from the WEAK class) */
+#define XNUSER0x0004 /** Shadow thread running in userland */
 
 /** @} */
 
@@ -91,7 +90,7 @@
  * 'r' - Undergoes round-robin.
  * 't' - Mode switches trapped.
  */
-#define XNTHREAD_STATE_LABELS  SWDRU...X.HbTlrt
+#define XNTHREAD_STATE_LABELS  SWDRU..X.HbTlrt
 
 /**
  * @brief Structure containing thread information.
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 0071d96..0b35cb9 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -545,7 +545,7 @@ int xnpod_start_thread(struct xnthread *thread,
}
 #endif /* CONFIG_SMP */
 
-   xnthread_set_state(thread, (attr-mode  (XNTHREAD_MODE_BITS | XNSUSP)) 
| XNSTARTED);
+   xnthread_set_state(thread, attr-mode  (XNTHREAD_MODE_BITS | XNSUSP));
thread-imode = (attr-mode  XNTHREAD_MODE_BITS);
thread-entry = attr-entry;
thread-cookie = attr-cookie;
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index c353674..342fd00 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -153,7 +153,7 @@ void xnsched_init(struct xnsched *sched, int cpu)
xntimer_set_sched(sched-htimer, sched);
sched-zombie = NULL;
 
-   attr.flags = XNROOT | XNSTARTED | XNFPU;
+   attr.flags = XNROOT | XNFPU;
attr.name = root_name;
attr.personality = generic_personality;
param.idle.prio = XNSCHED_IDLE_PRIO;
@@ -367,7 +367,7 @@ int xnsched_set_policy(struct xnthread *thread,
if (xnthread_test_state(thread, XNREADY))
xnsched_enqueue(thread);
 
-   if (xnthread_test_state(thread, XNSTARTED))
+   if (!xnthread_test_state(thread, XNDORMANT))
xnsched_set_resched(thread-sched);
 
return 0;
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index bfffef1..9efd929 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -1010,7 +1010,7 @@ int xnshadow_map_kernel(struct xnthread *thread, struct 
completion *done)
 * Make 

[Xenomai-git] Philippe Gerum : cobalt/thread: move non-critical cleanup code out of critical section

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 14:29:34 2013 +0200

cobalt/thread: move non-critical cleanup code out of critical section

Since the thread cleanup code can only run on behalf of the root
domain, and only from the exiting context, we may do a lot of
housekeeping locklessly.

Remove those fully private cleanups from the nklocked section, which
should help reducing the overall latency upon thread exit.

---

 include/cobalt/kernel/thread.h |2 +-
 kernel/cobalt/pod.c|   31 ---
 kernel/cobalt/shadow.c |2 +-
 kernel/cobalt/thread.c |4 +---
 4 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 28b4296..191c24e 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -324,7 +324,7 @@ void xnthread_init_shadow_tcb(struct xnthread *thread,
 
 void xnthread_init_root_tcb(struct xnthread *thread);
 
-void xnthread_cleanup(struct xnthread *thread);
+void xnthread_deregister(struct xnthread *thread);
 
 char *xnthread_format_status(unsigned long status, char *buf, int size);
 
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 3fd270d..5d911af 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -654,9 +654,6 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
 {
struct xnsched *sched = thread-sched;
 
-   trace_mark(xn_nucleus, thread_cleanup, thread %p thread_name %s,
-  thread, xnthread_name(thread));
-
list_del(thread-glink);
nkpod-nrthreads--;
xnvfile_touch_tag(nkpod-threadlist_tag);
@@ -667,16 +664,8 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
xnthread_clear_state(thread, XNREADY);
}
 
-   xntimer_destroy(thread-rtimer);
-   xntimer_destroy(thread-ptimer);
-   xntimer_destroy(thread-rrbtimer);
thread-idtag = 0;
 
-   if (thread-selector) {
-   xnselector_destroy(thread-selector);
-   thread-selector = NULL;
-   }
-
if (xnthread_test_state(thread, XNPEND))
xnsynch_forget_sleeper(thread);
 
@@ -695,12 +684,9 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
return;
 
xnsched_forget(thread);
-   xnthread_cleanup(thread);
+   xnthread_deregister(thread);
/* Finalize last since this incurs releasing the TCB. */
xnshadow_finalize(thread);
-
-   if (xnthread_test_state(sched-curr, XNROOT))
-   xnfreesync();
 }
 
 void __xnpod_cleanup_thread(struct xnthread *thread)
@@ -708,9 +694,24 @@ void __xnpod_cleanup_thread(struct xnthread *thread)
spl_t s;
 
XENO_BUGON(NUCLEUS, !ipipe_root_p);
+
+   trace_mark(xn_nucleus, thread_cleanup, thread %p thread_name %s,
+  thread, xnthread_name(thread));
+
+   xntimer_destroy(thread-rtimer);
+   xntimer_destroy(thread-ptimer);
+   xntimer_destroy(thread-rrbtimer);
+
+   if (thread-selector) {
+   xnselector_destroy(thread-selector);
+   thread-selector = NULL;
+   }
+
xnlock_get_irqsave(nklock, s);
cleanup_thread(thread);
+   xnfreesync();
xnlock_put_irqrestore(nklock, s);
+
wake_up(nkjoinq);
 }
 
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 11776ec..4d0b761 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -1025,7 +1025,7 @@ void xnshadow_finalize(struct xnthread *thread)
 {
struct xnsys_ppd *sys_ppd;
 
-   trace_mark(xn_nucleus, shadow_unmap,
+   trace_mark(xn_nucleus, shadow_finalize,
   thread %p thread_name %s pid %d,
   thread, xnthread_name(thread), xnthread_host_pid(thread));
 
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 5d268a2..4e0ae56 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -229,10 +229,8 @@ void xnthread_init_root_tcb(struct xnthread *thread)
xnarch_init_root_tcb(tcb);
 }
 
-void xnthread_cleanup(struct xnthread *thread)
+void xnthread_deregister(struct xnthread *thread)
 {
-   /* Does not wreck the TCB, only releases the held resources. */
-
if (thread-registry.handle != XN_NO_HANDLE)
xnregistry_remove(thread-registry.handle);
 


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


[Xenomai-git] Philippe Gerum : cobalt/pod: drop PEXEC and FATAL condition bits

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 15:32:14 2013 +0200

cobalt/pod: drop PEXEC and FATAL condition bits

XNPEXEC makes no sense anymore as it used to protect our kernel
handlers from running when no real-time services are available yet.

It turns out that the Cobalt core is now initialized early, and those
handlers are not even installed until the interrupt pipeline is
requested to forward the trap and syscall events, which only
happens...after the system has been initialized.

Finally, exposing the fatal bit as a global state flag, only to test
it within the panic handler was quite overkill.

---

 include/cobalt/kernel/assert.h|4 +-
 include/cobalt/kernel/pod.h   |   14 +-
 kernel/cobalt/arch/blackfin/machine.c |   19 ++-
 kernel/cobalt/pod.c   |   46 +
 kernel/cobalt/registry.c  |3 -
 kernel/cobalt/shadow.c|   92 
 kernel/cobalt/timer.c |7 +--
 kernel/cobalt/vfile.c |8 ---
 8 files changed, 59 insertions(+), 134 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index 6bd00bd..c54b824 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -46,6 +46,8 @@
 #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0
 #endif /* CONFIG_XENO_OPT_DEBUG_NUCLEUS */
 
-void xnpod_fatal(const char *format, ...);
+extern void (*nkpanic)(const char *format, ...);
+
+#define xnpod_fatal(__fmt, __args...) nkpanic(__fmt, ##__args)
 
 #endif /* !_COBALT_KERNEL_ASSERT_H */
diff --git a/include/cobalt/kernel/pod.h b/include/cobalt/kernel/pod.h
index c5b4290..d7e0d94 100644
--- a/include/cobalt/kernel/pod.h
+++ b/include/cobalt/kernel/pod.h
@@ -36,9 +36,7 @@
 #include cobalt/kernel/lock.h
 
 /* Pod status flags */
-#define XNFATAL  0x0001/* Fatal error in progress */
-#define XNPEXEC  0x0002/* Pod is active (a skin is attached) */
-#define XNCLKLK  0x0004/* All clocks locked */
+#define XNCLKLK  0x0001/* All clocks locked */
 
 #define XNPOD_NORMAL_EXIT  0x0
 #define XNPOD_FATAL_EXIT   0x1
@@ -102,16 +100,6 @@ static inline struct xnsched *xnpod_current_sched(void)
return __this_cpu_ptr(nksched);
 }
 
-static inline int xnpod_active_p(void)
-{
-   return nkpod-status  XNPEXEC;
-}
-
-static inline int xnpod_fatal_p(void)
-{
-   return nkpod-status  XNFATAL;
-}
-
 static inline int xnpod_interrupt_p(void)
 {
return xnpod_current_sched()-lflags  XNINIRQ;
diff --git a/kernel/cobalt/arch/blackfin/machine.c 
b/kernel/cobalt/arch/blackfin/machine.c
index ef279d6..bdaec5b 100644
--- a/kernel/cobalt/arch/blackfin/machine.c
+++ b/kernel/cobalt/arch/blackfin/machine.c
@@ -28,8 +28,23 @@ static unsigned long mach_blackfin_calibrate(void)
 
 static void schedule_deferred(void)
 {
-   if (xnpod_active_p())
-   xnpod_schedule();
+   /*
+* We have a small race window which turns out to be
+* innocuous, i.e.:
+*
+* mach_setup() ...
+*IRQ/syscall
+*= irq_tail_hook
+*   = xnpod_schedule()
+*...
+* xnpod_init()
+*
+* in which case, we would call xnpod_schedule() for a not yet
+* initialized system. However, we would be covered by the
+* check for XNSCHED in xnpod_schedule(), which basically
+* makes this call a nop.
+*/
+   xnpod_schedule();
 }
 
 static int mach_blackfin_init(void)
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 5d911af..7bb8d07 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -36,6 +36,7 @@
 #include linux/kallsyms.h
 #include linux/ptrace.h
 #include linux/sched.h
+#include linux/kernel.h
 #include linux/wait.h
 #include cobalt/kernel/pod.h
 #include cobalt/kernel/timer.h
@@ -55,6 +56,9 @@
 xnpod_t nkpod_struct;
 EXPORT_SYMBOL_GPL(nkpod_struct);
 
+void (*nkpanic)(const char *format, ...) = panic;
+EXPORT_SYMBOL_GPL(nkpanic);
+
 unsigned long nktimerlat;
 
 cpumask_t nkaffinity = XNPOD_ALL_CPUS;
@@ -133,11 +137,12 @@ static inline void __xnpod_switch_fpu(struct xnsched 
*sched)
 
 #endif /* !CONFIG_XENO_HW_FPU */
 
-void xnpod_fatal(const char *format, ...)
+static void fatal(const char *format, ...)
 {
static char msg_buf[1024];
struct xnthread *thread;
struct xnsched *sched;
+   static int oopsed;
char pbuf[16];
xnticks_t now;
unsigned cpu;
@@ -150,15 +155,15 @@ void xnpod_fatal(const char *format, ...)
 
xnlock_get_irqsave(nklock, s);
 
+   if (oopsed)
+   goto out;
+
+   oopsed = 1;
va_start(ap, format);
vsnprintf(msg_buf, sizeof(msg_buf), format, ap);

[Xenomai-git] Philippe Gerum : cobalt/intr: turn irq statistics into per-cpu data

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

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Jul 30 21:55:43 2013 +0200

cobalt/intr: turn irq statistics into per-cpu data

---

 include/cobalt/kernel/intr.h |   50 +
 kernel/cobalt/intr.c |  122 +-
 kernel/cobalt/pod.c  |4 +-
 3 files changed, 102 insertions(+), 74 deletions(-)

diff --git a/include/cobalt/kernel/intr.h b/include/cobalt/kernel/intr.h
index cd14a1e..835f7fd 100644
--- a/include/cobalt/kernel/intr.h
+++ b/include/cobalt/kernel/intr.h
@@ -46,32 +46,36 @@ typedef int (*xnisr_t)(struct xnintr *intr);
 
 typedef void (*xniack_t)(unsigned irq, void *arg);
 
-typedef struct xnintr {
+struct xnirqstat {
+   /* ! Number of handled receipts since attachment. */
+   xnstat_counter_t hits;
+   /* ! Runtime accounting entity */
+   xnstat_exectime_t account;
+   /* ! Accumulated accounting entity */
+   xnstat_exectime_t sum;
+};
 
+typedef struct xnintr {
 #ifdef CONFIG_XENO_OPT_SHIRQ
-struct xnintr *next; /* ! Next object in the IRQ-sharing chain. */
+   /* ! Next object in the IRQ-sharing chain. */
+   struct xnintr *next;
 #endif /* CONFIG_XENO_OPT_SHIRQ */
-
-unsigned unhandled;/* ! Number of consequent unhandled interrupts 
*/
-
-xnisr_t isr;   /* ! Interrupt service routine. */
-
-void *cookie;  /* ! User-defined cookie value. */
-
-int flags; /* ! Creation flags. */
-
-unsigned irq;  /* ! IRQ number. */
-
-xniack_t iack; /* ! Interrupt acknowledge routine. */
-
-const char *name;  /* ! Symbolic name. */
-
-struct {
-   xnstat_counter_t hits;/* ! Number of handled receipts since 
attachment. */
-   xnstat_exectime_t account; /* ! Runtime accounting entity */
-   xnstat_exectime_t sum; /* ! Accumulated accounting entity */
-} stat[NR_CPUS];
-
+   /* ! Number of consequent unhandled interrupts */
+   unsigned int unhandled;
+   /* ! Interrupt service routine. */
+   xnisr_t isr;
+   /* ! User-defined cookie value. */
+   void *cookie;
+   /* ! Creation flags. */
+   int flags;
+   /* ! IRQ number. */
+   unsigned int irq;
+   /* ! Interrupt acknowledge routine. */
+   xniack_t iack;
+   /* ! Symbolic name. */
+   const char *name;
+   /* ! Statistics. */
+   struct xnirqstat *stats;
 } xnintr_t;
 
 typedef struct xnintr_iterator {
diff --git a/kernel/cobalt/intr.c b/kernel/cobalt/intr.c
index 37851ff..7625fb4 100644
--- a/kernel/cobalt/intr.c
+++ b/kernel/cobalt/intr.c
@@ -51,35 +51,38 @@ static int xnintr_list_rev;  /* Modification counter of 
xnintr list */
  * This guarantees that module.c::stat_seq_open() won't get
  * an up-to-date xnintr_list_rev and old xnintr_count. */
 
-static inline void xnintr_stat_counter_inc(void)
+static inline void stat_counter_inc(void)
 {
xnintr_count++;
smp_mb();
xnintr_list_rev++;
 }
 
-static inline void xnintr_stat_counter_dec(void)
+static inline void stat_counter_dec(void)
 {
xnintr_count--;
smp_mb();
xnintr_list_rev++;
 }
 
-static inline void xnintr_sync_stat_references(xnintr_t *intr)
+static inline void sync_stat_references(struct xnintr *intr)
 {
+   struct xnirqstat *statp;
+   struct xnsched *sched;
int cpu;
 
for_each_online_cpu(cpu) {
-   struct xnsched *sched = xnpod_sched_slot(cpu);
+   sched = xnpod_sched_slot(cpu);
+   statp = per_cpu_ptr(intr-stats, cpu);
/* Synchronize on all dangling references to go away. */
-   while (sched-current_account == intr-stat[cpu].account)
+   while (sched-current_account == statp-account)
cpu_relax();
}
 }
 #else
-static inline void xnintr_stat_counter_inc(void) {}
-static inline void xnintr_stat_counter_dec(void) {}
-static inline void xnintr_sync_stat_references(xnintr_t *intr) {}
+static inline void stat_counter_inc(void) {}
+static inline void stat_counter_dec(void) {}
+static inline void sync_stat_references(xnintr_t *intr) {}
 #endif /* CONFIG_XENO_OPT_STATS */
 
 static void xnintr_irq_handler(unsigned irq, void *cookie);
@@ -100,10 +103,12 @@ void xnintr_core_clock_handler(void)
 {
struct xnsched *sched = xnpod_current_sched();
int cpu  __maybe_unused = xnsched_cpu(sched);
+   struct xnirqstat *statp;
xnstat_exectime_t *prev;
 
-   prev = xnstat_exectime_switch(sched, nktimer.stat[cpu].account);
-   xnstat_counter_inc(nktimer.stat[cpu].hits);
+   statp = __this_cpu_ptr(nktimer.stats);
+   prev = xnstat_exectime_switch(sched, statp-account);
+   xnstat_counter_inc(statp-hits);
 
trace_mark(xn_nucleus, irq_enter, irq %u,
   

[Xenomai-git] Philippe Gerum : copperplate: move init settings to copperplate/init.h

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

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Aug  8 09:36:38 2013 +0200

copperplate: move init settings to copperplate/init.h

---

 include/copperplate/init.h|   14 ++
 lib/copperplate/heapobj-pshared.c |1 +
 lib/copperplate/heapobj-tlsf.c|1 +
 lib/copperplate/init.c|   16 ++--
 lib/copperplate/internal.c|   13 +
 lib/copperplate/internal.h|   14 --
 lib/copperplate/registry.c|1 +
 lib/copperplate/traceobj.c|1 +
 8 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/include/copperplate/init.h b/include/copperplate/init.h
index 03e9231..69e5672 100644
--- a/include/copperplate/init.h
+++ b/include/copperplate/init.h
@@ -20,9 +20,21 @@
 #define _COPPERPLATE_INIT_H
 
 #include stdarg.h
+#include sched.h
 #include copperplate/trace.h
 #include copperplate/list.h
 
+struct coppernode {
+   unsigned int mem_pool;
+   const char *session_label;
+   const char *registry_root;
+   cpu_set_t cpu_affinity;
+   int no_mlock;
+   int no_registry;
+   int reset_session;
+   int silent_mode;
+};
+
 struct option;
 
 struct copperskin {
@@ -56,4 +68,6 @@ const char *symerror(int errnum);
 }
 #endif
 
+extern struct coppernode __node_info;
+
 #endif /* _COPPERPLATE_INIT_H */
diff --git a/lib/copperplate/heapobj-pshared.c 
b/lib/copperplate/heapobj-pshared.c
index b8308e0..d283bdc 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -39,6 +39,7 @@
 #include copperplate/hash.h
 #include copperplate/heapobj.h
 #include copperplate/debug.h
+#include copperplate/init.h
 #include internal.h
 
 #define HOBJ_PAGE_SHIFT9   /* 2^9 = 512 bytes */
diff --git a/lib/copperplate/heapobj-tlsf.c b/lib/copperplate/heapobj-tlsf.c
index d824a81..e4ae0dd 100644
--- a/lib/copperplate/heapobj-tlsf.c
+++ b/lib/copperplate/heapobj-tlsf.c
@@ -21,6 +21,7 @@
 #include stdint.h
 #include copperplate/heapobj.h
 #include copperplate/debug.h
+#include copperplate/init.h
 #include tlsf/tlsf.h
 #include internal.h
 
diff --git a/lib/copperplate/init.c b/lib/copperplate/init.c
index 98139f2..de17f47 100644
--- a/lib/copperplate/init.c
+++ b/lib/copperplate/init.c
@@ -39,6 +39,18 @@
 #include copperplate/debug.h
 #include internal.h
 
+struct coppernode __node_info = {
+   .mem_pool = 1024 * 1024, /* Default, 1Mb. */
+   .session_label = anon,
+   .registry_root = /mnt/xenomai,
+   .no_mlock = 0,
+   .no_registry = 0,
+   .reset_session = 0,
+   .silent_mode = 0,
+};
+
+pid_t __node_id;
+
 struct timespec __init_date;
 
 static DEFINE_PRIVATE_LIST(skins);
@@ -182,8 +194,8 @@ static int collect_cpu_affinity(const char *cpu_list)
ret = sched_setaffinity(0, sizeof(__node_info.cpu_affinity),
__node_info.cpu_affinity);
if (ret) {
-   warning(no valid CPU in affinity list '%s', cpu_list);
-   return __bt(-ret);
+   warning(invalid CPU in affinity list '%s', cpu_list);
+   return __bt(-errno);
}
 
return 0;
diff --git a/lib/copperplate/internal.c b/lib/copperplate/internal.c
index 865ba85..12daf45 100644
--- a/lib/copperplate/internal.c
+++ b/lib/copperplate/internal.c
@@ -28,20 +28,9 @@
 #include linux/unistd.h
 #include copperplate/clockobj.h
 #include copperplate/threadobj.h
+#include copperplate/init.h
 #include internal.h
 
-struct coppernode __node_info = {
-   .mem_pool = 1024 * 1024, /* Default, 1Mb. */
-   .session_label = anon,
-   .registry_root = /mnt/xenomai,
-   .no_mlock = 0,
-   .no_registry = 0,
-   .reset_session = 0,
-   .silent_mode = 0,
-};
-
-pid_t __node_id;
-
 pthread_mutex_t __printlock;
 
 pid_t copperplate_get_tid(void)
diff --git a/lib/copperplate/internal.h b/lib/copperplate/internal.h
index 72e8982..5a63b10 100644
--- a/lib/copperplate/internal.h
+++ b/lib/copperplate/internal.h
@@ -28,18 +28,6 @@
 #include copperplate/list.h
 #include copperplate/heapobj.h
 
-struct coppernode {
-   unsigned int mem_pool;
-   const char *session_label;
-   const char *registry_root;
-   cpu_set_t cpu_affinity;
-   /* No bitfield below, we have to take address of thoses. */
-   int no_mlock;
-   int no_registry;
-   int reset_session;
-   int silent_mode;
-};
-
 #define HOBJ_MINLOG23
 #define HOBJ_MAXLOG222 /* Must hold pagemap::bcount objects */
 #define HOBJ_NBUCKETS   (HOBJ_MAXLOG2 - HOBJ_MINLOG2 + 2)
@@ -75,8 +63,6 @@ struct corethread_attributes {
 
 extern pid_t __node_id;
 
-extern struct coppernode __node_info;
-
 extern struct timespec __init_date;
 
 extern const char *dashes;
diff --git a/lib/copperplate/registry.c 

[Xenomai-git] Philippe Gerum : cobalt/thread, posix: clearly distinguish exit vs finalization handlers

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 12:25:20 2013 +0200

cobalt/thread, posix: clearly distinguish exit vs finalization handlers

The exit handler is called locklessly with interrupts enabled, for
dropping all resources allocated by the personality, except the TCB
which may still be referenced for accessing resources maintained by
the Cobalt core.

The finalization handler shall drop the TCB and may therefore assume
that no further reference to this memory may be done afterwards from
the Cobalt core.

---

 include/cobalt/kernel/shadow.h |4 ++--
 kernel/cobalt/pod.c|4 ++--
 kernel/cobalt/posix/syscall.c  |2 +-
 kernel/cobalt/posix/thread.c   |   35 ---
 kernel/cobalt/posix/thread.h   |2 +-
 kernel/cobalt/shadow.c |6 +++---
 6 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/include/cobalt/kernel/shadow.h b/include/cobalt/kernel/shadow.h
index 5afadf8..5f63d55 100644
--- a/include/cobalt/kernel/shadow.h
+++ b/include/cobalt/kernel/shadow.h
@@ -42,7 +42,7 @@ struct xnpersonality {
void (*detach_process)(struct xnshadow_ppd *ppd);
struct xnpersonality *(*map_thread)(struct xnthread *thread);
struct xnpersonality *(*exit_thread)(struct xnthread *thread);
-   struct xnpersonality *(*unmap_thread)(struct xnthread *thread);
+   struct xnpersonality *(*finalize_thread)(struct xnthread 
*thread);
} ops;
struct module *module;
 };
@@ -89,7 +89,7 @@ int xnshadow_map_user(struct xnthread *thread,
 int xnshadow_map_kernel(struct xnthread *thread,
struct completion *done);
 
-void xnshadow_unmap(struct xnthread *thread);
+void xnshadow_finalize(struct xnthread *thread);
 
 int xnshadow_harden(void);
 
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 89ba956..5ff2a9d 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -696,8 +696,8 @@ static void cleanup_thread(struct xnthread *thread) /* 
nklock held, irqs off */
 
xnsched_forget(thread);
xnthread_cleanup(thread);
-   /* Unmap last since this incurs releasing the TCB. */
-   xnshadow_unmap(thread);
+   /* Finalize last since this incurs releasing the TCB. */
+   xnshadow_finalize(thread);
 
if (xnthread_test_state(sched-curr, XNROOT))
xnfreesync();
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 84f7c53..cf8c3a9 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -365,7 +365,7 @@ struct xnpersonality cobalt_personality = {
.attach_process = cobalt_process_attach,
.detach_process = cobalt_process_detach,
.exit_thread = cobalt_thread_exit,
-   .unmap_thread = cobalt_thread_unmap,
+   .finalize_thread = cobalt_thread_finalize,
},
 };
 EXPORT_SYMBOL_GPL(cobalt_personality);
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index bd6f3f1..7caf10f 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -182,14 +182,6 @@ thread_find_local(const struct cobalt_local_hkey *hkey)
return thread;
 }
 
-static void thread_destroy(struct cobalt_thread *thread)
-{
-   list_del(thread-link);
-   xnsynch_destroy(thread-monitor_synch);
-   xnsynch_destroy(thread-sigwait);
-   xnheap_schedule_free(kheap, thread, thread-link);
-}
-
 struct cobalt_thread *cobalt_thread_find(pid_t pid) /* nklocked, IRQs off */
 {
struct global_thread_hash *gslot;
@@ -218,17 +210,20 @@ struct xnpersonality *cobalt_thread_exit(struct xnthread 
*curr)
cobalt_mark_deleted(thread);
cobalt_signal_flush(thread);
cobalt_timer_flush(thread);
+   xnsynch_destroy(thread-monitor_synch);
+   xnsynch_destroy(thread-sigwait);
 
/* We don't stack over any personality, no chaining. */
return NULL;
 }
 
-struct xnpersonality *cobalt_thread_unmap(struct xnthread *zombie) /* 
nklocked, IRQs off */
+struct xnpersonality *cobalt_thread_finalize(struct xnthread *zombie) /* 
nklocked, IRQs off */
 {
struct cobalt_thread *thread;
 
thread = container_of(zombie, struct cobalt_thread, threadbase);
-   thread_destroy(thread);
+   list_del(thread-link);
+   xnheap_schedule_free(kheap, thread, thread-link);
 
return NULL;
 }
@@ -473,24 +468,26 @@ static inline int pthread_create(struct cobalt_thread 
**thread_p, const pthread_
if (thread-attr.policy == SCHED_RR)
xnpod_set_thread_tslice(thread-threadbase, cobalt_time_slice);
 
-   xnlock_get_irqsave(nklock, s);
-   thread-container = cobalt_kqueues(0)-threadq;
-   

[Xenomai-git] Philippe Gerum : cobalt/lock: turn lock statistics into per-cpu data

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

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Jul 30 17:32:43 2013 +0200

cobalt/lock: turn lock statistics into per-cpu data

---

 include/cobalt/kernel/lock.h |3 ++-
 kernel/cobalt/debug.c|2 +-
 kernel/cobalt/lock.c |4 ++--
 kernel/cobalt/procfs.c   |4 ++--
 4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/include/cobalt/kernel/lock.h b/include/cobalt/kernel/lock.h
index d26013b..a019100 100644
--- a/include/cobalt/kernel/lock.h
+++ b/include/cobalt/kernel/lock.h
@@ -25,6 +25,7 @@
 #define _COBALT_KERNEL_LOCK_H
 
 #include linux/ipipe.h
+#include linux/percpu.h
 #include cobalt/kernel/assert.h
 
 /** \addtogroup lock
@@ -95,7 +96,7 @@ int xnlock_dbg_release(struct xnlock *lock,
 const char *file, int line,
 const char *function);
 
-extern struct xnlockinfo xnlock_stats[];
+DECLARE_PER_CPU(struct xnlockinfo, xnlock_stats);
 
 #else /* !XENO_DEBUG(XNLOCK) */
 
diff --git a/kernel/cobalt/debug.c b/kernel/cobalt/debug.c
index b2540e3..c2afc2f 100644
--- a/kernel/cobalt/debug.c
+++ b/kernel/cobalt/debug.c
@@ -583,7 +583,7 @@ int xnlock_dbg_release(struct xnlock *lock,
 
lock_time = xnclock_read_raw(nkclock) - lock-lock_date;
cpu = ipipe_processor_id();
-   stats = xnlock_stats[cpu];
+   stats = per_cpu(xnlock_stats, cpu);
 
if (lock-file == NULL) {
lock-file = ??;
diff --git a/kernel/cobalt/lock.c b/kernel/cobalt/lock.c
index 7e43cd3..bc9077e 100644
--- a/kernel/cobalt/lock.c
+++ b/kernel/cobalt/lock.c
@@ -55,8 +55,8 @@ EXPORT_SYMBOL_GPL(__xnlock_spin);
 #endif /* CONFIG_SMP || XENO_DEBUG(XNLOCK) */
 
 #if XENO_DEBUG(XNLOCK)
-struct xnlockinfo xnlock_stats[NR_CPUS];
-EXPORT_SYMBOL_GPL(xnlock_stats);
+DEFINE_PER_CPU(struct xnlockinfo, xnlock_stats);
+EXPORT_PER_CPU_SYMBOL(xnlock_stats);
 #endif
 
 /*@}*/
diff --git a/kernel/cobalt/procfs.c b/kernel/cobalt/procfs.c
index 9600ccc..dd1c32b 100644
--- a/kernel/cobalt/procfs.c
+++ b/kernel/cobalt/procfs.c
@@ -39,7 +39,7 @@ static int lock_vfile_show(struct xnvfile_regular_iterator 
*it, void *data)
for_each_online_cpu(cpu) {
 
xnlock_get_irqsave(nklock, s);
-   lockinfo = xnlock_stats[cpu];
+   lockinfo = per_cpu(xnlock_stats, cpu);
xnlock_put_irqrestore(nklock, s);
 
if (cpu  0)
@@ -76,7 +76,7 @@ static ssize_t lock_vfile_store(struct xnvfile_input *input)
 
for_each_online_cpu(cpu) {
xnlock_get_irqsave(nklock, s);
-   memset(xnlock_stats[cpu], '\0', sizeof(xnlock_stats[cpu]));
+   memset(per_cpu(xnlock_stats, cpu), '\0', sizeof(struct 
xnlockinfo));
xnlock_put_irqrestore(nklock, s);
}
 


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


[Xenomai-git] Philippe Gerum : cobalt/posix: pthread_make_periodic_np: fix return code for bad clock_id

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 6602ed82bfe80d0ffd6e996c570d2c7a501eb417
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=6602ed82bfe80d0ffd6e996c570d2c7a501eb417

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Jul 27 12:28:27 2013 +0200

cobalt/posix: pthread_make_periodic_np: fix return code for bad clock_id

---

 kernel/cobalt/posix/thread.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index adff7f2..17ffad1 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -517,7 +517,7 @@ static inline int pthread_create(struct cobalt_thread 
**thread_p, const pthread_
  * @return an error number if:
  * - ESRCH, @a thread is invalid;
  * - ETIMEDOUT, the start time has already passed.
- * - EOPNOTSUPP, the specified clock is unsupported;
+ * - EINVAL, the specified clock is unsupported;
  *
  * Rescheduling: always, until the @a starttp start time has been reached.
  */
@@ -534,7 +534,7 @@ static inline int pthread_make_periodic_np(struct 
cobalt_thread *thread,
if (clock_id != CLOCK_MONOTONIC 
clock_id != CLOCK_MONOTONIC_RAW 
clock_id != CLOCK_REALTIME)
-   return EOPNOTSUPP;
+   return -EINVAL;
 
xnlock_get_irqsave(nklock, s);
 


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


[Xenomai-git] Philippe Gerum : cobalt/thread, posix: clearly distinguish exit vs finalization handlers

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 439eb3f33b19a2e7e5064e79777de4c23474cbf1
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=439eb3f33b19a2e7e5064e79777de4c23474cbf1

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 12:25:20 2013 +0200

cobalt/thread, posix: clearly distinguish exit vs finalization handlers

The exit handler is called locklessly with interrupts enabled, for
dropping all resources allocated by the personality, except the TCB
which may still be referenced for accessing resources maintained by
the Cobalt core.

The finalization handler shall drop the TCB and may therefore assume
that no further reference to this memory may be done afterwards from
the Cobalt core.

---

 include/cobalt/kernel/shadow.h |4 ++--
 kernel/cobalt/pod.c|4 ++--
 kernel/cobalt/posix/syscall.c  |2 +-
 kernel/cobalt/posix/thread.c   |   35 ---
 kernel/cobalt/posix/thread.h   |2 +-
 kernel/cobalt/shadow.c |6 +++---
 6 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/include/cobalt/kernel/shadow.h b/include/cobalt/kernel/shadow.h
index 5afadf8..5f63d55 100644
--- a/include/cobalt/kernel/shadow.h
+++ b/include/cobalt/kernel/shadow.h
@@ -42,7 +42,7 @@ struct xnpersonality {
void (*detach_process)(struct xnshadow_ppd *ppd);
struct xnpersonality *(*map_thread)(struct xnthread *thread);
struct xnpersonality *(*exit_thread)(struct xnthread *thread);
-   struct xnpersonality *(*unmap_thread)(struct xnthread *thread);
+   struct xnpersonality *(*finalize_thread)(struct xnthread 
*thread);
} ops;
struct module *module;
 };
@@ -89,7 +89,7 @@ int xnshadow_map_user(struct xnthread *thread,
 int xnshadow_map_kernel(struct xnthread *thread,
struct completion *done);
 
-void xnshadow_unmap(struct xnthread *thread);
+void xnshadow_finalize(struct xnthread *thread);
 
 int xnshadow_harden(void);
 
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 89ba956..5ff2a9d 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -696,8 +696,8 @@ static void cleanup_thread(struct xnthread *thread) /* 
nklock held, irqs off */
 
xnsched_forget(thread);
xnthread_cleanup(thread);
-   /* Unmap last since this incurs releasing the TCB. */
-   xnshadow_unmap(thread);
+   /* Finalize last since this incurs releasing the TCB. */
+   xnshadow_finalize(thread);
 
if (xnthread_test_state(sched-curr, XNROOT))
xnfreesync();
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 84f7c53..cf8c3a9 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -365,7 +365,7 @@ struct xnpersonality cobalt_personality = {
.attach_process = cobalt_process_attach,
.detach_process = cobalt_process_detach,
.exit_thread = cobalt_thread_exit,
-   .unmap_thread = cobalt_thread_unmap,
+   .finalize_thread = cobalt_thread_finalize,
},
 };
 EXPORT_SYMBOL_GPL(cobalt_personality);
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index bd6f3f1..7caf10f 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -182,14 +182,6 @@ thread_find_local(const struct cobalt_local_hkey *hkey)
return thread;
 }
 
-static void thread_destroy(struct cobalt_thread *thread)
-{
-   list_del(thread-link);
-   xnsynch_destroy(thread-monitor_synch);
-   xnsynch_destroy(thread-sigwait);
-   xnheap_schedule_free(kheap, thread, thread-link);
-}
-
 struct cobalt_thread *cobalt_thread_find(pid_t pid) /* nklocked, IRQs off */
 {
struct global_thread_hash *gslot;
@@ -218,17 +210,20 @@ struct xnpersonality *cobalt_thread_exit(struct xnthread 
*curr)
cobalt_mark_deleted(thread);
cobalt_signal_flush(thread);
cobalt_timer_flush(thread);
+   xnsynch_destroy(thread-monitor_synch);
+   xnsynch_destroy(thread-sigwait);
 
/* We don't stack over any personality, no chaining. */
return NULL;
 }
 
-struct xnpersonality *cobalt_thread_unmap(struct xnthread *zombie) /* 
nklocked, IRQs off */
+struct xnpersonality *cobalt_thread_finalize(struct xnthread *zombie) /* 
nklocked, IRQs off */
 {
struct cobalt_thread *thread;
 
thread = container_of(zombie, struct cobalt_thread, threadbase);
-   thread_destroy(thread);
+   list_del(thread-link);
+   xnheap_schedule_free(kheap, thread, thread-link);
 
return NULL;
 }
@@ -473,24 +468,26 @@ static inline int pthread_create(struct cobalt_thread 
**thread_p, const pthread_
if (thread-attr.policy == SCHED_RR)
xnpod_set_thread_tslice(thread-threadbase, cobalt_time_slice);
 
-   xnlock_get_irqsave(nklock, s);
-   thread-container = cobalt_kqueues(0)-threadq;
-   

[Xenomai-git] Philippe Gerum : cobalt/pod: privatize inner support routines

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 93e116a86735347c3a000d79c746644a41d5cf91
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=93e116a86735347c3a000d79c746644a41d5cf91

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 15:53:52 2013 +0200

cobalt/pod: privatize inner support routines

---

 include/cobalt/kernel/pod.h |6 -
 kernel/cobalt/pod.c |  338 ++-
 kernel/cobalt/shadow.c  |   71 +-
 3 files changed, 182 insertions(+), 233 deletions(-)

diff --git a/include/cobalt/kernel/pod.h b/include/cobalt/kernel/pod.h
index d7e0d94..dd7657c 100644
--- a/include/cobalt/kernel/pod.h
+++ b/include/cobalt/kernel/pod.h
@@ -132,10 +132,6 @@ static inline int xnpod_primary_p(void)
 
 int xnpod_init(void);
 
-int xnpod_enable_timesource(void);
-
-void xnpod_disable_timesource(void);
-
 void xnpod_shutdown(int xtype);
 
 int xnpod_init_thread(struct xnthread *thread,
@@ -278,8 +274,6 @@ static inline void xnpod_testcancel_thread(void)
__xnpod_testcancel_thread(curr);
 }
 
-int xnpod_handle_exception(struct ipipe_trap_data *d);
-
 int xnpod_set_thread_periodic(struct xnthread *thread,
  xnticks_t idate,
  xntmode_t timeout_mode,
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 7bb8d07..331dcf1 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -33,7 +33,6 @@
  *@{*/
 
 #include stdarg.h
-#include linux/kallsyms.h
 #include linux/ptrace.h
 #include linux/sched.h
 #include linux/kernel.h
@@ -217,9 +216,82 @@ static void xnpod_flush_heap(struct xnheap *heap,
free_pages_exact(extaddr, extsize);
 }
 
-/*!
- * \fn int xnpod_init(void)
- * \brief Initialize the core pod.
+static int enable_timesource(void)
+{
+   struct xnsched *sched;
+   int htickval, cpu;
+   spl_t s;
+
+   trace_mark(xn_nucleus, enable_timesource, MARK_NOARGS);
+
+#ifdef CONFIG_XENO_OPT_STATS
+   /*
+* Only for statistical purpose, the timer interrupt is
+* attached by xntimer_grab_hardware().
+*/
+   xnintr_init(nktimer, [timer],
+   per_cpu(ipipe_percpu.hrtimer_irq, 0), NULL, NULL, 0);
+#endif /* CONFIG_XENO_OPT_STATS */
+
+   nkclock.wallclock_offset =
+   xnclock_get_host_time() - xnclock_read_monotonic(nkclock);
+
+   for_each_online_cpu(cpu) {
+   if (!xnarch_cpu_supported(cpu))
+   continue;
+
+   htickval = xntimer_grab_hardware(cpu);
+   if (htickval  0) {
+   while (--cpu = 0)
+   xntimer_release_hardware(cpu);
+
+   return htickval;
+   }
+
+   xnlock_get_irqsave(nklock, s);
+
+   /* If the current tick device for the target CPU is
+* periodic, we won't be called back for host tick
+* emulation. Therefore, we need to start a periodic
+* nucleus timer which will emulate the ticking for
+* that CPU, since we are going to hijack the hw clock
+* chip for managing our own system timer.
+*
+* CAUTION:
+*
+* - nucleus timers may be started only _after_ the hw
+* timer has been set up for the target CPU through a
+* call to xntimer_grab_hardware().
+*
+* - we don't compensate for the elapsed portion of
+* the current host tick, since we cannot get this
+* information easily for all CPUs except the current
+* one, and also because of the declining relevance of
+* the jiffies clocksource anyway.
+*
+* - we must not hold the nklock across calls to
+* xntimer_grab_hardware().
+*/
+
+   sched = xnpod_sched_slot(cpu);
+   if (htickval  1)
+   xntimer_start(sched-htimer, htickval, htickval, 
XN_RELATIVE);
+   else if (htickval == 1)
+   xntimer_start(sched-htimer, 0, 0, XN_RELATIVE);
+
+#if defined(CONFIG_XENO_OPT_WATCHDOG)
+   xntimer_start(sched-wdtimer, 10UL, 10UL, 
XN_RELATIVE);
+   xnsched_reset_watchdog(sched);
+#endif /* CONFIG_XENO_OPT_WATCHDOG */
+   xnlock_put_irqrestore(nklock, s);
+   }
+
+   return 0;
+}
+
+/**
+ * @fn int xnpod_init(void)
+ * @brief Initialize the core pod.
  *
  * Initializes the core interface pod which can subsequently be used
  * to start real-time activities. Once the core pod is active,
@@ -230,13 +302,25 @@ static void xnpod_flush_heap(struct xnheap *heap,
  *
  * - -ENOMEM is returned if the memory manager fails to initialize.
  *
+ * - -ENODEV is returned if a failure occurred while configuring the
+ * hardware timer.
+ *
  

[Xenomai-git] Philippe Gerum : cobalt/thread: move finalizer call out of any critical section

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 16:00:50 2013 +0200

cobalt/thread: move finalizer call out of any critical section

There is no point in calling the thread finalization handler while
holding a lock, since it is supposed to release the TCB to some
allocator, which may incur some work.

Besides, the thread has entered an innocuous state long ago before the
finalizer is eventually called, so there is nothing to protect in its
TCB at this point.

Finalizers should do proper locking locally if need be.

---

 kernel/cobalt/pod.c  |6 +++---
 kernel/cobalt/posix/thread.c |6 +++---
 kernel/cobalt/shadow.c   |2 --
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 331dcf1..d90a2f6 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -782,8 +782,6 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
 
xnsched_forget(thread);
xnthread_deregister(thread);
-   /* Finalize last since this incurs releasing the TCB. */
-   xnshadow_finalize(thread);
 }
 
 void __xnpod_cleanup_thread(struct xnthread *thread)
@@ -806,9 +804,11 @@ void __xnpod_cleanup_thread(struct xnthread *thread)
 
xnlock_get_irqsave(nklock, s);
cleanup_thread(thread);
-   xnfreesync();
xnlock_put_irqrestore(nklock, s);
 
+   /* Finalize last since this incurs releasing the TCB. */
+   xnshadow_finalize(thread);
+
wake_up(nkjoinq);
 }
 
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 7caf10f..ac00826 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -212,18 +212,18 @@ struct xnpersonality *cobalt_thread_exit(struct xnthread 
*curr)
cobalt_timer_flush(thread);
xnsynch_destroy(thread-monitor_synch);
xnsynch_destroy(thread-sigwait);
+   list_del(thread-link);
 
/* We don't stack over any personality, no chaining. */
return NULL;
 }
 
-struct xnpersonality *cobalt_thread_finalize(struct xnthread *zombie) /* 
nklocked, IRQs off */
+struct xnpersonality *cobalt_thread_finalize(struct xnthread *zombie)
 {
struct cobalt_thread *thread;
 
thread = container_of(zombie, struct cobalt_thread, threadbase);
-   list_del(thread-link);
-   xnheap_schedule_free(kheap, thread, thread-link);
+   xnfree(thread);
 
return NULL;
 }
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 4d6b9eb..d43753f 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -1032,8 +1032,6 @@ void xnshadow_finalize(struct xnthread *thread)
 
xnthread_run_handler(thread, finalize_thread);
 
-   xnthread_clear_state(thread, XNMAPPED);
-
if (xnthread_test_state(thread, XNUSER)) {
sys_ppd = xnsys_ppd_get(0);
atomic_dec(sys_ppd-refcnt);


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


[Xenomai-git] Philippe Gerum : cobalt/sched: drop delayed thread cleanup via zombie state transition

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 11:59:30 2013 +0200

cobalt/sched: drop delayed thread cleanup via zombie state transition

Since Xenomai thread deletion now always involves a self-exit from
secondary mode, possibly after a pending cancellation request is
noticed, there is no way a thread could self-delete from primary mode
anymore.

For this reason, delaying resource cleanup until the exiting thread
schedules out from xnpod_schedule() becomes pointless, since it must
have done so earlier, when leaving primary mode prior to running
do_exit() and the taskexit handler. At this point, the exiting thread
runs in mere linux context, and may release any Xenomai-specific
resource.

We drop the mechanism for delaying thread finalization upon
self-deletion, removing all zombie state hooks in the same move.

---

 include/cobalt/kernel/sched.h |   68 +---
 kernel/cobalt/lock.c  |2 +-
 kernel/cobalt/pod.c   |   26 ---
 kernel/cobalt/sched.c |   44 +--
 kernel/cobalt/shadow.c|1 -
 5 files changed, 45 insertions(+), 96 deletions(-)

diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index be3f2c5..402c385 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -55,51 +55,65 @@ struct xnsched_rt {
  * \brief Scheduling information structure.
  */
 
-typedef struct xnsched {
-
-   unsigned long status;   /*! Scheduler specific status bitmask. 
*/
-   unsigned long lflags;   /*! Scheduler specific local flags 
bitmask. */
-   struct xnthread *curr;  /*! Current thread. */
+struct xnsched {
+   /*! Scheduler specific status bitmask. */
+   unsigned long status;
+   /*! Scheduler specific local flags bitmask. */
+   unsigned long lflags;
+   /*! Current thread. */
+   struct xnthread *curr;
 #ifdef CONFIG_SMP
+   /*! Owner CPU id. */
int cpu;
-   cpumask_t resched;  /*! Mask of CPUs needing rescheduling. 
*/
+   /*! Mask of CPUs needing rescheduling. */
+   cpumask_t resched;
 #endif
-   struct xnsched_rt rt;   /*! Context of built-in real-time 
class. */
+   /*! Context of built-in real-time class. */
+   struct xnsched_rt rt;
 #ifdef CONFIG_XENO_OPT_SCHED_WEAK
-   struct xnsched_weak weak;   /*! Context of weak scheduling class. 
*/
+   /*! Context of weak scheduling class. */
+   struct xnsched_weak weak;
 #endif
 #ifdef CONFIG_XENO_OPT_SCHED_TP
-   struct xnsched_tp tp;   /*! Context of TP class. */
+   /*! Context of TP class. */
+   struct xnsched_tp tp;
 #endif
 #ifdef CONFIG_XENO_OPT_SCHED_SPORADIC
-   struct xnsched_sporadic pss;/*! Context of sporadic scheduling 
class. */
+   /*! Context of sporadic scheduling class. */
+   struct xnsched_sporadic pss;
 #endif
-   volatile unsigned inesting; /*! Interrupt nesting level. */
-   struct xntimer htimer;  /*! Host timer. */
-   struct xnthread *zombie;
-   struct xnthread rootcb; /*! Root thread control block. */
+   /*! Interrupt nesting level. */
+   volatile unsigned inesting;
+   /*! Host timer. */
+   struct xntimer htimer;
+   /*! Root thread control block. */
+   struct xnthread rootcb;
 #ifdef CONFIG_XENO_HW_UNLOCKED_SWITCH
struct xnthread *last;
 #endif
 #ifdef CONFIG_XENO_HW_FPU
-   struct xnthread *fpuholder; /*! Thread owning the current FPU 
context. */
+   /*! Thread owning the current FPU context. */
+   struct xnthread *fpuholder;
 #endif
 #ifdef CONFIG_XENO_OPT_WATCHDOG
-   struct xntimer wdtimer; /*! Watchdog timer object. */
-   int wdcount;/*! Watchdog tick count. */
+   /*! Watchdog timer object. */
+   struct xntimer wdtimer;
+   /*! Watchdog tick count. */
+   int wdcount;
 #endif
 #ifdef CONFIG_XENO_OPT_STATS
-   xnticks_t last_account_switch;  /*! Last account switch date (ticks). 
*/
-   xnstat_exectime_t *current_account; /*! Currently active account */
+   /*! Last account switch date (ticks). */
+   xnticks_t last_account_switch;
+   /*! Currently active account */
+   xnstat_exectime_t *current_account;
 #endif
-} xnsched_t;
+};
 
 DECLARE_PER_CPU(struct xnsched, nksched);
 
 union xnsched_policy_param;
 
 struct xnsched_class {
-
void (*sched_init)(struct xnsched *sched);
void (*sched_enqueue)(struct xnthread *thread);
void (*sched_dequeue)(struct xnthread *thread);
@@ -156,7 +170,7 @@ static inline int xnsched_resched_p(struct xnsched *sched)
 /* Set resched flag for the given scheduler. */
 #ifdef CONFIG_SMP
 

[Xenomai-git] Philippe Gerum : cobalt/signal: export missing symbols

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 4ef36896628580479b6b6fb19287d93303ce3673
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=4ef36896628580479b6b6fb19287d93303ce3673

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Jul 30 16:04:53 2013 +0200

cobalt/signal: export missing symbols

---

 kernel/cobalt/posix/signal.c |5 +
 kernel/cobalt/posix/thread.c |1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index 29bca16..a3d443d 100644
--- a/kernel/cobalt/posix/signal.c
+++ b/kernel/cobalt/posix/signal.c
@@ -64,6 +64,7 @@ int cobalt_signal_deliver(struct cobalt_thread *thread,
 
return 1;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_deliver);
 
 int cobalt_signal_send(struct cobalt_thread *thread,
   struct cobalt_sigpending *sigp)
@@ -103,6 +104,7 @@ int cobalt_signal_send(struct cobalt_thread *thread,
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_send);
 
 int cobalt_signal_send_pid(pid_t pid, struct cobalt_sigpending *sigp)
 {  /* nklocked, IRQs off */
@@ -114,6 +116,7 @@ int cobalt_signal_send_pid(pid_t pid, struct 
cobalt_sigpending *sigp)
 
return -ESRCH;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_send_pid);
 
 int cobalt_signal_deliver_pid(pid_t pid, struct cobalt_sigpending *sigp)
 {  /* nklocked, IRQs off */
@@ -125,6 +128,7 @@ int cobalt_signal_deliver_pid(pid_t pid, struct 
cobalt_sigpending *sigp)
 
return -ESRCH;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_deliver_pid);
 
 struct cobalt_sigpending *cobalt_signal_alloc(void)
 {  /* nklocked, IRQs off */
@@ -138,6 +142,7 @@ struct cobalt_sigpending *cobalt_signal_alloc(void)
 
return sigp;
 }
+EXPORT_SYMBOL_GPL(cobalt_signal_alloc);
 
 void cobalt_signal_flush(struct cobalt_thread *thread)
 {
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 7dead4b..bd6f3f1 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -203,6 +203,7 @@ struct cobalt_thread *cobalt_thread_find(pid_t pid) /* 
nklocked, IRQs off */
 
return gslot ? gslot-thread : NULL;
 }
+EXPORT_SYMBOL_GPL(cobalt_thread_find);
 
 struct xnpersonality *cobalt_thread_exit(struct xnthread *curr)
 {


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


[Xenomai-git] Philippe Gerum : cobalt/pod: drop xnpod_stop_thread() service

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 832acb60ad4bbcce8e3e70f63fb0ad8ae3074ffb
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=832acb60ad4bbcce8e3e70f63fb0ad8ae3074ffb

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 11:04:29 2013 +0200

cobalt/pod: drop xnpod_stop_thread() service

This routine was aimed at implementing non-destructive thread
termination services (e.g. arinc653's STOP_SELF()), which can and
should be done from userland instead. Besides, xnpod_stop_thread()
blurred the semantics of XNDORMANT in a confusing way.

As a consequence of this change, XNDORMANT has a single meaning: it
tags a thread which is yet to be started via xnpod_start_thread(), and
therefore only happens once in any thread's lifetime.

---

 include/cobalt/kernel/pod.h |2 -
 include/cobalt/uapi/kernel/thread.h |2 +-
 kernel/cobalt/pod.c |  202 ++-
 kernel/cobalt/shadow.c  |   18 +---
 4 files changed, 59 insertions(+), 165 deletions(-)

diff --git a/include/cobalt/kernel/pod.h b/include/cobalt/kernel/pod.h
index 5b8af19..c5b4290 100644
--- a/include/cobalt/kernel/pod.h
+++ b/include/cobalt/kernel/pod.h
@@ -158,8 +158,6 @@ int xnpod_init_thread(struct xnthread *thread,
 int xnpod_start_thread(struct xnthread *thread,
   const struct xnthread_start_attr *attr);
 
-void xnpod_stop_thread(struct xnthread *thread);
-
 void xnpod_cancel_thread(struct xnthread *thread);
 
 void xnpod_join_thread(struct xnthread *thread);
diff --git a/include/cobalt/uapi/kernel/thread.h 
b/include/cobalt/uapi/kernel/thread.h
index fe7dfb0..7913d82 100644
--- a/include/cobalt/uapi/kernel/thread.h
+++ b/include/cobalt/uapi/kernel/thread.h
@@ -33,7 +33,7 @@
 #define XNPEND0x0002 /** Sleep-wait for a resource. */
 #define XNDELAY   0x0004 /** Delayed */
 #define XNREADY   0x0008 /** Linked to the ready queue. */
-#define XNDORMANT 0x0010 /** Not started yet or killed */
+#define XNDORMANT 0x0010 /** Not started yet */
 #define XNZOMBIE  0x0020 /** Zombie thread in deletion process */
 #define XNSTARTED 0x0040 /** Thread has been started */
 #define XNMAPPED  0x0080 /** Thread is mapped to a linux task */
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 524b7ae..0071d96 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -464,12 +464,11 @@ EXPORT_SYMBOL_GPL(xnpod_init_thread);
  *
  * Starts a (newly) created thread, scheduling it for the first
  * time. This call releases the target thread from the XNDORMANT
- * state. This service also sets the initial mode and interrupt mask
- * for the new thread.
+ * state. This service also sets the initial mode for the new thread.
  *
- * @param thread The descriptor address of the affected thread which
- * must have been previously initialized by the xnpod_init_thread()
- * service.
+ * @param thread The descriptor address of the started thread which
+ * must have been previously initialized by a call to
+ * xnpod_init_thread().
  *
  * @param attr A pointer to an attribute block describing the
  * execution properties of the new thread. Members of this structure
@@ -490,7 +489,8 @@ EXPORT_SYMBOL_GPL(xnpod_init_thread);
  * xnpod_resume_thread() service for its execution to actually begin.
  *
  * - affinity: The processor affinity of this thread. Passing
- * XNPOD_ALL_CPUS or an empty affinity set means any cpu.
+ * XNPOD_ALL_CPUS or an empty affinity set means any cpu from the
+ * allowed core affinity mask (nkaffinity).
  *
  * - entry: The address of the thread's body routine. In other words,
  * it is the thread entry point.
@@ -514,7 +514,6 @@ EXPORT_SYMBOL_GPL(xnpod_init_thread);
  *
  * Rescheduling: possible.
  */
-
 int xnpod_start_thread(struct xnthread *thread,
   const struct xnthread_start_attr *attr)
 {
@@ -530,14 +529,6 @@ int xnpod_start_thread(struct xnthread *thread,
goto unlock_and_exit;
}
 
-   if (xnthread_test_state(thread, XNSTARTED)) {
-   /* Resuming from a stopped state. */
-   xnpod_resume_thread(thread, XNDORMANT);
-   goto schedule;
-   }
-
-   /* This is our initial start. */
-
affinity = attr-affinity;
cpus_and(affinity, affinity, nkaffinity);
thread-affinity = *cpu_online_mask;
@@ -563,7 +554,6 @@ int xnpod_start_thread(struct xnthread *thread,
   thread, xnthread_name(thread));
 
xnpod_resume_thread(thread, XNDORMANT);
-schedule:
xnpod_schedule();
 unlock_and_exit:
xnlock_put_irqrestore(nklock, s);
@@ -573,86 +563,6 @@ unlock_and_exit:
 EXPORT_SYMBOL_GPL(xnpod_start_thread);
 
 /*!
- * @internal
- * \fn void __xnpod_reset_thread(struct xnthread *thread)
- * \brief Reset the thread.
- *
- * This internal routine resets the state of a thread so that it can
- * be subsequently stopped or restarted.
- */
-static void 

[Xenomai-git] Philippe Gerum : cobalt/lock: turn lock statistics into per-cpu data

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

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Jul 30 17:32:43 2013 +0200

cobalt/lock: turn lock statistics into per-cpu data

---

 include/cobalt/kernel/lock.h |3 ++-
 kernel/cobalt/debug.c|2 +-
 kernel/cobalt/lock.c |4 ++--
 kernel/cobalt/procfs.c   |4 ++--
 4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/include/cobalt/kernel/lock.h b/include/cobalt/kernel/lock.h
index d26013b..a019100 100644
--- a/include/cobalt/kernel/lock.h
+++ b/include/cobalt/kernel/lock.h
@@ -25,6 +25,7 @@
 #define _COBALT_KERNEL_LOCK_H
 
 #include linux/ipipe.h
+#include linux/percpu.h
 #include cobalt/kernel/assert.h
 
 /** \addtogroup lock
@@ -95,7 +96,7 @@ int xnlock_dbg_release(struct xnlock *lock,
 const char *file, int line,
 const char *function);
 
-extern struct xnlockinfo xnlock_stats[];
+DECLARE_PER_CPU(struct xnlockinfo, xnlock_stats);
 
 #else /* !XENO_DEBUG(XNLOCK) */
 
diff --git a/kernel/cobalt/debug.c b/kernel/cobalt/debug.c
index b2540e3..c2afc2f 100644
--- a/kernel/cobalt/debug.c
+++ b/kernel/cobalt/debug.c
@@ -583,7 +583,7 @@ int xnlock_dbg_release(struct xnlock *lock,
 
lock_time = xnclock_read_raw(nkclock) - lock-lock_date;
cpu = ipipe_processor_id();
-   stats = xnlock_stats[cpu];
+   stats = per_cpu(xnlock_stats, cpu);
 
if (lock-file == NULL) {
lock-file = ??;
diff --git a/kernel/cobalt/lock.c b/kernel/cobalt/lock.c
index 7e43cd3..bc9077e 100644
--- a/kernel/cobalt/lock.c
+++ b/kernel/cobalt/lock.c
@@ -55,8 +55,8 @@ EXPORT_SYMBOL_GPL(__xnlock_spin);
 #endif /* CONFIG_SMP || XENO_DEBUG(XNLOCK) */
 
 #if XENO_DEBUG(XNLOCK)
-struct xnlockinfo xnlock_stats[NR_CPUS];
-EXPORT_SYMBOL_GPL(xnlock_stats);
+DEFINE_PER_CPU(struct xnlockinfo, xnlock_stats);
+EXPORT_PER_CPU_SYMBOL(xnlock_stats);
 #endif
 
 /*@}*/
diff --git a/kernel/cobalt/procfs.c b/kernel/cobalt/procfs.c
index 9600ccc..dd1c32b 100644
--- a/kernel/cobalt/procfs.c
+++ b/kernel/cobalt/procfs.c
@@ -39,7 +39,7 @@ static int lock_vfile_show(struct xnvfile_regular_iterator 
*it, void *data)
for_each_online_cpu(cpu) {
 
xnlock_get_irqsave(nklock, s);
-   lockinfo = xnlock_stats[cpu];
+   lockinfo = per_cpu(xnlock_stats, cpu);
xnlock_put_irqrestore(nklock, s);
 
if (cpu  0)
@@ -76,7 +76,7 @@ static ssize_t lock_vfile_store(struct xnvfile_input *input)
 
for_each_online_cpu(cpu) {
xnlock_get_irqsave(nklock, s);
-   memset(xnlock_stats[cpu], '\0', sizeof(xnlock_stats[cpu]));
+   memset(per_cpu(xnlock_stats, cpu), '\0', sizeof(struct 
xnlockinfo));
xnlock_put_irqrestore(nklock, s);
}
 


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


[Xenomai-git] Philippe Gerum : cobalt/thread: move non-critical cleanup code out of critical section

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 14:29:34 2013 +0200

cobalt/thread: move non-critical cleanup code out of critical section

Since the thread cleanup code can only run on behalf of the root
domain, and only from the exiting context, we may do a lot of
housekeeping locklessly.

Remove those fully private cleanups from the nklocked section, which
should help reducing the overall latency upon thread exit.

---

 include/cobalt/kernel/thread.h |2 +-
 kernel/cobalt/pod.c|   31 ---
 kernel/cobalt/shadow.c |2 +-
 kernel/cobalt/thread.c |4 +---
 4 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 28b4296..191c24e 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -324,7 +324,7 @@ void xnthread_init_shadow_tcb(struct xnthread *thread,
 
 void xnthread_init_root_tcb(struct xnthread *thread);
 
-void xnthread_cleanup(struct xnthread *thread);
+void xnthread_deregister(struct xnthread *thread);
 
 char *xnthread_format_status(unsigned long status, char *buf, int size);
 
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 3fd270d..5d911af 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -654,9 +654,6 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
 {
struct xnsched *sched = thread-sched;
 
-   trace_mark(xn_nucleus, thread_cleanup, thread %p thread_name %s,
-  thread, xnthread_name(thread));
-
list_del(thread-glink);
nkpod-nrthreads--;
xnvfile_touch_tag(nkpod-threadlist_tag);
@@ -667,16 +664,8 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
xnthread_clear_state(thread, XNREADY);
}
 
-   xntimer_destroy(thread-rtimer);
-   xntimer_destroy(thread-ptimer);
-   xntimer_destroy(thread-rrbtimer);
thread-idtag = 0;
 
-   if (thread-selector) {
-   xnselector_destroy(thread-selector);
-   thread-selector = NULL;
-   }
-
if (xnthread_test_state(thread, XNPEND))
xnsynch_forget_sleeper(thread);
 
@@ -695,12 +684,9 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
return;
 
xnsched_forget(thread);
-   xnthread_cleanup(thread);
+   xnthread_deregister(thread);
/* Finalize last since this incurs releasing the TCB. */
xnshadow_finalize(thread);
-
-   if (xnthread_test_state(sched-curr, XNROOT))
-   xnfreesync();
 }
 
 void __xnpod_cleanup_thread(struct xnthread *thread)
@@ -708,9 +694,24 @@ void __xnpod_cleanup_thread(struct xnthread *thread)
spl_t s;
 
XENO_BUGON(NUCLEUS, !ipipe_root_p);
+
+   trace_mark(xn_nucleus, thread_cleanup, thread %p thread_name %s,
+  thread, xnthread_name(thread));
+
+   xntimer_destroy(thread-rtimer);
+   xntimer_destroy(thread-ptimer);
+   xntimer_destroy(thread-rrbtimer);
+
+   if (thread-selector) {
+   xnselector_destroy(thread-selector);
+   thread-selector = NULL;
+   }
+
xnlock_get_irqsave(nklock, s);
cleanup_thread(thread);
+   xnfreesync();
xnlock_put_irqrestore(nklock, s);
+
wake_up(nkjoinq);
 }
 
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 11776ec..4d0b761 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -1025,7 +1025,7 @@ void xnshadow_finalize(struct xnthread *thread)
 {
struct xnsys_ppd *sys_ppd;
 
-   trace_mark(xn_nucleus, shadow_unmap,
+   trace_mark(xn_nucleus, shadow_finalize,
   thread %p thread_name %s pid %d,
   thread, xnthread_name(thread), xnthread_host_pid(thread));
 
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 5d268a2..4e0ae56 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -229,10 +229,8 @@ void xnthread_init_root_tcb(struct xnthread *thread)
xnarch_init_root_tcb(tcb);
 }
 
-void xnthread_cleanup(struct xnthread *thread)
+void xnthread_deregister(struct xnthread *thread)
 {
-   /* Does not wreck the TCB, only releases the held resources. */
-
if (thread-registry.handle != XN_NO_HANDLE)
xnregistry_remove(thread-registry.handle);
 


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


[Xenomai-git] Philippe Gerum : cobalt/sched: turn scheduler slot into a per-cpu variable

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 167f7dcbbe65e33073e9fd62d2befef3e6316317
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=167f7dcbbe65e33073e9fd62d2befef3e6316317

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Jul 30 16:42:09 2013 +0200

cobalt/sched: turn scheduler slot into a per-cpu variable

---

 include/cobalt/kernel/pod.h   |   10 --
 include/cobalt/kernel/sched.h |3 +++
 kernel/cobalt/pod.c   |2 +-
 kernel/cobalt/sched.c |3 +++
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/pod.h b/include/cobalt/kernel/pod.h
index e8f69e4..5b8af19 100644
--- a/include/cobalt/kernel/pod.h
+++ b/include/cobalt/kernel/pod.h
@@ -59,8 +59,7 @@ struct xnsynch;
 
 struct xnpod {
unsigned long status; /*! Status bitmask. */
-   xnsched_t sched[NR_CPUS];   /*! Per-cpu scheduler slots. */
-   struct list_head threadq;   /*! All existing threads. */
+   struct list_head threadq; /*! All existing threads. */
int nrthreads;
 #ifdef CONFIG_XENO_OPT_VFILE
struct xnvfile_rev_tag threadlist_tag;
@@ -92,16 +91,15 @@ void __xnpod_schedule(struct xnsched *sched);
 
 void __xnpod_schedule_handler(void);
 
-   /* -- Beginning of the exported interface */
-
 static inline struct xnsched *xnpod_sched_slot(int cpu)
 {
-   return nkpod-sched + cpu;
+   return per_cpu(nksched, cpu);
 }
 
 static inline struct xnsched *xnpod_current_sched(void)
 {
-   return xnpod_sched_slot(ipipe_processor_id());
+   /* IRQs off */
+   return __this_cpu_ptr(nksched);
 }
 
 static inline int xnpod_active_p(void)
diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index a5acc16..be3f2c5 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -28,6 +28,7 @@
 /*! \addtogroup sched
  *@{*/
 
+#include linux/percpu.h
 #include cobalt/kernel/thread.h
 #include cobalt/kernel/schedqueue.h
 #include cobalt/kernel/sched-tp.h
@@ -93,6 +94,8 @@ typedef struct xnsched {
 #endif
 } xnsched_t;
 
+DECLARE_PER_CPU(struct xnsched, nksched);
+
 union xnsched_policy_param;
 
 struct xnsched_class {
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index c4c8ea3..bb79139 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -260,7 +260,7 @@ int xnpod_init(void)
xnheap_set_label(kheap, main heap);
 
for_each_online_cpu(cpu) {
-   sched = pod-sched[cpu];
+   sched = per_cpu(nksched, cpu);
xnsched_init(sched, cpu);
if (xnarch_cpu_supported(cpu)) {
list_add_tail(sched-rootcb.glink, pod-threadq);
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index 1769586..c353674 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -30,6 +30,9 @@
 #include cobalt/kernel/arith.h
 #include asm/xenomai/thread.h
 
+DEFINE_PER_CPU(struct xnsched, nksched);
+EXPORT_PER_CPU_SYMBOL(nksched);
+
 static struct xnsched_class *xnsched_class_highest;
 
 #define for_each_xnsched_class(p) \


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


[Xenomai-git] Philippe Gerum : cobalt/arch: turn apc and fault statistics into per-cpu data

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 141b8a556df026ecde40e79113763a6bfd701846
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=141b8a556df026ecde40e79113763a6bfd701846

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Jul 30 19:30:55 2013 +0200

cobalt/arch: turn apc and fault statistics into per-cpu data

---

 include/cobalt/kernel/apc.h|5 ++-
 kernel/cobalt/apc.c|   27 ++-
 .../cobalt/include/asm-generic/xenomai/machine.h   |   12 ++--
 kernel/cobalt/init.c   |3 ++
 kernel/cobalt/procfs.c |4 +-
 kernel/cobalt/shadow.c |   15 +++---
 6 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/include/cobalt/kernel/apc.h b/include/cobalt/kernel/apc.h
index c18bceb..67aa735 100644
--- a/include/cobalt/kernel/apc.h
+++ b/include/cobalt/kernel/apc.h
@@ -37,8 +37,9 @@ void xnapc_free(int apc);
 
 static inline void __xnapc_schedule(int apc)
 {
-   int cpu = ipipe_processor_id();
-   if (!__test_and_set_bit(apc, xnarch_machdata.apc_pending[cpu]))
+   unsigned long *p = 
__this_cpu_ptr(xnarch_percpu_machdata)-apc_pending;
+
+   if (!__test_and_set_bit(apc, p))
ipipe_post_irq_root(xnarch_machdata.apc_virq);
 }
 
diff --git a/kernel/cobalt/apc.c b/kernel/cobalt/apc.c
index 25bb33d..b01f0c8 100644
--- a/kernel/cobalt/apc.c
+++ b/kernel/cobalt/apc.c
@@ -44,27 +44,28 @@ static IPIPE_DEFINE_SPINLOCK(apc_lock);
 void apc_dispatch(unsigned int virq, void *arg)
 {
void (*handler)(void *), *cookie;
-   int apc, cpu;
-
-   spin_lock(apc_lock);
-
-   cpu = ipipe_processor_id();
+   unsigned long *p;
+   int apc;
 
/*
-* ! This loop is not protected against a handler becoming
-* unavailable while processing the pending queue; the
-* software must make sure to uninstall all APCs before
-* eventually unloading any module that may contain APC
+* CAUTION: The APC dispatch loop is not protected against a
+* handler becoming unavailable while processing the pending
+* queue; the software must make sure to uninstall all APCs
+* before eventually unloading any module that may contain APC
 * handlers. We keep the handler affinity with the poster's
 * CPU, so that the handler is invoked on the same CPU than
 * the code which called xnapc_schedule().
 */
-   while (xnarch_machdata.apc_pending[cpu]) {
-   apc = ffnz(xnarch_machdata.apc_pending[cpu]);
-   clear_bit(apc, xnarch_machdata.apc_pending[cpu]);
+   spin_lock(apc_lock);
+
+   /* This is atomic linux context (non-threaded IRQ). */
+   p = __this_cpu_ptr(xnarch_percpu_machdata)-apc_pending;
+   while (*p) {
+   apc = ffnz(*p);
+   clear_bit(apc, p);
handler = xnarch_machdata.apc_table[apc].handler;
cookie = xnarch_machdata.apc_table[apc].cookie;
-   xnarch_machdata.apc_table[apc].hits[cpu]++;
+   __this_cpu_ptr(xnarch_percpu_machdata)-apc_shots[apc]++;
spin_unlock(apc_lock);
handler(cookie);
spin_lock(apc_lock);
diff --git a/kernel/cobalt/include/asm-generic/xenomai/machine.h 
b/kernel/cobalt/include/asm-generic/xenomai/machine.h
index a32e63c..b6b4e8e 100644
--- a/kernel/cobalt/include/asm-generic/xenomai/machine.h
+++ b/kernel/cobalt/include/asm-generic/xenomai/machine.h
@@ -24,6 +24,7 @@
 #endif
 
 #include linux/ipipe.h
+#include linux/percpu.h
 #include asm/byteorder.h
 #include asm/xenomai/wrappers.h
 
@@ -40,21 +41,26 @@ struct xnarch_machdesc {
 
 extern struct xnarch_machdesc xnarch_machdesc;
 
+struct xnarch_percpu_machdata {
+   unsigned long apc_pending;
+   unsigned long apc_shots[BITS_PER_LONG];
+   unsigned int faults[IPIPE_NR_FAULTS];
+};
+
+DECLARE_PER_CPU(struct xnarch_percpu_machdata, xnarch_percpu_machdata);
+
 struct xnarch_machdata {
struct ipipe_domain domain;
unsigned long timer_freq;
unsigned long clock_freq;
unsigned int apc_virq;
unsigned long apc_map;
-   unsigned long apc_pending[NR_CPUS];
unsigned int escalate_virq;
struct {
void (*handler)(void *cookie);
void *cookie;
const char *name;
-   unsigned long hits[NR_CPUS];
} apc_table[BITS_PER_LONG];
-   unsigned int faults[NR_CPUS][IPIPE_NR_FAULTS];
 #ifdef CONFIG_SMP
cpumask_t supported_cpus;
 #endif
diff --git a/kernel/cobalt/init.c b/kernel/cobalt/init.c
index 2f3a4da..6604833 100644
--- a/kernel/cobalt/init.c
+++ b/kernel/cobalt/init.c
@@ -58,6 +58,9 @@ module_param_named(disable, disable_arg, ulong, 0444);
 struct xnarch_machdata xnarch_machdata;
 EXPORT_SYMBOL_GPL(xnarch_machdata);
 
+struct xnarch_percpu_machdata 

[Xenomai-git] Philippe Gerum : cobalt/shadow: emit rejected syscall id upon spurious non-shadow call

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

Author: Philippe Gerum r...@xenomai.org
Date:   Fri Jul 26 17:52:54 2013 +0200

cobalt/shadow: emit rejected syscall id upon spurious non-shadow call

---

 kernel/cobalt/shadow.c |   42 +-
 1 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 1a41e85..4413730 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -520,7 +520,7 @@ EXPORT_SYMBOL_GPL(xnshadow_harden);
  */
 void xnshadow_relax(int notify, int reason)
 {
-   xnthread_t *thread = xnpod_current_thread();
+   struct xnthread *thread = xnpod_current_thread();
struct task_struct *p = current;
siginfo_t si;
 
@@ -784,11 +784,6 @@ static inline void destroy_threadinfo(void)
  * (i.e. in order to process the signal in the Linux domain). This
  * error should not be considered as fatal.
  *
- * - -EPERM is returned if the shadow thread has been killed before
- * the current task had a chance to return to the caller. In such a
- * case, the real-time mapping operation has failed globally, and no
- * Xenomai resource remains attached to it.
- *
  * - -EINVAL is returned if the thread control block does not bear the
  * XNUSER bit.
  *
@@ -1037,7 +1032,7 @@ int xnshadow_map_kernel(struct xnthread *thread, struct 
completion *done)
xnlock_get_irqsave(nklock, s);
/*
 * Make sure xnpod_start_thread() did not slip in from another
-* CPU while we were back from the wakeup_parent().
+* CPU while we were back from wakeup_parent().
 */
if (xnthread_test_state(thread, XNSTARTED) == 0)
xnpod_suspend_thread(thread, XNDORMANT,
@@ -1505,7 +1500,7 @@ static int xnshadow_sys_heap_info(struct xnheap_desc 
__user *u_hd,
 
 static int xnshadow_sys_current(xnhandle_t __user *u_handle)
 {
-   xnthread_t *cur = xnshadow_current();
+   struct xnthread *cur = xnshadow_current();
 
if (cur == NULL)
return -EPERM;
@@ -1516,7 +1511,7 @@ static int xnshadow_sys_current(xnhandle_t __user 
*u_handle)
 
 static int xnshadow_sys_current_info(struct xnthread_info __user *u_info)
 {
-   xnthread_t *cur = xnshadow_current();
+   struct xnthread *cur = xnshadow_current();
struct xnthread_info info;
xnticks_t raw_exectime;
int i;
@@ -1683,7 +1678,7 @@ static struct xnpersonality user_personality = {
},
 };
 
-void xnshadow_send_sig(xnthread_t *thread, int sig, int arg)
+void xnshadow_send_sig(struct xnthread *thread, int sig, int arg)
 {
struct lostage_signal sigwork = {
.work = {
@@ -1876,14 +1871,6 @@ static int handle_head_syscall(struct ipipe_domain *ipd, 
struct pt_regs *regs)
if (!__xn_reg_mux_p(regs))
goto linux_syscall;
 
-   /*
-* Executing Xenomai services requires CAP_SYS_NICE, except for
-* sc_nucleus_bind which does its own checks.
-*/
-   if (unlikely(!cap_raised(current_cap(), CAP_SYS_NICE)) 
-   __xn_reg_mux(regs) != __xn_mux_code(0, sc_nucleus_bind))
-   goto no_permission;
-
muxid = __xn_mux_id(regs);
muxop = __xn_mux_op(regs);
 
@@ -1892,7 +1879,7 @@ static int handle_head_syscall(struct ipipe_domain *ipd, 
struct pt_regs *regs)
   thread, thread ? xnthread_name(thread) : NULL,
   muxid, muxop);
 
-   if (muxid  0 || muxid  PERSONALITIES_NR || muxop  0)
+   if (muxid  0 || muxid = PERSONALITIES_NR || muxop  0)
goto bad_syscall;
 
personality = personalities[muxid];
@@ -1902,17 +1889,22 @@ static int handle_head_syscall(struct ipipe_domain 
*ipd, struct pt_regs *regs)
sc = personality-syscalls + muxop;
sysflags = sc-flags;
 
-   if ((sysflags  __xn_exec_shadow) != 0  thread == NULL) {
-   no_permission:
+   /*
+* Executing Xenomai services requires CAP_SYS_NICE, except
+* for sc_nucleus_bind which does its own checks.
+*/
+   if (unlikely((thread == NULL  (sysflags  __xn_exec_shadow) != 0) ||
+(!cap_raised(current_cap(), CAP_SYS_NICE) 
+ muxid == 0  muxop == sc_nucleus_bind))) {
if (XENO_DEBUG(NUCLEUS))
-   printk(KERN_WARNING
-  Xenomai: non-shadow %s[%d] was denied a 
real-time call\n,
-  current-comm, current-pid);
+   printk(XENO_WARN
+  non-shadow %s[%d] was denied a real-time call 
(%s/%d)\n,
+  current-comm, current-pid, personality-name, 
muxop);
__xn_error_return(regs, -EPERM);
goto ret_handled;
}
 
-   if 

[Xenomai-git] Philippe Gerum : cobalt/kernel: remove pod abstraction entirely

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

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 19:03:46 2013 +0200

cobalt/kernel: remove pod abstraction entirely

We don't have full-fledged in-kernel APIs going in and out selectively
anymore, we now have a stable set of API services (i.e. core, POSIX
and RTDM), with optional limited extensions through Xenomai
personalities.

For this reason, the former pod abstraction, as a mean to group
multiple API siblings in a common generic container is not much
relevant anymore.

The ongoing design simplification now allows to drop the pod-related
services, dispatching them to the other existing abstractions.

The renaming involved are fairly straightforward for the most part,
i.e.:

* Former thread-directed ops:
  xnpod_action_thread() = xnthread_action()

* Former scheduler-related ops:
  xnpod_action() = xnsched_action()

Hint: xnpod_schedule() became xnsched_run() (although xnsched_ule()
would have been delighting).

---

 include/cobalt/kernel/Makefile.am  |2 +-
 include/cobalt/kernel/Makefile.in  |2 +-
 include/cobalt/kernel/assert.h |4 +-
 include/cobalt/kernel/clock.h  |4 +
 include/cobalt/kernel/lock.h   |   14 +-
 include/cobalt/kernel/pod.h|  310 ---
 include/cobalt/kernel/sched-tp.h   |5 +-
 include/cobalt/kernel/sched-weak.h |6 +-
 include/cobalt/kernel/sched.h  |  198 ++-
 include/cobalt/kernel/shadow.h |   17 +-
 include/cobalt/kernel/sys.h|   83 +
 include/cobalt/kernel/thread.h |   91 +-
 include/cobalt/kernel/timer.h  |2 +-
 include/cobalt/kernel/vdso.h   |1 -
 include/rtdm/rtdm_driver.h |   42 +-
 kernel/cobalt/Makefile |2 +-
 kernel/cobalt/arch/blackfin/machine.c  |   14 +-
 .../cobalt/arch/x86/include/asm/xenomai/thread.h   |3 +-
 kernel/cobalt/arch/x86/thread.c|3 +-
 kernel/cobalt/bufd.c   |   12 +-
 kernel/cobalt/clock.c  |   34 +-
 kernel/cobalt/debug.c  |   19 +-
 kernel/cobalt/heap.c   |   26 +-
 .../cobalt/include/asm-generic/xenomai/machine.h   |   16 -
 kernel/cobalt/init.c   |   16 +-
 kernel/cobalt/intr.c   |   59 +-
 kernel/cobalt/lock.c   |   15 +-
 kernel/cobalt/map.c|3 +-
 kernel/cobalt/pipe.c   |   10 +-
 kernel/cobalt/pod.c| 2161 
 kernel/cobalt/posix/clock.c|6 +-
 kernel/cobalt/posix/cond.c |2 +-
 kernel/cobalt/posix/event.c|4 +-
 kernel/cobalt/posix/internal.h |2 +-
 kernel/cobalt/posix/monitor.c  |   14 +-
 kernel/cobalt/posix/mqueue.c   |   12 +-
 kernel/cobalt/posix/mutex.c|   10 +-
 kernel/cobalt/posix/sem.c  |6 +-
 kernel/cobalt/posix/syscall.c  |2 +-
 kernel/cobalt/posix/thread.c   |   61 +-
 kernel/cobalt/posix/timer.c|2 +-
 kernel/cobalt/procfs.c |7 +-
 kernel/cobalt/registry.c   |   30 +-
 kernel/cobalt/rtdm/core.c  |1 -
 kernel/cobalt/rtdm/drvlib.c|   50 +-
 kernel/cobalt/rtdm/internal.h  |2 +-
 kernel/cobalt/sched-idle.c |8 +-
 kernel/cobalt/sched-rt.c   |   13 +-
 kernel/cobalt/sched-sporadic.c |   32 +-
 kernel/cobalt/sched-tp.c   |   16 +-
 kernel/cobalt/sched-weak.c |   16 +-
 kernel/cobalt/sched.c  |  339 +++-
 kernel/cobalt/select.c |   17 +-
 kernel/cobalt/shadow.c |  168 +-
 kernel/cobalt/synch.c  |   52 +-
 kernel/cobalt/sys.c|  332 +++
 kernel/cobalt/thread.c | 1506 ++-
 kernel/cobalt/timer.c  |   20 +-
 kernel/cobalt/vfile.c  |3 +-
 kernel/drivers/testing/switchtest.c|   24 +-
 60 files changed, 2869 insertions(+), 3062 deletions(-)

Diff:   

[Xenomai-git] Philippe Gerum : cobalt/pod: drop the XNSTARTED bit from the thread state mask

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 09da3f6450b184506411035b45751562b5c2e1a6
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=09da3f6450b184506411035b45751562b5c2e1a6

Author: Philippe Gerum r...@xenomai.org
Date:   Wed Jul 31 11:36:22 2013 +0200

cobalt/pod: drop the XNSTARTED bit from the thread state mask

Since XNDORMANT now exclusively means never started, we don't need
the XNSTARTED bit anymore.

Strictly speaking, XNDORMANT == !XNSTARTED and conversely.

---

 include/cobalt/uapi/kernel/thread.h |   29 ++---
 kernel/cobalt/pod.c |2 +-
 kernel/cobalt/sched.c   |4 ++--
 kernel/cobalt/shadow.c  |4 ++--
 4 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/include/cobalt/uapi/kernel/thread.h 
b/include/cobalt/uapi/kernel/thread.h
index 7913d82..069507b 100644
--- a/include/cobalt/uapi/kernel/thread.h
+++ b/include/cobalt/uapi/kernel/thread.h
@@ -35,21 +35,20 @@
 #define XNREADY   0x0008 /** Linked to the ready queue. */
 #define XNDORMANT 0x0010 /** Not started yet */
 #define XNZOMBIE  0x0020 /** Zombie thread in deletion process */
-#define XNSTARTED 0x0040 /** Thread has been started */
-#define XNMAPPED  0x0080 /** Thread is mapped to a linux task */
-#define XNRELAX   0x0100 /** Relaxed shadow thread (blocking bit) */
-#define XNMIGRATE 0x0200 /** Thread is currently migrating to another 
CPU. */
-#define XNHELD0x0400 /** Thread is held to process emergency. */
+#define XNMAPPED  0x0040 /** Thread is mapped to a linux task */
+#define XNRELAX   0x0080 /** Relaxed shadow thread (blocking bit) */
+#define XNMIGRATE 0x0100 /** Thread is currently migrating to another 
CPU. */
+#define XNHELD0x0200 /** Thread is held to process emergency. */
 
-#define XNBOOST   0x0800 /** Undergoes a PIP boost */
-#define XNDEBUG   0x1000 /** Hit a debugger breakpoint */
-#define XNLOCK0x2000 /** Holds the scheduler lock (i.e. not 
preemptible) */
-#define XNRRB 0x4000 /** Undergoes a round-robin scheduling */
-#define XNTRAPSW  0x8000 /** Trap execution mode switches */
-#define XNFPU 0x0001 /** Thread uses FPU */
-#define XNROOT0x0002 /** Root thread (that is, Linux/IDLE) */
-#define XNWEAK0x0004 /** Non real-time shadow (from the WEAK class) */
-#define XNUSER0x0008 /** Shadow thread running in userland */
+#define XNBOOST   0x0400 /** Undergoes a PIP boost */
+#define XNDEBUG   0x0800 /** Hit a debugger breakpoint */
+#define XNLOCK0x1000 /** Holds the scheduler lock (i.e. not 
preemptible) */
+#define XNRRB 0x2000 /** Undergoes a round-robin scheduling */
+#define XNTRAPSW  0x4000 /** Trap execution mode switches */
+#define XNFPU 0x8000 /** Thread uses FPU */
+#define XNROOT0x0001 /** Root thread (that is, Linux/IDLE) */
+#define XNWEAK0x0002 /** Non real-time shadow (from the WEAK class) */
+#define XNUSER0x0004 /** Shadow thread running in userland */
 
 /** @} */
 
@@ -91,7 +90,7 @@
  * 'r' - Undergoes round-robin.
  * 't' - Mode switches trapped.
  */
-#define XNTHREAD_STATE_LABELS  SWDRU...X.HbTlrt
+#define XNTHREAD_STATE_LABELS  SWDRU..X.HbTlrt
 
 /**
  * @brief Structure containing thread information.
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 0071d96..0b35cb9 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -545,7 +545,7 @@ int xnpod_start_thread(struct xnthread *thread,
}
 #endif /* CONFIG_SMP */
 
-   xnthread_set_state(thread, (attr-mode  (XNTHREAD_MODE_BITS | XNSUSP)) 
| XNSTARTED);
+   xnthread_set_state(thread, attr-mode  (XNTHREAD_MODE_BITS | XNSUSP));
thread-imode = (attr-mode  XNTHREAD_MODE_BITS);
thread-entry = attr-entry;
thread-cookie = attr-cookie;
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index c353674..342fd00 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -153,7 +153,7 @@ void xnsched_init(struct xnsched *sched, int cpu)
xntimer_set_sched(sched-htimer, sched);
sched-zombie = NULL;
 
-   attr.flags = XNROOT | XNSTARTED | XNFPU;
+   attr.flags = XNROOT | XNFPU;
attr.name = root_name;
attr.personality = generic_personality;
param.idle.prio = XNSCHED_IDLE_PRIO;
@@ -367,7 +367,7 @@ int xnsched_set_policy(struct xnthread *thread,
if (xnthread_test_state(thread, XNREADY))
xnsched_enqueue(thread);
 
-   if (xnthread_test_state(thread, XNSTARTED))
+   if (!xnthread_test_state(thread, XNDORMANT))
xnsched_set_resched(thread-sched);
 
return 0;
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index bfffef1..9efd929 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -1010,7 +1010,7 @@ int xnshadow_map_kernel(struct xnthread *thread, struct 
completion *done)
 * Make 

[Xenomai-git] Philippe Gerum : cobalt/sched: do not store cpu number in uniprocessor mode

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 726148c6d9c70f14b2de91eae183cc9c5e947451
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=726148c6d9c70f14b2de91eae183cc9c5e947451

Author: Philippe Gerum r...@xenomai.org
Date:   Tue Jul 30 16:17:35 2013 +0200

cobalt/sched: do not store cpu number in uniprocessor mode

---

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

diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index a2d18e3..a5acc16 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -58,9 +58,9 @@ typedef struct xnsched {
 
unsigned long status;   /*! Scheduler specific status bitmask. 
*/
unsigned long lflags;   /*! Scheduler specific local flags 
bitmask. */
-   int cpu;
struct xnthread *curr;  /*! Current thread. */
 #ifdef CONFIG_SMP
+   int cpu;
cpumask_t resched;  /*! Mask of CPUs needing rescheduling. 
*/
 #endif
struct xnsched_rt rt;   /*! Context of built-in real-time 
class. */
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index b97d3a2..1769586 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -121,20 +121,20 @@ void xnsched_init(struct xnsched *sched, int cpu)
struct xnthread_init_attr attr;
struct xnsched_class *p;
 
-   sched-cpu = cpu;
-
-   for_each_xnsched_class(p) {
-   if (p-sched_init)
-   p-sched_init(sched);
-   }
-
 #ifdef CONFIG_SMP
+   sched-cpu = cpu;
sprintf(htimer_name, [host-timer/%u], cpu);
sprintf(root_name, ROOT/%u, cpu);
+   cpus_clear(sched-resched);
 #else
strcpy(htimer_name, [host-timer]);
strcpy(root_name, ROOT);
 #endif
+   for_each_xnsched_class(p) {
+   if (p-sched_init)
+   p-sched_init(sched);
+   }
+
sched-status = 0;
sched-lflags = 0;
sched-inesting = 0;
@@ -149,9 +149,6 @@ void xnsched_init(struct xnsched *sched, int cpu)
xntimer_set_name(sched-htimer, htimer_name);
xntimer_set_sched(sched-htimer, sched);
sched-zombie = NULL;
-#ifdef CONFIG_SMP
-   cpus_clear(sched-resched);
-#endif
 
attr.flags = XNROOT | XNSTARTED | XNFPU;
attr.name = root_name;


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


[Xenomai-git] Philippe Gerum : cobalt/posix/thread: allow sc_cobalt_thread_getstat for self (pid=0)

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

Author: Philippe Gerum r...@xenomai.org
Date:   Mon Aug  5 11:25:01 2013 +0200

cobalt/posix/thread: allow sc_cobalt_thread_getstat for self (pid=0)

---

 kernel/cobalt/posix/thread.c |   32 +---
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 444a79a..ff2f100 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -1143,27 +1143,30 @@ out:
 int cobalt_thread_stat(pid_t pid,
   struct cobalt_threadstat __user *u_stat)
 {
-   struct global_thread_hash *gslot;
struct cobalt_threadstat stat;
+   struct cobalt_thread *p;
struct xnthread *thread;
xnticks_t xtime;
-   u32 hash;
spl_t s;
 
-   hash = jhash2((u32 *)pid, sizeof(pid) / sizeof(u32), 0);
-
-   xnlock_get_irqsave(nklock, s);
-
-   gslot = global_index[hash  (PTHREAD_HSLOTS - 1)];
-   while (gslot  gslot-pid != pid)
-   gslot = gslot-next;
-
-   if (gslot == NULL) {
-   xnlock_put_irqrestore(nklock, s);
-   return -ESRCH;
+   if (pid == 0) {
+   thread = xnshadow_current();
+   if (thread == NULL)
+   return -EPERM;
+   xnlock_get_irqsave(nklock, s);
+   } else {
+   xnlock_get_irqsave(nklock, s);
+   p = cobalt_thread_find(pid);
+   if (p == NULL) {
+   xnlock_put_irqrestore(nklock, s);
+   return -ESRCH;
+   }
+   thread = p-threadbase;
}
 
-   thread = gslot-thread-threadbase;
+   /*
+* We have to hold the nklock to keep most values consistent.
+*/
stat.cpu = xnsched_cpu(thread-sched);
xtime = xnthread_get_exectime(thread);
if (xnthread_sched(thread)-curr == thread)
@@ -1176,7 +1179,6 @@ int cobalt_thread_stat(pid_t pid,
stat.status = xnthread_state_flags(thread);
stat.timeout = xnthread_get_timeout(thread,
xnclock_read_monotonic(nkclock));
-
xnlock_put_irqrestore(nklock, s);
 
return __xn_safe_copy_to_user(u_stat, stat, sizeof(stat));


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


[Xenomai-git] Philippe Gerum : cobalt/debug: introduce canned checks for calling context/ domain

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

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Aug  1 16:54:56 2013 +0200

cobalt/debug: introduce canned checks for calling context/domain

---

 include/cobalt/kernel/assert.h |7 +++
 kernel/cobalt/Kconfig  |   17 +++--
 kernel/cobalt/clock.c  |4 
 kernel/cobalt/heap.c   |3 +++
 kernel/cobalt/intr.c   |   14 +-
 kernel/cobalt/registry.c   |2 --
 kernel/cobalt/shadow.c |3 +--
 kernel/cobalt/thread.c |9 +++--
 8 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index dbca076..4d4cf9f 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -47,6 +47,10 @@
 #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0
 #endif
 
+#ifndef CONFIG_XENO_OPT_DEBUG_CONTEXT
+#define CONFIG_XENO_OPT_DEBUG_CONTEXT 0
+#endif
+
 #ifndef CONFIG_XENO_OPT_DEBUG_XNLOCK
 #define CONFIG_XENO_OPT_DEBUG_XNLOCK 0
 #endif
@@ -67,6 +71,9 @@
 #define CONFIG_XENO_OPT_DEBUG_COBALT 0
 #endif
 
+#define primary_mode_only()XENO_BUGON(CONTEXT, ipipe_root_p)
+#define secondary_mode_only()  XENO_BUGON(CONTEXT, !ipipe_root_p)
+
 void __xnsys_assert_failed(const char *file, int line, const char *msg);
 
 void __xnsys_fatal(const char *format, ...);
diff --git a/kernel/cobalt/Kconfig b/kernel/cobalt/Kconfig
index 0b1d53b..fb13b8f 100644
--- a/kernel/cobalt/Kconfig
+++ b/kernel/cobalt/Kconfig
@@ -325,14 +325,19 @@ menuconfig XENO_OPT_DEBUG
 if XENO_OPT_DEBUG
 
 config XENO_OPT_DEBUG_NUCLEUS
-   bool Nucleus runtime checks
+   bool Nucleus runtime assertions
help
 
-   This option activates various debugging checks inside the core
-   system. Doing so adds a significant runtime overhead,
-   worsening the latency figures especially on SMP kernels.  Do
-   not switch this option on unless you really know what you are
-   doing.
+   This option activates various assertions inside the core
+   system. This option has limited overhead.
+
+config XENO_OPT_DEBUG_CONTEXT
+   bool Check for calling context
+   help
+
+   This option enables checks for the calling context in the
+   Xenomai code, aimed at detecting when regular linux code is
+   entered from a real-time context, and conversely.
 
 config XENO_OPT_DEBUG_XNLOCK
bool Spinlock latency measurement
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 15aad23..bd06a96 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -489,6 +489,8 @@ int xnclock_register(struct xnclock *clock)
struct xntimerdata *tmd;
int cpu;
 
+   secondary_mode_only();
+
trace_mark(xn_nucleus, clock_register, clock %s, clock-name);
 
/* Allocate the percpu timer queue slot. */
@@ -536,6 +538,8 @@ void xnclock_deregister(struct xnclock *clock)
struct xntimerdata *tmd;
int cpu;
 
+   secondary_mode_only();
+
trace_mark(xn_nucleus, clock_deregister, clock %s, clock-name);
 
cleanup_clock_proc(clock);
diff --git a/kernel/cobalt/heap.c b/kernel/cobalt/heap.c
index 3db83be..af2d6c7 100644
--- a/kernel/cobalt/heap.c
+++ b/kernel/cobalt/heap.c
@@ -1283,6 +1283,8 @@ int xnheap_init_mapped(struct xnheap *heap, unsigned long 
heapsize, int memflags
void *heapbase;
int err;
 
+   secondary_mode_only();
+
/* Caller must have accounted for internal overhead. */
heapsize = xnheap_align(heapsize, PAGE_SIZE);
 
@@ -1317,6 +1319,7 @@ void xnheap_destroy_mapped(struct xnheap *heap,
unsigned long len;
spl_t s;
 
+   secondary_mode_only();
/*
 * Trying to unmap user memory without providing a release
 * handler for deferred cleanup is a bug.
diff --git a/kernel/cobalt/intr.c b/kernel/cobalt/intr.c
index 36bf647..d315b25 100644
--- a/kernel/cobalt/intr.c
+++ b/kernel/cobalt/intr.c
@@ -624,7 +624,7 @@ int xnintr_init(xnintr_t *intr, const char *name,
unsigned int irq, xnisr_t isr, xniack_t iack,
int flags)
 {
-   XENO_BUGON(NUCLEUS, !ipipe_root_p);
+   secondary_mode_only();
 
if (irq = IPIPE_NR_IRQS)
return -EINVAL;
@@ -669,7 +669,7 @@ EXPORT_SYMBOL_GPL(xnintr_init);
  */
 void xnintr_destroy(xnintr_t *intr)
 {
-   XENO_BUGON(NUCLEUS, !ipipe_root_p);
+   secondary_mode_only();
xnintr_detach(intr);
free_percpu(intr-stats);
 }
@@ -713,12 +713,13 @@ EXPORT_SYMBOL_GPL(xnintr_destroy);
  * @note Attaching an interrupt resets the tracked number of receipts
  * to zero.
  */
-
 int xnintr_attach(xnintr_t *intr, void *cookie)
 {
int ret;
spl_t s;
 
+   secondary_mode_only();
+
trace_mark(xn_nucleus, 

[Xenomai-git] Philippe Gerum : cobalt/kernel: restrict CPU enumerations to Xenomai-enabled ones

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

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Aug  1 15:45:11 2013 +0200

cobalt/kernel: restrict CPU enumerations to Xenomai-enabled ones

Since we only initialize scheduler slots for Xenomai-enabled CPUs,
we'd better consider only those from Xenomai's cpu_supported mask,
which may be a subset of the cpu_online mask.

We define for_each_realtime_cpu() for enumerating these
Xenomai-enabled CPUs.

---

 include/cobalt/kernel/sys.h |2 +-
 kernel/cobalt/assert.c  |2 +-
 kernel/cobalt/clock.c   |6 +++---
 kernel/cobalt/intr.c|   12 ++--
 kernel/cobalt/procfs.c  |   13 ++---
 kernel/cobalt/sys.c |8 
 6 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/include/cobalt/kernel/sys.h b/include/cobalt/kernel/sys.h
index 00c63e9..c95f9d9 100644
--- a/include/cobalt/kernel/sys.h
+++ b/include/cobalt/kernel/sys.h
@@ -66,7 +66,7 @@ static inline int xnsys_supported_cpu(int cpu)
 
 #endif /* !CONFIG_SMP */
 
-#define for_each_xenomai_cpu(cpu)  \
+#define for_each_realtime_cpu(cpu) \
for_each_online_cpu(cpu)\
if (xnsys_supported_cpu(cpu))   \
 
diff --git a/kernel/cobalt/assert.c b/kernel/cobalt/assert.c
index 8032c02..b346b8d 100644
--- a/kernel/cobalt/assert.c
+++ b/kernel/cobalt/assert.c
@@ -62,7 +62,7 @@ void __xnsys_fatal(const char *format, ...)
 * NOTE: nkthreadq can't be empty, we have the root thread(s)
 * linked there at least.
 */
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
sched = xnsched_struct(cpu);
list_for_each_entry(thread, nkthreadq, glink) {
if (thread-sched != sched)
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 4386812..15aad23 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -252,7 +252,7 @@ static void adjust_clock_timers(struct xnclock *clock, 
xnsticks_t delta)
INIT_LIST_HEAD(adjq);
delta = xnclock_ns_to_ticks(clock, delta);
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
sched = xnsched_struct(cpu);
q = xnclock_percpu_timerdata(clock, cpu)-q;
 
@@ -496,7 +496,7 @@ int xnclock_register(struct xnclock *clock)
if (clock-timerdata == NULL)
return -ENOMEM;
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
tmd = xnclock_percpu_timerdata(clock, cpu);
xntimerq_init(tmd-q);
}
@@ -540,7 +540,7 @@ void xnclock_deregister(struct xnclock *clock)
 
cleanup_clock_proc(clock);
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
tmd = xnclock_percpu_timerdata(clock, cpu);
XENO_BUGON(NUCLEUS, !xntimerq_empty(tmd-q));
xntimerq_destroy(tmd-q);
diff --git a/kernel/cobalt/intr.c b/kernel/cobalt/intr.c
index cb5761b..36bf647 100644
--- a/kernel/cobalt/intr.c
+++ b/kernel/cobalt/intr.c
@@ -62,7 +62,7 @@ static inline void sync_stat_references(struct xnintr *intr)
struct xnsched *sched;
int cpu;
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
sched = xnsched_struct(cpu);
statp = per_cpu_ptr(intr-stats, cpu);
/* Synchronize on all dangling references to go away. */
@@ -511,7 +511,7 @@ static void clear_irqstats(struct xnintr *intr)
struct xnirqstat *p;
int cpu;
 
-   for_each_online_cpu(cpu) {
+   for_each_realtime_cpu(cpu) {
p = per_cpu_ptr(intr-stats, cpu);
memset(p, 0, sizeof(*p));
}
@@ -882,7 +882,7 @@ static inline int xnintr_is_timer_irq(int irq)
 {
int cpu;
 
-   for_each_online_cpu(cpu)
+   for_each_realtime_cpu(cpu)
if (irq == per_cpu(ipipe_percpu.hrtimer_irq, cpu))
return 1;
 
@@ -986,7 +986,7 @@ static inline int format_irq_proc(unsigned int irq,
spl_t s;
int cpu;
 
-   for_each_online_cpu(cpu)
+   for_each_realtime_cpu(cpu)
if (xnintr_is_timer_irq(irq)) {
xnvfile_printf(it,  [timer/%d], cpu);
return 0;
@@ -1038,7 +1038,7 @@ static int irq_vfile_show(struct xnvfile_regular_iterator 
*it,
 
xnvfile_puts(it,   IRQ );
 
-   for_each_online_cpu(cpu)
+   for_each_realtime_cpu(cpu)
xnvfile_printf(it, CPU%d, cpu);
 
for (irq = 0; irq  IPIPE_NR_IRQS; irq++) {
@@ -1047,7 +1047,7 @@ static int irq_vfile_show(struct xnvfile_regular_iterator 
*it,
 
xnvfile_printf(it, \n%5d:, irq);
 
-   for_each_online_cpu(cpu) {
+   

[Xenomai-git] Philippe Gerum : cobalt/assert: group default debug levels in one place

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

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Aug  1 16:19:30 2013 +0200

cobalt/assert: group default debug levels in one place

---

 include/cobalt/kernel/assert.h |   22 +-
 include/cobalt/kernel/lock.h   |4 
 include/cobalt/kernel/synch.h  |4 
 include/rtdm/rtdm_driver.h |4 
 kernel/cobalt/posix/internal.h |4 
 kernel/cobalt/rtdm/internal.h  |4 
 6 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index cad72d0..dbca076 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -45,7 +45,27 @@
 
 #ifndef CONFIG_XENO_OPT_DEBUG_NUCLEUS
 #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0
-#endif /* CONFIG_XENO_OPT_DEBUG_NUCLEUS */
+#endif
+
+#ifndef CONFIG_XENO_OPT_DEBUG_XNLOCK
+#define CONFIG_XENO_OPT_DEBUG_XNLOCK 0
+#endif
+
+#ifndef CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX
+#define CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX 0
+#endif
+
+#ifndef CONFIG_XENO_OPT_DEBUG_RTDM
+#define CONFIG_XENO_OPT_DEBUG_RTDM 0
+#endif
+
+#ifndef CONFIG_XENO_OPT_DEBUG_RTDM_APPL
+#define CONFIG_XENO_OPT_DEBUG_RTDM_APPL0
+#endif
+
+#ifndef CONFIG_XENO_OPT_DEBUG_COBALT
+#define CONFIG_XENO_OPT_DEBUG_COBALT 0
+#endif
 
 void __xnsys_assert_failed(const char *file, int line, const char *msg);
 
diff --git a/include/cobalt/kernel/lock.h b/include/cobalt/kernel/lock.h
index 21f0047..ea7cfed 100644
--- a/include/cobalt/kernel/lock.h
+++ b/include/cobalt/kernel/lock.h
@@ -41,10 +41,6 @@ typedef unsigned long spl_t;
 #define splnone()   ipipe_unstall_head()
 #define spltest()   ipipe_test_head()
 
-#ifndef CONFIG_XENO_OPT_DEBUG_XNLOCK
-#define CONFIG_XENO_OPT_DEBUG_XNLOCK 0
-#endif
-
 #if XENO_DEBUG(XNLOCK)
 
 struct xnlock {
diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index a596ae3..ea93129 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -26,10 +26,6 @@
 #include cobalt/kernel/assert.h
 #include cobalt/kernel/timer.h
 
-#ifndef CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX
-#define CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX 0
-#endif /* CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX */
-
 #define XNSYNCH_CLAIMED 0x10   /* Claimed by other thread(s) w/ PIP */
 
 #define XNSYNCH_FLCLAIM XN_HANDLE_SPARE3 /* Corresponding bit in fast lock */
diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h
index f8acc9c..ae986ff 100644
--- a/include/rtdm/rtdm_driver.h
+++ b/include/rtdm/rtdm_driver.h
@@ -52,10 +52,6 @@
 #include asm-generic/xenomai/pci_ids.h
 #endif /* CONFIG_PCI */
 
-#ifndef CONFIG_XENO_OPT_DEBUG_RTDM
-#define CONFIG_XENO_OPT_DEBUG_RTDM 0
-#endif
-
 struct rtdm_dev_context;
 typedef struct xnselector rtdm_selector_t;
 enum rtdm_selecttype;
diff --git a/kernel/cobalt/posix/internal.h b/kernel/cobalt/posix/internal.h
index 45a8815..fbf6505 100644
--- a/kernel/cobalt/posix/internal.h
+++ b/kernel/cobalt/posix/internal.h
@@ -28,10 +28,6 @@
 #include process.h
 #include extension.h
 
-#ifndef CONFIG_XENO_OPT_DEBUG_COBALT
-#define CONFIG_XENO_OPT_DEBUG_COBALT 0
-#endif
-
 #define COBALT_MAGIC(n) (0x8686##n##n)
 #define COBALT_ANY_MAGIC COBALT_MAGIC(00)
 #define COBALT_THREAD_MAGIC  COBALT_MAGIC(01)
diff --git a/kernel/cobalt/rtdm/internal.h b/kernel/cobalt/rtdm/internal.h
index 35703f8..f953c55 100644
--- a/kernel/cobalt/rtdm/internal.h
+++ b/kernel/cobalt/rtdm/internal.h
@@ -27,10 +27,6 @@
 #include linux/list.h
 #include linux/sem.h
 
-#ifndef CONFIG_XENO_OPT_DEBUG_RTDM_APPL
-#define CONFIG_XENO_OPT_DEBUG_RTDM_APPL0
-#endif
-
 #define RTDM_FD_MAXCONFIG_XENO_OPT_RTDM_FILDES
 
 #define DEF_DEVNAME_HASHTAB_SIZE   256 /* entries in name hash table */


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


[Xenomai-git] Philippe Gerum : cobalt/posix/clock: introduce dynamic clock registration

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 15390f5b6dee09b83e52916f1cd919aa087f85a1
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=15390f5b6dee09b83e52916f1cd919aa087f85a1

Author: Philippe Gerum r...@xenomai.org
Date:   Fri Aug  2 05:07:18 2013 +0200

cobalt/posix/clock: introduce dynamic clock registration

This patch provides the infrastructure for defining new POSIX clocks
dynamically, in addition to the standard CLOCK_MONOTONIC* and
CLOCK_REALTIME ones.

The API boils down cobalt_clock_register() and
cobalt_clock_deregister(), which operate on a Cobalt clock (struct
xnclock) internally.

---

 include/cobalt/kernel/assert.h  |3 +
 include/cobalt/kernel/clock.h   |   43 +-
 include/cobalt/kernel/timer.h   |   73 ++---
 include/cobalt/uapi/time.h  |   18 ++-
 kernel/cobalt/clock.c   |   35 +++--
 kernel/cobalt/posix/clock.c |  141 +
 kernel/cobalt/posix/clock.h |   17 ++-
 kernel/cobalt/posix/extension.h |   24 ++--
 kernel/cobalt/posix/thread.c|   27 ++-
 kernel/cobalt/posix/thread.h|   21 ++-
 kernel/cobalt/posix/timer.c |  341 +++
 kernel/cobalt/posix/timer.h |6 +-
 kernel/cobalt/sched.c   |   12 +-
 kernel/cobalt/timer.c   |   32 +++-
 14 files changed, 498 insertions(+), 295 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index 4d4cf9f..f7fd7f0 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -73,6 +73,9 @@
 
 #define primary_mode_only()XENO_BUGON(CONTEXT, ipipe_root_p)
 #define secondary_mode_only()  XENO_BUGON(CONTEXT, !ipipe_root_p)
+#define interrupt_only()   XENO_BUGON(CONTEXT, !xnsched_interrupt_p())
+#define atomic_only()  XENO_BUGON(CONTEXT, (xnlock_is_owner(nklock) \
+ spltest()) == 0)
 
 void __xnsys_assert_failed(const char *file, int line, const char *msg);
 
diff --git a/include/cobalt/kernel/clock.h b/include/cobalt/kernel/clock.h
index a33bbc1..fbe74d9 100644
--- a/include/cobalt/kernel/clock.h
+++ b/include/cobalt/kernel/clock.h
@@ -36,13 +36,17 @@ struct xntimerdata;
 
 struct xnclock {
xnticks_t wallclock_offset;
-   struct xntimerdata *timerdata;
+   /** ns */
+   xnticks_t resolution;
+   /** raw clock ticks. */
unsigned long gravity;
const char *name;
 #ifdef CONFIG_XENO_OPT_EXTCLOCK
struct {
xnticks_t (*read_raw)(struct xnclock *clock);
xnticks_t (*read_monotonic)(struct xnclock *clock);
+   int (*set_time)(struct xnclock *clock,
+   const struct timespec *ts);
xnsticks_t (*ns_to_ticks)(struct xnclock *clock,
  xnsticks_t ns);
xnsticks_t (*ticks_to_ns)(struct xnclock *clock,
@@ -55,10 +59,13 @@ struct xnclock {
struct xnsched *sched);
} ops;
 #endif 
+   /* Private section. */
+   struct xntimerdata *timerdata;
+   int id;
 #ifdef CONFIG_XENO_OPT_STATS
struct xnvfile_snapshot vfile;
struct xnvfile_rev_tag revtag;
-   struct list_head timerq;
+   struct list_head statq;
int nrtimers;
 #endif /* CONFIG_XENO_OPT_STATS */
 };
@@ -103,7 +110,7 @@ static inline void xnclock_program_shot(struct xnclock 
*clock,
struct xnsched *sched)
 {
if (likely(clock == nkclock))
-   xnclock_core_local_shot(clock, sched);
+   xnclock_core_local_shot(sched);
else if (clock-ops.program_local_shot)
clock-ops.program_local_shot(clock, sched);
 }
@@ -113,7 +120,7 @@ static inline void xnclock_remote_shot(struct xnclock 
*clock,
 {
 #ifdef CONFIG_SMP
if (likely(clock == nkclock))
-   xnclock_core_remote_shot(clock, sched);
+   xnclock_core_remote_shot(sched);
else if (clock-ops.program_remote_shot)
clock-ops.program_remote_shot(clock, sched);
 #endif
@@ -162,6 +169,15 @@ static inline xnticks_t xnclock_read_monotonic(struct 
xnclock *clock)
return clock-ops.read_monotonic(clock);
 }
 
+static inline int xnclock_set_time(struct xnclock *clock,
+  const struct timespec *ts)
+{
+   if (likely(clock == nkclock))
+   return -EINVAL;
+
+   return clock-ops.set_time(clock, ts);
+}
+
 #else /* !CONFIG_XENO_OPT_EXTCLOCK */
 
 static inline void xnclock_program_shot(struct xnclock *clock,
@@ -206,6 +222,15 @@ static inline xnticks_t xnclock_read_monotonic(struct 
xnclock *clock)
return xnclock_core_read_monotonic();
 }
 
+static inline int xnclock_set_time(struct xnclock *clock,
+  const struct timespec *ts)
+{
+   /*
+* There is no way to change the core clock's idea of time.
+*/
+