time.c

来自「omap3 linux 2.6 用nocc去除了冗余代码」· C语言 代码 · 共 163 行

C
163
字号
/* *  linux/arch/arm/kernel/time.c * *  Copyright (C) 1991, 1992, 1995  Linus Torvalds *  Modifications for ARM (C) 1994-2001 Russell King * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * *  This file contains the ARM-specific time handling details: *  reading the RTC at bootup, etc... * *  1994-07-02  Alan Modra *              fixed set_rtc_mmss, fixed time.year for >= 2000, new mktime *  1998-12-20  Updated NTP code according to technical memorandum Jan '96 *              "A Kernel Model for Precision Timekeeping" by Dave Mills */#include <linux/module.h>#include <linux/kernel.h>#include <linux/interrupt.h>#include <linux/time.h>#include <linux/init.h>#include <linux/smp.h>#include <linux/timex.h>#include <linux/errno.h>#include <linux/profile.h>#include <linux/sysdev.h>#include <linux/timer.h>#include <linux/irq.h>#include <linux/mc146818rtc.h>#include <asm/leds.h>#include <asm/thread_info.h>#include <asm/mach/time.h>/* * Our system timer. */struct sys_timer *system_timer;/* change this if you have some constant time drift */#define USECS_PER_JIFFY	(1000000/HZ)/* * hook for setting the RTC's idea of the current time. */int (*set_rtc)(void);/* * An implementation of printk_clock() independent from * sched_clock().  This avoids non-bootable kernels when * printk_clock is enabled. */unsigned long long printk_clock(void){	return (unsigned long long)(jiffies - INITIAL_JIFFIES) *			(1000000000 / HZ);}static unsigned long next_rtc_update;/* * If we have an externally synchronized linux clock, then update * CMOS clock accordingly every ~11 minutes.  set_rtc() has to be * called as close as possible to 500 ms before the new second * starts. */static inline void do_set_rtc(void){	if (!ntp_synced() || set_rtc == NULL)		return;	if (next_rtc_update &&	    time_before((unsigned long)xtime.tv_sec, next_rtc_update))		return;	if (xtime.tv_nsec < 500000000 - ((unsigned) tick_nsec >> 1) &&	    xtime.tv_nsec >= 500000000 + ((unsigned) tick_nsec >> 1))		return;	if (set_rtc())		/*		 * rtc update failed.  Try again in 60s		 */		next_rtc_update = xtime.tv_sec + 60;	else		next_rtc_update = xtime.tv_sec + 660;}#define	do_leds()/** * save_time_delta - Save the offset between system time and RTC time * @delta: pointer to timespec to store delta * @rtc: pointer to timespec for current RTC time * * Return a delta between the system time and the RTC time, such * that system time can be restored later with restore_time_delta() */void save_time_delta(struct timespec *delta, struct timespec *rtc){	set_normalized_timespec(delta,				xtime.tv_sec - rtc->tv_sec,				xtime.tv_nsec - rtc->tv_nsec);}EXPORT_SYMBOL(save_time_delta);/** * restore_time_delta - Restore the current system time * @delta: delta returned by save_time_delta() * @rtc: pointer to timespec for current RTC time */void restore_time_delta(struct timespec *delta, struct timespec *rtc){	struct timespec ts;	set_normalized_timespec(&ts,				delta->tv_sec + rtc->tv_sec,				delta->tv_nsec + rtc->tv_nsec);	do_settimeofday(&ts);}EXPORT_SYMBOL(restore_time_delta);#define timer_suspend NULL#define timer_resume NULLstatic struct sysdev_class timer_sysclass = {	set_kset_name("timer"),	.suspend	= timer_suspend,	.resume		= timer_resume,};static int __init timer_init_sysfs(void){	int ret = sysdev_class_register(&timer_sysclass);	if (ret == 0) {		system_timer->dev.cls = &timer_sysclass;		ret = sysdev_register(&system_timer->dev);	}	return ret;}device_initcall(timer_init_sysfs);void __init time_init(void){	system_timer->init();}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?