debuggers.hg

view xen/arch/ia64/patch/linux-2.6.11/time.c @ 4615:58efb3448933

bitkeeper revision 1.1327.1.1 (426536d2PUqtjTi2v06bzD10RFwarg)

Merge bk://xen.bkbits.net/xeno-unstable.bk
into bkbits.net:/repos/x/xen-ia64/xeno-unstable-ia64.bk
author xen-ia64.adm@bkbits.net
date Tue Apr 19 16:50:26 2005 +0000 (2005-04-19)
parents f1c946e1226a
children 5b9e241131fb 34c2b5c0ac81
line source
1 time.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 1 files changed, 158 insertions(+)
4 Index: linux-2.6.11-xendiffs/arch/ia64/kernel/time.c
5 ===================================================================
6 --- linux-2.6.11-xendiffs.orig/arch/ia64/kernel/time.c 2005-04-07 17:02:39.634985144 -0500
7 +++ linux-2.6.11-xendiffs/arch/ia64/kernel/time.c 2005-04-07 17:23:52.777723222 -0500
8 @@ -10,16 +10,22 @@
9 */
10 #include <linux/config.h>
12 +#ifndef XEN
13 #include <linux/cpu.h>
14 +#endif
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 +#ifndef XEN
19 #include <linux/profile.h>
20 +#endif
21 #include <linux/sched.h>
22 #include <linux/time.h>
23 #include <linux/interrupt.h>
24 #include <linux/efi.h>
25 +#ifndef XEN
26 #include <linux/profile.h>
27 +#endif
28 #include <linux/timex.h>
30 #include <asm/machvec.h>
31 @@ -29,10 +35,19 @@
32 #include <asm/sal.h>
33 #include <asm/sections.h>
34 #include <asm/system.h>
35 +#ifdef XEN
36 +#include <asm/ia64_int.h>
37 +#endif
39 extern unsigned long wall_jiffies;
41 +#ifndef XEN
42 u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES;
43 +#else
44 +#define INITIAL_JIFFIES 0
45 +u64 jiffies_64 = INITIAL_JIFFIES;
46 +#define CPU_PROFILING 0
47 +#endif
49 EXPORT_SYMBOL(jiffies_64);
51 @@ -45,33 +60,154 @@ EXPORT_SYMBOL(last_cli_ip);
53 #endif
55 +#ifdef XEN
56 +volatile unsigned long last_nsec_offset;
57 +extern rwlock_t xtime_lock;
58 +unsigned long cpu_khz; /* Detected as we calibrate the TSC */
59 +static s_time_t stime_irq; /* System time at last 'time update' */
60 +
61 +static inline u64 get_time_delta(void)
62 +{
63 + return ia64_get_itc();
64 +}
65 +
66 +s_time_t get_s_time(void)
67 +{
68 + s_time_t now;
69 + unsigned long flags;
70 +
71 + read_lock_irqsave(&xtime_lock, flags);
72 +
73 + now = stime_irq + get_time_delta();
74 +
75 + /* Ensure that the returned system time is monotonically increasing. */
76 + {
77 + static s_time_t prev_now = 0;
78 + if ( unlikely(now < prev_now) )
79 + now = prev_now;
80 + prev_now = now;
81 + }
82 +
83 + read_unlock_irqrestore(&xtime_lock, flags);
84 +
85 + return now;
86 +}
87 +
88 +void update_dom_time(struct exec_domain *ed)
89 +{
90 +// FIXME: implement this?
91 +// printf("update_dom_time: called, not implemented, skipping\n");
92 + return;
93 +}
94 +
95 +/* Set clock to <secs,usecs> after 00:00:00 UTC, 1 January, 1970. */
96 +void do_settime(unsigned long secs, unsigned long usecs, u64 system_time_base)
97 +{
98 +// FIXME: Should this be do_settimeofday (from linux)???
99 + printf("do_settime: called, not implemented, stopping\n");
100 + dummy();
101 +}
102 +#endif
103 +
104 +#if 0 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
105 +#endif /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
106 +
107 +#ifndef XEN
108 static struct time_interpolator itc_interpolator = {
109 .shift = 16,
110 .mask = 0xffffffffffffffffLL,
111 .source = TIME_SOURCE_CPU
112 };
113 +#endif
114 +
115 +#ifdef XEN
116 +unsigned long domain0_ready = 0; // FIXME (see below)
117 +#define typecheck(a,b) 1
118 +/* FROM linux/include/linux/jiffies.h */
119 +/*
120 + * These inlines deal with timer wrapping correctly. You are
121 + * strongly encouraged to use them
122 + * 1. Because people otherwise forget
123 + * 2. Because if the timer wrap changes in future you won't have to
124 + * alter your driver code.
125 + *
126 + * time_after(a,b) returns true if the time a is after time b.
127 + *
128 + * Do this with "<0" and ">=0" to only test the sign of the result. A
129 + * good compiler would generate better code (and a really good compiler
130 + * wouldn't care). Gcc is currently neither.
131 + */
132 +#define time_after(a,b) \
133 + (typecheck(unsigned long, a) && \
134 + typecheck(unsigned long, b) && \
135 + ((long)(b) - (long)(a) < 0))
136 +#define time_before(a,b) time_after(b,a)
137 +
138 +#define time_after_eq(a,b) \
139 + (typecheck(unsigned long, a) && \
140 + typecheck(unsigned long, b) && \
141 + ((long)(a) - (long)(b) >= 0))
142 +#define time_before_eq(a,b) time_after_eq(b,a)
143 +#endif
145 static irqreturn_t
146 timer_interrupt (int irq, void *dev_id, struct pt_regs *regs)
147 {
148 unsigned long new_itm;
150 +#ifndef XEN
151 if (unlikely(cpu_is_offline(smp_processor_id()))) {
152 return IRQ_HANDLED;
153 }
154 +#endif
155 +#ifdef XEN
156 + if (current->domain == dom0) {
157 + // FIXME: there's gotta be a better way of doing this...
158 + // We have to ensure that domain0 is launched before we
159 + // call vcpu_timer_expired on it
160 + //domain0_ready = 1; // moved to xensetup.c
161 + }
162 + if (domain0_ready && vcpu_timer_expired(dom0->exec_domain[0])) {
163 + vcpu_pend_timer(dom0->exec_domain[0]);
164 + //vcpu_set_next_timer(dom0->exec_domain[0]);
165 + domain_wake(dom0->exec_domain[0]);
166 + }
167 + if (!is_idle_task(current->domain) && current->domain != dom0) {
168 + if (vcpu_timer_expired(current)) {
169 + vcpu_pend_timer(current);
170 + // ensure another timer interrupt happens even if domain doesn't
171 + vcpu_set_next_timer(current);
172 + domain_wake(current);
173 + }
174 + }
175 + raise_actimer_softirq();
176 +#endif
178 +#ifndef XEN
179 platform_timer_interrupt(irq, dev_id, regs);
180 +#endif
182 new_itm = local_cpu_data->itm_next;
184 if (!time_after(ia64_get_itc(), new_itm))
185 +#ifdef XEN
186 + return;
187 +#else
188 printk(KERN_ERR "Oops: timer tick before it's due (itc=%lx,itm=%lx)\n",
189 ia64_get_itc(), new_itm);
190 +#endif
192 +#ifdef XEN
193 +// printf("GOT TO HERE!!!!!!!!!!!\n");
194 + //while(1);
195 +#else
196 profile_tick(CPU_PROFILING, regs);
197 +#endif
199 while (1) {
200 +#ifndef XEN
201 update_process_times(user_mode(regs));
202 +#endif
204 new_itm += local_cpu_data->itm_delta;
206 @@ -82,10 +218,16 @@ timer_interrupt (int irq, void *dev_id,
207 * another CPU. We need to avoid to SMP race by acquiring the
208 * xtime_lock.
209 */
210 +#ifdef TURN_ME_OFF_FOR_NOW_IA64_XEN
211 write_seqlock(&xtime_lock);
212 +#endif
213 +#ifdef TURN_ME_OFF_FOR_NOW_IA64_XEN
214 do_timer(regs);
215 +#endif
216 local_cpu_data->itm_next = new_itm;
217 +#ifdef TURN_ME_OFF_FOR_NOW_IA64_XEN
218 write_sequnlock(&xtime_lock);
219 +#endif
220 } else
221 local_cpu_data->itm_next = new_itm;
223 @@ -105,7 +247,12 @@ timer_interrupt (int irq, void *dev_id,
224 */
225 while (!time_after(new_itm, ia64_get_itc() + local_cpu_data->itm_delta/2))
226 new_itm += local_cpu_data->itm_delta;
227 +//#ifdef XEN
228 +// vcpu_set_next_timer(current);
229 +//#else
230 +//printf("***** timer_interrupt: Setting itm to %lx\n",new_itm);
231 ia64_set_itm(new_itm);
232 +//#endif
233 /* double check, in case we got hit by a (slow) PMI: */
234 } while (time_after_eq(ia64_get_itc(), new_itm));
235 return IRQ_HANDLED;
236 @@ -120,6 +267,7 @@ ia64_cpu_local_tick (void)
237 int cpu = smp_processor_id();
238 unsigned long shift = 0, delta;
240 +printf("ia64_cpu_local_tick: about to call ia64_set_itv\n");
241 /* arrange for the cycle counter to generate a timer interrupt: */
242 ia64_set_itv(IA64_TIMER_VECTOR);
244 @@ -133,6 +281,7 @@ ia64_cpu_local_tick (void)
245 shift = (2*(cpu - hi) + 1) * delta/hi/2;
246 }
247 local_cpu_data->itm_next = ia64_get_itc() + delta + shift;
248 +printf("***** ia64_cpu_local_tick: Setting itm to %lx\n",local_cpu_data->itm_next);
249 ia64_set_itm(local_cpu_data->itm_next);
250 }
252 @@ -160,6 +309,7 @@ ia64_init_itm (void)
253 * frequency and then a PAL call to determine the frequency ratio between the ITC
254 * and the base frequency.
255 */
256 +
257 status = ia64_sal_freq_base(SAL_FREQ_BASE_PLATFORM,
258 &platform_base_freq, &platform_base_drift);
259 if (status != 0) {
260 @@ -212,6 +362,7 @@ ia64_init_itm (void)
261 + itc_freq/2)/itc_freq;
263 if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
264 +#ifndef XEN
265 itc_interpolator.frequency = local_cpu_data->itc_freq;
266 itc_interpolator.drift = itc_drift;
267 #ifdef CONFIG_SMP
268 @@ -228,6 +379,7 @@ ia64_init_itm (void)
269 if (!nojitter) itc_interpolator.jitter = 1;
270 #endif
271 register_time_interpolator(&itc_interpolator);
272 +#endif
273 }
275 /* Setup the CPU local timer tick */
276 @@ -236,7 +388,9 @@ ia64_init_itm (void)
278 static struct irqaction timer_irqaction = {
279 .handler = timer_interrupt,
280 +#ifndef XEN
281 .flags = SA_INTERRUPT,
282 +#endif
283 .name = "timer"
284 };
286 @@ -244,12 +398,16 @@ void __init
287 time_init (void)
288 {
289 register_percpu_irq(IA64_TIMER_VECTOR, &timer_irqaction);
290 +#ifndef XEN
291 efi_gettimeofday(&xtime);
292 +#endif
293 ia64_init_itm();
295 +#ifndef XEN
296 /*
297 * Initialize wall_to_monotonic such that adding it to xtime will yield zero, the
298 * tv_nsec field must be normalized (i.e., 0 <= nsec < NSEC_PER_SEC).
299 */
300 set_normalized_timespec(&wall_to_monotonic, -xtime.tv_sec, -xtime.tv_nsec);
301 +#endif
302 }