转载:Linux时间系统之RTC时间_u013686019的专栏-CSDN博客_rtc时间
一、概述
不知道有没有“时间系统”的说法,我们暂且把它作为Linux中和时间相关的内容的统称吧。
Linux时间有两个, 系统时间(Wall Time), RTC时间。
系统时间(WT):由Linux系统软件维持的时间,比如command date:
$ date
2017年 02月 25日 星期六 16:58:10 CST
获取到的就是系统时间。
RTC时间:这个时间来自我们设备上的RTC芯片,通过command hwclock 可以读取:
# hwclock -r --> root权限才可以运行
2017年02月25日 星期六 17时01分57秒 -0.906462 seconds
我们通过man查看hwclock的介绍:
hwclock - query or set the hardware clock (RTC)
接下来,通过代码看下两者的关系。
二、WT时间和RTC时间
WT时间来自于RTC时间,流程是:
上电-->RTC驱动加载-->从RTC同步时间到WT时间
上代码:
hctosys.c (drivers\rtc)
static int __init rtc_hctosys(void)
{
struct timespec tv = {
.tv_nsec = NSEC_PER_SEC >> 1,
};
err = rtc_read_time(rtc, &tm);
err = do_settimeofday(&tv);
dev_info(rtc->dev.parent,
"setting system clock to "
"%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec,
(unsigned int) tv.tv_sec);
}
late_initcall(rtc_hctosys);
late_initcall说明系统在启动流程的后面才会调用该函数去同步时间。关于late_initcall可见最后PS。
接下来从底层到上层进行梳理。
————————————————
版权声明:本文为CSDN博主「__2017__」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u013686019/article/details/57126940