Module: xenomai-gch
Branch: dovetail-tsc-emul
Commit: 1a283914b15945f4c08cda791714a336fd79d04e
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=1a283914b15945f4c08cda791714a336fd79d04e

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Thu Jun 30 09:56:31 2016 +0200

lib/cobalt: use linux vdso for clock_host_realtime

This means the architecture specific update_vsyscall has to be
hardened.

---

 configure.ac                                       |    5 ++++
 lib/cobalt/arch/arm/features.c                     |    3 +++
 .../arm/include/asm/xenomai/clock_host_realtime.h  |   27 ++++++++++++++++++++
 .../x86/include/asm/xenomai/clock_host_realtime.h  |   12 +++++++++
 lib/cobalt/clock.c                                 |   12 +++++++--
 5 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 42f2f5d..b2fc685 100644
--- a/configure.ac
+++ b/configure.ac
@@ -125,6 +125,7 @@ case "$build_for" in
        use_tls=yes
        XENO_TARGET_ARCH=x86
        CONFIG_XENO_DEFAULT_PERIOD=100000
+       CONFIG_XENO_HAVE_VDSO
        ;;
  ppc-*|powerpc-*|powerpc64-*|ppc64-*)
        use_tls=yes
@@ -138,6 +139,7 @@ case "$build_for" in
  arm*-*)
        XENO_TARGET_ARCH=arm
        CONFIG_XENO_DEFAULT_PERIOD=1000000
+       CONFIG_XENO_HAVE_VDSO
        ;;
  aarch64-*)
        XENO_TARGET_ARCH=arm64
@@ -147,6 +149,7 @@ case "$build_for" in
        use_tls=yes
        XENO_TARGET_ARCH=x86
        CONFIG_XENO_DEFAULT_PERIOD=100000
+       CONFIG_XENO_HAVE_VDSO
        ;;
  *) echo ""
    echo "*******************************************"
@@ -621,6 +624,8 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared" = 
'yes'])
 # Default sampling period (ns) used in various tests
 
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
 
+AC_DEFINE_UNQUOTED(CONFIG_XENO_HAVE_VDSO,$CONFIG_XENO_HAVE_VDSO,[config])
+
 dnl Allocator for Copperplate
 dnl Note: in dual kernel mode, we don't want malloc, no matter what.
 dnl We switch to malloc only over the Mercury core in debug mode, to ease
diff --git a/lib/cobalt/arch/arm/features.c b/lib/cobalt/arch/arm/features.c
index 24ff406..2d5096c 100644
--- a/lib/cobalt/arch/arm/features.c
+++ b/lib/cobalt/arch/arm/features.c
@@ -27,6 +27,7 @@
 #include <cobalt/wrappers.h>
 #include <asm/xenomai/syscall.h>
 #include <asm/xenomai/tsc.h>
+#include <asm/xenomai/clock_host_realtime.h>
 #include <asm/xenomai/features.h>
 #include <asm/xenomai/uapi/fptest.h>
 #include <sys/auxv.h>
@@ -34,6 +35,7 @@
 #include "internal.h"
 
 struct __xn_full_tscinfo __xn_tscinfo;
+__vdso_cgt_t *__xn_vdso_cgt;
 
 static void cobalt_parse_vdso(void)
 {
@@ -72,6 +74,7 @@ void cobalt_check_features(struct cobalt_featinfo *finfo)
        if (!__xn_tscinfo.vdso_tsc_get)
                early_panic("Invalid rdtsc\n");
 
+       __xn_vdso_cgt = cobalt_vdso_sym("LINUX_2.6", "__vdso_clock_gettime");
 }
 
 int cobalt_fp_detect(void)
diff --git a/lib/cobalt/arch/arm/include/asm/xenomai/clock_host_realtime.h 
b/lib/cobalt/arch/arm/include/asm/xenomai/clock_host_realtime.h
new file mode 100644
index 0000000..17c5c3c
--- /dev/null
+++ b/lib/cobalt/arch/arm/include/asm/xenomai/clock_host_realtime.h
@@ -0,0 +1,27 @@
+#ifndef _LIB_COBALT_ARM_CLOCK_HOST_REALTIME_H
+#define _LIB_COBALT_ARM_CLOCK_HOST_REALTIME_H
+
+#include <errno.h>
+
+typedef int __vdso_cgt_t(clockid_t, struct timespec *);
+extern __vdso_cgt_t *__xn_vdso_cgt;
+
+static inline int cobalt_clock_host_realtime(struct timespec *ts)
+{
+       int err;
+
+       if (!__xn_vdso_cgt) {
+               errno = ENOSYS;
+               return -1;
+       }
+
+       err = __xn_vdso_cgt(CLOCK_REALTIME, ts);
+       if (err < 0) {
+               errno = -err;
+               return -1;
+       }
+
+       return 0;
+}
+
+#endif /* _LIB_COBALT_ARM_CLOCK_HOST_REALTIME_H */
diff --git a/lib/cobalt/arch/x86/include/asm/xenomai/clock_host_realtime.h 
b/lib/cobalt/arch/x86/include/asm/xenomai/clock_host_realtime.h
new file mode 100644
index 0000000..13d99fa
--- /dev/null
+++ b/lib/cobalt/arch/x86/include/asm/xenomai/clock_host_realtime.h
@@ -0,0 +1,12 @@
+#ifndef _LIB_COBALT_X86_CLOCK_HOST_REALTIME_H
+#define _LIB_COBALT_X86_CLOCK_HOST_REALTIME_H
+
+#include <cobalt/wrappers.h>
+#include <time.h>
+
+static inline int cobalt_clock_host_realtime(struct timespec *ts)
+{
+       return __STD(clock_gettime(CLOCK_REALTIME, ts));
+}
+
+#endif /* _LIB_COBALT_X86_CLOCK_HOST_REALTIME_H */
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index 0450019..58fd9fe 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -30,6 +30,9 @@
 #include <cobalt/ticks.h>
 #include <asm/xenomai/syscall.h>
 #include <asm/xenomai/tsc.h>
+#ifdef CONFIG_XENO_HAVE_VDSO
+#include <asm/xenomai/clock_host_realtime.h>
+#endif
 #include "umm.h"
 #include "internal.h"
 
@@ -119,12 +122,12 @@ static int __do_clock_host_realtime(struct timespec *ts)
        urwstate_t tmp;
 
        if (!xnvdso_test_feature(cobalt_vdso, XNVDSO_FEAT_HOST_REALTIME))
-               return -1;
+               return -EPERM;
 
        hostrt_data = &cobalt_vdso->hostrt_data;
 
        if (!hostrt_data->live)
-               return -1;
+               return -EPERM;
 
        /*
         * The following is essentially a verbatim copy of the
@@ -186,6 +189,11 @@ COBALT_IMPL(int, clock_gettime, (clockid_t clock_id, 
struct timespec *tp))
 
        switch (clock_id) {
        case CLOCK_HOST_REALTIME:
+#ifdef CONFIG_XENO_HAVE_VDSO
+               ret = cobalt_clock_host_realtime(tp);
+               if (ret != -1 || errno != ENOSYS)
+                       return ret;
+#endif
                ret = __do_clock_host_realtime(tp);
                break;
        case CLOCK_MONOTONIC:


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

Reply via email to