Real-time clock alarm

本文深入探讨了Linux系统中内核时钟与真实时间时钟(RTC)的作用,解释了系统启动时如何从RTC中读取时间进行时间同步,并详细介绍了Linux内核与RTC进行互操作的时机和过程。

Real-time clock alarm

A real time clock alarm is a feature that can be used to allow a computer to 'wake up' after shut down to execute tasks every day or on a certain day. It can sometimes be found in the 'Power Management' section of a motherboard's BIOS setup. However, newer BIOS setups do not include an RTC alarm option, although it can still be set from within user applications. Wake On LAN, Wake on ring, and IPMI functions could also be used to start a computer after it is turned off.



In Android 4.0.1 and earlier release,
GoogleServicesFramework, GooglePartnerSetup, Maps setup Alarms via
AlarmManagerService of the type ELAPSED_REALTIME_WAKEUP and
RTC_WAKEUP.

com.google.android.partnersetup

com.google.android.apps.maps
com.google.android.gsf


首先搞清楚RTC在kernel内的作用: linux系统有两个时钟:一个是由主板电池驱动的“Real Time Clock”也叫做RTC或者叫CMOS时钟,硬件时钟。当操作系统关机的时候,用这个来记录时间,但是对于运行的系统是不用这个时间的。

  另一个时间是 “System clock”也叫内核时钟或者软件时钟,是由软件根据时间中断来进行计数的,

  内核时钟在系统关机的情况下是不存在的,所以,当操作系统启动的时候,内核时钟是要读取RTC时间

  来进行时间同步。并且在系统关机的时候将系统时间写回RTC中进行同步。 如前所述,Linux内核与RTC进行互操作的时机只有两个:

  1) 内核在启动时从RTC中读取启动时的时间与日期;

  2) 内核在需要时将时间与日期回写到RTC中。 系统启动时,内核通过读取RTC来初始化内核时钟,又叫墙上时间,该时间放在xtime变量中。

  The current time of day (the wall time) is defined in kernel/timer.c:

  struct timespec xtime;

  The timespec data structure is defined in <linux/time.h> as:struct timespec {

  time_t tv_sec; /* seconds */

  long tv_nsec; /* nanoseconds */

  };

  问题1:系统启动时在哪读取RTC的值并设置内核时钟进行时间同步的呢?

  最有可能读取RTC设置内核时钟的位置应该在arch/arm/kernel/time.c里的time_init函数内.time.c为系统的时钟驱动部分.time_init函数会在系统初始化时,由init/main.c里的start_kernel函数内调用.X86架构就是在这里读 RTC值并初始化系统时钟xtime的. ARM架构的time_init代码如下:/* arch/arm/kernel/time.c */void __init time_init(void)

  {

  if (system_timer->offset == NULL)

  system_timer->offset = dummy_gettimeoffset;

  system_timer->init();#ifdef CONFIG_NO_IDLE_HZ

  if (system_timer->dyn_tick)

  system_timer->dyn_tick->lock = SPIN_LOCK_UNLOCKED;

  #endif
Signal Stop Print Pass to program Description SIGHUP Yes Yes Yes Hangup SIGINT Yes Yes No Interrupt SIGQUIT Yes Yes Yes Quit SIGILL Yes Yes Yes Illegal instruction SIGTRAP Yes Yes No Trace/breakpoint trap SIGABRT Yes Yes Yes Aborted SIGEMT Yes Yes Yes Emulation trap SIGFPE Yes Yes Yes Arithmetic exception SIGKILL Yes Yes Yes Killed SIGBUS Yes Yes Yes Bus error SIGSEGV Yes Yes Yes Segmentation fault SIGSYS Yes Yes Yes Bad system call SIGPIPE Yes Yes Yes Broken pipe SIGALRM No No Yes Alarm clock SIGTERM Yes Yes Yes Terminated SIGURG No No Yes Urgent I/O condition SIGSTOP Yes Yes Yes Stopped (signal) SIGTSTP Yes Yes Yes Stopped (user) SIGCONT Yes Yes Yes Continued SIGCHLD No No Yes Child status changed SIGTTIN Yes Yes Yes Stopped (tty input) SIGTTOU Yes Yes Yes Stopped (tty output) SIGIO No No Yes I/O possible SIGXCPU Yes Yes Yes CPU time limit exceeded SIGXFSZ Yes Yes Yes File size limit exceeded SIGVTALRM No No Yes Virtual timer expired SIGPROF No No Yes Profiling timer expired SIGWINCH No No Yes Window size changed SIGLOST Yes Yes Yes Resource lost SIGUSR1 Yes Yes Yes User defined signal 1 SIGUSR2 Yes Yes Yes User defined signal 2 SIGPWR Yes Yes Yes Power fail/restart SIGPOLL No No Yes Pollable event occurred SIGWIND Yes Yes Yes SIGWIND SIGPHONE Yes Yes Yes SIGPHONE SIGWAITING No No Yes Process's LWPs are blocked SIGLWP No No Yes Signal LWP SIGDANGER Yes Yes Yes Swap space dangerously low SIGGRANT Yes Yes Yes Monitor mode granted SIGRETRACT Yes Yes Yes Need to relinquish monitor mode SIGMSG Yes Yes Yes Monitor mode data available SIGSOUND Yes Yes Yes Sound completed SIGSAK Yes Yes Yes Secure attention SIGPRIO No No Yes SIGPRIO SIG33 Yes Yes Yes Real-time event 33 SIG34 Yes Yes Yes Real-time event 34 SIG35 Yes Yes Yes Real-time event 35 SIG36 Yes Yes Yes Real-time event 36 SIG37 Yes Yes Yes Real-time event 37 SIG38 Yes Yes Yes Real-time event 38 SIG39 Yes Yes Yes Real-time event 39
最新发布
09-04
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值