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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Sep  8 10:35:19 2014 +0200

cobalt/vdso, lib/cobalt: make vdso data 32/64bit-neutral

---

 include/cobalt/uapi/kernel/urw.h  |   10 ++++++----
 include/cobalt/uapi/kernel/vdso.h |   29 ++++++++++++++---------------
 kernel/cobalt/posix/clock.c       |    4 +++-
 lib/cobalt/clock.c                |    8 +++++---
 testsuite/clocktest/clocktest.c   |   23 ++++++++++++-----------
 5 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/include/cobalt/uapi/kernel/urw.h b/include/cobalt/uapi/kernel/urw.h
index 5083214..40a1eb5 100644
--- a/include/cobalt/uapi/kernel/urw.h
+++ b/include/cobalt/uapi/kernel/urw.h
@@ -18,6 +18,8 @@
 #ifndef _COBALT_UAPI_KERNEL_URW_H
 #define _COBALT_UAPI_KERNEL_URW_H
 
+#include <linux/types.h>
+
 /*
  * A restricted version of the kernel seqlocks with a slightly
  * different interface, allowing for unsynced reads with concurrent
@@ -40,12 +42,12 @@
  */
 
 typedef struct {
-       unsigned int sequence;
+       __u32 sequence;
 } urw_t;
 
 typedef struct {
-       unsigned int token;
-       int dirty;
+       __u32 token;
+       __u32 dirty;
 } urwstate_t;
 
 #define URW_INITIALIZER     { 0 }
@@ -53,7 +55,7 @@ typedef struct {
 
 static inline void __try_read_start(const urw_t *urw, urwstate_t *tmp)
 {
-       unsigned int token;
+       __u32 token;
 repeat:
        token = ACCESS_ONCE(urw->sequence);
        smp_rmb();
diff --git a/include/cobalt/uapi/kernel/vdso.h 
b/include/cobalt/uapi/kernel/vdso.h
index 9146873..d2ef159 100644
--- a/include/cobalt/uapi/kernel/vdso.h
+++ b/include/cobalt/uapi/kernel/vdso.h
@@ -21,30 +21,29 @@
 #include <cobalt/uapi/kernel/urw.h>
 
 struct xnvdso_hostrt_data {
-       short live;
+       __u16 live;
        urw_t lock;
-       time_t wall_time_sec;
-       unsigned int wall_time_nsec;
+       __u64 wall_time_sec;
+       __u32 wall_time_nsec;
        struct timespec wall_to_monotonic;
-       unsigned long long cycle_last;
-       unsigned long long mask;
-       unsigned int mult;
-       unsigned int shift;
+       __u64 cycle_last;
+       __u64 mask;
+       __u32 mult;
+       __u32 shift;
 };
 
 /*
- * Data shared between Xenomai kernel/userland and the Linux
- * kernel/userland on the global semaphore heap. The features element
- * indicates which data are shared. Notice that struct xnvdso may only
- * grow, but never shrink.
+ * Data shared between the Cobalt kernel and applications, which lives
+ * in the shared memory heap (COBALT_MEMDEV_SHARED).
+ * xnvdso_hostrt_data.features tells which data is present. Notice
+ * that struct xnvdso may only grow, but never shrink.
  */
 struct xnvdso {
-       unsigned long long features;
-
+       __u64 features;
        /* XNVDSO_FEAT_HOST_REALTIME */
        struct xnvdso_hostrt_data hostrt_data;
        /* XNVDSO_FEAT_WALLCLOCK_OFFSET */
-       unsigned long long wallclock_offset;
+       __u64 wallclock_offset;
 };
 
 /* For each shared feature, add a flag below. */
@@ -53,7 +52,7 @@ struct xnvdso {
 #define XNVDSO_FEAT_WALLCLOCK_OFFSET   0x0000000000000002ULL
 
 static inline int xnvdso_test_feature(struct xnvdso *vdso,
-                                     unsigned long long feature)
+                                     __u64 feature)
 {
        return (vdso->features & feature) != 0;
 }
diff --git a/kernel/cobalt/posix/clock.c b/kernel/cobalt/posix/clock.c
index 09e4d8b..28dd18f 100644
--- a/kernel/cobalt/posix/clock.c
+++ b/kernel/cobalt/posix/clock.c
@@ -34,8 +34,10 @@ static int do_clock_host_realtime(struct timespec *tp)
 #ifdef CONFIG_XENO_OPT_HOSTRT
        struct xnvdso_hostrt_data *hostrt_data;
        cycle_t now, base, mask, cycle_delta;
-       unsigned long mult, shift, nsec, rem;
+       __u32 mult, shift;
+       unsigned long rem;
        urwstate_t tmp;
+       __u64 nsec;
 
        hostrt_data = get_hostrt_data();
        BUG_ON(!hostrt_data);
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index fb93eb5..682c9cb 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <stdint.h>
 #include <pthread.h>
 #include <unistd.h>
 #include <time.h>
@@ -109,9 +110,10 @@ COBALT_IMPL(int, clock_getres, (clockid_t clock_id, struct 
timespec *tp))
 
 static int __do_clock_host_realtime(struct timespec *ts)
 {
-       unsigned long long now, base, mask, cycle_delta;
+       uint64_t now, base, mask, cycle_delta, nsec;
        struct xnvdso_hostrt_data *hostrt_data;
-       unsigned long mult, shift, nsec, rem;
+       uint32_t mult, shift;
+       unsigned long rem;
        urwstate_t tmp;
 
        if (!xnvdso_test_feature(vdso, XNVDSO_FEAT_HOST_REALTIME))
@@ -175,8 +177,8 @@ static int __do_clock_host_realtime(struct timespec *ts)
  */
 COBALT_IMPL(int, clock_gettime, (clockid_t clock_id, struct timespec *tp))
 {
-       unsigned long long ns;
        unsigned long rem;
+       xnticks_t ns;
        int ret;
 
        switch (clock_id) {
diff --git a/testsuite/clocktest/clocktest.c b/testsuite/clocktest/clocktest.c
index 96d83fc..56260c5 100644
--- a/testsuite/clocktest/clocktest.c
+++ b/testsuite/clocktest/clocktest.c
@@ -67,16 +67,16 @@ pthread_mutex_t lock;
 #define acquire_lock(lock)                     pthread_mutex_lock(lock)
 #define release_lock(lock)                     pthread_mutex_unlock(lock)
 #endif
-unsigned long long last_common = 0;
+uint64_t last_common = 0;
 clockid_t clock_id = CLOCK_REALTIME;
 
 struct per_cpu_data {
-       unsigned long long first_tod, first_clock;
+       uint64_t first_tod, first_clock;
        int first_round;
-       long long offset;
+       int64_t offset;
        double drift;
        unsigned long warps;
-       unsigned long long max_warp;
+       uint64_t max_warp;
        pthread_t thread;
 } *per_cpu_data;
 
@@ -96,7 +96,8 @@ static void show_hostrt_diagnostics(void)
 
        printf("Sequence counter : %u\n",
               vdso->hostrt_data.lock.sequence);
-       printf("wall_time_sec    : %ld\n", vdso->hostrt_data.wall_time_sec);
+       printf("wall_time_sec    : %lld\n",
+              (unsigned long long)vdso->hostrt_data.wall_time_sec);
        printf("wall_time_nsec   : %u\n", vdso->hostrt_data.wall_time_nsec);
        printf("wall_to_monotonic\n");
        printf("          tv_sec : %jd\n",
@@ -119,7 +120,7 @@ static void show_realtime_offset(void)
        printf("Wallclock offset : %llu\n", vdso->wallclock_offset);
 }
 
-static inline unsigned long long read_clock(clockid_t clock_id)
+static inline uint64_t read_clock(clockid_t clock_id)
 {
        struct timespec ts;
        int res;
@@ -138,7 +139,7 @@ static inline unsigned long long read_clock(clockid_t 
clock_id)
        return ts.tv_nsec + ts.tv_sec * 1000000000ULL;
 }
 
-static inline unsigned long long read_reference_clock(void)
+static inline uint64_t read_reference_clock(void)
 {
        struct timeval tv;
 
@@ -152,8 +153,8 @@ static inline unsigned long long read_reference_clock(void)
 
 static void check_reference(struct per_cpu_data *per_cpu_data)
 {
-       unsigned long long clock_val[10], tod_val[10];
-       long long delta, min_delta;
+       uint64_t clock_val[10], tod_val[10];
+       int64_t delta, min_delta;
        int i, idx;
 
        for (i = 0; i < 10; i++) {
@@ -188,8 +189,8 @@ static void check_reference(struct per_cpu_data 
*per_cpu_data)
 static void check_time_warps(struct per_cpu_data *per_cpu_data)
 {
        int i;
-       unsigned long long last, now;
-       long long incr;
+       uint64_t last, now;
+       int64_t incr;
 
        for (i = 0; i < 100; i++) {
                acquire_lock(&lock);


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

Reply via email to