/* * linux/kernel/time/timekeeping.c * * Kernel timekeeping code and accessor functions * * This code was moved from linux/kernel/timer.c. * Please see that file for copyright and history logs. * */#include<linux/timekeeper_internal.h>#include<linux/module.h>#include<linux/interrupt.h>#include<linux/percpu.h>#include<linux/init.h>#include<linux/mm.h>#include<linux/sched.h>#include<linux/syscore_ops.h>#include<linux/clocksource.h>#include<linux/jiffies.h>#include<linux/time.h>#include<linux/tick.h>#include<linux/stop_machine.h>staticstructtimekeepertimekeeper;/* * This read-write spinlock protects us from races in SMP while * playing with xtime. */__cacheline_aligned_in_smpDEFINE_SEQLOCK(xtime_lock);/* flag for if timekeeping is suspended */int__read_mostlytimekeeping_suspended;staticinlinevoidtk_normalize_xtime(structtimekeeper*tk){while(tk->xtime_nsec>=((u64)NSEC_PER_SEC<<tk->shift)){tk->xtime_nsec-=(u64)NSEC_PER_SEC<<tk->shift;tk->xtime_sec++;}}staticstructtimespectk_xtime(structtimekeeper*tk){structtimespects;ts.tv_sec=tk->xtime_sec;ts.tv_nsec=(long)(tk->xtime_nsec>>tk->shift);returnts;}staticvoidtk_set_xtime(structtimekeeper*tk,conststructtimespec*ts){tk->xtime_sec=ts->tv_sec;tk->xtime_nsec=(u64)ts->tv_nsec<<tk->shift;}staticvoidtk_xtime_add(structtimekeeper*tk,conststructtimespec*ts){tk->xtime_sec+=ts->tv_sec;tk->xtime_nsec+=(u64)ts->tv_nsec<<tk->shift;