Module: xenomai-head Branch: master Commit: 30b413538b2f1534d460d170a74e62b5132d1a92 URL: http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=30b413538b2f1534d460d170a74e62b5132d1a92
Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org> Date: Wed Oct 20 07:15:15 2010 +0200 hostrt: various fixes See: https://mail.gna.org/public/xenomai-core/2010-10/msg00075.html --- include/asm-sim/system.h | 29 ++++++++++------------ include/asm-x86/atomic.h | 7 ++++- include/nucleus/Makefile.am | 2 +- include/nucleus/Makefile.in | 2 + include/nucleus/hostrt.h | 32 +++++++++--------------- include/nucleus/{seqlock_user.h => seqlock.h} | 22 ++++++++-------- include/nucleus/vdso.h | 4 +- ksrc/nucleus/module.c | 10 ++++---- ksrc/skins/posix/clock.c | 20 +++++++------- src/skins/posix/clock.c | 9 +++---- src/testsuite/clocktest/clocktest.c | 10 ++++---- 11 files changed, 70 insertions(+), 77 deletions(-) diff --git a/include/asm-sim/system.h b/include/asm-sim/system.h index de24a3b..71036e7 100644 --- a/include/asm-sim/system.h +++ b/include/asm-sim/system.h @@ -128,10 +128,10 @@ typedef unsigned long xnarch_cpumask_t; #define xnarch_uldivrem(ull,uld,rem) ((u_long)xnarch_ulldiv((ull),(uld),(rem))) #define xnarch_uldiv(ull, d) xnarch_uldivrem(ull, d, NULL) #define xnarch_ulmod(ull, d) ({ u_long _rem; \ - xnarch_uldivrem(ull,d,&_rem); _rem; }) + xnarch_uldivrem(ull,d,&_rem); _rem; }) #define xnarch_divmod64(a,b,r) ({ if (r) \ - *r = (a) % (b); \ - (a) / (b); }) + *r = (a) % (b); \ + (a) / (b); }) #define xnarch_div64(a,b) ((a) / (b)) #define xnarch_mod64(a,b) ((a) % (b)) @@ -142,8 +142,8 @@ static inline int xnarch_imuldiv(int i, int mult, int div) } static inline unsigned long long __xnarch_ullimd(unsigned long long ull, - u_long m, - u_long d) + u_long m, + u_long d) { unsigned long long mh, ml; u_long h, l, mlh, mll, qh, r, ql; @@ -164,13 +164,13 @@ static inline unsigned long long __xnarch_ullimd(unsigned long long ull, static inline long long xnarch_llimd(long long ll, u_long m, u_long d) { if (ll < 0) - return -__xnarch_ullimd(-ll, m, d); + return -__xnarch_ullimd(-ll, m, d); return __xnarch_ullimd(ll, m, d); } static inline unsigned long long xnarch_ullmul(unsigned long m1, - unsigned long m2) + unsigned long m2) { return (unsigned long long) m1 * m2; } @@ -280,8 +280,8 @@ xnarch_read_environ (const char *name, const char **ptype, void *pvar) #define trace_mark(tag, args...) do { } while(0) #define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) #ifdef __cplusplus extern "C" { @@ -573,10 +573,10 @@ struct semaphore { }; #define sema_init(s, v) ((s)->count = (v)) #define down(s) ({ \ - while (!(s)->count) /* deadlock */ \ - ; \ - --(s)->count; \ - }) + while (!(s)->count) /* deadlock */ \ + ; \ + --(s)->count; \ + }) #define down_interruptible(s) (down(s),0) #define up(s) (++(s)->count) @@ -598,7 +598,4 @@ 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/asm-x86/atomic.h b/include/asm-x86/atomic.h index 16bc990..cc88de5 100644 --- a/include/asm-x86/atomic.h +++ b/include/asm-x86/atomic.h @@ -52,6 +52,8 @@ typedef atomic_long_t xnarch_atomic_t; #define xnarch_atomic_xchg(ptr,x) xchg(ptr,x) #define xnarch_memory_barrier() smp_mb() +#define xnarch_read_memory_barrier() rmb() +#define xnarch_write_memory_barrier() wmb() #else /* !__KERNEL__ */ @@ -69,8 +71,6 @@ typedef struct { unsigned long counter; } xnarch_atomic_t; #define xnarch_atomic_set(v,i) (((v)->counter) = (i)) -#define xnarch_write_memory_barrier() xnarch_memory_barrier() - static inline void cpu_relax(void) { asm volatile("rep; nop" ::: "memory"); @@ -107,6 +107,8 @@ xnarch_atomic_cmpxchg(xnarch_atomic_t *v, unsigned long old, unsigned long newva #define xnarch_memory_barrier() __asm__ __volatile__("": : :"memory") #define xnarch_read_memory_barrier() \ __asm__ __volatile__ (LOCK_PREFIX "addl $0,0(%%esp)": : :"memory") +#define xnarch_write_memory_barrier() \ + __asm__ __volatile__ (LOCK_PREFIX "addl $0,0(%%esp)": : :"memory") #else /* x86_64 */ @@ -137,6 +139,7 @@ xnarch_atomic_cmpxchg(xnarch_atomic_t *v, unsigned long old, unsigned long newva #define xnarch_memory_barrier() asm volatile("mfence":::"memory") #define xnarch_read_memory_barrier() asm volatile("lfence":::"memory") +#define xnarch_write_memory_barrier() asm volatile("sfence":::"memory") #endif /* x86_64 */ diff --git a/include/nucleus/Makefile.am b/include/nucleus/Makefile.am index 9a72b24..5fc1c21 100644 --- a/include/nucleus/Makefile.am +++ b/include/nucleus/Makefile.am @@ -35,6 +35,6 @@ includesub_HEADERS = \ trace.h \ types.h \ vdso.h \ - seqlock_user.h \ + seqlock.h \ version.h \ xenomai.h diff --git a/include/nucleus/Makefile.in b/include/nucleus/Makefile.in index 5e93dc9..a6fa801 100644 --- a/include/nucleus/Makefile.in +++ b/include/nucleus/Makefile.in @@ -231,6 +231,7 @@ includesub_HEADERS = \ bufd.h \ compiler.h \ heap.h \ + hostrt.h \ intr.h \ jhash.h \ map.h \ @@ -259,6 +260,7 @@ includesub_HEADERS = \ trace.h \ types.h \ vdso.h \ + seqlock.h \ version.h \ xenomai.h diff --git a/include/nucleus/hostrt.h b/include/nucleus/hostrt.h index 70ffbfe..85b8e88 100644 --- a/include/nucleus/hostrt.h +++ b/include/nucleus/hostrt.h @@ -23,32 +23,24 @@ * 02111-1307, USA. */ -#include <nucleus/types.h> -#ifdef __KERNEL__ -#include <asm-generic/xenomai/system.h> -#else /* !__KERNEL__ */ +#ifndef __KERNEL__ #include <time.h> #include <sys/types.h> -#include <nucleus/seqlock_user.h> -typedef u_int32_t u32; -typedef u_int64_t cycle_t; +#else /* __KERNEL__ */ +#include <asm-generic/xenomai/system.h> +#endif /* __KERNEL__ */ +#include <nucleus/seqlock.h> -/* - * xnarch_hostrt_data must be kept in sync with the corresponding ipipe - * definitions in ipipe_tickdev.h We cannot directly include the file - * here because the definitions are also required in Xenomai userland. - */ -struct xnarch_hostrt_data { +struct xnvdso_hostrt_data { short live; - seqcount_t seqcount; + xnseqcount_t seqcount; time_t wall_time_sec; - u32 wall_time_nsec; + unsigned wall_time_nsec; struct timespec wall_to_monotonic; - cycle_t cycle_last; - cycle_t mask; - u32 mult; - u32 shift; + unsigned long long cycle_last; + unsigned long long mask; + unsigned mult; + unsigned shift; }; -#endif /* !__KERNEL__ */ #endif diff --git a/include/nucleus/seqlock_user.h b/include/nucleus/seqlock.h similarity index 60% rename from include/nucleus/seqlock_user.h rename to include/nucleus/seqlock.h index 598d4da..897d411 100644 --- a/include/nucleus/seqlock_user.h +++ b/include/nucleus/seqlock.h @@ -1,19 +1,19 @@ -#ifndef __SEQLOCK_USER_H -#define __SEQLOCK_USER_H +#ifndef __SEQLOCK_H +#define __SEQLOCK_H /* Originally from the linux kernel, adapted for userland and Xenomai */ #include <asm/xenomai/atomic.h> -typedef struct seqcount { +typedef struct xnseqcount { unsigned sequence; -} seqcount_t; +} xnseqcount_t; -#define SEQCNT_ZERO { 0 } -#define seqcount_init(x) do { *(x) = (seqcount_t) SEQCNT_ZERO; } while (0) +#define XNSEQCNT_ZERO { 0 } +#define xnseqcount_init(x) do { *(x) = (xnseqcount_t) SEQCNT_ZERO; } while (0) /* Start of read using pointer to a sequence counter only. */ -static inline unsigned read_seqcount_begin(const seqcount_t *s) +static inline unsigned xnread_seqcount_begin(const xnseqcount_t *s) { unsigned ret; @@ -30,7 +30,7 @@ repeat: /* * Test if reader processed invalid data because sequence number has changed. */ -static inline int read_seqcount_retry(const seqcount_t *s, unsigned start) +static inline int xnread_seqcount_retry(const xnseqcount_t *s, unsigned start) { xnarch_read_memory_barrier(); @@ -42,16 +42,16 @@ static inline int read_seqcount_retry(const seqcount_t *s, unsigned start) * The sequence counter only protects readers from concurrent writers. * Writers must use their own locking. */ -static inline void write_seqcount_begin(seqcount_t *s) +static inline void xnwrite_seqcount_begin(xnseqcount_t *s) { s->sequence++; xnarch_write_memory_barrier(); } -static inline void write_seqcount_end(seqcount_t *s) +static inline void xnwrite_seqcount_end(xnseqcount_t *s) { xnarch_write_memory_barrier(); s->sequence++; } -#endif +#endif /* __SEQLOCK_H */ diff --git a/include/nucleus/vdso.h b/include/nucleus/vdso.h index bce4c5a..279574b 100644 --- a/include/nucleus/vdso.h +++ b/include/nucleus/vdso.h @@ -34,7 +34,7 @@ struct xnvdso { unsigned long long features; - struct xnarch_hostrt_data hostrt_data; + struct xnvdso_hostrt_data hostrt_data; /* * Embed further domain specific structures that * describe the shared data here @@ -61,7 +61,7 @@ struct xnvdso { extern struct xnvdso *nkvdso; -static inline struct xnarch_hostrt_data *get_hostrt_data(void) +static inline struct xnvdso_hostrt_data *get_hostrt_data(void) { return &nkvdso->hostrt_data; } diff --git a/ksrc/nucleus/module.c b/ksrc/nucleus/module.c index 3f962ba..234a82a 100644 --- a/ksrc/nucleus/module.c +++ b/ksrc/nucleus/module.c @@ -69,7 +69,7 @@ static inline void do_hostrt_event(struct xnarch_hostrt_data *hostrt) */ spin_lock_irqsave(&__hostrtlock, flags); - write_seqcount_begin(&nkvdso->hostrt_data.seqcount); + xnwrite_seqcount_begin(&nkvdso->hostrt_data.seqcount); nkvdso->hostrt_data.live = 1; nkvdso->hostrt_data.cycle_last = hostrt->cycle_last; @@ -80,7 +80,7 @@ static inline void do_hostrt_event(struct xnarch_hostrt_data *hostrt) nkvdso->hostrt_data.wall_time_nsec = hostrt->wall_time_nsec; nkvdso->hostrt_data.wall_to_monotonic = hostrt->wall_to_monotonic; - write_seqcount_end(&nkvdso->hostrt_data.seqcount); + xnwrite_seqcount_end(&nkvdso->hostrt_data.seqcount); spin_unlock_irqrestore(&__hostrtlock, flags); } @@ -88,7 +88,7 @@ RTHAL_DECLARE_HOSTRT_EVENT(hostrt_event); static inline void init_hostrt(void) { - seqcount_init(&nkvdso->hostrt_data.seqcount); + xnseqcount_init(&nkvdso->hostrt_data.seqcount); nkvdso->hostrt_data.live = 0; rthal_catch_hostrt(&hostrt_event); } @@ -170,7 +170,7 @@ int __init __xeno_sys_init(void) xnheap_init_vdso(); init_hostrt(); #endif /* !__XENO_SIM__ */ - + #ifdef __KERNEL__ xnpod_mount(); xnintr_mount(); @@ -228,7 +228,7 @@ int __init __xeno_sys_init(void) #ifdef CONFIG_XENO_OPT_SELECT xnselect_umount(); - + cleanup_pipe: #endif /* CONFIG_XENO_OPT_SELECT */ diff --git a/ksrc/skins/posix/clock.c b/ksrc/skins/posix/clock.c index 62493f1..9682380 100644 --- a/ksrc/skins/posix/clock.c +++ b/ksrc/skins/posix/clock.c @@ -75,7 +75,7 @@ * @see * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/clock_getres.html"> * Specification.</a> - * + * */ int clock_getres(clockid_t clock_id, struct timespec *res) { @@ -110,7 +110,7 @@ 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; + struct xnvdso_hostrt_data *hostrt_data; unsigned int seq; hostrt_data = get_hostrt_data(); @@ -128,7 +128,7 @@ static int do_clock_host_realtime(struct timespec *tp) * spinlock is not possible. */ retry: - seq = read_seqcount_begin(&hostrt_data->seqcount); + seq = xnread_seqcount_begin(&hostrt_data->seqcount); now = xnarch_get_cpu_tsc(); base = hostrt_data->cycle_last; @@ -138,7 +138,7 @@ retry: tp->tv_sec = hostrt_data->wall_time_sec; nsec = hostrt_data->wall_time_nsec; - if (read_seqcount_retry(&hostrt_data->seqcount, seq)) + if (xnread_seqcount_retry(&hostrt_data->seqcount, seq)) goto retry; /* @@ -161,7 +161,7 @@ retry: } /** - * Read the specified clock. + * Read the specified clock. * * This service returns, at the address @a tp the current value of the clock @a * clock_id. If @a clock_id is: @@ -182,11 +182,11 @@ retry: * @retval 0 on success; * @retval -1 with @a errno set if: * - EINVAL, @a clock_id is invalid. - * + * * @see * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/clock_gettime.html"> * Specification.</a> - * + * */ int clock_gettime(clockid_t clock_id, struct timespec *tp) { @@ -236,7 +236,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) * @see * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/clock_settime.html"> * Specification.</a> - * + * */ int clock_settime(clockid_t clock_id, const struct timespec *tp) { @@ -300,7 +300,7 @@ int clock_settime(clockid_t clock_id, const struct timespec *tp) * @see * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/clock_nanosleep.html"> * Specification.</a> - * + * */ int clock_nanosleep(clockid_t clock_id, int flags, @@ -387,7 +387,7 @@ int clock_nanosleep(clockid_t clock_id, * @see * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/nanosleep.html"> * Specification.</a> - * + * */ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) { diff --git a/src/skins/posix/clock.c b/src/skins/posix/clock.c index 7232c48..4f2171b 100644 --- a/src/skins/posix/clock.c +++ b/src/skins/posix/clock.c @@ -25,7 +25,6 @@ #include <time.h> #include <asm/xenomai/arith.h> #include <asm-generic/xenomai/timeconv.h> -#include <nucleus/seqlock_user.h> #include <sys/types.h> #include <nucleus/vdso.h> @@ -63,9 +62,9 @@ int __do_clock_host_realtime(struct timespec *ts, void *tzp) { #ifdef XNARCH_HAVE_NONPRIV_TSC unsigned int seq; - cycle_t now, base, mask, cycle_delta; + unsigned long long now, base, mask, cycle_delta; unsigned long mult, shift, nsec, rem; - struct xnarch_hostrt_data *hostrt_data; + struct xnvdso_hostrt_data *hostrt_data; if (!xnvdso_test_feature(XNVDSO_FEAT_HOST_REALTIME)) return -1; @@ -80,7 +79,7 @@ int __do_clock_host_realtime(struct timespec *ts, void *tzp) * mechanism in the kernel. */ retry: - seq = read_seqcount_begin(&hostrt_data->seqcount); + seq = xnread_seqcount_begin(&hostrt_data->seqcount); now = __xn_rdtsc(); base = hostrt_data->cycle_last; @@ -92,7 +91,7 @@ retry: /* If the data changed during the read, try the alternative data element */ - if (read_seqcount_retry(&hostrt_data->seqcount, seq)) + if (xnread_seqcount_retry(&hostrt_data->seqcount, seq)) goto retry; cycle_delta = (now - base) & mask; diff --git a/src/testsuite/clocktest/clocktest.c b/src/testsuite/clocktest/clocktest.c index bf4feb6..038cfbc 100644 --- a/src/testsuite/clocktest/clocktest.c +++ b/src/testsuite/clocktest/clocktest.c @@ -99,8 +99,8 @@ static void show_hostrt_diagnostics(void) (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("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); } @@ -276,11 +276,11 @@ int main(int argc, char *argv[]) printf("== Tested clock: %d (", clock_id); switch (clock_id) { - case CLOCK_REALTIME: + case CLOCK_REALTIME: printf("CLOCK_REALTIME"); break; - case CLOCK_MONOTONIC: + case CLOCK_MONOTONIC: printf("CLOCK_MONOTONIC"); break; @@ -288,7 +288,7 @@ int main(int argc, char *argv[]) printf("CLOCK_HOST_REALTIME"); break; - default: + default: printf("<unknown>"); break; } _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git