2

/dev/rtc 上的 ioctl RTC_SET_TIME 可用于设置 RTC 芯片的时间和日期。但是 /dev/rtc 只允许一个进程打开它。

所以我计划继续使用不需要打开 /dev/rtc 设备的clock_settime() 。但我不清楚它是否将日期和时间设置为 RTC芯片

根据手册页,clock_settime()API 支持以下时钟。哪一个写入 RTC芯片(如果它支持)?

CLOCK_REALTIME
    System-wide realtime clock. Setting this clock requires appropriate privileges. 
CLOCK_MONOTONIC
    Clock that cannot be set and represents monotonic time since some unspecified starting point. 
CLOCK_PROCESS_CPUTIME_ID
    High-resolution per-process timer from the CPU. 
CLOCK_THREAD_CPUTIME_ID
    Thread-specific CPU-time clock. 
4

2 回答 2

0

不幸clock_settime()的是,不,不会更新实时时钟 (RTC)。

我见过人们system("rtc -s hw");在打电话clock_settime()强制 RTC 更新后使用。

于 2013-12-06T21:03:36.200 回答
0

简短的回答:

是否clock_settime()写到 RTC 是未指定的,因此是特定于实现的


长答案:

调用 clock_settime(CLOCK_REALTIME, ...) 保证设置操作系统的系统时钟,这是内核中的软件时钟。而已。

  • 操作系统可能会在关机时将系统时钟写入 RTC。( vxWorks )
  • 操作系统可以周期性地将系统时钟写入RTC,例如每11分钟一次。(可能的 Linux 配置
  • 操作系统可以实现 RTC 漂移补偿。设置 RTC 可能会产生意想不到的结果。( Linux 与 adtimex )

底线:在设置 RTC 之前,了解事物是如何在您的平台上实现的。

于 2020-10-08T10:09:33.157 回答