1734efb46Sjohn stultz /*********************************************************************** 2734efb46Sjohn stultz * linux/kernel/time/jiffies.c 3734efb46Sjohn stultz * 4734efb46Sjohn stultz * This file contains the jiffies based clocksource. 5734efb46Sjohn stultz * 6734efb46Sjohn stultz * Copyright (C) 2004, 2005 IBM, John Stultz (johnstul@us.ibm.com) 7734efb46Sjohn stultz * 8734efb46Sjohn stultz * This program is free software; you can redistribute it and/or modify 9734efb46Sjohn stultz * it under the terms of the GNU General Public License as published by 10734efb46Sjohn stultz * the Free Software Foundation; either version 2 of the License, or 11734efb46Sjohn stultz * (at your option) any later version. 12734efb46Sjohn stultz * 13734efb46Sjohn stultz * This program is distributed in the hope that it will be useful, 14734efb46Sjohn stultz * but WITHOUT ANY WARRANTY; without even the implied warranty of 15734efb46Sjohn stultz * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16734efb46Sjohn stultz * GNU General Public License for more details. 17734efb46Sjohn stultz * 18734efb46Sjohn stultz * You should have received a copy of the GNU General Public License 19734efb46Sjohn stultz * along with this program; if not, write to the Free Software 20734efb46Sjohn stultz * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21734efb46Sjohn stultz * 22734efb46Sjohn stultz ************************************************************************/ 23734efb46Sjohn stultz #include <linux/clocksource.h> 24734efb46Sjohn stultz #include <linux/jiffies.h> 25734efb46Sjohn stultz #include <linux/init.h> 26734efb46Sjohn stultz 27734efb46Sjohn stultz /* The Jiffies based clocksource is the lowest common 28734efb46Sjohn stultz * denominator clock source which should function on 29734efb46Sjohn stultz * all systems. It has the same coarse resolution as 30734efb46Sjohn stultz * the timer interrupt frequency HZ and it suffers 31734efb46Sjohn stultz * inaccuracies caused by missed or lost timer 32734efb46Sjohn stultz * interrupts and the inability for the timer 33734efb46Sjohn stultz * interrupt hardware to accuratly tick at the 34734efb46Sjohn stultz * requested HZ value. It is also not reccomended 35734efb46Sjohn stultz * for "tick-less" systems. 36734efb46Sjohn stultz */ 37734efb46Sjohn stultz #define NSEC_PER_JIFFY ((u32)((((u64)NSEC_PER_SEC)<<8)/ACTHZ)) 38734efb46Sjohn stultz 39734efb46Sjohn stultz /* Since jiffies uses a simple NSEC_PER_JIFFY multiplier 40734efb46Sjohn stultz * conversion, the .shift value could be zero. However 41734efb46Sjohn stultz * this would make NTP adjustments impossible as they are 42734efb46Sjohn stultz * in units of 1/2^.shift. Thus we use JIFFIES_SHIFT to 43734efb46Sjohn stultz * shift both the nominator and denominator the same 44734efb46Sjohn stultz * amount, and give ntp adjustments in units of 1/2^8 45734efb46Sjohn stultz * 46734efb46Sjohn stultz * The value 8 is somewhat carefully chosen, as anything 47734efb46Sjohn stultz * larger can result in overflows. NSEC_PER_JIFFY grows as 48*025dfdafSFrederik Schwarzer * HZ shrinks, so values greater than 8 overflow 32bits when 49734efb46Sjohn stultz * HZ=100. 50734efb46Sjohn stultz */ 51734efb46Sjohn stultz #define JIFFIES_SHIFT 8 52734efb46Sjohn stultz 53734efb46Sjohn stultz static cycle_t jiffies_read(void) 54734efb46Sjohn stultz { 55734efb46Sjohn stultz return (cycle_t) jiffies; 56734efb46Sjohn stultz } 57734efb46Sjohn stultz 58734efb46Sjohn stultz struct clocksource clocksource_jiffies = { 59734efb46Sjohn stultz .name = "jiffies", 603f4a0b91Sjohn stultz .rating = 1, /* lowest valid rating*/ 61734efb46Sjohn stultz .read = jiffies_read, 62734efb46Sjohn stultz .mask = 0xffffffff, /*32bits*/ 63734efb46Sjohn stultz .mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */ 641aa5dfb7SJohn Stultz .mult_orig = NSEC_PER_JIFFY << JIFFIES_SHIFT, 65734efb46Sjohn stultz .shift = JIFFIES_SHIFT, 66734efb46Sjohn stultz }; 67734efb46Sjohn stultz 68734efb46Sjohn stultz static int __init init_jiffies_clocksource(void) 69734efb46Sjohn stultz { 70a2752549Sjohn stultz return clocksource_register(&clocksource_jiffies); 71734efb46Sjohn stultz } 72734efb46Sjohn stultz 7398de9e3bSjohn stultz core_initcall(init_jiffies_clocksource); 74