ia64/xen-unstable

view xen/arch/ia64/linux-xen/time.c @ 9770:ced37bea0647

[IA64] FPH enabling + cleanup

Move contents of switch_to macro from xensystem.h to context_switch function.
Initialize FPU on all processors. FPH is always enabled in Xen.
Speed up context-switch (a little bit!) by not enabling/disabling FPH.
Cleanup (unused function/variablesi/fields, debug printf...)
vmx_ia64_switch_to removed (was unused).

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author awilliam@xenbuild.aw
date Tue Apr 25 22:35:41 2006 -0600 (2006-04-25)
parents 9312a3e8a6f8
children 003157eafd66
line source
1 /*
2 * linux/arch/ia64/kernel/time.c
3 *
4 * Copyright (C) 1998-2003 Hewlett-Packard Co
5 * Stephane Eranian <eranian@hpl.hp.com>
6 * David Mosberger <davidm@hpl.hp.com>
7 * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
8 * Copyright (C) 1999-2000 VA Linux Systems
9 * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com>
10 */
11 #include <linux/config.h>
13 #include <linux/cpu.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/profile.h>
18 #include <linux/sched.h>
19 #include <linux/time.h>
20 #include <linux/interrupt.h>
21 #include <linux/efi.h>
22 #include <linux/profile.h>
23 #include <linux/timex.h>
25 #include <asm/machvec.h>
26 #include <asm/delay.h>
27 #include <asm/hw_irq.h>
28 #include <asm/ptrace.h>
29 #include <asm/sal.h>
30 #include <asm/sections.h>
31 #include <asm/system.h>
32 #ifdef XEN
33 #include <linux/jiffies.h> // not included by xen/sched.h
34 #endif
36 extern unsigned long wall_jiffies;
38 u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES;
40 EXPORT_SYMBOL(jiffies_64);
42 #define TIME_KEEPER_ID 0 /* smp_processor_id() of time-keeper */
44 #ifdef CONFIG_IA64_DEBUG_IRQ
46 unsigned long last_cli_ip;
47 EXPORT_SYMBOL(last_cli_ip);
49 #endif
51 #ifndef XEN
52 static struct time_interpolator itc_interpolator = {
53 .shift = 16,
54 .mask = 0xffffffffffffffffLL,
55 .source = TIME_SOURCE_CPU
56 };
58 static irqreturn_t
59 timer_interrupt (int irq, void *dev_id, struct pt_regs *regs)
60 {
61 unsigned long new_itm;
63 if (unlikely(cpu_is_offline(smp_processor_id()))) {
64 return IRQ_HANDLED;
65 }
67 platform_timer_interrupt(irq, dev_id, regs);
69 new_itm = local_cpu_data->itm_next;
71 if (!time_after(ia64_get_itc(), new_itm))
72 printk(KERN_ERR "Oops: timer tick before it's due (itc=%lx,itm=%lx)\n",
73 ia64_get_itc(), new_itm);
75 profile_tick(CPU_PROFILING, regs);
77 while (1) {
78 update_process_times(user_mode(regs));
80 new_itm += local_cpu_data->itm_delta;
82 if (smp_processor_id() == TIME_KEEPER_ID) {
83 /*
84 * Here we are in the timer irq handler. We have irqs locally
85 * disabled, but we don't know if the timer_bh is running on
86 * another CPU. We need to avoid to SMP race by acquiring the
87 * xtime_lock.
88 */
89 write_seqlock(&xtime_lock);
90 do_timer(regs);
91 local_cpu_data->itm_next = new_itm;
92 write_sequnlock(&xtime_lock);
93 } else
94 local_cpu_data->itm_next = new_itm;
96 if (time_after(new_itm, ia64_get_itc()))
97 break;
98 }
100 do {
101 /*
102 * If we're too close to the next clock tick for
103 * comfort, we increase the safety margin by
104 * intentionally dropping the next tick(s). We do NOT
105 * update itm.next because that would force us to call
106 * do_timer() which in turn would let our clock run
107 * too fast (with the potentially devastating effect
108 * of losing monotony of time).
109 */
110 while (!time_after(new_itm, ia64_get_itc() + local_cpu_data->itm_delta/2))
111 new_itm += local_cpu_data->itm_delta;
112 ia64_set_itm(new_itm);
113 /* double check, in case we got hit by a (slow) PMI: */
114 } while (time_after_eq(ia64_get_itc(), new_itm));
115 return IRQ_HANDLED;
116 }
117 #endif
119 /*
120 * Encapsulate access to the itm structure for SMP.
121 */
122 void
123 ia64_cpu_local_tick (void)
124 {
125 int cpu = smp_processor_id();
126 unsigned long shift = 0, delta;
128 /* arrange for the cycle counter to generate a timer interrupt: */
129 ia64_set_itv(IA64_TIMER_VECTOR);
131 delta = local_cpu_data->itm_delta;
132 /*
133 * Stagger the timer tick for each CPU so they don't occur all at (almost) the
134 * same time:
135 */
136 if (cpu) {
137 unsigned long hi = 1UL << ia64_fls(cpu);
138 shift = (2*(cpu - hi) + 1) * delta/hi/2;
139 }
140 local_cpu_data->itm_next = ia64_get_itc() + delta + shift;
141 ia64_set_itm(local_cpu_data->itm_next);
142 }
144 static int nojitter;
146 static int __init nojitter_setup(char *str)
147 {
148 nojitter = 1;
149 printk("Jitter checking for ITC timers disabled\n");
150 return 1;
151 }
153 __setup("nojitter", nojitter_setup);
156 void __devinit
157 ia64_init_itm (void)
158 {
159 unsigned long platform_base_freq, itc_freq;
160 struct pal_freq_ratio itc_ratio, proc_ratio;
161 long status, platform_base_drift, itc_drift;
163 /*
164 * According to SAL v2.6, we need to use a SAL call to determine the platform base
165 * frequency and then a PAL call to determine the frequency ratio between the ITC
166 * and the base frequency.
167 */
168 status = ia64_sal_freq_base(SAL_FREQ_BASE_PLATFORM,
169 &platform_base_freq, &platform_base_drift);
170 if (status != 0) {
171 printk(KERN_ERR "SAL_FREQ_BASE_PLATFORM failed: %s\n", ia64_sal_strerror(status));
172 } else {
173 status = ia64_pal_freq_ratios(&proc_ratio, NULL, &itc_ratio);
174 if (status != 0)
175 printk(KERN_ERR "PAL_FREQ_RATIOS failed with status=%ld\n", status);
176 }
177 if (status != 0) {
178 /* invent "random" values */
179 printk(KERN_ERR
180 "SAL/PAL failed to obtain frequency info---inventing reasonable values\n");
181 platform_base_freq = 100000000;
182 platform_base_drift = -1; /* no drift info */
183 itc_ratio.num = 3;
184 itc_ratio.den = 1;
185 }
186 if (platform_base_freq < 40000000) {
187 printk(KERN_ERR "Platform base frequency %lu bogus---resetting to 75MHz!\n",
188 platform_base_freq);
189 platform_base_freq = 75000000;
190 platform_base_drift = -1;
191 }
192 if (!proc_ratio.den)
193 proc_ratio.den = 1; /* avoid division by zero */
194 if (!itc_ratio.den)
195 itc_ratio.den = 1; /* avoid division by zero */
197 itc_freq = (platform_base_freq*itc_ratio.num)/itc_ratio.den;
199 local_cpu_data->itm_delta = (itc_freq + HZ/2) / HZ;
200 printk(KERN_DEBUG "CPU %d: base freq=%lu.%03luMHz, ITC ratio=%lu/%lu, "
201 "ITC freq=%lu.%03luMHz", smp_processor_id(),
202 platform_base_freq / 1000000, (platform_base_freq / 1000) % 1000,
203 itc_ratio.num, itc_ratio.den, itc_freq / 1000000, (itc_freq / 1000) % 1000);
205 if (platform_base_drift != -1) {
206 itc_drift = platform_base_drift*itc_ratio.num/itc_ratio.den;
207 printk("+/-%ldppm\n", itc_drift);
208 } else {
209 itc_drift = -1;
210 printk("\n");
211 }
213 local_cpu_data->proc_freq = (platform_base_freq*proc_ratio.num)/proc_ratio.den;
214 local_cpu_data->itc_freq = itc_freq;
215 local_cpu_data->cyc_per_usec = (itc_freq + USEC_PER_SEC/2) / USEC_PER_SEC;
216 local_cpu_data->nsec_per_cyc = ((NSEC_PER_SEC<<IA64_NSEC_PER_CYC_SHIFT)
217 + itc_freq/2)/itc_freq;
219 if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
220 #ifndef XEN
221 itc_interpolator.frequency = local_cpu_data->itc_freq;
222 itc_interpolator.drift = itc_drift;
223 #ifdef CONFIG_SMP
224 /* On IA64 in an SMP configuration ITCs are never accurately synchronized.
225 * Jitter compensation requires a cmpxchg which may limit
226 * the scalability of the syscalls for retrieving time.
227 * The ITC synchronization is usually successful to within a few
228 * ITC ticks but this is not a sure thing. If you need to improve
229 * timer performance in SMP situations then boot the kernel with the
230 * "nojitter" option. However, doing so may result in time fluctuating (maybe
231 * even going backward) if the ITC offsets between the individual CPUs
232 * are too large.
233 */
234 if (!nojitter) itc_interpolator.jitter = 1;
235 #endif
236 register_time_interpolator(&itc_interpolator);
237 #endif
238 }
240 /* Setup the CPU local timer tick */
241 ia64_cpu_local_tick();
242 }
244 #ifndef XEN
245 static struct irqaction timer_irqaction = {
246 .handler = timer_interrupt,
247 .flags = SA_INTERRUPT,
248 .name = "timer"
249 };
251 void __init
252 time_init (void)
253 {
254 register_percpu_irq(IA64_TIMER_VECTOR, &timer_irqaction);
255 efi_gettimeofday(&xtime);
256 ia64_init_itm();
258 /*
259 * Initialize wall_to_monotonic such that adding it to xtime will yield zero, the
260 * tv_nsec field must be normalized (i.e., 0 <= nsec < NSEC_PER_SEC).
261 */
262 set_normalized_timespec(&wall_to_monotonic, -xtime.tv_sec, -xtime.tv_nsec);
263 }
264 #endif