| 
									
										
										
										
											2006-06-26 00:25:05 -07:00
										 |  |  | /***********************************************************************
 | 
					
						
							|  |  |  | * linux/kernel/time/jiffies.c | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * This file contains the jiffies based clocksource. | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * Copyright (C) 2004, 2005 IBM, John Stultz (johnstul@us.ibm.com) | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  | * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  | * the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  | * (at your option) any later version. | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | * GNU General Public License for more details. | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | * along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | ************************************************************************/ | 
					
						
							|  |  |  | #include <linux/clocksource.h>
 | 
					
						
							|  |  |  | #include <linux/jiffies.h>
 | 
					
						
							| 
									
										
										
										
											2011-01-27 15:59:00 +01:00
										 |  |  | #include <linux/module.h>
 | 
					
						
							| 
									
										
										
										
											2006-06-26 00:25:05 -07:00
										 |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-27 16:00:32 +01:00
										 |  |  | #include "tick-internal.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-26 00:25:05 -07:00
										 |  |  | /* The Jiffies based clocksource is the lowest common
 | 
					
						
							|  |  |  |  * denominator clock source which should function on | 
					
						
							|  |  |  |  * all systems. It has the same coarse resolution as | 
					
						
							|  |  |  |  * the timer interrupt frequency HZ and it suffers | 
					
						
							|  |  |  |  * inaccuracies caused by missed or lost timer | 
					
						
							|  |  |  |  * interrupts and the inability for the timer | 
					
						
							|  |  |  |  * interrupt hardware to accuratly tick at the | 
					
						
							| 
									
										
										
										
											2011-03-30 22:57:33 -03:00
										 |  |  |  * requested HZ value. It is also not recommended | 
					
						
							| 
									
										
										
										
											2006-06-26 00:25:05 -07:00
										 |  |  |  * for "tick-less" systems. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define NSEC_PER_JIFFY	((u32)((((u64)NSEC_PER_SEC)<<8)/ACTHZ))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Since jiffies uses a simple NSEC_PER_JIFFY multiplier
 | 
					
						
							|  |  |  |  * conversion, the .shift value could be zero. However | 
					
						
							|  |  |  |  * this would make NTP adjustments impossible as they are | 
					
						
							|  |  |  |  * in units of 1/2^.shift. Thus we use JIFFIES_SHIFT to | 
					
						
							|  |  |  |  * shift both the nominator and denominator the same | 
					
						
							|  |  |  |  * amount, and give ntp adjustments in units of 1/2^8 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The value 8 is somewhat carefully chosen, as anything | 
					
						
							|  |  |  |  * larger can result in overflows. NSEC_PER_JIFFY grows as | 
					
						
							| 
									
										
										
										
											2008-10-16 19:02:37 +02:00
										 |  |  |  * HZ shrinks, so values greater than 8 overflow 32bits when | 
					
						
							| 
									
										
										
										
											2006-06-26 00:25:05 -07:00
										 |  |  |  * HZ=100. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define JIFFIES_SHIFT	8
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 12:24:00 -07:00
										 |  |  | static cycle_t jiffies_read(struct clocksource *cs) | 
					
						
							| 
									
										
										
										
											2006-06-26 00:25:05 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	return (cycle_t) jiffies; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct clocksource clocksource_jiffies = { | 
					
						
							|  |  |  | 	.name		= "jiffies", | 
					
						
							| 
									
										
										
										
											2006-10-17 00:09:32 -07:00
										 |  |  | 	.rating		= 1, /* lowest valid rating*/ | 
					
						
							| 
									
										
										
										
											2006-06-26 00:25:05 -07:00
										 |  |  | 	.read		= jiffies_read, | 
					
						
							|  |  |  | 	.mask		= 0xffffffff, /*32bits*/ | 
					
						
							|  |  |  | 	.mult		= NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */ | 
					
						
							|  |  |  | 	.shift		= JIFFIES_SHIFT, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-27 15:59:00 +01:00
										 |  |  | #if (BITS_PER_LONG < 64)
 | 
					
						
							|  |  |  | u64 get_jiffies_64(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long seq; | 
					
						
							|  |  |  | 	u64 ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		seq = read_seqbegin(&xtime_lock); | 
					
						
							|  |  |  | 		ret = jiffies_64; | 
					
						
							|  |  |  | 	} while (read_seqretry(&xtime_lock, seq)); | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL(get_jiffies_64); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EXPORT_SYMBOL(jiffies); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-26 00:25:05 -07:00
										 |  |  | static int __init init_jiffies_clocksource(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-06-26 00:25:14 -07:00
										 |  |  | 	return clocksource_register(&clocksource_jiffies); | 
					
						
							| 
									
										
										
										
											2006-06-26 00:25:05 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-04-04 19:08:24 -07:00
										 |  |  | core_initcall(init_jiffies_clocksource); | 
					
						
							| 
									
										
										
										
											2009-08-14 15:47:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct clocksource * __init __weak clocksource_default_clock(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return &clocksource_jiffies; | 
					
						
							|  |  |  | } |