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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Sep 15 17:43:23 2009 +0200

nucleus: start fixing misnomer between clock vs CPU frequency

For historical reason, we wrongly assumed cpufreq == clockfreq in the
early Xenomai days, albeit the CPU frequency may be very different
from the clock source frequency used when measuring time.

This patch contains a small set of related fixes that should be
followed by per-arch updates.

---

 include/asm-generic/bits/timeconv.h |   10 +++---
 include/asm-generic/hal.h           |   47 ++++++++++++++++++++++++++++++----
 ksrc/arch/generic/hal.c             |   16 +++++++++---
 3 files changed, 58 insertions(+), 15 deletions(-)

diff --git a/include/asm-generic/bits/timeconv.h 
b/include/asm-generic/bits/timeconv.h
index 8162369..4b8ecf1 100644
--- a/include/asm-generic/bits/timeconv.h
+++ b/include/asm-generic/bits/timeconv.h
@@ -21,7 +21,7 @@
 
 #include <asm/xenomai/arith.h>
 
-static unsigned long long cpufreq;
+static unsigned long long clockfreq;
 
 #ifdef XNARCH_HAVE_LLMULSHFT
 static unsigned int tsc_scale, tsc_shift;
@@ -71,15 +71,15 @@ long long xnarch_ns_to_tsc(long long ns)
 #else  /* !XNARCH_HAVE_LLMULSHFT */
 long long xnarch_tsc_to_ns(long long ticks)
 {
-       return xnarch_llimd(ticks, 1000000000, cpufreq);
+       return xnarch_llimd(ticks, 1000000000, clockfreq);
 }
 long long xnarch_tsc_to_ns_rounded(long long ticks)
 {
-       return (xnarch_llimd(ticks, 1000000000, cpufreq/2) + 1) / 2;
+       return (xnarch_llimd(ticks, 1000000000, clockfreq/2) + 1) / 2;
 }
 long long xnarch_ns_to_tsc(long long ns)
 {
-       return xnarch_llimd(ns, cpufreq, 1000000000);
+       return xnarch_llimd(ns, clockfreq, 1000000000);
 }
 #endif /* !XNARCH_HAVE_LLMULSHFT */
 
@@ -94,7 +94,7 @@ unsigned long long xnarch_divrem_billion(unsigned long long 
value,
 
 static inline void xnarch_init_timeconv(unsigned long long freq)
 {
-       cpufreq = freq;
+       clockfreq = freq;
 #ifdef XNARCH_HAVE_LLMULSHFT
        xnarch_init_llmulshft(1000000000, freq, &tsc_scale, &tsc_shift);
 #ifdef XNARCH_HAVE_NODIV_LLIMD
diff --git a/include/asm-generic/hal.h b/include/asm-generic/hal.h
index 244ca02..97c549e 100644
--- a/include/asm-generic/hal.h
+++ b/include/asm-generic/hal.h
@@ -46,6 +46,7 @@
 #define RTHAL_DOMAIN_ID                0x58454e4f
 
 #define RTHAL_TIMER_FREQ       (rthal_tunables.timer_freq)
+#define RTHAL_CLOCK_FREQ       (rthal_tunables.clock_freq)
 #define RTHAL_CPU_FREQ         (rthal_tunables.cpu_freq)
 #define RTHAL_NR_APCS          BITS_PER_LONG
 
@@ -177,11 +178,36 @@ typedef spinlock_t rthal_spinlock_t;
 #define rthal_emergency_console()      
ipipe_set_printk_sync(ipipe_current_domain)
 #define rthal_read_tsc(v)              ipipe_read_tsc(v)
 
+#ifdef __IPIPE_FEATURE_SYSINFO_V2
+       
 static inline unsigned long rthal_get_cpufreq(void)
 {
-    struct ipipe_sysinfo sysinfo;
-    rthal_get_sysinfo(&sysinfo);
-    return (unsigned long)sysinfo.cpufreq;
+       struct ipipe_sysinfo sysinfo;
+       rthal_get_sysinfo(&sysinfo);
+       return (unsigned long)sysinfo.sys_cpu_freq;
+}
+
+static inline unsigned long rthal_get_timerfreq(void)
+{
+       struct ipipe_sysinfo sysinfo;
+       rthal_get_sysinfo(&sysinfo);
+       return (unsigned long)sysinfo.sys_hrtimer_freq;
+}
+
+static inline unsigned long rthal_get_clockfreq(void)
+{
+       struct ipipe_sysinfo sysinfo;
+       rthal_get_sysinfo(&sysinfo);
+       return (unsigned long)sysinfo.sys_hrclock_freq;
+}
+
+#else /* !__IPIPE_FEATURE_SYSINFO_V2 */
+
+static inline unsigned long rthal_get_cpufreq(void)
+{
+       struct ipipe_sysinfo sysinfo;
+       rthal_get_sysinfo(&sysinfo);
+       return (unsigned long)sysinfo.cpufreq;
 }
 
 static inline unsigned long rthal_get_timerfreq(void)
@@ -191,6 +217,13 @@ static inline unsigned long rthal_get_timerfreq(void)
        return (unsigned long)sysinfo.archdep.tmfreq;
 }
 
+static inline unsigned long rthal_get_clockfreq(void)
+{
+       return rthal_get_cpufreq();
+}
+
+#endif /* !__IPIPE_FEATURE_SYSINFO_V2 */
+
 #define RTHAL_DECLARE_EVENT(hdlr)                                     \
 static int hdlr (unsigned event, struct ipipe_domain *ipd, void *data) \
 {                                                                     \
@@ -345,9 +378,9 @@ typedef ipipe_irq_handler_t rthal_irq_handler_t;
 typedef ipipe_irq_ackfn_t   rthal_irq_ackfn_t;
 
 struct rthal_calibration_data {
-
-    unsigned long cpu_freq;
-    unsigned long timer_freq;
+       unsigned long cpu_freq;
+       unsigned long timer_freq;
+       unsigned long clock_freq;
 };
 
 typedef int (*rthal_trap_handler_t)(unsigned trapno,
@@ -358,6 +391,8 @@ extern unsigned long rthal_cpufreq_arg;
 
 extern unsigned long rthal_timerfreq_arg;
 
+extern unsigned long rthal_clockfreq_arg;
+
 extern rthal_pipeline_stage_t rthal_domain;
 
 extern struct rthal_calibration_data rthal_tunables;
diff --git a/ksrc/arch/generic/hal.c b/ksrc/arch/generic/hal.c
index 762e544..9bb0020 100644
--- a/ksrc/arch/generic/hal.c
+++ b/ksrc/arch/generic/hal.c
@@ -58,6 +58,9 @@ module_param_named(cpufreq, rthal_cpufreq_arg, ulong, 0444);
 unsigned long rthal_timerfreq_arg;
 module_param_named(timerfreq, rthal_timerfreq_arg, ulong, 0444);
 
+unsigned long rthal_clockfreq_arg;
+module_param_named(clockfreq, rthal_clockfreq_arg, ulong, 0444);
+
 #ifdef CONFIG_SMP
 static unsigned long supported_cpus_arg = -1;
 module_param_named(supported_cpus, supported_cpus_arg, ulong, 0444);
@@ -815,13 +818,18 @@ int rthal_init(void)
     }
 #endif /* CONFIG_SMP */
 
-    /* The arch-dependent support must have updated the frequency args
-       as required. */
+    /*
+     * The arch-dependent support must have updated the various
+     * frequency args as required.
+     */
     rthal_tunables.cpu_freq = rthal_cpufreq_arg;
     rthal_tunables.timer_freq = rthal_timerfreq_arg;
+    rthal_tunables.clock_freq = rthal_clockfreq_arg;
 
-    /* Allocate a virtual interrupt to handle apcs within the Linux
-       domain. */
+    /*
+     * Allocate a virtual interrupt to handle apcs within the Linux
+     * domain.
+     */
     rthal_apc_virq = rthal_alloc_virq();
 
     if (!rthal_apc_virq) {


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

Reply via email to