Module: xenomai-2.6
Branch: master
Commit: 42a75ef2b77250ddbbf781eafec4de280fd909af
URL:    
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=42a75ef2b77250ddbbf781eafec4de280fd909af

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sat May 12 03:35:58 2012 +0200

hal/x86: fixup for refactored timers

---

 include/asm-x86/bits/init_32.h |    2 +-
 include/asm-x86/bits/init_64.h |    2 +-
 include/asm-x86/bits/timer.h   |    2 +-
 include/asm-x86/calibration.h  |   62 ++++++++++++++++++---------
 include/asm-x86/hal.h          |    4 ++
 include/asm-x86/hal_32.h       |   22 ++++++----
 include/asm-x86/hal_64.h       |   22 +++++++---
 ksrc/arch/x86/hal-common.c     |   92 ++++++++++++++++++++++++++++++++++++----
 ksrc/arch/x86/hal_32.c         |   39 +++++++++++++----
 ksrc/arch/x86/hal_64.c         |   32 +++++++++++---
 scripts/Kconfig.frag           |   17 ++++----
 11 files changed, 227 insertions(+), 69 deletions(-)

diff --git a/include/asm-x86/bits/init_32.h b/include/asm-x86/bits/init_32.h
index b03e7f6..589a845 100644
--- a/include/asm-x86/bits/init_32.h
+++ b/include/asm-x86/bits/init_32.h
@@ -58,7 +58,7 @@ static inline unsigned long xnarch_calibrate_timer(void)
           kernel configuration Xenomai is compiled against, the
           calibrated value will either refer to the local APIC or
           8254 timer latency value. */
-       return xnarch_ns_to_tsc(rthal_timer_calibrate())? : 1;
+       return rthal_timer_calibrate() ? : 1;
 }
 
 int xnarch_calibrate_sched(void)
diff --git a/include/asm-x86/bits/init_64.h b/include/asm-x86/bits/init_64.h
index 81776fc..922d9c4 100644
--- a/include/asm-x86/bits/init_64.h
+++ b/include/asm-x86/bits/init_64.h
@@ -55,7 +55,7 @@ static inline unsigned long xnarch_calibrate_timer(void)
        /* Compute the time needed to program the APIC timer in aperiodic
           mode. The return value is expressed in CPU ticks. It is assumed
           that CONFIG_X86_LOCAL_APIC is always enabled for x86_64. */
-       return xnarch_ns_to_tsc(rthal_timer_calibrate())? : 1;
+       return rthal_timer_calibrate()? : 1;
 }
 
 int xnarch_calibrate_sched(void)
diff --git a/include/asm-x86/bits/timer.h b/include/asm-x86/bits/timer.h
index 09033af..9e9b863 100644
--- a/include/asm-x86/bits/timer.h
+++ b/include/asm-x86/bits/timer.h
@@ -39,7 +39,7 @@ static inline void xnarch_program_timer_shot(unsigned long 
delay)
 static inline void xnarch_send_timer_ipi(xnarch_cpumask_t mask)
 {
 #ifdef CONFIG_SMP
-       rthal_send_ipi(RTHAL_APIC_TIMER_IPI, mask);
+       rthal_send_ipi(RTHAL_TIMER_IPI, mask);
 #endif /* CONFIG_SMP */
 }
 
diff --git a/include/asm-x86/calibration.h b/include/asm-x86/calibration.h
index 7cd5ac9..7520244 100644
--- a/include/asm-x86/calibration.h
+++ b/include/asm-x86/calibration.h
@@ -32,30 +32,52 @@ static inline unsigned long xnarch_get_sched_latency (void)
 
 #if CONFIG_XENO_OPT_TIMING_SCHEDLAT != 0
        sched_latency = CONFIG_XENO_OPT_TIMING_SCHEDLAT;
-#else
+#else /* !CONFIG_XENO_OPT_TIMING_SCHEDLAT */
+
+       if (strcmp(RTHAL_TIMER_DEVICE, "lapic") == 0) {
 #ifdef CONFIG_SMP
-       sched_latency = 3350;
-#elif defined(CONFIG_X86_LOCAL_APIC)
-       sched_latency = 1000;
-#else /* !CONFIG_X86_LOCAL_APIC */
-       /*
-        * Use the bogomips formula to identify low-end x86 boards
-        * when using the 8254 PIT. The following is still grossly
-        * experimental and needs work (i.e. more specific cases), but
-        * the approach is definitely saner than previous attempts to
-        * guess such value dynamically.
-        */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)
-#define __bogomips (current_cpu_data.loops_per_jiffy/(500000/HZ))
-#else
+               if (num_online_cpus() > 1)
+                       sched_latency = 3350;
+               else
+                       sched_latency = 2000;
+#else /* !SMP */
+               sched_latency = 1000;
+#endif /* !SMP */
+       } else if (strcmp(RTHAL_TIMER_DEVICE, "pit")) { /* HPET */
+#ifdef CONFIG_SMP
+               if (num_online_cpus() > 1)
+                       sched_latency = 3350;
+               else
+                       sched_latency = 1500;
+#else /* !SMP */
+               sched_latency = 1000;
+#endif /* !SMP */
+       } else {
+               /*
+                * Use the bogomips formula to identify low-end x86 boards
+                * when using the 8254 PIT. The following is still grossly
+                * experimental and needs work (i.e. more specific cases), but
+                * the approach is definitely saner than previous attempts to
+                * guess such value dynamically.
+                */
+#ifdef CONFIG_IPIPE_CORE
+#define __bogomips (this_cpu_read(cpu_info.loops_per_jiffy)/(500000/HZ))
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)
 #define __bogomips (cpu_info.loops_per_jiffy/(500000/HZ))
+#else
+#define __bogomips (current_cpu_data.loops_per_jiffy/(500000/HZ))
 #endif
-       sched_latency = (__bogomips < 250 ? 17000 :
-                        __bogomips < 2500 ? 4200 :
-                        3500);
+
+               sched_latency = (__bogomips < 250 ? 17000 :
+                                __bogomips < 2500 ? 4200 :
+                                3500);
 #undef __bogomips
-#endif /* CONFIG_X86_LOCAL_APIC */
-#endif /* CONFIG_XENO_OPT_TIMING_SCHEDLAT */
+
+#ifdef CONFIG_SMP
+               sched_latency += 1000;
+#endif /* CONFIG_SMP */
+       }
+#endif /* !CONFIG_XENO_OPT_TIMING_SCHEDLAT */
 
        return sched_latency;
 }
diff --git a/include/asm-x86/hal.h b/include/asm-x86/hal.h
index 158e3e6..b63f098 100644
--- a/include/asm-x86/hal.h
+++ b/include/asm-x86/hal.h
@@ -25,6 +25,9 @@
 
 #include <linux/ipipe.h>
 
+#ifdef CONFIG_IPIPE_CORE
+#define RTHAL_COMPAT_TIMERFREQ         __ipipe_hrtimer_freq
+#else
 #ifdef CONFIG_X86_LOCAL_APIC
 #ifdef __IPIPE_FEATURE_APIC_TIMER_FREQ
 #define RTHAL_COMPAT_TIMERFREQ         __ipipe_apic_timer_freq
@@ -35,6 +38,7 @@
 #else
 #define RTHAL_COMPAT_TIMERFREQ         CLOCK_TICK_RATE
 #endif
+#endif
 
 #if defined(CONFIG_GENERIC_CLOCKEVENTS) && 
!defined(__IPIPE_FEATURE_REQUEST_TICKDEV)
 
diff --git a/include/asm-x86/hal_32.h b/include/asm-x86/hal_32.h
index 34ac10d..f61e2ec 100644
--- a/include/asm-x86/hal_32.h
+++ b/include/asm-x86/hal_32.h
@@ -38,7 +38,9 @@
 #define _XENO_ASM_X86_HAL_32_H
 
 #define RTHAL_ARCH_NAME                        "i386"
-#ifdef CONFIG_X86_LOCAL_APIC
+#ifdef CONFIG_IPIPE_CORE
+# define RTHAL_TIMER_DEVICE            (ipipe_timer_name())
+#elif defined(CONFIG_X86_LOCAL_APIC)
 # define RTHAL_TIMER_DEVICE            "lapic"
 #else
 # define RTHAL_TIMER_DEVICE            "pit"
@@ -96,16 +98,16 @@ static inline __attribute_const__ unsigned long 
ffnz(unsigned long ul)
 #include <asm/xenomai/atomic.h>
 #include <asm/xenomai/smi.h>
 
-#ifdef CONFIG_X86_LOCAL_APIC
 #ifdef CONFIG_IPIPE_CORE
-#define RTHAL_HRTIMER_VECTOR   IPIPE_HRTIMER_VECTOR
-#else
+#define RTHAL_TIMER_IRQ                __ipipe_hrtimer_irq
+#define RTHAL_HOST_TICK_IRQ    __ipipe_hrtimer_irq
+#define RTHAL_TIMER_IPI                RTHAL_HRTIMER_IPI
+#elif defined(CONFIG_X86_LOCAL_APIC)
 #define RTHAL_HRTIMER_VECTOR   IPIPE_SERVICE_VECTOR0
-#endif
 #define RTHAL_APIC_TIMER_VECTOR        RTHAL_HRTIMER_VECTOR
-#define RTHAL_APIC_TIMER_IPI   RTHAL_HRTIMER_IPI
+#define RTHAL_TIMER_IPI        RTHAL_HRTIMER_IPI
 #define RTHAL_APIC_ICOUNT      ((RTHAL_TIMER_FREQ + HZ/2)/HZ)
-#define RTHAL_TIMER_IRQ                RTHAL_APIC_TIMER_IPI
+#define RTHAL_TIMER_IRQ                RTHAL_TIMER_IPI
 #define RTHAL_HOST_TICK_IRQ    ipipe_apic_vector_irq(LOCAL_TIMER_VECTOR)
 #define RTHAL_BCAST_TICK_IRQ   0       /* Tick broadcasting interrupt. */
 #ifndef ipipe_apic_vector_irq
@@ -152,6 +154,9 @@ static inline void rthal_timer_program_shot(unsigned long 
delay)
 {
 /* With head-optimization, callers are expected to have switched off
    hard-IRQs already -- no need for additional protection in this case. */
+#ifdef CONFIG_IPIPE_CORE
+       ipipe_timer_set(delay);
+#else /* !I-pipe core */
 #ifndef CONFIG_XENO_OPT_PIPELINE_HEAD
        unsigned long flags;
 
@@ -160,7 +165,7 @@ static inline void rthal_timer_program_shot(unsigned long 
delay)
 #ifdef CONFIG_X86_LOCAL_APIC
        if (!delay) {
                /* Pend the timer interrupt. */
-               rthal_schedule_irq_head(RTHAL_APIC_TIMER_IPI);
+               rthal_schedule_irq_head(RTHAL_TIMER_IPI);
        } else {
                /* Note: reading before writing just to work around the Pentium
                   APIC double write bug. apic_read() expands to nil
@@ -179,6 +184,7 @@ static inline void rthal_timer_program_shot(unsigned long 
delay)
 #ifndef CONFIG_XENO_OPT_PIPELINE_HEAD
        rthal_local_irq_restore_hw(flags);
 #endif /* CONFIG_XENO_OPT_PIPELINE_HEAD */
+#endif /* !I-pipe core */
 }
 
 static const char *const rthal_fault_labels[] = {
diff --git a/include/asm-x86/hal_64.h b/include/asm-x86/hal_64.h
index b6d083e..3462fb1 100644
--- a/include/asm-x86/hal_64.h
+++ b/include/asm-x86/hal_64.h
@@ -24,7 +24,11 @@
 #define _XENO_ASM_X86_HAL_64_H
 
 #define RTHAL_ARCH_NAME                        "x86_64"
+#ifdef CONFIG_IPIPE
+#define RTHAL_TIMER_DEVICE             (ipipe_timer_name())
+#else /* !I-ipipe core */
 #define RTHAL_TIMER_DEVICE             "lapic"
+#endif /* !I-ipipe core */
 #define RTHAL_CLOCK_DEVICE             "tsc"
 
 #include <asm/xenomai/wrappers.h>
@@ -50,17 +54,19 @@ static inline __attribute_const__ unsigned long 
ffnz(unsigned long ul)
 #include <asm/xenomai/smi.h>
 
 #ifdef CONFIG_IPIPE_CORE
-#define RTHAL_HRTIMER_VECTOR   IPIPE_HRTIMER_VECTOR
-#else
+#define RTHAL_TIMER_IRQ                __ipipe_hrtimer_irq
+#define RTHAL_HOST_TICK_IRQ    __ipipe_hrtimer_irq
+#define RTHAL_TIMER_IPI                RTHAL_HRTIMER_IPI
+#else /* !I-ipipe core */
 #define RTHAL_HRTIMER_VECTOR   IPIPE_SERVICE_VECTOR0
-#endif
 #define RTHAL_APIC_TIMER_VECTOR        RTHAL_HRTIMER_VECTOR
-#define RTHAL_APIC_TIMER_IPI   RTHAL_HRTIMER_IPI
+#define RTHAL_TIMER_IPI                RTHAL_HRTIMER_IPI
 #define RTHAL_APIC_ICOUNT      ((RTHAL_TIMER_FREQ + HZ/2)/HZ)
-#define RTHAL_TIMER_IRQ                RTHAL_APIC_TIMER_IPI
+#define RTHAL_TIMER_IRQ                RTHAL_TIMER_IPI
 #define RTHAL_NMICLK_FREQ      RTHAL_CPU_FREQ
 #define RTHAL_HOST_TICK_IRQ    ipipe_apic_vector_irq(LOCAL_TIMER_VECTOR)
 #define RTHAL_BCAST_TICK_IRQ   0
+#endif /* !I-ipipe core */
 
 static inline void rthal_grab_control(void)
 {
@@ -82,6 +88,9 @@ static inline unsigned long long rthal_rdtsc(void)
 
 static inline void rthal_timer_program_shot(unsigned long delay)
 {
+#ifdef CONFIG_IPIPE_CORE
+       ipipe_timer_set(delay);
+#else /* !I-pipe core */
 /* With head-optimization, callers are expected to have switched off
    hard-IRQs already -- no need for additional protection in this
    case. */
@@ -94,10 +103,11 @@ static inline void rthal_timer_program_shot(unsigned long 
delay)
                apic_write(APIC_TMICT,delay);
        else
                /* Pend the timer interrupt. */
-               rthal_schedule_irq_head(RTHAL_APIC_TIMER_IPI);
+               rthal_schedule_irq_head(RTHAL_TIMER_IPI);
 #ifndef CONFIG_XENO_OPT_PIPELINE_HEAD
        rthal_local_irq_restore_hw(flags);
 #endif /* CONFIG_XENO_OPT_PIPELINE_HEAD */
+#endif /* !I-pipe core */
 }
 
 static const char *const rthal_fault_labels[] = {
diff --git a/ksrc/arch/x86/hal-common.c b/ksrc/arch/x86/hal-common.c
index 7bc73c3..6fa4f73 100644
--- a/ksrc/arch/x86/hal-common.c
+++ b/ksrc/arch/x86/hal-common.c
@@ -38,7 +38,84 @@ static struct {
        int count;
 } rthal_linux_irq[IPIPE_NR_XIRQS];
 
-#ifdef CONFIG_X86_LOCAL_APIC
+static int cpu_timers_requested;
+
+#ifdef CONFIG_IPIPE_CORE
+
+int rthal_timer_request(
+       void (*tick_handler)(void),
+       void (*mode_emul)(enum clock_event_mode mode,
+                         struct clock_event_device *cdev),
+       int (*tick_emul)(unsigned long delay,
+                        struct clock_event_device *cdev),
+       int cpu)
+{
+       int tickval, res;
+
+       res = ipipe_timer_start(tick_handler, mode_emul, tick_emul, cpu);
+
+       switch (res) {
+       case CLOCK_EVT_MODE_PERIODIC:
+               /* oneshot tick emulation callback won't be used, ask
+                * the caller to start an internal timer for emulating
+                * a periodic tick. */
+               tickval = 1000000000UL / HZ;
+               break;
+
+       case CLOCK_EVT_MODE_ONESHOT:
+               /* oneshot tick emulation */
+               tickval = 1;
+               break;
+
+       case CLOCK_EVT_MODE_UNUSED:
+               /* we don't need to emulate the tick at all. */
+               tickval = 0;
+               break;
+
+       case CLOCK_EVT_MODE_SHUTDOWN:
+               res = -ENODEV;
+               /* fall through */
+
+       default:
+               return res;
+       }
+       rthal_ktimer_saved_mode = res;
+
+       if (cpu_timers_requested++ > 0)
+               return tickval;
+
+#ifdef CONFIG_SMP
+       if (num_online_cpus() > 1) {
+               int err = rthal_irq_request(RTHAL_TIMER_IPI,
+                                       (rthal_irq_handler_t) tick_handler,
+                                       NULL, NULL);
+               if (err)
+                       return err;
+
+       }
+#endif /* CONFIG_SMP */
+
+       return tickval;
+}
+
+void rthal_timer_release(int cpu)
+{
+       ipipe_timer_stop(cpu);
+
+       /*
+        * The rest of the cleanup work should only be performed once
+        * by the last releasing CPU.
+        */
+       if (--cpu_timers_requested > 0)
+               return;
+
+#ifdef CONFIG_SMP
+       if (num_online_cpus() > 1)
+               rthal_irq_release(RTHAL_TIMER_IPI);
+#endif
+}
+
+#elif defined(CONFIG_X86_LOCAL_APIC)
 
 #define RTHAL_SET_ONESHOT_XENOMAI      1
 #define RTHAL_SET_ONESHOT_LINUX                2
@@ -99,8 +176,6 @@ static void rthal_timer_set_periodic(void)
        rthal_critical_exit(flags);
 }
 
-static int cpu_timers_requested;
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 int rthal_timer_request(
@@ -115,7 +190,7 @@ int rthal_timer_request(
        int tickval, err, res;
 
        if (cpu_timers_requested == 0) {
-               err = rthal_irq_request(RTHAL_APIC_TIMER_IPI,
+               err = rthal_irq_request(RTHAL_TIMER_IPI,
                                        (rthal_irq_handler_t) tick_handler,
                                        NULL, NULL);
                if (err)
@@ -160,7 +235,7 @@ int rthal_timer_request(
 
        default:
                if (cpu_timers_requested == 0)
-                       rthal_irq_release(RTHAL_APIC_TIMER_IPI);
+                       rthal_irq_release(RTHAL_TIMER_IPI);
                return res;
        }
        rthal_ktimer_saved_mode = res;
@@ -214,7 +289,7 @@ int rthal_timer_request(void (*tick_handler)(void), int cpu)
         * support for clock events, we do not need to relay the host tick
         * since 8254 interrupts are already flowing normally to Linux
         * (i.e. the nucleus does not intercept them, but uses a dedicated
-        * APIC-based timer interrupt instead, i.e. RTHAL_APIC_TIMER_IPI).
+        * APIC-based timer interrupt instead, i.e. RTHAL_TIMER_IPI).
         *
         * This code works both for UP+LAPIC and SMP configurations.
         */
@@ -230,7 +305,7 @@ int rthal_timer_request(void (*tick_handler)(void), int cpu)
        if (cpu_timers_requested++ > 0)
                goto out;
 
-       err = rthal_irq_request(RTHAL_APIC_TIMER_IPI,
+       err = rthal_irq_request(RTHAL_TIMER_IPI,
                          (rthal_irq_handler_t) tick_handler, NULL, NULL);
 
        if (err)
@@ -277,9 +352,8 @@ void rthal_timer_release(int cpu)
        else if (rthal_ktimer_saved_mode == KTIMER_MODE_ONESHOT)
                rthal_timer_set_oneshot(0);
 
-       rthal_irq_release(RTHAL_APIC_TIMER_IPI);
+       rthal_irq_release(RTHAL_TIMER_IPI);
 }
-
 #endif /* CONFIG_X86_LOCAL_APIC */
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
diff --git a/ksrc/arch/x86/hal_32.c b/ksrc/arch/x86/hal_32.c
index 05ff9d6..5f58703 100644
--- a/ksrc/arch/x86/hal_32.c
+++ b/ksrc/arch/x86/hal_32.c
@@ -68,24 +68,30 @@ static void dummy_mksound(unsigned int hz, unsigned int 
ticks)
 #include <asm/nmi.h>
 #endif
 
-#ifdef CONFIG_X86_LOCAL_APIC
+#if defined(CONFIG_X86_LOCAL_APIC) || defined(CONFIG_IPIPE_CORE)
 
 unsigned long rthal_timer_calibrate(void)
 {
-       unsigned long flags, v;
+       unsigned long v, flags;
        rthal_time_t t, dt;
        int i;
 
+#ifndef CONFIG_IPIPE_CORE
+       v = 1;
+#else /* I-pipe core */
+       v = RTHAL_TIMER_FREQ / HZ;
+#endif /* I-pipe core */
+
        flags = rthal_critical_enter(NULL);
 
+       rthal_timer_program_shot(v);
+
        t = rthal_rdtsc();
 
-       for (i = 0; i < 20; i++) {
-               v = apic_read(APIC_TMICT);
-               apic_write(APIC_TMICT, v);
-       }
+       for (i = 0; i < 100; i++)
+               rthal_timer_program_shot(v);
 
-       dt = (rthal_rdtsc() - t) / 2;
+       dt = (rthal_rdtsc() - t);
 
        rthal_critical_exit(flags);
 
@@ -94,7 +100,7 @@ unsigned long rthal_timer_calibrate(void)
        rthal_trace_max_reset();
 #endif /* CONFIG_IPIPE_TRACE_IRQSOFF */
 
-       return rthal_imuldiv(dt, 20, RTHAL_CPU_FREQ);
+       return rthal_ulldiv(dt, i + 5, NULL);
 }
 
 #else /* !CONFIG_X86_LOCAL_APIC */
@@ -138,7 +144,7 @@ unsigned long rthal_timer_calibrate(void)
        rthal_trace_max_reset();
 #endif /* CONFIG_IPIPE_TRACE_IRQSOFF */
 
-       return rthal_imuldiv(dt, 20, RTHAL_CPU_FREQ);
+       return rthal_ulldiv(dt, i, NULL);
 }
 
 static void rthal_timer_set_oneshot(void)
@@ -330,6 +336,11 @@ rthal_time_t rthal_get_8254_tsc(void)
 
 int rthal_arch_init(void)
 {
+#ifdef CONFIG_IPIPE_CORE
+       int rc = ipipe_timers_request();
+       if (rc < 0)
+               return rc;
+#else /* !I-pipe core */
 #ifdef CONFIG_X86_LOCAL_APIC
        if (!boot_cpu_has(X86_FEATURE_APIC)) {
                printk("Xenomai: Local APIC absent or disabled!\n"
@@ -344,6 +355,7 @@ int rthal_arch_init(void)
        old_mksound = kd_mksound;
        kd_mksound = &dummy_mksound;
 #endif /* !CONFIG_X86_LOCAL_APIC && Linux < 2.6 && !CONFIG_X86_TSC && 
CONFIG_VT */
+#endif /* !I-pipe core */
 
        if (rthal_cpufreq_arg == 0)
 #ifdef CONFIG_X86_TSC
@@ -358,15 +370,24 @@ int rthal_arch_init(void)
        if (rthal_clockfreq_arg == 0)
                rthal_clockfreq_arg = rthal_get_clockfreq();
 
+#ifdef CONFIG_IPIPE_CORE
+       if (rthal_timerfreq_arg == 0)
+               rthal_timerfreq_arg = rthal_get_timerfreq();
+#endif
+
        return 0;
 }
 
 void rthal_arch_cleanup(void)
 {
+#ifdef CONFIG_IPIPE_CORE
+       ipipe_timers_release();
+#else /* !I-pipe core */
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) && !defined(CONFIG_X86_TSC) && 
defined(CONFIG_VT)
        /* Restore previous PC speaker code. */
        kd_mksound = old_mksound;
 #endif /* Linux < 2.6 && !CONFIG_X86_TSC && CONFIG_VT */
+#endif /* !I-pipe core */
        printk(KERN_INFO "Xenomai: hal/i386 stopped.\n");
 }
 
diff --git a/ksrc/arch/x86/hal_64.c b/ksrc/arch/x86/hal_64.c
index f392b32..9c5c390 100644
--- a/ksrc/arch/x86/hal_64.c
+++ b/ksrc/arch/x86/hal_64.c
@@ -52,16 +52,22 @@ unsigned long rthal_timer_calibrate(void)
        rthal_time_t t, dt;
        int i;
 
+#ifndef CONFIG_IPIPE_CORE
+       v = 1;
+#else /* I-pipe core */
+       v = RTHAL_TIMER_FREQ / HZ;
+#endif /* I-pipe core */
+
        flags = rthal_critical_enter(NULL);
 
+       rthal_timer_program_shot(v);
+
        t = rthal_rdtsc();
 
-       for (i = 0; i < 20; i++) {
-               v = apic_read(APIC_TMICT);
-               apic_write(APIC_TMICT, v);
-       }
+       for (i = 0; i < 100; i++)
+               rthal_timer_program_shot(v);
 
-       dt = (rthal_rdtsc() - t) / 2;
+       dt = (rthal_rdtsc() - t);
 
        rthal_critical_exit(flags);
 
@@ -70,11 +76,17 @@ unsigned long rthal_timer_calibrate(void)
        rthal_trace_max_reset();
 #endif /* CONFIG_IPIPE_TRACE_IRQSOFF */
 
-       return rthal_imuldiv(dt, 20, RTHAL_CPU_FREQ);
+       return rthal_ulldiv(dt, i + 5, NULL);
 }
 
 int rthal_arch_init(void)
 {
+#ifdef CONFIG_IPIPE_CORE
+       int rc = ipipe_timers_request();
+       if (rc < 0)
+               return rc;
+#endif /* I-pipe core */
+
        if (rthal_cpufreq_arg == 0)
                /* FIXME: 4Ghz barrier is close... */
                rthal_cpufreq_arg = rthal_get_cpufreq();
@@ -82,11 +94,19 @@ int rthal_arch_init(void)
        if (rthal_clockfreq_arg == 0)
                rthal_clockfreq_arg = rthal_get_clockfreq();
 
+#ifdef CONFIG_IPIPE_CORE
+       if (rthal_timerfreq_arg == 0)
+               rthal_timerfreq_arg = rthal_get_timerfreq();
+#endif
+
        return 0;
 }
 
 void rthal_arch_cleanup(void)
 {
+#ifdef CONFIG_IPIPE_CORE
+       ipipe_timers_release();
+#endif /* I-pipe core */
        printk(KERN_INFO "Xenomai: hal/x86_64 stopped.\n");
 }
 
diff --git a/scripts/Kconfig.frag b/scripts/Kconfig.frag
index c136ebf..c72f24c 100644
--- a/scripts/Kconfig.frag
+++ b/scripts/Kconfig.frag
@@ -1,4 +1,3 @@
-
 menu "Real-time sub-system"
 
 if APM || CPU_FREQ || ACPI_PROCESSOR || INTEL_IDLE
@@ -12,22 +11,24 @@ comment "NOTE: Xenomai conflicts with PC speaker support."
 comment "(menu Device Drivers/Input device support/Miscellaneous devices)"
        depends on !X86_TSC && X86 && INPUT_PCSPKR
 
+if !IPIPE_CORE
 comment "NOTE: Xenomai needs either X86_LOCAL_APIC enabled or HPET_TIMER 
disabled."
        depends on (!X86_LOCAL_APIC || !X86_TSC) && X86 && HPET_TIMER
 comment "(menu Processor type and features)"
        depends on (!X86_LOCAL_APIC || !X86_TSC) && X86 && HPET_TIMER
+endif
 
 config XENOMAI
-       depends on ((X86_TSC || !X86 || !INPUT_PCSPKR) && (!HPET_TIMER || !X86 
|| (X86_LOCAL_APIC && X86_TSC)))
+       depends on ((X86_TSC || !X86 || !INPUT_PCSPKR) && (IPIPE_CORE || 
!HPET_TIMER || !X86 || (X86_LOCAL_APIC && X86_TSC)))
        bool "Xenomai"
        default y
-        select IPIPE
+       select IPIPE
 
-        help
-          Xenomai is a real-time extension to the Linux kernel. Note
-          that Xenomai relies on Adeos interrupt pipeline (CONFIG_IPIPE
-          option) to be enabled, so enabling this option selects the
-          CONFIG_IPIPE option.
+       help
+         Xenomai is a real-time extension to the Linux kernel. Note
+         that Xenomai relies on Adeos interrupt pipeline (CONFIG_IPIPE
+         option) to be enabled, so enabling this option selects the
+         CONFIG_IPIPE option.
 
 source "arch/@LINUX_ARCH@/xenomai/Kconfig"
 


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

Reply via email to