monotonic time 该时间自系统开机后就一直单调地增加,它不像xtime可以因用户的调整时间而产生跳变,不过该时间不计算系统休眠的时间,也就是说,系统休眠时,monotoic时间不会递增。
raw monotonic time 该时间与monotonic时间类似,也是单调递增的时间,唯一的不同是:raw monotonic time“更纯净”,他不会受到NTP时间调整的影响,它代表着系统独立时钟硬件对时间的统计。
boot time 与monotonic时间相同,不过会累加上系统休眠的时间,它代表着系统上电后的总时间。
123456
时间种 类 精度(统计单位) 访问速度 累计休眠时间 受NTP调整的影响
RTC 低 慢 Yes Yes
xtime 高 快 Yes Yes
monotonic 高 快 No Yes
raw monotonic 高 快 No No
boot time 高 快 Yes Yes
2. struct timekeeper
内核用timekeeper结构来组织与时间相关的数据,它的定义如下:
1234567891011121314151617181920212223242526272829
struct timekeeper {
struct clocksource *clock; /* Current clocksource used for timekeeping. */
u32 mult; /* NTP adjusted clock multiplier */
int shift; /* The shift value of the current clocksource. */
cycle_t cycle_interval; /* Number of clock cycles in one NTP interval. */
u64 xtime_interval; /* Number of clock shifted nano seconds in one NTP interval. */
s64 xtime_remainder; /* shifted nano seconds left over when rounding cycle_interval */
u32 raw_interval; /* Raw nano seconds accumulated per NTP interval. */
u64 xtime_nsec; /* Clock shifted nano seconds remainder not stored in xtime.tv_nsec. */
/* Difference between accumulated time and NTP time in ntp
* shifted nano seconds. */
s64 ntp_error;
/* Shift conversion between clock shifted nano seconds and
* ntp shifted nano seconds. */
int ntp_error_shift;
struct timespec xtime; /* The current time */
struct timespec wall_to_monotonic;
struct timespec total_sleep_time; /* time spent in suspend */
struct timespec raw_time; /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
ktime_t offs_real; /* Offset clock monotonic -> clock realtime */
ktime_t offs_boot; /* Offset clock monotonic -> clock boottime */
seqlock_t lock; /* Seqlock for all timekeeper values */
};
unsigned int jiffies_to_msecs(const unsigned long j);
unsigned int jiffies_to_usecs(const unsigned long j);
unsigned long msecs_to_jiffies(const unsigned int m);
unsigned long usecs_to_jiffies(const unsigned int u);