2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
6 #include "linux/kernel.h"
7 #include "linux/module.h"
8 #include "linux/unistd.h"
9 #include "linux/stddef.h"
10 #include "linux/spinlock.h"
11 #include "linux/time.h"
12 #include "linux/sched.h"
13 #include "linux/interrupt.h"
14 #include "linux/init.h"
15 #include "linux/delay.h"
17 #include "asm/param.h"
18 #include "asm/current.h"
19 #include "kern_util.h"
20 #include "user_util.h"
21 #include "time_user.h"
27 EXPORT_SYMBOL(jiffies_64
);
35 * Scheduler clock - returns current time in nanosec units.
37 unsigned long long sched_clock(void)
39 return (unsigned long long)jiffies_64
* (1000000000 / HZ
);
42 /* Changed at early boot */
43 int timer_irq_inited
= 0;
45 static int first_tick
;
46 static unsigned long long prev_usecs
;
47 #ifdef CONFIG_UML_REAL_TIME_CLOCK
48 static long long delta
; /* Deviation per interval */
51 #define MILLION 1000000
53 void timer_irq(union uml_pt_regs
*regs
)
55 unsigned long long ticks
= 0;
57 if(!timer_irq_inited
){
58 /* This is to ensure that ticks don't pile up when
59 * the timer handler is suspended */
65 #ifdef CONFIG_UML_REAL_TIME_CLOCK
66 /* We've had 1 tick */
67 unsigned long long usecs
= os_usecs();
69 delta
+= usecs
- prev_usecs
;
72 /* Protect against the host clock being set backwards */
76 ticks
+= (delta
* HZ
) / MILLION
;
77 delta
-= (ticks
* MILLION
) / HZ
;
83 prev_usecs
= os_usecs();
88 do_IRQ(TIMER_IRQ
, regs
);
93 void boot_timer_handler(int sig
)
98 (UPT_SC(®s
.regs
) = (struct sigcontext
*) (&sig
+ 1)),
99 (void) (regs
.regs
.skas
.is_user
= 0));
103 irqreturn_t
um_timer(int irq
, void *dev
, struct pt_regs
*regs
)
108 write_seqlock_irqsave(&xtime_lock
, flags
);
110 write_sequnlock_irqrestore(&xtime_lock
, flags
);
114 long um_time(int * tloc
)
118 do_gettimeofday(&now
);
120 if (put_user(now
.tv_sec
,tloc
))
121 now
.tv_sec
= -EFAULT
;
126 long um_stime(int * tptr
)
131 if (get_user(value
, tptr
))
135 do_settimeofday(&new);
139 /* XXX Needs to be moved under sys-i386 */
140 void __delay(um_udelay_t time
)
142 /* Stolen from the i386 __loop_delay */
144 __asm__
__volatile__(
149 "2:\tdecl %0\n\tjns 2b"
154 void __udelay(um_udelay_t usecs
)
158 n
= (loops_per_jiffy
* HZ
* usecs
) / MILLION
;
162 void __const_udelay(um_udelay_t usecs
)
166 n
= (loops_per_jiffy
* HZ
* usecs
) / MILLION
;
170 void timer_handler(int sig
, union uml_pt_regs
*regs
)
174 update_process_times(user_context(UPT_SP(regs
)));
177 if(current_thread
->cpu
== 0)
181 static spinlock_t timer_spinlock
= SPIN_LOCK_UNLOCKED
;
183 unsigned long time_lock(void)
187 spin_lock_irqsave(&timer_spinlock
, flags
);
191 void time_unlock(unsigned long flags
)
193 spin_unlock_irqrestore(&timer_spinlock
, flags
);
196 int __init
timer_init(void)
200 CHOOSE_MODE(user_time_init_tt(), user_time_init_skas());
201 err
= request_irq(TIMER_IRQ
, um_timer
, SA_INTERRUPT
, "timer", NULL
);
203 printk(KERN_ERR
"timer_init : request_irq failed - "
204 "errno = %d\n", -err
);
205 timer_irq_inited
= 1;
209 __initcall(timer_init
);
212 * Overrides for Emacs so that we follow Linus's tabbing style.
213 * Emacs will notice this stuff at the end of the file and automatically
214 * adjust the settings for this buffer only. This must remain at the end
216 * ---------------------------------------------------------------------------
218 * c-file-style: "linux"