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"
31 * Scheduler clock - returns current time in nanosec units.
33 unsigned long long sched_clock(void)
35 return (unsigned long long)jiffies_64 * (1000000000 / HZ);
38 /* Changed at early boot */
39 int timer_irq_inited = 0;
41 static int first_tick;
42 static unsigned long long prev_usecs;
43 #ifdef CONFIG_UML_REAL_TIME_CLOCK
44 static long long delta; /* Deviation per interval */
47 void timer_irq(union uml_pt_regs *regs)
49 unsigned long long ticks = 0;
51 if(!timer_irq_inited){
52 /* This is to ensure that ticks don't pile up when
53 * the timer handler is suspended */
59 #ifdef CONFIG_UML_REAL_TIME_CLOCK
60 /* We've had 1 tick */
61 unsigned long long usecs = os_usecs();
63 delta += usecs - prev_usecs;
66 /* Protect against the host clock being set backwards */
70 ticks += (delta * HZ) / MILLION;
71 delta -= (ticks * MILLION) / HZ;
77 prev_usecs = os_usecs();
82 do_IRQ(TIMER_IRQ, regs);
87 void boot_timer_handler(int sig)
92 (UPT_SC(®s.regs) = (struct sigcontext *) (&sig + 1)),
93 (void) (regs.regs.skas.is_user = 0));
97 irqreturn_t um_timer(int irq, void *dev, struct pt_regs *regs)
102 write_seqlock_irqsave(&xtime_lock, flags);
104 write_sequnlock_irqrestore(&xtime_lock, flags);
108 long um_time(int __user *tloc)
112 do_gettimeofday(&now);
114 if (put_user(now.tv_sec, tloc))
115 now.tv_sec = -EFAULT;
120 long um_stime(int __user *tptr)
125 if (get_user(value, tptr))
129 do_settimeofday(&new);
133 void timer_handler(int sig, union uml_pt_regs *regs)
137 update_process_times(CHOOSE_MODE(user_context(UPT_SP(regs)),
138 (regs)->skas.is_user));
141 if(current_thread->cpu == 0)
145 static DEFINE_SPINLOCK(timer_spinlock);
147 unsigned long time_lock(void)
151 spin_lock_irqsave(&timer_spinlock, flags);
155 void time_unlock(unsigned long flags)
157 spin_unlock_irqrestore(&timer_spinlock, flags);
160 int __init timer_init(void)
165 err = request_irq(TIMER_IRQ, um_timer, SA_INTERRUPT, "timer", NULL);
167 printk(KERN_ERR "timer_init : request_irq failed - "
168 "errno = %d\n", -err);
169 timer_irq_inited = 1;
173 __initcall(timer_init);
176 * Overrides for Emacs so that we follow Linus's tabbing style.
177 * Emacs will notice this stuff at the end of the file and automatically
178 * adjust the settings for this buffer only. This must remain at the end
180 * ---------------------------------------------------------------------------
182 * c-file-style: "linux"