2006-01-19 09:42:42 +08:00
|
|
|
/*
|
2007-10-16 16:27:00 +08:00
|
|
|
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-17 06:20:36 +08:00
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "linux/interrupt.h"
|
2007-10-16 16:27:00 +08:00
|
|
|
#include "linux/jiffies.h"
|
|
|
|
#include "linux/threads.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "asm/irq.h"
|
|
|
|
#include "asm/param.h"
|
|
|
|
#include "kern_util.h"
|
|
|
|
#include "os.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scheduler clock - returns current time in nanosec units.
|
|
|
|
*/
|
|
|
|
unsigned long long sched_clock(void)
|
|
|
|
{
|
|
|
|
return (unsigned long long)jiffies_64 * (1000000000 / HZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_UML_REAL_TIME_CLOCK
|
2007-05-07 05:51:51 +08:00
|
|
|
static unsigned long long prev_nsecs[NR_CPUS];
|
2007-02-10 17:44:12 +08:00
|
|
|
static long long delta[NR_CPUS]; /* Deviation per interval */
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2007-10-16 16:26:58 +08:00
|
|
|
void timer_irq(struct uml_pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long long ticks = 0;
|
|
|
|
#ifdef CONFIG_UML_REAL_TIME_CLOCK
|
2007-02-10 17:44:12 +08:00
|
|
|
int c = cpu();
|
2007-10-16 16:27:00 +08:00
|
|
|
if (prev_nsecs[c]) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* We've had 1 tick */
|
2006-01-19 09:42:42 +08:00
|
|
|
unsigned long long nsecs = os_nsecs();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-10 17:44:12 +08:00
|
|
|
delta[c] += nsecs - prev_nsecs[c];
|
|
|
|
prev_nsecs[c] = nsecs;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Protect against the host clock being set backwards */
|
2007-10-16 16:27:00 +08:00
|
|
|
if (delta[c] < 0)
|
2007-02-10 17:44:12 +08:00
|
|
|
delta[c] = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-10 17:44:12 +08:00
|
|
|
ticks += (delta[c] * HZ) / BILLION;
|
|
|
|
delta[c] -= (ticks * BILLION) / HZ;
|
2006-07-10 19:45:08 +08:00
|
|
|
}
|
2007-02-10 17:44:12 +08:00
|
|
|
else prev_nsecs[c] = os_nsecs();
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
2006-07-10 19:45:08 +08:00
|
|
|
ticks = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2007-10-16 16:27:00 +08:00
|
|
|
while (ticks > 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
do_IRQ(TIMER_IRQ, regs);
|
|
|
|
ticks--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-10 17:44:12 +08:00
|
|
|
/* Protects local_offset */
|
2006-01-19 09:42:42 +08:00
|
|
|
static DEFINE_SPINLOCK(timer_spinlock);
|
|
|
|
static unsigned long long local_offset = 0;
|
|
|
|
|
|
|
|
static inline unsigned long long get_time(void)
|
|
|
|
{
|
|
|
|
unsigned long long nsecs;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&timer_spinlock, flags);
|
|
|
|
nsecs = os_nsecs();
|
|
|
|
nsecs += local_offset;
|
|
|
|
spin_unlock_irqrestore(&timer_spinlock, flags);
|
|
|
|
|
|
|
|
return nsecs;
|
|
|
|
}
|
|
|
|
|
2006-10-09 05:49:34 +08:00
|
|
|
irqreturn_t um_timer(int irq, void *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-19 09:42:42 +08:00
|
|
|
unsigned long long nsecs;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2006-06-30 16:55:56 +08:00
|
|
|
write_seqlock_irqsave(&xtime_lock, flags);
|
|
|
|
|
2006-09-29 17:00:32 +08:00
|
|
|
do_timer(1);
|
2006-01-19 09:42:42 +08:00
|
|
|
|
2007-05-07 05:51:51 +08:00
|
|
|
#ifdef CONFIG_UML_REAL_TIME_CLOCK
|
2006-09-27 16:50:42 +08:00
|
|
|
nsecs = get_time();
|
2007-05-07 05:51:51 +08:00
|
|
|
#else
|
|
|
|
nsecs = (unsigned long long) xtime.tv_sec * BILLION + xtime.tv_nsec +
|
|
|
|
BILLION / HZ;
|
|
|
|
#endif
|
2006-01-19 09:42:42 +08:00
|
|
|
xtime.tv_sec = nsecs / NSEC_PER_SEC;
|
|
|
|
xtime.tv_nsec = nsecs - xtime.tv_sec * NSEC_PER_SEC;
|
2006-06-30 16:55:56 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
write_sequnlock_irqrestore(&xtime_lock, flags);
|
2006-01-19 09:42:42 +08:00
|
|
|
|
2006-06-30 16:55:56 +08:00
|
|
|
return IRQ_HANDLED;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-07-10 19:45:05 +08:00
|
|
|
static void register_timer(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2007-10-16 16:27:23 +08:00
|
|
|
timer_init();
|
|
|
|
|
2006-07-10 19:45:05 +08:00
|
|
|
err = request_irq(TIMER_IRQ, um_timer, IRQF_DISABLED, "timer", NULL);
|
2007-10-16 16:27:00 +08:00
|
|
|
if (err != 0)
|
2006-09-26 14:33:05 +08:00
|
|
|
printk(KERN_ERR "register_timer : request_irq failed - "
|
2006-07-10 19:45:05 +08:00
|
|
|
"errno = %d\n", -err);
|
|
|
|
|
2007-10-16 16:27:22 +08:00
|
|
|
err = set_interval();
|
2007-10-16 16:27:00 +08:00
|
|
|
if (err != 0)
|
2006-09-26 14:33:05 +08:00
|
|
|
printk(KERN_ERR "register_timer : set_interval failed - "
|
|
|
|
"errno = %d\n", -err);
|
2006-07-10 19:45:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern void (*late_time_init)(void);
|
|
|
|
|
|
|
|
void time_init(void)
|
|
|
|
{
|
|
|
|
long long nsecs;
|
|
|
|
|
|
|
|
nsecs = os_nsecs();
|
|
|
|
set_normalized_timespec(&wall_to_monotonic, -nsecs / BILLION,
|
|
|
|
-nsecs % BILLION);
|
2007-05-07 05:51:51 +08:00
|
|
|
set_normalized_timespec(&xtime, nsecs / BILLION, nsecs % BILLION);
|
2006-07-10 19:45:05 +08:00
|
|
|
late_time_init = register_timer;
|
|
|
|
}
|
|
|
|
|
2007-10-16 16:26:58 +08:00
|
|
|
void timer_handler(int sig, struct uml_pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-16 16:27:00 +08:00
|
|
|
if (current_thread->cpu == 0)
|
2007-05-08 15:23:22 +08:00
|
|
|
timer_irq(regs);
|
2005-04-17 06:20:36 +08:00
|
|
|
local_irq_disable();
|
2005-07-29 12:16:09 +08:00
|
|
|
irq_enter();
|
2007-10-16 16:26:58 +08:00
|
|
|
update_process_times(regs->is_user);
|
2005-07-29 12:16:09 +08:00
|
|
|
irq_exit();
|
2005-04-17 06:20:36 +08:00
|
|
|
local_irq_enable();
|
|
|
|
}
|