[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 
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.
+*/
+  

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

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

Author: Philippe Gerum 
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.
+*/
+   r

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

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

Author: Philippe Gerum 
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   |   41 +-
 include/cobalt/uapi/time.h  |   18 ++-
 kernel/cobalt/clock.c   |2 +
 kernel/cobalt/posix/clock.c |  139 +
 kernel/cobalt/posix/clock.h |   17 ++-
 kernel/cobalt/posix/extension.h |   38 --
 kernel/cobalt/posix/thread.c|   27 ++-
 kernel/cobalt/posix/thread.h|5 +-
 kernel/cobalt/posix/timer.c |  341 +++
 kernel/cobalt/posix/timer.h |6 +-
 kernel/cobalt/timer.c   |2 +-
 12 files changed, 399 insertions(+), 240 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 716655d..03165e8 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,6 +59,9 @@ 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;
@@ -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.
+*/
+   return -EINVAL;
+}
+
 #endif /* !CONFIG_XENO_OPT_EXTCLOCK */
 
 static inline xnticks_t xnclock_get_offset(struct xnclock *clock)
@@ -213,6 +238,16 @@ static inline xnticks_t xnclock_get_offset(struct xnclock 
*clock)
re