Module: xenomai-forge
Branch: next
Commit: 937ead4abe6deb66b85e140a3a97ac88de88a3f8
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=937ead4abe6deb66b85e140a3a97ac88de88a3f8

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Aug 18 17:27:38 2014 +0200

cobalt/posix/clock: fix clock codes

We want all clock IDs to be usable in Cobalt calls receiving a clock
argument (i.e. standard, statically or dynamically defined extension
clocks). This change fixes up the clock identifier namespaces and
encoding accordingly.

---

 include/cobalt/uapi/thread.h    |    2 +-
 include/cobalt/uapi/time.h      |   18 ++++++++++--------
 kernel/cobalt/posix/clock.c     |    4 ++--
 testsuite/clocktest/clocktest.c |    4 ++--
 4 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/include/cobalt/uapi/thread.h b/include/cobalt/uapi/thread.h
index 94c378a..3264cdd 100644
--- a/include/cobalt/uapi/thread.h
+++ b/include/cobalt/uapi/thread.h
@@ -32,7 +32,7 @@ struct cobalt_mutexattr {
 };
 
 struct cobalt_condattr {
-       int clock : 3;
+       int clock : 6;
        int pshared : 2;
 };
 
diff --git a/include/cobalt/uapi/time.h b/include/cobalt/uapi/time.h
index 764c74c..10ad8ce 100644
--- a/include/cobalt/uapi/time.h
+++ b/include/cobalt/uapi/time.h
@@ -27,17 +27,19 @@
  * of the POSIX and Linux kernel definitions so that no ambiguities
  * arise when porting applications in both directions.
  *
- * The Cobalt API reserves the first 32 extended clock codes. for
- * dynamically registered clocks. Everything from
- * __COBALT_CLOCK_CODE(32) onward can be reserved statically for
- * whatever purpose.
+ * 0  .. 7   regular POSIX/linux clock ids.
+ * 8  .. 31  statically reserved Cobalt clocks
+ * 32 .. 63  dynamically registered Cobalt clocks (external)
  */
+#define __COBALT_CLOCK_STATIC(nr)      ((clockid_t)(nr + 8))
+
+#define CLOCK_HOST_REALTIME  __COBALT_CLOCK_STATIC(0)
+
 #define COBALT_MAX_EXTCLOCKS  32
-#define __COBALT_CLOCK_CODE(num)  ((clockid_t)((1 << 16)|num))
-#define __COBALT_CLOCK_INDEX(id)  ((int)(id) & ~(1 << 16))
-#define __COBALT_CLOCK_EXT_P(id)  ((int)(id) & (1 << 16))
 
-#define CLOCK_HOST_REALTIME  __COBALT_CLOCK_CODE(42)
+#define __COBALT_CLOCK_EXT(nr)         ((clockid_t)(nr) | (1 << 5))
+#define __COBALT_CLOCK_EXT_P(id)       ((int)(id) & (1 << 5))
+#define __COBALT_CLOCK_EXT_INDEX(id)   ((int)(id) & ~(1 << 5))
 
 /*
  * Additional timerfd defines
diff --git a/kernel/cobalt/posix/clock.c b/kernel/cobalt/posix/clock.c
index 269aa64..21c3e4c 100644
--- a/kernel/cobalt/posix/clock.c
+++ b/kernel/cobalt/posix/clock.c
@@ -90,7 +90,7 @@ static int do_clock_host_realtime(struct timespec *tp)
        if (!__COBALT_CLOCK_EXT_P(__clock_id))                  \
                __val = -EINVAL;                                \
        else {                                                  \
-               __nr = __COBALT_CLOCK_INDEX(__clock_id);        \
+               __nr = __COBALT_CLOCK_EXT_INDEX(__clock_id);    \
                xnlock_get_irqsave(&nklock, __s);               \
                if (!test_bit(__nr, cobalt_clock_extids)) {     \
                        xnlock_put_irqrestore(&nklock, __s);    \
@@ -280,7 +280,7 @@ int cobalt_clock_register(struct xnclock *clock, clockid_t 
*clk_id)
                return ret;
 
        clock->id = nr;
-       *clk_id = __COBALT_CLOCK_CODE(clock->id);
+       *clk_id = __COBALT_CLOCK_EXT(clock->id);
 
        trace_cobalt_clock_register(clock->name, *clk_id);
 
diff --git a/testsuite/clocktest/clocktest.c b/testsuite/clocktest/clocktest.c
index cea8de3..267469e 100644
--- a/testsuite/clocktest/clocktest.c
+++ b/testsuite/clocktest/clocktest.c
@@ -283,7 +283,7 @@ int main(int argc, char *argv[])
        init_lock(&lock);
 
        if (ext)
-               clock_id = __COBALT_CLOCK_CODE(clock_id);
+               clock_id = __COBALT_CLOCK_EXT(clock_id);
        if (d && clock_id == CLOCK_HOST_REALTIME)
                show_hostrt_diagnostics();
 
@@ -301,7 +301,7 @@ int main(int argc, char *argv[])
        }
 
        printf("== Tested %sclock: %d (", ext ? "extension " : "",
-              __COBALT_CLOCK_INDEX(clock_id));
+              __COBALT_CLOCK_EXT_INDEX(clock_id));
        switch (clock_id) {
        case CLOCK_REALTIME:
                printf("CLOCK_REALTIME");


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

Reply via email to