Host realtime clock support
Subsystems (2)
cover Host realtime clock support
(This is the Xenomai part of the mechanism, please see the ipipe
mailing list for the patches that provide the required basis infrastructure)
This patch series extends Xenomai with a new clock, CLOCK_HOST_REALTIME. It allows for sharing NTP-corrected real time timestamps between Linux/ipipe and Xenomai. The data are also available in userspace and can be read without switching to kernel mode. Notice, however, that the new clock only enables to read to time, but cannot serve as a full time basis. Some changes to the ipipe layer are required as basis.
In contrast to the initial approach, we don't use a transactional mechanism to copy the information over from Linux, but use classical synchronisation. The code can be compiled in conditionally for both, ipipe and Xenomai. When disabled by architectures that don't support apt clock sources, there is no runtime-overhead associated with the feature.
Some points that may require further discussion:
- POSIX only specifies a few clock_ids, and these have already been extended by the Linux kernel. We use the maximum id (16) for the new clock, but it might also make sense to use 7 (CLOCK_MONOTONIC_COARSE+1) or 4 (CLOCK_THREAD_CPUTIME_ID+1).
- The current implementation deals with x86_64's TSC. Support for other architectures can be added. Additionally, the user has to make sure that the TSC clock source remains active once selected. To implement deactivation (e.g., when the Linux clock source is changed), more ipipe hooks would be required, though.
There are two alternatives including other architectures:
* We can create a new clocksource that abstracts the per-architecture differences, and use this clocksource as basis for Xenomai. Essentially, this means mapping all desired non-x86-Clocksources to the interface offered in this patch. This requires more changes in the ipipe layer than variant B, namely,
* We can create a union in struct xnvdso of all arch-specific clock datasets and introduce feature flags like XNVDSO_FEAT_HOSTRT_X86, XNVDSO_FEAT_HOSTRT_WHATEVER. The reader-side code then needs to match the data provided, which requires more changes on the Xenomai side.
- The series supports dynamic switching from a non-TSC clocksource to clocksource_tsc, but does not handle the other direction. This is intentional, because when a user wants meaningful synchronised time stamps, the reliability of the underlying clock should be ensured.
Naturally, it would be possible to detect this change at the kernel level, but this would make the ipipe part more intrusive.
The code compiles with all combinations of IPIPE_HOSTRT and OPT_XENO_HOSTRT.
As always, thanks for your comments and review!
Best, Wolfgang
--- examples/posix/Makefile | 3 - examples/posix/show_hrtime.c | 82 ++++++++++++++++++++++++++++++++++++ include/asm-generic/hal.h | 2 include/asm-generic/system.h | 4 + include/asm-sim/system.h | 4 + include/asm-x86/atomic.h | 5 ++ include/nucleus/Makefile.am | 2 include/nucleus/hostrt.h | 65 ++++++++++++++++++++++++++++ include/nucleus/seqlock_user.h | 57 +++++++++++++++++++++++++ include/nucleus/vdso.h | 20 +++++++- include/posix/time.h | 2 ksrc/nucleus/Kconfig | 4 + ksrc/nucleus/module.c | 25 +++++++++++ ksrc/skins/posix/clock.c | 90 +++++++++++++++++++++++++++++++++++++++- src/skins/posix/clock.c | 65 ++++++++++++++++++++++++++++ src/testsuite/unit/check-vdso.c | 2 16 files changed, 426 insertions(+), 6 deletions(-)
PATCH 1/7 nucleus: Spelling fix for check-vdso.c
--- src/testsuite/unit/check-vdso.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
src/testsuite/unit/check-vdso.c +1 -1
@@ -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 );
Signature · 1 line
1.6.4
PATCH 2/7 nucleus: Sanity check for vdso.h
In reply to Wolfgang MauererIncluding the file only makes sense when support for pervasive rt is enabled, so add a corresponding check.
--- include/nucleus/vdso.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
include/nucleus/vdso.h +4 -0
@@ -23,6 +23,10 @@* 02111-1307, USA. */ +#if defined(__KERNEL__) && !defined(CONFIG_XENO_OPT_PERVASIVE ) +#error "vdso.h included in a kernel configuration without pervasive rt support!" +#endif +#include <nucleus/types.h> /*
Signature · 1 line
1.6.4
PATCH 3/7 nucleus: Add userland cpu_relax() definition for x86
In reply to Wolfgang Mauerer--- include/asm-x86/atomic.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
include/asm-x86/atomic.h +5 -0
@@ -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 ) +{ + asmvolatile ("rep; nop" :::"memory" ); +} +#ifdef __i386__struct __xeno_xchg_dummy {unsigned long a[100 ]; };
Signature · 1 line
1.6.4
PATCH 4/7 nucleus: Add CLOCK_HOST_REALTIME bits to nkvdso
In reply to Wolfgang MauererAugment 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.
The definition of the hostrt data is placed in a separate head file so that we can use it irregardless of pervasive rt support is compiled in or not.
--- include/asm-generic/hal.h | 2 + include/asm-generic/system.h | 4 ++ include/asm-sim/system.h | 4 ++ include/nucleus/Makefile.am | 1 + include/nucleus/hostrt.h | 65 ++++++++++++++++++++++++++++++++++++++++++ include/nucleus/vdso.h | 16 ++++++++-- ksrc/nucleus/Kconfig | 4 ++ ksrc/nucleus/module.c | 25 ++++++++++++++++ 8 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 include/nucleus/hostrt.h
include/asm-generic/hal.h +2 -0
@@ -680,6 +680,8 @@ static inline int rthal_trace_panic_dump(void)#endif /* CONFIG_IPIPE_TRACE */ +#define rthal_set_hostrt_data ipipe_set_hostrt_data +#define rthal_hostrt_data ipipe_hostrt_data #ifdef __cplusplus }#endif /* __cplusplus */
include/asm-generic/system.h +4 -0
@@ -490,4 +490,8 @@ 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_set_hostrt_data rthal_set_hostrt_data +#define xnarch_hostrt_data rthal_hostrt_data +#endif /* !_XENO_ASM_GENERIC_SYSTEM_H */
include/asm-sim/system.h +4 -0
@@ -598,4 +598,8 @@ static inline long IS_ERR(const void *ptr) return IS_ERR_VALUE((unsigned long)ptr); } +/* Host realtime support is not supported in the simulator */ +#define xnarch_set_hostrt_data { } +struct xnarch_hostrt_data { }; +#endif /* !_XENO_ASM_SIM_SYSTEM_H */
include/nucleus/Makefile.am +1 -0
@@ -6,6 +6,7 @@ includesub_HEADERS = \ bufd.h \ compiler.h \ heap.h \ + hostrt.h \ intr.h \ jhash.h \ map.h \
include/nucleus/hostrt.h new file +65 -0
65 lines not on this page · raw message
include/nucleus/vdso.h +13 -3
@@ -28,6 +28,7 @@#endif #include <nucleus/types.h> +#include <nucleus/hostrt.h> /* * Data shared between Xenomai kernel/userland and the Linux kernel/userland
@@ -37,8 +38,11 @@struct xnvdso {unsigned long long features; -/* Embed domain specific structures that describe the -* shared data here */ +struct xnarch_hostrt_data hostrt_data; +/* +* Embed further domain specific structures that +* describe the shared data here +*/ };/*
@@ -52,10 +56,16 @@ struct xnvdso {#define XNVDSO_FEATURES (XNVDSO_FEAT_A | XNVDSO_FEAT_B | XVDSO_FEAT_C) */ #define XNVDSO_FEAT_DROP_U_MODE 0x0000000000000001ULL -#define XNVDSO_FEATURES (XNVDSO_FEAT_DROP_U_MODE) +#define XNVDSO_FEAT_HOST_REALTIME 0x0000000000000002ULL +#define XNVDSO_FEATURES (XNVDSO_FEAT_DROP_U_MODE | XNVDSO_FEAT_HOST_REALTIME)extern struct xnvdso *nkvdso; +static inline struct xnarch_hostrt_data *get_hostrt_data (void ) +{ +return &nkvdso->hostrt_data; +} +static inline int xnvdso_test_feature (unsigned long long feature) {return testbits (nkvdso->features, feature);
ksrc/nucleus/Kconfig +4 -0
@@ -355,6 +355,10 @@ config XENO_OPT_SHIRQ config XENO_OPT_SELECT bool +config XENO_OPT_HOSTRT + depends on IPIPE_HOSTRT + def_bool y + menu "Timing" config XENO_OPT_TIMING_PERIODIC
ksrc/nucleus/module.c +25 -0
@@ -35,12 +35,28 @@#endif /* CONFIG_XENO_OPT_PIPE */ #include <nucleus/select.h> #include <asm/xenomai/bits/init.h> +#ifdef CONFIG_XENO_OPT_PERVASIVE #include <nucleus/vdso.h> #else static inline void xnheap_init_vdso (void ) { }#endif /* CONFIG_XENO_OPT_PERVASIVE */ +#ifdef CONFIG_XENO_OPT_HOSTRT +#include <nucleus/hostrt.h> + +#ifndef CONFIG_XENO_OPT_PERVASIVE +struct xnarch_hostrt_data *nkhostrt_data; +#endif + +static inline void init_hostrt (void ) +{ +seqcount_init (&get_hostrt_data ()->seqcount); +xnarch_set_hostrt_data (get_hostrt_data ()); +} +#else +static inline void init_hostrt (void ) { } +#endif /* CONFIG_XENO_OPT_HOSTRT */ MODULE_DESCRIPTION ("Xenomai nucleus" );MODULE_AUTHOR ("[email protected]" );MODULE_LICENSE ("GPL" );
@@ -113,7 +129,16 @@ int __init __xeno_sys_init(void)xnheap_set_label (&__xnsys_global_ppd.sem_heap,"global sem heap" );xnheap_init_vdso (); + +#if defined(CONFIG_XENO_OPT_HOSTRT ) && !defined(CONFIG_XENO_OPT_PERVASIVE ) + nkhostrt_data =xnarch_alloc_host_mem (sizeof (struct xnarch_hostrt_data )); +if (nkhostrt_data ==NULL ) { + ret = -ENOMEM ; + goto fail; + }#endif +init_hostrt (); +#endif /* !__XENO_SIM__ */ #ifdef __KERNEL__xnpod_mount ();
Signature · 1 line
1.6.4
Re: [Xenomai-core] [PATCH 4/7] nucleus: Add CLOCK_HOST_REALTIME bits to nkvdso
Quoted 8 lines · Wolfgang Mauerer
Augment the shared vdso page with all data required to implement a clock
CLOCK_HOST_REALTIMEthat provides time information synchronised with the NTP-corrected time in the Linux kernel.The definition of the hostrt data is placed in a separate head file so that we can use it irregardless of pervasive rt support is compiled in or not.
Ok. Would not it be more simple to define the nkvdso even without pervasive support?
ksrc/nucleus/module.c int __init __xeno_sys_init(void) · line 134
Quoted 2 lines
ksrc/nucleus/module.c +2
-0+#if defined(CONFIG_XENO_OPT_HOSTRT ) && !defined(CONFIG_XENO_OPT_PERVASIVE ) + nkhostrt_data =xnarch_alloc_host_mem (sizeof (struct xnarch_hostrt_data ));
should be sizeof(*nkhostrt_data)
But why a dynamic allocation at all?
Signature · 1 line
Gilles.
Re: [Xenomai-core] [PATCH 4/7] nucleus: Add CLOCK_HOST_REALTIME bits to nkvdso
Quoted 6 lines · Gilles Chanteperdrix
Quoted 5 lines · Wolfgang Mauerer
Augment the shared vdso page with all data required to implement a clock
CLOCK_HOST_REALTIMEthat provides time information synchronised with the NTP-corrected time in the Linux kernel.
Quoted 6 lines
Quoted 3 lines
The definition of the hostrt data is placed in a separate head file so that we can use it irregardless of pervasive rt support is compiled in or not.
Ok. Would not it be more simple to define the nkvdso even without pervasive support?
Thought about that, but having a shared kernel/userland object without pervasive RT support seemed a bit unnatural to me.
Quoted 7 lines
ksrc/nucleus/module.c int __init __xeno_sys_init(void) · line 134
Quoted 3 lines
ksrc/nucleus/module.c +2
-0+#if defined(CONFIG_XENO_OPT_HOSTRT ) && !defined(CONFIG_XENO_OPT_PERVASIVE ) + nkhostrt_data =xnarch_alloc_host_mem (sizeof (struct xnarch_hostrt_data ));should be
sizeof(*nkhostrt_data)But why a dynamic allocation at all?
not really required, can also make it static if you prefer.
Best regards, Wolfgang
Re: [Xenomai-core] [PATCH 4/7] nucleus: Add CLOCK_HOST_REALTIME bits to nkvdso
Quoted 7 lines · Wolfgang Mauerer
Quoted 6 lines · Gilles Chanteperdrix
Quoted 5 lines · Wolfgang Mauerer
Augment the shared vdso page with all data required to implement a clock
CLOCK_HOST_REALTIMEthat provides time information synchronised with the NTP-corrected time in the Linux kernel.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
The definition of the hostrt data is placed in a separate head file so that we can use it irregardless of pervasive rt support is compiled in or not.
Ok. Would not it be more simple to define the nkvdso even without pervasive support?
Thought about that, but having a shared kernel/userland object without pervasive RT support seemed a bit unnatural to me.
The idea would be to have a static nkvdso in the non-pervasive case, we do not need the mapping stuff. But at least, if we do this once and for all for nkvdso, we will not have to repeat the code which handles the non-pervasive case for all the data in nkvdso which need to exist in that case.
Signature · 1 line
Gilles.
Re: [Xenomai-core] [PATCH 4/7] nucleus: Add CLOCK_HOST_REALTIME bits to nkvdso
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Wolfgang Mauerer
Quoted 11 lines · Gilles Chanteperdrix
Quoted 8 lines · Wolfgang Mauerer
Augment the shared vdso page with all data required to implement a clock
CLOCK_HOST_REALTIMEthat provides time information synchronised with the NTP-corrected time in the Linux kernel.The definition of the hostrt data is placed in a separate head file so that we can use it irregardless of pervasive rt support is compiled in or not.
Ok. Would not it be more simple to define the nkvdso even without pervasive support?
Quoted 8 lines
Quoted 2 lines
Thought about that, but having a shared kernel/userland object without pervasive RT support seemed a bit unnatural to me.
The idea would be to have a static nkvdso in the non-pervasive case, we do not need the mapping stuff. But at least, if we do this once and for all for nkvdso, we will not have to repeat the code which handles the non-pervasive case for all the data in nkvdso which need to exist in that case.
okay, let's do it like this. Might also save a couple of ifdefs.
Regards, Wolfgang
PATCH 5/7 posix: Support reading the host realtime clock in realtime context
In reply to Wolfgang MauererWall 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.
--- include/posix/time.h | 2 + ksrc/skins/posix/clock.c | 90 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletions(-)
include/posix/time.h +2 -0
@@ -50,6 +50,8 @@#define CLOCK_MONOTONIC 1#endif /* CLOCK_MONOTONIC */ +#define CLOCK_HOST_REALTIME 16 +#if defined(__KERNEL__) || defined(__XENO_SIM__)struct sigevent ;
ksrc/skins/posix/clock.c +89 -1
115 lines not on this page · raw message
Signature · 1 line
1.6.4
Re: [Xenomai-core] [PATCH 5/7] posix: Support reading the host realtime clock in realtime context
Quoted 33 lines · Wolfgang Mauerer
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_REALTIMEclock 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 <[email protected]>Signed-off-by Jan Kiszka <[email protected]>--- include/posix/time.h | 2 + ksrc/skins/posix/clock.c | 90 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletions(-)include/posix/time.h +2
-0@@ -50,6 +50,8 @@#define CLOCK_MONOTONIC 1#endif /* CLOCK_MONOTONIC */ +#define CLOCK_HOST_REALTIME 16 +#if defined(__KERNEL__) || defined(__XENO_SIM__)struct sigevent ;ksrc/skins/posix/clock.c +0
-0
ksrc/skins/posix/clock.c line 54
Quoted 5 lines
ksrc/skins/posix/clock.c +2
-0@@ -50,6 +50,13 @@*@{*/ #include <posix/thread.h> +#include <linux/ipipe_tickdev.h> +#include <linux/math64.h>
Do we really need this? Because we probably do not have it in 2.4 kernels. Besides, we do not include linux/ headers in Xenomai code.
ksrc/skins/posix/clock.c int clock_getres(clockid_t clock_id, struct timespec *res) · line 163
Quoted 7 lines
ksrc/skins/posix/clock.c +6
-0+static int do_clock_host_realtime (struct timespec *tp) +{ +#ifdef CONFIG_XENO_OPT_HOSTRT +return 0 ; +#else /* CONFIG_XENO_OPT_HOSTRT */ +return -1 ;
return -EINVAL;
ksrc/skins/posix/clock.c int clock_gettime(clockid_t clock_id, struct timespec *tp) · line 211
Quoted 2 lines
ksrc/skins/posix/clock.c +2
-0+case CLOCK_HOST_REALTIME : +if (do_clock_host_realtime (tp) !=0 ) {
rc = do_clock_host_realtime(tp);
if (rc < 0) {
thread_set_errno(-rc);
return -1;
}Signature · 1 line
Gilles.
Re: [Xenomai-core] [PATCH 5/7] posix: Support reading the host realtime clock in realtime context
Quoted 36 lines · Gilles Chanteperdrix
Quoted 35 lines · Wolfgang Mauerer
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_REALTIMEclock 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 <[email protected]>Signed-off-by Jan Kiszka <[email protected]>--- include/posix/time.h | 2 + ksrc/skins/posix/clock.c | 90 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletions(-)include/posix/time.h +2
-0@@ -50,6 +50,8 @@#define CLOCK_MONOTONIC 1#endif /* CLOCK_MONOTONIC */ +#define CLOCK_HOST_REALTIME 16 +#if defined(__KERNEL__) || defined(__XENO_SIM__)struct sigevent ;ksrc/skins/posix/clock.c +0
-0@@ -50,6 +50,13 @@*@{*/
Quoted 7 lines
ksrc/skins/posix/clock.c line 54
Quoted 3 lines
ksrc/skins/posix/clock.c +2
-0#include <posix/thread.h> +#include <linux/ipipe_tickdev.h> +#include <linux/math64.h> Do we really need this? Because we probably do not have it in 2.4 kernels. Besides, we do not include linux/ headers in Xenomai code.
right, math64.h should be xenomai/asm-generic/arith.h for xnarch_divrem_billion(). ipipe_tickdev.h is superfluous since all definitions go through xnarch and rthal.
Quoted 19 lines
ksrc/skins/posix/clock.c int clock_getres(clockid_t clock_id, struct timespec *res) · line 163
Quoted 7 lines
ksrc/skins/posix/clock.c +6
-0+static int do_clock_host_realtime (struct timespec *tp) +{ +#ifdef CONFIG_XENO_OPT_HOSTRT +return 0 ; +#else /* CONFIG_XENO_OPT_HOSTRT */ +return -1 ;return
-EINVAL;ksrc/skins/posix/clock.c int clock_gettime(clockid_t clock_id, struct timespec *tp) · line 211
Quoted 2 lines
ksrc/skins/posix/clock.c +2
-0+case CLOCK_HOST_REALTIME : +if (do_clock_host_realtime (tp) !=0 ) {rc = do_clock_host_realtime(tp); if (rc < 0) { thread_set_errno(-rc); return -1; }
PATCH 6/7 posix: Userspace hostrt reading without switching to kernel mode
In reply to Wolfgang MauererFrom: Wolfgang Mauerer (none) <[email protected]>
We can do this since the data are on the shared semaphore heap. The basis data structure is placed so that it is accessible from both the Linux kernel and Xenomai kernel/userland. This also requires to make the structure work with both kernel and userland definitions for elementary data types.
We use a seqlock retry mechanism to ensure that we obtain a consistent data set.
--- include/nucleus/Makefile.am | 1 + include/nucleus/seqlock_user.h | 57 +++++++++++++++++++++++++++++++++++ src/skins/posix/clock.c | 65 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 0 deletions(-) create mode 100644 include/nucleus/seqlock_user.h
include/nucleus/Makefile.am +1 -0
@@ -35,5 +35,6 @@ includesub_HEADERS = \ trace.h \ types.h \ vdso.h \ + seqlock_user.h \ version.h \ xenomai.h
include/nucleus/seqlock_user.h new file +57 -0
57 lines not on this page · raw message
src/skins/posix/clock.c +65 -0
90 lines not on this page · raw message
Signature · 1 line
1.6.4
Re: [Xenomai-core] [PATCH 6/7] posix: Userspace hostrt reading without switching to kernel mode
src/skins/posix/clock.c int __wrap_clock_gettime(clockid_t clock_id, struct timespec *tp) · line 133
Quoted 10 lines · Wolfgang Mauerer
int
__wrap_clock_gettime(clockid_t clock_id, struct timespec *tp){src/skins/posix/clock.c +3
-0int err;@@ -68,7 +128,11 @@ int __wrap_clock_gettime(clockid_t clock_id, struct timespec *tp) tp->tv_sec =xnarch_divrem_billion (ns, &rem); tp->tv_nsec = rem;return 0 ; + }else if (clock_id ==CLOCK_HOST_REALTIME ) { + err =__do_clock_host_realtime (tp,NULL ); + goto out;
swich case here
Signature · 1 line
Gilles.
PATCH 7/7 posix: Add some example code for CLOCK_HOST_REALTIME
In reply to Wolfgang Mauerer... and for reading the contents of the hostrt data.
--- examples/posix/Makefile | 3 +- examples/posix/show_hrtime.c | 82 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletions(-) create mode 100644 examples/posix/show_hrtime.c
examples/posix/Makefile +2 -1
@@ -1,7 +1,7 @@ ###### CONFIGURATION ###### ### List of applications to be build -APPLICATIONS = satch +APPLICATIONS = satch show_hrtime ### Note: to override the search path for the xeno-config script, use "make XENO=..."
@@ -14,6 +14,7 @@ MODULES = satch all:: satch: satch.c +show_hrtime: show_hrtime.c ###### USER SPACE BUILD (no change required normally) ######
examples/posix/show_hrtime.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
1.6.4
Re: [Xenomai-core] [PATCH 7/7] posix: Add some example code for CLOCK_HOST_REALTIME
Quoted 2 lines · Wolfgang Mauerer
... and for reading the contents of the hostrt data.
Just realized: Please also update clocktest. Should already work with the new clock ID, but requires a cosmetic output patch.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Re: [Xenomai-core] [PATCH 7/7] posix: Add some example code for CLOCK_HOST_REALTIME
Quoted 6 lines · Jan Kiszka
Quoted 2 lines · Wolfgang Mauerer
... and for reading the contents of the hostrt data.
Just realized: Please also update clocktest. Should already work with the new clock ID, but requires a cosmetic output patch.
Yes, I thought about that. Maybe even if clocktest uses the new clock_id, we could drop the example?
I do not think it is a good idea to provide as an example code which uses the internals of the implementation (though it makes sense to use the implementation internals in the clocktest code). And if we remove that, only clock_gettime(CLOCK_HOST_REALTIME) remains, which does not seem to need an example.
Signature · 1 line
Gilles.
Re: [Xenomai-core] [PATCH 7/7] posix: Add some example code for CLOCK_HOST_REALTIME
Quoted 7 lines · Gilles Chanteperdrix
Quoted 5 lines · Jan Kiszka
Quoted 2 lines · Wolfgang Mauerer
... and for reading the contents of the hostrt data.
Just realized: Please also update clocktest. Should already work with the new clock ID, but requires a cosmetic output patch.
Quoted 9 lines
Yes, I thought about that. Maybe even if clocktest uses the new
clock_id, we could drop the example?I do not think it is a good idea to provide as an example code which uses the internals of the implementation (though it makes sense to use the implementation internals in the clocktest code). And if we remove that, only
clock_gettime(CLOCK_HOST_REALTIME)remains, which does not seem to need an example.
I would not keep it as an example, but as a test case for checking that nothing is wrong with the data on the shared page. Which does not fit quite well into clocktest. Although I have no problem with just omitting the stuff if reading the (internal) content of the data page is deemed inappropriate.
Regards, Wolfgang
Re: [Xenomai-core] [PATCH 7/7] posix: Add some example code for CLOCK_HOST_REALTIME
Quoted 17 lines · Wolfgang Mauerer
Quoted 6 lines · Gilles Chanteperdrix
Quoted 5 lines · Jan Kiszka
Quoted 2 lines · Wolfgang Mauerer
... and for reading the contents of the hostrt data.
Just realized: Please also update clocktest. Should already work with the new clock ID, but requires a cosmetic output patch.
Quoted 9 lines
Yes, I thought about that. Maybe even if clocktest uses the new
clock_id, we could drop the example?I do not think it is a good idea to provide as an example code which uses the internals of the implementation (though it makes sense to use the implementation internals in the clocktest code). And if we remove that, only
clock_gettime(CLOCK_HOST_REALTIME)remains, which does not seem to need an example.
Quoted 5 lines
I would not keep it as an example, but as a test case for checking that nothing is wrong with the data on the shared page. Which does not fit quite well into clocktest. Although I have no problem with just omitting the stuff if reading the (internal) content of the data page is deemed inappropriate.
Well, I see nothing wrong with checking the internals at the beginning of clocktest is the clockid passed to clocktest is CLOCK_HOST_REALTIME. But Jan may have another opinion, since he is the one who wrote this code.
Signature · 1 line
Gilles.
Re: [Xenomai-core] [PATCH 7/7] posix: Add some example code for CLOCK_HOST_REALTIME
Quoted 23 lines · Gilles Chanteperdrix
Quoted 16 lines · Wolfgang Mauerer
Quoted 6 lines · Gilles Chanteperdrix
Quoted 5 lines · Jan Kiszka
Quoted 2 lines · Wolfgang Mauerer
... and for reading the contents of the hostrt data.
Just realized: Please also update clocktest. Should already work with the new clock ID, but requires a cosmetic output patch.
Quoted 9 lines
Yes, I thought about that. Maybe even if clocktest uses the new
clock_id, we could drop the example?I do not think it is a good idea to provide as an example code which uses the internals of the implementation (though it makes sense to use the implementation internals in the clocktest code). And if we remove that, only
clock_gettime(CLOCK_HOST_REALTIME)remains, which does not seem to need an example.Quoted 5 lines
I would not keep it as an example, but as a test case for checking that nothing is wrong with the data on the shared page. Which does not fit quite well into clocktest. Although I have no problem with just omitting the stuff if reading the (internal) content of the data page is deemed inappropriate.
Quoted 3 lines
Well, I see nothing wrong with checking the internals at the beginning of clocktest is the clockid passed to clocktest is
CLOCK_HOST_REALTIME. But Jan may have another opinion, since he is the one who wrote this code.
If clock_gettime(CLOCK_HOST_REALTIME) succeeds, I don't think we need to do anything special. But if it should fail, dumping a more detailed reason based on those additional checks in the example would be helpful.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
PATCH 1/1 posix: Add some example code for CLOCK_HOST_REALTIME
In reply to Jan KiszkaQuoted 6 lines · Jan
Quoted 2 lines · Wolfgang Mauerer
... and for reading the contents of the hostrt data.
Just realized: Please also update clocktest. Should already work with the new clock ID, but requires a cosmetic output patch.
easy enough -- here you go ;-) (I'll integrate this into the series)
Best, Wolfgang
(quoted diff) +0 -0
b/src/testsuite/clocktest/clocktest.c
index f0a29ba..42f3f0b 100644
src/testsuite/clocktest/clocktest.c +4 -0
@@ -234,6 +234,10 @@ int main(int argc, char *argv[])printf ("CLOCK_MONOTONIC" );break ; +case CLOCK_HOST_REALTIME : +printf ("CLOCK_HOST_REALTIME" ); +break ; +default :printf ("<unknown>" );break ;
Quoted 32 lines · Wolfgang Mauerer
(This is the Xenomai part of the mechanism, please see the ipipe
mailing list for the patches that provide the required basis infrastructure)This patch series extends Xenomai with a new clock,
CLOCK_HOST_REALTIME. It allows for sharing NTP-corrected real time timestamps between Linux/ipipe and Xenomai. The data are also available in userspace and can be read without switching to kernel mode. Notice, however, that the new clock only enables to read to time, but cannot serve as a full time basis. Some changes to the ipipe layer are required as basis.In contrast to the initial approach, we don't use a transactional mechanism to copy the information over from Linux, but use classical synchronisation. The code can be compiled in conditionally for both, ipipe and Xenomai. When disabled by architectures that don't support apt clock sources, there is no runtime-overhead associated with the feature.
Some points that may require further discussion:
- POSIX only specifies a few
clock_ids, and these have already been extended by the Linux kernel. We use the maximum id (16) for the new clock, but it might also make sense to use 7 (CLOCK_MONOTONIC_COARSE+1) or 4 (CLOCK_THREAD_CPUTIME_ID+1).- The current implementation deals with x86_64's TSC. Support for other architectures can be added. Additionally, the user has to make sure that the TSC clock source remains active once selected. To implement deactivation (e.g., when the Linux clock source is changed), more ipipe hooks would be required, though.
There are two alternatives including other architectures:
Quoted 10 lines
* We can create a new clocksource that abstracts the per-architecture differences, and use this clocksource as basis for Xenomai. Essentially, this means mapping all desired non-x86-Clocksources to the interface offered in this patch. This requires more changes in the ipipe layer than variant B, namely,
* We can create a union in struct xnvdso of all arch-specific clock datasets and introduce feature flags likeXNVDSO_FEAT_HOSTRT_X86,XNVDSO_FEAT_HOSTRT_WHATEVER. The reader-side code then needs to match the data provided, which requires more changes on the Xenomai side.
The dataset is the same on all architectures, since we provide the same "clocksource abstraction" on the 5 architectures we support: a TSC emulation. So, a simple approach is simply cut-and-paste the x86 update_vsyscall code for other architectures, another approach is to put this code in a wrapper which we call on all architectures.
This update_vsyscall code would call ipipe_dispatch_event to pass the data to Xenomai.
Signature · 1 line
Gilles.
Quoted 44 lines · Gilles Chanteperdrix
Quoted 32 lines · Wolfgang Mauerer
(This is the Xenomai part of the mechanism, please see the ipipe
mailing list for the patches that provide the required basis infrastructure)This patch series extends Xenomai with a new clock,
CLOCK_HOST_REALTIME. It allows for sharing NTP-corrected real time timestamps between Linux/ipipe and Xenomai. The data are also available in userspace and can be read without switching to kernel mode. Notice, however, that the new clock only enables to read to time, but cannot serve as a full time basis. Some changes to the ipipe layer are required as basis.In contrast to the initial approach, we don't use a transactional mechanism to copy the information over from Linux, but use classical synchronisation. The code can be compiled in conditionally for both, ipipe and Xenomai. When disabled by architectures that don't support apt clock sources, there is no runtime-overhead associated with the feature.
Some points that may require further discussion:
- POSIX only specifies a few
clock_ids, and these have already been extended by the Linux kernel. We use the maximum id (16) for the new clock, but it might also make sense to use 7 (CLOCK_MONOTONIC_COARSE+1) or 4 (CLOCK_THREAD_CPUTIME_ID+1).- The current implementation deals with x86_64's TSC. Support for other architectures can be added. Additionally, the user has to make sure that the TSC clock source remains active once selected. To implement deactivation (e.g., when the Linux clock source is changed), more ipipe hooks would be required, though.
There are two alternatives including other architectures:
Quoted 10 lines
* We can create a new clocksource that abstracts the per-architecture differences, and use this clocksource as basis for Xenomai. Essentially, this means mapping all desired non-x86-Clocksources to the interface offered in this patch. This requires more changes in the ipipe layer than variant B, namely,
* We can create a union in struct xnvdso of all arch-specific clock datasets and introduce feature flags likeXNVDSO_FEAT_HOSTRT_X86,XNVDSO_FEAT_HOSTRT_WHATEVER. The reader-side code then needs to match the data provided, which requires more changes on the Xenomai side.
Quoted 5 lines
The dataset is the same on all architectures, since we provide the same "clocksource abstraction" on the 5 architectures we support: a TSC emulation. So, a simple approach is simply cut-and-paste the x86
update_vsyscallcode for other architectures, another approach is to put this code in a wrapper which we call on all architectures.
this disables the possibility of using non-TSC time sources that can also be accessed from userland. That's certainly not a requirement for us, I'd just like to mention it.
We also need to ensure that the host has not switched away from TSC because in this case, the NTP correction values delivered from Linux are for a different clocksource than the one used by Xenomai. So we need to detect a switch from TSC to non-TSC, which can only be done in arch-specific code -- I don't see a generic way to know which clocksources are based on the TSC and which one are not.
Quoted 4 lines
This
update_vsyscallcode would callipipe_dispatch_eventto pass the data to Xenomai.
okay. That seems to have dropped from my radar, as I don't recall having any issues with this requirement.
Regards, Wolfgang
Quoted 50 lines · Wolfgang Mauerer
Quoted 43 lines · Gilles Chanteperdrix
Quoted 32 lines · Wolfgang Mauerer
(This is the Xenomai part of the mechanism, please see the ipipe
mailing list for the patches that provide the required basis infrastructure)This patch series extends Xenomai with a new clock,
CLOCK_HOST_REALTIME. It allows for sharing NTP-corrected real time timestamps between Linux/ipipe and Xenomai. The data are also available in userspace and can be read without switching to kernel mode. Notice, however, that the new clock only enables to read to time, but cannot serve as a full time basis. Some changes to the ipipe layer are required as basis.In contrast to the initial approach, we don't use a transactional mechanism to copy the information over from Linux, but use classical synchronisation. The code can be compiled in conditionally for both, ipipe and Xenomai. When disabled by architectures that don't support apt clock sources, there is no runtime-overhead associated with the feature.
Some points that may require further discussion:
- POSIX only specifies a few
clock_ids, and these have already been extended by the Linux kernel. We use the maximum id (16) for the new clock, but it might also make sense to use 7 (CLOCK_MONOTONIC_COARSE+1) or 4 (CLOCK_THREAD_CPUTIME_ID+1).- The current implementation deals with x86_64's TSC. Support for other architectures can be added. Additionally, the user has to make sure that the TSC clock source remains active once selected. To implement deactivation (e.g., when the Linux clock source is changed), more ipipe hooks would be required, though.
There are two alternatives including other architectures:
Quoted 10 lines
* We can create a new clocksource that abstracts the per-architecture differences, and use this clocksource as basis for Xenomai. Essentially, this means mapping all desired non-x86-Clocksources to the interface offered in this patch. This requires more changes in the ipipe layer than variant B, namely,
* We can create a union in struct xnvdso of all arch-specific clock datasets and introduce feature flags likeXNVDSO_FEAT_HOSTRT_X86,XNVDSO_FEAT_HOSTRT_WHATEVER. The reader-side code then needs to match the data provided, which requires more changes on the Xenomai side.Quoted 5 lines
The dataset is the same on all architectures, since we provide the same "clocksource abstraction" on the 5 architectures we support: a TSC emulation. So, a simple approach is simply cut-and-paste the x86
update_vsyscallcode for other architectures, another approach is to put this code in a wrapper which we call on all architectures.
Quoted 3 lines
this disables the possibility of using non-TSC time sources that can also be accessed from userland. That's certainly not a requirement for us, I'd just like to mention it.
This would only make sense on x86, as other architectures seem to have only one clock-source. And since other clocksources than TSC have a higher overhead, I do not think it is likely that we would like to use them. Anyway, we can start with TSC and if the need arises, fix that later.
Quoted 7 lines
We also need to ensure that the host has not switched away from TSC because in this case, the NTP correction values delivered from Linux are for a different clocksource than the one used by Xenomai. So we need to detect a switch from TSC to non-TSC, which can only be done in arch-specific code -- I don't see a generic way to know which clocksources are based on the TSC and which one are not.
Well, all architectures call ipipe_request_tickdev, so, we can check if the clock pointer passed to update_vsyscall is the same as the one returned by ipipe_request_tickdev. Do not know if this is really possible, I would need to check more closely how ipipe_request_tickdev works.
Quoted 5 lines
Quoted 3 lines
This
update_vsyscallcode would callipipe_dispatch_eventto pass the data to Xenomai.okay. That seems to have dropped from my radar, as I don't recall having any issues with this requirement.
I am sure that I always thought that it should be done this way. But maybe I did not say it... Sorry if that is the case.
Signature · 1 line
Gilles.
Quoted 50 lines · Gilles Chanteperdrix
Quoted 49 lines · Wolfgang Mauerer
Quoted 48 lines · Gilles Chanteperdrix
Quoted 32 lines · Wolfgang Mauerer
(This is the Xenomai part of the mechanism, please see the ipipe
mailing list for the patches that provide the required basis infrastructure)This patch series extends Xenomai with a new clock,
CLOCK_HOST_REALTIME. It allows for sharing NTP-corrected real time timestamps between Linux/ipipe and Xenomai. The data are also available in userspace and can be read without switching to kernel mode. Notice, however, that the new clock only enables to read to time, but cannot serve as a full time basis. Some changes to the ipipe layer are required as basis.In contrast to the initial approach, we don't use a transactional mechanism to copy the information over from Linux, but use classical synchronisation. The code can be compiled in conditionally for both, ipipe and Xenomai. When disabled by architectures that don't support apt clock sources, there is no runtime-overhead associated with the feature.
Some points that may require further discussion:
- POSIX only specifies a few
clock_ids, and these have already been extended by the Linux kernel. We use the maximum id (16) for the new clock, but it might also make sense to use 7 (CLOCK_MONOTONIC_COARSE+1) or 4 (CLOCK_THREAD_CPUTIME_ID+1).- The current implementation deals with x86_64's TSC. Support for other architectures can be added. Additionally, the user has to make sure that the TSC clock source remains active once selected. To implement deactivation (e.g., when the Linux clock source is changed), more ipipe hooks would be required, though.
There are two alternatives including other architectures:
Quoted 10 lines
* We can create a new clocksource that abstracts the per-architecture differences, and use this clocksource as basis for Xenomai. Essentially, this means mapping all desired non-x86-Clocksources to the interface offered in this patch. This requires more changes in the ipipe layer than variant B, namely,
* We can create a union in struct xnvdso of all arch-specific clock datasets and introduce feature flags likeXNVDSO_FEAT_HOSTRT_X86,XNVDSO_FEAT_HOSTRT_WHATEVER. The reader-side code then needs to match the data provided, which requires more changes on the Xenomai side.The dataset is the same on all architectures, since we provide the same "clocksource abstraction" on the 5 architectures we support: a TSC emulation. So, a simple approach is simply cut-and-paste the x86
update_vsyscallcode for other architectures, another approach is to put this code in a wrapper which we call on all architectures.
Quoted 8 lines
Quoted 3 lines
this disables the possibility of using non-TSC time sources that can also be accessed from userland. That's certainly not a requirement for us, I'd just like to mention it.
This would only make sense on x86, as other architectures seem to have only one clock-source. And since other clocksources than TSC have a higher overhead, I do not think it is likely that we would like to use them.
So far, we insist on running Xenomai only on x86 hardware with non-broken TSCs. But there are still too many boxes out there (both Intel and AMD) where TSCs can drift or jump between cores or packages, even when disabling all the fancy power saving and frequency scaling stuff.
We were lucky in our project not having to deal with such hardware -- for production use. Some intermediate version did suffer from unsynchronous TSCs.
Quoted 1 line
Anyway, we can start with TSC and if the need arises, fix that later.
That's true.
Quoted 8 lines
Quoted 7 lines
We also need to ensure that the host has not switched away from TSC because in this case, the NTP correction values delivered from Linux are for a different clocksource than the one used by Xenomai. So we need to detect a switch from TSC to non-TSC, which can only be done in arch-specific code -- I don't see a generic way to know which clocksources are based on the TSC and which one are not.
Quoted 5 lines
Well, all architectures call
ipipe_request_tickdev, so, we can check if the clock pointer passed toupdate_vsyscallis the same as the one returned byipipe_request_tickdev. Do not know if this is really possible, I would need to check more closely howipipe_request_tickdevworks.
Unfortunately, ipipe_request_tickdev is not involved in clocksource business, it requests a clockevent.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 4 lines · Gilles Chanteperdrix
Quoted 2 lines · Wolfgang Mauerer
Quoted 1 line · Gilles Chanteperdrix
Wolfgang Mauerer wrote:
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
This
update_vsyscallcode would callipipe_dispatch_eventto pass the data to Xenomai.okay. That seems to have dropped from my radar, as I don't recall having any issues with this requirement.
I am sure that I always thought that it should be done this way. But maybe I did not say it... Sorry if that is the case.
you did say it, in fact. I looked at the interface, but seemingly forgot to make this change. Will follow in the next submission.
Regards, Wolfgang
Quoted 6 lines · Wolfgang Mauerer
Some points that may require further discussion:
- POSIX only specifies a few
clock_ids, and these have already been extended by the Linux kernel. We use the maximum id (16) for the new clock, but it might also make sense to use 7 (CLOCK_MONOTONIC_COARSE+1) or 4 (CLOCK_THREAD_CPUTIME_ID+1).
Why are we limited to 16 clocks? I mean we do not go trough any kernel/glibc path, so it looks like we can use any number. Or did I miss something?
Signature · 1 line
Gilles.
Quoted 12 lines · Gilles Chanteperdrix
Quoted 6 lines · Wolfgang Mauerer
Some points that may require further discussion:
- POSIX only specifies a few
clock_ids, and these have already been extended by the Linux kernel. We use the maximum id (16) for the new clock, but it might also make sense to use 7 (CLOCK_MONOTONIC_COARSE+1) or 4 (CLOCK_THREAD_CPUTIME_ID+1).Why are we limited to 16 clocks? I mean we do not go trough any kernel/glibc path, so it looks like we can use any number. Or did I miss something?
To goal was to find a number that's least surprising and blends best with the POSIX conventions and the existing numbers in Linux. Maximum was referring to the definition in the Linux kernel, but I'm happy to pick any larger number, including 23 and 42 ;-)
Regards, Wolfgang