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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Jan  1 12:09:10 2012 +0100

hal: factor out timer and scheduler calibration

All architectures can use the same code for calibrating the system
timer, providing all implementations of rthal_timer_calibrate() are
aligned to return clock cycles.

Scheduler calibration is already a generic operation we can fold in
the xnarch_init() code.

---

 include/asm-arm/bits/init.h       |   30 +++++-------------------------
 include/asm-blackfin/bits/init.h  |   30 +++++-------------------------
 include/asm-nios2/bits/init.h     |   28 +++++-----------------------
 include/asm-powerpc/bits/init.h   |   30 +++++-------------------------
 include/asm-sh/bits/init.h        |   28 +++++-----------------------
 include/asm-x86/bits/init_32.h    |   32 +++++---------------------------
 include/asm-x86/bits/init_64.h    |   31 +++++--------------------------
 kernel/cobalt/arch/blackfin/hal.c |    2 +-
 kernel/cobalt/arch/nios2/hal.c    |   10 +++-------
 kernel/cobalt/arch/powerpc/hal.c  |    2 +-
 kernel/cobalt/arch/sh/hal.c       |   10 +++-------
 kernel/cobalt/arch/x86/hal_32.c   |    4 ++--
 kernel/cobalt/arch/x86/hal_64.c   |    2 +-
 13 files changed, 46 insertions(+), 193 deletions(-)

diff --git a/include/asm-arm/bits/init.h b/include/asm-arm/bits/init.h
index b3a7b9b..453d1cb 100644
--- a/include/asm-arm/bits/init.h
+++ b/include/asm-arm/bits/init.h
@@ -35,28 +35,6 @@ int xnarch_escalation_virq;
 
 void xnpod_schedule_handler(void);
 
-unsigned long xnarch_calibrate_timer(void)
-{
-       /*
-        * Compute the time needed to program the decrementer in
-        * aperiodic mode. The return value is expressed in timebase
-        * ticks.
-        */
-       return rthal_timer_calibrate() ? : 1;
-}
-
-int xnarch_calibrate_sched(void)
-{
-       nktimerlat = xnarch_calibrate_timer();
-
-       if (nktimerlat == 0)
-               return -ENODEV;
-
-       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
-
-       return 0;
-}
-
 static inline int xnarch_init(void)
 {
        int ret;
@@ -67,9 +45,11 @@ static inline int xnarch_init(void)
 
        xnarch_init_timeconv(RTHAL_CLOCK_FREQ);
 
-       ret = xnarch_calibrate_sched();
-       if (ret)
-               return ret;
+       nktimerlat = rthal_timer_calibrate();
+       if (nktimerlat == 0)
+               return -ENODEV;
+
+       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
 
        xnarch_escalation_virq = ipipe_alloc_virq();
        if (xnarch_escalation_virq == 0)
diff --git a/include/asm-blackfin/bits/init.h b/include/asm-blackfin/bits/init.h
index 6e53465..101abc2 100644
--- a/include/asm-blackfin/bits/init.h
+++ b/include/asm-blackfin/bits/init.h
@@ -34,28 +34,6 @@ void xnpod_schedule_handler(void);
 
 void xnpod_schedule_deferred(void);
 
-unsigned long xnarch_calibrate_timer(void)
-{
-       /*
-        * Compute the time needed to program the decrementer in
-        * aperiodic mode. The return value is expressed in timebase
-        * ticks.
-        */
-       return xnarch_ns_to_tsc(rthal_timer_calibrate())? : 1;
-}
-
-int xnarch_calibrate_sched(void)
-{
-       nktimerlat = xnarch_calibrate_timer();
-
-       if (nktimerlat == 0)
-               return -ENODEV;
-
-       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
-
-       return 0;
-}
-
 static inline int xnarch_init(void)
 {
        int ret;
@@ -68,9 +46,11 @@ static inline int xnarch_init(void)
 
        xnarch_init_timeconv(RTHAL_CLOCK_FREQ);
 
-       ret = xnarch_calibrate_sched();
-       if (ret)
-               return ret;
+       nktimerlat = rthal_timer_calibrate();
+       if (nktimerlat == 0)
+               return -ENODEV;
+
+       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
 
        xnarch_escalation_virq = ipipe_alloc_virq();
        if (xnarch_escalation_virq == 0)
diff --git a/include/asm-nios2/bits/init.h b/include/asm-nios2/bits/init.h
index 1acca9a..3971416 100644
--- a/include/asm-nios2/bits/init.h
+++ b/include/asm-nios2/bits/init.h
@@ -32,26 +32,6 @@ int xnarch_escalation_virq;
 
 void xnpod_schedule_handler(void);
 
-unsigned long xnarch_calibrate_timer(void)
-{
-       /*
-        * Compute the time needed to program the dedicated hrtimer.
-        * The return value is expressed in hrclock counter unit.
-        */
-       return xnarch_ns_to_tsc(rthal_timer_calibrate());
-}
-
-int xnarch_calibrate_sched(void)
-{
-       nktimerlat = xnarch_calibrate_timer();
-       if (nktimerlat == 0)
-               return -ENODEV;
-
-       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
-
-       return 0;
-}
-
 static inline int xnarch_init(void)
 {
        int ret;
@@ -62,9 +42,11 @@ static inline int xnarch_init(void)
 
        xnarch_init_timeconv(RTHAL_CLOCK_FREQ);
 
-       ret = xnarch_calibrate_sched();
-       if (ret)
-               return ret;
+       nktimerlat = rthal_timer_calibrate();
+       if (nktimerlat == 0)
+               return -ENODEV;
+
+       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
 
        xnarch_escalation_virq = ipipe_alloc_virq();
        if (xnarch_escalation_virq == 0)
diff --git a/include/asm-powerpc/bits/init.h b/include/asm-powerpc/bits/init.h
index cd4f720..7bf602b 100644
--- a/include/asm-powerpc/bits/init.h
+++ b/include/asm-powerpc/bits/init.h
@@ -35,28 +35,6 @@ int xnarch_escalation_virq;
 
 void xnpod_schedule_handler(void);
 
-unsigned long xnarch_calibrate_timer(void)
-{
-       /*
-        * Compute the time needed to program the decrementer in
-        * aperiodic mode. The return value is expressed in timebase
-        * ticks.
-        */
-       return xnarch_ns_to_tsc(rthal_timer_calibrate())? : 1;
-}
-
-int xnarch_calibrate_sched(void)
-{
-       nktimerlat = xnarch_calibrate_timer();
-
-       if (nktimerlat == 0)
-               return -ENODEV;
-
-       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
-
-       return 0;
-}
-
 static inline int xnarch_init(void)
 {
        int ret;
@@ -67,9 +45,11 @@ static inline int xnarch_init(void)
 
        xnarch_init_timeconv(RTHAL_CLOCK_FREQ);
 
-       ret = xnarch_calibrate_sched();
-       if (ret)
-               return ret;
+       nktimerlat = rthal_timer_calibrate();
+       if (nktimerlat == 0)
+               return -ENODEV;
+
+       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
 
        xnarch_escalation_virq = ipipe_alloc_virq();
        if (xnarch_escalation_virq == 0)
diff --git a/include/asm-sh/bits/init.h b/include/asm-sh/bits/init.h
index 8ee408a..c8d3db4 100644
--- a/include/asm-sh/bits/init.h
+++ b/include/asm-sh/bits/init.h
@@ -32,26 +32,6 @@ int xnarch_escalation_virq;
 
 void xnpod_schedule_handler(void);
 
-unsigned long xnarch_calibrate_timer(void)
-{
-       /*
-        * Compute the time needed to program the dedicated hrtimer.
-        * The return value is expressed in hrclock counter unit.
-        */
-       return xnarch_ns_to_tsc(rthal_timer_calibrate());
-}
-
-int xnarch_calibrate_sched(void)
-{
-       nktimerlat = xnarch_calibrate_timer();
-       if (nktimerlat == 0)
-               return -ENODEV;
-
-       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
-
-       return 0;
-}
-
 static inline int xnarch_init(void)
 {
        int ret;
@@ -62,9 +42,11 @@ static inline int xnarch_init(void)
 
        xnarch_init_timeconv(RTHAL_CLOCK_FREQ);
 
-       ret = xnarch_calibrate_sched();
-       if (ret)
-               return ret;
+       nktimerlat = rthal_timer_calibrate();
+       if (nktimerlat == 0)
+               return -ENODEV;
+
+       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
 
        xnarch_escalation_virq = ipipe_alloc_virq();
        if (xnarch_escalation_virq == 0)
diff --git a/include/asm-x86/bits/init_32.h b/include/asm-x86/bits/init_32.h
index 5895a11..c010b6f 100644
--- a/include/asm-x86/bits/init_32.h
+++ b/include/asm-x86/bits/init_32.h
@@ -33,30 +33,6 @@ int xnarch_escalation_virq;
 
 void xnpod_schedule_handler(void);
 
-static inline unsigned long xnarch_calibrate_timer(void)
-{
-       /*
-        * Compute the time needed to program the PIT. The return
-        * value is expressed in CPU ticks. Depending on whether
-        * CONFIG_X86_LOCAL_APIC is enabled or not in the kernel
-        * configuration, the calibrated value will either refer to
-        * the local APIC or 8254 timer latency value.
-        */
-       return xnarch_ns_to_tsc(rthal_timer_calibrate())? : 1;
-}
-
-int xnarch_calibrate_sched(void)
-{
-       nktimerlat = xnarch_calibrate_timer();
-
-       if (nktimerlat == 0)
-               return -ENODEV;
-
-       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
-
-       return 0;
-}
-
 static inline int xnarch_init(void)
 {
        int ret;
@@ -67,9 +43,11 @@ static inline int xnarch_init(void)
 
        xnarch_init_timeconv(RTHAL_CLOCK_FREQ);
 
-       ret = xnarch_calibrate_sched();
-       if (ret)
-               return ret;
+       nktimerlat = rthal_timer_calibrate();
+       if (nktimerlat == 0)
+               return -ENODEV;
+
+       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
 
        xnarch_escalation_virq = ipipe_alloc_virq();
        if (xnarch_escalation_virq == 0)
diff --git a/include/asm-x86/bits/init_64.h b/include/asm-x86/bits/init_64.h
index ee9741e..a744ffb 100644
--- a/include/asm-x86/bits/init_64.h
+++ b/include/asm-x86/bits/init_64.h
@@ -33,29 +33,6 @@ int xnarch_escalation_virq;
 
 void xnpod_schedule_handler(void);
 
-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;
-}
-
-int xnarch_calibrate_sched(void)
-{
-       nktimerlat = xnarch_calibrate_timer();
-
-       if (nktimerlat == 0)
-               return -ENODEV;
-
-       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
-
-       return 0;
-}
-
 static inline int xnarch_init(void)
 {
        int ret;
@@ -66,9 +43,11 @@ static inline int xnarch_init(void)
 
        xnarch_init_timeconv(RTHAL_CLOCK_FREQ);
 
-       ret = xnarch_calibrate_sched();
-       if (ret)
-               return ret;
+       nktimerlat = rthal_timer_calibrate();
+       if (nktimerlat == 0)
+               return -ENODEV;
+
+       nklatency = xnarch_ns_to_tsc(xnarch_get_sched_latency()) + nktimerlat;
 
        xnarch_escalation_virq = ipipe_alloc_virq();
        if (xnarch_escalation_virq == 0)
diff --git a/kernel/cobalt/arch/blackfin/hal.c 
b/kernel/cobalt/arch/blackfin/hal.c
index 691d063..8291778 100644
--- a/kernel/cobalt/arch/blackfin/hal.c
+++ b/kernel/cobalt/arch/blackfin/hal.c
@@ -197,7 +197,7 @@ EXPORT_SYMBOL_GPL(rthal_timer_notify_switch);
 
 unsigned long rthal_timer_calibrate(void)
 {
-       return (1000000000 / RTHAL_CLOCK_FREQ) * 100;   /* 100 clock cycles -- 
FIXME */
+       return 20;      /* 20 clock cycles */
 }
 
 int rthal_arch_init(void)
diff --git a/kernel/cobalt/arch/nios2/hal.c b/kernel/cobalt/arch/nios2/hal.c
index 81ddbc6..d520a8e 100644
--- a/kernel/cobalt/arch/nios2/hal.c
+++ b/kernel/cobalt/arch/nios2/hal.c
@@ -64,9 +64,8 @@ void rthal_timer_release(int cpu)
 
 unsigned long rthal_timer_calibrate(void)
 {
-       unsigned long flags, freq;
+       unsigned long flags;
        u64 t, v;
-       u32 d;
        int n;
 
        flags = hard_local_irq_save();
@@ -75,15 +74,12 @@ unsigned long rthal_timer_calibrate(void)
 
        barrier();
 
-       for (n = 1; n < 100; n++)
+       for (n = 1; n <= 100; n++)
                ipipe_read_tsc(v);
 
        hard_local_irq_restore(flags);
 
-       d = (u32)(v - t);
-       freq = rthal_get_clockfreq();
-
-       return ((1000000000 / freq) * (d / n));
+       return rthal_ulldiv(v - t, n, NULL);
 }
 
 int rthal_arch_init(void)
diff --git a/kernel/cobalt/arch/powerpc/hal.c b/kernel/cobalt/arch/powerpc/hal.c
index dff37eb..a659e00 100644
--- a/kernel/cobalt/arch/powerpc/hal.c
+++ b/kernel/cobalt/arch/powerpc/hal.c
@@ -240,7 +240,7 @@ EXPORT_SYMBOL_GPL(rthal_timer_notify_switch);
 
 unsigned long rthal_timer_calibrate(void)
 {
-       return 1000000000 / RTHAL_CLOCK_FREQ;
+       return 5;       /* 5 clock cycles. */
 }
 
 int rthal_arch_init(void)
diff --git a/kernel/cobalt/arch/sh/hal.c b/kernel/cobalt/arch/sh/hal.c
index a842edc..9f2e498 100644
--- a/kernel/cobalt/arch/sh/hal.c
+++ b/kernel/cobalt/arch/sh/hal.c
@@ -102,9 +102,8 @@ EXPORT_SYMBOL_GPL(rthal_timer_notify_switch);
 
 unsigned long rthal_timer_calibrate(void)
 {
-       unsigned long flags, freq;
+       unsigned long flags;
        u64 t, v;
-       u32 d;
        int n;
 
        flags = hard_local_irq_save();
@@ -113,15 +112,12 @@ unsigned long rthal_timer_calibrate(void)
 
        barrier();
 
-       for (n = 1; n < 100; n++)
+       for (n = 1; n <= 100; n++)
                ipipe_read_tsc(v);
 
        hard_local_irq_restore(flags);
 
-       d = (u32)(v - t);
-       freq = rthal_get_clockfreq();
-
-       return ((1000000000 / freq) * (d / n));
+       return rthal_ulldiv(v - t, n, NULL);
 }
 
 int rthal_arch_init(void)
diff --git a/kernel/cobalt/arch/x86/hal_32.c b/kernel/cobalt/arch/x86/hal_32.c
index 4521c0e..0182c90 100644
--- a/kernel/cobalt/arch/x86/hal_32.c
+++ b/kernel/cobalt/arch/x86/hal_32.c
@@ -76,7 +76,7 @@ unsigned long rthal_timer_calibrate(void)
         */
        ipipe_trace_max_reset();
 
-       return rthal_imuldiv(dt, 20, RTHAL_CLOCK_FREQ);
+       return rthal_ulldiv(dt, 20, NULL);
 }
 
 #else /* !CONFIG_X86_LOCAL_APIC */
@@ -123,7 +123,7 @@ unsigned long rthal_timer_calibrate(void)
         */
        ipipe_trace_max_reset();
 
-       return rthal_imuldiv(dt, 20, RTHAL_CLOCK_FREQ);
+       return rthal_ulldiv(dt, 20, NULL);
 }
 
 static void rthal_timer_set_oneshot(void)
diff --git a/kernel/cobalt/arch/x86/hal_64.c b/kernel/cobalt/arch/x86/hal_64.c
index 1e9bc3b..805aff9 100644
--- a/kernel/cobalt/arch/x86/hal_64.c
+++ b/kernel/cobalt/arch/x86/hal_64.c
@@ -65,7 +65,7 @@ unsigned long rthal_timer_calibrate(void)
         */
        ipipe_trace_max_reset();
 
-       return rthal_imuldiv(dt, 20, RTHAL_CLOCK_FREQ);
+       return rthal_ulldiv(dt, 20, NULL);
 }
 
 int rthal_arch_init(void)


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

Reply via email to