time.c (77bf4400319db9d2a8af6b00c2be6faa0f3d07cb) | time.c (ba180fd437156f7fd8cfb2fdd021d949eeef08d6) |
---|---|
1/* | 1/* |
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) | 2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
3 * Licensed under the GPL 4 */ 5 | 3 * Licensed under the GPL 4 */ 5 |
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" | 6#include "linux/interrupt.h" |
14#include "linux/init.h" 15#include "linux/delay.h" 16#include "linux/hrtimer.h" | 7#include "linux/jiffies.h" 8#include "linux/threads.h" |
17#include "asm/irq.h" 18#include "asm/param.h" | 9#include "asm/irq.h" 10#include "asm/param.h" |
19#include "asm/current.h" | |
20#include "kern_util.h" 21#include "os.h" 22 23int hz(void) 24{ | 11#include "kern_util.h" 12#include "os.h" 13 14int hz(void) 15{ |
25 return(HZ); | 16 return HZ; |
26} 27 28/* 29 * Scheduler clock - returns current time in nanosec units. 30 */ 31unsigned long long sched_clock(void) 32{ 33 return (unsigned long long)jiffies_64 * (1000000000 / HZ); --- 4 unchanged lines hidden (view full) --- 38static long long delta[NR_CPUS]; /* Deviation per interval */ 39#endif 40 41void timer_irq(struct uml_pt_regs *regs) 42{ 43 unsigned long long ticks = 0; 44#ifdef CONFIG_UML_REAL_TIME_CLOCK 45 int c = cpu(); | 17} 18 19/* 20 * Scheduler clock - returns current time in nanosec units. 21 */ 22unsigned long long sched_clock(void) 23{ 24 return (unsigned long long)jiffies_64 * (1000000000 / HZ); --- 4 unchanged lines hidden (view full) --- 29static long long delta[NR_CPUS]; /* Deviation per interval */ 30#endif 31 32void timer_irq(struct uml_pt_regs *regs) 33{ 34 unsigned long long ticks = 0; 35#ifdef CONFIG_UML_REAL_TIME_CLOCK 36 int c = cpu(); |
46 if(prev_nsecs[c]){ | 37 if (prev_nsecs[c]) { |
47 /* We've had 1 tick */ 48 unsigned long long nsecs = os_nsecs(); 49 50 delta[c] += nsecs - prev_nsecs[c]; 51 prev_nsecs[c] = nsecs; 52 53 /* Protect against the host clock being set backwards */ | 38 /* We've had 1 tick */ 39 unsigned long long nsecs = os_nsecs(); 40 41 delta[c] += nsecs - prev_nsecs[c]; 42 prev_nsecs[c] = nsecs; 43 44 /* Protect against the host clock being set backwards */ |
54 if(delta[c] < 0) | 45 if (delta[c] < 0) |
55 delta[c] = 0; 56 57 ticks += (delta[c] * HZ) / BILLION; 58 delta[c] -= (ticks * BILLION) / HZ; 59 } 60 else prev_nsecs[c] = os_nsecs(); 61#else 62 ticks = 1; 63#endif | 46 delta[c] = 0; 47 48 ticks += (delta[c] * HZ) / BILLION; 49 delta[c] -= (ticks * BILLION) / HZ; 50 } 51 else prev_nsecs[c] = os_nsecs(); 52#else 53 ticks = 1; 54#endif |
64 while(ticks > 0){ | 55 while (ticks > 0) { |
65 do_IRQ(TIMER_IRQ, regs); 66 ticks--; 67 } 68} 69 70/* Protects local_offset */ 71static DEFINE_SPINLOCK(timer_spinlock); 72static unsigned long long local_offset = 0; --- 34 unchanged lines hidden (view full) --- 107 return IRQ_HANDLED; 108} 109 110static void register_timer(void) 111{ 112 int err; 113 114 err = request_irq(TIMER_IRQ, um_timer, IRQF_DISABLED, "timer", NULL); | 56 do_IRQ(TIMER_IRQ, regs); 57 ticks--; 58 } 59} 60 61/* Protects local_offset */ 62static DEFINE_SPINLOCK(timer_spinlock); 63static unsigned long long local_offset = 0; --- 34 unchanged lines hidden (view full) --- 98 return IRQ_HANDLED; 99} 100 101static void register_timer(void) 102{ 103 int err; 104 105 err = request_irq(TIMER_IRQ, um_timer, IRQF_DISABLED, "timer", NULL); |
115 if(err != 0) | 106 if (err != 0) |
116 printk(KERN_ERR "register_timer : request_irq failed - " 117 "errno = %d\n", -err); 118 119 err = set_interval(1); | 107 printk(KERN_ERR "register_timer : request_irq failed - " 108 "errno = %d\n", -err); 109 110 err = set_interval(1); |
120 if(err != 0) | 111 if (err != 0) |
121 printk(KERN_ERR "register_timer : set_interval failed - " 122 "errno = %d\n", -err); 123} 124 125extern void (*late_time_init)(void); 126 127void time_init(void) 128{ --- 10 unchanged lines hidden (view full) --- 139{ 140#ifdef CONFIG_UML_REAL_TIME_CLOCK 141 unsigned long long nsecs = get_time(); 142#else 143 unsigned long long nsecs = (unsigned long long) xtime.tv_sec * BILLION + 144 xtime.tv_nsec; 145#endif 146 tv->tv_sec = nsecs / NSEC_PER_SEC; | 112 printk(KERN_ERR "register_timer : set_interval failed - " 113 "errno = %d\n", -err); 114} 115 116extern void (*late_time_init)(void); 117 118void time_init(void) 119{ --- 10 unchanged lines hidden (view full) --- 130{ 131#ifdef CONFIG_UML_REAL_TIME_CLOCK 132 unsigned long long nsecs = get_time(); 133#else 134 unsigned long long nsecs = (unsigned long long) xtime.tv_sec * BILLION + 135 xtime.tv_nsec; 136#endif 137 tv->tv_sec = nsecs / NSEC_PER_SEC; |
147 /* Careful about calculations here - this was originally done as | 138 /* 139 * Careful about calculations here - this was originally done as |
148 * (nsecs - tv->tv_sec * NSEC_PER_SEC) / NSEC_PER_USEC 149 * which gave bogus (> 1000000) values. Dunno why, suspect gcc 150 * (4.0.0) miscompiled it, or there's a subtle 64/32-bit conversion 151 * problem that I missed. 152 */ 153 nsecs -= tv->tv_sec * NSEC_PER_SEC; 154 tv->tv_usec = (unsigned long) nsecs / NSEC_PER_USEC; 155} --- 15 unchanged lines hidden (view full) --- 171{ 172 set_time((unsigned long long) tv->tv_sec * NSEC_PER_SEC + tv->tv_nsec); 173 174 return 0; 175} 176 177void timer_handler(int sig, struct uml_pt_regs *regs) 178{ | 140 * (nsecs - tv->tv_sec * NSEC_PER_SEC) / NSEC_PER_USEC 141 * which gave bogus (> 1000000) values. Dunno why, suspect gcc 142 * (4.0.0) miscompiled it, or there's a subtle 64/32-bit conversion 143 * problem that I missed. 144 */ 145 nsecs -= tv->tv_sec * NSEC_PER_SEC; 146 tv->tv_usec = (unsigned long) nsecs / NSEC_PER_USEC; 147} --- 15 unchanged lines hidden (view full) --- 163{ 164 set_time((unsigned long long) tv->tv_sec * NSEC_PER_SEC + tv->tv_nsec); 165 166 return 0; 167} 168 169void timer_handler(int sig, struct uml_pt_regs *regs) 170{ |
179 if(current_thread->cpu == 0) | 171 if (current_thread->cpu == 0) |
180 timer_irq(regs); 181 local_irq_disable(); 182 irq_enter(); 183 update_process_times(regs->is_user); 184 irq_exit(); 185 local_irq_enable(); 186} | 172 timer_irq(regs); 173 local_irq_disable(); 174 irq_enter(); 175 update_process_times(regs->is_user); 176 irq_exit(); 177 local_irq_enable(); 178} |