mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-19 02:04:19 +08:00
1aa5dfb751
The clocksource frequency is represented by clocksource->mult/2^(clocksource->shift). Currently, when NTP makes adjustments to the clock frequency, they are made directly to the mult value. This has the drawback that once changed, we cannot know what the orignal mult value was, or how much adjustment has been applied. This property causes problems in calculating proper ntp intervals when switching back and forth between clocksources. This patch separates the current mult value into a mult and mult_orig pair. The mult_orig value stays constant, while the ntp clocksource adjustments are done only to the mult value. This allows for correct ntp interval calculation and additionally lays the groundwork for a new notion of time, what I'm calling the monotonic-raw time, which is introduced in a following patch. Signed-off-by: John Stultz <johnstul@us.ibm.com> Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
74 lines
2.6 KiB
C
74 lines
2.6 KiB
C
/***********************************************************************
|
|
* 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>
|
|
#include <linux/init.h>
|
|
|
|
/* 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
|
|
* requested HZ value. It is also not reccomended
|
|
* 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
|
|
* HZ shrinks, so values greater then 8 overflow 32bits when
|
|
* HZ=100.
|
|
*/
|
|
#define JIFFIES_SHIFT 8
|
|
|
|
static cycle_t jiffies_read(void)
|
|
{
|
|
return (cycle_t) jiffies;
|
|
}
|
|
|
|
struct clocksource clocksource_jiffies = {
|
|
.name = "jiffies",
|
|
.rating = 1, /* lowest valid rating*/
|
|
.read = jiffies_read,
|
|
.mask = 0xffffffff, /*32bits*/
|
|
.mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
|
|
.mult_orig = NSEC_PER_JIFFY << JIFFIES_SHIFT,
|
|
.shift = JIFFIES_SHIFT,
|
|
};
|
|
|
|
static int __init init_jiffies_clocksource(void)
|
|
{
|
|
return clocksource_register(&clocksource_jiffies);
|
|
}
|
|
|
|
core_initcall(init_jiffies_clocksource);
|