[Xenomai-git] Jan Kiszka : RTDM: Plug race between proc_read_dev_info and device deregistration

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: 39e0775d6109fcb39b942718a5f609ea0e775e0c
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=39e0775d6109fcb39b942718a5f609ea0e775e0c

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Fri Aug 20 14:42:07 2010 +0200

RTDM: Plug race between proc_read_dev_info and device deregistration

As the device references passed to proc_read_dev_info may become invalid
while we dereference it, we need to acquire nrt_dev_lock and check the
pointer against our list of registered devices.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 ksrc/skins/rtdm/proc.c |   27 ---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/ksrc/skins/rtdm/proc.c b/ksrc/skins/rtdm/proc.c
index a3e708f..cd6802c 100644
--- a/ksrc/skins/rtdm/proc.c
+++ b/ksrc/skins/rtdm/proc.c
@@ -305,12 +305,32 @@ static struct xnvfile_regular allfd_vfile = {
 
 static int devinfo_vfile_show(struct xnvfile_regular_iterator *it, void *data)
 {
-   struct rtdm_device *device = xnvfile_priv(it-vfile);
+   struct rtdm_device *device;
+   int i;
+
+   if (down_interruptible(nrt_dev_lock))
+   return -ERESTARTSYS;
 
/*
-* Accessing the device during unregister (remove_proc_entry) might be
-* racy, but no official workaround is known yet.
+* As the device may have disappeared while the handler was called,
+* first match the pointer against registered devices.
 */
+   for (i = 0; i  devname_hashtab_size; i++)
+   list_for_each_entry(device, rtdm_named_devices[i],
+   reserved.entry)
+   if (device == xnvfile_priv(it-vfile))
+   goto found;
+
+   for (i = 0; i  protocol_hashtab_size; i++)
+   list_for_each_entry(device, rtdm_protocol_devices[i],
+   reserved.entry)
+   if (device == xnvfile_priv(it-vfile))
+   goto found;
+
+   up(nrt_dev_lock);
+   return -ENODEV;
+
+found:
xnvfile_printf(it, driver:\t\t%s\nversion:\t%d.%d.%d\n,
   device-driver_name,
   RTDM_DRIVER_MAJOR_VER(device-driver_version),
@@ -334,6 +354,7 @@ static int devinfo_vfile_show(struct 
xnvfile_regular_iterator *it, void *data)
xnvfile_printf(it, lock count:\t%d\n,
   atomic_read(device-reserved.refcount));
 
+   up(nrt_dev_lock);
return 0;
 }
 


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Wolfgang Mauerer : nucleus: Spelling fix for check-vdso.c

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: f0971d3a77b07c8f17347f03a9721fb4e3154d60
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=f0971d3a77b07c8f17347f03a9721fb4e3154d60

Author: Wolfgang Mauerer wolfgang.maue...@siemens.com
Date:   Thu Jul  8 12:18:15 2010 +0200

nucleus: Spelling fix for check-vdso.c

Signed-off-by: Wolfgang Mauerer wolfgang.maue...@siemens.com
Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 src/testsuite/unit/check-vdso.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/testsuite/unit/check-vdso.c b/src/testsuite/unit/check-vdso.c
index 8f90420..17684de 100644
--- a/src/testsuite/unit/check-vdso.c
+++ b/src/testsuite/unit/check-vdso.c
@@ -15,7 +15,7 @@ int main(int argc, char **argv)
unsigned long long test_features;
 
if (argc != 2) {
-   printf(No specific feature(s) given, using XNVDSO_FEATURE\n);
+   printf(No specific feature(s) given, using XNVDSO_FEATURES\n);
test_features = XNVDSO_FEATURES;
} else {
test_features = strtoull(argv[1], NULL, 0);


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : nucleus: Fix lock imbalance in registry_proc_callback

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: edce5551f514641eaa828a97accc3eefebf60443
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=edce5551f514641eaa828a97accc3eefebf60443

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Tue Aug 24 16:14:04 2010 +0200

nucleus: Fix lock imbalance in registry_proc_callback

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 ksrc/nucleus/registry.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/ksrc/nucleus/registry.c b/ksrc/nucleus/registry.c
index 9a6f66e..01d2f6a 100644
--- a/ksrc/nucleus/registry.c
+++ b/ksrc/nucleus/registry.c
@@ -303,7 +303,8 @@ static DECLARE_WORK_FUNC(registry_proc_callback)
xnvfile_destroy_dir(rdir);
xnlock_get_irqsave(nklock, s);
object-pnode = NULL;
-   }
+   } else
+   xnlock_get_irqsave(nklock, s);
 
continue;
 


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : rt_print: Properly return printed length

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: cd3804dd06df4633f1866221f7ccb472b333b91c
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=cd3804dd06df4633f1866221f7ccb472b333b91c

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Fri Jun  4 14:30:16 2010 +0200

rt_print: Properly return printed length

When rt_print is truncating an output chunk longer than
RT_PRINT_LINE_BREAK, it currently does not return the actually printed
length but the string length. Align this to normal printf which returns
the written length.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 src/rtdk/rt_print.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/rtdk/rt_print.c b/src/rtdk/rt_print.c
index ca948df..93b711a 100644
--- a/src/rtdk/rt_print.c
+++ b/src/rtdk/rt_print.c
@@ -150,6 +150,7 @@ static int print_to_buffer(FILE *stream, int priority, 
const char *format,
/* Text was truncated, remove closing \0 that entry_head
   already includes */
len--;
+   res = len;
}
 
/* If we were able to write some text, finalise the entry */


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : RTDM: Extend device name space in open_fildes proc output

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: fbde18795f71eff4c1bb323abd1c32039ca4aa12
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=fbde18795f71eff4c1bb323abd1c32039ca4aa12

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Fri Aug 20 14:51:18 2010 +0200

RTDM: Extend device name space in open_fildes proc output

Device names can be up to 31 characters long.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 ksrc/skins/rtdm/proc.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/ksrc/skins/rtdm/proc.c b/ksrc/skins/rtdm/proc.c
index f898608..4c91368 100644
--- a/ksrc/skins/rtdm/proc.c
+++ b/ksrc/skins/rtdm/proc.c
@@ -227,7 +227,7 @@ static int openfd_show(struct xnvfile_regular_iterator *it, 
void *data)
spl_t s;
 
if (data == NULL) {
-   xnvfile_puts(it, Index\tLocked\tDevice\t\tOwner [PID]\n);
+   xnvfile_puts(it, Index\tLocked\tDevice\t\t\t\tOwner [PID]\n);
return 0;
}
 
@@ -252,7 +252,7 @@ static int openfd_show(struct xnvfile_regular_iterator *it, 
void *data)
 
xnlock_put_irqrestore(rt_fildes_lock, s);
 
-   xnvfile_printf(it, %d\t%d\t%-15s %s [%d]\n, fd,
+   xnvfile_printf(it, %d\t%d\t%-31s %s [%d]\n, fd,
   close_lock_count,
   (device-device_flags  RTDM_NAMED_DEVICE) ?
   device-device_name : device-proc_name,


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : RTDM: Properly clean up on xnvfile setup errors

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: 8533bdf94108da73278cb6300cc15a1d8dde68cc
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=8533bdf94108da73278cb6300cc15a1d8dde68cc

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Fri Aug 20 14:44:40 2010 +0200

RTDM: Properly clean up on xnvfile setup errors

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 ksrc/skins/rtdm/proc.c |   14 +-
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/ksrc/skins/rtdm/proc.c b/ksrc/skins/rtdm/proc.c
index cd6802c..f898608 100644
--- a/ksrc/skins/rtdm/proc.c
+++ b/ksrc/skins/rtdm/proc.c
@@ -403,25 +403,29 @@ int __init rtdm_proc_init(void)
/* Initialise vfiles */
ret = xnvfile_init_dir(rtdm, rtdm_vfroot, nkvfroot);
if (ret)
-   return ret;
+   goto error;
 
ret = xnvfile_init_regular(named_devices, named_vfile, rtdm_vfroot);
if (ret)
-   return ret;
+   goto error;
 
ret = xnvfile_init_regular(protocol_devices, proto_vfile, 
rtdm_vfroot);
if (ret)
-   return ret;
+   goto error;
 
ret = xnvfile_init_regular(open_fildes, openfd_vfile, rtdm_vfroot);
if (ret)
-   return ret;
+   goto error;
 
ret = xnvfile_init_regular(fildes, allfd_vfile, rtdm_vfroot);
if (ret)
-   return ret;
+   goto error;
 
return 0;
+
+error:
+   rtdm_proc_cleanup();
+   return ret;
 }
 
 void rtdm_proc_cleanup(void)


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Wolfgang Mauerer : nucleus: Infrastructure for CLOCK_HOST_REALTIME

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: 5128a05e42270e2d6b1a5038efb88ea81d539e1c
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=5128a05e42270e2d6b1a5038efb88ea81d539e1c

Author: Wolfgang Mauerer wolfgang.maue...@siemens.com
Date:   Thu Jul  8 12:18:17 2010 +0200

nucleus: Infrastructure for CLOCK_HOST_REALTIME

Augment the shared vdso page with all data required to
implement a clock CLOCK_HOST_REALTIME that provides time
information synchronised with the NTP-corrected time
in the Linux kernel. Data exchange between Linux and
Xenomai is handled via an ipipe event.

Additionally, the patch creates an instance of struct xnvdso
independently of pervasive rt support. This avoids repeating
the definitions for hostrt in both cases.

Signed-off-by: Wolfgang Mauerer wolfgang.maue...@siemens.com
Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 include/asm-generic/hal.h|   11 +++
 include/asm-generic/system.h |3 ++
 include/asm-sim/system.h |3 ++
 include/nucleus/Makefile.am  |1 +
 include/nucleus/hostrt.h |   54 +++
 include/nucleus/vdso.h   |   20 +++--
 ksrc/nucleus/Kconfig |4 ++
 ksrc/nucleus/module.c|   64 +++--
 8 files changed, 153 insertions(+), 7 deletions(-)

diff --git a/include/asm-generic/hal.h b/include/asm-generic/hal.h
index f964939..8c2b825 100644
--- a/include/asm-generic/hal.h
+++ b/include/asm-generic/hal.h
@@ -295,6 +295,14 @@ static int hdlr(unsigned event, struct ipipe_domain *ipd, 
void *data) \
return RTHAL_EVENT_PROPAGATE; \
 }
 
+#define RTHAL_DECLARE_HOSTRT_EVENT(hdlr) \
+static int hdlr(unsigned event, struct ipipe_domain *ipd, void *data) \
+{\
+   struct rthal_hostrt_data *hostrt = data;  \
+   do_##hdlr(hostrt);\
+   return RTHAL_EVENT_PROPAGATE; \
+}
+
 #ifndef TASK_ATOMICSWITCH
 #ifdef CONFIG_PREEMPT
 /* We want this feature for preemptible kernels, or the behaviour when
@@ -354,6 +362,8 @@ static inline void rthal_enable_notifier(struct task_struct 
*p)
 ipipe_catch_event(rthal_domain,IPIPE_EVENT_SYSCALL,hdlr)
 #define rthal_catch_exception(ex,hdlr) \
 ipipe_catch_event(rthal_domain,ex|IPIPE_EVENT_SELF,hdlr)
+#define rthal_catch_hostrt(hdlr)   \
+ipipe_catch_event(ipipe_root_domain, IPIPE_EVENT_HOSTRT, hdlr)
 
 #ifdef IPIPE_EVENT_RETURN
 #define RTHAL_HAVE_RETURN_EVENT
@@ -692,6 +702,7 @@ static inline int rthal_trace_panic_dump(void)
 
 #endif /* CONFIG_IPIPE_TRACE */
 
+#define rthal_hostrt_data  ipipe_hostrt_data
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/include/asm-generic/system.h b/include/asm-generic/system.h
index 4b5ce95..dd2282f 100644
--- a/include/asm-generic/system.h
+++ b/include/asm-generic/system.h
@@ -491,4 +491,7 @@ static inline void xnarch_hisyscall_entry(void) { }
 #define xnarch_post_graph(obj,state)
 #define xnarch_post_graph_if(obj,state,cond)
 
+/* Synchronised realtime clock*/
+#define xnarch_hostrt_data rthal_hostrt_data
+
 #endif /* !_XENO_ASM_GENERIC_SYSTEM_H */
diff --git a/include/asm-sim/system.h b/include/asm-sim/system.h
index 1a5a875..de24a3b 100644
--- a/include/asm-sim/system.h
+++ b/include/asm-sim/system.h
@@ -598,4 +598,7 @@ static inline long IS_ERR(const void *ptr)
return IS_ERR_VALUE((unsigned long)ptr);
 }
 
+/* Host realtime support is not supported in the simulator */
+struct xnarch_hostrt_data { };
+
 #endif /* !_XENO_ASM_SIM_SYSTEM_H */
diff --git a/include/nucleus/Makefile.am b/include/nucleus/Makefile.am
index 3a6a024..b04d7f6 100644
--- a/include/nucleus/Makefile.am
+++ b/include/nucleus/Makefile.am
@@ -6,6 +6,7 @@ includesub_HEADERS = \
bufd.h \
compiler.h \
heap.h \
+   hostrt.h \
intr.h \
jhash.h \
map.h \
diff --git a/include/nucleus/hostrt.h b/include/nucleus/hostrt.h
new file mode 100644
index 000..70ffbfe
--- /dev/null
+++ b/include/nucleus/hostrt.h
@@ -0,0 +1,54 @@
+#ifndef _XENO_NUCLEUS_HOSTRT_H
+#define _XENO_NUCLEUS_HOSTRT_H
+
+/*!\file hostrt.h
+ * \brief Definitions for global semaphore heap shared objects
+ * \author Wolfgang Mauerer
+ *
+ * Copyright (C) 2010 Wolfgang Mauerer wolfgang.maue...@siemens.com.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You 

[Xenomai-git] Wolfgang Mauerer : nucleus: Add userland cpu_relax() definition for x86

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: ad70240cc91c5b3959fd093270fca61eb1c17ecc
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=ad70240cc91c5b3959fd093270fca61eb1c17ecc

Author: Wolfgang Mauerer wolfgang.maue...@siemens.com
Date:   Thu Jul  8 12:18:16 2010 +0200

nucleus: Add userland cpu_relax() definition for x86

Signed-off-by: Wolfgang Mauerer wolfgang.maue...@siemens.com
Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 include/asm-x86/atomic.h |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/include/asm-x86/atomic.h b/include/asm-x86/atomic.h
index bb3ce46..16bc990 100644
--- a/include/asm-x86/atomic.h
+++ b/include/asm-x86/atomic.h
@@ -71,6 +71,11 @@ typedef struct { unsigned long counter; } xnarch_atomic_t;
 
 #define xnarch_write_memory_barrier()  xnarch_memory_barrier()
 
+static inline void cpu_relax(void)
+{
+   asm volatile(rep; nop ::: memory);
+}
+
 #ifdef __i386__
 
 struct __xeno_xchg_dummy { unsigned long a[100]; };


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Wolfgang Mauerer : Update clocktest for CLOCK_HOST_REALTIME

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: 53334a2fa4b806938870c17fd9e134da1a039bee
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=53334a2fa4b806938870c17fd9e134da1a039bee

Author: Wolfgang Mauerer wolfgang.maue...@siemens.com
Date:   Thu Jul  8 12:18:21 2010 +0200

Update clocktest for CLOCK_HOST_REALTIME

Signed-off-by: Wolfgang Mauerer wolfgang.maue...@siemens.com
Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 src/testsuite/clocktest/clocktest.c |   64 ---
 1 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/src/testsuite/clocktest/clocktest.c 
b/src/testsuite/clocktest/clocktest.c
index 7f29c23..bf4feb6 100644
--- a/src/testsuite/clocktest/clocktest.c
+++ b/src/testsuite/clocktest/clocktest.c
@@ -28,6 +28,7 @@
 #include sys/syscall.h
 #include sys/mman.h
 #include sys/time.h
+#include nucleus/vdso.h
 
 #include xeno_config.h
 
@@ -75,11 +76,49 @@ struct per_cpu_data {
pthread_t thread;
 } *per_cpu_data;
 
+static void show_hostrt_diagnostics(void)
+{
+   if (!xnvdso_test_feature(XNVDSO_FEAT_HOST_REALTIME)) {
+   printf(XNVDSO_FEAT_HOST_REALTIME not available\n);
+   return;
+   }
+
+   if (nkvdso-hostrt_data.live)
+   printf(hostrt data area is live\n);
+   else {
+   printf(hostrt data area is not live\n);
+   return;
+   }
+
+   printf(Sequence counter : %u\n,
+  nkvdso-hostrt_data.seqcount.sequence);
+   printf(wall_time_sec: %ld\n, nkvdso-hostrt_data.wall_time_sec);
+   printf(wall_time_nsec   : %u\n, nkvdso-hostrt_data.wall_time_nsec);
+   printf(wall_to_monotonic\n);
+   printf(  tv_sec : %jd\n,
+  (intmax_t)nkvdso-hostrt_data.wall_to_monotonic.tv_sec);
+   printf( tv_nsec : %ld\n,
+  nkvdso-hostrt_data.wall_to_monotonic.tv_nsec);
+   printf(cycle_last   : %lu\n, nkvdso-hostrt_data.cycle_last);
+   printf(mask : 0x%lx\n, nkvdso-hostrt_data.mask);
+   printf(mult : %u\n, nkvdso-hostrt_data.mult);
+   printf(shift: %u\n\n, nkvdso-hostrt_data.shift);
+}
+
 static inline unsigned long long read_clock(clockid_t clock_id)
 {
struct timespec ts;
+   int res;
 
-   clock_gettime(clock_id, ts);
+   res = clock_gettime(clock_id, ts);
+   if (res != 0) {
+   fprintf(stderr, clock_gettime failed for clock id %d\n,
+   clock_id);
+   if (clock_id == CLOCK_HOST_REALTIME)
+   show_hostrt_diagnostics();
+
+   exit(-1);
+   }
return ts.tv_nsec + ts.tv_sec * 10ULL;
 }
 
@@ -87,8 +126,10 @@ static inline unsigned long long read_reference_clock(void)
 {
struct timeval tv;
 
-   /* Make sure we do not pick the vsyscall variant. It won't
-  switch us into secondary mode and can easily deadlock. */
+   /*
+* Make sure we do not pick the vsyscall variant. It won't
+* switch us into secondary mode and can easily deadlock.
+*/
syscall(SYS_gettimeofday, tv, NULL);
return tv.tv_usec * 1000ULL + tv.tv_sec * 10ULL;
 }
@@ -186,8 +227,9 @@ int main(int argc, char *argv[])
int cpus = sysconf(_SC_NPROCESSORS_ONLN);
int i;
int c;
+   int d = 0;
 
-   while ((c = getopt(argc, argv, C:T:)) != EOF)
+   while ((c = getopt(argc, argv, C:T:D)) != EOF)
switch (c) {
case 'C':
clock_id = atoi(optarg);
@@ -197,10 +239,15 @@ int main(int argc, char *argv[])
alarm(atoi(optarg));
break;
 
+   case 'D':
+   d = 1;
+   break;
+
default:
fprintf(stderr, usage: clocktest [options]\n
  [-C clock_id]  # tested clock, 
default=%d (CLOCK_REALTIME)\n
- [-T test_duration_seconds] # default=0, so 
^C to end\n,
+ [-T test_duration_seconds] # default=0, so 
^C to end\n
+ [-D] # print extra 
diagnostics for CLOCK_HOST_REALTIME\n,
CLOCK_REALTIME);
exit(2);
}
@@ -211,6 +258,9 @@ int main(int argc, char *argv[])
 
init_lock(lock);
 
+   if (d  clock_id == CLOCK_HOST_REALTIME)
+   show_hostrt_diagnostics();
+
per_cpu_data = malloc(sizeof(*per_cpu_data) * cpus);
if (!per_cpu_data) {
fprintf(stderr, %s\n, strerror(ENOMEM));
@@ -234,6 +284,10 @@ int main(int argc, char *argv[])
printf(CLOCK_MONOTONIC);
break;
 
+   case CLOCK_HOST_REALTIME:
+   printf(CLOCK_HOST_REALTIME);
+   break;
+
 default:
   

[Xenomai-git] Wolfgang Mauerer : posix: Support reading the host realtime clock in realtime context

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: 4fe8edd7442c4f8c94f7a77783ec45b16fd107dd
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=4fe8edd7442c4f8c94f7a77783ec45b16fd107dd

Author: Wolfgang Mauerer wolfgang.maue...@siemens.com
Date:   Thu Jul  8 12:18:18 2010 +0200

posix: Support reading the host realtime clock in realtime context

Wall time management is typically assisted by the NTP
protocol in the Linux context, but this information is
not propagated to Xenomai. This patch adds support
for a CLOCK_HOST_REALTIME clock id that is coupled to the
host operating system's realtime clock. The required
information from the Kernel into Xenomai. The data exchange
is designed to allow for lockless reading from userland.

Signed-off-by: Wolfgang Mauerer wolfgang.maue...@siemens.com
Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 include/posix/time.h |7 
 ksrc/skins/posix/clock.c |   86 +-
 2 files changed, 92 insertions(+), 1 deletions(-)

diff --git a/include/posix/time.h b/include/posix/time.h
index 4f2d760..92ec1d5 100644
--- a/include/posix/time.h
+++ b/include/posix/time.h
@@ -50,6 +50,13 @@
 #define CLOCK_MONOTONIC 1
 #endif /* CLOCK_MONOTONIC */
 
+/*
+ * This number is supposed to not collide with any of the POSIX and
+ * Linux kernel definitions so that no ambiguities arise when porting
+ * applications in both directions.
+ */
+#define CLOCK_HOST_REALTIME 42
+
 #if defined(__KERNEL__) || defined(__XENO_SIM__)
 
 struct sigevent;
diff --git a/ksrc/skins/posix/clock.c b/ksrc/skins/posix/clock.c
index 553e123..62493f1 100644
--- a/ksrc/skins/posix/clock.c
+++ b/ksrc/skins/posix/clock.c
@@ -50,6 +50,9 @@
  *...@{*/
 
 #include posix/thread.h
+#include nucleus/vdso.h
+#include asm-generic/xenomai/arith.h
+#include asm-generic/xenomai/system.h
 
 /**
  * Get the resolution of the specified clock.
@@ -88,6 +91,76 @@ int clock_getres(clockid_t clock_id, struct timespec *res)
 }
 
 /**
+ * Read the host-synchronised realtime clock.
+ *
+ * Obtain the current time with NTP corrections from the Linux domain
+ *
+ * @param tp pointer to a struct timespec
+ *
+ * @retval 0 on success;
+ * @retval -1 if no suitable NTP-corrected clocksource is availabel
+ *
+ * @see
+ * a 
href=http://www.opengroup.org/onlinepubs/95399/functions/gettimeofday.html;
+ * Specification./a
+ *
+ */
+static int do_clock_host_realtime(struct timespec *tp)
+{
+#ifdef CONFIG_XENO_OPT_HOSTRT
+   cycle_t now, base, mask, cycle_delta;
+   unsigned long mult, shift, nsec, rem;
+   struct xnarch_hostrt_data *hostrt_data;
+   unsigned int seq;
+
+   hostrt_data = get_hostrt_data();
+   BUG_ON(!hostrt_data);
+
+   if (unlikely(!hostrt_data-live))
+   return -1;
+
+   /*
+* Note: Disabling HW interrupts around writes to hostrt_data ensures
+* that a reader (on the Xenomai side) cannot interrupt a writer (on
+* the Linux kernel side) on the same CPU.  The sequence counter is
+* required when a reader is interleaved by a writer on a different
+* CPU. This follows the approach from userland, where tasking the
+* spinlock is not possible.
+*/
+retry:
+   seq = read_seqcount_begin(hostrt_data-seqcount);
+
+   now = xnarch_get_cpu_tsc();
+   base = hostrt_data-cycle_last;
+   mask = hostrt_data-mask;
+   mult = hostrt_data-mult;
+   shift = hostrt_data-shift;
+   tp-tv_sec = hostrt_data-wall_time_sec;
+   nsec = hostrt_data-wall_time_nsec;
+
+   if (read_seqcount_retry(hostrt_data-seqcount, seq))
+   goto retry;
+
+   /*
+* At this point, we have a consistent copy of the fundamental
+* data structure - calculate the interval between the current
+* and base time stamp cycles, and convert the difference
+* to nanoseconds.
+*/
+   cycle_delta = (now - base)  mask;
+   nsec += (cycle_delta * mult)  shift;
+
+   /* Convert to the desired sec, usec representation */
+   tp-tv_sec += xnarch_divrem_billion(nsec, rem);
+   tp-tv_nsec = rem;
+
+   return 0;
+#else /* CONFIG_XENO_OPT_HOSTRT */
+   return -EINVAL;
+#endif
+}
+
+/**
  * Read the specified clock. 
  *
  * This service returns, at the address @a tp the current value of the clock @a
@@ -97,8 +170,12 @@ int clock_getres(clockid_t clock_id, struct timespec *res)
  * - CLOCK_MONOTONIC, the clock value is given by an architecture-dependent 
high
  *   resolution counter, with a precision independent from the system clock 
tick
  *   duration.
+ * - CLOCK_HOST_REALTIME, the clock value as seen by the host, typically
+ *   Linux. Resolution and precision depend on the host, but it is guaranteed
+ *   that both, host and Xenomai, see the same information.
  *
- * @param clock_id clock identifier, either CLOCK_REALTIME or CLOCK_MONOTONIC;
+ * @param clock_id clock identifier, either CLOCK_REALTIME, 

[Xenomai-git] Jan Kiszka : Fix copypaste mistake in SMI device ID for legacy kernels

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: 2caecf2ac1569c6dd925814376f4f7820ff4864a
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=2caecf2ac1569c6dd925814376f4f7820ff4864a

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Wed Oct  6 13:35:41 2010 +0200

Fix copypaste mistake in SMI device ID for legacy kernels

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 include/asm-generic/pci_ids.h |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/pci_ids.h b/include/asm-generic/pci_ids.h
index 0ae95d2..d298bf4 100644
--- a/include/asm-generic/pci_ids.h
+++ b/include/asm-generic/pci_ids.h
@@ -4,8 +4,8 @@
 #include linux/pci_ids.h
 
 /* SMI */
-#ifndef PCI_DEVICE_ID_INTEL_82801EB_0
-#define PCI_DEVICE_ID_INTEL_82801EB_0 0x24d0
+#ifndef PCI_DEVICE_ID_INTEL_ESB2_0
+#define PCI_DEVICE_ID_INTEL_ESB2_0 0x2670
 #endif
 #ifndef PCI_DEVICE_ID_INTEL_ICH7_0
 #define PCI_DEVICE_ID_INTEL_ICH7_0 0x27b8


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : rtipc: Fix types of internal thread variables

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: dbc9c302b1504391dd711ca16b4a373f374f6235
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=dbc9c302b1504391dd711ca16b4a373f374f6235

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Wed Oct  6 15:56:37 2010 +0200

rtipc: Fix types of internal thread variables

Those waiters refer to generic xnthreads, not rtdm_tasks (will break
once rtdm_task_t and xnthread_t diverge).

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 ksrc/drivers/ipc/bufp.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/ksrc/drivers/ipc/bufp.c b/ksrc/drivers/ipc/bufp.c
index 2394a5d..8737ee2 100644
--- a/ksrc/drivers/ipc/bufp.c
+++ b/ksrc/drivers/ipc/bufp.c
@@ -180,7 +180,7 @@ static ssize_t __bufp_readbuf(struct bufp_socket *sk,
 {
struct bufp_wait_context wait, *bufwc;
struct rtipc_wait_context *wc;
-   rtdm_task_t *waiter;
+   xnthread_t *waiter;
rtdm_toseq_t toseq;
ssize_t len, ret;
size_t rbytes, n;
@@ -431,7 +431,7 @@ static ssize_t __bufp_writebuf(struct bufp_socket *rsk,
 {
struct bufp_wait_context wait, *bufwc;
struct rtipc_wait_context *wc;
-   rtdm_task_t *waiter;
+   xnthread_t *waiter;
rtdm_toseq_t toseq;
ssize_t len, ret;
size_t wbytes, n;


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : Merge remote branch 'jan'

2010-10-08 Thread GIT version control
Module: xenomai-head
Branch: master
Commit: cef2c5db7aabfefc25411326527c0cba15845a7b
URL:
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=cef2c5db7aabfefc25411326527c0cba15845a7b

Author: Philippe Gerum r...@xenomai.org
Date:   Fri Oct  8 08:01:19 2010 +0200

Merge remote branch 'jan'

---




___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git